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 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2460 fde->stack_realign = 1;
2461 fde->stack_realignment = INTVAL (XEXP (src, 1));
2462 cfa_store.offset = 0;
2464 if (cfa.reg != STACK_POINTER_REGNUM
2465 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2466 fde->drap_reg = cfa.reg;
2474 def_cfa_1 (label, &cfa);
2479 /* Saving a register to the stack. Make sure dest is relative to the
2481 switch (GET_CODE (XEXP (dest, 0)))
2486 /* We can't handle variable size modifications. */
2487 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2489 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2491 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2492 && cfa_store.reg == STACK_POINTER_REGNUM);
2494 cfa_store.offset += offset;
2495 if (cfa.reg == STACK_POINTER_REGNUM)
2496 cfa.offset = cfa_store.offset;
2498 offset = -cfa_store.offset;
2504 offset = GET_MODE_SIZE (GET_MODE (dest));
2505 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2508 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2509 == STACK_POINTER_REGNUM)
2510 && cfa_store.reg == STACK_POINTER_REGNUM);
2512 cfa_store.offset += offset;
2514 /* Rule 18: If stack is aligned, we will use FP as a
2515 reference to represent the address of the stored
2518 && fde->stack_realign
2519 && src == hard_frame_pointer_rtx)
2521 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2522 cfa_store.offset = 0;
2525 if (cfa.reg == STACK_POINTER_REGNUM)
2526 cfa.offset = cfa_store.offset;
2528 offset = -cfa_store.offset;
2532 /* With an offset. */
2539 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2540 && REG_P (XEXP (XEXP (dest, 0), 0)));
2541 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2542 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2545 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2547 if (cfa_store.reg == (unsigned) regno)
2548 offset -= cfa_store.offset;
2551 gcc_assert (cfa_temp.reg == (unsigned) regno);
2552 offset -= cfa_temp.offset;
2558 /* Without an offset. */
2561 int regno = REGNO (XEXP (dest, 0));
2563 if (cfa_store.reg == (unsigned) regno)
2564 offset = -cfa_store.offset;
2567 gcc_assert (cfa_temp.reg == (unsigned) regno);
2568 offset = -cfa_temp.offset;
2575 gcc_assert (cfa_temp.reg
2576 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2577 offset = -cfa_temp.offset;
2578 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2586 /* If the source operand of this MEM operation is not a
2587 register, basically the source is return address. Here
2588 we only care how much stack grew and we don't save it. */
2592 if (REGNO (src) != STACK_POINTER_REGNUM
2593 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2594 && (unsigned) REGNO (src) == cfa.reg)
2596 /* We're storing the current CFA reg into the stack. */
2598 if (cfa.offset == 0)
2601 /* If stack is aligned, putting CFA reg into stack means
2602 we can no longer use reg + offset to represent CFA.
2603 Here we use DW_CFA_def_cfa_expression instead. The
2604 result of this expression equals to the original CFA
2607 && fde->stack_realign
2608 && cfa.indirect == 0
2609 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2611 dw_cfa_location cfa_exp;
2613 gcc_assert (fde->drap_reg == cfa.reg);
2615 cfa_exp.indirect = 1;
2616 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2617 cfa_exp.base_offset = offset;
2620 fde->drap_reg_saved = 1;
2622 def_cfa_1 (label, &cfa_exp);
2626 /* If the source register is exactly the CFA, assume
2627 we're saving SP like any other register; this happens
2629 def_cfa_1 (label, &cfa);
2630 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2635 /* Otherwise, we'll need to look in the stack to
2636 calculate the CFA. */
2637 rtx x = XEXP (dest, 0);
2641 gcc_assert (REG_P (x));
2643 cfa.reg = REGNO (x);
2644 cfa.base_offset = offset;
2646 def_cfa_1 (label, &cfa);
2651 def_cfa_1 (label, &cfa);
2653 span = targetm.dwarf_register_span (src);
2656 queue_reg_save (label, src, NULL_RTX, offset);
2659 /* We have a PARALLEL describing where the contents of SRC
2660 live. Queue register saves for each piece of the
2664 HOST_WIDE_INT span_offset = offset;
2666 gcc_assert (GET_CODE (span) == PARALLEL);
2668 limit = XVECLEN (span, 0);
2669 for (par_index = 0; par_index < limit; par_index++)
2671 rtx elem = XVECEXP (span, 0, par_index);
2673 queue_reg_save (label, elem, NULL_RTX, span_offset);
2674 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2685 /* Record call frame debugging information for INSN, which either
2686 sets SP or FP (adjusting how we calculate the frame address) or saves a
2687 register to the stack. If INSN is NULL_RTX, initialize our state.
2689 If AFTER_P is false, we're being called before the insn is emitted,
2690 otherwise after. Call instructions get invoked twice. */
2693 dwarf2out_frame_debug (rtx insn, bool after_p)
2697 bool handled_one = false;
2699 if (insn == NULL_RTX)
2703 /* Flush any queued register saves. */
2704 flush_queued_reg_saves ();
2706 /* Set up state for generating call frame debug info. */
2709 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2711 cfa.reg = STACK_POINTER_REGNUM;
2714 cfa_temp.offset = 0;
2716 for (i = 0; i < num_regs_saved_in_regs; i++)
2718 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2719 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2721 num_regs_saved_in_regs = 0;
2723 if (barrier_args_size)
2725 XDELETEVEC (barrier_args_size);
2726 barrier_args_size = NULL;
2731 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2732 flush_queued_reg_saves ();
2734 if (!RTX_FRAME_RELATED_P (insn))
2736 /* ??? This should be done unconditionally since stack adjustments
2737 matter if the stack pointer is not the CFA register anymore but
2738 is still used to save registers. */
2739 if (!ACCUMULATE_OUTGOING_ARGS)
2740 dwarf2out_notice_stack_adjust (insn, after_p);
2744 label = dwarf2out_cfi_label (false);
2746 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2747 switch (REG_NOTE_KIND (note))
2749 case REG_FRAME_RELATED_EXPR:
2750 insn = XEXP (note, 0);
2753 case REG_CFA_DEF_CFA:
2754 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2758 case REG_CFA_ADJUST_CFA:
2763 if (GET_CODE (n) == PARALLEL)
2764 n = XVECEXP (n, 0, 0);
2766 dwarf2out_frame_debug_adjust_cfa (n, label);
2770 case REG_CFA_OFFSET:
2773 n = single_set (insn);
2774 dwarf2out_frame_debug_cfa_offset (n, label);
2778 case REG_CFA_REGISTER:
2783 if (GET_CODE (n) == PARALLEL)
2784 n = XVECEXP (n, 0, 0);
2786 dwarf2out_frame_debug_cfa_register (n, label);
2790 case REG_CFA_EXPRESSION:
2793 n = single_set (insn);
2794 dwarf2out_frame_debug_cfa_expression (n, label);
2798 case REG_CFA_RESTORE:
2803 if (GET_CODE (n) == PARALLEL)
2804 n = XVECEXP (n, 0, 0);
2807 dwarf2out_frame_debug_cfa_restore (n, label);
2811 case REG_CFA_SET_VDRAP:
2815 dw_fde_ref fde = current_fde ();
2818 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2820 fde->vdrap_reg = REGNO (n);
2832 insn = PATTERN (insn);
2834 dwarf2out_frame_debug_expr (insn, label);
2836 /* Check again. A parallel can save and update the same register.
2837 We could probably check just once, here, but this is safer than
2838 removing the check above. */
2839 if (clobbers_queued_reg_save (insn))
2840 flush_queued_reg_saves ();
2843 /* Determine if we need to save and restore CFI information around this
2844 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2845 we do need to save/restore, then emit the save now, and insert a
2846 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2849 dwarf2out_cfi_begin_epilogue (rtx insn)
2851 bool saw_frp = false;
2854 /* Scan forward to the return insn, noticing if there are possible
2855 frame related insns. */
2856 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2861 /* Look for both regular and sibcalls to end the block. */
2862 if (returnjump_p (i))
2864 if (CALL_P (i) && SIBLING_CALL_P (i))
2867 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2870 rtx seq = PATTERN (i);
2872 if (returnjump_p (XVECEXP (seq, 0, 0)))
2874 if (CALL_P (XVECEXP (seq, 0, 0))
2875 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2878 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2879 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2883 if (RTX_FRAME_RELATED_P (i))
2887 /* If the port doesn't emit epilogue unwind info, we don't need a
2888 save/restore pair. */
2892 /* Otherwise, search forward to see if the return insn was the last
2893 basic block of the function. If so, we don't need save/restore. */
2894 gcc_assert (i != NULL);
2895 i = next_real_insn (i);
2899 /* Insert the restore before that next real insn in the stream, and before
2900 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2901 properly nested. This should be after any label or alignment. This
2902 will be pushed into the CFI stream by the function below. */
2905 rtx p = PREV_INSN (i);
2908 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2912 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2914 emit_cfa_remember = true;
2916 /* And emulate the state save. */
2917 gcc_assert (!cfa_remember.in_use);
2919 cfa_remember.in_use = 1;
2922 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
2926 dwarf2out_frame_debug_restore_state (void)
2928 dw_cfi_ref cfi = new_cfi ();
2929 const char *label = dwarf2out_cfi_label (false);
2931 cfi->dw_cfi_opc = DW_CFA_restore_state;
2932 add_fde_cfi (label, cfi);
2934 gcc_assert (cfa_remember.in_use);
2936 cfa_remember.in_use = 0;
2939 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2940 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2941 (enum dwarf_call_frame_info cfi);
2943 static enum dw_cfi_oprnd_type
2944 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2949 case DW_CFA_GNU_window_save:
2950 case DW_CFA_remember_state:
2951 case DW_CFA_restore_state:
2952 return dw_cfi_oprnd_unused;
2954 case DW_CFA_set_loc:
2955 case DW_CFA_advance_loc1:
2956 case DW_CFA_advance_loc2:
2957 case DW_CFA_advance_loc4:
2958 case DW_CFA_MIPS_advance_loc8:
2959 return dw_cfi_oprnd_addr;
2962 case DW_CFA_offset_extended:
2963 case DW_CFA_def_cfa:
2964 case DW_CFA_offset_extended_sf:
2965 case DW_CFA_def_cfa_sf:
2966 case DW_CFA_restore:
2967 case DW_CFA_restore_extended:
2968 case DW_CFA_undefined:
2969 case DW_CFA_same_value:
2970 case DW_CFA_def_cfa_register:
2971 case DW_CFA_register:
2972 case DW_CFA_expression:
2973 return dw_cfi_oprnd_reg_num;
2975 case DW_CFA_def_cfa_offset:
2976 case DW_CFA_GNU_args_size:
2977 case DW_CFA_def_cfa_offset_sf:
2978 return dw_cfi_oprnd_offset;
2980 case DW_CFA_def_cfa_expression:
2981 return dw_cfi_oprnd_loc;
2988 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2989 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2990 (enum dwarf_call_frame_info cfi);
2992 static enum dw_cfi_oprnd_type
2993 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2997 case DW_CFA_def_cfa:
2998 case DW_CFA_def_cfa_sf:
3000 case DW_CFA_offset_extended_sf:
3001 case DW_CFA_offset_extended:
3002 return dw_cfi_oprnd_offset;
3004 case DW_CFA_register:
3005 return dw_cfi_oprnd_reg_num;
3007 case DW_CFA_expression:
3008 return dw_cfi_oprnd_loc;
3011 return dw_cfi_oprnd_unused;
3015 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3016 switch to the data section instead, and write out a synthetic start label
3017 for collect2 the first time around. */
3020 switch_to_eh_frame_section (bool back)
3024 #ifdef EH_FRAME_SECTION_NAME
3025 if (eh_frame_section == 0)
3029 if (EH_TABLES_CAN_BE_READ_ONLY)
3035 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3037 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3039 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3041 flags = ((! flag_pic
3042 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3043 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3044 && (per_encoding & 0x70) != DW_EH_PE_absptr
3045 && (per_encoding & 0x70) != DW_EH_PE_aligned
3046 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3047 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3048 ? 0 : SECTION_WRITE);
3051 flags = SECTION_WRITE;
3052 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3054 #endif /* EH_FRAME_SECTION_NAME */
3056 if (eh_frame_section)
3057 switch_to_section (eh_frame_section);
3060 /* We have no special eh_frame section. Put the information in
3061 the data section and emit special labels to guide collect2. */
3062 switch_to_section (data_section);
3066 label = get_file_function_name ("F");
3067 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3068 targetm.asm_out.globalize_label (asm_out_file,
3069 IDENTIFIER_POINTER (label));
3070 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3075 /* Switch [BACK] to the eh or debug frame table section, depending on
3079 switch_to_frame_table_section (int for_eh, bool back)
3082 switch_to_eh_frame_section (back);
3085 if (!debug_frame_section)
3086 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3087 SECTION_DEBUG, NULL);
3088 switch_to_section (debug_frame_section);
3092 /* Output a Call Frame Information opcode and its operand(s). */
3095 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3100 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3101 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3102 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3103 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3104 ((unsigned HOST_WIDE_INT)
3105 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3106 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3108 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3109 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3110 "DW_CFA_offset, column %#lx", r);
3111 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3112 dw2_asm_output_data_uleb128 (off, NULL);
3114 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3116 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3117 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3118 "DW_CFA_restore, column %#lx", r);
3122 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3123 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3125 switch (cfi->dw_cfi_opc)
3127 case DW_CFA_set_loc:
3129 dw2_asm_output_encoded_addr_rtx (
3130 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3131 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3134 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3135 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3136 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3139 case DW_CFA_advance_loc1:
3140 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3141 fde->dw_fde_current_label, NULL);
3142 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3145 case DW_CFA_advance_loc2:
3146 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3147 fde->dw_fde_current_label, NULL);
3148 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3151 case DW_CFA_advance_loc4:
3152 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3153 fde->dw_fde_current_label, NULL);
3154 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3157 case DW_CFA_MIPS_advance_loc8:
3158 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3159 fde->dw_fde_current_label, NULL);
3160 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3163 case DW_CFA_offset_extended:
3164 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3165 dw2_asm_output_data_uleb128 (r, NULL);
3166 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3167 dw2_asm_output_data_uleb128 (off, NULL);
3170 case DW_CFA_def_cfa:
3171 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3172 dw2_asm_output_data_uleb128 (r, NULL);
3173 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3176 case DW_CFA_offset_extended_sf:
3177 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3178 dw2_asm_output_data_uleb128 (r, NULL);
3179 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3180 dw2_asm_output_data_sleb128 (off, NULL);
3183 case DW_CFA_def_cfa_sf:
3184 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3185 dw2_asm_output_data_uleb128 (r, NULL);
3186 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3187 dw2_asm_output_data_sleb128 (off, NULL);
3190 case DW_CFA_restore_extended:
3191 case DW_CFA_undefined:
3192 case DW_CFA_same_value:
3193 case DW_CFA_def_cfa_register:
3194 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3195 dw2_asm_output_data_uleb128 (r, NULL);
3198 case DW_CFA_register:
3199 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3200 dw2_asm_output_data_uleb128 (r, NULL);
3201 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3202 dw2_asm_output_data_uleb128 (r, NULL);
3205 case DW_CFA_def_cfa_offset:
3206 case DW_CFA_GNU_args_size:
3207 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3210 case DW_CFA_def_cfa_offset_sf:
3211 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3212 dw2_asm_output_data_sleb128 (off, NULL);
3215 case DW_CFA_GNU_window_save:
3218 case DW_CFA_def_cfa_expression:
3219 case DW_CFA_expression:
3220 output_cfa_loc (cfi);
3223 case DW_CFA_GNU_negative_offset_extended:
3224 /* Obsoleted by DW_CFA_offset_extended_sf. */
3233 /* Similar, but do it via assembler directives instead. */
3236 output_cfi_directive (dw_cfi_ref cfi)
3238 unsigned long r, r2;
3240 switch (cfi->dw_cfi_opc)
3242 case DW_CFA_advance_loc:
3243 case DW_CFA_advance_loc1:
3244 case DW_CFA_advance_loc2:
3245 case DW_CFA_advance_loc4:
3246 case DW_CFA_MIPS_advance_loc8:
3247 case DW_CFA_set_loc:
3248 /* Should only be created by add_fde_cfi in a code path not
3249 followed when emitting via directives. The assembler is
3250 going to take care of this for us. */
3254 case DW_CFA_offset_extended:
3255 case DW_CFA_offset_extended_sf:
3256 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3257 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3258 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3261 case DW_CFA_restore:
3262 case DW_CFA_restore_extended:
3263 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3264 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3267 case DW_CFA_undefined:
3268 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3269 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3272 case DW_CFA_same_value:
3273 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3274 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3277 case DW_CFA_def_cfa:
3278 case DW_CFA_def_cfa_sf:
3279 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3280 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3281 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3284 case DW_CFA_def_cfa_register:
3285 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3286 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3289 case DW_CFA_register:
3290 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3291 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3292 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3295 case DW_CFA_def_cfa_offset:
3296 case DW_CFA_def_cfa_offset_sf:
3297 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3298 HOST_WIDE_INT_PRINT_DEC"\n",
3299 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3302 case DW_CFA_remember_state:
3303 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3305 case DW_CFA_restore_state:
3306 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3309 case DW_CFA_GNU_args_size:
3310 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3311 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3313 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3314 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3315 fputc ('\n', asm_out_file);
3318 case DW_CFA_GNU_window_save:
3319 fprintf (asm_out_file, "\t.cfi_window_save\n");
3322 case DW_CFA_def_cfa_expression:
3323 case DW_CFA_expression:
3324 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3325 output_cfa_loc_raw (cfi);
3326 fputc ('\n', asm_out_file);
3334 DEF_VEC_P (dw_cfi_ref);
3335 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3337 /* Output CFIs to bring current FDE to the same state as after executing
3338 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3339 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3340 other arguments to pass to output_cfi. */
3343 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3345 struct dw_cfi_struct cfi_buf;
3347 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3348 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3349 unsigned int len, idx;
3351 for (;; cfi = cfi->dw_cfi_next)
3352 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3354 case DW_CFA_advance_loc:
3355 case DW_CFA_advance_loc1:
3356 case DW_CFA_advance_loc2:
3357 case DW_CFA_advance_loc4:
3358 case DW_CFA_MIPS_advance_loc8:
3359 case DW_CFA_set_loc:
3360 /* All advances should be ignored. */
3362 case DW_CFA_remember_state:
3364 dw_cfi_ref args_size = cfi_args_size;
3366 /* Skip everything between .cfi_remember_state and
3367 .cfi_restore_state. */
3368 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3369 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3371 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3374 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3381 cfi_args_size = args_size;
3385 case DW_CFA_GNU_args_size:
3386 cfi_args_size = cfi;
3388 case DW_CFA_GNU_window_save:
3391 case DW_CFA_offset_extended:
3392 case DW_CFA_offset_extended_sf:
3393 case DW_CFA_restore:
3394 case DW_CFA_restore_extended:
3395 case DW_CFA_undefined:
3396 case DW_CFA_same_value:
3397 case DW_CFA_register:
3398 case DW_CFA_val_offset:
3399 case DW_CFA_val_offset_sf:
3400 case DW_CFA_expression:
3401 case DW_CFA_val_expression:
3402 case DW_CFA_GNU_negative_offset_extended:
3403 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3404 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3405 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3406 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3408 case DW_CFA_def_cfa:
3409 case DW_CFA_def_cfa_sf:
3410 case DW_CFA_def_cfa_expression:
3412 cfi_cfa_offset = cfi;
3414 case DW_CFA_def_cfa_register:
3417 case DW_CFA_def_cfa_offset:
3418 case DW_CFA_def_cfa_offset_sf:
3419 cfi_cfa_offset = cfi;
3422 gcc_assert (cfi == NULL);
3424 len = VEC_length (dw_cfi_ref, regs);
3425 for (idx = 0; idx < len; idx++)
3427 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3429 && cfi2->dw_cfi_opc != DW_CFA_restore
3430 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3433 output_cfi_directive (cfi2);
3435 output_cfi (cfi2, fde, for_eh);
3438 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3440 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3442 switch (cfi_cfa_offset->dw_cfi_opc)
3444 case DW_CFA_def_cfa_offset:
3445 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3446 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3448 case DW_CFA_def_cfa_offset_sf:
3449 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3450 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3452 case DW_CFA_def_cfa:
3453 case DW_CFA_def_cfa_sf:
3454 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3455 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3462 else if (cfi_cfa_offset)
3463 cfi_cfa = cfi_cfa_offset;
3467 output_cfi_directive (cfi_cfa);
3469 output_cfi (cfi_cfa, fde, for_eh);
3472 cfi_cfa_offset = NULL;
3474 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3477 output_cfi_directive (cfi_args_size);
3479 output_cfi (cfi_args_size, fde, for_eh);
3481 cfi_args_size = NULL;
3484 VEC_free (dw_cfi_ref, heap, regs);
3487 else if (do_cfi_asm)
3488 output_cfi_directive (cfi);
3490 output_cfi (cfi, fde, for_eh);
3497 /* Output one FDE. */
3500 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3501 char *section_start_label, int fde_encoding, char *augmentation,
3502 bool any_lsda_needed, int lsda_encoding)
3504 const char *begin, *end;
3505 static unsigned int j;
3506 char l1[20], l2[20];
3509 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3511 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3513 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3514 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3515 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3516 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3517 " indicating 64-bit DWARF extension");
3518 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3520 ASM_OUTPUT_LABEL (asm_out_file, l1);
3523 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3525 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3526 debug_frame_section, "FDE CIE offset");
3528 if (!fde->dw_fde_switched_sections)
3530 begin = fde->dw_fde_begin;
3531 end = fde->dw_fde_end;
3535 /* For the first section, prefer dw_fde_begin over
3536 dw_fde_{hot,cold}_section_label, as the latter
3537 might be separated from the real start of the
3538 function by alignment padding. */
3540 begin = fde->dw_fde_begin;
3541 else if (fde->dw_fde_switched_cold_to_hot)
3542 begin = fde->dw_fde_hot_section_label;
3544 begin = fde->dw_fde_unlikely_section_label;
3545 if (second ^ fde->dw_fde_switched_cold_to_hot)
3546 end = fde->dw_fde_unlikely_section_end_label;
3548 end = fde->dw_fde_hot_section_end_label;
3553 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3554 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3555 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3556 "FDE initial location");
3557 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3558 end, begin, "FDE address range");
3562 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3563 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3566 if (augmentation[0])
3568 if (any_lsda_needed)
3570 int size = size_of_encoded_value (lsda_encoding);
3572 if (lsda_encoding == DW_EH_PE_aligned)
3574 int offset = ( 4 /* Length */
3575 + 4 /* CIE offset */
3576 + 2 * size_of_encoded_value (fde_encoding)
3577 + 1 /* Augmentation size */ );
3578 int pad = -offset & (PTR_SIZE - 1);
3581 gcc_assert (size_of_uleb128 (size) == 1);
3584 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3586 if (fde->uses_eh_lsda)
3588 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3589 fde->funcdef_number);
3590 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3591 gen_rtx_SYMBOL_REF (Pmode, l1),
3593 "Language Specific Data Area");
3597 if (lsda_encoding == DW_EH_PE_aligned)
3598 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3599 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3600 "Language Specific Data Area (none)");
3604 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3607 /* Loop through the Call Frame Instructions associated with
3609 fde->dw_fde_current_label = begin;
3610 if (!fde->dw_fde_switched_sections)
3611 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3612 output_cfi (cfi, fde, for_eh);
3615 if (fde->dw_fde_switch_cfi)
3616 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3618 output_cfi (cfi, fde, for_eh);
3619 if (cfi == fde->dw_fde_switch_cfi)
3625 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3627 if (fde->dw_fde_switch_cfi)
3629 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3630 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3631 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3632 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3634 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3635 output_cfi (cfi, fde, for_eh);
3638 /* If we are to emit a ref/link from function bodies to their frame tables,
3639 do it now. This is typically performed to make sure that tables
3640 associated with functions are dragged with them and not discarded in
3641 garbage collecting links. We need to do this on a per function basis to
3642 cope with -ffunction-sections. */
3644 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3645 /* Switch to the function section, emit the ref to the tables, and
3646 switch *back* into the table section. */
3647 switch_to_section (function_section (fde->decl));
3648 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3649 switch_to_frame_table_section (for_eh, true);
3652 /* Pad the FDE out to an address sized boundary. */
3653 ASM_OUTPUT_ALIGN (asm_out_file,
3654 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3655 ASM_OUTPUT_LABEL (asm_out_file, l2);
3660 /* Return true if frame description entry FDE is needed for EH. */
3663 fde_needed_for_eh_p (dw_fde_ref fde)
3665 if (flag_asynchronous_unwind_tables)
3668 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3671 if (fde->uses_eh_lsda)
3674 /* If exceptions are enabled, we have collected nothrow info. */
3675 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3681 /* Output the call frame information used to record information
3682 that relates to calculating the frame pointer, and records the
3683 location of saved registers. */
3686 output_call_frame_info (int for_eh)
3691 char l1[20], l2[20], section_start_label[20];
3692 bool any_lsda_needed = false;
3693 char augmentation[6];
3694 int augmentation_size;
3695 int fde_encoding = DW_EH_PE_absptr;
3696 int per_encoding = DW_EH_PE_absptr;
3697 int lsda_encoding = DW_EH_PE_absptr;
3699 rtx personality = NULL;
3702 /* Don't emit a CIE if there won't be any FDEs. */
3703 if (fde_table_in_use == 0)
3706 /* Nothing to do if the assembler's doing it all. */
3707 if (dwarf2out_do_cfi_asm ())
3710 /* If we don't have any functions we'll want to unwind out of, don't emit
3711 any EH unwind information. If we make FDEs linkonce, we may have to
3712 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3713 want to avoid having an FDE kept around when the function it refers to
3714 is discarded. Example where this matters: a primary function template
3715 in C++ requires EH information, an explicit specialization doesn't. */
3718 bool any_eh_needed = false;
3720 for (i = 0; i < fde_table_in_use; i++)
3721 if (fde_table[i].uses_eh_lsda)
3722 any_eh_needed = any_lsda_needed = true;
3723 else if (fde_needed_for_eh_p (&fde_table[i]))
3724 any_eh_needed = true;
3725 else if (TARGET_USES_WEAK_UNWIND_INFO)
3726 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3733 /* We're going to be generating comments, so turn on app. */
3737 /* Switch to the proper frame section, first time. */
3738 switch_to_frame_table_section (for_eh, false);
3740 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3741 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3743 /* Output the CIE. */
3744 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3745 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3746 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3747 dw2_asm_output_data (4, 0xffffffff,
3748 "Initial length escape value indicating 64-bit DWARF extension");
3749 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3750 "Length of Common Information Entry");
3751 ASM_OUTPUT_LABEL (asm_out_file, l1);
3753 /* Now that the CIE pointer is PC-relative for EH,
3754 use 0 to identify the CIE. */
3755 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3756 (for_eh ? 0 : DWARF_CIE_ID),
3757 "CIE Identifier Tag");
3759 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3760 use CIE version 1, unless that would produce incorrect results
3761 due to overflowing the return register column. */
3762 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3764 if (return_reg >= 256 || dwarf_version > 2)
3766 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3768 augmentation[0] = 0;
3769 augmentation_size = 0;
3771 personality = current_unit_personality;
3777 z Indicates that a uleb128 is present to size the
3778 augmentation section.
3779 L Indicates the encoding (and thus presence) of
3780 an LSDA pointer in the FDE augmentation.
3781 R Indicates a non-default pointer encoding for
3783 P Indicates the presence of an encoding + language
3784 personality routine in the CIE augmentation. */
3786 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3787 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3788 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3790 p = augmentation + 1;
3794 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3795 assemble_external_libcall (personality);
3797 if (any_lsda_needed)
3800 augmentation_size += 1;
3802 if (fde_encoding != DW_EH_PE_absptr)
3805 augmentation_size += 1;
3807 if (p > augmentation + 1)
3809 augmentation[0] = 'z';
3813 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3814 if (personality && per_encoding == DW_EH_PE_aligned)
3816 int offset = ( 4 /* Length */
3818 + 1 /* CIE version */
3819 + strlen (augmentation) + 1 /* Augmentation */
3820 + size_of_uleb128 (1) /* Code alignment */
3821 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3823 + 1 /* Augmentation size */
3824 + 1 /* Personality encoding */ );
3825 int pad = -offset & (PTR_SIZE - 1);
3827 augmentation_size += pad;
3829 /* Augmentations should be small, so there's scarce need to
3830 iterate for a solution. Die if we exceed one uleb128 byte. */
3831 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3835 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3836 if (dw_cie_version >= 4)
3838 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3839 dw2_asm_output_data (1, 0, "CIE Segment Size");
3841 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3842 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3843 "CIE Data Alignment Factor");
3845 if (dw_cie_version == 1)
3846 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3848 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3850 if (augmentation[0])
3852 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3855 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3856 eh_data_format_name (per_encoding));
3857 dw2_asm_output_encoded_addr_rtx (per_encoding,
3862 if (any_lsda_needed)
3863 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3864 eh_data_format_name (lsda_encoding));
3866 if (fde_encoding != DW_EH_PE_absptr)
3867 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3868 eh_data_format_name (fde_encoding));
3871 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3872 output_cfi (cfi, NULL, for_eh);
3874 /* Pad the CIE out to an address sized boundary. */
3875 ASM_OUTPUT_ALIGN (asm_out_file,
3876 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3877 ASM_OUTPUT_LABEL (asm_out_file, l2);
3879 /* Loop through all of the FDE's. */
3880 for (i = 0; i < fde_table_in_use; i++)
3883 fde = &fde_table[i];
3885 /* Don't emit EH unwind info for leaf functions that don't need it. */
3886 if (for_eh && !fde_needed_for_eh_p (fde))
3889 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3890 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3891 augmentation, any_lsda_needed, lsda_encoding);
3894 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3895 dw2_asm_output_data (4, 0, "End of Table");
3896 #ifdef MIPS_DEBUGGING_INFO
3897 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3898 get a value of 0. Putting .align 0 after the label fixes it. */
3899 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3902 /* Turn off app to make assembly quicker. */
3907 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3910 dwarf2out_do_cfi_startproc (bool second)
3914 rtx personality = get_personality_function (current_function_decl);
3916 fprintf (asm_out_file, "\t.cfi_startproc\n");
3920 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3923 /* ??? The GAS support isn't entirely consistent. We have to
3924 handle indirect support ourselves, but PC-relative is done
3925 in the assembler. Further, the assembler can't handle any
3926 of the weirder relocation types. */
3927 if (enc & DW_EH_PE_indirect)
3928 ref = dw2_force_const_mem (ref, true);
3930 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
3931 output_addr_const (asm_out_file, ref);
3932 fputc ('\n', asm_out_file);
3935 if (crtl->uses_eh_lsda)
3939 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3940 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
3941 current_function_funcdef_no);
3942 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3943 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3945 if (enc & DW_EH_PE_indirect)
3946 ref = dw2_force_const_mem (ref, true);
3948 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
3949 output_addr_const (asm_out_file, ref);
3950 fputc ('\n', asm_out_file);
3954 /* Output a marker (i.e. a label) for the beginning of a function, before
3958 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3959 const char *file ATTRIBUTE_UNUSED)
3961 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3966 current_function_func_begin_label = NULL;
3968 #ifdef TARGET_UNWIND_INFO
3969 /* ??? current_function_func_begin_label is also used by except.c
3970 for call-site information. We must emit this label if it might
3972 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3973 && ! dwarf2out_do_frame ())
3976 if (! dwarf2out_do_frame ())
3980 fnsec = function_section (current_function_decl);
3981 switch_to_section (fnsec);
3982 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3983 current_function_funcdef_no);
3984 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3985 current_function_funcdef_no);
3986 dup_label = xstrdup (label);
3987 current_function_func_begin_label = dup_label;
3989 #ifdef TARGET_UNWIND_INFO
3990 /* We can elide the fde allocation if we're not emitting debug info. */
3991 if (! dwarf2out_do_frame ())
3995 /* Expand the fde table if necessary. */
3996 if (fde_table_in_use == fde_table_allocated)
3998 fde_table_allocated += FDE_TABLE_INCREMENT;
3999 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4000 memset (fde_table + fde_table_in_use, 0,
4001 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4004 /* Record the FDE associated with this function. */
4005 current_funcdef_fde = fde_table_in_use;
4007 /* Add the new FDE at the end of the fde_table. */
4008 fde = &fde_table[fde_table_in_use++];
4009 fde->decl = current_function_decl;
4010 fde->dw_fde_begin = dup_label;
4011 fde->dw_fde_current_label = dup_label;
4012 fde->dw_fde_hot_section_label = NULL;
4013 fde->dw_fde_hot_section_end_label = NULL;
4014 fde->dw_fde_unlikely_section_label = NULL;
4015 fde->dw_fde_unlikely_section_end_label = NULL;
4016 fde->dw_fde_switched_sections = 0;
4017 fde->dw_fde_switched_cold_to_hot = 0;
4018 fde->dw_fde_end = NULL;
4019 fde->dw_fde_vms_end_prologue = NULL;
4020 fde->dw_fde_vms_begin_epilogue = NULL;
4021 fde->dw_fde_cfi = NULL;
4022 fde->dw_fde_switch_cfi = NULL;
4023 fde->funcdef_number = current_function_funcdef_no;
4024 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4025 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4026 fde->nothrow = crtl->nothrow;
4027 fde->drap_reg = INVALID_REGNUM;
4028 fde->vdrap_reg = INVALID_REGNUM;
4029 if (flag_reorder_blocks_and_partition)
4031 section *unlikelysec;
4032 if (first_function_block_is_cold)
4033 fde->in_std_section = 1;
4036 = (fnsec == text_section
4037 || (cold_text_section && fnsec == cold_text_section));
4038 unlikelysec = unlikely_text_section ();
4039 fde->cold_in_std_section
4040 = (unlikelysec == text_section
4041 || (cold_text_section && unlikelysec == cold_text_section));
4046 = (fnsec == text_section
4047 || (cold_text_section && fnsec == cold_text_section));
4048 fde->cold_in_std_section = 0;
4051 args_size = old_args_size = 0;
4053 /* We only want to output line number information for the genuine dwarf2
4054 prologue case, not the eh frame case. */
4055 #ifdef DWARF2_DEBUGGING_INFO
4057 dwarf2out_source_line (line, file, 0, true);
4060 if (dwarf2out_do_cfi_asm ())
4061 dwarf2out_do_cfi_startproc (false);
4064 rtx personality = get_personality_function (current_function_decl);
4065 if (!current_unit_personality)
4066 current_unit_personality = personality;
4068 /* We cannot keep a current personality per function as without CFI
4069 asm, at the point where we emit the CFI data, there is no current
4070 function anymore. */
4071 if (personality && current_unit_personality != personality)
4072 sorry ("multiple EH personalities are supported only with assemblers "
4073 "supporting .cfi_personality directive");
4077 /* Output a marker (i.e. a label) for the end of the generated code
4078 for a function prologue. This gets called *after* the prologue code has
4082 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4083 const char *file ATTRIBUTE_UNUSED)
4086 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4088 /* Output a label to mark the endpoint of the code generated for this
4090 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4091 current_function_funcdef_no);
4092 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4093 current_function_funcdef_no);
4094 fde = &fde_table[fde_table_in_use - 1];
4095 fde->dw_fde_vms_end_prologue = xstrdup (label);
4098 /* Output a marker (i.e. a label) for the beginning of the generated code
4099 for a function epilogue. This gets called *before* the prologue code has
4103 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4104 const char *file ATTRIBUTE_UNUSED)
4107 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4109 fde = &fde_table[fde_table_in_use - 1];
4110 if (fde->dw_fde_vms_begin_epilogue)
4113 /* Output a label to mark the endpoint of the code generated for this
4115 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4116 current_function_funcdef_no);
4117 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4118 current_function_funcdef_no);
4119 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4122 /* Output a marker (i.e. a label) for the absolute end of the generated code
4123 for a function definition. This gets called *after* the epilogue code has
4127 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4128 const char *file ATTRIBUTE_UNUSED)
4131 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4133 last_var_location_insn = NULL_RTX;
4135 if (dwarf2out_do_cfi_asm ())
4136 fprintf (asm_out_file, "\t.cfi_endproc\n");
4138 /* Output a label to mark the endpoint of the code generated for this
4140 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4141 current_function_funcdef_no);
4142 ASM_OUTPUT_LABEL (asm_out_file, label);
4143 fde = current_fde ();
4144 gcc_assert (fde != NULL);
4145 fde->dw_fde_end = xstrdup (label);
4149 dwarf2out_frame_init (void)
4151 /* Allocate the initial hunk of the fde_table. */
4152 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4153 fde_table_allocated = FDE_TABLE_INCREMENT;
4154 fde_table_in_use = 0;
4156 /* Generate the CFA instructions common to all FDE's. Do it now for the
4157 sake of lookup_cfa. */
4159 /* On entry, the Canonical Frame Address is at SP. */
4160 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4162 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
4163 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4167 dwarf2out_frame_finish (void)
4169 /* Output call frame information. */
4170 if (DWARF2_FRAME_INFO)
4171 output_call_frame_info (0);
4173 #ifndef TARGET_UNWIND_INFO
4174 /* Output another copy for the unwinder. */
4175 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
4176 output_call_frame_info (1);
4180 /* Note that the current function section is being used for code. */
4183 dwarf2out_note_section_used (void)
4185 section *sec = current_function_section ();
4186 if (sec == text_section)
4187 text_section_used = true;
4188 else if (sec == cold_text_section)
4189 cold_text_section_used = true;
4193 dwarf2out_switch_text_section (void)
4195 dw_fde_ref fde = current_fde ();
4197 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4199 fde->dw_fde_switched_sections = 1;
4200 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4202 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4203 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4204 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4205 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4206 have_multiple_function_sections = true;
4208 /* Reset the current label on switching text sections, so that we
4209 don't attempt to advance_loc4 between labels in different sections. */
4210 fde->dw_fde_current_label = NULL;
4212 /* There is no need to mark used sections when not debugging. */
4213 if (cold_text_section != NULL)
4214 dwarf2out_note_section_used ();
4216 if (dwarf2out_do_cfi_asm ())
4217 fprintf (asm_out_file, "\t.cfi_endproc\n");
4219 /* Now do the real section switch. */
4220 switch_to_section (current_function_section ());
4222 if (dwarf2out_do_cfi_asm ())
4224 dwarf2out_do_cfi_startproc (true);
4225 /* As this is a different FDE, insert all current CFI instructions
4227 output_cfis (fde->dw_fde_cfi, true, fde, true);
4231 dw_cfi_ref cfi = fde->dw_fde_cfi;
4233 cfi = fde->dw_fde_cfi;
4235 while (cfi->dw_cfi_next != NULL)
4236 cfi = cfi->dw_cfi_next;
4237 fde->dw_fde_switch_cfi = cfi;
4241 /* And now, the subset of the debugging information support code necessary
4242 for emitting location expressions. */
4244 /* Data about a single source file. */
4245 struct GTY(()) dwarf_file_data {
4246 const char * filename;
4250 typedef struct dw_val_struct *dw_val_ref;
4251 typedef struct die_struct *dw_die_ref;
4252 typedef const struct die_struct *const_dw_die_ref;
4253 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4254 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4256 typedef struct GTY(()) deferred_locations_struct
4260 } deferred_locations;
4262 DEF_VEC_O(deferred_locations);
4263 DEF_VEC_ALLOC_O(deferred_locations,gc);
4265 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4267 DEF_VEC_P(dw_die_ref);
4268 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4270 /* Each DIE may have a series of attribute/value pairs. Values
4271 can take on several forms. The forms that are used in this
4272 implementation are listed below. */
4277 dw_val_class_offset,
4279 dw_val_class_loc_list,
4280 dw_val_class_range_list,
4282 dw_val_class_unsigned_const,
4283 dw_val_class_const_double,
4286 dw_val_class_die_ref,
4287 dw_val_class_fde_ref,
4288 dw_val_class_lbl_id,
4289 dw_val_class_lineptr,
4291 dw_val_class_macptr,
4294 dw_val_class_vms_delta
4297 /* Describe a floating point constant value, or a vector constant value. */
4299 typedef struct GTY(()) dw_vec_struct {
4300 unsigned char * GTY((length ("%h.length"))) array;
4306 /* The dw_val_node describes an attribute's value, as it is
4307 represented internally. */
4309 typedef struct GTY(()) dw_val_struct {
4310 enum dw_val_class val_class;
4311 union dw_val_struct_union
4313 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4314 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4315 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4316 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4317 HOST_WIDE_INT GTY ((default)) val_int;
4318 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4319 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4320 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4321 struct dw_val_die_union
4325 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4326 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4327 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4328 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4329 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4330 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4331 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4332 struct dw_val_vms_delta_union
4336 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4338 GTY ((desc ("%1.val_class"))) v;
4342 /* Locations in memory are described using a sequence of stack machine
4345 typedef struct GTY(()) dw_loc_descr_struct {
4346 dw_loc_descr_ref dw_loc_next;
4347 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4348 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4349 from DW_OP_addr with a dtp-relative symbol relocation. */
4350 unsigned int dtprel : 1;
4352 dw_val_node dw_loc_oprnd1;
4353 dw_val_node dw_loc_oprnd2;
4357 /* Location lists are ranges + location descriptions for that range,
4358 so you can track variables that are in different places over
4359 their entire life. */
4360 typedef struct GTY(()) dw_loc_list_struct {
4361 dw_loc_list_ref dw_loc_next;
4362 const char *begin; /* Label for begin address of range */
4363 const char *end; /* Label for end address of range */
4364 char *ll_symbol; /* Label for beginning of location list.
4365 Only on head of list */
4366 const char *section; /* Section this loclist is relative to */
4367 dw_loc_descr_ref expr;
4370 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4372 /* Convert a DWARF stack opcode into its string name. */
4375 dwarf_stack_op_name (unsigned int op)
4380 return "DW_OP_addr";
4382 return "DW_OP_deref";
4384 return "DW_OP_const1u";
4386 return "DW_OP_const1s";
4388 return "DW_OP_const2u";
4390 return "DW_OP_const2s";
4392 return "DW_OP_const4u";
4394 return "DW_OP_const4s";
4396 return "DW_OP_const8u";
4398 return "DW_OP_const8s";
4400 return "DW_OP_constu";
4402 return "DW_OP_consts";
4406 return "DW_OP_drop";
4408 return "DW_OP_over";
4410 return "DW_OP_pick";
4412 return "DW_OP_swap";
4416 return "DW_OP_xderef";
4424 return "DW_OP_minus";
4436 return "DW_OP_plus";
4437 case DW_OP_plus_uconst:
4438 return "DW_OP_plus_uconst";
4444 return "DW_OP_shra";
4462 return "DW_OP_skip";
4464 return "DW_OP_lit0";
4466 return "DW_OP_lit1";
4468 return "DW_OP_lit2";
4470 return "DW_OP_lit3";
4472 return "DW_OP_lit4";
4474 return "DW_OP_lit5";
4476 return "DW_OP_lit6";
4478 return "DW_OP_lit7";
4480 return "DW_OP_lit8";
4482 return "DW_OP_lit9";
4484 return "DW_OP_lit10";
4486 return "DW_OP_lit11";
4488 return "DW_OP_lit12";
4490 return "DW_OP_lit13";
4492 return "DW_OP_lit14";
4494 return "DW_OP_lit15";
4496 return "DW_OP_lit16";
4498 return "DW_OP_lit17";
4500 return "DW_OP_lit18";
4502 return "DW_OP_lit19";
4504 return "DW_OP_lit20";
4506 return "DW_OP_lit21";
4508 return "DW_OP_lit22";
4510 return "DW_OP_lit23";
4512 return "DW_OP_lit24";
4514 return "DW_OP_lit25";
4516 return "DW_OP_lit26";
4518 return "DW_OP_lit27";
4520 return "DW_OP_lit28";
4522 return "DW_OP_lit29";
4524 return "DW_OP_lit30";
4526 return "DW_OP_lit31";
4528 return "DW_OP_reg0";
4530 return "DW_OP_reg1";
4532 return "DW_OP_reg2";
4534 return "DW_OP_reg3";
4536 return "DW_OP_reg4";
4538 return "DW_OP_reg5";
4540 return "DW_OP_reg6";
4542 return "DW_OP_reg7";
4544 return "DW_OP_reg8";
4546 return "DW_OP_reg9";
4548 return "DW_OP_reg10";
4550 return "DW_OP_reg11";
4552 return "DW_OP_reg12";
4554 return "DW_OP_reg13";
4556 return "DW_OP_reg14";
4558 return "DW_OP_reg15";
4560 return "DW_OP_reg16";
4562 return "DW_OP_reg17";
4564 return "DW_OP_reg18";
4566 return "DW_OP_reg19";
4568 return "DW_OP_reg20";
4570 return "DW_OP_reg21";
4572 return "DW_OP_reg22";
4574 return "DW_OP_reg23";
4576 return "DW_OP_reg24";
4578 return "DW_OP_reg25";
4580 return "DW_OP_reg26";
4582 return "DW_OP_reg27";
4584 return "DW_OP_reg28";
4586 return "DW_OP_reg29";
4588 return "DW_OP_reg30";
4590 return "DW_OP_reg31";
4592 return "DW_OP_breg0";
4594 return "DW_OP_breg1";
4596 return "DW_OP_breg2";
4598 return "DW_OP_breg3";
4600 return "DW_OP_breg4";
4602 return "DW_OP_breg5";
4604 return "DW_OP_breg6";
4606 return "DW_OP_breg7";
4608 return "DW_OP_breg8";
4610 return "DW_OP_breg9";
4612 return "DW_OP_breg10";
4614 return "DW_OP_breg11";
4616 return "DW_OP_breg12";
4618 return "DW_OP_breg13";
4620 return "DW_OP_breg14";
4622 return "DW_OP_breg15";
4624 return "DW_OP_breg16";
4626 return "DW_OP_breg17";
4628 return "DW_OP_breg18";
4630 return "DW_OP_breg19";
4632 return "DW_OP_breg20";
4634 return "DW_OP_breg21";
4636 return "DW_OP_breg22";
4638 return "DW_OP_breg23";
4640 return "DW_OP_breg24";
4642 return "DW_OP_breg25";
4644 return "DW_OP_breg26";
4646 return "DW_OP_breg27";
4648 return "DW_OP_breg28";
4650 return "DW_OP_breg29";
4652 return "DW_OP_breg30";
4654 return "DW_OP_breg31";
4656 return "DW_OP_regx";
4658 return "DW_OP_fbreg";
4660 return "DW_OP_bregx";
4662 return "DW_OP_piece";
4663 case DW_OP_deref_size:
4664 return "DW_OP_deref_size";
4665 case DW_OP_xderef_size:
4666 return "DW_OP_xderef_size";
4670 case DW_OP_push_object_address:
4671 return "DW_OP_push_object_address";
4673 return "DW_OP_call2";
4675 return "DW_OP_call4";
4676 case DW_OP_call_ref:
4677 return "DW_OP_call_ref";
4678 case DW_OP_implicit_value:
4679 return "DW_OP_implicit_value";
4680 case DW_OP_stack_value:
4681 return "DW_OP_stack_value";
4682 case DW_OP_form_tls_address:
4683 return "DW_OP_form_tls_address";
4684 case DW_OP_call_frame_cfa:
4685 return "DW_OP_call_frame_cfa";
4686 case DW_OP_bit_piece:
4687 return "DW_OP_bit_piece";
4689 case DW_OP_GNU_push_tls_address:
4690 return "DW_OP_GNU_push_tls_address";
4691 case DW_OP_GNU_uninit:
4692 return "DW_OP_GNU_uninit";
4693 case DW_OP_GNU_encoded_addr:
4694 return "DW_OP_GNU_encoded_addr";
4697 return "OP_<unknown>";
4701 /* Return a pointer to a newly allocated location description. Location
4702 descriptions are simple expression terms that can be strung
4703 together to form more complicated location (address) descriptions. */
4705 static inline dw_loc_descr_ref
4706 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4707 unsigned HOST_WIDE_INT oprnd2)
4709 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4711 descr->dw_loc_opc = op;
4712 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4713 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4714 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4715 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4720 /* Return a pointer to a newly allocated location description for
4723 static inline dw_loc_descr_ref
4724 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4727 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4730 return new_loc_descr (DW_OP_bregx, reg, offset);
4733 /* Add a location description term to a location description expression. */
4736 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4738 dw_loc_descr_ref *d;
4740 /* Find the end of the chain. */
4741 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4747 /* Add a constant OFFSET to a location expression. */
4750 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4752 dw_loc_descr_ref loc;
4755 gcc_assert (*list_head != NULL);
4760 /* Find the end of the chain. */
4761 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4765 if (loc->dw_loc_opc == DW_OP_fbreg
4766 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4767 p = &loc->dw_loc_oprnd1.v.val_int;
4768 else if (loc->dw_loc_opc == DW_OP_bregx)
4769 p = &loc->dw_loc_oprnd2.v.val_int;
4771 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4772 offset. Don't optimize if an signed integer overflow would happen. */
4774 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4775 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4778 else if (offset > 0)
4779 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4783 loc->dw_loc_next = int_loc_descriptor (-offset);
4784 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4788 /* Add a constant OFFSET to a location list. */
4791 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4794 for (d = list_head; d != NULL; d = d->dw_loc_next)
4795 loc_descr_plus_const (&d->expr, offset);
4798 /* Return the size of a location descriptor. */
4800 static unsigned long
4801 size_of_loc_descr (dw_loc_descr_ref loc)
4803 unsigned long size = 1;
4805 switch (loc->dw_loc_opc)
4808 size += DWARF2_ADDR_SIZE;
4827 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4830 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4835 case DW_OP_plus_uconst:
4836 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4874 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4877 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4880 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4883 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4884 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4887 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4889 case DW_OP_bit_piece:
4890 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4891 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
4893 case DW_OP_deref_size:
4894 case DW_OP_xderef_size:
4903 case DW_OP_call_ref:
4904 size += DWARF2_ADDR_SIZE;
4906 case DW_OP_implicit_value:
4907 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4908 + loc->dw_loc_oprnd1.v.val_unsigned;
4917 /* Return the size of a series of location descriptors. */
4919 static unsigned long
4920 size_of_locs (dw_loc_descr_ref loc)
4925 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4926 field, to avoid writing to a PCH file. */
4927 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4929 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4931 size += size_of_loc_descr (l);
4936 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4938 l->dw_loc_addr = size;
4939 size += size_of_loc_descr (l);
4945 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4947 /* Output location description stack opcode's operands (if any). */
4950 output_loc_operands (dw_loc_descr_ref loc)
4952 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4953 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4955 switch (loc->dw_loc_opc)
4957 #ifdef DWARF2_DEBUGGING_INFO
4960 dw2_asm_output_data (2, val1->v.val_int, NULL);
4965 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
4966 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
4968 fputc ('\n', asm_out_file);
4973 dw2_asm_output_data (4, val1->v.val_int, NULL);
4978 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
4979 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
4981 fputc ('\n', asm_out_file);
4986 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
4987 dw2_asm_output_data (8, val1->v.val_int, NULL);
4994 gcc_assert (val1->val_class == dw_val_class_loc);
4995 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4997 dw2_asm_output_data (2, offset, NULL);
5000 case DW_OP_implicit_value:
5001 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5002 switch (val2->val_class)
5004 case dw_val_class_const:
5005 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5007 case dw_val_class_vec:
5009 unsigned int elt_size = val2->v.val_vec.elt_size;
5010 unsigned int len = val2->v.val_vec.length;
5014 if (elt_size > sizeof (HOST_WIDE_INT))
5019 for (i = 0, p = val2->v.val_vec.array;
5022 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5023 "fp or vector constant word %u", i);
5026 case dw_val_class_const_double:
5028 unsigned HOST_WIDE_INT first, second;
5030 if (WORDS_BIG_ENDIAN)
5032 first = val2->v.val_double.high;
5033 second = val2->v.val_double.low;
5037 first = val2->v.val_double.low;
5038 second = val2->v.val_double.high;
5040 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5042 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5046 case dw_val_class_addr:
5047 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5048 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5063 case DW_OP_implicit_value:
5064 /* We currently don't make any attempt to make sure these are
5065 aligned properly like we do for the main unwind info, so
5066 don't support emitting things larger than a byte if we're
5067 only doing unwinding. */
5072 dw2_asm_output_data (1, val1->v.val_int, NULL);
5075 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5078 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5081 dw2_asm_output_data (1, val1->v.val_int, NULL);
5083 case DW_OP_plus_uconst:
5084 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5118 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5121 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5124 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5127 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5128 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5131 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5133 case DW_OP_bit_piece:
5134 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5135 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5137 case DW_OP_deref_size:
5138 case DW_OP_xderef_size:
5139 dw2_asm_output_data (1, val1->v.val_int, NULL);
5145 if (targetm.asm_out.output_dwarf_dtprel)
5147 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5150 fputc ('\n', asm_out_file);
5157 #ifdef DWARF2_DEBUGGING_INFO
5158 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5166 /* Other codes have no operands. */
5171 /* Output a sequence of location operations. */
5174 output_loc_sequence (dw_loc_descr_ref loc)
5176 for (; loc != NULL; loc = loc->dw_loc_next)
5178 /* Output the opcode. */
5179 dw2_asm_output_data (1, loc->dw_loc_opc,
5180 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
5182 /* Output the operand(s) (if any). */
5183 output_loc_operands (loc);
5187 /* Output location description stack opcode's operands (if any).
5188 The output is single bytes on a line, suitable for .cfi_escape. */
5191 output_loc_operands_raw (dw_loc_descr_ref loc)
5193 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5194 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5196 switch (loc->dw_loc_opc)
5199 case DW_OP_implicit_value:
5200 /* We cannot output addresses in .cfi_escape, only bytes. */
5206 case DW_OP_deref_size:
5207 case DW_OP_xderef_size:
5208 fputc (',', asm_out_file);
5209 dw2_asm_output_data_raw (1, val1->v.val_int);
5214 fputc (',', asm_out_file);
5215 dw2_asm_output_data_raw (2, val1->v.val_int);
5220 fputc (',', asm_out_file);
5221 dw2_asm_output_data_raw (4, val1->v.val_int);
5226 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5227 fputc (',', asm_out_file);
5228 dw2_asm_output_data_raw (8, val1->v.val_int);
5236 gcc_assert (val1->val_class == dw_val_class_loc);
5237 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5239 fputc (',', asm_out_file);
5240 dw2_asm_output_data_raw (2, offset);
5245 case DW_OP_plus_uconst:
5248 fputc (',', asm_out_file);
5249 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5252 case DW_OP_bit_piece:
5253 fputc (',', asm_out_file);
5254 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5255 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5292 fputc (',', asm_out_file);
5293 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5297 fputc (',', asm_out_file);
5298 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5299 fputc (',', asm_out_file);
5300 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5304 /* Other codes have no operands. */
5310 output_loc_sequence_raw (dw_loc_descr_ref loc)
5314 /* Output the opcode. */
5315 fprintf (asm_out_file, "%#x", loc->dw_loc_opc);
5316 output_loc_operands_raw (loc);
5318 if (!loc->dw_loc_next)
5320 loc = loc->dw_loc_next;
5322 fputc (',', asm_out_file);
5326 /* This routine will generate the correct assembly data for a location
5327 description based on a cfi entry with a complex address. */
5330 output_cfa_loc (dw_cfi_ref cfi)
5332 dw_loc_descr_ref loc;
5335 if (cfi->dw_cfi_opc == DW_CFA_expression)
5337 dw2_asm_output_data (1, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
5338 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5341 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5343 /* Output the size of the block. */
5344 size = size_of_locs (loc);
5345 dw2_asm_output_data_uleb128 (size, NULL);
5347 /* Now output the operations themselves. */
5348 output_loc_sequence (loc);
5351 /* Similar, but used for .cfi_escape. */
5354 output_cfa_loc_raw (dw_cfi_ref cfi)
5356 dw_loc_descr_ref loc;
5359 if (cfi->dw_cfi_opc == DW_CFA_expression)
5361 fprintf (asm_out_file, "%#x,", cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
5362 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5365 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5367 /* Output the size of the block. */
5368 size = size_of_locs (loc);
5369 dw2_asm_output_data_uleb128_raw (size);
5370 fputc (',', asm_out_file);
5372 /* Now output the operations themselves. */
5373 output_loc_sequence_raw (loc);
5376 /* This function builds a dwarf location descriptor sequence from a
5377 dw_cfa_location, adding the given OFFSET to the result of the
5380 static struct dw_loc_descr_struct *
5381 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5383 struct dw_loc_descr_struct *head, *tmp;
5385 offset += cfa->offset;
5389 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5390 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5391 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5392 add_loc_descr (&head, tmp);
5395 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5396 add_loc_descr (&head, tmp);
5400 head = new_reg_loc_descr (cfa->reg, offset);
5405 /* This function builds a dwarf location descriptor sequence for
5406 the address at OFFSET from the CFA when stack is aligned to
5409 static struct dw_loc_descr_struct *
5410 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5412 struct dw_loc_descr_struct *head;
5413 unsigned int dwarf_fp
5414 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5416 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5417 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5419 head = new_reg_loc_descr (dwarf_fp, 0);
5420 add_loc_descr (&head, int_loc_descriptor (alignment));
5421 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5422 loc_descr_plus_const (&head, offset);
5425 head = new_reg_loc_descr (dwarf_fp, offset);
5429 /* This function fills in aa dw_cfa_location structure from a dwarf location
5430 descriptor sequence. */
5433 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5435 struct dw_loc_descr_struct *ptr;
5437 cfa->base_offset = 0;
5441 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5443 enum dwarf_location_atom op = ptr->dw_loc_opc;
5479 cfa->reg = op - DW_OP_reg0;
5482 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5516 cfa->reg = op - DW_OP_breg0;
5517 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5520 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5521 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5526 case DW_OP_plus_uconst:
5527 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5530 internal_error ("DW_LOC_OP %s not implemented",
5531 dwarf_stack_op_name (ptr->dw_loc_opc));
5536 /* And now, the support for symbolic debugging information. */
5538 /* .debug_str support. */
5539 static int output_indirect_string (void **, void *);
5541 static void dwarf2out_init (const char *);
5542 static void dwarf2out_finish (const char *);
5543 static void dwarf2out_assembly_start (void);
5544 static void dwarf2out_define (unsigned int, const char *);
5545 static void dwarf2out_undef (unsigned int, const char *);
5546 static void dwarf2out_start_source_file (unsigned, const char *);
5547 static void dwarf2out_end_source_file (unsigned);
5548 static void dwarf2out_function_decl (tree);
5549 static void dwarf2out_begin_block (unsigned, unsigned);
5550 static void dwarf2out_end_block (unsigned, unsigned);
5551 static bool dwarf2out_ignore_block (const_tree);
5552 static void dwarf2out_global_decl (tree);
5553 static void dwarf2out_type_decl (tree, int);
5554 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5555 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5557 static void dwarf2out_abstract_function (tree);
5558 static void dwarf2out_var_location (rtx);
5559 static void dwarf2out_direct_call (tree);
5560 static void dwarf2out_virtual_call_token (tree, int);
5561 static void dwarf2out_copy_call_info (rtx, rtx);
5562 static void dwarf2out_virtual_call (int);
5563 static void dwarf2out_begin_function (tree);
5564 static void dwarf2out_set_name (tree, tree);
5566 /* The debug hooks structure. */
5568 const struct gcc_debug_hooks dwarf2_debug_hooks =
5572 dwarf2out_assembly_start,
5575 dwarf2out_start_source_file,
5576 dwarf2out_end_source_file,
5577 dwarf2out_begin_block,
5578 dwarf2out_end_block,
5579 dwarf2out_ignore_block,
5580 dwarf2out_source_line,
5581 dwarf2out_begin_prologue,
5582 #if VMS_DEBUGGING_INFO
5583 dwarf2out_vms_end_prologue,
5584 dwarf2out_vms_begin_epilogue,
5586 debug_nothing_int_charstar,
5587 debug_nothing_int_charstar,
5589 dwarf2out_end_epilogue,
5590 dwarf2out_begin_function,
5591 debug_nothing_int, /* end_function */
5592 dwarf2out_function_decl, /* function_decl */
5593 dwarf2out_global_decl,
5594 dwarf2out_type_decl, /* type_decl */
5595 dwarf2out_imported_module_or_decl,
5596 debug_nothing_tree, /* deferred_inline_function */
5597 /* The DWARF 2 backend tries to reduce debugging bloat by not
5598 emitting the abstract description of inline functions until
5599 something tries to reference them. */
5600 dwarf2out_abstract_function, /* outlining_inline_function */
5601 debug_nothing_rtx, /* label */
5602 debug_nothing_int, /* handle_pch */
5603 dwarf2out_var_location,
5604 dwarf2out_switch_text_section,
5605 dwarf2out_direct_call,
5606 dwarf2out_virtual_call_token,
5607 dwarf2out_copy_call_info,
5608 dwarf2out_virtual_call,
5610 1 /* start_end_main_source_file */
5613 /* NOTE: In the comments in this file, many references are made to
5614 "Debugging Information Entries". This term is abbreviated as `DIE'
5615 throughout the remainder of this file. */
5617 /* An internal representation of the DWARF output is built, and then
5618 walked to generate the DWARF debugging info. The walk of the internal
5619 representation is done after the entire program has been compiled.
5620 The types below are used to describe the internal representation. */
5622 /* Various DIE's use offsets relative to the beginning of the
5623 .debug_info section to refer to each other. */
5625 typedef long int dw_offset;
5627 /* Define typedefs here to avoid circular dependencies. */
5629 typedef struct dw_attr_struct *dw_attr_ref;
5630 typedef struct dw_line_info_struct *dw_line_info_ref;
5631 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5632 typedef struct pubname_struct *pubname_ref;
5633 typedef struct dw_ranges_struct *dw_ranges_ref;
5634 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5635 typedef struct comdat_type_struct *comdat_type_node_ref;
5637 /* Each entry in the line_info_table maintains the file and
5638 line number associated with the label generated for that
5639 entry. The label gives the PC value associated with
5640 the line number entry. */
5642 typedef struct GTY(()) dw_line_info_struct {
5643 unsigned long dw_file_num;
5644 unsigned long dw_line_num;
5648 /* Line information for functions in separate sections; each one gets its
5650 typedef struct GTY(()) dw_separate_line_info_struct {
5651 unsigned long dw_file_num;
5652 unsigned long dw_line_num;
5653 unsigned long function;
5655 dw_separate_line_info_entry;
5657 /* Each DIE attribute has a field specifying the attribute kind,
5658 a link to the next attribute in the chain, and an attribute value.
5659 Attributes are typically linked below the DIE they modify. */
5661 typedef struct GTY(()) dw_attr_struct {
5662 enum dwarf_attribute dw_attr;
5663 dw_val_node dw_attr_val;
5667 DEF_VEC_O(dw_attr_node);
5668 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5670 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5671 The children of each node form a circular list linked by
5672 die_sib. die_child points to the node *before* the "first" child node. */
5674 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5675 enum dwarf_tag die_tag;
5676 union die_symbol_or_type_node
5678 char * GTY ((tag ("0"))) die_symbol;
5679 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5681 GTY ((desc ("dwarf_version >= 4"))) die_id;
5682 VEC(dw_attr_node,gc) * die_attr;
5683 dw_die_ref die_parent;
5684 dw_die_ref die_child;
5686 dw_die_ref die_definition; /* ref from a specification to its definition */
5687 dw_offset die_offset;
5688 unsigned long die_abbrev;
5690 /* Die is used and must not be pruned as unused. */
5691 int die_perennial_p;
5692 unsigned int decl_id;
5696 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5697 #define FOR_EACH_CHILD(die, c, expr) do { \
5698 c = die->die_child; \
5702 } while (c != die->die_child); \
5705 /* The pubname structure */
5707 typedef struct GTY(()) pubname_struct {
5713 DEF_VEC_O(pubname_entry);
5714 DEF_VEC_ALLOC_O(pubname_entry, gc);
5716 struct GTY(()) dw_ranges_struct {
5717 /* If this is positive, it's a block number, otherwise it's a
5718 bitwise-negated index into dw_ranges_by_label. */
5722 struct GTY(()) dw_ranges_by_label_struct {
5727 /* The comdat type node structure. */
5728 typedef struct GTY(()) comdat_type_struct
5730 dw_die_ref root_die;
5731 dw_die_ref type_die;
5732 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5733 struct comdat_type_struct *next;
5737 /* The limbo die list structure. */
5738 typedef struct GTY(()) limbo_die_struct {
5741 struct limbo_die_struct *next;
5745 typedef struct GTY(()) skeleton_chain_struct
5749 struct skeleton_chain_struct *parent;
5751 skeleton_chain_node;
5753 /* How to start an assembler comment. */
5754 #ifndef ASM_COMMENT_START
5755 #define ASM_COMMENT_START ";#"
5758 /* Define a macro which returns nonzero for a TYPE_DECL which was
5759 implicitly generated for a tagged type.
5761 Note that unlike the gcc front end (which generates a NULL named
5762 TYPE_DECL node for each complete tagged type, each array type, and
5763 each function type node created) the g++ front end generates a
5764 _named_ TYPE_DECL node for each tagged type node created.
5765 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5766 generate a DW_TAG_typedef DIE for them. */
5768 #define TYPE_DECL_IS_STUB(decl) \
5769 (DECL_NAME (decl) == NULL_TREE \
5770 || (DECL_ARTIFICIAL (decl) \
5771 && is_tagged_type (TREE_TYPE (decl)) \
5772 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5773 /* This is necessary for stub decls that \
5774 appear in nested inline functions. */ \
5775 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5776 && (decl_ultimate_origin (decl) \
5777 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5779 /* Information concerning the compilation unit's programming
5780 language, and compiler version. */
5782 /* Fixed size portion of the DWARF compilation unit header. */
5783 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5784 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5786 /* Fixed size portion of the DWARF comdat type unit header. */
5787 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
5788 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
5789 + DWARF_OFFSET_SIZE)
5791 /* Fixed size portion of public names info. */
5792 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5794 /* Fixed size portion of the address range info. */
5795 #define DWARF_ARANGES_HEADER_SIZE \
5796 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5797 DWARF2_ADDR_SIZE * 2) \
5798 - DWARF_INITIAL_LENGTH_SIZE)
5800 /* Size of padding portion in the address range info. It must be
5801 aligned to twice the pointer size. */
5802 #define DWARF_ARANGES_PAD_SIZE \
5803 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5804 DWARF2_ADDR_SIZE * 2) \
5805 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5807 /* Use assembler line directives if available. */
5808 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5809 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5810 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5812 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5816 /* Minimum line offset in a special line info. opcode.
5817 This value was chosen to give a reasonable range of values. */
5818 #define DWARF_LINE_BASE -10
5820 /* First special line opcode - leave room for the standard opcodes. */
5821 #define DWARF_LINE_OPCODE_BASE 10
5823 /* Range of line offsets in a special line info. opcode. */
5824 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5826 /* Flag that indicates the initial value of the is_stmt_start flag.
5827 In the present implementation, we do not mark any lines as
5828 the beginning of a source statement, because that information
5829 is not made available by the GCC front-end. */
5830 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5832 /* Maximum number of operations per instruction bundle. */
5833 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
5834 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
5837 /* This location is used by calc_die_sizes() to keep track
5838 the offset of each DIE within the .debug_info section. */
5839 static unsigned long next_die_offset;
5841 /* Record the root of the DIE's built for the current compilation unit. */
5842 static GTY(()) dw_die_ref comp_unit_die;
5844 /* A list of type DIEs that have been separated into comdat sections. */
5845 static GTY(()) comdat_type_node *comdat_type_list;
5847 /* A list of DIEs with a NULL parent waiting to be relocated. */
5848 static GTY(()) limbo_die_node *limbo_die_list;
5850 /* A list of DIEs for which we may have to generate
5851 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
5852 static GTY(()) limbo_die_node *deferred_asm_name;
5854 /* Filenames referenced by this compilation unit. */
5855 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5857 /* A hash table of references to DIE's that describe declarations.
5858 The key is a DECL_UID() which is a unique number identifying each decl. */
5859 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5861 /* A hash table of references to DIE's that describe COMMON blocks.
5862 The key is DECL_UID() ^ die_parent. */
5863 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5865 typedef struct GTY(()) die_arg_entry_struct {
5870 DEF_VEC_O(die_arg_entry);
5871 DEF_VEC_ALLOC_O(die_arg_entry,gc);
5873 /* Node of the variable location list. */
5874 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5875 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
5876 EXPR_LIST chain. For small bitsizes, bitsize is encoded
5877 in mode of the EXPR_LIST node and first EXPR_LIST operand
5878 is either NOTE_INSN_VAR_LOCATION for a piece with a known
5879 location or NULL for padding. For larger bitsizes,
5880 mode is 0 and first operand is a CONCAT with bitsize
5881 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
5882 NULL as second operand. */
5884 const char * GTY (()) label;
5885 struct var_loc_node * GTY (()) next;
5888 /* Variable location list. */
5889 struct GTY (()) var_loc_list_def {
5890 struct var_loc_node * GTY (()) first;
5892 /* Pointer to the last but one or last element of the
5893 chained list. If the list is empty, both first and
5894 last are NULL, if the list contains just one node
5895 or the last node certainly is not redundant, it points
5896 to the last node, otherwise points to the last but one.
5897 Do not mark it for GC because it is marked through the chain. */
5898 struct var_loc_node * GTY ((skip ("%h"))) last;
5900 /* DECL_UID of the variable decl. */
5901 unsigned int decl_id;
5903 typedef struct var_loc_list_def var_loc_list;
5906 /* Table of decl location linked lists. */
5907 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5909 /* A pointer to the base of a list of references to DIE's that
5910 are uniquely identified by their tag, presence/absence of
5911 children DIE's, and list of attribute/value pairs. */
5912 static GTY((length ("abbrev_die_table_allocated")))
5913 dw_die_ref *abbrev_die_table;
5915 /* Number of elements currently allocated for abbrev_die_table. */
5916 static GTY(()) unsigned abbrev_die_table_allocated;
5918 /* Number of elements in type_die_table currently in use. */
5919 static GTY(()) unsigned abbrev_die_table_in_use;
5921 /* Size (in elements) of increments by which we may expand the
5922 abbrev_die_table. */
5923 #define ABBREV_DIE_TABLE_INCREMENT 256
5925 /* A pointer to the base of a table that contains line information
5926 for each source code line in .text in the compilation unit. */
5927 static GTY((length ("line_info_table_allocated")))
5928 dw_line_info_ref line_info_table;
5930 /* Number of elements currently allocated for line_info_table. */
5931 static GTY(()) unsigned line_info_table_allocated;
5933 /* Number of elements in line_info_table currently in use. */
5934 static GTY(()) unsigned line_info_table_in_use;
5936 /* A pointer to the base of a table that contains line information
5937 for each source code line outside of .text in the compilation unit. */
5938 static GTY ((length ("separate_line_info_table_allocated")))
5939 dw_separate_line_info_ref separate_line_info_table;
5941 /* Number of elements currently allocated for separate_line_info_table. */
5942 static GTY(()) unsigned separate_line_info_table_allocated;
5944 /* Number of elements in separate_line_info_table currently in use. */
5945 static GTY(()) unsigned separate_line_info_table_in_use;
5947 /* Size (in elements) of increments by which we may expand the
5949 #define LINE_INFO_TABLE_INCREMENT 1024
5951 /* A pointer to the base of a table that contains a list of publicly
5952 accessible names. */
5953 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5955 /* A pointer to the base of a table that contains a list of publicly
5956 accessible types. */
5957 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5959 /* Array of dies for which we should generate .debug_arange info. */
5960 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5962 /* Number of elements currently allocated for arange_table. */
5963 static GTY(()) unsigned arange_table_allocated;
5965 /* Number of elements in arange_table currently in use. */
5966 static GTY(()) unsigned arange_table_in_use;
5968 /* Size (in elements) of increments by which we may expand the
5970 #define ARANGE_TABLE_INCREMENT 64
5972 /* Array of dies for which we should generate .debug_ranges info. */
5973 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5975 /* Number of elements currently allocated for ranges_table. */
5976 static GTY(()) unsigned ranges_table_allocated;
5978 /* Number of elements in ranges_table currently in use. */
5979 static GTY(()) unsigned ranges_table_in_use;
5981 /* Array of pairs of labels referenced in ranges_table. */
5982 static GTY ((length ("ranges_by_label_allocated")))
5983 dw_ranges_by_label_ref ranges_by_label;
5985 /* Number of elements currently allocated for ranges_by_label. */
5986 static GTY(()) unsigned ranges_by_label_allocated;
5988 /* Number of elements in ranges_by_label currently in use. */
5989 static GTY(()) unsigned ranges_by_label_in_use;
5991 /* Size (in elements) of increments by which we may expand the
5993 #define RANGES_TABLE_INCREMENT 64
5995 /* Whether we have location lists that need outputting */
5996 static GTY(()) bool have_location_lists;
5998 /* Unique label counter. */
5999 static GTY(()) unsigned int loclabel_num;
6001 /* Unique label counter for point-of-call tables. */
6002 static GTY(()) unsigned int poc_label_num;
6004 /* The direct call table structure. */
6006 typedef struct GTY(()) dcall_struct {
6007 unsigned int poc_label_num;
6009 dw_die_ref targ_die;
6013 DEF_VEC_O(dcall_entry);
6014 DEF_VEC_ALLOC_O(dcall_entry, gc);
6016 /* The virtual call table structure. */
6018 typedef struct GTY(()) vcall_struct {
6019 unsigned int poc_label_num;
6020 unsigned int vtable_slot;
6024 DEF_VEC_O(vcall_entry);
6025 DEF_VEC_ALLOC_O(vcall_entry, gc);
6027 /* Pointers to the direct and virtual call tables. */
6028 static GTY (()) VEC (dcall_entry, gc) * dcall_table = NULL;
6029 static GTY (()) VEC (vcall_entry, gc) * vcall_table = NULL;
6031 /* A hash table to map INSN_UIDs to vtable slot indexes. */
6033 struct GTY (()) vcall_insn {
6035 unsigned int vtable_slot;
6038 static GTY ((param_is (struct vcall_insn))) htab_t vcall_insn_table;
6040 /* Record whether the function being analyzed contains inlined functions. */
6041 static int current_function_has_inlines;
6042 #if 0 && defined (MIPS_DEBUGGING_INFO)
6043 static int comp_unit_has_inlines;
6046 /* The last file entry emitted by maybe_emit_file(). */
6047 static GTY(()) struct dwarf_file_data * last_emitted_file;
6049 /* Number of internal labels generated by gen_internal_sym(). */
6050 static GTY(()) int label_num;
6052 /* Cached result of previous call to lookup_filename. */
6053 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6055 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6057 /* Offset from the "steady-state frame pointer" to the frame base,
6058 within the current function. */
6059 static HOST_WIDE_INT frame_pointer_fb_offset;
6061 /* Forward declarations for functions defined in this file. */
6063 static int is_pseudo_reg (const_rtx);
6064 static tree type_main_variant (tree);
6065 static int is_tagged_type (const_tree);
6066 static const char *dwarf_tag_name (unsigned);
6067 static const char *dwarf_attr_name (unsigned);
6068 static const char *dwarf_form_name (unsigned);
6069 static tree decl_ultimate_origin (const_tree);
6070 static tree decl_class_context (tree);
6071 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6072 static inline enum dw_val_class AT_class (dw_attr_ref);
6073 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6074 static inline unsigned AT_flag (dw_attr_ref);
6075 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6076 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6077 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6078 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6079 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6080 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6081 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6082 unsigned int, unsigned char *);
6083 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6084 static hashval_t debug_str_do_hash (const void *);
6085 static int debug_str_eq (const void *, const void *);
6086 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6087 static inline const char *AT_string (dw_attr_ref);
6088 static enum dwarf_form AT_string_form (dw_attr_ref);
6089 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6090 static void add_AT_specification (dw_die_ref, dw_die_ref);
6091 static inline dw_die_ref AT_ref (dw_attr_ref);
6092 static inline int AT_ref_external (dw_attr_ref);
6093 static inline void set_AT_ref_external (dw_attr_ref, int);
6094 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6095 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6096 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6097 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6099 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6100 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6101 static inline rtx AT_addr (dw_attr_ref);
6102 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6103 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6104 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6105 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6106 unsigned HOST_WIDE_INT);
6107 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6109 static inline const char *AT_lbl (dw_attr_ref);
6110 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6111 static const char *get_AT_low_pc (dw_die_ref);
6112 static const char *get_AT_hi_pc (dw_die_ref);
6113 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6114 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6115 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6116 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6117 static bool is_cxx (void);
6118 static bool is_fortran (void);
6119 static bool is_ada (void);
6120 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6121 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6122 static void add_child_die (dw_die_ref, dw_die_ref);
6123 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6124 static dw_die_ref lookup_type_die (tree);
6125 static void equate_type_number_to_die (tree, dw_die_ref);
6126 static hashval_t decl_die_table_hash (const void *);
6127 static int decl_die_table_eq (const void *, const void *);
6128 static dw_die_ref lookup_decl_die (tree);
6129 static hashval_t common_block_die_table_hash (const void *);
6130 static int common_block_die_table_eq (const void *, const void *);
6131 static hashval_t decl_loc_table_hash (const void *);
6132 static int decl_loc_table_eq (const void *, const void *);
6133 static var_loc_list *lookup_decl_loc (const_tree);
6134 static void equate_decl_number_to_die (tree, dw_die_ref);
6135 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6136 static void print_spaces (FILE *);
6137 static void print_die (dw_die_ref, FILE *);
6138 static void print_dwarf_line_table (FILE *);
6139 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6140 static dw_die_ref pop_compile_unit (dw_die_ref);
6141 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6142 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6143 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6144 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6145 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6146 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6147 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6148 struct md5_ctx *, int *);
6149 struct checksum_attributes;
6150 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6151 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6152 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6153 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6154 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6155 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6156 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6157 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6158 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6159 static void compute_section_prefix (dw_die_ref);
6160 static int is_type_die (dw_die_ref);
6161 static int is_comdat_die (dw_die_ref);
6162 static int is_symbol_die (dw_die_ref);
6163 static void assign_symbol_names (dw_die_ref);
6164 static void break_out_includes (dw_die_ref);
6165 static int is_declaration_die (dw_die_ref);
6166 static int should_move_die_to_comdat (dw_die_ref);
6167 static dw_die_ref clone_as_declaration (dw_die_ref);
6168 static dw_die_ref clone_die (dw_die_ref);
6169 static dw_die_ref clone_tree (dw_die_ref);
6170 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6171 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6172 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6173 static dw_die_ref generate_skeleton (dw_die_ref);
6174 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6176 static void break_out_comdat_types (dw_die_ref);
6177 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6178 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6179 static void copy_decls_for_unworthy_types (dw_die_ref);
6181 static hashval_t htab_cu_hash (const void *);
6182 static int htab_cu_eq (const void *, const void *);
6183 static void htab_cu_del (void *);
6184 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6185 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6186 static void add_sibling_attributes (dw_die_ref);
6187 static void build_abbrev_table (dw_die_ref);
6188 static void output_location_lists (dw_die_ref);
6189 static int constant_size (unsigned HOST_WIDE_INT);
6190 static unsigned long size_of_die (dw_die_ref);
6191 static void calc_die_sizes (dw_die_ref);
6192 static void mark_dies (dw_die_ref);
6193 static void unmark_dies (dw_die_ref);
6194 static void unmark_all_dies (dw_die_ref);
6195 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6196 static unsigned long size_of_aranges (void);
6197 static enum dwarf_form value_format (dw_attr_ref);
6198 static void output_value_format (dw_attr_ref);
6199 static void output_abbrev_section (void);
6200 static void output_die_symbol (dw_die_ref);
6201 static void output_die (dw_die_ref);
6202 static void output_compilation_unit_header (void);
6203 static void output_comp_unit (dw_die_ref, int);
6204 static void output_comdat_type_unit (comdat_type_node *);
6205 static const char *dwarf2_name (tree, int);
6206 static void add_pubname (tree, dw_die_ref);
6207 static void add_pubname_string (const char *, dw_die_ref);
6208 static void add_pubtype (tree, dw_die_ref);
6209 static void output_pubnames (VEC (pubname_entry,gc) *);
6210 static void add_arange (tree, dw_die_ref);
6211 static void output_aranges (void);
6212 static unsigned int add_ranges_num (int);
6213 static unsigned int add_ranges (const_tree);
6214 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6216 static void output_ranges (void);
6217 static void output_line_info (void);
6218 static void output_file_names (void);
6219 static dw_die_ref base_type_die (tree);
6220 static int is_base_type (tree);
6221 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6222 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6223 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6224 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6225 static int type_is_enum (const_tree);
6226 static unsigned int dbx_reg_number (const_rtx);
6227 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6228 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6229 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6230 enum var_init_status);
6231 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6232 enum var_init_status);
6233 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6234 enum var_init_status);
6235 static int is_based_loc (const_rtx);
6236 static int resolve_one_addr (rtx *, void *);
6237 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6238 enum var_init_status);
6239 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6240 enum var_init_status);
6241 static dw_loc_list_ref loc_list_from_tree (tree, int);
6242 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6243 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6244 static tree field_type (const_tree);
6245 static unsigned int simple_type_align_in_bits (const_tree);
6246 static unsigned int simple_decl_align_in_bits (const_tree);
6247 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6248 static HOST_WIDE_INT field_byte_offset (const_tree);
6249 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6251 static void add_data_member_location_attribute (dw_die_ref, tree);
6252 static bool add_const_value_attribute (dw_die_ref, rtx);
6253 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6254 static void insert_double (double_int, unsigned char *);
6255 static void insert_float (const_rtx, unsigned char *);
6256 static rtx rtl_for_decl_location (tree);
6257 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
6258 enum dwarf_attribute);
6259 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6260 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6261 static void add_name_attribute (dw_die_ref, const char *);
6262 static void add_comp_dir_attribute (dw_die_ref);
6263 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6264 static void add_subscript_info (dw_die_ref, tree, bool);
6265 static void add_byte_size_attribute (dw_die_ref, tree);
6266 static void add_bit_offset_attribute (dw_die_ref, tree);
6267 static void add_bit_size_attribute (dw_die_ref, tree);
6268 static void add_prototyped_attribute (dw_die_ref, tree);
6269 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6270 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6271 static void add_src_coords_attributes (dw_die_ref, tree);
6272 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6273 static void push_decl_scope (tree);
6274 static void pop_decl_scope (void);
6275 static dw_die_ref scope_die_for (tree, dw_die_ref);
6276 static inline int local_scope_p (dw_die_ref);
6277 static inline int class_scope_p (dw_die_ref);
6278 static inline int class_or_namespace_scope_p (dw_die_ref);
6279 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6280 static void add_calling_convention_attribute (dw_die_ref, tree);
6281 static const char *type_tag (const_tree);
6282 static tree member_declared_type (const_tree);
6284 static const char *decl_start_label (tree);
6286 static void gen_array_type_die (tree, dw_die_ref);
6287 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6289 static void gen_entry_point_die (tree, dw_die_ref);
6291 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6292 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6293 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6294 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6295 static void gen_formal_types_die (tree, dw_die_ref);
6296 static void gen_subprogram_die (tree, dw_die_ref);
6297 static void gen_variable_die (tree, tree, dw_die_ref);
6298 static void gen_const_die (tree, dw_die_ref);
6299 static void gen_label_die (tree, dw_die_ref);
6300 static void gen_lexical_block_die (tree, dw_die_ref, int);
6301 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6302 static void gen_field_die (tree, dw_die_ref);
6303 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6304 static dw_die_ref gen_compile_unit_die (const char *);
6305 static void gen_inheritance_die (tree, tree, dw_die_ref);
6306 static void gen_member_die (tree, dw_die_ref);
6307 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6308 enum debug_info_usage);
6309 static void gen_subroutine_type_die (tree, dw_die_ref);
6310 static void gen_typedef_die (tree, dw_die_ref);
6311 static void gen_type_die (tree, dw_die_ref);
6312 static void gen_block_die (tree, dw_die_ref, int);
6313 static void decls_for_scope (tree, dw_die_ref, int);
6314 static int is_redundant_typedef (const_tree);
6315 static bool is_naming_typedef_decl (const_tree);
6316 static inline dw_die_ref get_context_die (tree);
6317 static void gen_namespace_die (tree, dw_die_ref);
6318 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6319 static dw_die_ref force_decl_die (tree);
6320 static dw_die_ref force_type_die (tree);
6321 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6322 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6323 static struct dwarf_file_data * lookup_filename (const char *);
6324 static void retry_incomplete_types (void);
6325 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6326 static void gen_generic_params_dies (tree);
6327 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6328 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6329 static void splice_child_die (dw_die_ref, dw_die_ref);
6330 static int file_info_cmp (const void *, const void *);
6331 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6332 const char *, const char *);
6333 static void output_loc_list (dw_loc_list_ref);
6334 static char *gen_internal_sym (const char *);
6336 static void prune_unmark_dies (dw_die_ref);
6337 static void prune_unused_types_mark (dw_die_ref, int);
6338 static void prune_unused_types_walk (dw_die_ref);
6339 static void prune_unused_types_walk_attribs (dw_die_ref);
6340 static void prune_unused_types_prune (dw_die_ref);
6341 static void prune_unused_types (void);
6342 static int maybe_emit_file (struct dwarf_file_data *fd);
6343 static inline const char *AT_vms_delta1 (dw_attr_ref);
6344 static inline const char *AT_vms_delta2 (dw_attr_ref);
6345 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6346 const char *, const char *);
6347 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6348 static void gen_remaining_tmpl_value_param_die_attribute (void);
6350 /* Section names used to hold DWARF debugging information. */
6351 #ifndef DEBUG_INFO_SECTION
6352 #define DEBUG_INFO_SECTION ".debug_info"
6354 #ifndef DEBUG_ABBREV_SECTION
6355 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6357 #ifndef DEBUG_ARANGES_SECTION
6358 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6360 #ifndef DEBUG_MACINFO_SECTION
6361 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6363 #ifndef DEBUG_LINE_SECTION
6364 #define DEBUG_LINE_SECTION ".debug_line"
6366 #ifndef DEBUG_LOC_SECTION
6367 #define DEBUG_LOC_SECTION ".debug_loc"
6369 #ifndef DEBUG_PUBNAMES_SECTION
6370 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6372 #ifndef DEBUG_PUBTYPES_SECTION
6373 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6375 #ifndef DEBUG_DCALL_SECTION
6376 #define DEBUG_DCALL_SECTION ".debug_dcall"
6378 #ifndef DEBUG_VCALL_SECTION
6379 #define DEBUG_VCALL_SECTION ".debug_vcall"
6381 #ifndef DEBUG_STR_SECTION
6382 #define DEBUG_STR_SECTION ".debug_str"
6384 #ifndef DEBUG_RANGES_SECTION
6385 #define DEBUG_RANGES_SECTION ".debug_ranges"
6388 /* Standard ELF section names for compiled code and data. */
6389 #ifndef TEXT_SECTION_NAME
6390 #define TEXT_SECTION_NAME ".text"
6393 /* Section flags for .debug_str section. */
6394 #define DEBUG_STR_SECTION_FLAGS \
6395 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6396 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6399 /* Labels we insert at beginning sections we can reference instead of
6400 the section names themselves. */
6402 #ifndef TEXT_SECTION_LABEL
6403 #define TEXT_SECTION_LABEL "Ltext"
6405 #ifndef COLD_TEXT_SECTION_LABEL
6406 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6408 #ifndef DEBUG_LINE_SECTION_LABEL
6409 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6411 #ifndef DEBUG_INFO_SECTION_LABEL
6412 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6414 #ifndef DEBUG_ABBREV_SECTION_LABEL
6415 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6417 #ifndef DEBUG_LOC_SECTION_LABEL
6418 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6420 #ifndef DEBUG_RANGES_SECTION_LABEL
6421 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6423 #ifndef DEBUG_MACINFO_SECTION_LABEL
6424 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6428 /* Definitions of defaults for formats and names of various special
6429 (artificial) labels which may be generated within this file (when the -g
6430 options is used and DWARF2_DEBUGGING_INFO is in effect.
6431 If necessary, these may be overridden from within the tm.h file, but
6432 typically, overriding these defaults is unnecessary. */
6434 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6435 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6436 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6437 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6438 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6439 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6440 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6441 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6442 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6443 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6445 #ifndef TEXT_END_LABEL
6446 #define TEXT_END_LABEL "Letext"
6448 #ifndef COLD_END_LABEL
6449 #define COLD_END_LABEL "Letext_cold"
6451 #ifndef BLOCK_BEGIN_LABEL
6452 #define BLOCK_BEGIN_LABEL "LBB"
6454 #ifndef BLOCK_END_LABEL
6455 #define BLOCK_END_LABEL "LBE"
6457 #ifndef LINE_CODE_LABEL
6458 #define LINE_CODE_LABEL "LM"
6460 #ifndef SEPARATE_LINE_CODE_LABEL
6461 #define SEPARATE_LINE_CODE_LABEL "LSM"
6465 /* We allow a language front-end to designate a function that is to be
6466 called to "demangle" any name before it is put into a DIE. */
6468 static const char *(*demangle_name_func) (const char *);
6471 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6473 demangle_name_func = func;
6476 /* Test if rtl node points to a pseudo register. */
6479 is_pseudo_reg (const_rtx rtl)
6481 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6482 || (GET_CODE (rtl) == SUBREG
6483 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6486 /* Return a reference to a type, with its const and volatile qualifiers
6490 type_main_variant (tree type)
6492 type = TYPE_MAIN_VARIANT (type);
6494 /* ??? There really should be only one main variant among any group of
6495 variants of a given type (and all of the MAIN_VARIANT values for all
6496 members of the group should point to that one type) but sometimes the C
6497 front-end messes this up for array types, so we work around that bug
6499 if (TREE_CODE (type) == ARRAY_TYPE)
6500 while (type != TYPE_MAIN_VARIANT (type))
6501 type = TYPE_MAIN_VARIANT (type);
6506 /* Return nonzero if the given type node represents a tagged type. */
6509 is_tagged_type (const_tree type)
6511 enum tree_code code = TREE_CODE (type);
6513 return (code == RECORD_TYPE || code == UNION_TYPE
6514 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6517 /* Convert a DIE tag into its string name. */
6520 dwarf_tag_name (unsigned int tag)
6524 case DW_TAG_padding:
6525 return "DW_TAG_padding";
6526 case DW_TAG_array_type:
6527 return "DW_TAG_array_type";
6528 case DW_TAG_class_type:
6529 return "DW_TAG_class_type";
6530 case DW_TAG_entry_point:
6531 return "DW_TAG_entry_point";
6532 case DW_TAG_enumeration_type:
6533 return "DW_TAG_enumeration_type";
6534 case DW_TAG_formal_parameter:
6535 return "DW_TAG_formal_parameter";
6536 case DW_TAG_imported_declaration:
6537 return "DW_TAG_imported_declaration";
6539 return "DW_TAG_label";
6540 case DW_TAG_lexical_block:
6541 return "DW_TAG_lexical_block";
6543 return "DW_TAG_member";
6544 case DW_TAG_pointer_type:
6545 return "DW_TAG_pointer_type";
6546 case DW_TAG_reference_type:
6547 return "DW_TAG_reference_type";
6548 case DW_TAG_compile_unit:
6549 return "DW_TAG_compile_unit";
6550 case DW_TAG_string_type:
6551 return "DW_TAG_string_type";
6552 case DW_TAG_structure_type:
6553 return "DW_TAG_structure_type";
6554 case DW_TAG_subroutine_type:
6555 return "DW_TAG_subroutine_type";
6556 case DW_TAG_typedef:
6557 return "DW_TAG_typedef";
6558 case DW_TAG_union_type:
6559 return "DW_TAG_union_type";
6560 case DW_TAG_unspecified_parameters:
6561 return "DW_TAG_unspecified_parameters";
6562 case DW_TAG_variant:
6563 return "DW_TAG_variant";
6564 case DW_TAG_common_block:
6565 return "DW_TAG_common_block";
6566 case DW_TAG_common_inclusion:
6567 return "DW_TAG_common_inclusion";
6568 case DW_TAG_inheritance:
6569 return "DW_TAG_inheritance";
6570 case DW_TAG_inlined_subroutine:
6571 return "DW_TAG_inlined_subroutine";
6573 return "DW_TAG_module";
6574 case DW_TAG_ptr_to_member_type:
6575 return "DW_TAG_ptr_to_member_type";
6576 case DW_TAG_set_type:
6577 return "DW_TAG_set_type";
6578 case DW_TAG_subrange_type:
6579 return "DW_TAG_subrange_type";
6580 case DW_TAG_with_stmt:
6581 return "DW_TAG_with_stmt";
6582 case DW_TAG_access_declaration:
6583 return "DW_TAG_access_declaration";
6584 case DW_TAG_base_type:
6585 return "DW_TAG_base_type";
6586 case DW_TAG_catch_block:
6587 return "DW_TAG_catch_block";
6588 case DW_TAG_const_type:
6589 return "DW_TAG_const_type";
6590 case DW_TAG_constant:
6591 return "DW_TAG_constant";
6592 case DW_TAG_enumerator:
6593 return "DW_TAG_enumerator";
6594 case DW_TAG_file_type:
6595 return "DW_TAG_file_type";
6597 return "DW_TAG_friend";
6598 case DW_TAG_namelist:
6599 return "DW_TAG_namelist";
6600 case DW_TAG_namelist_item:
6601 return "DW_TAG_namelist_item";
6602 case DW_TAG_packed_type:
6603 return "DW_TAG_packed_type";
6604 case DW_TAG_subprogram:
6605 return "DW_TAG_subprogram";
6606 case DW_TAG_template_type_param:
6607 return "DW_TAG_template_type_param";
6608 case DW_TAG_template_value_param:
6609 return "DW_TAG_template_value_param";
6610 case DW_TAG_thrown_type:
6611 return "DW_TAG_thrown_type";
6612 case DW_TAG_try_block:
6613 return "DW_TAG_try_block";
6614 case DW_TAG_variant_part:
6615 return "DW_TAG_variant_part";
6616 case DW_TAG_variable:
6617 return "DW_TAG_variable";
6618 case DW_TAG_volatile_type:
6619 return "DW_TAG_volatile_type";
6620 case DW_TAG_dwarf_procedure:
6621 return "DW_TAG_dwarf_procedure";
6622 case DW_TAG_restrict_type:
6623 return "DW_TAG_restrict_type";
6624 case DW_TAG_interface_type:
6625 return "DW_TAG_interface_type";
6626 case DW_TAG_namespace:
6627 return "DW_TAG_namespace";
6628 case DW_TAG_imported_module:
6629 return "DW_TAG_imported_module";
6630 case DW_TAG_unspecified_type:
6631 return "DW_TAG_unspecified_type";
6632 case DW_TAG_partial_unit:
6633 return "DW_TAG_partial_unit";
6634 case DW_TAG_imported_unit:
6635 return "DW_TAG_imported_unit";
6636 case DW_TAG_condition:
6637 return "DW_TAG_condition";
6638 case DW_TAG_shared_type:
6639 return "DW_TAG_shared_type";
6640 case DW_TAG_type_unit:
6641 return "DW_TAG_type_unit";
6642 case DW_TAG_rvalue_reference_type:
6643 return "DW_TAG_rvalue_reference_type";
6644 case DW_TAG_template_alias:
6645 return "DW_TAG_template_alias";
6646 case DW_TAG_GNU_template_parameter_pack:
6647 return "DW_TAG_GNU_template_parameter_pack";
6648 case DW_TAG_GNU_formal_parameter_pack:
6649 return "DW_TAG_GNU_formal_parameter_pack";
6650 case DW_TAG_MIPS_loop:
6651 return "DW_TAG_MIPS_loop";
6652 case DW_TAG_format_label:
6653 return "DW_TAG_format_label";
6654 case DW_TAG_function_template:
6655 return "DW_TAG_function_template";
6656 case DW_TAG_class_template:
6657 return "DW_TAG_class_template";
6658 case DW_TAG_GNU_BINCL:
6659 return "DW_TAG_GNU_BINCL";
6660 case DW_TAG_GNU_EINCL:
6661 return "DW_TAG_GNU_EINCL";
6662 case DW_TAG_GNU_template_template_param:
6663 return "DW_TAG_GNU_template_template_param";
6665 return "DW_TAG_<unknown>";
6669 /* Convert a DWARF attribute code into its string name. */
6672 dwarf_attr_name (unsigned int attr)
6677 return "DW_AT_sibling";
6678 case DW_AT_location:
6679 return "DW_AT_location";
6681 return "DW_AT_name";
6682 case DW_AT_ordering:
6683 return "DW_AT_ordering";
6684 case DW_AT_subscr_data:
6685 return "DW_AT_subscr_data";
6686 case DW_AT_byte_size:
6687 return "DW_AT_byte_size";
6688 case DW_AT_bit_offset:
6689 return "DW_AT_bit_offset";
6690 case DW_AT_bit_size:
6691 return "DW_AT_bit_size";
6692 case DW_AT_element_list:
6693 return "DW_AT_element_list";
6694 case DW_AT_stmt_list:
6695 return "DW_AT_stmt_list";
6697 return "DW_AT_low_pc";
6699 return "DW_AT_high_pc";
6700 case DW_AT_language:
6701 return "DW_AT_language";
6703 return "DW_AT_member";
6705 return "DW_AT_discr";
6706 case DW_AT_discr_value:
6707 return "DW_AT_discr_value";
6708 case DW_AT_visibility:
6709 return "DW_AT_visibility";
6711 return "DW_AT_import";
6712 case DW_AT_string_length:
6713 return "DW_AT_string_length";
6714 case DW_AT_common_reference:
6715 return "DW_AT_common_reference";
6716 case DW_AT_comp_dir:
6717 return "DW_AT_comp_dir";
6718 case DW_AT_const_value:
6719 return "DW_AT_const_value";
6720 case DW_AT_containing_type:
6721 return "DW_AT_containing_type";
6722 case DW_AT_default_value:
6723 return "DW_AT_default_value";
6725 return "DW_AT_inline";
6726 case DW_AT_is_optional:
6727 return "DW_AT_is_optional";
6728 case DW_AT_lower_bound:
6729 return "DW_AT_lower_bound";
6730 case DW_AT_producer:
6731 return "DW_AT_producer";
6732 case DW_AT_prototyped:
6733 return "DW_AT_prototyped";
6734 case DW_AT_return_addr:
6735 return "DW_AT_return_addr";
6736 case DW_AT_start_scope:
6737 return "DW_AT_start_scope";
6738 case DW_AT_bit_stride:
6739 return "DW_AT_bit_stride";
6740 case DW_AT_upper_bound:
6741 return "DW_AT_upper_bound";
6742 case DW_AT_abstract_origin:
6743 return "DW_AT_abstract_origin";
6744 case DW_AT_accessibility:
6745 return "DW_AT_accessibility";
6746 case DW_AT_address_class:
6747 return "DW_AT_address_class";
6748 case DW_AT_artificial:
6749 return "DW_AT_artificial";
6750 case DW_AT_base_types:
6751 return "DW_AT_base_types";
6752 case DW_AT_calling_convention:
6753 return "DW_AT_calling_convention";
6755 return "DW_AT_count";
6756 case DW_AT_data_member_location:
6757 return "DW_AT_data_member_location";
6758 case DW_AT_decl_column:
6759 return "DW_AT_decl_column";
6760 case DW_AT_decl_file:
6761 return "DW_AT_decl_file";
6762 case DW_AT_decl_line:
6763 return "DW_AT_decl_line";
6764 case DW_AT_declaration:
6765 return "DW_AT_declaration";
6766 case DW_AT_discr_list:
6767 return "DW_AT_discr_list";
6768 case DW_AT_encoding:
6769 return "DW_AT_encoding";
6770 case DW_AT_external:
6771 return "DW_AT_external";
6772 case DW_AT_explicit:
6773 return "DW_AT_explicit";
6774 case DW_AT_frame_base:
6775 return "DW_AT_frame_base";
6777 return "DW_AT_friend";
6778 case DW_AT_identifier_case:
6779 return "DW_AT_identifier_case";
6780 case DW_AT_macro_info:
6781 return "DW_AT_macro_info";
6782 case DW_AT_namelist_items:
6783 return "DW_AT_namelist_items";
6784 case DW_AT_priority:
6785 return "DW_AT_priority";
6787 return "DW_AT_segment";
6788 case DW_AT_specification:
6789 return "DW_AT_specification";
6790 case DW_AT_static_link:
6791 return "DW_AT_static_link";
6793 return "DW_AT_type";
6794 case DW_AT_use_location:
6795 return "DW_AT_use_location";
6796 case DW_AT_variable_parameter:
6797 return "DW_AT_variable_parameter";
6798 case DW_AT_virtuality:
6799 return "DW_AT_virtuality";
6800 case DW_AT_vtable_elem_location:
6801 return "DW_AT_vtable_elem_location";
6803 case DW_AT_allocated:
6804 return "DW_AT_allocated";
6805 case DW_AT_associated:
6806 return "DW_AT_associated";
6807 case DW_AT_data_location:
6808 return "DW_AT_data_location";
6809 case DW_AT_byte_stride:
6810 return "DW_AT_byte_stride";
6811 case DW_AT_entry_pc:
6812 return "DW_AT_entry_pc";
6813 case DW_AT_use_UTF8:
6814 return "DW_AT_use_UTF8";
6815 case DW_AT_extension:
6816 return "DW_AT_extension";
6818 return "DW_AT_ranges";
6819 case DW_AT_trampoline:
6820 return "DW_AT_trampoline";
6821 case DW_AT_call_column:
6822 return "DW_AT_call_column";
6823 case DW_AT_call_file:
6824 return "DW_AT_call_file";
6825 case DW_AT_call_line:
6826 return "DW_AT_call_line";
6827 case DW_AT_object_pointer:
6828 return "DW_AT_object_pointer";
6830 case DW_AT_signature:
6831 return "DW_AT_signature";
6832 case DW_AT_main_subprogram:
6833 return "DW_AT_main_subprogram";
6834 case DW_AT_data_bit_offset:
6835 return "DW_AT_data_bit_offset";
6836 case DW_AT_const_expr:
6837 return "DW_AT_const_expr";
6838 case DW_AT_enum_class:
6839 return "DW_AT_enum_class";
6840 case DW_AT_linkage_name:
6841 return "DW_AT_linkage_name";
6843 case DW_AT_MIPS_fde:
6844 return "DW_AT_MIPS_fde";
6845 case DW_AT_MIPS_loop_begin:
6846 return "DW_AT_MIPS_loop_begin";
6847 case DW_AT_MIPS_tail_loop_begin:
6848 return "DW_AT_MIPS_tail_loop_begin";
6849 case DW_AT_MIPS_epilog_begin:
6850 return "DW_AT_MIPS_epilog_begin";
6851 #if VMS_DEBUGGING_INFO
6852 case DW_AT_HP_prologue:
6853 return "DW_AT_HP_prologue";
6855 case DW_AT_MIPS_loop_unroll_factor:
6856 return "DW_AT_MIPS_loop_unroll_factor";
6858 case DW_AT_MIPS_software_pipeline_depth:
6859 return "DW_AT_MIPS_software_pipeline_depth";
6860 case DW_AT_MIPS_linkage_name:
6861 return "DW_AT_MIPS_linkage_name";
6862 #if VMS_DEBUGGING_INFO
6863 case DW_AT_HP_epilogue:
6864 return "DW_AT_HP_epilogue";
6866 case DW_AT_MIPS_stride:
6867 return "DW_AT_MIPS_stride";
6869 case DW_AT_MIPS_abstract_name:
6870 return "DW_AT_MIPS_abstract_name";
6871 case DW_AT_MIPS_clone_origin:
6872 return "DW_AT_MIPS_clone_origin";
6873 case DW_AT_MIPS_has_inlines:
6874 return "DW_AT_MIPS_has_inlines";
6876 case DW_AT_sf_names:
6877 return "DW_AT_sf_names";
6878 case DW_AT_src_info:
6879 return "DW_AT_src_info";
6880 case DW_AT_mac_info:
6881 return "DW_AT_mac_info";
6882 case DW_AT_src_coords:
6883 return "DW_AT_src_coords";
6884 case DW_AT_body_begin:
6885 return "DW_AT_body_begin";
6886 case DW_AT_body_end:
6887 return "DW_AT_body_end";
6888 case DW_AT_GNU_vector:
6889 return "DW_AT_GNU_vector";
6890 case DW_AT_GNU_guarded_by:
6891 return "DW_AT_GNU_guarded_by";
6892 case DW_AT_GNU_pt_guarded_by:
6893 return "DW_AT_GNU_pt_guarded_by";
6894 case DW_AT_GNU_guarded:
6895 return "DW_AT_GNU_guarded";
6896 case DW_AT_GNU_pt_guarded:
6897 return "DW_AT_GNU_pt_guarded";
6898 case DW_AT_GNU_locks_excluded:
6899 return "DW_AT_GNU_locks_excluded";
6900 case DW_AT_GNU_exclusive_locks_required:
6901 return "DW_AT_GNU_exclusive_locks_required";
6902 case DW_AT_GNU_shared_locks_required:
6903 return "DW_AT_GNU_shared_locks_required";
6904 case DW_AT_GNU_odr_signature:
6905 return "DW_AT_GNU_odr_signature";
6906 case DW_AT_GNU_template_name:
6907 return "DW_AT_GNU_template_name";
6909 case DW_AT_VMS_rtnbeg_pd_address:
6910 return "DW_AT_VMS_rtnbeg_pd_address";
6913 return "DW_AT_<unknown>";
6917 /* Convert a DWARF value form code into its string name. */
6920 dwarf_form_name (unsigned int form)
6925 return "DW_FORM_addr";
6926 case DW_FORM_block2:
6927 return "DW_FORM_block2";
6928 case DW_FORM_block4:
6929 return "DW_FORM_block4";
6931 return "DW_FORM_data2";
6933 return "DW_FORM_data4";
6935 return "DW_FORM_data8";
6936 case DW_FORM_string:
6937 return "DW_FORM_string";
6939 return "DW_FORM_block";
6940 case DW_FORM_block1:
6941 return "DW_FORM_block1";
6943 return "DW_FORM_data1";
6945 return "DW_FORM_flag";
6947 return "DW_FORM_sdata";
6949 return "DW_FORM_strp";
6951 return "DW_FORM_udata";
6952 case DW_FORM_ref_addr:
6953 return "DW_FORM_ref_addr";
6955 return "DW_FORM_ref1";
6957 return "DW_FORM_ref2";
6959 return "DW_FORM_ref4";
6961 return "DW_FORM_ref8";
6962 case DW_FORM_ref_udata:
6963 return "DW_FORM_ref_udata";
6964 case DW_FORM_indirect:
6965 return "DW_FORM_indirect";
6966 case DW_FORM_sec_offset:
6967 return "DW_FORM_sec_offset";
6968 case DW_FORM_exprloc:
6969 return "DW_FORM_exprloc";
6970 case DW_FORM_flag_present:
6971 return "DW_FORM_flag_present";
6972 case DW_FORM_ref_sig8:
6973 return "DW_FORM_ref_sig8";
6975 return "DW_FORM_<unknown>";
6979 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6980 instance of an inlined instance of a decl which is local to an inline
6981 function, so we have to trace all of the way back through the origin chain
6982 to find out what sort of node actually served as the original seed for the
6986 decl_ultimate_origin (const_tree decl)
6988 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6991 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6992 nodes in the function to point to themselves; ignore that if
6993 we're trying to output the abstract instance of this function. */
6994 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
6997 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6998 most distant ancestor, this should never happen. */
6999 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7001 return DECL_ABSTRACT_ORIGIN (decl);
7004 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7005 of a virtual function may refer to a base class, so we check the 'this'
7009 decl_class_context (tree decl)
7011 tree context = NULL_TREE;
7013 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7014 context = DECL_CONTEXT (decl);
7016 context = TYPE_MAIN_VARIANT
7017 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7019 if (context && !TYPE_P (context))
7020 context = NULL_TREE;
7025 /* Add an attribute/value pair to a DIE. */
7028 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7030 /* Maybe this should be an assert? */
7034 if (die->die_attr == NULL)
7035 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7036 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7039 static inline enum dw_val_class
7040 AT_class (dw_attr_ref a)
7042 return a->dw_attr_val.val_class;
7045 /* Add a flag value attribute to a DIE. */
7048 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7052 attr.dw_attr = attr_kind;
7053 attr.dw_attr_val.val_class = dw_val_class_flag;
7054 attr.dw_attr_val.v.val_flag = flag;
7055 add_dwarf_attr (die, &attr);
7058 static inline unsigned
7059 AT_flag (dw_attr_ref a)
7061 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7062 return a->dw_attr_val.v.val_flag;
7065 /* Add a signed integer attribute value to a DIE. */
7068 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7072 attr.dw_attr = attr_kind;
7073 attr.dw_attr_val.val_class = dw_val_class_const;
7074 attr.dw_attr_val.v.val_int = int_val;
7075 add_dwarf_attr (die, &attr);
7078 static inline HOST_WIDE_INT
7079 AT_int (dw_attr_ref a)
7081 gcc_assert (a && AT_class (a) == dw_val_class_const);
7082 return a->dw_attr_val.v.val_int;
7085 /* Add an unsigned integer attribute value to a DIE. */
7088 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7089 unsigned HOST_WIDE_INT unsigned_val)
7093 attr.dw_attr = attr_kind;
7094 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7095 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7096 add_dwarf_attr (die, &attr);
7099 static inline unsigned HOST_WIDE_INT
7100 AT_unsigned (dw_attr_ref a)
7102 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7103 return a->dw_attr_val.v.val_unsigned;
7106 /* Add an unsigned double integer attribute value to a DIE. */
7109 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7110 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7114 attr.dw_attr = attr_kind;
7115 attr.dw_attr_val.val_class = dw_val_class_const_double;
7116 attr.dw_attr_val.v.val_double.high = high;
7117 attr.dw_attr_val.v.val_double.low = low;
7118 add_dwarf_attr (die, &attr);
7121 /* Add a floating point attribute value to a DIE and return it. */
7124 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7125 unsigned int length, unsigned int elt_size, unsigned char *array)
7129 attr.dw_attr = attr_kind;
7130 attr.dw_attr_val.val_class = dw_val_class_vec;
7131 attr.dw_attr_val.v.val_vec.length = length;
7132 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7133 attr.dw_attr_val.v.val_vec.array = array;
7134 add_dwarf_attr (die, &attr);
7137 /* Add an 8-byte data attribute value to a DIE. */
7140 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7141 unsigned char data8[8])
7145 attr.dw_attr = attr_kind;
7146 attr.dw_attr_val.val_class = dw_val_class_data8;
7147 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7148 add_dwarf_attr (die, &attr);
7151 /* Hash and equality functions for debug_str_hash. */
7154 debug_str_do_hash (const void *x)
7156 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7160 debug_str_eq (const void *x1, const void *x2)
7162 return strcmp ((((const struct indirect_string_node *)x1)->str),
7163 (const char *)x2) == 0;
7166 /* Add STR to the indirect string hash table. */
7168 static struct indirect_string_node *
7169 find_AT_string (const char *str)
7171 struct indirect_string_node *node;
7174 if (! debug_str_hash)
7175 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7176 debug_str_eq, NULL);
7178 slot = htab_find_slot_with_hash (debug_str_hash, str,
7179 htab_hash_string (str), INSERT);
7182 node = ggc_alloc_cleared_indirect_string_node ();
7183 node->str = ggc_strdup (str);
7187 node = (struct indirect_string_node *) *slot;
7193 /* Add a string attribute value to a DIE. */
7196 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7199 struct indirect_string_node *node;
7201 node = find_AT_string (str);
7203 attr.dw_attr = attr_kind;
7204 attr.dw_attr_val.val_class = dw_val_class_str;
7205 attr.dw_attr_val.v.val_str = node;
7206 add_dwarf_attr (die, &attr);
7209 /* Create a label for an indirect string node, ensuring it is going to
7210 be output, unless its reference count goes down to zero. */
7213 gen_label_for_indirect_string (struct indirect_string_node *node)
7220 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7221 ++dw2_string_counter;
7222 node->label = xstrdup (label);
7225 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7226 debug string STR. */
7229 get_debug_string_label (const char *str)
7231 struct indirect_string_node *node = find_AT_string (str);
7233 debug_str_hash_forced = true;
7235 gen_label_for_indirect_string (node);
7237 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7240 static inline const char *
7241 AT_string (dw_attr_ref a)
7243 gcc_assert (a && AT_class (a) == dw_val_class_str);
7244 return a->dw_attr_val.v.val_str->str;
7247 /* Find out whether a string should be output inline in DIE
7248 or out-of-line in .debug_str section. */
7250 static enum dwarf_form
7251 AT_string_form (dw_attr_ref a)
7253 struct indirect_string_node *node;
7256 gcc_assert (a && AT_class (a) == dw_val_class_str);
7258 node = a->dw_attr_val.v.val_str;
7262 len = strlen (node->str) + 1;
7264 /* If the string is shorter or equal to the size of the reference, it is
7265 always better to put it inline. */
7266 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7267 return node->form = DW_FORM_string;
7269 /* If we cannot expect the linker to merge strings in .debug_str
7270 section, only put it into .debug_str if it is worth even in this
7272 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7273 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7274 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7275 return node->form = DW_FORM_string;
7277 gen_label_for_indirect_string (node);
7279 return node->form = DW_FORM_strp;
7282 /* Add a DIE reference attribute value to a DIE. */
7285 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7289 attr.dw_attr = attr_kind;
7290 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7291 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7292 attr.dw_attr_val.v.val_die_ref.external = 0;
7293 add_dwarf_attr (die, &attr);
7296 /* Add an AT_specification attribute to a DIE, and also make the back
7297 pointer from the specification to the definition. */
7300 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7302 add_AT_die_ref (die, DW_AT_specification, targ_die);
7303 gcc_assert (!targ_die->die_definition);
7304 targ_die->die_definition = die;
7307 static inline dw_die_ref
7308 AT_ref (dw_attr_ref a)
7310 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7311 return a->dw_attr_val.v.val_die_ref.die;
7315 AT_ref_external (dw_attr_ref a)
7317 if (a && AT_class (a) == dw_val_class_die_ref)
7318 return a->dw_attr_val.v.val_die_ref.external;
7324 set_AT_ref_external (dw_attr_ref a, int i)
7326 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7327 a->dw_attr_val.v.val_die_ref.external = i;
7330 /* Add an FDE reference attribute value to a DIE. */
7333 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7337 attr.dw_attr = attr_kind;
7338 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7339 attr.dw_attr_val.v.val_fde_index = targ_fde;
7340 add_dwarf_attr (die, &attr);
7343 /* Add a location description attribute value to a DIE. */
7346 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7350 attr.dw_attr = attr_kind;
7351 attr.dw_attr_val.val_class = dw_val_class_loc;
7352 attr.dw_attr_val.v.val_loc = loc;
7353 add_dwarf_attr (die, &attr);
7356 static inline dw_loc_descr_ref
7357 AT_loc (dw_attr_ref a)
7359 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7360 return a->dw_attr_val.v.val_loc;
7364 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7368 attr.dw_attr = attr_kind;
7369 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7370 attr.dw_attr_val.v.val_loc_list = loc_list;
7371 add_dwarf_attr (die, &attr);
7372 have_location_lists = true;
7375 static inline dw_loc_list_ref
7376 AT_loc_list (dw_attr_ref a)
7378 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7379 return a->dw_attr_val.v.val_loc_list;
7382 static inline dw_loc_list_ref *
7383 AT_loc_list_ptr (dw_attr_ref a)
7385 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7386 return &a->dw_attr_val.v.val_loc_list;
7389 /* Add an address constant attribute value to a DIE. */
7392 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7396 attr.dw_attr = attr_kind;
7397 attr.dw_attr_val.val_class = dw_val_class_addr;
7398 attr.dw_attr_val.v.val_addr = addr;
7399 add_dwarf_attr (die, &attr);
7402 /* Get the RTX from to an address DIE attribute. */
7405 AT_addr (dw_attr_ref a)
7407 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7408 return a->dw_attr_val.v.val_addr;
7411 /* Add a file attribute value to a DIE. */
7414 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7415 struct dwarf_file_data *fd)
7419 attr.dw_attr = attr_kind;
7420 attr.dw_attr_val.val_class = dw_val_class_file;
7421 attr.dw_attr_val.v.val_file = fd;
7422 add_dwarf_attr (die, &attr);
7425 /* Get the dwarf_file_data from a file DIE attribute. */
7427 static inline struct dwarf_file_data *
7428 AT_file (dw_attr_ref a)
7430 gcc_assert (a && AT_class (a) == dw_val_class_file);
7431 return a->dw_attr_val.v.val_file;
7434 /* Add a vms delta attribute value to a DIE. */
7437 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7438 const char *lbl1, const char *lbl2)
7442 attr.dw_attr = attr_kind;
7443 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7444 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7445 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7446 add_dwarf_attr (die, &attr);
7449 /* Add a label identifier attribute value to a DIE. */
7452 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7456 attr.dw_attr = attr_kind;
7457 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7458 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7459 add_dwarf_attr (die, &attr);
7462 /* Add a section offset attribute value to a DIE, an offset into the
7463 debug_line section. */
7466 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7471 attr.dw_attr = attr_kind;
7472 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7473 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7474 add_dwarf_attr (die, &attr);
7477 /* Add a section offset attribute value to a DIE, an offset into the
7478 debug_macinfo section. */
7481 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7486 attr.dw_attr = attr_kind;
7487 attr.dw_attr_val.val_class = dw_val_class_macptr;
7488 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7489 add_dwarf_attr (die, &attr);
7492 /* Add an offset attribute value to a DIE. */
7495 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7496 unsigned HOST_WIDE_INT offset)
7500 attr.dw_attr = attr_kind;
7501 attr.dw_attr_val.val_class = dw_val_class_offset;
7502 attr.dw_attr_val.v.val_offset = offset;
7503 add_dwarf_attr (die, &attr);
7506 /* Add an range_list attribute value to a DIE. */
7509 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7510 long unsigned int offset)
7514 attr.dw_attr = attr_kind;
7515 attr.dw_attr_val.val_class = dw_val_class_range_list;
7516 attr.dw_attr_val.v.val_offset = offset;
7517 add_dwarf_attr (die, &attr);
7520 /* Return the start label of a delta attribute. */
7522 static inline const char *
7523 AT_vms_delta1 (dw_attr_ref a)
7525 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7526 return a->dw_attr_val.v.val_vms_delta.lbl1;
7529 /* Return the end label of a delta attribute. */
7531 static inline const char *
7532 AT_vms_delta2 (dw_attr_ref a)
7534 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7535 return a->dw_attr_val.v.val_vms_delta.lbl2;
7538 static inline const char *
7539 AT_lbl (dw_attr_ref a)
7541 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7542 || AT_class (a) == dw_val_class_lineptr
7543 || AT_class (a) == dw_val_class_macptr));
7544 return a->dw_attr_val.v.val_lbl_id;
7547 /* Get the attribute of type attr_kind. */
7550 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7554 dw_die_ref spec = NULL;
7559 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7560 if (a->dw_attr == attr_kind)
7562 else if (a->dw_attr == DW_AT_specification
7563 || a->dw_attr == DW_AT_abstract_origin)
7567 return get_AT (spec, attr_kind);
7572 /* Return the "low pc" attribute value, typically associated with a subprogram
7573 DIE. Return null if the "low pc" attribute is either not present, or if it
7574 cannot be represented as an assembler label identifier. */
7576 static inline const char *
7577 get_AT_low_pc (dw_die_ref die)
7579 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7581 return a ? AT_lbl (a) : NULL;
7584 /* Return the "high pc" attribute value, typically associated with a subprogram
7585 DIE. Return null if the "high pc" attribute is either not present, or if it
7586 cannot be represented as an assembler label identifier. */
7588 static inline const char *
7589 get_AT_hi_pc (dw_die_ref die)
7591 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7593 return a ? AT_lbl (a) : NULL;
7596 /* Return the value of the string attribute designated by ATTR_KIND, or
7597 NULL if it is not present. */
7599 static inline const char *
7600 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7602 dw_attr_ref a = get_AT (die, attr_kind);
7604 return a ? AT_string (a) : NULL;
7607 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7608 if it is not present. */
7611 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7613 dw_attr_ref a = get_AT (die, attr_kind);
7615 return a ? AT_flag (a) : 0;
7618 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7619 if it is not present. */
7621 static inline unsigned
7622 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7624 dw_attr_ref a = get_AT (die, attr_kind);
7626 return a ? AT_unsigned (a) : 0;
7629 static inline dw_die_ref
7630 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7632 dw_attr_ref a = get_AT (die, attr_kind);
7634 return a ? AT_ref (a) : NULL;
7637 static inline struct dwarf_file_data *
7638 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7640 dw_attr_ref a = get_AT (die, attr_kind);
7642 return a ? AT_file (a) : NULL;
7645 /* Return TRUE if the language is C++. */
7650 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7652 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7655 /* Return TRUE if the language is Fortran. */
7660 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7662 return (lang == DW_LANG_Fortran77
7663 || lang == DW_LANG_Fortran90
7664 || lang == DW_LANG_Fortran95);
7667 /* Return TRUE if the language is Ada. */
7672 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7674 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7677 /* Remove the specified attribute if present. */
7680 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7688 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7689 if (a->dw_attr == attr_kind)
7691 if (AT_class (a) == dw_val_class_str)
7692 if (a->dw_attr_val.v.val_str->refcount)
7693 a->dw_attr_val.v.val_str->refcount--;
7695 /* VEC_ordered_remove should help reduce the number of abbrevs
7697 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7702 /* Remove CHILD from its parent. PREV must have the property that
7703 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7706 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7708 gcc_assert (child->die_parent == prev->die_parent);
7709 gcc_assert (prev->die_sib == child);
7712 gcc_assert (child->die_parent->die_child == child);
7716 prev->die_sib = child->die_sib;
7717 if (child->die_parent->die_child == child)
7718 child->die_parent->die_child = prev;
7721 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7722 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7725 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
7727 dw_die_ref parent = old_child->die_parent;
7729 gcc_assert (parent == prev->die_parent);
7730 gcc_assert (prev->die_sib == old_child);
7732 new_child->die_parent = parent;
7733 if (prev == old_child)
7735 gcc_assert (parent->die_child == old_child);
7736 new_child->die_sib = new_child;
7740 prev->die_sib = new_child;
7741 new_child->die_sib = old_child->die_sib;
7743 if (old_child->die_parent->die_child == old_child)
7744 old_child->die_parent->die_child = new_child;
7747 /* Move all children from OLD_PARENT to NEW_PARENT. */
7750 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
7753 new_parent->die_child = old_parent->die_child;
7754 old_parent->die_child = NULL;
7755 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
7758 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7762 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7768 dw_die_ref prev = c;
7770 while (c->die_tag == tag)
7772 remove_child_with_prev (c, prev);
7773 /* Might have removed every child. */
7774 if (c == c->die_sib)
7778 } while (c != die->die_child);
7781 /* Add a CHILD_DIE as the last child of DIE. */
7784 add_child_die (dw_die_ref die, dw_die_ref child_die)
7786 /* FIXME this should probably be an assert. */
7787 if (! die || ! child_die)
7789 gcc_assert (die != child_die);
7791 child_die->die_parent = die;
7794 child_die->die_sib = die->die_child->die_sib;
7795 die->die_child->die_sib = child_die;
7798 child_die->die_sib = child_die;
7799 die->die_child = child_die;
7802 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7803 is the specification, to the end of PARENT's list of children.
7804 This is done by removing and re-adding it. */
7807 splice_child_die (dw_die_ref parent, dw_die_ref child)
7811 /* We want the declaration DIE from inside the class, not the
7812 specification DIE at toplevel. */
7813 if (child->die_parent != parent)
7815 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7821 gcc_assert (child->die_parent == parent
7822 || (child->die_parent
7823 == get_AT_ref (parent, DW_AT_specification)));
7825 for (p = child->die_parent->die_child; ; p = p->die_sib)
7826 if (p->die_sib == child)
7828 remove_child_with_prev (child, p);
7832 add_child_die (parent, child);
7835 /* Return a pointer to a newly created DIE node. */
7837 static inline dw_die_ref
7838 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
7840 dw_die_ref die = ggc_alloc_cleared_die_node ();
7842 die->die_tag = tag_value;
7844 if (parent_die != NULL)
7845 add_child_die (parent_die, die);
7848 limbo_die_node *limbo_node;
7850 limbo_node = ggc_alloc_cleared_limbo_die_node ();
7851 limbo_node->die = die;
7852 limbo_node->created_for = t;
7853 limbo_node->next = limbo_die_list;
7854 limbo_die_list = limbo_node;
7860 /* Return the DIE associated with the given type specifier. */
7862 static inline dw_die_ref
7863 lookup_type_die (tree type)
7865 return TYPE_SYMTAB_DIE (type);
7868 /* Equate a DIE to a given type specifier. */
7871 equate_type_number_to_die (tree type, dw_die_ref type_die)
7873 TYPE_SYMTAB_DIE (type) = type_die;
7876 /* Returns a hash value for X (which really is a die_struct). */
7879 decl_die_table_hash (const void *x)
7881 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7884 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7887 decl_die_table_eq (const void *x, const void *y)
7889 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7892 /* Return the DIE associated with a given declaration. */
7894 static inline dw_die_ref
7895 lookup_decl_die (tree decl)
7897 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7900 /* Returns a hash value for X (which really is a var_loc_list). */
7903 decl_loc_table_hash (const void *x)
7905 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7908 /* Return nonzero if decl_id of var_loc_list X is the same as
7912 decl_loc_table_eq (const void *x, const void *y)
7914 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7917 /* Return the var_loc list associated with a given declaration. */
7919 static inline var_loc_list *
7920 lookup_decl_loc (const_tree decl)
7922 if (!decl_loc_table)
7924 return (var_loc_list *)
7925 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7928 /* Equate a DIE to a particular declaration. */
7931 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7933 unsigned int decl_id = DECL_UID (decl);
7936 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7938 decl_die->decl_id = decl_id;
7941 /* Return how many bits covers PIECE EXPR_LIST. */
7944 decl_piece_bitsize (rtx piece)
7946 int ret = (int) GET_MODE (piece);
7949 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
7950 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
7951 return INTVAL (XEXP (XEXP (piece, 0), 0));
7954 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
7957 decl_piece_varloc_ptr (rtx piece)
7959 if ((int) GET_MODE (piece))
7960 return &XEXP (piece, 0);
7962 return &XEXP (XEXP (piece, 0), 1);
7965 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
7966 Next is the chain of following piece nodes. */
7969 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
7971 if (bitsize <= (int) MAX_MACHINE_MODE)
7972 return alloc_EXPR_LIST (bitsize, loc_note, next);
7974 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
7979 /* Return rtx that should be stored into loc field for
7980 LOC_NOTE and BITPOS/BITSIZE. */
7983 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
7984 HOST_WIDE_INT bitsize)
7988 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
7990 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
7995 /* This function either modifies location piece list *DEST in
7996 place (if SRC and INNER is NULL), or copies location piece list
7997 *SRC to *DEST while modifying it. Location BITPOS is modified
7998 to contain LOC_NOTE, any pieces overlapping it are removed resp.
7999 not copied and if needed some padding around it is added.
8000 When modifying in place, DEST should point to EXPR_LIST where
8001 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8002 to the start of the whole list and INNER points to the EXPR_LIST
8003 where earlier pieces cover PIECE_BITPOS bits. */
8006 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8007 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8008 HOST_WIDE_INT bitsize, rtx loc_note)
8011 bool copy = inner != NULL;
8015 /* First copy all nodes preceeding the current bitpos. */
8016 while (src != inner)
8018 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8019 decl_piece_bitsize (*src), NULL_RTX);
8020 dest = &XEXP (*dest, 1);
8021 src = &XEXP (*src, 1);
8024 /* Add padding if needed. */
8025 if (bitpos != piece_bitpos)
8027 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8028 copy ? NULL_RTX : *dest);
8029 dest = &XEXP (*dest, 1);
8031 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8034 /* A piece with correct bitpos and bitsize already exist,
8035 just update the location for it and return. */
8036 *decl_piece_varloc_ptr (*dest) = loc_note;
8039 /* Add the piece that changed. */
8040 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8041 dest = &XEXP (*dest, 1);
8042 /* Skip over pieces that overlap it. */
8043 diff = bitpos - piece_bitpos + bitsize;
8046 while (diff > 0 && *src)
8049 diff -= decl_piece_bitsize (piece);
8051 src = &XEXP (piece, 1);
8054 *src = XEXP (piece, 1);
8055 free_EXPR_LIST_node (piece);
8058 /* Add padding if needed. */
8059 if (diff < 0 && *src)
8063 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8064 dest = &XEXP (*dest, 1);
8068 /* Finally copy all nodes following it. */
8071 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8072 decl_piece_bitsize (*src), NULL_RTX);
8073 dest = &XEXP (*dest, 1);
8074 src = &XEXP (*src, 1);
8078 /* Add a variable location node to the linked list for DECL. */
8080 static struct var_loc_node *
8081 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8083 unsigned int decl_id;
8086 struct var_loc_node *loc = NULL;
8087 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8089 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8091 tree realdecl = DECL_DEBUG_EXPR (decl);
8092 if (realdecl && handled_component_p (realdecl))
8094 HOST_WIDE_INT maxsize;
8097 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8098 if (!DECL_P (innerdecl)
8099 || DECL_IGNORED_P (innerdecl)
8100 || TREE_STATIC (innerdecl)
8102 || bitpos + bitsize > 256
8103 || bitsize != maxsize)
8109 decl_id = DECL_UID (decl);
8110 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8113 temp = ggc_alloc_cleared_var_loc_list ();
8114 temp->decl_id = decl_id;
8118 temp = (var_loc_list *) *slot;
8122 struct var_loc_node *last = temp->last, *unused = NULL;
8123 rtx *piece_loc = NULL, last_loc_note;
8124 int piece_bitpos = 0;
8128 gcc_assert (last->next == NULL);
8130 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8132 piece_loc = &last->loc;
8135 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8136 if (piece_bitpos + cur_bitsize > bitpos)
8138 piece_bitpos += cur_bitsize;
8139 piece_loc = &XEXP (*piece_loc, 1);
8143 /* TEMP->LAST here is either pointer to the last but one or
8144 last element in the chained list, LAST is pointer to the
8146 if (label && strcmp (last->label, label) == 0)
8148 /* For SRA optimized variables if there weren't any real
8149 insns since last note, just modify the last node. */
8150 if (piece_loc != NULL)
8152 adjust_piece_list (piece_loc, NULL, NULL,
8153 bitpos, piece_bitpos, bitsize, loc_note);
8156 /* If the last note doesn't cover any instructions, remove it. */
8157 if (temp->last != last)
8159 temp->last->next = NULL;
8162 gcc_assert (strcmp (last->label, label) != 0);
8166 gcc_assert (temp->first == temp->last);
8167 memset (temp->last, '\0', sizeof (*temp->last));
8168 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8172 if (bitsize == -1 && NOTE_P (last->loc))
8173 last_loc_note = last->loc;
8174 else if (piece_loc != NULL
8175 && *piece_loc != NULL_RTX
8176 && piece_bitpos == bitpos
8177 && decl_piece_bitsize (*piece_loc) == bitsize)
8178 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8180 last_loc_note = NULL_RTX;
8181 /* If the current location is the same as the end of the list,
8182 and either both or neither of the locations is uninitialized,
8183 we have nothing to do. */
8184 if (last_loc_note == NULL_RTX
8185 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8186 NOTE_VAR_LOCATION_LOC (loc_note)))
8187 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8188 != NOTE_VAR_LOCATION_STATUS (loc_note))
8189 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8190 == VAR_INIT_STATUS_UNINITIALIZED)
8191 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8192 == VAR_INIT_STATUS_UNINITIALIZED))))
8194 /* Add LOC to the end of list and update LAST. If the last
8195 element of the list has been removed above, reuse its
8196 memory for the new node, otherwise allocate a new one. */
8200 memset (loc, '\0', sizeof (*loc));
8203 loc = ggc_alloc_cleared_var_loc_node ();
8204 if (bitsize == -1 || piece_loc == NULL)
8205 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8207 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8208 bitpos, piece_bitpos, bitsize, loc_note);
8210 /* Ensure TEMP->LAST will point either to the new last but one
8211 element of the chain, or to the last element in it. */
8212 if (last != temp->last)
8220 loc = ggc_alloc_cleared_var_loc_node ();
8223 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8228 /* Keep track of the number of spaces used to indent the
8229 output of the debugging routines that print the structure of
8230 the DIE internal representation. */
8231 static int print_indent;
8233 /* Indent the line the number of spaces given by print_indent. */
8236 print_spaces (FILE *outfile)
8238 fprintf (outfile, "%*s", print_indent, "");
8241 /* Print a type signature in hex. */
8244 print_signature (FILE *outfile, char *sig)
8248 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8249 fprintf (outfile, "%02x", sig[i] & 0xff);
8252 /* Print the information associated with a given DIE, and its children.
8253 This routine is a debugging aid only. */
8256 print_die (dw_die_ref die, FILE *outfile)
8262 print_spaces (outfile);
8263 fprintf (outfile, "DIE %4ld: %s\n",
8264 die->die_offset, dwarf_tag_name (die->die_tag));
8265 print_spaces (outfile);
8266 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8267 fprintf (outfile, " offset: %ld\n", die->die_offset);
8268 if (dwarf_version >= 4 && die->die_id.die_type_node)
8270 print_spaces (outfile);
8271 fprintf (outfile, " signature: ");
8272 print_signature (outfile, die->die_id.die_type_node->signature);
8273 fprintf (outfile, "\n");
8276 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8278 print_spaces (outfile);
8279 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8281 switch (AT_class (a))
8283 case dw_val_class_addr:
8284 fprintf (outfile, "address");
8286 case dw_val_class_offset:
8287 fprintf (outfile, "offset");
8289 case dw_val_class_loc:
8290 fprintf (outfile, "location descriptor");
8292 case dw_val_class_loc_list:
8293 fprintf (outfile, "location list -> label:%s",
8294 AT_loc_list (a)->ll_symbol);
8296 case dw_val_class_range_list:
8297 fprintf (outfile, "range list");
8299 case dw_val_class_const:
8300 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8302 case dw_val_class_unsigned_const:
8303 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8305 case dw_val_class_const_double:
8306 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8307 HOST_WIDE_INT_PRINT_UNSIGNED")",
8308 a->dw_attr_val.v.val_double.high,
8309 a->dw_attr_val.v.val_double.low);
8311 case dw_val_class_vec:
8312 fprintf (outfile, "floating-point or vector constant");
8314 case dw_val_class_flag:
8315 fprintf (outfile, "%u", AT_flag (a));
8317 case dw_val_class_die_ref:
8318 if (AT_ref (a) != NULL)
8320 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8322 fprintf (outfile, "die -> signature: ");
8323 print_signature (outfile,
8324 AT_ref (a)->die_id.die_type_node->signature);
8326 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8327 fprintf (outfile, "die -> label: %s",
8328 AT_ref (a)->die_id.die_symbol);
8330 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8333 fprintf (outfile, "die -> <null>");
8335 case dw_val_class_vms_delta:
8336 fprintf (outfile, "delta: @slotcount(%s-%s)",
8337 AT_vms_delta2 (a), AT_vms_delta1 (a));
8339 case dw_val_class_lbl_id:
8340 case dw_val_class_lineptr:
8341 case dw_val_class_macptr:
8342 fprintf (outfile, "label: %s", AT_lbl (a));
8344 case dw_val_class_str:
8345 if (AT_string (a) != NULL)
8346 fprintf (outfile, "\"%s\"", AT_string (a));
8348 fprintf (outfile, "<null>");
8350 case dw_val_class_file:
8351 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8352 AT_file (a)->emitted_number);
8354 case dw_val_class_data8:
8358 for (i = 0; i < 8; i++)
8359 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8366 fprintf (outfile, "\n");
8369 if (die->die_child != NULL)
8372 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8375 if (print_indent == 0)
8376 fprintf (outfile, "\n");
8379 /* Print the contents of the source code line number correspondence table.
8380 This routine is a debugging aid only. */
8383 print_dwarf_line_table (FILE *outfile)
8386 dw_line_info_ref line_info;
8388 fprintf (outfile, "\n\nDWARF source line information\n");
8389 for (i = 1; i < line_info_table_in_use; i++)
8391 line_info = &line_info_table[i];
8392 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8393 line_info->dw_file_num,
8394 line_info->dw_line_num);
8397 fprintf (outfile, "\n\n");
8400 /* Print the information collected for a given DIE. */
8403 debug_dwarf_die (dw_die_ref die)
8405 print_die (die, stderr);
8408 /* Print all DWARF information collected for the compilation unit.
8409 This routine is a debugging aid only. */
8415 print_die (comp_unit_die, stderr);
8416 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8417 print_dwarf_line_table (stderr);
8420 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8421 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8422 DIE that marks the start of the DIEs for this include file. */
8425 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8427 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8428 dw_die_ref new_unit = gen_compile_unit_die (filename);
8430 new_unit->die_sib = old_unit;
8434 /* Close an include-file CU and reopen the enclosing one. */
8437 pop_compile_unit (dw_die_ref old_unit)
8439 dw_die_ref new_unit = old_unit->die_sib;
8441 old_unit->die_sib = NULL;
8445 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8446 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8448 /* Calculate the checksum of a location expression. */
8451 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8455 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8457 CHECKSUM (loc->dw_loc_oprnd1);
8458 CHECKSUM (loc->dw_loc_oprnd2);
8461 /* Calculate the checksum of an attribute. */
8464 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8466 dw_loc_descr_ref loc;
8469 CHECKSUM (at->dw_attr);
8471 /* We don't care that this was compiled with a different compiler
8472 snapshot; if the output is the same, that's what matters. */
8473 if (at->dw_attr == DW_AT_producer)
8476 switch (AT_class (at))
8478 case dw_val_class_const:
8479 CHECKSUM (at->dw_attr_val.v.val_int);
8481 case dw_val_class_unsigned_const:
8482 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8484 case dw_val_class_const_double:
8485 CHECKSUM (at->dw_attr_val.v.val_double);
8487 case dw_val_class_vec:
8488 CHECKSUM (at->dw_attr_val.v.val_vec);
8490 case dw_val_class_flag:
8491 CHECKSUM (at->dw_attr_val.v.val_flag);
8493 case dw_val_class_str:
8494 CHECKSUM_STRING (AT_string (at));
8497 case dw_val_class_addr:
8499 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8500 CHECKSUM_STRING (XSTR (r, 0));
8503 case dw_val_class_offset:
8504 CHECKSUM (at->dw_attr_val.v.val_offset);
8507 case dw_val_class_loc:
8508 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8509 loc_checksum (loc, ctx);
8512 case dw_val_class_die_ref:
8513 die_checksum (AT_ref (at), ctx, mark);
8516 case dw_val_class_fde_ref:
8517 case dw_val_class_vms_delta:
8518 case dw_val_class_lbl_id:
8519 case dw_val_class_lineptr:
8520 case dw_val_class_macptr:
8523 case dw_val_class_file:
8524 CHECKSUM_STRING (AT_file (at)->filename);
8527 case dw_val_class_data8:
8528 CHECKSUM (at->dw_attr_val.v.val_data8);
8536 /* Calculate the checksum of a DIE. */
8539 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8545 /* To avoid infinite recursion. */
8548 CHECKSUM (die->die_mark);
8551 die->die_mark = ++(*mark);
8553 CHECKSUM (die->die_tag);
8555 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8556 attr_checksum (a, ctx, mark);
8558 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8562 #undef CHECKSUM_STRING
8564 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8565 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8566 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8567 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8568 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8569 #define CHECKSUM_ATTR(FOO) \
8570 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8572 /* Calculate the checksum of a number in signed LEB128 format. */
8575 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8582 byte = (value & 0x7f);
8584 more = !((value == 0 && (byte & 0x40) == 0)
8585 || (value == -1 && (byte & 0x40) != 0));
8594 /* Calculate the checksum of a number in unsigned LEB128 format. */
8597 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8601 unsigned char byte = (value & 0x7f);
8604 /* More bytes to follow. */
8612 /* Checksum the context of the DIE. This adds the names of any
8613 surrounding namespaces or structures to the checksum. */
8616 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8620 int tag = die->die_tag;
8622 if (tag != DW_TAG_namespace
8623 && tag != DW_TAG_structure_type
8624 && tag != DW_TAG_class_type)
8627 name = get_AT_string (die, DW_AT_name);
8629 spec = get_AT_ref (die, DW_AT_specification);
8633 if (die->die_parent != NULL)
8634 checksum_die_context (die->die_parent, ctx);
8636 CHECKSUM_ULEB128 ('C');
8637 CHECKSUM_ULEB128 (tag);
8639 CHECKSUM_STRING (name);
8642 /* Calculate the checksum of a location expression. */
8645 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8647 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8648 were emitted as a DW_FORM_sdata instead of a location expression. */
8649 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8651 CHECKSUM_ULEB128 (DW_FORM_sdata);
8652 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8656 /* Otherwise, just checksum the raw location expression. */
8659 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8660 CHECKSUM (loc->dw_loc_oprnd1);
8661 CHECKSUM (loc->dw_loc_oprnd2);
8662 loc = loc->dw_loc_next;
8666 /* Calculate the checksum of an attribute. */
8669 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8670 struct md5_ctx *ctx, int *mark)
8672 dw_loc_descr_ref loc;
8675 if (AT_class (at) == dw_val_class_die_ref)
8677 dw_die_ref target_die = AT_ref (at);
8679 /* For pointer and reference types, we checksum only the (qualified)
8680 name of the target type (if there is a name). For friend entries,
8681 we checksum only the (qualified) name of the target type or function.
8682 This allows the checksum to remain the same whether the target type
8683 is complete or not. */
8684 if ((at->dw_attr == DW_AT_type
8685 && (tag == DW_TAG_pointer_type
8686 || tag == DW_TAG_reference_type
8687 || tag == DW_TAG_rvalue_reference_type
8688 || tag == DW_TAG_ptr_to_member_type))
8689 || (at->dw_attr == DW_AT_friend
8690 && tag == DW_TAG_friend))
8692 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
8694 if (name_attr != NULL)
8696 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8700 CHECKSUM_ULEB128 ('N');
8701 CHECKSUM_ULEB128 (at->dw_attr);
8702 if (decl->die_parent != NULL)
8703 checksum_die_context (decl->die_parent, ctx);
8704 CHECKSUM_ULEB128 ('E');
8705 CHECKSUM_STRING (AT_string (name_attr));
8710 /* For all other references to another DIE, we check to see if the
8711 target DIE has already been visited. If it has, we emit a
8712 backward reference; if not, we descend recursively. */
8713 if (target_die->die_mark > 0)
8715 CHECKSUM_ULEB128 ('R');
8716 CHECKSUM_ULEB128 (at->dw_attr);
8717 CHECKSUM_ULEB128 (target_die->die_mark);
8721 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8725 target_die->die_mark = ++(*mark);
8726 CHECKSUM_ULEB128 ('T');
8727 CHECKSUM_ULEB128 (at->dw_attr);
8728 if (decl->die_parent != NULL)
8729 checksum_die_context (decl->die_parent, ctx);
8730 die_checksum_ordered (target_die, ctx, mark);
8735 CHECKSUM_ULEB128 ('A');
8736 CHECKSUM_ULEB128 (at->dw_attr);
8738 switch (AT_class (at))
8740 case dw_val_class_const:
8741 CHECKSUM_ULEB128 (DW_FORM_sdata);
8742 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
8745 case dw_val_class_unsigned_const:
8746 CHECKSUM_ULEB128 (DW_FORM_sdata);
8747 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
8750 case dw_val_class_const_double:
8751 CHECKSUM_ULEB128 (DW_FORM_block);
8752 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
8753 CHECKSUM (at->dw_attr_val.v.val_double);
8756 case dw_val_class_vec:
8757 CHECKSUM_ULEB128 (DW_FORM_block);
8758 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
8759 CHECKSUM (at->dw_attr_val.v.val_vec);
8762 case dw_val_class_flag:
8763 CHECKSUM_ULEB128 (DW_FORM_flag);
8764 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
8767 case dw_val_class_str:
8768 CHECKSUM_ULEB128 (DW_FORM_string);
8769 CHECKSUM_STRING (AT_string (at));
8772 case dw_val_class_addr:
8774 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8775 CHECKSUM_ULEB128 (DW_FORM_string);
8776 CHECKSUM_STRING (XSTR (r, 0));
8779 case dw_val_class_offset:
8780 CHECKSUM_ULEB128 (DW_FORM_sdata);
8781 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
8784 case dw_val_class_loc:
8785 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8786 loc_checksum_ordered (loc, ctx);
8789 case dw_val_class_fde_ref:
8790 case dw_val_class_lbl_id:
8791 case dw_val_class_lineptr:
8792 case dw_val_class_macptr:
8795 case dw_val_class_file:
8796 CHECKSUM_ULEB128 (DW_FORM_string);
8797 CHECKSUM_STRING (AT_file (at)->filename);
8800 case dw_val_class_data8:
8801 CHECKSUM (at->dw_attr_val.v.val_data8);
8809 struct checksum_attributes
8811 dw_attr_ref at_name;
8812 dw_attr_ref at_type;
8813 dw_attr_ref at_friend;
8814 dw_attr_ref at_accessibility;
8815 dw_attr_ref at_address_class;
8816 dw_attr_ref at_allocated;
8817 dw_attr_ref at_artificial;
8818 dw_attr_ref at_associated;
8819 dw_attr_ref at_binary_scale;
8820 dw_attr_ref at_bit_offset;
8821 dw_attr_ref at_bit_size;
8822 dw_attr_ref at_bit_stride;
8823 dw_attr_ref at_byte_size;
8824 dw_attr_ref at_byte_stride;
8825 dw_attr_ref at_const_value;
8826 dw_attr_ref at_containing_type;
8827 dw_attr_ref at_count;
8828 dw_attr_ref at_data_location;
8829 dw_attr_ref at_data_member_location;
8830 dw_attr_ref at_decimal_scale;
8831 dw_attr_ref at_decimal_sign;
8832 dw_attr_ref at_default_value;
8833 dw_attr_ref at_digit_count;
8834 dw_attr_ref at_discr;
8835 dw_attr_ref at_discr_list;
8836 dw_attr_ref at_discr_value;
8837 dw_attr_ref at_encoding;
8838 dw_attr_ref at_endianity;
8839 dw_attr_ref at_explicit;
8840 dw_attr_ref at_is_optional;
8841 dw_attr_ref at_location;
8842 dw_attr_ref at_lower_bound;
8843 dw_attr_ref at_mutable;
8844 dw_attr_ref at_ordering;
8845 dw_attr_ref at_picture_string;
8846 dw_attr_ref at_prototyped;
8847 dw_attr_ref at_small;
8848 dw_attr_ref at_segment;
8849 dw_attr_ref at_string_length;
8850 dw_attr_ref at_threads_scaled;
8851 dw_attr_ref at_upper_bound;
8852 dw_attr_ref at_use_location;
8853 dw_attr_ref at_use_UTF8;
8854 dw_attr_ref at_variable_parameter;
8855 dw_attr_ref at_virtuality;
8856 dw_attr_ref at_visibility;
8857 dw_attr_ref at_vtable_elem_location;
8860 /* Collect the attributes that we will want to use for the checksum. */
8863 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
8868 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8879 attrs->at_friend = a;
8881 case DW_AT_accessibility:
8882 attrs->at_accessibility = a;
8884 case DW_AT_address_class:
8885 attrs->at_address_class = a;
8887 case DW_AT_allocated:
8888 attrs->at_allocated = a;
8890 case DW_AT_artificial:
8891 attrs->at_artificial = a;
8893 case DW_AT_associated:
8894 attrs->at_associated = a;
8896 case DW_AT_binary_scale:
8897 attrs->at_binary_scale = a;
8899 case DW_AT_bit_offset:
8900 attrs->at_bit_offset = a;
8902 case DW_AT_bit_size:
8903 attrs->at_bit_size = a;
8905 case DW_AT_bit_stride:
8906 attrs->at_bit_stride = a;
8908 case DW_AT_byte_size:
8909 attrs->at_byte_size = a;
8911 case DW_AT_byte_stride:
8912 attrs->at_byte_stride = a;
8914 case DW_AT_const_value:
8915 attrs->at_const_value = a;
8917 case DW_AT_containing_type:
8918 attrs->at_containing_type = a;
8921 attrs->at_count = a;
8923 case DW_AT_data_location:
8924 attrs->at_data_location = a;
8926 case DW_AT_data_member_location:
8927 attrs->at_data_member_location = a;
8929 case DW_AT_decimal_scale:
8930 attrs->at_decimal_scale = a;
8932 case DW_AT_decimal_sign:
8933 attrs->at_decimal_sign = a;
8935 case DW_AT_default_value:
8936 attrs->at_default_value = a;
8938 case DW_AT_digit_count:
8939 attrs->at_digit_count = a;
8942 attrs->at_discr = a;
8944 case DW_AT_discr_list:
8945 attrs->at_discr_list = a;
8947 case DW_AT_discr_value:
8948 attrs->at_discr_value = a;
8950 case DW_AT_encoding:
8951 attrs->at_encoding = a;
8953 case DW_AT_endianity:
8954 attrs->at_endianity = a;
8956 case DW_AT_explicit:
8957 attrs->at_explicit = a;
8959 case DW_AT_is_optional:
8960 attrs->at_is_optional = a;
8962 case DW_AT_location:
8963 attrs->at_location = a;
8965 case DW_AT_lower_bound:
8966 attrs->at_lower_bound = a;
8969 attrs->at_mutable = a;
8971 case DW_AT_ordering:
8972 attrs->at_ordering = a;
8974 case DW_AT_picture_string:
8975 attrs->at_picture_string = a;
8977 case DW_AT_prototyped:
8978 attrs->at_prototyped = a;
8981 attrs->at_small = a;
8984 attrs->at_segment = a;
8986 case DW_AT_string_length:
8987 attrs->at_string_length = a;
8989 case DW_AT_threads_scaled:
8990 attrs->at_threads_scaled = a;
8992 case DW_AT_upper_bound:
8993 attrs->at_upper_bound = a;
8995 case DW_AT_use_location:
8996 attrs->at_use_location = a;
8998 case DW_AT_use_UTF8:
8999 attrs->at_use_UTF8 = a;
9001 case DW_AT_variable_parameter:
9002 attrs->at_variable_parameter = a;
9004 case DW_AT_virtuality:
9005 attrs->at_virtuality = a;
9007 case DW_AT_visibility:
9008 attrs->at_visibility = a;
9010 case DW_AT_vtable_elem_location:
9011 attrs->at_vtable_elem_location = a;
9019 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9022 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9026 struct checksum_attributes attrs;
9028 CHECKSUM_ULEB128 ('D');
9029 CHECKSUM_ULEB128 (die->die_tag);
9031 memset (&attrs, 0, sizeof (attrs));
9033 decl = get_AT_ref (die, DW_AT_specification);
9035 collect_checksum_attributes (&attrs, decl);
9036 collect_checksum_attributes (&attrs, die);
9038 CHECKSUM_ATTR (attrs.at_name);
9039 CHECKSUM_ATTR (attrs.at_accessibility);
9040 CHECKSUM_ATTR (attrs.at_address_class);
9041 CHECKSUM_ATTR (attrs.at_allocated);
9042 CHECKSUM_ATTR (attrs.at_artificial);
9043 CHECKSUM_ATTR (attrs.at_associated);
9044 CHECKSUM_ATTR (attrs.at_binary_scale);
9045 CHECKSUM_ATTR (attrs.at_bit_offset);
9046 CHECKSUM_ATTR (attrs.at_bit_size);
9047 CHECKSUM_ATTR (attrs.at_bit_stride);
9048 CHECKSUM_ATTR (attrs.at_byte_size);
9049 CHECKSUM_ATTR (attrs.at_byte_stride);
9050 CHECKSUM_ATTR (attrs.at_const_value);
9051 CHECKSUM_ATTR (attrs.at_containing_type);
9052 CHECKSUM_ATTR (attrs.at_count);
9053 CHECKSUM_ATTR (attrs.at_data_location);
9054 CHECKSUM_ATTR (attrs.at_data_member_location);
9055 CHECKSUM_ATTR (attrs.at_decimal_scale);
9056 CHECKSUM_ATTR (attrs.at_decimal_sign);
9057 CHECKSUM_ATTR (attrs.at_default_value);
9058 CHECKSUM_ATTR (attrs.at_digit_count);
9059 CHECKSUM_ATTR (attrs.at_discr);
9060 CHECKSUM_ATTR (attrs.at_discr_list);
9061 CHECKSUM_ATTR (attrs.at_discr_value);
9062 CHECKSUM_ATTR (attrs.at_encoding);
9063 CHECKSUM_ATTR (attrs.at_endianity);
9064 CHECKSUM_ATTR (attrs.at_explicit);
9065 CHECKSUM_ATTR (attrs.at_is_optional);
9066 CHECKSUM_ATTR (attrs.at_location);
9067 CHECKSUM_ATTR (attrs.at_lower_bound);
9068 CHECKSUM_ATTR (attrs.at_mutable);
9069 CHECKSUM_ATTR (attrs.at_ordering);
9070 CHECKSUM_ATTR (attrs.at_picture_string);
9071 CHECKSUM_ATTR (attrs.at_prototyped);
9072 CHECKSUM_ATTR (attrs.at_small);
9073 CHECKSUM_ATTR (attrs.at_segment);
9074 CHECKSUM_ATTR (attrs.at_string_length);
9075 CHECKSUM_ATTR (attrs.at_threads_scaled);
9076 CHECKSUM_ATTR (attrs.at_upper_bound);
9077 CHECKSUM_ATTR (attrs.at_use_location);
9078 CHECKSUM_ATTR (attrs.at_use_UTF8);
9079 CHECKSUM_ATTR (attrs.at_variable_parameter);
9080 CHECKSUM_ATTR (attrs.at_virtuality);
9081 CHECKSUM_ATTR (attrs.at_visibility);
9082 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9083 CHECKSUM_ATTR (attrs.at_type);
9084 CHECKSUM_ATTR (attrs.at_friend);
9086 /* Checksum the child DIEs, except for nested types and member functions. */
9089 dw_attr_ref name_attr;
9092 name_attr = get_AT (c, DW_AT_name);
9093 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9094 && name_attr != NULL)
9096 CHECKSUM_ULEB128 ('S');
9097 CHECKSUM_ULEB128 (c->die_tag);
9098 CHECKSUM_STRING (AT_string (name_attr));
9102 /* Mark this DIE so it gets processed when unmarking. */
9103 if (c->die_mark == 0)
9105 die_checksum_ordered (c, ctx, mark);
9107 } while (c != die->die_child);
9109 CHECKSUM_ULEB128 (0);
9113 #undef CHECKSUM_STRING
9114 #undef CHECKSUM_ATTR
9115 #undef CHECKSUM_LEB128
9116 #undef CHECKSUM_ULEB128
9118 /* Generate the type signature for DIE. This is computed by generating an
9119 MD5 checksum over the DIE's tag, its relevant attributes, and its
9120 children. Attributes that are references to other DIEs are processed
9121 by recursion, using the MARK field to prevent infinite recursion.
9122 If the DIE is nested inside a namespace or another type, we also
9123 need to include that context in the signature. The lower 64 bits
9124 of the resulting MD5 checksum comprise the signature. */
9127 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9131 unsigned char checksum[16];
9135 name = get_AT_string (die, DW_AT_name);
9136 decl = get_AT_ref (die, DW_AT_specification);
9138 /* First, compute a signature for just the type name (and its surrounding
9139 context, if any. This is stored in the type unit DIE for link-time
9140 ODR (one-definition rule) checking. */
9142 if (is_cxx() && name != NULL)
9144 md5_init_ctx (&ctx);
9146 /* Checksum the names of surrounding namespaces and structures. */
9147 if (decl != NULL && decl->die_parent != NULL)
9148 checksum_die_context (decl->die_parent, &ctx);
9150 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9151 md5_process_bytes (name, strlen (name) + 1, &ctx);
9152 md5_finish_ctx (&ctx, checksum);
9154 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9157 /* Next, compute the complete type signature. */
9159 md5_init_ctx (&ctx);
9161 die->die_mark = mark;
9163 /* Checksum the names of surrounding namespaces and structures. */
9164 if (decl != NULL && decl->die_parent != NULL)
9165 checksum_die_context (decl->die_parent, &ctx);
9167 /* Checksum the DIE and its children. */
9168 die_checksum_ordered (die, &ctx, &mark);
9169 unmark_all_dies (die);
9170 md5_finish_ctx (&ctx, checksum);
9172 /* Store the signature in the type node and link the type DIE and the
9173 type node together. */
9174 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9175 DWARF_TYPE_SIGNATURE_SIZE);
9176 die->die_id.die_type_node = type_node;
9177 type_node->type_die = die;
9179 /* If the DIE is a specification, link its declaration to the type node
9182 decl->die_id.die_type_node = type_node;
9185 /* Do the location expressions look same? */
9187 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9189 return loc1->dw_loc_opc == loc2->dw_loc_opc
9190 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9191 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9194 /* Do the values look the same? */
9196 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9198 dw_loc_descr_ref loc1, loc2;
9201 if (v1->val_class != v2->val_class)
9204 switch (v1->val_class)
9206 case dw_val_class_const:
9207 return v1->v.val_int == v2->v.val_int;
9208 case dw_val_class_unsigned_const:
9209 return v1->v.val_unsigned == v2->v.val_unsigned;
9210 case dw_val_class_const_double:
9211 return v1->v.val_double.high == v2->v.val_double.high
9212 && v1->v.val_double.low == v2->v.val_double.low;
9213 case dw_val_class_vec:
9214 if (v1->v.val_vec.length != v2->v.val_vec.length
9215 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9217 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9218 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9221 case dw_val_class_flag:
9222 return v1->v.val_flag == v2->v.val_flag;
9223 case dw_val_class_str:
9224 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9226 case dw_val_class_addr:
9227 r1 = v1->v.val_addr;
9228 r2 = v2->v.val_addr;
9229 if (GET_CODE (r1) != GET_CODE (r2))
9231 return !rtx_equal_p (r1, r2);
9233 case dw_val_class_offset:
9234 return v1->v.val_offset == v2->v.val_offset;
9236 case dw_val_class_loc:
9237 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9239 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9240 if (!same_loc_p (loc1, loc2, mark))
9242 return !loc1 && !loc2;
9244 case dw_val_class_die_ref:
9245 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9247 case dw_val_class_fde_ref:
9248 case dw_val_class_vms_delta:
9249 case dw_val_class_lbl_id:
9250 case dw_val_class_lineptr:
9251 case dw_val_class_macptr:
9254 case dw_val_class_file:
9255 return v1->v.val_file == v2->v.val_file;
9257 case dw_val_class_data8:
9258 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9265 /* Do the attributes look the same? */
9268 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9270 if (at1->dw_attr != at2->dw_attr)
9273 /* We don't care that this was compiled with a different compiler
9274 snapshot; if the output is the same, that's what matters. */
9275 if (at1->dw_attr == DW_AT_producer)
9278 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9281 /* Do the dies look the same? */
9284 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9290 /* To avoid infinite recursion. */
9292 return die1->die_mark == die2->die_mark;
9293 die1->die_mark = die2->die_mark = ++(*mark);
9295 if (die1->die_tag != die2->die_tag)
9298 if (VEC_length (dw_attr_node, die1->die_attr)
9299 != VEC_length (dw_attr_node, die2->die_attr))
9302 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
9303 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9306 c1 = die1->die_child;
9307 c2 = die2->die_child;
9316 if (!same_die_p (c1, c2, mark))
9320 if (c1 == die1->die_child)
9322 if (c2 == die2->die_child)
9332 /* Do the dies look the same? Wrapper around same_die_p. */
9335 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9338 int ret = same_die_p (die1, die2, &mark);
9340 unmark_all_dies (die1);
9341 unmark_all_dies (die2);
9346 /* The prefix to attach to symbols on DIEs in the current comdat debug
9348 static char *comdat_symbol_id;
9350 /* The index of the current symbol within the current comdat CU. */
9351 static unsigned int comdat_symbol_number;
9353 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9354 children, and set comdat_symbol_id accordingly. */
9357 compute_section_prefix (dw_die_ref unit_die)
9359 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9360 const char *base = die_name ? lbasename (die_name) : "anonymous";
9361 char *name = XALLOCAVEC (char, strlen (base) + 64);
9364 unsigned char checksum[16];
9367 /* Compute the checksum of the DIE, then append part of it as hex digits to
9368 the name filename of the unit. */
9370 md5_init_ctx (&ctx);
9372 die_checksum (unit_die, &ctx, &mark);
9373 unmark_all_dies (unit_die);
9374 md5_finish_ctx (&ctx, checksum);
9376 sprintf (name, "%s.", base);
9377 clean_symbol_name (name);
9379 p = name + strlen (name);
9380 for (i = 0; i < 4; i++)
9382 sprintf (p, "%.2x", checksum[i]);
9386 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9387 comdat_symbol_number = 0;
9390 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9393 is_type_die (dw_die_ref die)
9395 switch (die->die_tag)
9397 case DW_TAG_array_type:
9398 case DW_TAG_class_type:
9399 case DW_TAG_interface_type:
9400 case DW_TAG_enumeration_type:
9401 case DW_TAG_pointer_type:
9402 case DW_TAG_reference_type:
9403 case DW_TAG_rvalue_reference_type:
9404 case DW_TAG_string_type:
9405 case DW_TAG_structure_type:
9406 case DW_TAG_subroutine_type:
9407 case DW_TAG_union_type:
9408 case DW_TAG_ptr_to_member_type:
9409 case DW_TAG_set_type:
9410 case DW_TAG_subrange_type:
9411 case DW_TAG_base_type:
9412 case DW_TAG_const_type:
9413 case DW_TAG_file_type:
9414 case DW_TAG_packed_type:
9415 case DW_TAG_volatile_type:
9416 case DW_TAG_typedef:
9423 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9424 Basically, we want to choose the bits that are likely to be shared between
9425 compilations (types) and leave out the bits that are specific to individual
9426 compilations (functions). */
9429 is_comdat_die (dw_die_ref c)
9431 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9432 we do for stabs. The advantage is a greater likelihood of sharing between
9433 objects that don't include headers in the same order (and therefore would
9434 put the base types in a different comdat). jason 8/28/00 */
9436 if (c->die_tag == DW_TAG_base_type)
9439 if (c->die_tag == DW_TAG_pointer_type
9440 || c->die_tag == DW_TAG_reference_type
9441 || c->die_tag == DW_TAG_rvalue_reference_type
9442 || c->die_tag == DW_TAG_const_type
9443 || c->die_tag == DW_TAG_volatile_type)
9445 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9447 return t ? is_comdat_die (t) : 0;
9450 return is_type_die (c);
9453 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9454 compilation unit. */
9457 is_symbol_die (dw_die_ref c)
9459 return (is_type_die (c)
9460 || is_declaration_die (c)
9461 || c->die_tag == DW_TAG_namespace
9462 || c->die_tag == DW_TAG_module);
9466 gen_internal_sym (const char *prefix)
9470 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9471 return xstrdup (buf);
9474 /* Assign symbols to all worthy DIEs under DIE. */
9477 assign_symbol_names (dw_die_ref die)
9481 if (is_symbol_die (die))
9483 if (comdat_symbol_id)
9485 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9487 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9488 comdat_symbol_id, comdat_symbol_number++);
9489 die->die_id.die_symbol = xstrdup (p);
9492 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9495 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9498 struct cu_hash_table_entry
9501 unsigned min_comdat_num, max_comdat_num;
9502 struct cu_hash_table_entry *next;
9505 /* Routines to manipulate hash table of CUs. */
9507 htab_cu_hash (const void *of)
9509 const struct cu_hash_table_entry *const entry =
9510 (const struct cu_hash_table_entry *) of;
9512 return htab_hash_string (entry->cu->die_id.die_symbol);
9516 htab_cu_eq (const void *of1, const void *of2)
9518 const struct cu_hash_table_entry *const entry1 =
9519 (const struct cu_hash_table_entry *) of1;
9520 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9522 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9526 htab_cu_del (void *what)
9528 struct cu_hash_table_entry *next,
9529 *entry = (struct cu_hash_table_entry *) what;
9539 /* Check whether we have already seen this CU and set up SYM_NUM
9542 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9544 struct cu_hash_table_entry dummy;
9545 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9547 dummy.max_comdat_num = 0;
9549 slot = (struct cu_hash_table_entry **)
9550 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9554 for (; entry; last = entry, entry = entry->next)
9556 if (same_die_p_wrap (cu, entry->cu))
9562 *sym_num = entry->min_comdat_num;
9566 entry = XCNEW (struct cu_hash_table_entry);
9568 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9569 entry->next = *slot;
9575 /* Record SYM_NUM to record of CU in HTABLE. */
9577 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9579 struct cu_hash_table_entry **slot, *entry;
9581 slot = (struct cu_hash_table_entry **)
9582 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9586 entry->max_comdat_num = sym_num;
9589 /* Traverse the DIE (which is always comp_unit_die), and set up
9590 additional compilation units for each of the include files we see
9591 bracketed by BINCL/EINCL. */
9594 break_out_includes (dw_die_ref die)
9597 dw_die_ref unit = NULL;
9598 limbo_die_node *node, **pnode;
9599 htab_t cu_hash_table;
9603 dw_die_ref prev = c;
9605 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9606 || (unit && is_comdat_die (c)))
9608 dw_die_ref next = c->die_sib;
9610 /* This DIE is for a secondary CU; remove it from the main one. */
9611 remove_child_with_prev (c, prev);
9613 if (c->die_tag == DW_TAG_GNU_BINCL)
9614 unit = push_new_compile_unit (unit, c);
9615 else if (c->die_tag == DW_TAG_GNU_EINCL)
9616 unit = pop_compile_unit (unit);
9618 add_child_die (unit, c);
9620 if (c == die->die_child)
9623 } while (c != die->die_child);
9626 /* We can only use this in debugging, since the frontend doesn't check
9627 to make sure that we leave every include file we enter. */
9631 assign_symbol_names (die);
9632 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9633 for (node = limbo_die_list, pnode = &limbo_die_list;
9639 compute_section_prefix (node->die);
9640 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9641 &comdat_symbol_number);
9642 assign_symbol_names (node->die);
9644 *pnode = node->next;
9647 pnode = &node->next;
9648 record_comdat_symbol_number (node->die, cu_hash_table,
9649 comdat_symbol_number);
9652 htab_delete (cu_hash_table);
9655 /* Return non-zero if this DIE is a declaration. */
9658 is_declaration_die (dw_die_ref die)
9663 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
9664 if (a->dw_attr == DW_AT_declaration)
9670 /* Return non-zero if this DIE is nested inside a subprogram. */
9673 is_nested_in_subprogram (dw_die_ref die)
9675 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
9679 return local_scope_p (decl);
9682 /* Return non-zero if this is a type DIE that should be moved to a
9683 COMDAT .debug_types section. */
9686 should_move_die_to_comdat (dw_die_ref die)
9688 switch (die->die_tag)
9690 case DW_TAG_class_type:
9691 case DW_TAG_structure_type:
9692 case DW_TAG_enumeration_type:
9693 case DW_TAG_union_type:
9694 /* Don't move declarations, inlined instances, or types nested in a
9696 if (is_declaration_die (die)
9697 || get_AT (die, DW_AT_abstract_origin)
9698 || is_nested_in_subprogram (die))
9701 case DW_TAG_array_type:
9702 case DW_TAG_interface_type:
9703 case DW_TAG_pointer_type:
9704 case DW_TAG_reference_type:
9705 case DW_TAG_rvalue_reference_type:
9706 case DW_TAG_string_type:
9707 case DW_TAG_subroutine_type:
9708 case DW_TAG_ptr_to_member_type:
9709 case DW_TAG_set_type:
9710 case DW_TAG_subrange_type:
9711 case DW_TAG_base_type:
9712 case DW_TAG_const_type:
9713 case DW_TAG_file_type:
9714 case DW_TAG_packed_type:
9715 case DW_TAG_volatile_type:
9716 case DW_TAG_typedef:
9722 /* Make a clone of DIE. */
9725 clone_die (dw_die_ref die)
9731 clone = ggc_alloc_cleared_die_node ();
9732 clone->die_tag = die->die_tag;
9734 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
9735 add_dwarf_attr (clone, a);
9740 /* Make a clone of the tree rooted at DIE. */
9743 clone_tree (dw_die_ref die)
9746 dw_die_ref clone = clone_die (die);
9748 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
9753 /* Make a clone of DIE as a declaration. */
9756 clone_as_declaration (dw_die_ref die)
9763 /* If the DIE is already a declaration, just clone it. */
9764 if (is_declaration_die (die))
9765 return clone_die (die);
9767 /* If the DIE is a specification, just clone its declaration DIE. */
9768 decl = get_AT_ref (die, DW_AT_specification);
9770 return clone_die (decl);
9772 clone = ggc_alloc_cleared_die_node ();
9773 clone->die_tag = die->die_tag;
9775 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
9777 /* We don't want to copy over all attributes.
9778 For example we don't want DW_AT_byte_size because otherwise we will no
9779 longer have a declaration and GDB will treat it as a definition. */
9783 case DW_AT_artificial:
9784 case DW_AT_containing_type:
9785 case DW_AT_external:
9788 case DW_AT_virtuality:
9789 case DW_AT_linkage_name:
9790 case DW_AT_MIPS_linkage_name:
9791 add_dwarf_attr (clone, a);
9793 case DW_AT_byte_size:
9799 if (die->die_id.die_type_node)
9800 add_AT_die_ref (clone, DW_AT_signature, die);
9802 add_AT_flag (clone, DW_AT_declaration, 1);
9806 /* Copy the declaration context to the new compile unit DIE. This includes
9807 any surrounding namespace or type declarations. If the DIE has an
9808 AT_specification attribute, it also includes attributes and children
9809 attached to the specification. */
9812 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
9815 dw_die_ref new_decl;
9817 decl = get_AT_ref (die, DW_AT_specification);
9826 /* Copy the type node pointer from the new DIE to the original
9827 declaration DIE so we can forward references later. */
9828 decl->die_id.die_type_node = die->die_id.die_type_node;
9830 remove_AT (die, DW_AT_specification);
9832 for (ix = 0; VEC_iterate (dw_attr_node, decl->die_attr, ix, a); ix++)
9834 if (a->dw_attr != DW_AT_name
9835 && a->dw_attr != DW_AT_declaration
9836 && a->dw_attr != DW_AT_external)
9837 add_dwarf_attr (die, a);
9840 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
9843 if (decl->die_parent != NULL
9844 && decl->die_parent->die_tag != DW_TAG_compile_unit
9845 && decl->die_parent->die_tag != DW_TAG_type_unit)
9847 new_decl = copy_ancestor_tree (unit, decl, NULL);
9848 if (new_decl != NULL)
9850 remove_AT (new_decl, DW_AT_signature);
9851 add_AT_specification (die, new_decl);
9856 /* Generate the skeleton ancestor tree for the given NODE, then clone
9857 the DIE and add the clone into the tree. */
9860 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
9862 if (node->new_die != NULL)
9865 node->new_die = clone_as_declaration (node->old_die);
9867 if (node->parent != NULL)
9869 generate_skeleton_ancestor_tree (node->parent);
9870 add_child_die (node->parent->new_die, node->new_die);
9874 /* Generate a skeleton tree of DIEs containing any declarations that are
9875 found in the original tree. We traverse the tree looking for declaration
9876 DIEs, and construct the skeleton from the bottom up whenever we find one. */
9879 generate_skeleton_bottom_up (skeleton_chain_node *parent)
9881 skeleton_chain_node node;
9884 dw_die_ref prev = NULL;
9885 dw_die_ref next = NULL;
9887 node.parent = parent;
9889 first = c = parent->old_die->die_child;
9893 if (prev == NULL || prev->die_sib == c)
9896 next = (c == first ? NULL : c->die_sib);
9898 node.new_die = NULL;
9899 if (is_declaration_die (c))
9901 /* Clone the existing DIE, move the original to the skeleton
9902 tree (which is in the main CU), and put the clone, with
9903 all the original's children, where the original came from. */
9904 dw_die_ref clone = clone_die (c);
9905 move_all_children (c, clone);
9907 replace_child (c, clone, prev);
9908 generate_skeleton_ancestor_tree (parent);
9909 add_child_die (parent->new_die, c);
9913 generate_skeleton_bottom_up (&node);
9914 } while (next != NULL);
9917 /* Wrapper function for generate_skeleton_bottom_up. */
9920 generate_skeleton (dw_die_ref die)
9922 skeleton_chain_node node;
9925 node.new_die = NULL;
9928 /* If this type definition is nested inside another type,
9929 always leave at least a declaration in its place. */
9930 if (die->die_parent != NULL && is_type_die (die->die_parent))
9931 node.new_die = clone_as_declaration (die);
9933 generate_skeleton_bottom_up (&node);
9934 return node.new_die;
9937 /* Remove the DIE from its parent, possibly replacing it with a cloned
9938 declaration. The original DIE will be moved to a new compile unit
9939 so that existing references to it follow it to the new location. If
9940 any of the original DIE's descendants is a declaration, we need to
9941 replace the original DIE with a skeleton tree and move the
9942 declarations back into the skeleton tree. */
9945 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
9947 dw_die_ref skeleton;
9949 skeleton = generate_skeleton (child);
9950 if (skeleton == NULL)
9951 remove_child_with_prev (child, prev);
9954 skeleton->die_id.die_type_node = child->die_id.die_type_node;
9955 replace_child (child, skeleton, prev);
9961 /* Traverse the DIE and set up additional .debug_types sections for each
9962 type worthy of being placed in a COMDAT section. */
9965 break_out_comdat_types (dw_die_ref die)
9969 dw_die_ref prev = NULL;
9970 dw_die_ref next = NULL;
9971 dw_die_ref unit = NULL;
9973 first = c = die->die_child;
9977 if (prev == NULL || prev->die_sib == c)
9980 next = (c == first ? NULL : c->die_sib);
9981 if (should_move_die_to_comdat (c))
9983 dw_die_ref replacement;
9984 comdat_type_node_ref type_node;
9986 /* Create a new type unit DIE as the root for the new tree, and
9987 add it to the list of comdat types. */
9988 unit = new_die (DW_TAG_type_unit, NULL, NULL);
9989 add_AT_unsigned (unit, DW_AT_language,
9990 get_AT_unsigned (comp_unit_die, DW_AT_language));
9991 type_node = ggc_alloc_cleared_comdat_type_node ();
9992 type_node->root_die = unit;
9993 type_node->next = comdat_type_list;
9994 comdat_type_list = type_node;
9996 /* Generate the type signature. */
9997 generate_type_signature (c, type_node);
9999 /* Copy the declaration context, attributes, and children of the
10000 declaration into the new compile unit DIE. */
10001 copy_declaration_context (unit, c);
10003 /* Remove this DIE from the main CU. */
10004 replacement = remove_child_or_replace_with_skeleton (c, prev);
10006 /* Break out nested types into their own type units. */
10007 break_out_comdat_types (c);
10009 /* Add the DIE to the new compunit. */
10010 add_child_die (unit, c);
10012 if (replacement != NULL)
10015 else if (c->die_tag == DW_TAG_namespace
10016 || c->die_tag == DW_TAG_class_type
10017 || c->die_tag == DW_TAG_structure_type
10018 || c->die_tag == DW_TAG_union_type)
10020 /* Look for nested types that can be broken out. */
10021 break_out_comdat_types (c);
10023 } while (next != NULL);
10026 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10028 struct decl_table_entry
10034 /* Routines to manipulate hash table of copied declarations. */
10037 htab_decl_hash (const void *of)
10039 const struct decl_table_entry *const entry =
10040 (const struct decl_table_entry *) of;
10042 return htab_hash_pointer (entry->orig);
10046 htab_decl_eq (const void *of1, const void *of2)
10048 const struct decl_table_entry *const entry1 =
10049 (const struct decl_table_entry *) of1;
10050 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10052 return entry1->orig == entry2;
10056 htab_decl_del (void *what)
10058 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10063 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10064 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10065 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10066 to check if the ancestor has already been copied into UNIT. */
10069 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10071 dw_die_ref parent = die->die_parent;
10072 dw_die_ref new_parent = unit;
10074 void **slot = NULL;
10075 struct decl_table_entry *entry = NULL;
10079 /* Check if the entry has already been copied to UNIT. */
10080 slot = htab_find_slot_with_hash (decl_table, die,
10081 htab_hash_pointer (die), INSERT);
10082 if (*slot != HTAB_EMPTY_ENTRY)
10084 entry = (struct decl_table_entry *) *slot;
10085 return entry->copy;
10088 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10089 entry = XCNEW (struct decl_table_entry);
10091 entry->copy = NULL;
10095 if (parent != NULL)
10097 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10100 if (parent->die_tag != DW_TAG_compile_unit
10101 && parent->die_tag != DW_TAG_type_unit)
10102 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10105 copy = clone_as_declaration (die);
10106 add_child_die (new_parent, copy);
10108 if (decl_table != NULL)
10110 /* Record the pointer to the copy. */
10111 entry->copy = copy;
10117 /* Walk the DIE and its children, looking for references to incomplete
10118 or trivial types that are unmarked (i.e., that are not in the current
10122 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10128 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
10130 if (AT_class (a) == dw_val_class_die_ref)
10132 dw_die_ref targ = AT_ref (a);
10133 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10135 struct decl_table_entry *entry;
10137 if (targ->die_mark != 0 || type_node != NULL)
10140 slot = htab_find_slot_with_hash (decl_table, targ,
10141 htab_hash_pointer (targ), INSERT);
10143 if (*slot != HTAB_EMPTY_ENTRY)
10145 /* TARG has already been copied, so we just need to
10146 modify the reference to point to the copy. */
10147 entry = (struct decl_table_entry *) *slot;
10148 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10152 dw_die_ref parent = unit;
10153 dw_die_ref copy = clone_tree (targ);
10155 /* Make sure the cloned tree is marked as part of the
10159 /* Record in DECL_TABLE that TARG has been copied.
10160 Need to do this now, before the recursive call,
10161 because DECL_TABLE may be expanded and SLOT
10162 would no longer be a valid pointer. */
10163 entry = XCNEW (struct decl_table_entry);
10164 entry->orig = targ;
10165 entry->copy = copy;
10168 /* If TARG has surrounding context, copy its ancestor tree
10169 into the new type unit. */
10170 if (targ->die_parent != NULL
10171 && targ->die_parent->die_tag != DW_TAG_compile_unit
10172 && targ->die_parent->die_tag != DW_TAG_type_unit)
10173 parent = copy_ancestor_tree (unit, targ->die_parent,
10176 add_child_die (parent, copy);
10177 a->dw_attr_val.v.val_die_ref.die = copy;
10179 /* Make sure the newly-copied DIE is walked. If it was
10180 installed in a previously-added context, it won't
10181 get visited otherwise. */
10182 if (parent != unit)
10184 /* Find the highest point of the newly-added tree,
10185 mark each node along the way, and walk from there. */
10186 parent->die_mark = 1;
10187 while (parent->die_parent
10188 && parent->die_parent->die_mark == 0)
10190 parent = parent->die_parent;
10191 parent->die_mark = 1;
10193 copy_decls_walk (unit, parent, decl_table);
10199 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10202 /* Copy declarations for "unworthy" types into the new comdat section.
10203 Incomplete types, modified types, and certain other types aren't broken
10204 out into comdat sections of their own, so they don't have a signature,
10205 and we need to copy the declaration into the same section so that we
10206 don't have an external reference. */
10209 copy_decls_for_unworthy_types (dw_die_ref unit)
10214 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10215 copy_decls_walk (unit, unit, decl_table);
10216 htab_delete (decl_table);
10217 unmark_dies (unit);
10220 /* Traverse the DIE and add a sibling attribute if it may have the
10221 effect of speeding up access to siblings. To save some space,
10222 avoid generating sibling attributes for DIE's without children. */
10225 add_sibling_attributes (dw_die_ref die)
10229 if (! die->die_child)
10232 if (die->die_parent && die != die->die_parent->die_child)
10233 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10235 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10238 /* Output all location lists for the DIE and its children. */
10241 output_location_lists (dw_die_ref die)
10247 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
10248 if (AT_class (a) == dw_val_class_loc_list)
10249 output_loc_list (AT_loc_list (a));
10251 FOR_EACH_CHILD (die, c, output_location_lists (c));
10254 /* The format of each DIE (and its attribute value pairs) is encoded in an
10255 abbreviation table. This routine builds the abbreviation table and assigns
10256 a unique abbreviation id for each abbreviation entry. The children of each
10257 die are visited recursively. */
10260 build_abbrev_table (dw_die_ref die)
10262 unsigned long abbrev_id;
10263 unsigned int n_alloc;
10268 /* Scan the DIE references, and mark as external any that refer to
10269 DIEs from other CUs (i.e. those which are not marked). */
10270 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
10271 if (AT_class (a) == dw_val_class_die_ref
10272 && AT_ref (a)->die_mark == 0)
10274 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10275 set_AT_ref_external (a, 1);
10278 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10280 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10281 dw_attr_ref die_a, abbrev_a;
10285 if (abbrev->die_tag != die->die_tag)
10287 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10290 if (VEC_length (dw_attr_node, abbrev->die_attr)
10291 != VEC_length (dw_attr_node, die->die_attr))
10294 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
10296 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10297 if ((abbrev_a->dw_attr != die_a->dw_attr)
10298 || (value_format (abbrev_a) != value_format (die_a)))
10308 if (abbrev_id >= abbrev_die_table_in_use)
10310 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10312 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10313 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10316 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10317 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10318 abbrev_die_table_allocated = n_alloc;
10321 ++abbrev_die_table_in_use;
10322 abbrev_die_table[abbrev_id] = die;
10325 die->die_abbrev = abbrev_id;
10326 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10329 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10332 constant_size (unsigned HOST_WIDE_INT value)
10339 log = floor_log2 (value);
10342 log = 1 << (floor_log2 (log) + 1);
10347 /* Return the size of a DIE as it is represented in the
10348 .debug_info section. */
10350 static unsigned long
10351 size_of_die (dw_die_ref die)
10353 unsigned long size = 0;
10357 size += size_of_uleb128 (die->die_abbrev);
10358 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
10360 switch (AT_class (a))
10362 case dw_val_class_addr:
10363 size += DWARF2_ADDR_SIZE;
10365 case dw_val_class_offset:
10366 size += DWARF_OFFSET_SIZE;
10368 case dw_val_class_loc:
10370 unsigned long lsize = size_of_locs (AT_loc (a));
10372 /* Block length. */
10373 if (dwarf_version >= 4)
10374 size += size_of_uleb128 (lsize);
10376 size += constant_size (lsize);
10380 case dw_val_class_loc_list:
10381 size += DWARF_OFFSET_SIZE;
10383 case dw_val_class_range_list:
10384 size += DWARF_OFFSET_SIZE;
10386 case dw_val_class_const:
10387 size += size_of_sleb128 (AT_int (a));
10389 case dw_val_class_unsigned_const:
10390 size += constant_size (AT_unsigned (a));
10392 case dw_val_class_const_double:
10393 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10394 if (HOST_BITS_PER_WIDE_INT >= 64)
10395 size++; /* block */
10397 case dw_val_class_vec:
10398 size += constant_size (a->dw_attr_val.v.val_vec.length
10399 * a->dw_attr_val.v.val_vec.elt_size)
10400 + a->dw_attr_val.v.val_vec.length
10401 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10403 case dw_val_class_flag:
10404 if (dwarf_version >= 4)
10405 /* Currently all add_AT_flag calls pass in 1 as last argument,
10406 so DW_FORM_flag_present can be used. If that ever changes,
10407 we'll need to use DW_FORM_flag and have some optimization
10408 in build_abbrev_table that will change those to
10409 DW_FORM_flag_present if it is set to 1 in all DIEs using
10410 the same abbrev entry. */
10411 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10415 case dw_val_class_die_ref:
10416 if (AT_ref_external (a))
10418 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10419 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10420 is sized by target address length, whereas in DWARF3
10421 it's always sized as an offset. */
10422 if (dwarf_version >= 4)
10423 size += DWARF_TYPE_SIGNATURE_SIZE;
10424 else if (dwarf_version == 2)
10425 size += DWARF2_ADDR_SIZE;
10427 size += DWARF_OFFSET_SIZE;
10430 size += DWARF_OFFSET_SIZE;
10432 case dw_val_class_fde_ref:
10433 size += DWARF_OFFSET_SIZE;
10435 case dw_val_class_lbl_id:
10436 size += DWARF2_ADDR_SIZE;
10438 case dw_val_class_lineptr:
10439 case dw_val_class_macptr:
10440 size += DWARF_OFFSET_SIZE;
10442 case dw_val_class_str:
10443 if (AT_string_form (a) == DW_FORM_strp)
10444 size += DWARF_OFFSET_SIZE;
10446 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10448 case dw_val_class_file:
10449 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10451 case dw_val_class_data8:
10454 case dw_val_class_vms_delta:
10455 size += DWARF_OFFSET_SIZE;
10458 gcc_unreachable ();
10465 /* Size the debugging information associated with a given DIE. Visits the
10466 DIE's children recursively. Updates the global variable next_die_offset, on
10467 each time through. Uses the current value of next_die_offset to update the
10468 die_offset field in each DIE. */
10471 calc_die_sizes (dw_die_ref die)
10475 die->die_offset = next_die_offset;
10476 next_die_offset += size_of_die (die);
10478 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10480 if (die->die_child != NULL)
10481 /* Count the null byte used to terminate sibling lists. */
10482 next_die_offset += 1;
10485 /* Set the marks for a die and its children. We do this so
10486 that we know whether or not a reference needs to use FORM_ref_addr; only
10487 DIEs in the same CU will be marked. We used to clear out the offset
10488 and use that as the flag, but ran into ordering problems. */
10491 mark_dies (dw_die_ref die)
10495 gcc_assert (!die->die_mark);
10498 FOR_EACH_CHILD (die, c, mark_dies (c));
10501 /* Clear the marks for a die and its children. */
10504 unmark_dies (dw_die_ref die)
10508 if (dwarf_version < 4)
10509 gcc_assert (die->die_mark);
10512 FOR_EACH_CHILD (die, c, unmark_dies (c));
10515 /* Clear the marks for a die, its children and referred dies. */
10518 unmark_all_dies (dw_die_ref die)
10524 if (!die->die_mark)
10528 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10530 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
10531 if (AT_class (a) == dw_val_class_die_ref)
10532 unmark_all_dies (AT_ref (a));
10535 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10536 generated for the compilation unit. */
10538 static unsigned long
10539 size_of_pubnames (VEC (pubname_entry, gc) * names)
10541 unsigned long size;
10545 size = DWARF_PUBNAMES_HEADER_SIZE;
10546 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
10547 if (names != pubtype_table
10548 || p->die->die_offset != 0
10549 || !flag_eliminate_unused_debug_types)
10550 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10552 size += DWARF_OFFSET_SIZE;
10556 /* Return the size of the information in the .debug_aranges section. */
10558 static unsigned long
10559 size_of_aranges (void)
10561 unsigned long size;
10563 size = DWARF_ARANGES_HEADER_SIZE;
10565 /* Count the address/length pair for this compilation unit. */
10566 if (text_section_used)
10567 size += 2 * DWARF2_ADDR_SIZE;
10568 if (cold_text_section_used)
10569 size += 2 * DWARF2_ADDR_SIZE;
10570 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
10572 /* Count the two zero words used to terminated the address range table. */
10573 size += 2 * DWARF2_ADDR_SIZE;
10577 /* Select the encoding of an attribute value. */
10579 static enum dwarf_form
10580 value_format (dw_attr_ref a)
10582 switch (a->dw_attr_val.val_class)
10584 case dw_val_class_addr:
10585 /* Only very few attributes allow DW_FORM_addr. */
10586 switch (a->dw_attr)
10589 case DW_AT_high_pc:
10590 case DW_AT_entry_pc:
10591 case DW_AT_trampoline:
10592 return DW_FORM_addr;
10596 switch (DWARF2_ADDR_SIZE)
10599 return DW_FORM_data1;
10601 return DW_FORM_data2;
10603 return DW_FORM_data4;
10605 return DW_FORM_data8;
10607 gcc_unreachable ();
10609 case dw_val_class_range_list:
10610 case dw_val_class_loc_list:
10611 if (dwarf_version >= 4)
10612 return DW_FORM_sec_offset;
10614 case dw_val_class_vms_delta:
10615 case dw_val_class_offset:
10616 switch (DWARF_OFFSET_SIZE)
10619 return DW_FORM_data4;
10621 return DW_FORM_data8;
10623 gcc_unreachable ();
10625 case dw_val_class_loc:
10626 if (dwarf_version >= 4)
10627 return DW_FORM_exprloc;
10628 switch (constant_size (size_of_locs (AT_loc (a))))
10631 return DW_FORM_block1;
10633 return DW_FORM_block2;
10635 gcc_unreachable ();
10637 case dw_val_class_const:
10638 return DW_FORM_sdata;
10639 case dw_val_class_unsigned_const:
10640 switch (constant_size (AT_unsigned (a)))
10643 return DW_FORM_data1;
10645 return DW_FORM_data2;
10647 return DW_FORM_data4;
10649 return DW_FORM_data8;
10651 gcc_unreachable ();
10653 case dw_val_class_const_double:
10654 switch (HOST_BITS_PER_WIDE_INT)
10657 return DW_FORM_data2;
10659 return DW_FORM_data4;
10661 return DW_FORM_data8;
10664 return DW_FORM_block1;
10666 case dw_val_class_vec:
10667 switch (constant_size (a->dw_attr_val.v.val_vec.length
10668 * a->dw_attr_val.v.val_vec.elt_size))
10671 return DW_FORM_block1;
10673 return DW_FORM_block2;
10675 return DW_FORM_block4;
10677 gcc_unreachable ();
10679 case dw_val_class_flag:
10680 if (dwarf_version >= 4)
10682 /* Currently all add_AT_flag calls pass in 1 as last argument,
10683 so DW_FORM_flag_present can be used. If that ever changes,
10684 we'll need to use DW_FORM_flag and have some optimization
10685 in build_abbrev_table that will change those to
10686 DW_FORM_flag_present if it is set to 1 in all DIEs using
10687 the same abbrev entry. */
10688 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10689 return DW_FORM_flag_present;
10691 return DW_FORM_flag;
10692 case dw_val_class_die_ref:
10693 if (AT_ref_external (a))
10694 return dwarf_version >= 4 ? DW_FORM_sig8 : DW_FORM_ref_addr;
10696 return DW_FORM_ref;
10697 case dw_val_class_fde_ref:
10698 return DW_FORM_data;
10699 case dw_val_class_lbl_id:
10700 return DW_FORM_addr;
10701 case dw_val_class_lineptr:
10702 case dw_val_class_macptr:
10703 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
10704 case dw_val_class_str:
10705 return AT_string_form (a);
10706 case dw_val_class_file:
10707 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
10710 return DW_FORM_data1;
10712 return DW_FORM_data2;
10714 return DW_FORM_data4;
10716 gcc_unreachable ();
10719 case dw_val_class_data8:
10720 return DW_FORM_data8;
10723 gcc_unreachable ();
10727 /* Output the encoding of an attribute value. */
10730 output_value_format (dw_attr_ref a)
10732 enum dwarf_form form = value_format (a);
10734 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
10737 /* Output the .debug_abbrev section which defines the DIE abbreviation
10741 output_abbrev_section (void)
10743 unsigned long abbrev_id;
10745 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10747 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10749 dw_attr_ref a_attr;
10751 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
10752 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
10753 dwarf_tag_name (abbrev->die_tag));
10755 if (abbrev->die_child != NULL)
10756 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
10758 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
10760 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
10763 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
10764 dwarf_attr_name (a_attr->dw_attr));
10765 output_value_format (a_attr);
10768 dw2_asm_output_data (1, 0, NULL);
10769 dw2_asm_output_data (1, 0, NULL);
10772 /* Terminate the table. */
10773 dw2_asm_output_data (1, 0, NULL);
10776 /* Output a symbol we can use to refer to this DIE from another CU. */
10779 output_die_symbol (dw_die_ref die)
10781 char *sym = die->die_id.die_symbol;
10786 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
10787 /* We make these global, not weak; if the target doesn't support
10788 .linkonce, it doesn't support combining the sections, so debugging
10790 targetm.asm_out.globalize_label (asm_out_file, sym);
10792 ASM_OUTPUT_LABEL (asm_out_file, sym);
10795 /* Return a new location list, given the begin and end range, and the
10798 static inline dw_loc_list_ref
10799 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
10800 const char *section)
10802 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
10804 retlist->begin = begin;
10805 retlist->end = end;
10806 retlist->expr = expr;
10807 retlist->section = section;
10812 /* Generate a new internal symbol for this location list node, if it
10813 hasn't got one yet. */
10816 gen_llsym (dw_loc_list_ref list)
10818 gcc_assert (!list->ll_symbol);
10819 list->ll_symbol = gen_internal_sym ("LLST");
10822 /* Output the location list given to us. */
10825 output_loc_list (dw_loc_list_ref list_head)
10827 dw_loc_list_ref curr = list_head;
10829 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
10831 /* Walk the location list, and output each range + expression. */
10832 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
10834 unsigned long size;
10835 /* Don't output an entry that starts and ends at the same address. */
10836 if (strcmp (curr->begin, curr->end) == 0)
10838 if (!have_multiple_function_sections)
10840 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
10841 "Location list begin address (%s)",
10842 list_head->ll_symbol);
10843 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
10844 "Location list end address (%s)",
10845 list_head->ll_symbol);
10849 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10850 "Location list begin address (%s)",
10851 list_head->ll_symbol);
10852 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
10853 "Location list end address (%s)",
10854 list_head->ll_symbol);
10856 size = size_of_locs (curr->expr);
10858 /* Output the block length for this list of location operations. */
10859 gcc_assert (size <= 0xffff);
10860 dw2_asm_output_data (2, size, "%s", "Location expression size");
10862 output_loc_sequence (curr->expr);
10865 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10866 "Location list terminator begin (%s)",
10867 list_head->ll_symbol);
10868 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10869 "Location list terminator end (%s)",
10870 list_head->ll_symbol);
10873 /* Output a type signature. */
10876 output_signature (const char *sig, const char *name)
10880 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
10881 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
10884 /* Output the DIE and its attributes. Called recursively to generate
10885 the definitions of each child DIE. */
10888 output_die (dw_die_ref die)
10892 unsigned long size;
10895 /* If someone in another CU might refer to us, set up a symbol for
10896 them to point to. */
10897 if (dwarf_version < 4 && die->die_id.die_symbol)
10898 output_die_symbol (die);
10900 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
10901 (unsigned long)die->die_offset,
10902 dwarf_tag_name (die->die_tag));
10904 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
10906 const char *name = dwarf_attr_name (a->dw_attr);
10908 switch (AT_class (a))
10910 case dw_val_class_addr:
10911 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
10914 case dw_val_class_offset:
10915 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
10919 case dw_val_class_range_list:
10921 char *p = strchr (ranges_section_label, '\0');
10923 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
10924 a->dw_attr_val.v.val_offset);
10925 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
10926 debug_ranges_section, "%s", name);
10931 case dw_val_class_loc:
10932 size = size_of_locs (AT_loc (a));
10934 /* Output the block length for this list of location operations. */
10935 if (dwarf_version >= 4)
10936 dw2_asm_output_data_uleb128 (size, "%s", name);
10938 dw2_asm_output_data (constant_size (size), size, "%s", name);
10940 output_loc_sequence (AT_loc (a));
10943 case dw_val_class_const:
10944 /* ??? It would be slightly more efficient to use a scheme like is
10945 used for unsigned constants below, but gdb 4.x does not sign
10946 extend. Gdb 5.x does sign extend. */
10947 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
10950 case dw_val_class_unsigned_const:
10951 dw2_asm_output_data (constant_size (AT_unsigned (a)),
10952 AT_unsigned (a), "%s", name);
10955 case dw_val_class_const_double:
10957 unsigned HOST_WIDE_INT first, second;
10959 if (HOST_BITS_PER_WIDE_INT >= 64)
10960 dw2_asm_output_data (1,
10961 2 * HOST_BITS_PER_WIDE_INT
10962 / HOST_BITS_PER_CHAR,
10965 if (WORDS_BIG_ENDIAN)
10967 first = a->dw_attr_val.v.val_double.high;
10968 second = a->dw_attr_val.v.val_double.low;
10972 first = a->dw_attr_val.v.val_double.low;
10973 second = a->dw_attr_val.v.val_double.high;
10976 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
10978 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
10983 case dw_val_class_vec:
10985 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
10986 unsigned int len = a->dw_attr_val.v.val_vec.length;
10990 dw2_asm_output_data (constant_size (len * elt_size),
10991 len * elt_size, "%s", name);
10992 if (elt_size > sizeof (HOST_WIDE_INT))
10997 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
10999 i++, p += elt_size)
11000 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11001 "fp or vector constant word %u", i);
11005 case dw_val_class_flag:
11006 if (dwarf_version >= 4)
11008 /* Currently all add_AT_flag calls pass in 1 as last argument,
11009 so DW_FORM_flag_present can be used. If that ever changes,
11010 we'll need to use DW_FORM_flag and have some optimization
11011 in build_abbrev_table that will change those to
11012 DW_FORM_flag_present if it is set to 1 in all DIEs using
11013 the same abbrev entry. */
11014 gcc_assert (AT_flag (a) == 1);
11015 if (flag_debug_asm)
11016 fprintf (asm_out_file, "\t\t\t%s %s\n",
11017 ASM_COMMENT_START, name);
11020 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11023 case dw_val_class_loc_list:
11025 char *sym = AT_loc_list (a)->ll_symbol;
11028 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11033 case dw_val_class_die_ref:
11034 if (AT_ref_external (a))
11036 if (dwarf_version >= 4)
11038 comdat_type_node_ref type_node =
11039 AT_ref (a)->die_id.die_type_node;
11041 gcc_assert (type_node);
11042 output_signature (type_node->signature, name);
11046 char *sym = AT_ref (a)->die_id.die_symbol;
11050 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11051 length, whereas in DWARF3 it's always sized as an
11053 if (dwarf_version == 2)
11054 size = DWARF2_ADDR_SIZE;
11056 size = DWARF_OFFSET_SIZE;
11057 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11063 gcc_assert (AT_ref (a)->die_offset);
11064 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11069 case dw_val_class_fde_ref:
11073 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11074 a->dw_attr_val.v.val_fde_index * 2);
11075 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11080 case dw_val_class_vms_delta:
11081 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11082 AT_vms_delta2 (a), AT_vms_delta1 (a),
11086 case dw_val_class_lbl_id:
11087 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11090 case dw_val_class_lineptr:
11091 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11092 debug_line_section, "%s", name);
11095 case dw_val_class_macptr:
11096 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11097 debug_macinfo_section, "%s", name);
11100 case dw_val_class_str:
11101 if (AT_string_form (a) == DW_FORM_strp)
11102 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11103 a->dw_attr_val.v.val_str->label,
11105 "%s: \"%s\"", name, AT_string (a));
11107 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11110 case dw_val_class_file:
11112 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11114 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11115 a->dw_attr_val.v.val_file->filename);
11119 case dw_val_class_data8:
11123 for (i = 0; i < 8; i++)
11124 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11125 i == 0 ? "%s" : NULL, name);
11130 gcc_unreachable ();
11134 FOR_EACH_CHILD (die, c, output_die (c));
11136 /* Add null byte to terminate sibling list. */
11137 if (die->die_child != NULL)
11138 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11139 (unsigned long) die->die_offset);
11142 /* Output the compilation unit that appears at the beginning of the
11143 .debug_info section, and precedes the DIE descriptions. */
11146 output_compilation_unit_header (void)
11148 int ver = dwarf_version;
11150 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11151 dw2_asm_output_data (4, 0xffffffff,
11152 "Initial length escape value indicating 64-bit DWARF extension");
11153 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11154 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11155 "Length of Compilation Unit Info");
11156 dw2_asm_output_data (2, ver, "DWARF version number");
11157 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11158 debug_abbrev_section,
11159 "Offset Into Abbrev. Section");
11160 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11163 /* Output the compilation unit DIE and its children. */
11166 output_comp_unit (dw_die_ref die, int output_if_empty)
11168 const char *secname;
11169 char *oldsym, *tmp;
11171 /* Unless we are outputting main CU, we may throw away empty ones. */
11172 if (!output_if_empty && die->die_child == NULL)
11175 /* Even if there are no children of this DIE, we must output the information
11176 about the compilation unit. Otherwise, on an empty translation unit, we
11177 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11178 will then complain when examining the file. First mark all the DIEs in
11179 this CU so we know which get local refs. */
11182 build_abbrev_table (die);
11184 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11185 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11186 calc_die_sizes (die);
11188 oldsym = die->die_id.die_symbol;
11191 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11193 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11195 die->die_id.die_symbol = NULL;
11196 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11199 switch_to_section (debug_info_section);
11201 /* Output debugging information. */
11202 output_compilation_unit_header ();
11205 /* Leave the marks on the main CU, so we can check them in
11206 output_pubnames. */
11210 die->die_id.die_symbol = oldsym;
11214 /* Output a comdat type unit DIE and its children. */
11217 output_comdat_type_unit (comdat_type_node *node)
11219 const char *secname;
11222 #if defined (OBJECT_FORMAT_ELF)
11226 /* First mark all the DIEs in this CU so we know which get local refs. */
11227 mark_dies (node->root_die);
11229 build_abbrev_table (node->root_die);
11231 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11232 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11233 calc_die_sizes (node->root_die);
11235 #if defined (OBJECT_FORMAT_ELF)
11236 secname = ".debug_types";
11237 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11238 sprintf (tmp, "wt.");
11239 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11240 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11241 comdat_key = get_identifier (tmp);
11242 targetm.asm_out.named_section (secname,
11243 SECTION_DEBUG | SECTION_LINKONCE,
11246 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11247 sprintf (tmp, ".gnu.linkonce.wt.");
11248 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11249 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11251 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11254 /* Output debugging information. */
11255 output_compilation_unit_header ();
11256 output_signature (node->signature, "Type Signature");
11257 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11258 "Offset to Type DIE");
11259 output_die (node->root_die);
11261 unmark_dies (node->root_die);
11264 /* Return the DWARF2/3 pubname associated with a decl. */
11266 static const char *
11267 dwarf2_name (tree decl, int scope)
11269 if (DECL_NAMELESS (decl))
11271 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11274 /* Add a new entry to .debug_pubnames if appropriate. */
11277 add_pubname_string (const char *str, dw_die_ref die)
11279 if (targetm.want_debug_pub_sections)
11284 e.name = xstrdup (str);
11285 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11290 add_pubname (tree decl, dw_die_ref die)
11292 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11294 const char *name = dwarf2_name (decl, 1);
11296 add_pubname_string (name, die);
11300 /* Add a new entry to .debug_pubtypes if appropriate. */
11303 add_pubtype (tree decl, dw_die_ref die)
11307 if (!targetm.want_debug_pub_sections)
11311 if ((TREE_PUBLIC (decl)
11312 || die->die_parent == comp_unit_die)
11313 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11318 if (TYPE_NAME (decl))
11320 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11321 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11322 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11323 && DECL_NAME (TYPE_NAME (decl)))
11324 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11326 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11331 e.name = dwarf2_name (decl, 1);
11333 e.name = xstrdup (e.name);
11336 /* If we don't have a name for the type, there's no point in adding
11337 it to the table. */
11338 if (e.name && e.name[0] != '\0')
11339 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11343 /* Output the public names table used to speed up access to externally
11344 visible names; or the public types table used to find type definitions. */
11347 output_pubnames (VEC (pubname_entry, gc) * names)
11350 unsigned long pubnames_length = size_of_pubnames (names);
11353 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11354 dw2_asm_output_data (4, 0xffffffff,
11355 "Initial length escape value indicating 64-bit DWARF extension");
11356 if (names == pubname_table)
11357 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11358 "Length of Public Names Info");
11360 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11361 "Length of Public Type Names Info");
11362 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11363 dw2_asm_output_data (2, 2, "DWARF Version");
11364 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11365 debug_info_section,
11366 "Offset of Compilation Unit Info");
11367 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11368 "Compilation Unit Length");
11370 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
11372 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11373 if (names == pubname_table)
11374 gcc_assert (pub->die->die_mark);
11376 if (names != pubtype_table
11377 || pub->die->die_offset != 0
11378 || !flag_eliminate_unused_debug_types)
11380 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11383 dw2_asm_output_nstring (pub->name, -1, "external name");
11387 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11390 /* Add a new entry to .debug_aranges if appropriate. */
11393 add_arange (tree decl, dw_die_ref die)
11395 if (! DECL_SECTION_NAME (decl))
11398 if (arange_table_in_use == arange_table_allocated)
11400 arange_table_allocated += ARANGE_TABLE_INCREMENT;
11401 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
11402 arange_table_allocated);
11403 memset (arange_table + arange_table_in_use, 0,
11404 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
11407 arange_table[arange_table_in_use++] = die;
11410 /* Output the information that goes into the .debug_aranges table.
11411 Namely, define the beginning and ending address range of the
11412 text section generated for this compilation unit. */
11415 output_aranges (void)
11418 unsigned long aranges_length = size_of_aranges ();
11420 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11421 dw2_asm_output_data (4, 0xffffffff,
11422 "Initial length escape value indicating 64-bit DWARF extension");
11423 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11424 "Length of Address Ranges Info");
11425 /* Version number for aranges is still 2, even in DWARF3. */
11426 dw2_asm_output_data (2, 2, "DWARF Version");
11427 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11428 debug_info_section,
11429 "Offset of Compilation Unit Info");
11430 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11431 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11433 /* We need to align to twice the pointer size here. */
11434 if (DWARF_ARANGES_PAD_SIZE)
11436 /* Pad using a 2 byte words so that padding is correct for any
11438 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11439 2 * DWARF2_ADDR_SIZE);
11440 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11441 dw2_asm_output_data (2, 0, NULL);
11444 /* It is necessary not to output these entries if the sections were
11445 not used; if the sections were not used, the length will be 0 and
11446 the address may end up as 0 if the section is discarded by ld
11447 --gc-sections, leaving an invalid (0, 0) entry that can be
11448 confused with the terminator. */
11449 if (text_section_used)
11451 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11452 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11453 text_section_label, "Length");
11455 if (cold_text_section_used)
11457 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11459 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11460 cold_text_section_label, "Length");
11463 for (i = 0; i < arange_table_in_use; i++)
11465 dw_die_ref die = arange_table[i];
11467 /* We shouldn't see aranges for DIEs outside of the main CU. */
11468 gcc_assert (die->die_mark);
11470 if (die->die_tag == DW_TAG_subprogram)
11472 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
11474 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
11475 get_AT_low_pc (die), "Length");
11479 /* A static variable; extract the symbol from DW_AT_location.
11480 Note that this code isn't currently hit, as we only emit
11481 aranges for functions (jason 9/23/99). */
11482 dw_attr_ref a = get_AT (die, DW_AT_location);
11483 dw_loc_descr_ref loc;
11485 gcc_assert (a && AT_class (a) == dw_val_class_loc);
11488 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
11490 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
11491 loc->dw_loc_oprnd1.v.val_addr, "Address");
11492 dw2_asm_output_data (DWARF2_ADDR_SIZE,
11493 get_AT_unsigned (die, DW_AT_byte_size),
11498 /* Output the terminator words. */
11499 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11500 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11503 /* Add a new entry to .debug_ranges. Return the offset at which it
11506 static unsigned int
11507 add_ranges_num (int num)
11509 unsigned int in_use = ranges_table_in_use;
11511 if (in_use == ranges_table_allocated)
11513 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11514 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11515 ranges_table_allocated);
11516 memset (ranges_table + ranges_table_in_use, 0,
11517 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11520 ranges_table[in_use].num = num;
11521 ranges_table_in_use = in_use + 1;
11523 return in_use * 2 * DWARF2_ADDR_SIZE;
11526 /* Add a new entry to .debug_ranges corresponding to a block, or a
11527 range terminator if BLOCK is NULL. */
11529 static unsigned int
11530 add_ranges (const_tree block)
11532 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11535 /* Add a new entry to .debug_ranges corresponding to a pair of
11539 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11542 unsigned int in_use = ranges_by_label_in_use;
11543 unsigned int offset;
11545 if (in_use == ranges_by_label_allocated)
11547 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11548 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11550 ranges_by_label_allocated);
11551 memset (ranges_by_label + ranges_by_label_in_use, 0,
11552 RANGES_TABLE_INCREMENT
11553 * sizeof (struct dw_ranges_by_label_struct));
11556 ranges_by_label[in_use].begin = begin;
11557 ranges_by_label[in_use].end = end;
11558 ranges_by_label_in_use = in_use + 1;
11560 offset = add_ranges_num (-(int)in_use - 1);
11563 add_AT_range_list (die, DW_AT_ranges, offset);
11569 output_ranges (void)
11572 static const char *const start_fmt = "Offset %#x";
11573 const char *fmt = start_fmt;
11575 for (i = 0; i < ranges_table_in_use; i++)
11577 int block_num = ranges_table[i].num;
11581 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11582 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11584 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11585 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11587 /* If all code is in the text section, then the compilation
11588 unit base address defaults to DW_AT_low_pc, which is the
11589 base of the text section. */
11590 if (!have_multiple_function_sections)
11592 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11593 text_section_label,
11594 fmt, i * 2 * DWARF2_ADDR_SIZE);
11595 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11596 text_section_label, NULL);
11599 /* Otherwise, the compilation unit base address is zero,
11600 which allows us to use absolute addresses, and not worry
11601 about whether the target supports cross-section
11605 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11606 fmt, i * 2 * DWARF2_ADDR_SIZE);
11607 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11613 /* Negative block_num stands for an index into ranges_by_label. */
11614 else if (block_num < 0)
11616 int lab_idx = - block_num - 1;
11618 if (!have_multiple_function_sections)
11620 gcc_unreachable ();
11622 /* If we ever use add_ranges_by_labels () for a single
11623 function section, all we have to do is to take out
11624 the #if 0 above. */
11625 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11626 ranges_by_label[lab_idx].begin,
11627 text_section_label,
11628 fmt, i * 2 * DWARF2_ADDR_SIZE);
11629 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11630 ranges_by_label[lab_idx].end,
11631 text_section_label, NULL);
11636 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11637 ranges_by_label[lab_idx].begin,
11638 fmt, i * 2 * DWARF2_ADDR_SIZE);
11639 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11640 ranges_by_label[lab_idx].end,
11646 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11647 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11653 /* Data structure containing information about input files. */
11656 const char *path; /* Complete file name. */
11657 const char *fname; /* File name part. */
11658 int length; /* Length of entire string. */
11659 struct dwarf_file_data * file_idx; /* Index in input file table. */
11660 int dir_idx; /* Index in directory table. */
11663 /* Data structure containing information about directories with source
11667 const char *path; /* Path including directory name. */
11668 int length; /* Path length. */
11669 int prefix; /* Index of directory entry which is a prefix. */
11670 int count; /* Number of files in this directory. */
11671 int dir_idx; /* Index of directory used as base. */
11674 /* Callback function for file_info comparison. We sort by looking at
11675 the directories in the path. */
11678 file_info_cmp (const void *p1, const void *p2)
11680 const struct file_info *const s1 = (const struct file_info *) p1;
11681 const struct file_info *const s2 = (const struct file_info *) p2;
11682 const unsigned char *cp1;
11683 const unsigned char *cp2;
11685 /* Take care of file names without directories. We need to make sure that
11686 we return consistent values to qsort since some will get confused if
11687 we return the same value when identical operands are passed in opposite
11688 orders. So if neither has a directory, return 0 and otherwise return
11689 1 or -1 depending on which one has the directory. */
11690 if ((s1->path == s1->fname || s2->path == s2->fname))
11691 return (s2->path == s2->fname) - (s1->path == s1->fname);
11693 cp1 = (const unsigned char *) s1->path;
11694 cp2 = (const unsigned char *) s2->path;
11700 /* Reached the end of the first path? If so, handle like above. */
11701 if ((cp1 == (const unsigned char *) s1->fname)
11702 || (cp2 == (const unsigned char *) s2->fname))
11703 return ((cp2 == (const unsigned char *) s2->fname)
11704 - (cp1 == (const unsigned char *) s1->fname));
11706 /* Character of current path component the same? */
11707 else if (*cp1 != *cp2)
11708 return *cp1 - *cp2;
11712 struct file_name_acquire_data
11714 struct file_info *files;
11719 /* Traversal function for the hash table. */
11722 file_name_acquire (void ** slot, void *data)
11724 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
11725 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
11726 struct file_info *fi;
11729 gcc_assert (fnad->max_files >= d->emitted_number);
11731 if (! d->emitted_number)
11734 gcc_assert (fnad->max_files != fnad->used_files);
11736 fi = fnad->files + fnad->used_files++;
11738 /* Skip all leading "./". */
11740 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
11743 /* Create a new array entry. */
11745 fi->length = strlen (f);
11748 /* Search for the file name part. */
11749 f = strrchr (f, DIR_SEPARATOR);
11750 #if defined (DIR_SEPARATOR_2)
11752 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
11756 if (f == NULL || f < g)
11762 fi->fname = f == NULL ? fi->path : f + 1;
11766 /* Output the directory table and the file name table. We try to minimize
11767 the total amount of memory needed. A heuristic is used to avoid large
11768 slowdowns with many input files. */
11771 output_file_names (void)
11773 struct file_name_acquire_data fnad;
11775 struct file_info *files;
11776 struct dir_info *dirs;
11784 if (!last_emitted_file)
11786 dw2_asm_output_data (1, 0, "End directory table");
11787 dw2_asm_output_data (1, 0, "End file name table");
11791 numfiles = last_emitted_file->emitted_number;
11793 /* Allocate the various arrays we need. */
11794 files = XALLOCAVEC (struct file_info, numfiles);
11795 dirs = XALLOCAVEC (struct dir_info, numfiles);
11797 fnad.files = files;
11798 fnad.used_files = 0;
11799 fnad.max_files = numfiles;
11800 htab_traverse (file_table, file_name_acquire, &fnad);
11801 gcc_assert (fnad.used_files == fnad.max_files);
11803 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
11805 /* Find all the different directories used. */
11806 dirs[0].path = files[0].path;
11807 dirs[0].length = files[0].fname - files[0].path;
11808 dirs[0].prefix = -1;
11810 dirs[0].dir_idx = 0;
11811 files[0].dir_idx = 0;
11814 for (i = 1; i < numfiles; i++)
11815 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
11816 && memcmp (dirs[ndirs - 1].path, files[i].path,
11817 dirs[ndirs - 1].length) == 0)
11819 /* Same directory as last entry. */
11820 files[i].dir_idx = ndirs - 1;
11821 ++dirs[ndirs - 1].count;
11827 /* This is a new directory. */
11828 dirs[ndirs].path = files[i].path;
11829 dirs[ndirs].length = files[i].fname - files[i].path;
11830 dirs[ndirs].count = 1;
11831 dirs[ndirs].dir_idx = ndirs;
11832 files[i].dir_idx = ndirs;
11834 /* Search for a prefix. */
11835 dirs[ndirs].prefix = -1;
11836 for (j = 0; j < ndirs; j++)
11837 if (dirs[j].length < dirs[ndirs].length
11838 && dirs[j].length > 1
11839 && (dirs[ndirs].prefix == -1
11840 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
11841 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
11842 dirs[ndirs].prefix = j;
11847 /* Now to the actual work. We have to find a subset of the directories which
11848 allow expressing the file name using references to the directory table
11849 with the least amount of characters. We do not do an exhaustive search
11850 where we would have to check out every combination of every single
11851 possible prefix. Instead we use a heuristic which provides nearly optimal
11852 results in most cases and never is much off. */
11853 saved = XALLOCAVEC (int, ndirs);
11854 savehere = XALLOCAVEC (int, ndirs);
11856 memset (saved, '\0', ndirs * sizeof (saved[0]));
11857 for (i = 0; i < ndirs; i++)
11862 /* We can always save some space for the current directory. But this
11863 does not mean it will be enough to justify adding the directory. */
11864 savehere[i] = dirs[i].length;
11865 total = (savehere[i] - saved[i]) * dirs[i].count;
11867 for (j = i + 1; j < ndirs; j++)
11870 if (saved[j] < dirs[i].length)
11872 /* Determine whether the dirs[i] path is a prefix of the
11876 k = dirs[j].prefix;
11877 while (k != -1 && k != (int) i)
11878 k = dirs[k].prefix;
11882 /* Yes it is. We can possibly save some memory by
11883 writing the filenames in dirs[j] relative to
11885 savehere[j] = dirs[i].length;
11886 total += (savehere[j] - saved[j]) * dirs[j].count;
11891 /* Check whether we can save enough to justify adding the dirs[i]
11893 if (total > dirs[i].length + 1)
11895 /* It's worthwhile adding. */
11896 for (j = i; j < ndirs; j++)
11897 if (savehere[j] > 0)
11899 /* Remember how much we saved for this directory so far. */
11900 saved[j] = savehere[j];
11902 /* Remember the prefix directory. */
11903 dirs[j].dir_idx = i;
11908 /* Emit the directory name table. */
11909 idx_offset = dirs[0].length > 0 ? 1 : 0;
11910 for (i = 1 - idx_offset; i < ndirs; i++)
11911 dw2_asm_output_nstring (dirs[i].path,
11913 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
11914 "Directory Entry: %#x", i + idx_offset);
11916 dw2_asm_output_data (1, 0, "End directory table");
11918 /* We have to emit them in the order of emitted_number since that's
11919 used in the debug info generation. To do this efficiently we
11920 generate a back-mapping of the indices first. */
11921 backmap = XALLOCAVEC (int, numfiles);
11922 for (i = 0; i < numfiles; i++)
11923 backmap[files[i].file_idx->emitted_number - 1] = i;
11925 /* Now write all the file names. */
11926 for (i = 0; i < numfiles; i++)
11928 int file_idx = backmap[i];
11929 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
11931 #ifdef VMS_DEBUGGING_INFO
11932 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11934 /* Setting these fields can lead to debugger miscomparisons,
11935 but VMS Debug requires them to be set correctly. */
11940 int maxfilelen = strlen (files[file_idx].path)
11941 + dirs[dir_idx].length
11942 + MAX_VMS_VERSION_LEN + 1;
11943 char *filebuf = XALLOCAVEC (char, maxfilelen);
11945 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
11946 snprintf (filebuf, maxfilelen, "%s;%d",
11947 files[file_idx].path + dirs[dir_idx].length, ver);
11949 dw2_asm_output_nstring
11950 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
11952 /* Include directory index. */
11953 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
11955 /* Modification time. */
11956 dw2_asm_output_data_uleb128
11957 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
11961 /* File length in bytes. */
11962 dw2_asm_output_data_uleb128
11963 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
11967 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
11968 "File Entry: %#x", (unsigned) i + 1);
11970 /* Include directory index. */
11971 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
11973 /* Modification time. */
11974 dw2_asm_output_data_uleb128 (0, NULL);
11976 /* File length in bytes. */
11977 dw2_asm_output_data_uleb128 (0, NULL);
11978 #endif /* VMS_DEBUGGING_INFO */
11981 dw2_asm_output_data (1, 0, "End file name table");
11985 /* Output the source line number correspondence information. This
11986 information goes into the .debug_line section. */
11989 output_line_info (void)
11991 char l1[20], l2[20], p1[20], p2[20];
11992 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
11993 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
11995 unsigned n_op_args;
11996 unsigned long lt_index;
11997 unsigned long current_line;
12000 unsigned long current_file;
12001 unsigned long function;
12002 int ver = dwarf_version;
12004 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12005 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12006 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12007 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12009 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12010 dw2_asm_output_data (4, 0xffffffff,
12011 "Initial length escape value indicating 64-bit DWARF extension");
12012 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12013 "Length of Source Line Info");
12014 ASM_OUTPUT_LABEL (asm_out_file, l1);
12016 dw2_asm_output_data (2, ver, "DWARF Version");
12017 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12018 ASM_OUTPUT_LABEL (asm_out_file, p1);
12020 /* Define the architecture-dependent minimum instruction length (in
12021 bytes). In this implementation of DWARF, this field is used for
12022 information purposes only. Since GCC generates assembly language,
12023 we have no a priori knowledge of how many instruction bytes are
12024 generated for each source line, and therefore can use only the
12025 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12026 commands. Accordingly, we fix this as `1', which is "correct
12027 enough" for all architectures, and don't let the target override. */
12028 dw2_asm_output_data (1, 1,
12029 "Minimum Instruction Length");
12032 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12033 "Maximum Operations Per Instruction");
12034 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12035 "Default is_stmt_start flag");
12036 dw2_asm_output_data (1, DWARF_LINE_BASE,
12037 "Line Base Value (Special Opcodes)");
12038 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12039 "Line Range Value (Special Opcodes)");
12040 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12041 "Special Opcode Base");
12043 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12047 case DW_LNS_advance_pc:
12048 case DW_LNS_advance_line:
12049 case DW_LNS_set_file:
12050 case DW_LNS_set_column:
12051 case DW_LNS_fixed_advance_pc:
12059 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12063 /* Write out the information about the files we use. */
12064 output_file_names ();
12065 ASM_OUTPUT_LABEL (asm_out_file, p2);
12067 /* We used to set the address register to the first location in the text
12068 section here, but that didn't accomplish anything since we already
12069 have a line note for the opening brace of the first function. */
12071 /* Generate the line number to PC correspondence table, encoded as
12072 a series of state machine operations. */
12076 if (cfun && in_cold_section_p)
12077 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12079 strcpy (prev_line_label, text_section_label);
12080 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12082 dw_line_info_ref line_info = &line_info_table[lt_index];
12085 /* Disable this optimization for now; GDB wants to see two line notes
12086 at the beginning of a function so it can find the end of the
12089 /* Don't emit anything for redundant notes. Just updating the
12090 address doesn't accomplish anything, because we already assume
12091 that anything after the last address is this line. */
12092 if (line_info->dw_line_num == current_line
12093 && line_info->dw_file_num == current_file)
12097 /* Emit debug info for the address of the current line.
12099 Unfortunately, we have little choice here currently, and must always
12100 use the most general form. GCC does not know the address delta
12101 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12102 attributes which will give an upper bound on the address range. We
12103 could perhaps use length attributes to determine when it is safe to
12104 use DW_LNS_fixed_advance_pc. */
12106 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12109 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12110 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12111 "DW_LNS_fixed_advance_pc");
12112 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12116 /* This can handle any delta. This takes
12117 4+DWARF2_ADDR_SIZE bytes. */
12118 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12119 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12120 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12121 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12124 strcpy (prev_line_label, line_label);
12126 /* Emit debug info for the source file of the current line, if
12127 different from the previous line. */
12128 if (line_info->dw_file_num != current_file)
12130 current_file = line_info->dw_file_num;
12131 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12132 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12135 /* Emit debug info for the current line number, choosing the encoding
12136 that uses the least amount of space. */
12137 if (line_info->dw_line_num != current_line)
12139 line_offset = line_info->dw_line_num - current_line;
12140 line_delta = line_offset - DWARF_LINE_BASE;
12141 current_line = line_info->dw_line_num;
12142 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12143 /* This can handle deltas from -10 to 234, using the current
12144 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12146 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12147 "line %lu", current_line);
12150 /* This can handle any delta. This takes at least 4 bytes,
12151 depending on the value being encoded. */
12152 dw2_asm_output_data (1, DW_LNS_advance_line,
12153 "advance to line %lu", current_line);
12154 dw2_asm_output_data_sleb128 (line_offset, NULL);
12155 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12159 /* We still need to start a new row, so output a copy insn. */
12160 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12163 /* Emit debug info for the address of the end of the function. */
12166 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12167 "DW_LNS_fixed_advance_pc");
12168 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12172 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12173 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12174 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12175 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12178 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12179 dw2_asm_output_data_uleb128 (1, NULL);
12180 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12185 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12187 dw_separate_line_info_ref line_info
12188 = &separate_line_info_table[lt_index];
12191 /* Don't emit anything for redundant notes. */
12192 if (line_info->dw_line_num == current_line
12193 && line_info->dw_file_num == current_file
12194 && line_info->function == function)
12198 /* Emit debug info for the address of the current line. If this is
12199 a new function, or the first line of a function, then we need
12200 to handle it differently. */
12201 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12203 if (function != line_info->function)
12205 function = line_info->function;
12207 /* Set the address register to the first line in the function. */
12208 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12209 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12210 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12211 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12215 /* ??? See the DW_LNS_advance_pc comment above. */
12218 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12219 "DW_LNS_fixed_advance_pc");
12220 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12224 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12225 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12226 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12227 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12231 strcpy (prev_line_label, line_label);
12233 /* Emit debug info for the source file of the current line, if
12234 different from the previous line. */
12235 if (line_info->dw_file_num != current_file)
12237 current_file = line_info->dw_file_num;
12238 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12239 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12242 /* Emit debug info for the current line number, choosing the encoding
12243 that uses the least amount of space. */
12244 if (line_info->dw_line_num != current_line)
12246 line_offset = line_info->dw_line_num - current_line;
12247 line_delta = line_offset - DWARF_LINE_BASE;
12248 current_line = line_info->dw_line_num;
12249 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12250 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12251 "line %lu", current_line);
12254 dw2_asm_output_data (1, DW_LNS_advance_line,
12255 "advance to line %lu", current_line);
12256 dw2_asm_output_data_sleb128 (line_offset, NULL);
12257 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12261 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12269 /* If we're done with a function, end its sequence. */
12270 if (lt_index == separate_line_info_table_in_use
12271 || separate_line_info_table[lt_index].function != function)
12276 /* Emit debug info for the address of the end of the function. */
12277 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12280 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12281 "DW_LNS_fixed_advance_pc");
12282 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12286 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12287 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12288 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12289 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12292 /* Output the marker for the end of this sequence. */
12293 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12294 dw2_asm_output_data_uleb128 (1, NULL);
12295 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12299 /* Output the marker for the end of the line number info. */
12300 ASM_OUTPUT_LABEL (asm_out_file, l2);
12303 /* Return the size of the .debug_dcall table for the compilation unit. */
12305 static unsigned long
12306 size_of_dcall_table (void)
12308 unsigned long size;
12311 tree last_poc_decl = NULL;
12313 /* Header: version + debug info section pointer + pointer size. */
12314 size = 2 + DWARF_OFFSET_SIZE + 1;
12316 /* Each entry: code label + DIE offset. */
12317 for (i = 0; VEC_iterate (dcall_entry, dcall_table, i, p); i++)
12319 gcc_assert (p->targ_die != NULL);
12320 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12321 if (p->poc_decl != last_poc_decl)
12323 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12324 gcc_assert (poc_die);
12325 last_poc_decl = p->poc_decl;
12327 size += (DWARF_OFFSET_SIZE
12328 + size_of_uleb128 (poc_die->die_offset));
12330 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->targ_die->die_offset);
12336 /* Output the direct call table used to disambiguate PC values when
12337 identical function have been merged. */
12340 output_dcall_table (void)
12343 unsigned long dcall_length = size_of_dcall_table ();
12345 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12346 tree last_poc_decl = NULL;
12348 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12349 dw2_asm_output_data (4, 0xffffffff,
12350 "Initial length escape value indicating 64-bit DWARF extension");
12351 dw2_asm_output_data (DWARF_OFFSET_SIZE, dcall_length,
12352 "Length of Direct Call Table");
12353 dw2_asm_output_data (2, 4, "Version number");
12354 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12355 debug_info_section,
12356 "Offset of Compilation Unit Info");
12357 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12359 for (i = 0; VEC_iterate (dcall_entry, dcall_table, i, p); i++)
12361 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12362 if (p->poc_decl != last_poc_decl)
12364 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12365 last_poc_decl = p->poc_decl;
12368 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "New caller");
12369 dw2_asm_output_data_uleb128 (poc_die->die_offset,
12370 "Caller DIE offset");
12373 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12374 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12375 dw2_asm_output_data_uleb128 (p->targ_die->die_offset,
12376 "Callee DIE offset");
12380 /* Return the size of the .debug_vcall table for the compilation unit. */
12382 static unsigned long
12383 size_of_vcall_table (void)
12385 unsigned long size;
12389 /* Header: version + pointer size. */
12392 /* Each entry: code label + vtable slot index. */
12393 for (i = 0; VEC_iterate (vcall_entry, vcall_table, i, p); i++)
12394 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->vtable_slot);
12399 /* Output the virtual call table used to disambiguate PC values when
12400 identical function have been merged. */
12403 output_vcall_table (void)
12406 unsigned long vcall_length = size_of_vcall_table ();
12408 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12410 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12411 dw2_asm_output_data (4, 0xffffffff,
12412 "Initial length escape value indicating 64-bit DWARF extension");
12413 dw2_asm_output_data (DWARF_OFFSET_SIZE, vcall_length,
12414 "Length of Virtual Call Table");
12415 dw2_asm_output_data (2, 4, "Version number");
12416 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12418 for (i = 0; VEC_iterate (vcall_entry, vcall_table, i, p); i++)
12420 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12421 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12422 dw2_asm_output_data_uleb128 (p->vtable_slot, "Vtable slot");
12426 /* Given a pointer to a tree node for some base type, return a pointer to
12427 a DIE that describes the given type.
12429 This routine must only be called for GCC type nodes that correspond to
12430 Dwarf base (fundamental) types. */
12433 base_type_die (tree type)
12435 dw_die_ref base_type_result;
12436 enum dwarf_type encoding;
12438 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12441 /* If this is a subtype that should not be emitted as a subrange type,
12442 use the base type. See subrange_type_for_debug_p. */
12443 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12444 type = TREE_TYPE (type);
12446 switch (TREE_CODE (type))
12449 if ((dwarf_version >= 4 || !dwarf_strict)
12450 && TYPE_NAME (type)
12451 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12452 && DECL_IS_BUILTIN (TYPE_NAME (type))
12453 && DECL_NAME (TYPE_NAME (type)))
12455 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12456 if (strcmp (name, "char16_t") == 0
12457 || strcmp (name, "char32_t") == 0)
12459 encoding = DW_ATE_UTF;
12463 if (TYPE_STRING_FLAG (type))
12465 if (TYPE_UNSIGNED (type))
12466 encoding = DW_ATE_unsigned_char;
12468 encoding = DW_ATE_signed_char;
12470 else if (TYPE_UNSIGNED (type))
12471 encoding = DW_ATE_unsigned;
12473 encoding = DW_ATE_signed;
12477 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12479 if (dwarf_version >= 3 || !dwarf_strict)
12480 encoding = DW_ATE_decimal_float;
12482 encoding = DW_ATE_lo_user;
12485 encoding = DW_ATE_float;
12488 case FIXED_POINT_TYPE:
12489 if (!(dwarf_version >= 3 || !dwarf_strict))
12490 encoding = DW_ATE_lo_user;
12491 else if (TYPE_UNSIGNED (type))
12492 encoding = DW_ATE_unsigned_fixed;
12494 encoding = DW_ATE_signed_fixed;
12497 /* Dwarf2 doesn't know anything about complex ints, so use
12498 a user defined type for it. */
12500 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12501 encoding = DW_ATE_complex_float;
12503 encoding = DW_ATE_lo_user;
12507 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12508 encoding = DW_ATE_boolean;
12512 /* No other TREE_CODEs are Dwarf fundamental types. */
12513 gcc_unreachable ();
12516 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
12518 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12519 int_size_in_bytes (type));
12520 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12522 return base_type_result;
12525 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12526 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12529 is_base_type (tree type)
12531 switch (TREE_CODE (type))
12537 case FIXED_POINT_TYPE:
12545 case QUAL_UNION_TYPE:
12546 case ENUMERAL_TYPE:
12547 case FUNCTION_TYPE:
12550 case REFERENCE_TYPE:
12557 gcc_unreachable ();
12563 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12564 node, return the size in bits for the type if it is a constant, or else
12565 return the alignment for the type if the type's size is not constant, or
12566 else return BITS_PER_WORD if the type actually turns out to be an
12567 ERROR_MARK node. */
12569 static inline unsigned HOST_WIDE_INT
12570 simple_type_size_in_bits (const_tree type)
12572 if (TREE_CODE (type) == ERROR_MARK)
12573 return BITS_PER_WORD;
12574 else if (TYPE_SIZE (type) == NULL_TREE)
12576 else if (host_integerp (TYPE_SIZE (type), 1))
12577 return tree_low_cst (TYPE_SIZE (type), 1);
12579 return TYPE_ALIGN (type);
12582 /* Similarly, but return a double_int instead of UHWI. */
12584 static inline double_int
12585 double_int_type_size_in_bits (const_tree type)
12587 if (TREE_CODE (type) == ERROR_MARK)
12588 return uhwi_to_double_int (BITS_PER_WORD);
12589 else if (TYPE_SIZE (type) == NULL_TREE)
12590 return double_int_zero;
12591 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12592 return tree_to_double_int (TYPE_SIZE (type));
12594 return uhwi_to_double_int (TYPE_ALIGN (type));
12597 /* Given a pointer to a tree node for a subrange type, return a pointer
12598 to a DIE that describes the given type. */
12601 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12603 dw_die_ref subrange_die;
12604 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12606 if (context_die == NULL)
12607 context_die = comp_unit_die;
12609 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12611 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12613 /* The size of the subrange type and its base type do not match,
12614 so we need to generate a size attribute for the subrange type. */
12615 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12619 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12621 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12623 return subrange_die;
12626 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12627 entry that chains various modifiers in front of the given type. */
12630 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12631 dw_die_ref context_die)
12633 enum tree_code code = TREE_CODE (type);
12634 dw_die_ref mod_type_die;
12635 dw_die_ref sub_die = NULL;
12636 tree item_type = NULL;
12637 tree qualified_type;
12638 tree name, low, high;
12640 if (code == ERROR_MARK)
12643 /* See if we already have the appropriately qualified variant of
12646 = get_qualified_type (type,
12647 ((is_const_type ? TYPE_QUAL_CONST : 0)
12648 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12650 if (qualified_type == sizetype
12651 && TYPE_NAME (qualified_type)
12652 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12654 #ifdef ENABLE_CHECKING
12655 gcc_assert (TREE_CODE (TREE_TYPE (TYPE_NAME (qualified_type)))
12657 && TYPE_PRECISION (TREE_TYPE (TYPE_NAME (qualified_type)))
12658 == TYPE_PRECISION (qualified_type)
12659 && TYPE_UNSIGNED (TREE_TYPE (TYPE_NAME (qualified_type)))
12660 == TYPE_UNSIGNED (qualified_type));
12662 qualified_type = TREE_TYPE (TYPE_NAME (qualified_type));
12665 /* If we do, then we can just use its DIE, if it exists. */
12666 if (qualified_type)
12668 mod_type_die = lookup_type_die (qualified_type);
12670 return mod_type_die;
12673 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12675 /* Handle C typedef types. */
12676 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12677 && !DECL_ARTIFICIAL (name))
12679 tree dtype = TREE_TYPE (name);
12681 if (qualified_type == dtype)
12683 /* For a named type, use the typedef. */
12684 gen_type_die (qualified_type, context_die);
12685 return lookup_type_die (qualified_type);
12687 else if (is_const_type < TYPE_READONLY (dtype)
12688 || is_volatile_type < TYPE_VOLATILE (dtype)
12689 || (is_const_type <= TYPE_READONLY (dtype)
12690 && is_volatile_type <= TYPE_VOLATILE (dtype)
12691 && DECL_ORIGINAL_TYPE (name) != type))
12692 /* cv-unqualified version of named type. Just use the unnamed
12693 type to which it refers. */
12694 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12695 is_const_type, is_volatile_type,
12697 /* Else cv-qualified version of named type; fall through. */
12702 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
12703 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12705 else if (is_volatile_type)
12707 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
12708 sub_die = modified_type_die (type, 0, 0, context_die);
12710 else if (code == POINTER_TYPE)
12712 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
12713 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12714 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12715 item_type = TREE_TYPE (type);
12716 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12717 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12718 TYPE_ADDR_SPACE (item_type));
12720 else if (code == REFERENCE_TYPE)
12722 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
12723 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die,
12726 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
12727 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12728 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12729 item_type = TREE_TYPE (type);
12730 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12731 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12732 TYPE_ADDR_SPACE (item_type));
12734 else if (code == INTEGER_TYPE
12735 && TREE_TYPE (type) != NULL_TREE
12736 && subrange_type_for_debug_p (type, &low, &high))
12738 mod_type_die = subrange_type_die (type, low, high, context_die);
12739 item_type = TREE_TYPE (type);
12741 else if (is_base_type (type))
12742 mod_type_die = base_type_die (type);
12745 gen_type_die (type, context_die);
12747 /* We have to get the type_main_variant here (and pass that to the
12748 `lookup_type_die' routine) because the ..._TYPE node we have
12749 might simply be a *copy* of some original type node (where the
12750 copy was created to help us keep track of typedef names) and
12751 that copy might have a different TYPE_UID from the original
12753 if (TREE_CODE (type) != VECTOR_TYPE)
12754 return lookup_type_die (type_main_variant (type));
12756 /* Vectors have the debugging information in the type,
12757 not the main variant. */
12758 return lookup_type_die (type);
12761 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12762 don't output a DW_TAG_typedef, since there isn't one in the
12763 user's program; just attach a DW_AT_name to the type.
12764 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12765 if the base type already has the same name. */
12767 && ((TREE_CODE (name) != TYPE_DECL
12768 && (qualified_type == TYPE_MAIN_VARIANT (type)
12769 || (!is_const_type && !is_volatile_type)))
12770 || (TREE_CODE (name) == TYPE_DECL
12771 && TREE_TYPE (name) == qualified_type
12772 && DECL_NAME (name))))
12774 if (TREE_CODE (name) == TYPE_DECL)
12775 /* Could just call add_name_and_src_coords_attributes here,
12776 but since this is a builtin type it doesn't have any
12777 useful source coordinates anyway. */
12778 name = DECL_NAME (name);
12779 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12781 /* This probably indicates a bug. */
12782 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12783 add_name_attribute (mod_type_die, "__unknown__");
12785 if (qualified_type)
12786 equate_type_number_to_die (qualified_type, mod_type_die);
12789 /* We must do this after the equate_type_number_to_die call, in case
12790 this is a recursive type. This ensures that the modified_type_die
12791 recursion will terminate even if the type is recursive. Recursive
12792 types are possible in Ada. */
12793 sub_die = modified_type_die (item_type,
12794 TYPE_READONLY (item_type),
12795 TYPE_VOLATILE (item_type),
12798 if (sub_die != NULL)
12799 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
12801 return mod_type_die;
12804 /* Generate DIEs for the generic parameters of T.
12805 T must be either a generic type or a generic function.
12806 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12809 gen_generic_params_dies (tree t)
12813 dw_die_ref die = NULL;
12815 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
12819 die = lookup_type_die (t);
12820 else if (DECL_P (t))
12821 die = lookup_decl_die (t);
12825 parms = lang_hooks.get_innermost_generic_parms (t);
12827 /* T has no generic parameter. It means T is neither a generic type
12828 or function. End of story. */
12831 parms_num = TREE_VEC_LENGTH (parms);
12832 args = lang_hooks.get_innermost_generic_args (t);
12833 for (i = 0; i < parms_num; i++)
12835 tree parm, arg, arg_pack_elems;
12837 parm = TREE_VEC_ELT (parms, i);
12838 arg = TREE_VEC_ELT (args, i);
12839 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
12840 gcc_assert (parm && TREE_VALUE (parm) && arg);
12842 if (parm && TREE_VALUE (parm) && arg)
12844 /* If PARM represents a template parameter pack,
12845 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12846 by DW_TAG_template_*_parameter DIEs for the argument
12847 pack elements of ARG. Note that ARG would then be
12848 an argument pack. */
12849 if (arg_pack_elems)
12850 template_parameter_pack_die (TREE_VALUE (parm),
12854 generic_parameter_die (TREE_VALUE (parm), arg,
12855 true /* Emit DW_AT_name */, die);
12860 /* Create and return a DIE for PARM which should be
12861 the representation of a generic type parameter.
12862 For instance, in the C++ front end, PARM would be a template parameter.
12863 ARG is the argument to PARM.
12864 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12866 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12867 as a child node. */
12870 generic_parameter_die (tree parm, tree arg,
12872 dw_die_ref parent_die)
12874 dw_die_ref tmpl_die = NULL;
12875 const char *name = NULL;
12877 if (!parm || !DECL_NAME (parm) || !arg)
12880 /* We support non-type generic parameters and arguments,
12881 type generic parameters and arguments, as well as
12882 generic generic parameters (a.k.a. template template parameters in C++)
12884 if (TREE_CODE (parm) == PARM_DECL)
12885 /* PARM is a nontype generic parameter */
12886 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
12887 else if (TREE_CODE (parm) == TYPE_DECL)
12888 /* PARM is a type generic parameter. */
12889 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
12890 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
12891 /* PARM is a generic generic parameter.
12892 Its DIE is a GNU extension. It shall have a
12893 DW_AT_name attribute to represent the name of the template template
12894 parameter, and a DW_AT_GNU_template_name attribute to represent the
12895 name of the template template argument. */
12896 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
12899 gcc_unreachable ();
12905 /* If PARM is a generic parameter pack, it means we are
12906 emitting debug info for a template argument pack element.
12907 In other terms, ARG is a template argument pack element.
12908 In that case, we don't emit any DW_AT_name attribute for
12912 name = IDENTIFIER_POINTER (DECL_NAME (parm));
12914 add_AT_string (tmpl_die, DW_AT_name, name);
12917 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
12919 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12920 TMPL_DIE should have a child DW_AT_type attribute that is set
12921 to the type of the argument to PARM, which is ARG.
12922 If PARM is a type generic parameter, TMPL_DIE should have a
12923 child DW_AT_type that is set to ARG. */
12924 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
12925 add_type_attribute (tmpl_die, tmpl_type, 0,
12926 TREE_THIS_VOLATILE (tmpl_type),
12931 /* So TMPL_DIE is a DIE representing a
12932 a generic generic template parameter, a.k.a template template
12933 parameter in C++ and arg is a template. */
12935 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12936 to the name of the argument. */
12937 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
12939 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
12942 if (TREE_CODE (parm) == PARM_DECL)
12943 /* So PARM is a non-type generic parameter.
12944 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12945 attribute of TMPL_DIE which value represents the value
12947 We must be careful here:
12948 The value of ARG might reference some function decls.
12949 We might currently be emitting debug info for a generic
12950 type and types are emitted before function decls, we don't
12951 know if the function decls referenced by ARG will actually be
12952 emitted after cgraph computations.
12953 So must defer the generation of the DW_AT_const_value to
12954 after cgraph is ready. */
12955 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
12961 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
12962 PARM_PACK must be a template parameter pack. The returned DIE
12963 will be child DIE of PARENT_DIE. */
12966 template_parameter_pack_die (tree parm_pack,
12967 tree parm_pack_args,
12968 dw_die_ref parent_die)
12973 gcc_assert (parent_die && parm_pack);
12975 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
12976 add_name_and_src_coords_attributes (die, parm_pack);
12977 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
12978 generic_parameter_die (parm_pack,
12979 TREE_VEC_ELT (parm_pack_args, j),
12980 false /* Don't emit DW_AT_name */,
12985 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
12986 an enumerated type. */
12989 type_is_enum (const_tree type)
12991 return TREE_CODE (type) == ENUMERAL_TYPE;
12994 /* Return the DBX register number described by a given RTL node. */
12996 static unsigned int
12997 dbx_reg_number (const_rtx rtl)
12999 unsigned regno = REGNO (rtl);
13001 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13003 #ifdef LEAF_REG_REMAP
13004 if (current_function_uses_only_leaf_regs)
13006 int leaf_reg = LEAF_REG_REMAP (regno);
13007 if (leaf_reg != -1)
13008 regno = (unsigned) leaf_reg;
13012 return DBX_REGISTER_NUMBER (regno);
13015 /* Optionally add a DW_OP_piece term to a location description expression.
13016 DW_OP_piece is only added if the location description expression already
13017 doesn't end with DW_OP_piece. */
13020 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13022 dw_loc_descr_ref loc;
13024 if (*list_head != NULL)
13026 /* Find the end of the chain. */
13027 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13030 if (loc->dw_loc_opc != DW_OP_piece)
13031 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13035 /* Return a location descriptor that designates a machine register or
13036 zero if there is none. */
13038 static dw_loc_descr_ref
13039 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13043 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13046 /* We only use "frame base" when we're sure we're talking about the
13047 post-prologue local stack frame. We do this by *not* running
13048 register elimination until this point, and recognizing the special
13049 argument pointer and soft frame pointer rtx's.
13050 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13051 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13052 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13054 dw_loc_descr_ref result = NULL;
13056 if (dwarf_version >= 4 || !dwarf_strict)
13058 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13060 add_loc_descr (&result,
13061 new_loc_descr (DW_OP_stack_value, 0, 0));
13066 regs = targetm.dwarf_register_span (rtl);
13068 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13069 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13071 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13074 /* Return a location descriptor that designates a machine register for
13075 a given hard register number. */
13077 static dw_loc_descr_ref
13078 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13080 dw_loc_descr_ref reg_loc_descr;
13084 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13086 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13088 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13089 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13091 return reg_loc_descr;
13094 /* Given an RTL of a register, return a location descriptor that
13095 designates a value that spans more than one register. */
13097 static dw_loc_descr_ref
13098 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13099 enum var_init_status initialized)
13101 int nregs, size, i;
13103 dw_loc_descr_ref loc_result = NULL;
13106 #ifdef LEAF_REG_REMAP
13107 if (current_function_uses_only_leaf_regs)
13109 int leaf_reg = LEAF_REG_REMAP (reg);
13110 if (leaf_reg != -1)
13111 reg = (unsigned) leaf_reg;
13114 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13115 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13117 /* Simple, contiguous registers. */
13118 if (regs == NULL_RTX)
13120 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13125 dw_loc_descr_ref t;
13127 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13128 VAR_INIT_STATUS_INITIALIZED);
13129 add_loc_descr (&loc_result, t);
13130 add_loc_descr_op_piece (&loc_result, size);
13136 /* Now onto stupid register sets in non contiguous locations. */
13138 gcc_assert (GET_CODE (regs) == PARALLEL);
13140 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13143 for (i = 0; i < XVECLEN (regs, 0); ++i)
13145 dw_loc_descr_ref t;
13147 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13148 VAR_INIT_STATUS_INITIALIZED);
13149 add_loc_descr (&loc_result, t);
13150 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13151 add_loc_descr_op_piece (&loc_result, size);
13154 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13155 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13159 /* Return a location descriptor that designates a constant. */
13161 static dw_loc_descr_ref
13162 int_loc_descriptor (HOST_WIDE_INT i)
13164 enum dwarf_location_atom op;
13166 /* Pick the smallest representation of a constant, rather than just
13167 defaulting to the LEB encoding. */
13171 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13172 else if (i <= 0xff)
13173 op = DW_OP_const1u;
13174 else if (i <= 0xffff)
13175 op = DW_OP_const2u;
13176 else if (HOST_BITS_PER_WIDE_INT == 32
13177 || i <= 0xffffffff)
13178 op = DW_OP_const4u;
13185 op = DW_OP_const1s;
13186 else if (i >= -0x8000)
13187 op = DW_OP_const2s;
13188 else if (HOST_BITS_PER_WIDE_INT == 32
13189 || i >= -0x80000000)
13190 op = DW_OP_const4s;
13195 return new_loc_descr (op, i, 0);
13198 /* Return loc description representing "address" of integer value.
13199 This can appear only as toplevel expression. */
13201 static dw_loc_descr_ref
13202 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13205 dw_loc_descr_ref loc_result = NULL;
13207 if (!(dwarf_version >= 4 || !dwarf_strict))
13214 else if (i <= 0xff)
13216 else if (i <= 0xffff)
13218 else if (HOST_BITS_PER_WIDE_INT == 32
13219 || i <= 0xffffffff)
13222 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13228 else if (i >= -0x8000)
13230 else if (HOST_BITS_PER_WIDE_INT == 32
13231 || i >= -0x80000000)
13234 litsize = 1 + size_of_sleb128 (i);
13236 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13237 is more compact. For DW_OP_stack_value we need:
13238 litsize + 1 (DW_OP_stack_value)
13239 and for DW_OP_implicit_value:
13240 1 (DW_OP_implicit_value) + 1 (length) + size. */
13241 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13243 loc_result = int_loc_descriptor (i);
13244 add_loc_descr (&loc_result,
13245 new_loc_descr (DW_OP_stack_value, 0, 0));
13249 loc_result = new_loc_descr (DW_OP_implicit_value,
13251 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13252 loc_result->dw_loc_oprnd2.v.val_int = i;
13256 /* Return a location descriptor that designates a base+offset location. */
13258 static dw_loc_descr_ref
13259 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13260 enum var_init_status initialized)
13262 unsigned int regno;
13263 dw_loc_descr_ref result;
13264 dw_fde_ref fde = current_fde ();
13266 /* We only use "frame base" when we're sure we're talking about the
13267 post-prologue local stack frame. We do this by *not* running
13268 register elimination until this point, and recognizing the special
13269 argument pointer and soft frame pointer rtx's. */
13270 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13272 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13276 if (GET_CODE (elim) == PLUS)
13278 offset += INTVAL (XEXP (elim, 1));
13279 elim = XEXP (elim, 0);
13281 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13282 && (elim == hard_frame_pointer_rtx
13283 || elim == stack_pointer_rtx))
13284 || elim == (frame_pointer_needed
13285 ? hard_frame_pointer_rtx
13286 : stack_pointer_rtx));
13288 /* If drap register is used to align stack, use frame
13289 pointer + offset to access stack variables. If stack
13290 is aligned without drap, use stack pointer + offset to
13291 access stack variables. */
13292 if (crtl->stack_realign_tried
13293 && reg == frame_pointer_rtx)
13296 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13297 ? HARD_FRAME_POINTER_REGNUM
13298 : STACK_POINTER_REGNUM);
13299 return new_reg_loc_descr (base_reg, offset);
13302 offset += frame_pointer_fb_offset;
13303 return new_loc_descr (DW_OP_fbreg, offset, 0);
13308 && (fde->drap_reg == REGNO (reg)
13309 || fde->vdrap_reg == REGNO (reg)))
13311 /* Use cfa+offset to represent the location of arguments passed
13312 on the stack when drap is used to align stack.
13313 Only do this when not optimizing, for optimized code var-tracking
13314 is supposed to track where the arguments live and the register
13315 used as vdrap or drap in some spot might be used for something
13316 else in other part of the routine. */
13317 return new_loc_descr (DW_OP_fbreg, offset, 0);
13320 regno = dbx_reg_number (reg);
13322 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13325 result = new_loc_descr (DW_OP_bregx, regno, offset);
13327 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13328 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13333 /* Return true if this RTL expression describes a base+offset calculation. */
13336 is_based_loc (const_rtx rtl)
13338 return (GET_CODE (rtl) == PLUS
13339 && ((REG_P (XEXP (rtl, 0))
13340 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13341 && CONST_INT_P (XEXP (rtl, 1)))));
13344 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13347 static dw_loc_descr_ref
13348 tls_mem_loc_descriptor (rtx mem)
13351 dw_loc_descr_ref loc_result;
13353 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13356 base = get_base_address (MEM_EXPR (mem));
13358 || TREE_CODE (base) != VAR_DECL
13359 || !DECL_THREAD_LOCAL_P (base))
13362 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13363 if (loc_result == NULL)
13366 if (INTVAL (MEM_OFFSET (mem)))
13367 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13372 /* Output debug info about reason why we failed to expand expression as dwarf
13376 expansion_failed (tree expr, rtx rtl, char const *reason)
13378 if (dump_file && (dump_flags & TDF_DETAILS))
13380 fprintf (dump_file, "Failed to expand as dwarf: ");
13382 print_generic_expr (dump_file, expr, dump_flags);
13385 fprintf (dump_file, "\n");
13386 print_rtl (dump_file, rtl);
13388 fprintf (dump_file, "\nReason: %s\n", reason);
13392 /* Helper function for const_ok_for_output, called either directly
13393 or via for_each_rtx. */
13396 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13400 if (GET_CODE (rtl) == UNSPEC)
13402 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13403 we can't express it in the debug info. */
13404 #ifdef ENABLE_CHECKING
13405 inform (current_function_decl
13406 ? DECL_SOURCE_LOCATION (current_function_decl)
13407 : UNKNOWN_LOCATION,
13408 "non-delegitimized UNSPEC %d found in variable location",
13411 expansion_failed (NULL_TREE, rtl,
13412 "UNSPEC hasn't been delegitimized.\n");
13416 if (GET_CODE (rtl) != SYMBOL_REF)
13419 if (CONSTANT_POOL_ADDRESS_P (rtl))
13422 get_pool_constant_mark (rtl, &marked);
13423 /* If all references to this pool constant were optimized away,
13424 it was not output and thus we can't represent it. */
13427 expansion_failed (NULL_TREE, rtl,
13428 "Constant was removed from constant pool.\n");
13433 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13436 /* Avoid references to external symbols in debug info, on several targets
13437 the linker might even refuse to link when linking a shared library,
13438 and in many other cases the relocations for .debug_info/.debug_loc are
13439 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13440 to be defined within the same shared library or executable are fine. */
13441 if (SYMBOL_REF_EXTERNAL_P (rtl))
13443 tree decl = SYMBOL_REF_DECL (rtl);
13445 if (decl == NULL || !targetm.binds_local_p (decl))
13447 expansion_failed (NULL_TREE, rtl,
13448 "Symbol not defined in current TU.\n");
13456 /* Return true if constant RTL can be emitted in DW_OP_addr or
13457 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13458 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13461 const_ok_for_output (rtx rtl)
13463 if (GET_CODE (rtl) == SYMBOL_REF)
13464 return const_ok_for_output_1 (&rtl, NULL) == 0;
13466 if (GET_CODE (rtl) == CONST)
13467 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13472 /* The following routine converts the RTL for a variable or parameter
13473 (resident in memory) into an equivalent Dwarf representation of a
13474 mechanism for getting the address of that same variable onto the top of a
13475 hypothetical "address evaluation" stack.
13477 When creating memory location descriptors, we are effectively transforming
13478 the RTL for a memory-resident object into its Dwarf postfix expression
13479 equivalent. This routine recursively descends an RTL tree, turning
13480 it into Dwarf postfix code as it goes.
13482 MODE is the mode of the memory reference, needed to handle some
13483 autoincrement addressing modes.
13485 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13486 location list for RTL.
13488 Return 0 if we can't represent the location. */
13490 static dw_loc_descr_ref
13491 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13492 enum var_init_status initialized)
13494 dw_loc_descr_ref mem_loc_result = NULL;
13495 enum dwarf_location_atom op;
13496 dw_loc_descr_ref op0, op1;
13498 /* Note that for a dynamically sized array, the location we will generate a
13499 description of here will be the lowest numbered location which is
13500 actually within the array. That's *not* necessarily the same as the
13501 zeroth element of the array. */
13503 rtl = targetm.delegitimize_address (rtl);
13505 switch (GET_CODE (rtl))
13510 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13513 /* The case of a subreg may arise when we have a local (register)
13514 variable or a formal (register) parameter which doesn't quite fill
13515 up an entire register. For now, just assume that it is
13516 legitimate to make the Dwarf info refer to the whole register which
13517 contains the given subreg. */
13518 if (!subreg_lowpart_p (rtl))
13520 rtl = SUBREG_REG (rtl);
13521 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13523 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13525 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13529 /* Whenever a register number forms a part of the description of the
13530 method for calculating the (dynamic) address of a memory resident
13531 object, DWARF rules require the register number be referred to as
13532 a "base register". This distinction is not based in any way upon
13533 what category of register the hardware believes the given register
13534 belongs to. This is strictly DWARF terminology we're dealing with
13535 here. Note that in cases where the location of a memory-resident
13536 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13537 OP_CONST (0)) the actual DWARF location descriptor that we generate
13538 may just be OP_BASEREG (basereg). This may look deceptively like
13539 the object in question was allocated to a register (rather than in
13540 memory) so DWARF consumers need to be aware of the subtle
13541 distinction between OP_REG and OP_BASEREG. */
13542 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13543 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13544 else if (stack_realign_drap
13546 && crtl->args.internal_arg_pointer == rtl
13547 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13549 /* If RTL is internal_arg_pointer, which has been optimized
13550 out, use DRAP instead. */
13551 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13552 VAR_INIT_STATUS_INITIALIZED);
13558 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13559 VAR_INIT_STATUS_INITIALIZED);
13564 int shift = DWARF2_ADDR_SIZE
13565 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13566 shift *= BITS_PER_UNIT;
13567 if (GET_CODE (rtl) == SIGN_EXTEND)
13571 mem_loc_result = op0;
13572 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13573 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13574 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13575 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13580 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13581 VAR_INIT_STATUS_INITIALIZED);
13582 if (mem_loc_result == NULL)
13583 mem_loc_result = tls_mem_loc_descriptor (rtl);
13584 if (mem_loc_result != 0)
13586 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13588 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13591 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13592 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13594 add_loc_descr (&mem_loc_result,
13595 new_loc_descr (DW_OP_deref_size,
13596 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13600 rtx new_rtl = avoid_constant_pool_reference (rtl);
13601 if (new_rtl != rtl)
13602 return mem_loc_descriptor (new_rtl, mode, initialized);
13607 rtl = XEXP (rtl, 1);
13609 /* ... fall through ... */
13612 /* Some ports can transform a symbol ref into a label ref, because
13613 the symbol ref is too far away and has to be dumped into a constant
13617 if (GET_CODE (rtl) == SYMBOL_REF
13618 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13620 dw_loc_descr_ref temp;
13622 /* If this is not defined, we have no way to emit the data. */
13623 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13626 /* We used to emit DW_OP_addr here, but that's wrong, since
13627 DW_OP_addr should be relocated by the debug info consumer,
13628 while DW_OP_GNU_push_tls_address operand should not. */
13629 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13630 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13631 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13632 temp->dw_loc_oprnd1.v.val_addr = rtl;
13633 temp->dtprel = true;
13635 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13636 add_loc_descr (&mem_loc_result, temp);
13641 if (!const_ok_for_output (rtl))
13645 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13646 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13647 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13648 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13654 expansion_failed (NULL_TREE, rtl,
13655 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13659 /* Extract the PLUS expression nested inside and fall into
13660 PLUS code below. */
13661 rtl = XEXP (rtl, 1);
13666 /* Turn these into a PLUS expression and fall into the PLUS code
13668 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13669 GEN_INT (GET_CODE (rtl) == PRE_INC
13670 ? GET_MODE_UNIT_SIZE (mode)
13671 : -GET_MODE_UNIT_SIZE (mode)));
13673 /* ... fall through ... */
13677 if (is_based_loc (rtl))
13678 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13679 INTVAL (XEXP (rtl, 1)),
13680 VAR_INIT_STATUS_INITIALIZED);
13683 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13684 VAR_INIT_STATUS_INITIALIZED);
13685 if (mem_loc_result == 0)
13688 if (CONST_INT_P (XEXP (rtl, 1)))
13689 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13692 dw_loc_descr_ref mem_loc_result2
13693 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13694 VAR_INIT_STATUS_INITIALIZED);
13695 if (mem_loc_result2 == 0)
13697 add_loc_descr (&mem_loc_result, mem_loc_result2);
13698 add_loc_descr (&mem_loc_result,
13699 new_loc_descr (DW_OP_plus, 0, 0));
13704 /* If a pseudo-reg is optimized away, it is possible for it to
13705 be replaced with a MEM containing a multiply or shift. */
13747 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13748 VAR_INIT_STATUS_INITIALIZED);
13749 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13750 VAR_INIT_STATUS_INITIALIZED);
13752 if (op0 == 0 || op1 == 0)
13755 mem_loc_result = op0;
13756 add_loc_descr (&mem_loc_result, op1);
13757 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13761 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13762 VAR_INIT_STATUS_INITIALIZED);
13763 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13764 VAR_INIT_STATUS_INITIALIZED);
13766 if (op0 == 0 || op1 == 0)
13769 mem_loc_result = op0;
13770 add_loc_descr (&mem_loc_result, op1);
13771 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13772 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13773 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13774 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13775 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
13791 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13792 VAR_INIT_STATUS_INITIALIZED);
13797 mem_loc_result = op0;
13798 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13802 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13830 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
13831 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
13835 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13837 if (op_mode == VOIDmode)
13838 op_mode = GET_MODE (XEXP (rtl, 1));
13839 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
13842 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13843 VAR_INIT_STATUS_INITIALIZED);
13844 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13845 VAR_INIT_STATUS_INITIALIZED);
13847 if (op0 == 0 || op1 == 0)
13850 if (op_mode != VOIDmode
13851 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
13853 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
13854 shift *= BITS_PER_UNIT;
13855 /* For eq/ne, if the operands are known to be zero-extended,
13856 there is no need to do the fancy shifting up. */
13857 if (op == DW_OP_eq || op == DW_OP_ne)
13859 dw_loc_descr_ref last0, last1;
13861 last0->dw_loc_next != NULL;
13862 last0 = last0->dw_loc_next)
13865 last1->dw_loc_next != NULL;
13866 last1 = last1->dw_loc_next)
13868 /* deref_size zero extends, and for constants we can check
13869 whether they are zero extended or not. */
13870 if (((last0->dw_loc_opc == DW_OP_deref_size
13871 && last0->dw_loc_oprnd1.v.val_int
13872 <= GET_MODE_SIZE (op_mode))
13873 || (CONST_INT_P (XEXP (rtl, 0))
13874 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
13875 == (INTVAL (XEXP (rtl, 0))
13876 & GET_MODE_MASK (op_mode))))
13877 && ((last1->dw_loc_opc == DW_OP_deref_size
13878 && last1->dw_loc_oprnd1.v.val_int
13879 <= GET_MODE_SIZE (op_mode))
13880 || (CONST_INT_P (XEXP (rtl, 1))
13881 && (unsigned HOST_WIDE_INT)
13882 INTVAL (XEXP (rtl, 1))
13883 == (INTVAL (XEXP (rtl, 1))
13884 & GET_MODE_MASK (op_mode)))))
13887 add_loc_descr (&op0, int_loc_descriptor (shift));
13888 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
13889 if (CONST_INT_P (XEXP (rtl, 1)))
13890 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
13893 add_loc_descr (&op1, int_loc_descriptor (shift));
13894 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
13900 mem_loc_result = op0;
13901 add_loc_descr (&mem_loc_result, op1);
13902 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13903 if (STORE_FLAG_VALUE != 1)
13905 add_loc_descr (&mem_loc_result,
13906 int_loc_descriptor (STORE_FLAG_VALUE));
13907 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13928 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
13929 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
13933 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13935 if (op_mode == VOIDmode)
13936 op_mode = GET_MODE (XEXP (rtl, 1));
13937 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
13940 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13941 VAR_INIT_STATUS_INITIALIZED);
13942 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13943 VAR_INIT_STATUS_INITIALIZED);
13945 if (op0 == 0 || op1 == 0)
13948 if (op_mode != VOIDmode
13949 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
13951 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
13952 dw_loc_descr_ref last0, last1;
13954 last0->dw_loc_next != NULL;
13955 last0 = last0->dw_loc_next)
13958 last1->dw_loc_next != NULL;
13959 last1 = last1->dw_loc_next)
13961 if (CONST_INT_P (XEXP (rtl, 0)))
13962 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
13963 /* deref_size zero extends, so no need to mask it again. */
13964 else if (last0->dw_loc_opc != DW_OP_deref_size
13965 || last0->dw_loc_oprnd1.v.val_int
13966 > GET_MODE_SIZE (op_mode))
13968 add_loc_descr (&op0, int_loc_descriptor (mask));
13969 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
13971 if (CONST_INT_P (XEXP (rtl, 1)))
13972 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
13973 /* deref_size zero extends, so no need to mask it again. */
13974 else if (last1->dw_loc_opc != DW_OP_deref_size
13975 || last1->dw_loc_oprnd1.v.val_int
13976 > GET_MODE_SIZE (op_mode))
13978 add_loc_descr (&op1, int_loc_descriptor (mask));
13979 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
13984 HOST_WIDE_INT bias = 1;
13985 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
13986 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
13987 if (CONST_INT_P (XEXP (rtl, 1)))
13988 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
13989 + INTVAL (XEXP (rtl, 1)));
13991 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14001 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14002 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14003 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14006 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14007 VAR_INIT_STATUS_INITIALIZED);
14008 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14009 VAR_INIT_STATUS_INITIALIZED);
14011 if (op0 == 0 || op1 == 0)
14014 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14015 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14016 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14017 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14019 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14021 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14022 add_loc_descr (&op0, int_loc_descriptor (mask));
14023 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14024 add_loc_descr (&op1, int_loc_descriptor (mask));
14025 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14029 HOST_WIDE_INT bias = 1;
14030 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14031 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14032 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14035 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14037 int shift = DWARF2_ADDR_SIZE
14038 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14039 shift *= BITS_PER_UNIT;
14040 add_loc_descr (&op0, int_loc_descriptor (shift));
14041 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14042 add_loc_descr (&op1, int_loc_descriptor (shift));
14043 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14046 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14050 mem_loc_result = op0;
14051 add_loc_descr (&mem_loc_result, op1);
14052 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14054 dw_loc_descr_ref bra_node, drop_node;
14056 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14057 add_loc_descr (&mem_loc_result, bra_node);
14058 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14059 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14060 add_loc_descr (&mem_loc_result, drop_node);
14061 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14062 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14068 if (CONST_INT_P (XEXP (rtl, 1))
14069 && CONST_INT_P (XEXP (rtl, 2))
14070 && ((unsigned) INTVAL (XEXP (rtl, 1))
14071 + (unsigned) INTVAL (XEXP (rtl, 2))
14072 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14073 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14074 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14077 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14078 VAR_INIT_STATUS_INITIALIZED);
14081 if (GET_CODE (rtl) == SIGN_EXTRACT)
14085 mem_loc_result = op0;
14086 size = INTVAL (XEXP (rtl, 1));
14087 shift = INTVAL (XEXP (rtl, 2));
14088 if (BITS_BIG_ENDIAN)
14089 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14091 if (shift + size != (int) DWARF2_ADDR_SIZE)
14093 add_loc_descr (&mem_loc_result,
14094 int_loc_descriptor (DWARF2_ADDR_SIZE
14096 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14098 if (size != (int) DWARF2_ADDR_SIZE)
14100 add_loc_descr (&mem_loc_result,
14101 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14102 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14112 /* In theory, we could implement the above. */
14113 /* DWARF cannot represent the unsigned compare operations
14140 case FLOAT_TRUNCATE:
14142 case UNSIGNED_FLOAT:
14145 case FRACT_CONVERT:
14146 case UNSIGNED_FRACT_CONVERT:
14148 case UNSIGNED_SAT_FRACT:
14160 case VEC_DUPLICATE:
14163 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14164 can't express it in the debug info. This can happen e.g. with some
14169 resolve_one_addr (&rtl, NULL);
14173 #ifdef ENABLE_CHECKING
14174 print_rtl (stderr, rtl);
14175 gcc_unreachable ();
14181 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14182 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14184 return mem_loc_result;
14187 /* Return a descriptor that describes the concatenation of two locations.
14188 This is typically a complex variable. */
14190 static dw_loc_descr_ref
14191 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14193 dw_loc_descr_ref cc_loc_result = NULL;
14194 dw_loc_descr_ref x0_ref
14195 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14196 dw_loc_descr_ref x1_ref
14197 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14199 if (x0_ref == 0 || x1_ref == 0)
14202 cc_loc_result = x0_ref;
14203 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14205 add_loc_descr (&cc_loc_result, x1_ref);
14206 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14208 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14209 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14211 return cc_loc_result;
14214 /* Return a descriptor that describes the concatenation of N
14217 static dw_loc_descr_ref
14218 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14221 dw_loc_descr_ref cc_loc_result = NULL;
14222 unsigned int n = XVECLEN (concatn, 0);
14224 for (i = 0; i < n; ++i)
14226 dw_loc_descr_ref ref;
14227 rtx x = XVECEXP (concatn, 0, i);
14229 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14233 add_loc_descr (&cc_loc_result, ref);
14234 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14237 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14238 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14240 return cc_loc_result;
14243 /* Output a proper Dwarf location descriptor for a variable or parameter
14244 which is either allocated in a register or in a memory location. For a
14245 register, we just generate an OP_REG and the register number. For a
14246 memory location we provide a Dwarf postfix expression describing how to
14247 generate the (dynamic) address of the object onto the address stack.
14249 MODE is mode of the decl if this loc_descriptor is going to be used in
14250 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14251 allowed, VOIDmode otherwise.
14253 If we don't know how to describe it, return 0. */
14255 static dw_loc_descr_ref
14256 loc_descriptor (rtx rtl, enum machine_mode mode,
14257 enum var_init_status initialized)
14259 dw_loc_descr_ref loc_result = NULL;
14261 switch (GET_CODE (rtl))
14264 /* The case of a subreg may arise when we have a local (register)
14265 variable or a formal (register) parameter which doesn't quite fill
14266 up an entire register. For now, just assume that it is
14267 legitimate to make the Dwarf info refer to the whole register which
14268 contains the given subreg. */
14269 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14273 loc_result = reg_loc_descriptor (rtl, initialized);
14277 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14279 if (loc_result == NULL)
14280 loc_result = tls_mem_loc_descriptor (rtl);
14281 if (loc_result == NULL)
14283 rtx new_rtl = avoid_constant_pool_reference (rtl);
14284 if (new_rtl != rtl)
14285 loc_result = loc_descriptor (new_rtl, mode, initialized);
14290 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14295 loc_result = concatn_loc_descriptor (rtl, initialized);
14300 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14302 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14303 if (GET_CODE (loc) == EXPR_LIST)
14304 loc = XEXP (loc, 0);
14305 loc_result = loc_descriptor (loc, mode, initialized);
14309 rtl = XEXP (rtl, 1);
14314 rtvec par_elems = XVEC (rtl, 0);
14315 int num_elem = GET_NUM_ELEM (par_elems);
14316 enum machine_mode mode;
14319 /* Create the first one, so we have something to add to. */
14320 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14321 VOIDmode, initialized);
14322 if (loc_result == NULL)
14324 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14325 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14326 for (i = 1; i < num_elem; i++)
14328 dw_loc_descr_ref temp;
14330 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14331 VOIDmode, initialized);
14334 add_loc_descr (&loc_result, temp);
14335 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14336 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14342 if (mode != VOIDmode && mode != BLKmode)
14343 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14348 if (mode == VOIDmode)
14349 mode = GET_MODE (rtl);
14351 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14353 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14355 /* Note that a CONST_DOUBLE rtx could represent either an integer
14356 or a floating-point constant. A CONST_DOUBLE is used whenever
14357 the constant requires more than one word in order to be
14358 adequately represented. We output CONST_DOUBLEs as blocks. */
14359 loc_result = new_loc_descr (DW_OP_implicit_value,
14360 GET_MODE_SIZE (mode), 0);
14361 if (SCALAR_FLOAT_MODE_P (mode))
14363 unsigned int length = GET_MODE_SIZE (mode);
14364 unsigned char *array
14365 = (unsigned char*) ggc_alloc_atomic (length);
14367 insert_float (rtl, array);
14368 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14369 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14370 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14371 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14375 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14376 loc_result->dw_loc_oprnd2.v.val_double
14377 = rtx_to_double_int (rtl);
14383 if (mode == VOIDmode)
14384 mode = GET_MODE (rtl);
14386 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14388 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14389 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14390 unsigned char *array = (unsigned char *)
14391 ggc_alloc_atomic (length * elt_size);
14395 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14396 switch (GET_MODE_CLASS (mode))
14398 case MODE_VECTOR_INT:
14399 for (i = 0, p = array; i < length; i++, p += elt_size)
14401 rtx elt = CONST_VECTOR_ELT (rtl, i);
14402 double_int val = rtx_to_double_int (elt);
14404 if (elt_size <= sizeof (HOST_WIDE_INT))
14405 insert_int (double_int_to_shwi (val), elt_size, p);
14408 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14409 insert_double (val, p);
14414 case MODE_VECTOR_FLOAT:
14415 for (i = 0, p = array; i < length; i++, p += elt_size)
14417 rtx elt = CONST_VECTOR_ELT (rtl, i);
14418 insert_float (elt, p);
14423 gcc_unreachable ();
14426 loc_result = new_loc_descr (DW_OP_implicit_value,
14427 length * elt_size, 0);
14428 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14429 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14430 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14431 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14436 if (mode == VOIDmode
14437 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14438 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14439 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14441 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14446 if (!const_ok_for_output (rtl))
14449 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14450 && (dwarf_version >= 4 || !dwarf_strict))
14452 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14453 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14454 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14455 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14456 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14461 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14462 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14463 && (dwarf_version >= 4 || !dwarf_strict))
14465 /* Value expression. */
14466 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14468 add_loc_descr (&loc_result,
14469 new_loc_descr (DW_OP_stack_value, 0, 0));
14477 /* We need to figure out what section we should use as the base for the
14478 address ranges where a given location is valid.
14479 1. If this particular DECL has a section associated with it, use that.
14480 2. If this function has a section associated with it, use that.
14481 3. Otherwise, use the text section.
14482 XXX: If you split a variable across multiple sections, we won't notice. */
14484 static const char *
14485 secname_for_decl (const_tree decl)
14487 const char *secname;
14489 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14491 tree sectree = DECL_SECTION_NAME (decl);
14492 secname = TREE_STRING_POINTER (sectree);
14494 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14496 tree sectree = DECL_SECTION_NAME (current_function_decl);
14497 secname = TREE_STRING_POINTER (sectree);
14499 else if (cfun && in_cold_section_p)
14500 secname = crtl->subsections.cold_section_label;
14502 secname = text_section_label;
14507 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14510 decl_by_reference_p (tree decl)
14512 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14513 || TREE_CODE (decl) == VAR_DECL)
14514 && DECL_BY_REFERENCE (decl));
14517 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14520 static dw_loc_descr_ref
14521 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14522 enum var_init_status initialized)
14524 int have_address = 0;
14525 dw_loc_descr_ref descr;
14526 enum machine_mode mode;
14528 if (want_address != 2)
14530 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14532 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14534 varloc = PAT_VAR_LOCATION_LOC (varloc);
14535 if (GET_CODE (varloc) == EXPR_LIST)
14536 varloc = XEXP (varloc, 0);
14537 mode = GET_MODE (varloc);
14538 if (MEM_P (varloc))
14540 rtx addr = XEXP (varloc, 0);
14541 descr = mem_loc_descriptor (addr, mode, initialized);
14546 rtx x = avoid_constant_pool_reference (varloc);
14548 descr = mem_loc_descriptor (x, mode, initialized);
14552 descr = mem_loc_descriptor (varloc, mode, initialized);
14559 if (GET_CODE (varloc) == VAR_LOCATION)
14560 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14562 mode = DECL_MODE (loc);
14563 descr = loc_descriptor (varloc, mode, initialized);
14570 if (want_address == 2 && !have_address
14571 && (dwarf_version >= 4 || !dwarf_strict))
14573 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14575 expansion_failed (loc, NULL_RTX,
14576 "DWARF address size mismatch");
14579 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14582 /* Show if we can't fill the request for an address. */
14583 if (want_address && !have_address)
14585 expansion_failed (loc, NULL_RTX,
14586 "Want address and only have value");
14590 /* If we've got an address and don't want one, dereference. */
14591 if (!want_address && have_address)
14593 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14594 enum dwarf_location_atom op;
14596 if (size > DWARF2_ADDR_SIZE || size == -1)
14598 expansion_failed (loc, NULL_RTX,
14599 "DWARF address size mismatch");
14602 else if (size == DWARF2_ADDR_SIZE)
14605 op = DW_OP_deref_size;
14607 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14613 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14614 if it is not possible. */
14616 static dw_loc_descr_ref
14617 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14619 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14620 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14621 else if (dwarf_version >= 3 || !dwarf_strict)
14622 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14627 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14628 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14630 static dw_loc_descr_ref
14631 dw_sra_loc_expr (tree decl, rtx loc)
14634 unsigned int padsize = 0;
14635 dw_loc_descr_ref descr, *descr_tail;
14636 unsigned HOST_WIDE_INT decl_size;
14638 enum var_init_status initialized;
14640 if (DECL_SIZE (decl) == NULL
14641 || !host_integerp (DECL_SIZE (decl), 1))
14644 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14646 descr_tail = &descr;
14648 for (p = loc; p; p = XEXP (p, 1))
14650 unsigned int bitsize = decl_piece_bitsize (p);
14651 rtx loc_note = *decl_piece_varloc_ptr (p);
14652 dw_loc_descr_ref cur_descr;
14653 dw_loc_descr_ref *tail, last = NULL;
14654 unsigned int opsize = 0;
14656 if (loc_note == NULL_RTX
14657 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14659 padsize += bitsize;
14662 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14663 varloc = NOTE_VAR_LOCATION (loc_note);
14664 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14665 if (cur_descr == NULL)
14667 padsize += bitsize;
14671 /* Check that cur_descr either doesn't use
14672 DW_OP_*piece operations, or their sum is equal
14673 to bitsize. Otherwise we can't embed it. */
14674 for (tail = &cur_descr; *tail != NULL;
14675 tail = &(*tail)->dw_loc_next)
14676 if ((*tail)->dw_loc_opc == DW_OP_piece)
14678 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14682 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14684 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14688 if (last != NULL && opsize != bitsize)
14690 padsize += bitsize;
14694 /* If there is a hole, add DW_OP_*piece after empty DWARF
14695 expression, which means that those bits are optimized out. */
14698 if (padsize > decl_size)
14700 decl_size -= padsize;
14701 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14702 if (*descr_tail == NULL)
14704 descr_tail = &(*descr_tail)->dw_loc_next;
14707 *descr_tail = cur_descr;
14709 if (bitsize > decl_size)
14711 decl_size -= bitsize;
14714 HOST_WIDE_INT offset = 0;
14715 if (GET_CODE (varloc) == VAR_LOCATION
14716 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14718 varloc = PAT_VAR_LOCATION_LOC (varloc);
14719 if (GET_CODE (varloc) == EXPR_LIST)
14720 varloc = XEXP (varloc, 0);
14724 if (GET_CODE (varloc) == CONST
14725 || GET_CODE (varloc) == SIGN_EXTEND
14726 || GET_CODE (varloc) == ZERO_EXTEND)
14727 varloc = XEXP (varloc, 0);
14728 else if (GET_CODE (varloc) == SUBREG)
14729 varloc = SUBREG_REG (varloc);
14734 /* DW_OP_bit_size offset should be zero for register
14735 or implicit location descriptions and empty location
14736 descriptions, but for memory addresses needs big endian
14738 if (MEM_P (varloc))
14740 unsigned HOST_WIDE_INT memsize
14741 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
14742 if (memsize != bitsize)
14744 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
14745 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
14747 if (memsize < bitsize)
14749 if (BITS_BIG_ENDIAN)
14750 offset = memsize - bitsize;
14754 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
14755 if (*descr_tail == NULL)
14757 descr_tail = &(*descr_tail)->dw_loc_next;
14761 /* If there were any non-empty expressions, add padding till the end of
14763 if (descr != NULL && decl_size != 0)
14765 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
14766 if (*descr_tail == NULL)
14772 /* Return the dwarf representation of the location list LOC_LIST of
14773 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14776 static dw_loc_list_ref
14777 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
14779 const char *endname, *secname;
14781 enum var_init_status initialized;
14782 struct var_loc_node *node;
14783 dw_loc_descr_ref descr;
14784 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
14785 dw_loc_list_ref list = NULL;
14786 dw_loc_list_ref *listp = &list;
14788 /* Now that we know what section we are using for a base,
14789 actually construct the list of locations.
14790 The first location information is what is passed to the
14791 function that creates the location list, and the remaining
14792 locations just get added on to that list.
14793 Note that we only know the start address for a location
14794 (IE location changes), so to build the range, we use
14795 the range [current location start, next location start].
14796 This means we have to special case the last node, and generate
14797 a range of [last location start, end of function label]. */
14799 secname = secname_for_decl (decl);
14801 for (node = loc_list->first; node; node = node->next)
14802 if (GET_CODE (node->loc) == EXPR_LIST
14803 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
14805 if (GET_CODE (node->loc) == EXPR_LIST)
14807 /* This requires DW_OP_{,bit_}piece, which is not usable
14808 inside DWARF expressions. */
14809 if (want_address != 2)
14811 descr = dw_sra_loc_expr (decl, node->loc);
14817 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
14818 varloc = NOTE_VAR_LOCATION (node->loc);
14819 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
14823 /* The variable has a location between NODE->LABEL and
14824 NODE->NEXT->LABEL. */
14826 endname = node->next->label;
14827 /* If the variable has a location at the last label
14828 it keeps its location until the end of function. */
14829 else if (!current_function_decl)
14830 endname = text_end_label;
14833 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
14834 current_function_funcdef_no);
14835 endname = ggc_strdup (label_id);
14838 *listp = new_loc_list (descr, node->label, endname, secname);
14839 listp = &(*listp)->dw_loc_next;
14843 /* Try to avoid the overhead of a location list emitting a location
14844 expression instead, but only if we didn't have more than one
14845 location entry in the first place. If some entries were not
14846 representable, we don't want to pretend a single entry that was
14847 applies to the entire scope in which the variable is
14849 if (list && loc_list->first->next)
14855 /* Return if the loc_list has only single element and thus can be represented
14856 as location description. */
14859 single_element_loc_list_p (dw_loc_list_ref list)
14861 gcc_assert (!list->dw_loc_next || list->ll_symbol);
14862 return !list->ll_symbol;
14865 /* To each location in list LIST add loc descr REF. */
14868 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
14870 dw_loc_descr_ref copy;
14871 add_loc_descr (&list->expr, ref);
14872 list = list->dw_loc_next;
14875 copy = ggc_alloc_dw_loc_descr_node ();
14876 memcpy (copy, ref, sizeof (dw_loc_descr_node));
14877 add_loc_descr (&list->expr, copy);
14878 while (copy->dw_loc_next)
14880 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
14881 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
14882 copy->dw_loc_next = new_copy;
14885 list = list->dw_loc_next;
14889 /* Given two lists RET and LIST
14890 produce location list that is result of adding expression in LIST
14891 to expression in RET on each possition in program.
14892 Might be destructive on both RET and LIST.
14894 TODO: We handle only simple cases of RET or LIST having at most one
14895 element. General case would inolve sorting the lists in program order
14896 and merging them that will need some additional work.
14897 Adding that will improve quality of debug info especially for SRA-ed
14901 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
14910 if (!list->dw_loc_next)
14912 add_loc_descr_to_each (*ret, list->expr);
14915 if (!(*ret)->dw_loc_next)
14917 add_loc_descr_to_each (list, (*ret)->expr);
14921 expansion_failed (NULL_TREE, NULL_RTX,
14922 "Don't know how to merge two non-trivial"
14923 " location lists.\n");
14928 /* LOC is constant expression. Try a luck, look it up in constant
14929 pool and return its loc_descr of its address. */
14931 static dw_loc_descr_ref
14932 cst_pool_loc_descr (tree loc)
14934 /* Get an RTL for this, if something has been emitted. */
14935 rtx rtl = lookup_constant_def (loc);
14936 enum machine_mode mode;
14938 if (!rtl || !MEM_P (rtl))
14943 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
14945 /* TODO: We might get more coverage if we was actually delaying expansion
14946 of all expressions till end of compilation when constant pools are fully
14948 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
14950 expansion_failed (loc, NULL_RTX,
14951 "CST value in contant pool but not marked.");
14954 mode = GET_MODE (rtl);
14955 rtl = XEXP (rtl, 0);
14956 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
14959 /* Return dw_loc_list representing address of addr_expr LOC
14960 by looking for innder INDIRECT_REF expression and turing it
14961 into simple arithmetics. */
14963 static dw_loc_list_ref
14964 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
14967 HOST_WIDE_INT bitsize, bitpos, bytepos;
14968 enum machine_mode mode;
14970 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
14971 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
14973 obj = get_inner_reference (TREE_OPERAND (loc, 0),
14974 &bitsize, &bitpos, &offset, &mode,
14975 &unsignedp, &volatilep, false);
14977 if (bitpos % BITS_PER_UNIT)
14979 expansion_failed (loc, NULL_RTX, "bitfield access");
14982 if (!INDIRECT_REF_P (obj))
14984 expansion_failed (obj,
14985 NULL_RTX, "no indirect ref in inner refrence");
14988 if (!offset && !bitpos)
14989 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
14991 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
14992 && (dwarf_version >= 4 || !dwarf_strict))
14994 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
14999 /* Variable offset. */
15000 list_ret1 = loc_list_from_tree (offset, 0);
15001 if (list_ret1 == 0)
15003 add_loc_list (&list_ret, list_ret1);
15006 add_loc_descr_to_each (list_ret,
15007 new_loc_descr (DW_OP_plus, 0, 0));
15009 bytepos = bitpos / BITS_PER_UNIT;
15011 add_loc_descr_to_each (list_ret,
15012 new_loc_descr (DW_OP_plus_uconst,
15014 else if (bytepos < 0)
15015 loc_list_plus_const (list_ret, bytepos);
15016 add_loc_descr_to_each (list_ret,
15017 new_loc_descr (DW_OP_stack_value, 0, 0));
15023 /* Generate Dwarf location list representing LOC.
15024 If WANT_ADDRESS is false, expression computing LOC will be computed
15025 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15026 if WANT_ADDRESS is 2, expression computing address useable in location
15027 will be returned (i.e. DW_OP_reg can be used
15028 to refer to register values). */
15030 static dw_loc_list_ref
15031 loc_list_from_tree (tree loc, int want_address)
15033 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15034 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15035 int have_address = 0;
15036 enum dwarf_location_atom op;
15038 /* ??? Most of the time we do not take proper care for sign/zero
15039 extending the values properly. Hopefully this won't be a real
15042 switch (TREE_CODE (loc))
15045 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15048 case PLACEHOLDER_EXPR:
15049 /* This case involves extracting fields from an object to determine the
15050 position of other fields. We don't try to encode this here. The
15051 only user of this is Ada, which encodes the needed information using
15052 the names of types. */
15053 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15057 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15058 /* There are no opcodes for these operations. */
15061 case PREINCREMENT_EXPR:
15062 case PREDECREMENT_EXPR:
15063 case POSTINCREMENT_EXPR:
15064 case POSTDECREMENT_EXPR:
15065 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15066 /* There are no opcodes for these operations. */
15070 /* If we already want an address, see if there is INDIRECT_REF inside
15071 e.g. for &this->field. */
15074 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15075 (loc, want_address == 2);
15078 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15079 && (ret = cst_pool_loc_descr (loc)))
15082 /* Otherwise, process the argument and look for the address. */
15083 if (!list_ret && !ret)
15084 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15088 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15094 if (DECL_THREAD_LOCAL_P (loc))
15097 enum dwarf_location_atom first_op;
15098 enum dwarf_location_atom second_op;
15099 bool dtprel = false;
15101 if (targetm.have_tls)
15103 /* If this is not defined, we have no way to emit the
15105 if (!targetm.asm_out.output_dwarf_dtprel)
15108 /* The way DW_OP_GNU_push_tls_address is specified, we
15109 can only look up addresses of objects in the current
15110 module. We used DW_OP_addr as first op, but that's
15111 wrong, because DW_OP_addr is relocated by the debug
15112 info consumer, while DW_OP_GNU_push_tls_address
15113 operand shouldn't be. */
15114 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15116 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15118 second_op = DW_OP_GNU_push_tls_address;
15122 if (!targetm.emutls.debug_form_tls_address
15123 || !(dwarf_version >= 3 || !dwarf_strict))
15125 /* We stuffed the control variable into the DECL_VALUE_EXPR
15126 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15127 no longer appear in gimple code. We used the control
15128 variable in specific so that we could pick it up here. */
15129 loc = DECL_VALUE_EXPR (loc);
15130 first_op = DW_OP_addr;
15131 second_op = DW_OP_form_tls_address;
15134 rtl = rtl_for_decl_location (loc);
15135 if (rtl == NULL_RTX)
15140 rtl = XEXP (rtl, 0);
15141 if (! CONSTANT_P (rtl))
15144 ret = new_loc_descr (first_op, 0, 0);
15145 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15146 ret->dw_loc_oprnd1.v.val_addr = rtl;
15147 ret->dtprel = dtprel;
15149 ret1 = new_loc_descr (second_op, 0, 0);
15150 add_loc_descr (&ret, ret1);
15158 if (DECL_HAS_VALUE_EXPR_P (loc))
15159 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15164 case FUNCTION_DECL:
15167 var_loc_list *loc_list = lookup_decl_loc (loc);
15169 if (loc_list && loc_list->first)
15171 list_ret = dw_loc_list (loc_list, loc, want_address);
15172 have_address = want_address != 0;
15175 rtl = rtl_for_decl_location (loc);
15176 if (rtl == NULL_RTX)
15178 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15181 else if (CONST_INT_P (rtl))
15183 HOST_WIDE_INT val = INTVAL (rtl);
15184 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15185 val &= GET_MODE_MASK (DECL_MODE (loc));
15186 ret = int_loc_descriptor (val);
15188 else if (GET_CODE (rtl) == CONST_STRING)
15190 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15193 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15195 ret = new_loc_descr (DW_OP_addr, 0, 0);
15196 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15197 ret->dw_loc_oprnd1.v.val_addr = rtl;
15201 enum machine_mode mode;
15203 /* Certain constructs can only be represented at top-level. */
15204 if (want_address == 2)
15206 ret = loc_descriptor (rtl, VOIDmode,
15207 VAR_INIT_STATUS_INITIALIZED);
15212 mode = GET_MODE (rtl);
15215 rtl = XEXP (rtl, 0);
15218 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15221 expansion_failed (loc, rtl,
15222 "failed to produce loc descriptor for rtl");
15229 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15233 case MISALIGNED_INDIRECT_REF:
15234 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15238 case COMPOUND_EXPR:
15239 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15242 case VIEW_CONVERT_EXPR:
15245 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15247 case COMPONENT_REF:
15248 case BIT_FIELD_REF:
15250 case ARRAY_RANGE_REF:
15251 case REALPART_EXPR:
15252 case IMAGPART_EXPR:
15255 HOST_WIDE_INT bitsize, bitpos, bytepos;
15256 enum machine_mode mode;
15258 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15260 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15261 &unsignedp, &volatilep, false);
15263 gcc_assert (obj != loc);
15265 list_ret = loc_list_from_tree (obj,
15267 && !bitpos && !offset ? 2 : 1);
15268 /* TODO: We can extract value of the small expression via shifting even
15269 for nonzero bitpos. */
15272 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15274 expansion_failed (loc, NULL_RTX,
15275 "bitfield access");
15279 if (offset != NULL_TREE)
15281 /* Variable offset. */
15282 list_ret1 = loc_list_from_tree (offset, 0);
15283 if (list_ret1 == 0)
15285 add_loc_list (&list_ret, list_ret1);
15288 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15291 bytepos = bitpos / BITS_PER_UNIT;
15293 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15294 else if (bytepos < 0)
15295 loc_list_plus_const (list_ret, bytepos);
15302 if ((want_address || !host_integerp (loc, 0))
15303 && (ret = cst_pool_loc_descr (loc)))
15305 else if (want_address == 2
15306 && host_integerp (loc, 0)
15307 && (ret = address_of_int_loc_descriptor
15308 (int_size_in_bytes (TREE_TYPE (loc)),
15309 tree_low_cst (loc, 0))))
15311 else if (host_integerp (loc, 0))
15312 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15315 expansion_failed (loc, NULL_RTX,
15316 "Integer operand is not host integer");
15325 if ((ret = cst_pool_loc_descr (loc)))
15328 /* We can construct small constants here using int_loc_descriptor. */
15329 expansion_failed (loc, NULL_RTX,
15330 "constructor or constant not in constant pool");
15333 case TRUTH_AND_EXPR:
15334 case TRUTH_ANDIF_EXPR:
15339 case TRUTH_XOR_EXPR:
15344 case TRUTH_OR_EXPR:
15345 case TRUTH_ORIF_EXPR:
15350 case FLOOR_DIV_EXPR:
15351 case CEIL_DIV_EXPR:
15352 case ROUND_DIV_EXPR:
15353 case TRUNC_DIV_EXPR:
15354 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15363 case FLOOR_MOD_EXPR:
15364 case CEIL_MOD_EXPR:
15365 case ROUND_MOD_EXPR:
15366 case TRUNC_MOD_EXPR:
15367 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15372 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15373 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15374 if (list_ret == 0 || list_ret1 == 0)
15377 add_loc_list (&list_ret, list_ret1);
15380 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15381 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15382 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15383 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15384 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15396 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15399 case POINTER_PLUS_EXPR:
15401 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15403 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15407 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15415 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15422 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15429 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15436 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15451 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15452 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15453 if (list_ret == 0 || list_ret1 == 0)
15456 add_loc_list (&list_ret, list_ret1);
15459 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15462 case TRUTH_NOT_EXPR:
15476 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15480 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15486 const enum tree_code code =
15487 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15489 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15490 build2 (code, integer_type_node,
15491 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15492 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15495 /* ... fall through ... */
15499 dw_loc_descr_ref lhs
15500 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15501 dw_loc_list_ref rhs
15502 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15503 dw_loc_descr_ref bra_node, jump_node, tmp;
15505 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15506 if (list_ret == 0 || lhs == 0 || rhs == 0)
15509 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15510 add_loc_descr_to_each (list_ret, bra_node);
15512 add_loc_list (&list_ret, rhs);
15513 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15514 add_loc_descr_to_each (list_ret, jump_node);
15516 add_loc_descr_to_each (list_ret, lhs);
15517 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15518 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15520 /* ??? Need a node to point the skip at. Use a nop. */
15521 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15522 add_loc_descr_to_each (list_ret, tmp);
15523 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15524 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15528 case FIX_TRUNC_EXPR:
15532 /* Leave front-end specific codes as simply unknown. This comes
15533 up, for instance, with the C STMT_EXPR. */
15534 if ((unsigned int) TREE_CODE (loc)
15535 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15537 expansion_failed (loc, NULL_RTX,
15538 "language specific tree node");
15542 #ifdef ENABLE_CHECKING
15543 /* Otherwise this is a generic code; we should just lists all of
15544 these explicitly. We forgot one. */
15545 gcc_unreachable ();
15547 /* In a release build, we want to degrade gracefully: better to
15548 generate incomplete debugging information than to crash. */
15553 if (!ret && !list_ret)
15556 if (want_address == 2 && !have_address
15557 && (dwarf_version >= 4 || !dwarf_strict))
15559 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15561 expansion_failed (loc, NULL_RTX,
15562 "DWARF address size mismatch");
15566 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15568 add_loc_descr_to_each (list_ret,
15569 new_loc_descr (DW_OP_stack_value, 0, 0));
15572 /* Show if we can't fill the request for an address. */
15573 if (want_address && !have_address)
15575 expansion_failed (loc, NULL_RTX,
15576 "Want address and only have value");
15580 gcc_assert (!ret || !list_ret);
15582 /* If we've got an address and don't want one, dereference. */
15583 if (!want_address && have_address)
15585 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15587 if (size > DWARF2_ADDR_SIZE || size == -1)
15589 expansion_failed (loc, NULL_RTX,
15590 "DWARF address size mismatch");
15593 else if (size == DWARF2_ADDR_SIZE)
15596 op = DW_OP_deref_size;
15599 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15601 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15604 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15609 /* Same as above but return only single location expression. */
15610 static dw_loc_descr_ref
15611 loc_descriptor_from_tree (tree loc, int want_address)
15613 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15616 if (ret->dw_loc_next)
15618 expansion_failed (loc, NULL_RTX,
15619 "Location list where only loc descriptor needed");
15625 /* Given a value, round it up to the lowest multiple of `boundary'
15626 which is not less than the value itself. */
15628 static inline HOST_WIDE_INT
15629 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15631 return (((value + boundary - 1) / boundary) * boundary);
15634 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15635 pointer to the declared type for the relevant field variable, or return
15636 `integer_type_node' if the given node turns out to be an
15637 ERROR_MARK node. */
15640 field_type (const_tree decl)
15644 if (TREE_CODE (decl) == ERROR_MARK)
15645 return integer_type_node;
15647 type = DECL_BIT_FIELD_TYPE (decl);
15648 if (type == NULL_TREE)
15649 type = TREE_TYPE (decl);
15654 /* Given a pointer to a tree node, return the alignment in bits for
15655 it, or else return BITS_PER_WORD if the node actually turns out to
15656 be an ERROR_MARK node. */
15658 static inline unsigned
15659 simple_type_align_in_bits (const_tree type)
15661 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15664 static inline unsigned
15665 simple_decl_align_in_bits (const_tree decl)
15667 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15670 /* Return the result of rounding T up to ALIGN. */
15672 static inline double_int
15673 round_up_to_align (double_int t, unsigned int align)
15675 double_int alignd = uhwi_to_double_int (align);
15676 t = double_int_add (t, alignd);
15677 t = double_int_add (t, double_int_minus_one);
15678 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
15679 t = double_int_mul (t, alignd);
15683 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15684 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15685 or return 0 if we are unable to determine what that offset is, either
15686 because the argument turns out to be a pointer to an ERROR_MARK node, or
15687 because the offset is actually variable. (We can't handle the latter case
15690 static HOST_WIDE_INT
15691 field_byte_offset (const_tree decl)
15693 double_int object_offset_in_bits;
15694 double_int object_offset_in_bytes;
15695 double_int bitpos_int;
15697 if (TREE_CODE (decl) == ERROR_MARK)
15700 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15702 /* We cannot yet cope with fields whose positions are variable, so
15703 for now, when we see such things, we simply return 0. Someday, we may
15704 be able to handle such cases, but it will be damn difficult. */
15705 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
15708 bitpos_int = tree_to_double_int (bit_position (decl));
15710 #ifdef PCC_BITFIELD_TYPE_MATTERS
15711 if (PCC_BITFIELD_TYPE_MATTERS)
15714 tree field_size_tree;
15715 double_int deepest_bitpos;
15716 double_int field_size_in_bits;
15717 unsigned int type_align_in_bits;
15718 unsigned int decl_align_in_bits;
15719 double_int type_size_in_bits;
15721 type = field_type (decl);
15722 type_size_in_bits = double_int_type_size_in_bits (type);
15723 type_align_in_bits = simple_type_align_in_bits (type);
15725 field_size_tree = DECL_SIZE (decl);
15727 /* The size could be unspecified if there was an error, or for
15728 a flexible array member. */
15729 if (!field_size_tree)
15730 field_size_tree = bitsize_zero_node;
15732 /* If the size of the field is not constant, use the type size. */
15733 if (TREE_CODE (field_size_tree) == INTEGER_CST)
15734 field_size_in_bits = tree_to_double_int (field_size_tree);
15736 field_size_in_bits = type_size_in_bits;
15738 decl_align_in_bits = simple_decl_align_in_bits (decl);
15740 /* The GCC front-end doesn't make any attempt to keep track of the
15741 starting bit offset (relative to the start of the containing
15742 structure type) of the hypothetical "containing object" for a
15743 bit-field. Thus, when computing the byte offset value for the
15744 start of the "containing object" of a bit-field, we must deduce
15745 this information on our own. This can be rather tricky to do in
15746 some cases. For example, handling the following structure type
15747 definition when compiling for an i386/i486 target (which only
15748 aligns long long's to 32-bit boundaries) can be very tricky:
15750 struct S { int field1; long long field2:31; };
15752 Fortunately, there is a simple rule-of-thumb which can be used
15753 in such cases. When compiling for an i386/i486, GCC will
15754 allocate 8 bytes for the structure shown above. It decides to
15755 do this based upon one simple rule for bit-field allocation.
15756 GCC allocates each "containing object" for each bit-field at
15757 the first (i.e. lowest addressed) legitimate alignment boundary
15758 (based upon the required minimum alignment for the declared
15759 type of the field) which it can possibly use, subject to the
15760 condition that there is still enough available space remaining
15761 in the containing object (when allocated at the selected point)
15762 to fully accommodate all of the bits of the bit-field itself.
15764 This simple rule makes it obvious why GCC allocates 8 bytes for
15765 each object of the structure type shown above. When looking
15766 for a place to allocate the "containing object" for `field2',
15767 the compiler simply tries to allocate a 64-bit "containing
15768 object" at each successive 32-bit boundary (starting at zero)
15769 until it finds a place to allocate that 64- bit field such that
15770 at least 31 contiguous (and previously unallocated) bits remain
15771 within that selected 64 bit field. (As it turns out, for the
15772 example above, the compiler finds it is OK to allocate the
15773 "containing object" 64-bit field at bit-offset zero within the
15776 Here we attempt to work backwards from the limited set of facts
15777 we're given, and we try to deduce from those facts, where GCC
15778 must have believed that the containing object started (within
15779 the structure type). The value we deduce is then used (by the
15780 callers of this routine) to generate DW_AT_location and
15781 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15782 the case of DW_AT_location, regular fields as well). */
15784 /* Figure out the bit-distance from the start of the structure to
15785 the "deepest" bit of the bit-field. */
15786 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
15788 /* This is the tricky part. Use some fancy footwork to deduce
15789 where the lowest addressed bit of the containing object must
15791 object_offset_in_bits
15792 = double_int_sub (deepest_bitpos, type_size_in_bits);
15794 /* Round up to type_align by default. This works best for
15796 object_offset_in_bits
15797 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
15799 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
15801 object_offset_in_bits
15802 = double_int_sub (deepest_bitpos, type_size_in_bits);
15804 /* Round up to decl_align instead. */
15805 object_offset_in_bits
15806 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
15810 #endif /* PCC_BITFIELD_TYPE_MATTERS */
15811 object_offset_in_bits = bitpos_int;
15813 object_offset_in_bytes
15814 = double_int_div (object_offset_in_bits,
15815 uhwi_to_double_int (BITS_PER_UNIT), true,
15817 return double_int_to_shwi (object_offset_in_bytes);
15820 /* The following routines define various Dwarf attributes and any data
15821 associated with them. */
15823 /* Add a location description attribute value to a DIE.
15825 This emits location attributes suitable for whole variables and
15826 whole parameters. Note that the location attributes for struct fields are
15827 generated by the routine `data_member_location_attribute' below. */
15830 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
15831 dw_loc_list_ref descr)
15835 if (single_element_loc_list_p (descr))
15836 add_AT_loc (die, attr_kind, descr->expr);
15838 add_AT_loc_list (die, attr_kind, descr);
15841 /* Add DW_AT_accessibility attribute to DIE if needed. */
15844 add_accessibility_attribute (dw_die_ref die, tree decl)
15846 if (TREE_PROTECTED (decl))
15847 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
15848 else if (TREE_PRIVATE (decl))
15849 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
15852 /* Attach the specialized form of location attribute used for data members of
15853 struct and union types. In the special case of a FIELD_DECL node which
15854 represents a bit-field, the "offset" part of this special location
15855 descriptor must indicate the distance in bytes from the lowest-addressed
15856 byte of the containing struct or union type to the lowest-addressed byte of
15857 the "containing object" for the bit-field. (See the `field_byte_offset'
15860 For any given bit-field, the "containing object" is a hypothetical object
15861 (of some integral or enum type) within which the given bit-field lives. The
15862 type of this hypothetical "containing object" is always the same as the
15863 declared type of the individual bit-field itself (for GCC anyway... the
15864 DWARF spec doesn't actually mandate this). Note that it is the size (in
15865 bytes) of the hypothetical "containing object" which will be given in the
15866 DW_AT_byte_size attribute for this bit-field. (See the
15867 `byte_size_attribute' function below.) It is also used when calculating the
15868 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15869 function below.) */
15872 add_data_member_location_attribute (dw_die_ref die, tree decl)
15874 HOST_WIDE_INT offset;
15875 dw_loc_descr_ref loc_descr = 0;
15877 if (TREE_CODE (decl) == TREE_BINFO)
15879 /* We're working on the TAG_inheritance for a base class. */
15880 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
15882 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15883 aren't at a fixed offset from all (sub)objects of the same
15884 type. We need to extract the appropriate offset from our
15885 vtable. The following dwarf expression means
15887 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15889 This is specific to the V3 ABI, of course. */
15891 dw_loc_descr_ref tmp;
15893 /* Make a copy of the object address. */
15894 tmp = new_loc_descr (DW_OP_dup, 0, 0);
15895 add_loc_descr (&loc_descr, tmp);
15897 /* Extract the vtable address. */
15898 tmp = new_loc_descr (DW_OP_deref, 0, 0);
15899 add_loc_descr (&loc_descr, tmp);
15901 /* Calculate the address of the offset. */
15902 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
15903 gcc_assert (offset < 0);
15905 tmp = int_loc_descriptor (-offset);
15906 add_loc_descr (&loc_descr, tmp);
15907 tmp = new_loc_descr (DW_OP_minus, 0, 0);
15908 add_loc_descr (&loc_descr, tmp);
15910 /* Extract the offset. */
15911 tmp = new_loc_descr (DW_OP_deref, 0, 0);
15912 add_loc_descr (&loc_descr, tmp);
15914 /* Add it to the object address. */
15915 tmp = new_loc_descr (DW_OP_plus, 0, 0);
15916 add_loc_descr (&loc_descr, tmp);
15919 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
15922 offset = field_byte_offset (decl);
15926 if (dwarf_version > 2)
15928 /* Don't need to output a location expression, just the constant. */
15930 add_AT_int (die, DW_AT_data_member_location, offset);
15932 add_AT_unsigned (die, DW_AT_data_member_location, offset);
15937 enum dwarf_location_atom op;
15939 /* The DWARF2 standard says that we should assume that the structure
15940 address is already on the stack, so we can specify a structure
15941 field address by using DW_OP_plus_uconst. */
15943 #ifdef MIPS_DEBUGGING_INFO
15944 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
15945 operator correctly. It works only if we leave the offset on the
15949 op = DW_OP_plus_uconst;
15952 loc_descr = new_loc_descr (op, offset, 0);
15956 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
15959 /* Writes integer values to dw_vec_const array. */
15962 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
15966 *dest++ = val & 0xff;
15972 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15974 static HOST_WIDE_INT
15975 extract_int (const unsigned char *src, unsigned int size)
15977 HOST_WIDE_INT val = 0;
15983 val |= *--src & 0xff;
15989 /* Writes double_int values to dw_vec_const array. */
15992 insert_double (double_int val, unsigned char *dest)
15994 unsigned char *p0 = dest;
15995 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
15997 if (WORDS_BIG_ENDIAN)
16003 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16004 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16007 /* Writes floating point values to dw_vec_const array. */
16010 insert_float (const_rtx rtl, unsigned char *array)
16012 REAL_VALUE_TYPE rv;
16016 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16017 real_to_target (val, &rv, GET_MODE (rtl));
16019 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16020 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16022 insert_int (val[i], 4, array);
16027 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16028 does not have a "location" either in memory or in a register. These
16029 things can arise in GNU C when a constant is passed as an actual parameter
16030 to an inlined function. They can also arise in C++ where declared
16031 constants do not necessarily get memory "homes". */
16034 add_const_value_attribute (dw_die_ref die, rtx rtl)
16036 switch (GET_CODE (rtl))
16040 HOST_WIDE_INT val = INTVAL (rtl);
16043 add_AT_int (die, DW_AT_const_value, val);
16045 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16050 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16051 floating-point constant. A CONST_DOUBLE is used whenever the
16052 constant requires more than one word in order to be adequately
16055 enum machine_mode mode = GET_MODE (rtl);
16057 if (SCALAR_FLOAT_MODE_P (mode))
16059 unsigned int length = GET_MODE_SIZE (mode);
16060 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16062 insert_float (rtl, array);
16063 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16066 add_AT_double (die, DW_AT_const_value,
16067 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16073 enum machine_mode mode = GET_MODE (rtl);
16074 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16075 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16076 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16077 (length * elt_size);
16081 switch (GET_MODE_CLASS (mode))
16083 case MODE_VECTOR_INT:
16084 for (i = 0, p = array; i < length; i++, p += elt_size)
16086 rtx elt = CONST_VECTOR_ELT (rtl, i);
16087 double_int val = rtx_to_double_int (elt);
16089 if (elt_size <= sizeof (HOST_WIDE_INT))
16090 insert_int (double_int_to_shwi (val), elt_size, p);
16093 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16094 insert_double (val, p);
16099 case MODE_VECTOR_FLOAT:
16100 for (i = 0, p = array; i < length; i++, p += elt_size)
16102 rtx elt = CONST_VECTOR_ELT (rtl, i);
16103 insert_float (elt, p);
16108 gcc_unreachable ();
16111 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16116 if (dwarf_version >= 4 || !dwarf_strict)
16118 dw_loc_descr_ref loc_result;
16119 resolve_one_addr (&rtl, NULL);
16121 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16122 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16123 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16124 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16125 add_AT_loc (die, DW_AT_location, loc_result);
16126 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16132 if (CONSTANT_P (XEXP (rtl, 0)))
16133 return add_const_value_attribute (die, XEXP (rtl, 0));
16136 if (!const_ok_for_output (rtl))
16139 if (dwarf_version >= 4 || !dwarf_strict)
16144 /* In cases where an inlined instance of an inline function is passed
16145 the address of an `auto' variable (which is local to the caller) we
16146 can get a situation where the DECL_RTL of the artificial local
16147 variable (for the inlining) which acts as a stand-in for the
16148 corresponding formal parameter (of the inline function) will look
16149 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16150 exactly a compile-time constant expression, but it isn't the address
16151 of the (artificial) local variable either. Rather, it represents the
16152 *value* which the artificial local variable always has during its
16153 lifetime. We currently have no way to represent such quasi-constant
16154 values in Dwarf, so for now we just punt and generate nothing. */
16162 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16163 && MEM_READONLY_P (rtl)
16164 && GET_MODE (rtl) == BLKmode)
16166 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16172 /* No other kinds of rtx should be possible here. */
16173 gcc_unreachable ();
16178 /* Determine whether the evaluation of EXPR references any variables
16179 or functions which aren't otherwise used (and therefore may not be
16182 reference_to_unused (tree * tp, int * walk_subtrees,
16183 void * data ATTRIBUTE_UNUSED)
16185 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16186 *walk_subtrees = 0;
16188 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16189 && ! TREE_ASM_WRITTEN (*tp))
16191 /* ??? The C++ FE emits debug information for using decls, so
16192 putting gcc_unreachable here falls over. See PR31899. For now
16193 be conservative. */
16194 else if (!cgraph_global_info_ready
16195 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16197 else if (TREE_CODE (*tp) == VAR_DECL)
16199 struct varpool_node *node = varpool_get_node (*tp);
16200 if (!node || !node->needed)
16203 else if (TREE_CODE (*tp) == FUNCTION_DECL
16204 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16206 /* The call graph machinery must have finished analyzing,
16207 optimizing and gimplifying the CU by now.
16208 So if *TP has no call graph node associated
16209 to it, it means *TP will not be emitted. */
16210 if (!cgraph_get_node (*tp))
16213 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16219 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16220 for use in a later add_const_value_attribute call. */
16223 rtl_for_decl_init (tree init, tree type)
16225 rtx rtl = NULL_RTX;
16227 /* If a variable is initialized with a string constant without embedded
16228 zeros, build CONST_STRING. */
16229 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16231 tree enttype = TREE_TYPE (type);
16232 tree domain = TYPE_DOMAIN (type);
16233 enum machine_mode mode = TYPE_MODE (enttype);
16235 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16237 && integer_zerop (TYPE_MIN_VALUE (domain))
16238 && compare_tree_int (TYPE_MAX_VALUE (domain),
16239 TREE_STRING_LENGTH (init) - 1) == 0
16240 && ((size_t) TREE_STRING_LENGTH (init)
16241 == strlen (TREE_STRING_POINTER (init)) + 1))
16243 rtl = gen_rtx_CONST_STRING (VOIDmode,
16244 ggc_strdup (TREE_STRING_POINTER (init)));
16245 rtl = gen_rtx_MEM (BLKmode, rtl);
16246 MEM_READONLY_P (rtl) = 1;
16249 /* Other aggregates, and complex values, could be represented using
16251 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
16253 /* Vectors only work if their mode is supported by the target.
16254 FIXME: generic vectors ought to work too. */
16255 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
16257 /* If the initializer is something that we know will expand into an
16258 immediate RTL constant, expand it now. We must be careful not to
16259 reference variables which won't be output. */
16260 else if (initializer_constant_valid_p (init, type)
16261 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16263 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16265 if (TREE_CODE (type) == VECTOR_TYPE)
16266 switch (TREE_CODE (init))
16271 if (TREE_CONSTANT (init))
16273 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16274 bool constant_p = true;
16276 unsigned HOST_WIDE_INT ix;
16278 /* Even when ctor is constant, it might contain non-*_CST
16279 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16280 belong into VECTOR_CST nodes. */
16281 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16282 if (!CONSTANT_CLASS_P (value))
16284 constant_p = false;
16290 init = build_vector_from_ctor (type, elts);
16300 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16302 /* If expand_expr returns a MEM, it wasn't immediate. */
16303 gcc_assert (!rtl || !MEM_P (rtl));
16309 /* Generate RTL for the variable DECL to represent its location. */
16312 rtl_for_decl_location (tree decl)
16316 /* Here we have to decide where we are going to say the parameter "lives"
16317 (as far as the debugger is concerned). We only have a couple of
16318 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16320 DECL_RTL normally indicates where the parameter lives during most of the
16321 activation of the function. If optimization is enabled however, this
16322 could be either NULL or else a pseudo-reg. Both of those cases indicate
16323 that the parameter doesn't really live anywhere (as far as the code
16324 generation parts of GCC are concerned) during most of the function's
16325 activation. That will happen (for example) if the parameter is never
16326 referenced within the function.
16328 We could just generate a location descriptor here for all non-NULL
16329 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16330 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16331 where DECL_RTL is NULL or is a pseudo-reg.
16333 Note however that we can only get away with using DECL_INCOMING_RTL as
16334 a backup substitute for DECL_RTL in certain limited cases. In cases
16335 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16336 we can be sure that the parameter was passed using the same type as it is
16337 declared to have within the function, and that its DECL_INCOMING_RTL
16338 points us to a place where a value of that type is passed.
16340 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16341 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16342 because in these cases DECL_INCOMING_RTL points us to a value of some
16343 type which is *different* from the type of the parameter itself. Thus,
16344 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16345 such cases, the debugger would end up (for example) trying to fetch a
16346 `float' from a place which actually contains the first part of a
16347 `double'. That would lead to really incorrect and confusing
16348 output at debug-time.
16350 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16351 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16352 are a couple of exceptions however. On little-endian machines we can
16353 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16354 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16355 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16356 when (on a little-endian machine) a non-prototyped function has a
16357 parameter declared to be of type `short' or `char'. In such cases,
16358 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16359 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16360 passed `int' value. If the debugger then uses that address to fetch
16361 a `short' or a `char' (on a little-endian machine) the result will be
16362 the correct data, so we allow for such exceptional cases below.
16364 Note that our goal here is to describe the place where the given formal
16365 parameter lives during most of the function's activation (i.e. between the
16366 end of the prologue and the start of the epilogue). We'll do that as best
16367 as we can. Note however that if the given formal parameter is modified
16368 sometime during the execution of the function, then a stack backtrace (at
16369 debug-time) will show the function as having been called with the *new*
16370 value rather than the value which was originally passed in. This happens
16371 rarely enough that it is not a major problem, but it *is* a problem, and
16372 I'd like to fix it.
16374 A future version of dwarf2out.c may generate two additional attributes for
16375 any given DW_TAG_formal_parameter DIE which will describe the "passed
16376 type" and the "passed location" for the given formal parameter in addition
16377 to the attributes we now generate to indicate the "declared type" and the
16378 "active location" for each parameter. This additional set of attributes
16379 could be used by debuggers for stack backtraces. Separately, note that
16380 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16381 This happens (for example) for inlined-instances of inline function formal
16382 parameters which are never referenced. This really shouldn't be
16383 happening. All PARM_DECL nodes should get valid non-NULL
16384 DECL_INCOMING_RTL values. FIXME. */
16386 /* Use DECL_RTL as the "location" unless we find something better. */
16387 rtl = DECL_RTL_IF_SET (decl);
16389 /* When generating abstract instances, ignore everything except
16390 constants, symbols living in memory, and symbols living in
16391 fixed registers. */
16392 if (! reload_completed)
16395 && (CONSTANT_P (rtl)
16397 && CONSTANT_P (XEXP (rtl, 0)))
16399 && TREE_CODE (decl) == VAR_DECL
16400 && TREE_STATIC (decl))))
16402 rtl = targetm.delegitimize_address (rtl);
16407 else if (TREE_CODE (decl) == PARM_DECL)
16409 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
16411 tree declared_type = TREE_TYPE (decl);
16412 tree passed_type = DECL_ARG_TYPE (decl);
16413 enum machine_mode dmode = TYPE_MODE (declared_type);
16414 enum machine_mode pmode = TYPE_MODE (passed_type);
16416 /* This decl represents a formal parameter which was optimized out.
16417 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16418 all cases where (rtl == NULL_RTX) just below. */
16419 if (dmode == pmode)
16420 rtl = DECL_INCOMING_RTL (decl);
16421 else if (SCALAR_INT_MODE_P (dmode)
16422 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16423 && DECL_INCOMING_RTL (decl))
16425 rtx inc = DECL_INCOMING_RTL (decl);
16428 else if (MEM_P (inc))
16430 if (BYTES_BIG_ENDIAN)
16431 rtl = adjust_address_nv (inc, dmode,
16432 GET_MODE_SIZE (pmode)
16433 - GET_MODE_SIZE (dmode));
16440 /* If the parm was passed in registers, but lives on the stack, then
16441 make a big endian correction if the mode of the type of the
16442 parameter is not the same as the mode of the rtl. */
16443 /* ??? This is the same series of checks that are made in dbxout.c before
16444 we reach the big endian correction code there. It isn't clear if all
16445 of these checks are necessary here, but keeping them all is the safe
16447 else if (MEM_P (rtl)
16448 && XEXP (rtl, 0) != const0_rtx
16449 && ! CONSTANT_P (XEXP (rtl, 0))
16450 /* Not passed in memory. */
16451 && !MEM_P (DECL_INCOMING_RTL (decl))
16452 /* Not passed by invisible reference. */
16453 && (!REG_P (XEXP (rtl, 0))
16454 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16455 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16456 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
16457 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16460 /* Big endian correction check. */
16461 && BYTES_BIG_ENDIAN
16462 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16463 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16466 int offset = (UNITS_PER_WORD
16467 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16469 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16470 plus_constant (XEXP (rtl, 0), offset));
16473 else if (TREE_CODE (decl) == VAR_DECL
16476 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16477 && BYTES_BIG_ENDIAN)
16479 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16480 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16482 /* If a variable is declared "register" yet is smaller than
16483 a register, then if we store the variable to memory, it
16484 looks like we're storing a register-sized value, when in
16485 fact we are not. We need to adjust the offset of the
16486 storage location to reflect the actual value's bytes,
16487 else gdb will not be able to display it. */
16489 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16490 plus_constant (XEXP (rtl, 0), rsize-dsize));
16493 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16494 and will have been substituted directly into all expressions that use it.
16495 C does not have such a concept, but C++ and other languages do. */
16496 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16497 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16500 rtl = targetm.delegitimize_address (rtl);
16502 /* If we don't look past the constant pool, we risk emitting a
16503 reference to a constant pool entry that isn't referenced from
16504 code, and thus is not emitted. */
16506 rtl = avoid_constant_pool_reference (rtl);
16508 /* Try harder to get a rtl. If this symbol ends up not being emitted
16509 in the current CU, resolve_addr will remove the expression referencing
16511 if (rtl == NULL_RTX
16512 && TREE_CODE (decl) == VAR_DECL
16513 && !DECL_EXTERNAL (decl)
16514 && TREE_STATIC (decl)
16515 && DECL_NAME (decl)
16516 && !DECL_HARD_REGISTER (decl)
16517 && DECL_MODE (decl) != VOIDmode)
16519 rtl = make_decl_rtl_for_debug (decl);
16521 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16522 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16529 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16530 returned. If so, the decl for the COMMON block is returned, and the
16531 value is the offset into the common block for the symbol. */
16534 fortran_common (tree decl, HOST_WIDE_INT *value)
16536 tree val_expr, cvar;
16537 enum machine_mode mode;
16538 HOST_WIDE_INT bitsize, bitpos;
16540 int volatilep = 0, unsignedp = 0;
16542 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16543 it does not have a value (the offset into the common area), or if it
16544 is thread local (as opposed to global) then it isn't common, and shouldn't
16545 be handled as such. */
16546 if (TREE_CODE (decl) != VAR_DECL
16547 || !TREE_STATIC (decl)
16548 || !DECL_HAS_VALUE_EXPR_P (decl)
16552 val_expr = DECL_VALUE_EXPR (decl);
16553 if (TREE_CODE (val_expr) != COMPONENT_REF)
16556 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16557 &mode, &unsignedp, &volatilep, true);
16559 if (cvar == NULL_TREE
16560 || TREE_CODE (cvar) != VAR_DECL
16561 || DECL_ARTIFICIAL (cvar)
16562 || !TREE_PUBLIC (cvar))
16566 if (offset != NULL)
16568 if (!host_integerp (offset, 0))
16570 *value = tree_low_cst (offset, 0);
16573 *value += bitpos / BITS_PER_UNIT;
16578 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16579 data attribute for a variable or a parameter. We generate the
16580 DW_AT_const_value attribute only in those cases where the given variable
16581 or parameter does not have a true "location" either in memory or in a
16582 register. This can happen (for example) when a constant is passed as an
16583 actual argument in a call to an inline function. (It's possible that
16584 these things can crop up in other ways also.) Note that one type of
16585 constant value which can be passed into an inlined function is a constant
16586 pointer. This can happen for example if an actual argument in an inlined
16587 function call evaluates to a compile-time constant address. */
16590 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
16591 enum dwarf_attribute attr)
16594 dw_loc_list_ref list;
16595 var_loc_list *loc_list;
16597 if (TREE_CODE (decl) == ERROR_MARK)
16600 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16601 || TREE_CODE (decl) == RESULT_DECL);
16603 /* Try to get some constant RTL for this decl, and use that as the value of
16606 rtl = rtl_for_decl_location (decl);
16607 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16608 && add_const_value_attribute (die, rtl))
16611 /* See if we have single element location list that is equivalent to
16612 a constant value. That way we are better to use add_const_value_attribute
16613 rather than expanding constant value equivalent. */
16614 loc_list = lookup_decl_loc (decl);
16617 && loc_list->first->next == NULL
16618 && NOTE_P (loc_list->first->loc)
16619 && NOTE_VAR_LOCATION (loc_list->first->loc)
16620 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16622 struct var_loc_node *node;
16624 node = loc_list->first;
16625 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16626 if (GET_CODE (rtl) == EXPR_LIST)
16627 rtl = XEXP (rtl, 0);
16628 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16629 && add_const_value_attribute (die, rtl))
16632 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
16635 add_AT_location_description (die, attr, list);
16638 /* None of that worked, so it must not really have a location;
16639 try adding a constant value attribute from the DECL_INITIAL. */
16640 return tree_add_const_value_attribute_for_decl (die, decl);
16643 /* Add VARIABLE and DIE into deferred locations list. */
16646 defer_location (tree variable, dw_die_ref die)
16648 deferred_locations entry;
16649 entry.variable = variable;
16651 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
16654 /* Helper function for tree_add_const_value_attribute. Natively encode
16655 initializer INIT into an array. Return true if successful. */
16658 native_encode_initializer (tree init, unsigned char *array, int size)
16662 if (init == NULL_TREE)
16666 switch (TREE_CODE (init))
16669 type = TREE_TYPE (init);
16670 if (TREE_CODE (type) == ARRAY_TYPE)
16672 tree enttype = TREE_TYPE (type);
16673 enum machine_mode mode = TYPE_MODE (enttype);
16675 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16677 if (int_size_in_bytes (type) != size)
16679 if (size > TREE_STRING_LENGTH (init))
16681 memcpy (array, TREE_STRING_POINTER (init),
16682 TREE_STRING_LENGTH (init));
16683 memset (array + TREE_STRING_LENGTH (init),
16684 '\0', size - TREE_STRING_LENGTH (init));
16687 memcpy (array, TREE_STRING_POINTER (init), size);
16692 type = TREE_TYPE (init);
16693 if (int_size_in_bytes (type) != size)
16695 if (TREE_CODE (type) == ARRAY_TYPE)
16697 HOST_WIDE_INT min_index;
16698 unsigned HOST_WIDE_INT cnt;
16699 int curpos = 0, fieldsize;
16700 constructor_elt *ce;
16702 if (TYPE_DOMAIN (type) == NULL_TREE
16703 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
16706 fieldsize = int_size_in_bytes (TREE_TYPE (type));
16707 if (fieldsize <= 0)
16710 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
16711 memset (array, '\0', size);
16713 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
16716 tree val = ce->value;
16717 tree index = ce->index;
16719 if (index && TREE_CODE (index) == RANGE_EXPR)
16720 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
16723 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
16728 if (!native_encode_initializer (val, array + pos, fieldsize))
16731 curpos = pos + fieldsize;
16732 if (index && TREE_CODE (index) == RANGE_EXPR)
16734 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
16735 - tree_low_cst (TREE_OPERAND (index, 0), 0);
16739 memcpy (array + curpos, array + pos, fieldsize);
16740 curpos += fieldsize;
16743 gcc_assert (curpos <= size);
16747 else if (TREE_CODE (type) == RECORD_TYPE
16748 || TREE_CODE (type) == UNION_TYPE)
16750 tree field = NULL_TREE;
16751 unsigned HOST_WIDE_INT cnt;
16752 constructor_elt *ce;
16754 if (int_size_in_bytes (type) != size)
16757 if (TREE_CODE (type) == RECORD_TYPE)
16758 field = TYPE_FIELDS (type);
16761 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
16762 cnt++, field = field ? DECL_CHAIN (field) : 0)
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)
21121 VEC_iterate (die_arg_entry, tmpl_value_parm_die_table, i, e);
21123 tree_add_const_value_attribute (e->die, e->arg);
21128 /* Replace DW_AT_name for the decl with name. */
21131 dwarf2out_set_name (tree decl, tree name)
21137 die = TYPE_SYMTAB_DIE (decl);
21141 dname = dwarf2_name (name, 0);
21145 attr = get_AT (die, DW_AT_name);
21148 struct indirect_string_node *node;
21150 node = find_AT_string (dname);
21151 /* replace the string. */
21152 attr->dw_attr_val.v.val_str = node;
21156 add_name_attribute (die, dname);
21159 /* Called by the final INSN scan whenever we see a direct function call.
21160 Make an entry into the direct call table, recording the point of call
21161 and a reference to the target function's debug entry. */
21164 dwarf2out_direct_call (tree targ)
21167 tree origin = decl_ultimate_origin (targ);
21169 /* If this is a clone, use the abstract origin as the target. */
21173 e.poc_label_num = poc_label_num++;
21174 e.poc_decl = current_function_decl;
21175 e.targ_die = force_decl_die (targ);
21176 VEC_safe_push (dcall_entry, gc, dcall_table, &e);
21178 /* Drop a label at the return point to mark the point of call. */
21179 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21182 /* Returns a hash value for X (which really is a struct vcall_insn). */
21185 vcall_insn_table_hash (const void *x)
21187 return (hashval_t) ((const struct vcall_insn *) x)->insn_uid;
21190 /* Return nonzero if insn_uid of struct vcall_insn *X is the same as
21191 insnd_uid of *Y. */
21194 vcall_insn_table_eq (const void *x, const void *y)
21196 return (((const struct vcall_insn *) x)->insn_uid
21197 == ((const struct vcall_insn *) y)->insn_uid);
21200 /* Associate VTABLE_SLOT with INSN_UID in the VCALL_INSN_TABLE. */
21203 store_vcall_insn (unsigned int vtable_slot, int insn_uid)
21205 struct vcall_insn *item = ggc_alloc_vcall_insn ();
21206 struct vcall_insn **slot;
21209 item->insn_uid = insn_uid;
21210 item->vtable_slot = vtable_slot;
21211 slot = (struct vcall_insn **)
21212 htab_find_slot_with_hash (vcall_insn_table, &item,
21213 (hashval_t) insn_uid, INSERT);
21217 /* Return the VTABLE_SLOT associated with INSN_UID. */
21219 static unsigned int
21220 lookup_vcall_insn (unsigned int insn_uid)
21222 struct vcall_insn item;
21223 struct vcall_insn *p;
21225 item.insn_uid = insn_uid;
21226 item.vtable_slot = 0;
21227 p = (struct vcall_insn *) htab_find_with_hash (vcall_insn_table,
21229 (hashval_t) insn_uid);
21231 return (unsigned int) -1;
21232 return p->vtable_slot;
21236 /* Called when lowering indirect calls to RTL. We make a note of INSN_UID
21237 and the OBJ_TYPE_REF_TOKEN from ADDR. For C++ virtual calls, the token
21238 is the vtable slot index that we will need to put in the virtual call
21242 dwarf2out_virtual_call_token (tree addr, int insn_uid)
21244 if (is_cxx() && TREE_CODE (addr) == OBJ_TYPE_REF)
21246 tree token = OBJ_TYPE_REF_TOKEN (addr);
21247 if (TREE_CODE (token) == INTEGER_CST)
21248 store_vcall_insn (TREE_INT_CST_LOW (token), insn_uid);
21252 /* Called when scheduling RTL, when a CALL_INSN is split. Copies the
21253 OBJ_TYPE_REF_TOKEN previously associated with OLD_INSN and associates it
21257 dwarf2out_copy_call_info (rtx old_insn, rtx new_insn)
21259 unsigned int vtable_slot = lookup_vcall_insn (INSN_UID (old_insn));
21261 if (vtable_slot != (unsigned int) -1)
21262 store_vcall_insn (vtable_slot, INSN_UID (new_insn));
21265 /* Called by the final INSN scan whenever we see a virtual function call.
21266 Make an entry into the virtual call table, recording the point of call
21267 and the slot index of the vtable entry used to call the virtual member
21268 function. The slot index was associated with the INSN_UID during the
21269 lowering to RTL. */
21272 dwarf2out_virtual_call (int insn_uid)
21274 unsigned int vtable_slot = lookup_vcall_insn (insn_uid);
21277 if (vtable_slot == (unsigned int) -1)
21280 e.poc_label_num = poc_label_num++;
21281 e.vtable_slot = vtable_slot;
21282 VEC_safe_push (vcall_entry, gc, vcall_table, &e);
21284 /* Drop a label at the return point to mark the point of call. */
21285 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21288 /* Called by the final INSN scan whenever we see a var location. We
21289 use it to drop labels in the right places, and throw the location in
21290 our lookup table. */
21293 dwarf2out_var_location (rtx loc_note)
21295 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21296 struct var_loc_node *newloc;
21298 static const char *last_label;
21299 static const char *last_postcall_label;
21300 static bool last_in_cold_section_p;
21303 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21306 next_real = next_real_insn (loc_note);
21307 /* If there are no instructions which would be affected by this note,
21308 don't do anything. */
21309 if (next_real == NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
21312 /* If there were any real insns between note we processed last time
21313 and this note (or if it is the first note), clear
21314 last_{,postcall_}label so that they are not reused this time. */
21315 if (last_var_location_insn == NULL_RTX
21316 || last_var_location_insn != next_real
21317 || last_in_cold_section_p != in_cold_section_p)
21320 last_postcall_label = NULL;
21323 decl = NOTE_VAR_LOCATION_DECL (loc_note);
21324 newloc = add_var_loc_to_decl (decl, loc_note,
21325 NOTE_DURING_CALL_P (loc_note)
21326 ? last_postcall_label : last_label);
21327 if (newloc == NULL)
21330 /* If there were no real insns between note we processed last time
21331 and this note, use the label we emitted last time. Otherwise
21332 create a new label and emit it. */
21333 if (last_label == NULL)
21335 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
21336 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
21338 last_label = ggc_strdup (loclabel);
21341 if (!NOTE_DURING_CALL_P (loc_note))
21342 newloc->label = last_label;
21345 if (!last_postcall_label)
21347 sprintf (loclabel, "%s-1", last_label);
21348 last_postcall_label = ggc_strdup (loclabel);
21350 newloc->label = last_postcall_label;
21353 last_var_location_insn = next_real;
21354 last_in_cold_section_p = in_cold_section_p;
21357 /* We need to reset the locations at the beginning of each
21358 function. We can't do this in the end_function hook, because the
21359 declarations that use the locations won't have been output when
21360 that hook is called. Also compute have_multiple_function_sections here. */
21363 dwarf2out_begin_function (tree fun)
21365 if (function_section (fun) != text_section)
21366 have_multiple_function_sections = true;
21368 dwarf2out_note_section_used ();
21371 /* Output a label to mark the beginning of a source code line entry
21372 and record information relating to this source line, in
21373 'line_info_table' for later output of the .debug_line section. */
21376 dwarf2out_source_line (unsigned int line, const char *filename,
21377 int discriminator, bool is_stmt)
21379 static bool last_is_stmt = true;
21381 if (debug_info_level >= DINFO_LEVEL_NORMAL
21384 int file_num = maybe_emit_file (lookup_filename (filename));
21386 switch_to_section (current_function_section ());
21388 /* If requested, emit something human-readable. */
21389 if (flag_debug_asm)
21390 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
21393 if (DWARF2_ASM_LINE_DEBUG_INFO)
21395 /* Emit the .loc directive understood by GNU as. */
21396 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
21397 if (is_stmt != last_is_stmt)
21399 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
21400 last_is_stmt = is_stmt;
21402 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
21403 fprintf (asm_out_file, " discriminator %d", discriminator);
21404 fputc ('\n', asm_out_file);
21406 /* Indicate that line number info exists. */
21407 line_info_table_in_use++;
21409 else if (function_section (current_function_decl) != text_section)
21411 dw_separate_line_info_ref line_info;
21412 targetm.asm_out.internal_label (asm_out_file,
21413 SEPARATE_LINE_CODE_LABEL,
21414 separate_line_info_table_in_use);
21416 /* Expand the line info table if necessary. */
21417 if (separate_line_info_table_in_use
21418 == separate_line_info_table_allocated)
21420 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21421 separate_line_info_table
21422 = GGC_RESIZEVEC (dw_separate_line_info_entry,
21423 separate_line_info_table,
21424 separate_line_info_table_allocated);
21425 memset (separate_line_info_table
21426 + separate_line_info_table_in_use,
21428 (LINE_INFO_TABLE_INCREMENT
21429 * sizeof (dw_separate_line_info_entry)));
21432 /* Add the new entry at the end of the line_info_table. */
21434 = &separate_line_info_table[separate_line_info_table_in_use++];
21435 line_info->dw_file_num = file_num;
21436 line_info->dw_line_num = line;
21437 line_info->function = current_function_funcdef_no;
21441 dw_line_info_ref line_info;
21443 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
21444 line_info_table_in_use);
21446 /* Expand the line info table if necessary. */
21447 if (line_info_table_in_use == line_info_table_allocated)
21449 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21451 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
21452 line_info_table_allocated);
21453 memset (line_info_table + line_info_table_in_use, 0,
21454 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
21457 /* Add the new entry at the end of the line_info_table. */
21458 line_info = &line_info_table[line_info_table_in_use++];
21459 line_info->dw_file_num = file_num;
21460 line_info->dw_line_num = line;
21465 /* Record the beginning of a new source file. */
21468 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
21470 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21472 /* Record the beginning of the file for break_out_includes. */
21473 dw_die_ref bincl_die;
21475 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
21476 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
21479 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21481 int file_num = maybe_emit_file (lookup_filename (filename));
21483 switch_to_section (debug_macinfo_section);
21484 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
21485 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
21488 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
21492 /* Record the end of a source file. */
21495 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
21497 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21498 /* Record the end of the file for break_out_includes. */
21499 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
21501 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21503 switch_to_section (debug_macinfo_section);
21504 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
21508 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21509 the tail part of the directive line, i.e. the part which is past the
21510 initial whitespace, #, whitespace, directive-name, whitespace part. */
21513 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
21514 const char *buffer ATTRIBUTE_UNUSED)
21516 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21518 switch_to_section (debug_macinfo_section);
21519 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
21520 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
21521 dw2_asm_output_nstring (buffer, -1, "The macro");
21525 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21526 the tail part of the directive line, i.e. the part which is past the
21527 initial whitespace, #, whitespace, directive-name, whitespace part. */
21530 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
21531 const char *buffer ATTRIBUTE_UNUSED)
21533 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21535 switch_to_section (debug_macinfo_section);
21536 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
21537 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
21538 dw2_asm_output_nstring (buffer, -1, "The macro");
21542 /* Set up for Dwarf output at the start of compilation. */
21545 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
21547 /* Allocate the file_table. */
21548 file_table = htab_create_ggc (50, file_table_hash,
21549 file_table_eq, NULL);
21551 /* Allocate the decl_die_table. */
21552 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
21553 decl_die_table_eq, NULL);
21555 /* Allocate the decl_loc_table. */
21556 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
21557 decl_loc_table_eq, NULL);
21559 /* Allocate the initial hunk of the decl_scope_table. */
21560 decl_scope_table = VEC_alloc (tree, gc, 256);
21562 /* Allocate the initial hunk of the abbrev_die_table. */
21563 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
21564 (ABBREV_DIE_TABLE_INCREMENT);
21565 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
21566 /* Zero-th entry is allocated, but unused. */
21567 abbrev_die_table_in_use = 1;
21569 /* Allocate the initial hunk of the line_info_table. */
21570 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
21571 (LINE_INFO_TABLE_INCREMENT);
21572 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
21574 /* Zero-th entry is allocated, but unused. */
21575 line_info_table_in_use = 1;
21577 /* Allocate the pubtypes and pubnames vectors. */
21578 pubname_table = VEC_alloc (pubname_entry, gc, 32);
21579 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
21581 /* Allocate the table that maps insn UIDs to vtable slot indexes. */
21582 vcall_insn_table = htab_create_ggc (10, vcall_insn_table_hash,
21583 vcall_insn_table_eq, NULL);
21585 /* Generate the initial DIE for the .debug section. Note that the (string)
21586 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
21587 will (typically) be a relative pathname and that this pathname should be
21588 taken as being relative to the directory from which the compiler was
21589 invoked when the given (base) source file was compiled. We will fill
21590 in this value in dwarf2out_finish. */
21591 comp_unit_die = gen_compile_unit_die (NULL);
21593 incomplete_types = VEC_alloc (tree, gc, 64);
21595 used_rtx_array = VEC_alloc (rtx, gc, 32);
21597 debug_info_section = get_section (DEBUG_INFO_SECTION,
21598 SECTION_DEBUG, NULL);
21599 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
21600 SECTION_DEBUG, NULL);
21601 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
21602 SECTION_DEBUG, NULL);
21603 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
21604 SECTION_DEBUG, NULL);
21605 debug_line_section = get_section (DEBUG_LINE_SECTION,
21606 SECTION_DEBUG, NULL);
21607 debug_loc_section = get_section (DEBUG_LOC_SECTION,
21608 SECTION_DEBUG, NULL);
21609 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
21610 SECTION_DEBUG, NULL);
21611 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
21612 SECTION_DEBUG, NULL);
21613 debug_dcall_section = get_section (DEBUG_DCALL_SECTION,
21614 SECTION_DEBUG, NULL);
21615 debug_vcall_section = get_section (DEBUG_VCALL_SECTION,
21616 SECTION_DEBUG, NULL);
21617 debug_str_section = get_section (DEBUG_STR_SECTION,
21618 DEBUG_STR_SECTION_FLAGS, NULL);
21619 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
21620 SECTION_DEBUG, NULL);
21621 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
21622 SECTION_DEBUG, NULL);
21624 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
21625 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
21626 DEBUG_ABBREV_SECTION_LABEL, 0);
21627 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
21628 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
21629 COLD_TEXT_SECTION_LABEL, 0);
21630 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
21632 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
21633 DEBUG_INFO_SECTION_LABEL, 0);
21634 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
21635 DEBUG_LINE_SECTION_LABEL, 0);
21636 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
21637 DEBUG_RANGES_SECTION_LABEL, 0);
21638 switch_to_section (debug_abbrev_section);
21639 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
21640 switch_to_section (debug_info_section);
21641 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
21642 switch_to_section (debug_line_section);
21643 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
21645 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21647 switch_to_section (debug_macinfo_section);
21648 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
21649 DEBUG_MACINFO_SECTION_LABEL, 0);
21650 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
21653 switch_to_section (text_section);
21654 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
21655 if (flag_reorder_blocks_and_partition)
21657 cold_text_section = unlikely_text_section ();
21658 switch_to_section (cold_text_section);
21659 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
21664 /* Called before cgraph_optimize starts outputtting functions, variables
21665 and toplevel asms into assembly. */
21668 dwarf2out_assembly_start (void)
21670 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE && dwarf2out_do_cfi_asm ())
21672 #ifndef TARGET_UNWIND_INFO
21673 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
21675 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
21679 /* A helper function for dwarf2out_finish called through
21680 htab_traverse. Emit one queued .debug_str string. */
21683 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
21685 struct indirect_string_node *node = (struct indirect_string_node *) *h;
21687 if (node->label && node->refcount)
21689 switch_to_section (debug_str_section);
21690 ASM_OUTPUT_LABEL (asm_out_file, node->label);
21691 assemble_string (node->str, strlen (node->str) + 1);
21697 #if ENABLE_ASSERT_CHECKING
21698 /* Verify that all marks are clear. */
21701 verify_marks_clear (dw_die_ref die)
21705 gcc_assert (! die->die_mark);
21706 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
21708 #endif /* ENABLE_ASSERT_CHECKING */
21710 /* Clear the marks for a die and its children.
21711 Be cool if the mark isn't set. */
21714 prune_unmark_dies (dw_die_ref die)
21720 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
21723 /* Given DIE that we're marking as used, find any other dies
21724 it references as attributes and mark them as used. */
21727 prune_unused_types_walk_attribs (dw_die_ref die)
21732 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
21734 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
21736 /* A reference to another DIE.
21737 Make sure that it will get emitted.
21738 If it was broken out into a comdat group, don't follow it. */
21739 if (dwarf_version < 4
21740 || a->dw_attr == DW_AT_specification
21741 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
21742 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
21744 /* Set the string's refcount to 0 so that prune_unused_types_mark
21745 accounts properly for it. */
21746 if (AT_class (a) == dw_val_class_str)
21747 a->dw_attr_val.v.val_str->refcount = 0;
21752 /* Mark DIE as being used. If DOKIDS is true, then walk down
21753 to DIE's children. */
21756 prune_unused_types_mark (dw_die_ref die, int dokids)
21760 if (die->die_mark == 0)
21762 /* We haven't done this node yet. Mark it as used. */
21765 /* We also have to mark its parents as used.
21766 (But we don't want to mark our parents' kids due to this.) */
21767 if (die->die_parent)
21768 prune_unused_types_mark (die->die_parent, 0);
21770 /* Mark any referenced nodes. */
21771 prune_unused_types_walk_attribs (die);
21773 /* If this node is a specification,
21774 also mark the definition, if it exists. */
21775 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
21776 prune_unused_types_mark (die->die_definition, 1);
21779 if (dokids && die->die_mark != 2)
21781 /* We need to walk the children, but haven't done so yet.
21782 Remember that we've walked the kids. */
21785 /* If this is an array type, we need to make sure our
21786 kids get marked, even if they're types. If we're
21787 breaking out types into comdat sections, do this
21788 for all type definitions. */
21789 if (die->die_tag == DW_TAG_array_type
21790 || (dwarf_version >= 4
21791 && is_type_die (die) && ! is_declaration_die (die)))
21792 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
21794 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21798 /* For local classes, look if any static member functions were emitted
21799 and if so, mark them. */
21802 prune_unused_types_walk_local_classes (dw_die_ref die)
21806 if (die->die_mark == 2)
21809 switch (die->die_tag)
21811 case DW_TAG_structure_type:
21812 case DW_TAG_union_type:
21813 case DW_TAG_class_type:
21816 case DW_TAG_subprogram:
21817 if (!get_AT_flag (die, DW_AT_declaration)
21818 || die->die_definition != NULL)
21819 prune_unused_types_mark (die, 1);
21826 /* Mark children. */
21827 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
21830 /* Walk the tree DIE and mark types that we actually use. */
21833 prune_unused_types_walk (dw_die_ref die)
21837 /* Don't do anything if this node is already marked and
21838 children have been marked as well. */
21839 if (die->die_mark == 2)
21842 switch (die->die_tag)
21844 case DW_TAG_structure_type:
21845 case DW_TAG_union_type:
21846 case DW_TAG_class_type:
21847 if (die->die_perennial_p)
21850 for (c = die->die_parent; c; c = c->die_parent)
21851 if (c->die_tag == DW_TAG_subprogram)
21854 /* Finding used static member functions inside of classes
21855 is needed just for local classes, because for other classes
21856 static member function DIEs with DW_AT_specification
21857 are emitted outside of the DW_TAG_*_type. If we ever change
21858 it, we'd need to call this even for non-local classes. */
21860 prune_unused_types_walk_local_classes (die);
21862 /* It's a type node --- don't mark it. */
21865 case DW_TAG_const_type:
21866 case DW_TAG_packed_type:
21867 case DW_TAG_pointer_type:
21868 case DW_TAG_reference_type:
21869 case DW_TAG_rvalue_reference_type:
21870 case DW_TAG_volatile_type:
21871 case DW_TAG_typedef:
21872 case DW_TAG_array_type:
21873 case DW_TAG_interface_type:
21874 case DW_TAG_friend:
21875 case DW_TAG_variant_part:
21876 case DW_TAG_enumeration_type:
21877 case DW_TAG_subroutine_type:
21878 case DW_TAG_string_type:
21879 case DW_TAG_set_type:
21880 case DW_TAG_subrange_type:
21881 case DW_TAG_ptr_to_member_type:
21882 case DW_TAG_file_type:
21883 if (die->die_perennial_p)
21886 /* It's a type node --- don't mark it. */
21890 /* Mark everything else. */
21894 if (die->die_mark == 0)
21898 /* Now, mark any dies referenced from here. */
21899 prune_unused_types_walk_attribs (die);
21904 /* Mark children. */
21905 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21908 /* Increment the string counts on strings referred to from DIE's
21912 prune_unused_types_update_strings (dw_die_ref die)
21917 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
21918 if (AT_class (a) == dw_val_class_str)
21920 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
21922 /* Avoid unnecessarily putting strings that are used less than
21923 twice in the hash table. */
21925 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
21928 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
21929 htab_hash_string (s->str),
21931 gcc_assert (*slot == NULL);
21937 /* Remove from the tree DIE any dies that aren't marked. */
21940 prune_unused_types_prune (dw_die_ref die)
21944 gcc_assert (die->die_mark);
21945 prune_unused_types_update_strings (die);
21947 if (! die->die_child)
21950 c = die->die_child;
21952 dw_die_ref prev = c;
21953 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
21954 if (c == die->die_child)
21956 /* No marked children between 'prev' and the end of the list. */
21958 /* No marked children at all. */
21959 die->die_child = NULL;
21962 prev->die_sib = c->die_sib;
21963 die->die_child = prev;
21968 if (c != prev->die_sib)
21970 prune_unused_types_prune (c);
21971 } while (c != die->die_child);
21974 /* A helper function for dwarf2out_finish called through
21975 htab_traverse. Clear .debug_str strings that we haven't already
21976 decided to emit. */
21979 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
21981 struct indirect_string_node *node = (struct indirect_string_node *) *h;
21983 if (!node->label || !node->refcount)
21984 htab_clear_slot (debug_str_hash, h);
21989 /* Remove dies representing declarations that we never use. */
21992 prune_unused_types (void)
21995 limbo_die_node *node;
21996 comdat_type_node *ctnode;
21998 dcall_entry *dcall;
22000 #if ENABLE_ASSERT_CHECKING
22001 /* All the marks should already be clear. */
22002 verify_marks_clear (comp_unit_die);
22003 for (node = limbo_die_list; node; node = node->next)
22004 verify_marks_clear (node->die);
22005 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22006 verify_marks_clear (ctnode->root_die);
22007 #endif /* ENABLE_ASSERT_CHECKING */
22009 /* Mark types that are used in global variables. */
22010 premark_types_used_by_global_vars ();
22012 /* Set the mark on nodes that are actually used. */
22013 prune_unused_types_walk (comp_unit_die);
22014 for (node = limbo_die_list; node; node = node->next)
22015 prune_unused_types_walk (node->die);
22016 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22018 prune_unused_types_walk (ctnode->root_die);
22019 prune_unused_types_mark (ctnode->type_die, 1);
22022 /* Also set the mark on nodes referenced from the
22023 pubname_table or arange_table. */
22024 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
22025 prune_unused_types_mark (pub->die, 1);
22026 for (i = 0; i < arange_table_in_use; i++)
22027 prune_unused_types_mark (arange_table[i], 1);
22029 /* Mark nodes referenced from the direct call table. */
22030 for (i = 0; VEC_iterate (dcall_entry, dcall_table, i, dcall); i++)
22031 prune_unused_types_mark (dcall->targ_die, 1);
22033 /* Get rid of nodes that aren't marked; and update the string counts. */
22034 if (debug_str_hash && debug_str_hash_forced)
22035 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22036 else if (debug_str_hash)
22037 htab_empty (debug_str_hash);
22038 prune_unused_types_prune (comp_unit_die);
22039 for (node = limbo_die_list; node; node = node->next)
22040 prune_unused_types_prune (node->die);
22041 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22042 prune_unused_types_prune (ctnode->root_die);
22044 /* Leave the marks clear. */
22045 prune_unmark_dies (comp_unit_die);
22046 for (node = limbo_die_list; node; node = node->next)
22047 prune_unmark_dies (node->die);
22048 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22049 prune_unmark_dies (ctnode->root_die);
22052 /* Set the parameter to true if there are any relative pathnames in
22055 file_table_relative_p (void ** slot, void *param)
22057 bool *p = (bool *) param;
22058 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22059 if (!IS_ABSOLUTE_PATH (d->filename))
22067 /* Routines to manipulate hash table of comdat type units. */
22070 htab_ct_hash (const void *of)
22073 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22075 memcpy (&h, type_node->signature, sizeof (h));
22080 htab_ct_eq (const void *of1, const void *of2)
22082 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22083 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22085 return (! memcmp (type_node_1->signature, type_node_2->signature,
22086 DWARF_TYPE_SIGNATURE_SIZE));
22089 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22090 to the location it would have been added, should we know its
22091 DECL_ASSEMBLER_NAME when we added other attributes. This will
22092 probably improve compactness of debug info, removing equivalent
22093 abbrevs, and hide any differences caused by deferring the
22094 computation of the assembler name, triggered by e.g. PCH. */
22097 move_linkage_attr (dw_die_ref die)
22099 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22100 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22102 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22103 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22107 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22109 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22113 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22115 VEC_pop (dw_attr_node, die->die_attr);
22116 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22120 /* Helper function for resolve_addr, attempt to resolve
22121 one CONST_STRING, return non-zero if not successful. Similarly verify that
22122 SYMBOL_REFs refer to variables emitted in the current CU. */
22125 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22129 if (GET_CODE (rtl) == CONST_STRING)
22131 size_t len = strlen (XSTR (rtl, 0)) + 1;
22132 tree t = build_string (len, XSTR (rtl, 0));
22133 tree tlen = build_int_cst (NULL_TREE, len - 1);
22135 = build_array_type (char_type_node, build_index_type (tlen));
22136 rtl = lookup_constant_def (t);
22137 if (!rtl || !MEM_P (rtl))
22139 rtl = XEXP (rtl, 0);
22140 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22145 if (GET_CODE (rtl) == SYMBOL_REF
22146 && SYMBOL_REF_DECL (rtl)
22147 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22150 if (GET_CODE (rtl) == CONST
22151 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22157 /* Helper function for resolve_addr, handle one location
22158 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22159 the location list couldn't be resolved. */
22162 resolve_addr_in_expr (dw_loc_descr_ref loc)
22164 for (; loc; loc = loc->dw_loc_next)
22165 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22166 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22167 || (loc->dw_loc_opc == DW_OP_implicit_value
22168 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22169 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22174 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22175 an address in .rodata section if the string literal is emitted there,
22176 or remove the containing location list or replace DW_AT_const_value
22177 with DW_AT_location and empty location expression, if it isn't found
22178 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22179 to something that has been emitted in the current CU. */
22182 resolve_addr (dw_die_ref die)
22186 dw_loc_list_ref *curr;
22189 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
22190 switch (AT_class (a))
22192 case dw_val_class_loc_list:
22193 curr = AT_loc_list_ptr (a);
22196 if (!resolve_addr_in_expr ((*curr)->expr))
22198 dw_loc_list_ref next = (*curr)->dw_loc_next;
22199 if (next && (*curr)->ll_symbol)
22201 gcc_assert (!next->ll_symbol);
22202 next->ll_symbol = (*curr)->ll_symbol;
22207 curr = &(*curr)->dw_loc_next;
22209 if (!AT_loc_list (a))
22211 remove_AT (die, a->dw_attr);
22215 case dw_val_class_loc:
22216 if (!resolve_addr_in_expr (AT_loc (a)))
22218 remove_AT (die, a->dw_attr);
22222 case dw_val_class_addr:
22223 if (a->dw_attr == DW_AT_const_value
22224 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
22226 remove_AT (die, a->dw_attr);
22234 FOR_EACH_CHILD (die, c, resolve_addr (c));
22237 /* Output stuff that dwarf requires at the end of every file,
22238 and generate the DWARF-2 debugging info. */
22241 dwarf2out_finish (const char *filename)
22243 limbo_die_node *node, *next_node;
22244 comdat_type_node *ctnode;
22245 htab_t comdat_type_table;
22246 dw_die_ref die = 0;
22249 gen_remaining_tmpl_value_param_die_attribute ();
22251 /* Add the name for the main input file now. We delayed this from
22252 dwarf2out_init to avoid complications with PCH. */
22253 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
22254 if (!IS_ABSOLUTE_PATH (filename))
22255 add_comp_dir_attribute (comp_unit_die);
22256 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
22259 htab_traverse (file_table, file_table_relative_p, &p);
22261 add_comp_dir_attribute (comp_unit_die);
22264 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
22266 add_location_or_const_value_attribute (
22267 VEC_index (deferred_locations, deferred_locations_list, i)->die,
22268 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
22272 /* Traverse the limbo die list, and add parent/child links. The only
22273 dies without parents that should be here are concrete instances of
22274 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22275 For concrete instances, we can get the parent die from the abstract
22277 for (node = limbo_die_list; node; node = next_node)
22279 next_node = node->next;
22282 if (die->die_parent == NULL)
22284 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
22287 add_child_die (origin->die_parent, die);
22288 else if (die == comp_unit_die)
22290 else if (seen_error ())
22291 /* It's OK to be confused by errors in the input. */
22292 add_child_die (comp_unit_die, die);
22295 /* In certain situations, the lexical block containing a
22296 nested function can be optimized away, which results
22297 in the nested function die being orphaned. Likewise
22298 with the return type of that nested function. Force
22299 this to be a child of the containing function.
22301 It may happen that even the containing function got fully
22302 inlined and optimized out. In that case we are lost and
22303 assign the empty child. This should not be big issue as
22304 the function is likely unreachable too. */
22305 tree context = NULL_TREE;
22307 gcc_assert (node->created_for);
22309 if (DECL_P (node->created_for))
22310 context = DECL_CONTEXT (node->created_for);
22311 else if (TYPE_P (node->created_for))
22312 context = TYPE_CONTEXT (node->created_for);
22314 gcc_assert (context
22315 && (TREE_CODE (context) == FUNCTION_DECL
22316 || TREE_CODE (context) == NAMESPACE_DECL));
22318 origin = lookup_decl_die (context);
22320 add_child_die (origin, die);
22322 add_child_die (comp_unit_die, die);
22327 limbo_die_list = NULL;
22329 resolve_addr (comp_unit_die);
22331 for (node = deferred_asm_name; node; node = node->next)
22333 tree decl = node->created_for;
22334 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22336 add_linkage_attr (node->die, decl);
22337 move_linkage_attr (node->die);
22341 deferred_asm_name = NULL;
22343 /* Walk through the list of incomplete types again, trying once more to
22344 emit full debugging info for them. */
22345 retry_incomplete_types ();
22347 if (flag_eliminate_unused_debug_types)
22348 prune_unused_types ();
22350 /* Generate separate CUs for each of the include files we've seen.
22351 They will go into limbo_die_list. */
22352 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22353 break_out_includes (comp_unit_die);
22355 /* Generate separate COMDAT sections for type DIEs. */
22356 if (dwarf_version >= 4)
22358 break_out_comdat_types (comp_unit_die);
22360 /* Each new type_unit DIE was added to the limbo die list when created.
22361 Since these have all been added to comdat_type_list, clear the
22363 limbo_die_list = NULL;
22365 /* For each new comdat type unit, copy declarations for incomplete
22366 types to make the new unit self-contained (i.e., no direct
22367 references to the main compile unit). */
22368 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22369 copy_decls_for_unworthy_types (ctnode->root_die);
22370 copy_decls_for_unworthy_types (comp_unit_die);
22372 /* In the process of copying declarations from one unit to another,
22373 we may have left some declarations behind that are no longer
22374 referenced. Prune them. */
22375 prune_unused_types ();
22378 /* Traverse the DIE's and add add sibling attributes to those DIE's
22379 that have children. */
22380 add_sibling_attributes (comp_unit_die);
22381 for (node = limbo_die_list; node; node = node->next)
22382 add_sibling_attributes (node->die);
22383 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22384 add_sibling_attributes (ctnode->root_die);
22386 /* Output a terminator label for the .text section. */
22387 switch_to_section (text_section);
22388 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
22389 if (flag_reorder_blocks_and_partition)
22391 switch_to_section (unlikely_text_section ());
22392 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
22395 /* We can only use the low/high_pc attributes if all of the code was
22397 if (!have_multiple_function_sections
22398 || !(dwarf_version >= 3 || !dwarf_strict))
22400 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
22401 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
22406 unsigned fde_idx = 0;
22407 bool range_list_added = false;
22409 /* We need to give .debug_loc and .debug_ranges an appropriate
22410 "base address". Use zero so that these addresses become
22411 absolute. Historically, we've emitted the unexpected
22412 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22413 Emit both to give time for other tools to adapt. */
22414 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
22415 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
22417 if (text_section_used)
22418 add_ranges_by_labels (comp_unit_die, text_section_label,
22419 text_end_label, &range_list_added);
22420 if (flag_reorder_blocks_and_partition && cold_text_section_used)
22421 add_ranges_by_labels (comp_unit_die, cold_text_section_label,
22422 cold_end_label, &range_list_added);
22424 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
22426 dw_fde_ref fde = &fde_table[fde_idx];
22428 if (fde->dw_fde_switched_sections)
22430 if (!fde->in_std_section)
22431 add_ranges_by_labels (comp_unit_die,
22432 fde->dw_fde_hot_section_label,
22433 fde->dw_fde_hot_section_end_label,
22434 &range_list_added);
22435 if (!fde->cold_in_std_section)
22436 add_ranges_by_labels (comp_unit_die,
22437 fde->dw_fde_unlikely_section_label,
22438 fde->dw_fde_unlikely_section_end_label,
22439 &range_list_added);
22441 else if (!fde->in_std_section)
22442 add_ranges_by_labels (comp_unit_die, fde->dw_fde_begin,
22443 fde->dw_fde_end, &range_list_added);
22446 if (range_list_added)
22450 /* Output location list section if necessary. */
22451 if (have_location_lists)
22453 /* Output the location lists info. */
22454 switch_to_section (debug_loc_section);
22455 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
22456 DEBUG_LOC_SECTION_LABEL, 0);
22457 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
22458 output_location_lists (die);
22461 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22462 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
22463 debug_line_section_label);
22465 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22466 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
22468 /* Output all of the compilation units. We put the main one last so that
22469 the offsets are available to output_pubnames. */
22470 for (node = limbo_die_list; node; node = node->next)
22471 output_comp_unit (node->die, 0);
22473 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
22474 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22476 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
22478 /* Don't output duplicate types. */
22479 if (*slot != HTAB_EMPTY_ENTRY)
22482 /* Add a pointer to the line table for the main compilation unit
22483 so that the debugger can make sense of DW_AT_decl_file
22485 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22486 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
22487 debug_line_section_label);
22489 output_comdat_type_unit (ctnode);
22492 htab_delete (comdat_type_table);
22494 /* Output the main compilation unit if non-empty or if .debug_macinfo
22495 has been emitted. */
22496 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
22498 /* Output the abbreviation table. */
22499 switch_to_section (debug_abbrev_section);
22500 output_abbrev_section ();
22502 /* Output public names table if necessary. */
22503 if (!VEC_empty (pubname_entry, pubname_table))
22505 switch_to_section (debug_pubnames_section);
22506 output_pubnames (pubname_table);
22509 /* Output public types table if necessary. */
22510 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22511 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22512 simply won't look for the section. */
22513 if (!VEC_empty (pubname_entry, pubtype_table))
22515 switch_to_section (debug_pubtypes_section);
22516 output_pubnames (pubtype_table);
22519 /* Output direct and virtual call tables if necessary. */
22520 if (!VEC_empty (dcall_entry, dcall_table))
22522 switch_to_section (debug_dcall_section);
22523 output_dcall_table ();
22525 if (!VEC_empty (vcall_entry, vcall_table))
22527 switch_to_section (debug_vcall_section);
22528 output_vcall_table ();
22531 /* Output the address range information. We only put functions in the arange
22532 table, so don't write it out if we don't have any. */
22533 if (fde_table_in_use)
22535 switch_to_section (debug_aranges_section);
22539 /* Output ranges section if necessary. */
22540 if (ranges_table_in_use)
22542 switch_to_section (debug_ranges_section);
22543 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
22547 /* Output the source line correspondence table. We must do this
22548 even if there is no line information. Otherwise, on an empty
22549 translation unit, we will generate a present, but empty,
22550 .debug_info section. IRIX 6.5 `nm' will then complain when
22551 examining the file. This is done late so that any filenames
22552 used by the debug_info section are marked as 'used'. */
22553 if (! DWARF2_ASM_LINE_DEBUG_INFO)
22555 switch_to_section (debug_line_section);
22556 output_line_info ();
22559 /* Have to end the macro section. */
22560 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22562 switch_to_section (debug_macinfo_section);
22563 dw2_asm_output_data (1, 0, "End compilation unit");
22566 /* If we emitted any DW_FORM_strp form attribute, output the string
22568 if (debug_str_hash)
22569 htab_traverse (debug_str_hash, output_indirect_string, NULL);
22572 #include "gt-dwarf2out.h"