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 /* ??? Poison these here until it can be done generically. They've been
116 totally replaced in this file; make sure it stays that way. */
117 #undef DWARF2_UNWIND_INFO
118 #undef DWARF2_FRAME_INFO
119 #if (GCC_VERSION >= 3000)
120 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
123 #ifndef INCOMING_RETURN_ADDR_RTX
124 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
127 /* Map register numbers held in the call frame info that gcc has
128 collected using DWARF_FRAME_REGNUM to those that should be output in
129 .debug_frame and .eh_frame. */
130 #ifndef DWARF2_FRAME_REG_OUT
131 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
134 /* Save the result of dwarf2out_do_frame across PCH. */
135 static GTY(()) bool saved_do_cfi_asm = 0;
137 /* Decide whether we want to emit frame unwind information for the current
141 dwarf2out_do_frame (void)
143 /* We want to emit correct CFA location expressions or lists, so we
144 have to return true if we're going to output debug info, even if
145 we're not going to output frame or unwind info. */
146 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
149 if (saved_do_cfi_asm)
152 if (targetm.debug_unwind_info () == UI_DWARF2)
155 if ((flag_unwind_tables || flag_exceptions)
156 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
162 /* Decide whether to emit frame unwind via assembler directives. */
165 dwarf2out_do_cfi_asm (void)
169 #ifdef MIPS_DEBUGGING_INFO
172 if (saved_do_cfi_asm)
174 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
176 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
179 /* Make sure the personality encoding is one the assembler can support.
180 In particular, aligned addresses can't be handled. */
181 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
182 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
184 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
185 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
188 /* If we can't get the assembler to emit only .debug_frame, and we don't need
189 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
190 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
191 && !flag_unwind_tables && !flag_exceptions
192 && targetm.except_unwind_info (&global_options) != UI_DWARF2)
195 saved_do_cfi_asm = true;
199 /* The size of the target's pointer type. */
201 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
204 /* Array of RTXes referenced by the debugging information, which therefore
205 must be kept around forever. */
206 static GTY(()) VEC(rtx,gc) *used_rtx_array;
208 /* A pointer to the base of a list of incomplete types which might be
209 completed at some later time. incomplete_types_list needs to be a
210 VEC(tree,gc) because we want to tell the garbage collector about
212 static GTY(()) VEC(tree,gc) *incomplete_types;
214 /* A pointer to the base of a table of references to declaration
215 scopes. This table is a display which tracks the nesting
216 of declaration scopes at the current scope and containing
217 scopes. This table is used to find the proper place to
218 define type declaration DIE's. */
219 static GTY(()) VEC(tree,gc) *decl_scope_table;
221 /* Pointers to various DWARF2 sections. */
222 static GTY(()) section *debug_info_section;
223 static GTY(()) section *debug_abbrev_section;
224 static GTY(()) section *debug_aranges_section;
225 static GTY(()) section *debug_macinfo_section;
226 static GTY(()) section *debug_line_section;
227 static GTY(()) section *debug_loc_section;
228 static GTY(()) section *debug_pubnames_section;
229 static GTY(()) section *debug_pubtypes_section;
230 static GTY(()) section *debug_dcall_section;
231 static GTY(()) section *debug_vcall_section;
232 static GTY(()) section *debug_str_section;
233 static GTY(()) section *debug_ranges_section;
234 static GTY(()) section *debug_frame_section;
236 /* Personality decl of current unit. Used only when assembler does not support
238 static GTY(()) rtx current_unit_personality;
240 /* How to start an assembler comment. */
241 #ifndef ASM_COMMENT_START
242 #define ASM_COMMENT_START ";#"
245 typedef struct dw_cfi_struct *dw_cfi_ref;
246 typedef struct dw_fde_struct *dw_fde_ref;
247 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
249 /* Call frames are described using a sequence of Call Frame
250 Information instructions. The register number, offset
251 and address fields are provided as possible operands;
252 their use is selected by the opcode field. */
254 enum dw_cfi_oprnd_type {
256 dw_cfi_oprnd_reg_num,
262 typedef union GTY(()) dw_cfi_oprnd_struct {
263 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
264 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
265 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
266 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
270 typedef struct GTY(()) dw_cfi_struct {
271 dw_cfi_ref dw_cfi_next;
272 enum dwarf_call_frame_info dw_cfi_opc;
273 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
275 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
280 /* This is how we define the location of the CFA. We use to handle it
281 as REG + OFFSET all the time, but now it can be more complex.
282 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
283 Instead of passing around REG and OFFSET, we pass a copy
284 of this structure. */
285 typedef struct cfa_loc {
286 HOST_WIDE_INT offset;
287 HOST_WIDE_INT base_offset;
289 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
290 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
293 /* All call frame descriptions (FDE's) in the GCC generated DWARF
294 refer to a single Common Information Entry (CIE), defined at
295 the beginning of the .debug_frame section. This use of a single
296 CIE obviates the need to keep track of multiple CIE's
297 in the DWARF generation routines below. */
299 typedef struct GTY(()) dw_fde_struct {
301 const char *dw_fde_begin;
302 const char *dw_fde_current_label;
303 const char *dw_fde_end;
304 const char *dw_fde_vms_end_prologue;
305 const char *dw_fde_vms_begin_epilogue;
306 const char *dw_fde_second_begin;
307 const char *dw_fde_second_end;
308 dw_cfi_ref dw_fde_cfi;
309 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
310 HOST_WIDE_INT stack_realignment;
311 unsigned funcdef_number;
312 /* Dynamic realign argument pointer register. */
313 unsigned int drap_reg;
314 /* Virtual dynamic realign argument pointer register. */
315 unsigned int vdrap_reg;
316 /* These 3 flags are copied from rtl_data in function.h. */
317 unsigned all_throwers_are_sibcalls : 1;
318 unsigned uses_eh_lsda : 1;
319 unsigned nothrow : 1;
320 /* Whether we did stack realign in this call frame. */
321 unsigned stack_realign : 1;
322 /* Whether dynamic realign argument pointer register has been saved. */
323 unsigned drap_reg_saved: 1;
324 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
325 unsigned in_std_section : 1;
326 /* True iff dw_fde_second_begin label is in text_section or
327 cold_text_section. */
328 unsigned second_in_std_section : 1;
332 /* Maximum size (in bytes) of an artificially generated label. */
333 #define MAX_ARTIFICIAL_LABEL_BYTES 30
335 /* The size of addresses as they appear in the Dwarf 2 data.
336 Some architectures use word addresses to refer to code locations,
337 but Dwarf 2 info always uses byte addresses. On such machines,
338 Dwarf 2 addresses need to be larger than the architecture's
340 #ifndef DWARF2_ADDR_SIZE
341 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
344 /* The size in bytes of a DWARF field indicating an offset or length
345 relative to a debug info section, specified to be 4 bytes in the
346 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
349 #ifndef DWARF_OFFSET_SIZE
350 #define DWARF_OFFSET_SIZE 4
353 /* The size in bytes of a DWARF 4 type signature. */
355 #ifndef DWARF_TYPE_SIGNATURE_SIZE
356 #define DWARF_TYPE_SIGNATURE_SIZE 8
359 /* According to the (draft) DWARF 3 specification, the initial length
360 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
361 bytes are 0xffffffff, followed by the length stored in the next 8
364 However, the SGI/MIPS ABI uses an initial length which is equal to
365 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
367 #ifndef DWARF_INITIAL_LENGTH_SIZE
368 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
371 /* Round SIZE up to the nearest BOUNDARY. */
372 #define DWARF_ROUND(SIZE,BOUNDARY) \
373 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
375 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
376 #ifndef DWARF_CIE_DATA_ALIGNMENT
377 #ifdef STACK_GROWS_DOWNWARD
378 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
380 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
384 /* CIE identifier. */
385 #if HOST_BITS_PER_WIDE_INT >= 64
386 #define DWARF_CIE_ID \
387 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
389 #define DWARF_CIE_ID DW_CIE_ID
392 /* A pointer to the base of a table that contains frame description
393 information for each routine. */
394 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
396 /* Number of elements currently allocated for fde_table. */
397 static GTY(()) unsigned fde_table_allocated;
399 /* Number of elements in fde_table currently in use. */
400 static GTY(()) unsigned fde_table_in_use;
402 /* Size (in elements) of increments by which we may expand the
404 #define FDE_TABLE_INCREMENT 256
406 /* Get the current fde_table entry we should use. */
408 static inline dw_fde_ref
411 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
414 /* A list of call frame insns for the CIE. */
415 static GTY(()) dw_cfi_ref cie_cfi_head;
417 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
418 attribute that accelerates the lookup of the FDE associated
419 with the subprogram. This variable holds the table index of the FDE
420 associated with the current function (body) definition. */
421 static unsigned current_funcdef_fde;
423 struct GTY(()) indirect_string_node {
425 unsigned int refcount;
426 enum dwarf_form form;
430 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
432 /* True if the compilation unit has location entries that reference
434 static GTY(()) bool debug_str_hash_forced = false;
436 static GTY(()) int dw2_string_counter;
437 static GTY(()) unsigned long dwarf2out_cfi_label_num;
439 /* True if the compilation unit places functions in more than one section. */
440 static GTY(()) bool have_multiple_function_sections = false;
442 /* Whether the default text and cold text sections have been used at all. */
444 static GTY(()) bool text_section_used = false;
445 static GTY(()) bool cold_text_section_used = false;
447 /* The default cold text section. */
448 static GTY(()) section *cold_text_section;
450 /* Forward declarations for functions defined in this file. */
452 static char *stripattributes (const char *);
453 static const char *dwarf_cfi_name (unsigned);
454 static dw_cfi_ref new_cfi (void);
455 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
456 static void add_fde_cfi (const char *, dw_cfi_ref);
457 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
458 static void lookup_cfa (dw_cfa_location *);
459 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
460 static void initial_return_save (rtx);
461 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
463 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
464 static void output_cfi_directive (dw_cfi_ref);
465 static void output_call_frame_info (int);
466 static void dwarf2out_note_section_used (void);
467 static bool clobbers_queued_reg_save (const_rtx);
468 static void dwarf2out_frame_debug_expr (rtx, const char *);
470 /* Support for complex CFA locations. */
471 static void output_cfa_loc (dw_cfi_ref, int);
472 static void output_cfa_loc_raw (dw_cfi_ref);
473 static void get_cfa_from_loc_descr (dw_cfa_location *,
474 struct dw_loc_descr_struct *);
475 static struct dw_loc_descr_struct *build_cfa_loc
476 (dw_cfa_location *, HOST_WIDE_INT);
477 static struct dw_loc_descr_struct *build_cfa_aligned_loc
478 (HOST_WIDE_INT, HOST_WIDE_INT);
479 static void def_cfa_1 (const char *, dw_cfa_location *);
480 static struct dw_loc_descr_struct *mem_loc_descriptor
481 (rtx, enum machine_mode mode, enum var_init_status);
483 /* How to start an assembler comment. */
484 #ifndef ASM_COMMENT_START
485 #define ASM_COMMENT_START ";#"
488 /* Data and reference forms for relocatable data. */
489 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
490 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
492 #ifndef DEBUG_FRAME_SECTION
493 #define DEBUG_FRAME_SECTION ".debug_frame"
496 #ifndef FUNC_BEGIN_LABEL
497 #define FUNC_BEGIN_LABEL "LFB"
500 #ifndef FUNC_END_LABEL
501 #define FUNC_END_LABEL "LFE"
504 #ifndef PROLOGUE_END_LABEL
505 #define PROLOGUE_END_LABEL "LPE"
508 #ifndef EPILOGUE_BEGIN_LABEL
509 #define EPILOGUE_BEGIN_LABEL "LEB"
512 #ifndef FRAME_BEGIN_LABEL
513 #define FRAME_BEGIN_LABEL "Lframe"
515 #define CIE_AFTER_SIZE_LABEL "LSCIE"
516 #define CIE_END_LABEL "LECIE"
517 #define FDE_LABEL "LSFDE"
518 #define FDE_AFTER_SIZE_LABEL "LASFDE"
519 #define FDE_END_LABEL "LEFDE"
520 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
521 #define LINE_NUMBER_END_LABEL "LELT"
522 #define LN_PROLOG_AS_LABEL "LASLTP"
523 #define LN_PROLOG_END_LABEL "LELTP"
524 #define DIE_LABEL_PREFIX "DW"
526 /* The DWARF 2 CFA column which tracks the return address. Normally this
527 is the column for PC, or the first column after all of the hard
529 #ifndef DWARF_FRAME_RETURN_COLUMN
531 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
533 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
537 /* The mapping from gcc register number to DWARF 2 CFA column number. By
538 default, we just provide columns for all registers. */
539 #ifndef DWARF_FRAME_REGNUM
540 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
543 /* Match the base name of a file to the base name of a compilation unit. */
546 matches_main_base (const char *path)
548 /* Cache the last query. */
549 static const char *last_path = NULL;
550 static int last_match = 0;
551 if (path != last_path)
554 int length = base_of_path (path, &base);
556 last_match = (length == main_input_baselength
557 && memcmp (base, main_input_basename, length) == 0);
562 #ifdef DEBUG_DEBUG_STRUCT
565 dump_struct_debug (tree type, enum debug_info_usage usage,
566 enum debug_struct_file criterion, int generic,
567 int matches, int result)
569 /* Find the type name. */
570 tree type_decl = TYPE_STUB_DECL (type);
572 const char *name = 0;
573 if (TREE_CODE (t) == TYPE_DECL)
576 name = IDENTIFIER_POINTER (t);
578 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
580 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
581 matches ? "bas" : "hdr",
582 generic ? "gen" : "ord",
583 usage == DINFO_USAGE_DFN ? ";" :
584 usage == DINFO_USAGE_DIR_USE ? "." : "*",
586 (void*) type_decl, name);
589 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
590 dump_struct_debug (type, usage, criterion, generic, matches, result)
594 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
600 should_emit_struct_debug (tree type, enum debug_info_usage usage)
602 enum debug_struct_file criterion;
604 bool generic = lang_hooks.types.generic_p (type);
607 criterion = debug_struct_generic[usage];
609 criterion = debug_struct_ordinary[usage];
611 if (criterion == DINFO_STRUCT_FILE_NONE)
612 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
613 if (criterion == DINFO_STRUCT_FILE_ANY)
614 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
616 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
618 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
619 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
621 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
622 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
623 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
626 /* Hook used by __throw. */
629 expand_builtin_dwarf_sp_column (void)
631 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
632 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
635 /* Return a pointer to a copy of the section string name S with all
636 attributes stripped off, and an asterisk prepended (for assemble_name). */
639 stripattributes (const char *s)
641 char *stripped = XNEWVEC (char, strlen (s) + 2);
646 while (*s && *s != ',')
653 /* MEM is a memory reference for the register size table, each element of
654 which has mode MODE. Initialize column C as a return address column. */
657 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
659 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
660 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
661 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
664 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
666 static inline HOST_WIDE_INT
667 div_data_align (HOST_WIDE_INT off)
669 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
670 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
674 /* Return true if we need a signed version of a given opcode
675 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
678 need_data_align_sf_opcode (HOST_WIDE_INT off)
680 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
683 /* Generate code to initialize the register size table. */
686 expand_builtin_init_dwarf_reg_sizes (tree address)
689 enum machine_mode mode = TYPE_MODE (char_type_node);
690 rtx addr = expand_normal (address);
691 rtx mem = gen_rtx_MEM (BLKmode, addr);
692 bool wrote_return_column = false;
694 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
696 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
698 if (rnum < DWARF_FRAME_REGISTERS)
700 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
701 enum machine_mode save_mode = reg_raw_mode[i];
704 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
705 save_mode = choose_hard_reg_mode (i, 1, true);
706 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
708 if (save_mode == VOIDmode)
710 wrote_return_column = true;
712 size = GET_MODE_SIZE (save_mode);
716 emit_move_insn (adjust_address (mem, mode, offset),
717 gen_int_mode (size, mode));
721 if (!wrote_return_column)
722 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
724 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
725 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
728 targetm.init_dwarf_reg_sizes_extra (address);
731 /* Convert a DWARF call frame info. operation to its string name */
734 dwarf_cfi_name (unsigned int cfi_opc)
738 case DW_CFA_advance_loc:
739 return "DW_CFA_advance_loc";
741 return "DW_CFA_offset";
743 return "DW_CFA_restore";
747 return "DW_CFA_set_loc";
748 case DW_CFA_advance_loc1:
749 return "DW_CFA_advance_loc1";
750 case DW_CFA_advance_loc2:
751 return "DW_CFA_advance_loc2";
752 case DW_CFA_advance_loc4:
753 return "DW_CFA_advance_loc4";
754 case DW_CFA_offset_extended:
755 return "DW_CFA_offset_extended";
756 case DW_CFA_restore_extended:
757 return "DW_CFA_restore_extended";
758 case DW_CFA_undefined:
759 return "DW_CFA_undefined";
760 case DW_CFA_same_value:
761 return "DW_CFA_same_value";
762 case DW_CFA_register:
763 return "DW_CFA_register";
764 case DW_CFA_remember_state:
765 return "DW_CFA_remember_state";
766 case DW_CFA_restore_state:
767 return "DW_CFA_restore_state";
769 return "DW_CFA_def_cfa";
770 case DW_CFA_def_cfa_register:
771 return "DW_CFA_def_cfa_register";
772 case DW_CFA_def_cfa_offset:
773 return "DW_CFA_def_cfa_offset";
776 case DW_CFA_def_cfa_expression:
777 return "DW_CFA_def_cfa_expression";
778 case DW_CFA_expression:
779 return "DW_CFA_expression";
780 case DW_CFA_offset_extended_sf:
781 return "DW_CFA_offset_extended_sf";
782 case DW_CFA_def_cfa_sf:
783 return "DW_CFA_def_cfa_sf";
784 case DW_CFA_def_cfa_offset_sf:
785 return "DW_CFA_def_cfa_offset_sf";
787 /* SGI/MIPS specific */
788 case DW_CFA_MIPS_advance_loc8:
789 return "DW_CFA_MIPS_advance_loc8";
792 case DW_CFA_GNU_window_save:
793 return "DW_CFA_GNU_window_save";
794 case DW_CFA_GNU_args_size:
795 return "DW_CFA_GNU_args_size";
796 case DW_CFA_GNU_negative_offset_extended:
797 return "DW_CFA_GNU_negative_offset_extended";
800 return "DW_CFA_<unknown>";
804 /* Return a pointer to a newly allocated Call Frame Instruction. */
806 static inline dw_cfi_ref
809 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
811 cfi->dw_cfi_next = NULL;
812 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
813 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
818 /* Add a Call Frame Instruction to list of instructions. */
821 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
824 dw_fde_ref fde = current_fde ();
826 /* When DRAP is used, CFA is defined with an expression. Redefine
827 CFA may lead to a different CFA value. */
828 /* ??? Of course, this heuristic fails when we're annotating epilogues,
829 because of course we'll always want to redefine the CFA back to the
830 stack pointer on the way out. Where should we move this check? */
831 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
832 switch (cfi->dw_cfi_opc)
834 case DW_CFA_def_cfa_register:
835 case DW_CFA_def_cfa_offset:
836 case DW_CFA_def_cfa_offset_sf:
838 case DW_CFA_def_cfa_sf:
845 /* Find the end of the chain. */
846 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
852 /* Generate a new label for the CFI info to refer to. FORCE is true
853 if a label needs to be output even when using .cfi_* directives. */
856 dwarf2out_cfi_label (bool force)
858 static char label[20];
860 if (!force && dwarf2out_do_cfi_asm ())
862 /* In this case, we will be emitting the asm directive instead of
863 the label, so just return a placeholder to keep the rest of the
865 strcpy (label, "<do not output>");
869 int num = dwarf2out_cfi_label_num++;
870 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
871 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
877 /* True if remember_state should be emitted before following CFI directive. */
878 static bool emit_cfa_remember;
880 /* True if any CFI directives were emitted at the current insn. */
881 static bool any_cfis_emitted;
883 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
884 or to the CIE if LABEL is NULL. */
887 add_fde_cfi (const char *label, dw_cfi_ref cfi)
889 dw_cfi_ref *list_head;
891 if (emit_cfa_remember)
893 dw_cfi_ref cfi_remember;
895 /* Emit the state save. */
896 emit_cfa_remember = false;
897 cfi_remember = new_cfi ();
898 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
899 add_fde_cfi (label, cfi_remember);
902 list_head = &cie_cfi_head;
904 if (dwarf2out_do_cfi_asm ())
908 dw_fde_ref fde = current_fde ();
910 gcc_assert (fde != NULL);
912 /* We still have to add the cfi to the list so that lookup_cfa
913 works later on. When -g2 and above we even need to force
914 emitting of CFI labels and add to list a DW_CFA_set_loc for
915 convert_cfa_to_fb_loc_list purposes. If we're generating
916 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
917 convert_cfa_to_fb_loc_list. */
918 if (dwarf_version == 2
919 && debug_info_level > DINFO_LEVEL_TERSE
920 && (write_symbols == DWARF2_DEBUG
921 || write_symbols == VMS_AND_DWARF2_DEBUG))
923 switch (cfi->dw_cfi_opc)
925 case DW_CFA_def_cfa_offset:
926 case DW_CFA_def_cfa_offset_sf:
927 case DW_CFA_def_cfa_register:
929 case DW_CFA_def_cfa_sf:
930 case DW_CFA_def_cfa_expression:
931 case DW_CFA_restore_state:
932 if (*label == 0 || strcmp (label, "<do not output>") == 0)
933 label = dwarf2out_cfi_label (true);
935 if (fde->dw_fde_current_label == NULL
936 || strcmp (label, fde->dw_fde_current_label) != 0)
940 label = xstrdup (label);
942 /* Set the location counter to the new label. */
944 /* It doesn't metter whether DW_CFA_set_loc
945 or DW_CFA_advance_loc4 is added here, those aren't
946 emitted into assembly, only looked up by
947 convert_cfa_to_fb_loc_list. */
948 xcfi->dw_cfi_opc = DW_CFA_set_loc;
949 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
950 add_cfi (&fde->dw_fde_cfi, xcfi);
951 fde->dw_fde_current_label = label;
959 output_cfi_directive (cfi);
961 list_head = &fde->dw_fde_cfi;
962 any_cfis_emitted = true;
964 /* ??? If this is a CFI for the CIE, we don't emit. This
965 assumes that the standard CIE contents that the assembler
966 uses matches the standard CIE contents that the compiler
967 uses. This is probably a bad assumption. I'm not quite
968 sure how to address this for now. */
972 dw_fde_ref fde = current_fde ();
974 gcc_assert (fde != NULL);
977 label = dwarf2out_cfi_label (false);
979 if (fde->dw_fde_current_label == NULL
980 || strcmp (label, fde->dw_fde_current_label) != 0)
984 label = xstrdup (label);
986 /* Set the location counter to the new label. */
988 /* If we have a current label, advance from there, otherwise
989 set the location directly using set_loc. */
990 xcfi->dw_cfi_opc = fde->dw_fde_current_label
991 ? DW_CFA_advance_loc4
993 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
994 add_cfi (&fde->dw_fde_cfi, xcfi);
996 fde->dw_fde_current_label = label;
999 list_head = &fde->dw_fde_cfi;
1000 any_cfis_emitted = true;
1003 add_cfi (list_head, cfi);
1006 /* Subroutine of lookup_cfa. */
1009 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
1011 switch (cfi->dw_cfi_opc)
1013 case DW_CFA_def_cfa_offset:
1014 case DW_CFA_def_cfa_offset_sf:
1015 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
1017 case DW_CFA_def_cfa_register:
1018 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1020 case DW_CFA_def_cfa:
1021 case DW_CFA_def_cfa_sf:
1022 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1023 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
1025 case DW_CFA_def_cfa_expression:
1026 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
1029 case DW_CFA_remember_state:
1030 gcc_assert (!remember->in_use);
1032 remember->in_use = 1;
1034 case DW_CFA_restore_state:
1035 gcc_assert (remember->in_use);
1037 remember->in_use = 0;
1045 /* Find the previous value for the CFA. */
1048 lookup_cfa (dw_cfa_location *loc)
1052 dw_cfa_location remember;
1054 memset (loc, 0, sizeof (*loc));
1055 loc->reg = INVALID_REGNUM;
1058 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
1059 lookup_cfa_1 (cfi, loc, &remember);
1061 fde = current_fde ();
1063 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
1064 lookup_cfa_1 (cfi, loc, &remember);
1067 /* The current rule for calculating the DWARF2 canonical frame address. */
1068 static dw_cfa_location cfa;
1070 /* The register used for saving registers to the stack, and its offset
1072 static dw_cfa_location cfa_store;
1074 /* The current save location around an epilogue. */
1075 static dw_cfa_location cfa_remember;
1077 /* The running total of the size of arguments pushed onto the stack. */
1078 static HOST_WIDE_INT args_size;
1080 /* The last args_size we actually output. */
1081 static HOST_WIDE_INT old_args_size;
1083 /* Entry point to update the canonical frame address (CFA).
1084 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1085 calculated from REG+OFFSET. */
1088 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1090 dw_cfa_location loc;
1092 loc.base_offset = 0;
1094 loc.offset = offset;
1095 def_cfa_1 (label, &loc);
1098 /* Determine if two dw_cfa_location structures define the same data. */
1101 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1103 return (loc1->reg == loc2->reg
1104 && loc1->offset == loc2->offset
1105 && loc1->indirect == loc2->indirect
1106 && (loc1->indirect == 0
1107 || loc1->base_offset == loc2->base_offset));
1110 /* This routine does the actual work. The CFA is now calculated from
1111 the dw_cfa_location structure. */
1114 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1117 dw_cfa_location old_cfa, loc;
1122 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1123 cfa_store.offset = loc.offset;
1125 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1126 lookup_cfa (&old_cfa);
1128 /* If nothing changed, no need to issue any call frame instructions. */
1129 if (cfa_equal_p (&loc, &old_cfa))
1134 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1136 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1137 the CFA register did not change but the offset did. The data
1138 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1139 in the assembler via the .cfi_def_cfa_offset directive. */
1141 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1143 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1144 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1147 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1148 else if (loc.offset == old_cfa.offset
1149 && old_cfa.reg != INVALID_REGNUM
1151 && !old_cfa.indirect)
1153 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1154 indicating the CFA register has changed to <register> but the
1155 offset has not changed. */
1156 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1157 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1161 else if (loc.indirect == 0)
1163 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1164 indicating the CFA register has changed to <register> with
1165 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1166 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1169 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1171 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1172 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1173 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1177 /* Construct a DW_CFA_def_cfa_expression instruction to
1178 calculate the CFA using a full location expression since no
1179 register-offset pair is available. */
1180 struct dw_loc_descr_struct *loc_list;
1182 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1183 loc_list = build_cfa_loc (&loc, 0);
1184 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1187 add_fde_cfi (label, cfi);
1190 /* Add the CFI for saving a register. REG is the CFA column number.
1191 LABEL is passed to add_fde_cfi.
1192 If SREG is -1, the register is saved at OFFSET from the CFA;
1193 otherwise it is saved in SREG. */
1196 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1198 dw_cfi_ref cfi = new_cfi ();
1199 dw_fde_ref fde = current_fde ();
1201 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1203 /* When stack is aligned, store REG using DW_CFA_expression with
1206 && fde->stack_realign
1207 && sreg == INVALID_REGNUM)
1209 cfi->dw_cfi_opc = DW_CFA_expression;
1210 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1211 cfi->dw_cfi_oprnd2.dw_cfi_loc
1212 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1214 else if (sreg == INVALID_REGNUM)
1216 if (need_data_align_sf_opcode (offset))
1217 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1218 else if (reg & ~0x3f)
1219 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1221 cfi->dw_cfi_opc = DW_CFA_offset;
1222 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1224 else if (sreg == reg)
1225 cfi->dw_cfi_opc = DW_CFA_same_value;
1228 cfi->dw_cfi_opc = DW_CFA_register;
1229 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1232 add_fde_cfi (label, cfi);
1235 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1236 This CFI tells the unwinder that it needs to restore the window registers
1237 from the previous frame's window save area.
1239 ??? Perhaps we should note in the CIE where windows are saved (instead of
1240 assuming 0(cfa)) and what registers are in the window. */
1243 dwarf2out_window_save (const char *label)
1245 dw_cfi_ref cfi = new_cfi ();
1247 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1248 add_fde_cfi (label, cfi);
1251 /* Entry point for saving a register to the stack. REG is the GCC register
1252 number. LABEL and OFFSET are passed to reg_save. */
1255 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1257 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1260 /* Entry point for saving the return address in the stack.
1261 LABEL and OFFSET are passed to reg_save. */
1264 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1266 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1269 /* Entry point for saving the return address in a register.
1270 LABEL and SREG are passed to reg_save. */
1273 dwarf2out_return_reg (const char *label, unsigned int sreg)
1275 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1278 /* Record the initial position of the return address. RTL is
1279 INCOMING_RETURN_ADDR_RTX. */
1282 initial_return_save (rtx rtl)
1284 unsigned int reg = INVALID_REGNUM;
1285 HOST_WIDE_INT offset = 0;
1287 switch (GET_CODE (rtl))
1290 /* RA is in a register. */
1291 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1295 /* RA is on the stack. */
1296 rtl = XEXP (rtl, 0);
1297 switch (GET_CODE (rtl))
1300 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1305 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1306 offset = INTVAL (XEXP (rtl, 1));
1310 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1311 offset = -INTVAL (XEXP (rtl, 1));
1321 /* The return address is at some offset from any value we can
1322 actually load. For instance, on the SPARC it is in %i7+8. Just
1323 ignore the offset for now; it doesn't matter for unwinding frames. */
1324 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1325 initial_return_save (XEXP (rtl, 0));
1332 if (reg != DWARF_FRAME_RETURN_COLUMN)
1333 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1336 /* Given a SET, calculate the amount of stack adjustment it
1339 static HOST_WIDE_INT
1340 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1341 HOST_WIDE_INT cur_offset)
1343 const_rtx src = SET_SRC (pattern);
1344 const_rtx dest = SET_DEST (pattern);
1345 HOST_WIDE_INT offset = 0;
1348 if (dest == stack_pointer_rtx)
1350 code = GET_CODE (src);
1352 /* Assume (set (reg sp) (reg whatever)) sets args_size
1354 if (code == REG && src != stack_pointer_rtx)
1356 offset = -cur_args_size;
1357 #ifndef STACK_GROWS_DOWNWARD
1360 return offset - cur_offset;
1363 if (! (code == PLUS || code == MINUS)
1364 || XEXP (src, 0) != stack_pointer_rtx
1365 || !CONST_INT_P (XEXP (src, 1)))
1368 /* (set (reg sp) (plus (reg sp) (const_int))) */
1369 offset = INTVAL (XEXP (src, 1));
1375 if (MEM_P (src) && !MEM_P (dest))
1379 /* (set (mem (pre_dec (reg sp))) (foo)) */
1380 src = XEXP (dest, 0);
1381 code = GET_CODE (src);
1387 if (XEXP (src, 0) == stack_pointer_rtx)
1389 rtx val = XEXP (XEXP (src, 1), 1);
1390 /* We handle only adjustments by constant amount. */
1391 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1392 && CONST_INT_P (val));
1393 offset = -INTVAL (val);
1400 if (XEXP (src, 0) == stack_pointer_rtx)
1402 offset = GET_MODE_SIZE (GET_MODE (dest));
1409 if (XEXP (src, 0) == stack_pointer_rtx)
1411 offset = -GET_MODE_SIZE (GET_MODE (dest));
1426 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1427 indexed by INSN_UID. */
1429 static HOST_WIDE_INT *barrier_args_size;
1431 /* Helper function for compute_barrier_args_size. Handle one insn. */
1433 static HOST_WIDE_INT
1434 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1435 VEC (rtx, heap) **next)
1437 HOST_WIDE_INT offset = 0;
1440 if (! RTX_FRAME_RELATED_P (insn))
1442 if (prologue_epilogue_contains (insn))
1444 else if (GET_CODE (PATTERN (insn)) == SET)
1445 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1446 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1447 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1449 /* There may be stack adjustments inside compound insns. Search
1451 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1452 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1453 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1454 cur_args_size, offset);
1459 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1463 expr = XEXP (expr, 0);
1464 if (GET_CODE (expr) == PARALLEL
1465 || GET_CODE (expr) == SEQUENCE)
1466 for (i = 1; i < XVECLEN (expr, 0); i++)
1468 rtx elem = XVECEXP (expr, 0, i);
1470 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1471 offset += stack_adjust_offset (elem, cur_args_size, offset);
1476 #ifndef STACK_GROWS_DOWNWARD
1480 cur_args_size += offset;
1481 if (cur_args_size < 0)
1486 rtx dest = JUMP_LABEL (insn);
1490 if (barrier_args_size [INSN_UID (dest)] < 0)
1492 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1493 VEC_safe_push (rtx, heap, *next, dest);
1498 return cur_args_size;
1501 /* Walk the whole function and compute args_size on BARRIERs. */
1504 compute_barrier_args_size (void)
1506 int max_uid = get_max_uid (), i;
1508 VEC (rtx, heap) *worklist, *next, *tmp;
1510 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1511 for (i = 0; i < max_uid; i++)
1512 barrier_args_size[i] = -1;
1514 worklist = VEC_alloc (rtx, heap, 20);
1515 next = VEC_alloc (rtx, heap, 20);
1516 insn = get_insns ();
1517 barrier_args_size[INSN_UID (insn)] = 0;
1518 VEC_quick_push (rtx, worklist, insn);
1521 while (!VEC_empty (rtx, worklist))
1523 rtx prev, body, first_insn;
1524 HOST_WIDE_INT cur_args_size;
1526 first_insn = insn = VEC_pop (rtx, worklist);
1527 cur_args_size = barrier_args_size[INSN_UID (insn)];
1528 prev = prev_nonnote_insn (insn);
1529 if (prev && BARRIER_P (prev))
1530 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1532 for (; insn; insn = NEXT_INSN (insn))
1534 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1536 if (BARRIER_P (insn))
1541 if (insn == first_insn)
1543 else if (barrier_args_size[INSN_UID (insn)] < 0)
1545 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1550 /* The insns starting with this label have been
1551 already scanned or are in the worklist. */
1556 body = PATTERN (insn);
1557 if (GET_CODE (body) == SEQUENCE)
1559 HOST_WIDE_INT dest_args_size = cur_args_size;
1560 for (i = 1; i < XVECLEN (body, 0); i++)
1561 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1562 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1564 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1565 dest_args_size, &next);
1568 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1569 cur_args_size, &next);
1571 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1572 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1573 dest_args_size, &next);
1576 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1577 cur_args_size, &next);
1581 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1585 if (VEC_empty (rtx, next))
1588 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1592 VEC_truncate (rtx, next, 0);
1595 VEC_free (rtx, heap, worklist);
1596 VEC_free (rtx, heap, next);
1599 /* Add a CFI to update the running total of the size of arguments
1600 pushed onto the stack. */
1603 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1607 if (size == old_args_size)
1610 old_args_size = size;
1613 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1614 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1615 add_fde_cfi (label, cfi);
1618 /* Record a stack adjustment of OFFSET bytes. */
1621 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1623 if (cfa.reg == STACK_POINTER_REGNUM)
1624 cfa.offset += offset;
1626 if (cfa_store.reg == STACK_POINTER_REGNUM)
1627 cfa_store.offset += offset;
1629 if (ACCUMULATE_OUTGOING_ARGS)
1632 #ifndef STACK_GROWS_DOWNWARD
1636 args_size += offset;
1640 def_cfa_1 (label, &cfa);
1641 if (flag_asynchronous_unwind_tables)
1642 dwarf2out_args_size (label, args_size);
1645 /* Check INSN to see if it looks like a push or a stack adjustment, and
1646 make a note of it if it does. EH uses this information to find out
1647 how much extra space it needs to pop off the stack. */
1650 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1652 HOST_WIDE_INT offset;
1656 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1657 with this function. Proper support would require all frame-related
1658 insns to be marked, and to be able to handle saving state around
1659 epilogues textually in the middle of the function. */
1660 if (prologue_epilogue_contains (insn))
1663 /* If INSN is an instruction from target of an annulled branch, the
1664 effects are for the target only and so current argument size
1665 shouldn't change at all. */
1667 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1668 && INSN_FROM_TARGET_P (insn))
1671 /* If only calls can throw, and we have a frame pointer,
1672 save up adjustments until we see the CALL_INSN. */
1673 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1675 if (CALL_P (insn) && !after_p)
1677 /* Extract the size of the args from the CALL rtx itself. */
1678 insn = PATTERN (insn);
1679 if (GET_CODE (insn) == PARALLEL)
1680 insn = XVECEXP (insn, 0, 0);
1681 if (GET_CODE (insn) == SET)
1682 insn = SET_SRC (insn);
1683 gcc_assert (GET_CODE (insn) == CALL);
1684 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1689 if (CALL_P (insn) && !after_p)
1691 if (!flag_asynchronous_unwind_tables)
1692 dwarf2out_args_size ("", args_size);
1695 else if (BARRIER_P (insn))
1697 /* Don't call compute_barrier_args_size () if the only
1698 BARRIER is at the end of function. */
1699 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1700 compute_barrier_args_size ();
1701 if (barrier_args_size == NULL)
1705 offset = barrier_args_size[INSN_UID (insn)];
1710 offset -= args_size;
1711 #ifndef STACK_GROWS_DOWNWARD
1715 else if (GET_CODE (PATTERN (insn)) == SET)
1716 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1717 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1718 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1720 /* There may be stack adjustments inside compound insns. Search
1722 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1723 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1724 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1733 label = dwarf2out_cfi_label (false);
1734 dwarf2out_stack_adjust (offset, label);
1737 /* We delay emitting a register save until either (a) we reach the end
1738 of the prologue or (b) the register is clobbered. This clusters
1739 register saves so that there are fewer pc advances. */
1741 struct GTY(()) queued_reg_save {
1742 struct queued_reg_save *next;
1744 HOST_WIDE_INT cfa_offset;
1748 static GTY(()) struct queued_reg_save *queued_reg_saves;
1750 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1751 struct GTY(()) reg_saved_in_data {
1756 /* A list of registers saved in other registers.
1757 The list intentionally has a small maximum capacity of 4; if your
1758 port needs more than that, you might consider implementing a
1759 more efficient data structure. */
1760 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1761 static GTY(()) size_t num_regs_saved_in_regs;
1763 static const char *last_reg_save_label;
1765 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1766 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1769 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1771 struct queued_reg_save *q;
1773 /* Duplicates waste space, but it's also necessary to remove them
1774 for correctness, since the queue gets output in reverse
1776 for (q = queued_reg_saves; q != NULL; q = q->next)
1777 if (REGNO (q->reg) == REGNO (reg))
1782 q = ggc_alloc_queued_reg_save ();
1783 q->next = queued_reg_saves;
1784 queued_reg_saves = q;
1788 q->cfa_offset = offset;
1789 q->saved_reg = sreg;
1791 last_reg_save_label = label;
1794 /* Output all the entries in QUEUED_REG_SAVES. */
1797 dwarf2out_flush_queued_reg_saves (void)
1799 struct queued_reg_save *q;
1801 for (q = queued_reg_saves; q; q = q->next)
1804 unsigned int reg, sreg;
1806 for (i = 0; i < num_regs_saved_in_regs; i++)
1807 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1809 if (q->saved_reg && i == num_regs_saved_in_regs)
1811 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1812 num_regs_saved_in_regs++;
1814 if (i != num_regs_saved_in_regs)
1816 regs_saved_in_regs[i].orig_reg = q->reg;
1817 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1820 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1822 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1824 sreg = INVALID_REGNUM;
1825 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1828 queued_reg_saves = NULL;
1829 last_reg_save_label = NULL;
1832 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1833 location for? Or, does it clobber a register which we've previously
1834 said that some other register is saved in, and for which we now
1835 have a new location for? */
1838 clobbers_queued_reg_save (const_rtx insn)
1840 struct queued_reg_save *q;
1842 for (q = queued_reg_saves; q; q = q->next)
1845 if (modified_in_p (q->reg, insn))
1847 for (i = 0; i < num_regs_saved_in_regs; i++)
1848 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1849 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1856 /* Entry point for saving the first register into the second. */
1859 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1862 unsigned int regno, sregno;
1864 for (i = 0; i < num_regs_saved_in_regs; i++)
1865 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1867 if (i == num_regs_saved_in_regs)
1869 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1870 num_regs_saved_in_regs++;
1872 regs_saved_in_regs[i].orig_reg = reg;
1873 regs_saved_in_regs[i].saved_in_reg = sreg;
1875 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1876 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1877 reg_save (label, regno, sregno, 0);
1880 /* What register, if any, is currently saved in REG? */
1883 reg_saved_in (rtx reg)
1885 unsigned int regn = REGNO (reg);
1887 struct queued_reg_save *q;
1889 for (q = queued_reg_saves; q; q = q->next)
1890 if (q->saved_reg && regn == REGNO (q->saved_reg))
1893 for (i = 0; i < num_regs_saved_in_regs; i++)
1894 if (regs_saved_in_regs[i].saved_in_reg
1895 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1896 return regs_saved_in_regs[i].orig_reg;
1902 /* A temporary register holding an integral value used in adjusting SP
1903 or setting up the store_reg. The "offset" field holds the integer
1904 value, not an offset. */
1905 static dw_cfa_location cfa_temp;
1907 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1910 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1912 memset (&cfa, 0, sizeof (cfa));
1914 switch (GET_CODE (pat))
1917 cfa.reg = REGNO (XEXP (pat, 0));
1918 cfa.offset = INTVAL (XEXP (pat, 1));
1922 cfa.reg = REGNO (pat);
1927 pat = XEXP (pat, 0);
1928 if (GET_CODE (pat) == PLUS)
1930 cfa.base_offset = INTVAL (XEXP (pat, 1));
1931 pat = XEXP (pat, 0);
1933 cfa.reg = REGNO (pat);
1937 /* Recurse and define an expression. */
1941 def_cfa_1 (label, &cfa);
1944 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1947 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1951 gcc_assert (GET_CODE (pat) == SET);
1952 dest = XEXP (pat, 0);
1953 src = XEXP (pat, 1);
1955 switch (GET_CODE (src))
1958 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1959 cfa.offset -= INTVAL (XEXP (src, 1));
1969 cfa.reg = REGNO (dest);
1970 gcc_assert (cfa.indirect == 0);
1972 def_cfa_1 (label, &cfa);
1975 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1978 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1980 HOST_WIDE_INT offset;
1981 rtx src, addr, span;
1983 src = XEXP (set, 1);
1984 addr = XEXP (set, 0);
1985 gcc_assert (MEM_P (addr));
1986 addr = XEXP (addr, 0);
1988 /* As documented, only consider extremely simple addresses. */
1989 switch (GET_CODE (addr))
1992 gcc_assert (REGNO (addr) == cfa.reg);
1993 offset = -cfa.offset;
1996 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1997 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2003 span = targetm.dwarf_register_span (src);
2005 /* ??? We'd like to use queue_reg_save, but we need to come up with
2006 a different flushing heuristic for epilogues. */
2008 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2011 /* We have a PARALLEL describing where the contents of SRC live.
2012 Queue register saves for each piece of the PARALLEL. */
2015 HOST_WIDE_INT span_offset = offset;
2017 gcc_assert (GET_CODE (span) == PARALLEL);
2019 limit = XVECLEN (span, 0);
2020 for (par_index = 0; par_index < limit; par_index++)
2022 rtx elem = XVECEXP (span, 0, par_index);
2024 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2025 INVALID_REGNUM, span_offset);
2026 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2031 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2034 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2037 unsigned sregno, dregno;
2039 src = XEXP (set, 1);
2040 dest = XEXP (set, 0);
2043 sregno = DWARF_FRAME_RETURN_COLUMN;
2045 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2047 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2049 /* ??? We'd like to use queue_reg_save, but we need to come up with
2050 a different flushing heuristic for epilogues. */
2051 reg_save (label, sregno, dregno, 0);
2054 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2057 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2059 rtx src, dest, span;
2060 dw_cfi_ref cfi = new_cfi ();
2062 dest = SET_DEST (set);
2063 src = SET_SRC (set);
2065 gcc_assert (REG_P (src));
2066 gcc_assert (MEM_P (dest));
2068 span = targetm.dwarf_register_span (src);
2071 cfi->dw_cfi_opc = DW_CFA_expression;
2072 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2073 cfi->dw_cfi_oprnd2.dw_cfi_loc
2074 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
2075 VAR_INIT_STATUS_INITIALIZED);
2077 /* ??? We'd like to use queue_reg_save, were the interface different,
2078 and, as above, we could manage flushing for epilogues. */
2079 add_fde_cfi (label, cfi);
2082 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2085 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2087 dw_cfi_ref cfi = new_cfi ();
2088 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2090 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2091 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2093 add_fde_cfi (label, cfi);
2096 /* Record call frame debugging information for an expression EXPR,
2097 which either sets SP or FP (adjusting how we calculate the frame
2098 address) or saves a register to the stack or another register.
2099 LABEL indicates the address of EXPR.
2101 This function encodes a state machine mapping rtxes to actions on
2102 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2103 users need not read the source code.
2105 The High-Level Picture
2107 Changes in the register we use to calculate the CFA: Currently we
2108 assume that if you copy the CFA register into another register, we
2109 should take the other one as the new CFA register; this seems to
2110 work pretty well. If it's wrong for some target, it's simple
2111 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2113 Changes in the register we use for saving registers to the stack:
2114 This is usually SP, but not always. Again, we deduce that if you
2115 copy SP into another register (and SP is not the CFA register),
2116 then the new register is the one we will be using for register
2117 saves. This also seems to work.
2119 Register saves: There's not much guesswork about this one; if
2120 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2121 register save, and the register used to calculate the destination
2122 had better be the one we think we're using for this purpose.
2123 It's also assumed that a copy from a call-saved register to another
2124 register is saving that register if RTX_FRAME_RELATED_P is set on
2125 that instruction. If the copy is from a call-saved register to
2126 the *same* register, that means that the register is now the same
2127 value as in the caller.
2129 Except: If the register being saved is the CFA register, and the
2130 offset is nonzero, we are saving the CFA, so we assume we have to
2131 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2132 the intent is to save the value of SP from the previous frame.
2134 In addition, if a register has previously been saved to a different
2137 Invariants / Summaries of Rules
2139 cfa current rule for calculating the CFA. It usually
2140 consists of a register and an offset.
2141 cfa_store register used by prologue code to save things to the stack
2142 cfa_store.offset is the offset from the value of
2143 cfa_store.reg to the actual CFA
2144 cfa_temp register holding an integral value. cfa_temp.offset
2145 stores the value, which will be used to adjust the
2146 stack pointer. cfa_temp is also used like cfa_store,
2147 to track stores to the stack via fp or a temp reg.
2149 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2150 with cfa.reg as the first operand changes the cfa.reg and its
2151 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2154 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2155 expression yielding a constant. This sets cfa_temp.reg
2156 and cfa_temp.offset.
2158 Rule 5: Create a new register cfa_store used to save items to the
2161 Rules 10-14: Save a register to the stack. Define offset as the
2162 difference of the original location and cfa_store's
2163 location (or cfa_temp's location if cfa_temp is used).
2165 Rules 16-20: If AND operation happens on sp in prologue, we assume
2166 stack is realigned. We will use a group of DW_OP_XXX
2167 expressions to represent the location of the stored
2168 register instead of CFA+offset.
2172 "{a,b}" indicates a choice of a xor b.
2173 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2176 (set <reg1> <reg2>:cfa.reg)
2177 effects: cfa.reg = <reg1>
2178 cfa.offset unchanged
2179 cfa_temp.reg = <reg1>
2180 cfa_temp.offset = cfa.offset
2183 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2184 {<const_int>,<reg>:cfa_temp.reg}))
2185 effects: cfa.reg = sp if fp used
2186 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2187 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2188 if cfa_store.reg==sp
2191 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2192 effects: cfa.reg = fp
2193 cfa_offset += +/- <const_int>
2196 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2197 constraints: <reg1> != fp
2199 effects: cfa.reg = <reg1>
2200 cfa_temp.reg = <reg1>
2201 cfa_temp.offset = cfa.offset
2204 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2205 constraints: <reg1> != fp
2207 effects: cfa_store.reg = <reg1>
2208 cfa_store.offset = cfa.offset - cfa_temp.offset
2211 (set <reg> <const_int>)
2212 effects: cfa_temp.reg = <reg>
2213 cfa_temp.offset = <const_int>
2216 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2217 effects: cfa_temp.reg = <reg1>
2218 cfa_temp.offset |= <const_int>
2221 (set <reg> (high <exp>))
2225 (set <reg> (lo_sum <exp> <const_int>))
2226 effects: cfa_temp.reg = <reg>
2227 cfa_temp.offset = <const_int>
2230 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2231 effects: cfa_store.offset -= <const_int>
2232 cfa.offset = cfa_store.offset if cfa.reg == sp
2234 cfa.base_offset = -cfa_store.offset
2237 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2238 effects: cfa_store.offset += -/+ mode_size(mem)
2239 cfa.offset = cfa_store.offset if cfa.reg == sp
2241 cfa.base_offset = -cfa_store.offset
2244 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2247 effects: cfa.reg = <reg1>
2248 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2251 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2252 effects: cfa.reg = <reg1>
2253 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2256 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2257 effects: cfa.reg = <reg1>
2258 cfa.base_offset = -cfa_temp.offset
2259 cfa_temp.offset -= mode_size(mem)
2262 (set <reg> {unspec, unspec_volatile})
2263 effects: target-dependent
2266 (set sp (and: sp <const_int>))
2267 constraints: cfa_store.reg == sp
2268 effects: current_fde.stack_realign = 1
2269 cfa_store.offset = 0
2270 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2273 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2274 effects: cfa_store.offset += -/+ mode_size(mem)
2277 (set (mem ({pre_inc, pre_dec} sp)) fp)
2278 constraints: fde->stack_realign == 1
2279 effects: cfa_store.offset = 0
2280 cfa.reg != HARD_FRAME_POINTER_REGNUM
2283 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2284 constraints: fde->stack_realign == 1
2286 && cfa.indirect == 0
2287 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2288 effects: Use DW_CFA_def_cfa_expression to define cfa
2289 cfa.reg == fde->drap_reg */
2292 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2294 rtx src, dest, span;
2295 HOST_WIDE_INT offset;
2298 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2299 the PARALLEL independently. The first element is always processed if
2300 it is a SET. This is for backward compatibility. Other elements
2301 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2302 flag is set in them. */
2303 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2306 int limit = XVECLEN (expr, 0);
2309 /* PARALLELs have strict read-modify-write semantics, so we
2310 ought to evaluate every rvalue before changing any lvalue.
2311 It's cumbersome to do that in general, but there's an
2312 easy approximation that is enough for all current users:
2313 handle register saves before register assignments. */
2314 if (GET_CODE (expr) == PARALLEL)
2315 for (par_index = 0; par_index < limit; par_index++)
2317 elem = XVECEXP (expr, 0, par_index);
2318 if (GET_CODE (elem) == SET
2319 && MEM_P (SET_DEST (elem))
2320 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2321 dwarf2out_frame_debug_expr (elem, label);
2324 for (par_index = 0; par_index < limit; par_index++)
2326 elem = XVECEXP (expr, 0, par_index);
2327 if (GET_CODE (elem) == SET
2328 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2329 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2330 dwarf2out_frame_debug_expr (elem, label);
2331 else if (GET_CODE (elem) == SET
2333 && !RTX_FRAME_RELATED_P (elem))
2335 /* Stack adjustment combining might combine some post-prologue
2336 stack adjustment into a prologue stack adjustment. */
2337 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2340 dwarf2out_stack_adjust (offset, label);
2346 gcc_assert (GET_CODE (expr) == SET);
2348 src = SET_SRC (expr);
2349 dest = SET_DEST (expr);
2353 rtx rsi = reg_saved_in (src);
2358 fde = current_fde ();
2360 switch (GET_CODE (dest))
2363 switch (GET_CODE (src))
2365 /* Setting FP from SP. */
2367 if (cfa.reg == (unsigned) REGNO (src))
2370 /* Update the CFA rule wrt SP or FP. Make sure src is
2371 relative to the current CFA register.
2373 We used to require that dest be either SP or FP, but the
2374 ARM copies SP to a temporary register, and from there to
2375 FP. So we just rely on the backends to only set
2376 RTX_FRAME_RELATED_P on appropriate insns. */
2377 cfa.reg = REGNO (dest);
2378 cfa_temp.reg = cfa.reg;
2379 cfa_temp.offset = cfa.offset;
2383 /* Saving a register in a register. */
2384 gcc_assert (!fixed_regs [REGNO (dest)]
2385 /* For the SPARC and its register window. */
2386 || (DWARF_FRAME_REGNUM (REGNO (src))
2387 == DWARF_FRAME_RETURN_COLUMN));
2389 /* After stack is aligned, we can only save SP in FP
2390 if drap register is used. In this case, we have
2391 to restore stack pointer with the CFA value and we
2392 don't generate this DWARF information. */
2394 && fde->stack_realign
2395 && REGNO (src) == STACK_POINTER_REGNUM)
2396 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2397 && fde->drap_reg != INVALID_REGNUM
2398 && cfa.reg != REGNO (src));
2400 queue_reg_save (label, src, dest, 0);
2407 if (dest == stack_pointer_rtx)
2411 switch (GET_CODE (XEXP (src, 1)))
2414 offset = INTVAL (XEXP (src, 1));
2417 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2419 offset = cfa_temp.offset;
2425 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2427 /* Restoring SP from FP in the epilogue. */
2428 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2429 cfa.reg = STACK_POINTER_REGNUM;
2431 else if (GET_CODE (src) == LO_SUM)
2432 /* Assume we've set the source reg of the LO_SUM from sp. */
2435 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2437 if (GET_CODE (src) != MINUS)
2439 if (cfa.reg == STACK_POINTER_REGNUM)
2440 cfa.offset += offset;
2441 if (cfa_store.reg == STACK_POINTER_REGNUM)
2442 cfa_store.offset += offset;
2444 else if (dest == hard_frame_pointer_rtx)
2447 /* Either setting the FP from an offset of the SP,
2448 or adjusting the FP */
2449 gcc_assert (frame_pointer_needed);
2451 gcc_assert (REG_P (XEXP (src, 0))
2452 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2453 && CONST_INT_P (XEXP (src, 1)));
2454 offset = INTVAL (XEXP (src, 1));
2455 if (GET_CODE (src) != MINUS)
2457 cfa.offset += offset;
2458 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2462 gcc_assert (GET_CODE (src) != MINUS);
2465 if (REG_P (XEXP (src, 0))
2466 && REGNO (XEXP (src, 0)) == cfa.reg
2467 && CONST_INT_P (XEXP (src, 1)))
2469 /* Setting a temporary CFA register that will be copied
2470 into the FP later on. */
2471 offset = - INTVAL (XEXP (src, 1));
2472 cfa.offset += offset;
2473 cfa.reg = REGNO (dest);
2474 /* Or used to save regs to the stack. */
2475 cfa_temp.reg = cfa.reg;
2476 cfa_temp.offset = cfa.offset;
2480 else if (REG_P (XEXP (src, 0))
2481 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2482 && XEXP (src, 1) == stack_pointer_rtx)
2484 /* Setting a scratch register that we will use instead
2485 of SP for saving registers to the stack. */
2486 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2487 cfa_store.reg = REGNO (dest);
2488 cfa_store.offset = cfa.offset - cfa_temp.offset;
2492 else if (GET_CODE (src) == LO_SUM
2493 && CONST_INT_P (XEXP (src, 1)))
2495 cfa_temp.reg = REGNO (dest);
2496 cfa_temp.offset = INTVAL (XEXP (src, 1));
2505 cfa_temp.reg = REGNO (dest);
2506 cfa_temp.offset = INTVAL (src);
2511 gcc_assert (REG_P (XEXP (src, 0))
2512 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2513 && CONST_INT_P (XEXP (src, 1)));
2515 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2516 cfa_temp.reg = REGNO (dest);
2517 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2520 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2521 which will fill in all of the bits. */
2528 case UNSPEC_VOLATILE:
2529 gcc_assert (targetm.dwarf_handle_frame_unspec);
2530 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2535 /* If this AND operation happens on stack pointer in prologue,
2536 we assume the stack is realigned and we extract the
2538 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2540 /* We interpret reg_save differently with stack_realign set.
2541 Thus we must flush whatever we have queued first. */
2542 dwarf2out_flush_queued_reg_saves ();
2544 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2545 fde->stack_realign = 1;
2546 fde->stack_realignment = INTVAL (XEXP (src, 1));
2547 cfa_store.offset = 0;
2549 if (cfa.reg != STACK_POINTER_REGNUM
2550 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2551 fde->drap_reg = cfa.reg;
2559 def_cfa_1 (label, &cfa);
2564 /* Saving a register to the stack. Make sure dest is relative to the
2566 switch (GET_CODE (XEXP (dest, 0)))
2571 /* We can't handle variable size modifications. */
2572 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2574 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2576 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2577 && cfa_store.reg == STACK_POINTER_REGNUM);
2579 cfa_store.offset += offset;
2580 if (cfa.reg == STACK_POINTER_REGNUM)
2581 cfa.offset = cfa_store.offset;
2583 offset = -cfa_store.offset;
2590 offset = GET_MODE_SIZE (GET_MODE (dest));
2591 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2594 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2595 == STACK_POINTER_REGNUM)
2596 && cfa_store.reg == STACK_POINTER_REGNUM);
2598 cfa_store.offset += offset;
2600 /* Rule 18: If stack is aligned, we will use FP as a
2601 reference to represent the address of the stored
2604 && fde->stack_realign
2605 && src == hard_frame_pointer_rtx)
2607 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2608 cfa_store.offset = 0;
2611 if (cfa.reg == STACK_POINTER_REGNUM)
2612 cfa.offset = cfa_store.offset;
2614 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
2615 offset += -cfa_store.offset;
2617 offset = -cfa_store.offset;
2621 /* With an offset. */
2628 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2629 && REG_P (XEXP (XEXP (dest, 0), 0)));
2630 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2631 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2634 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2636 if (cfa.reg == (unsigned) regno)
2637 offset -= cfa.offset;
2638 else if (cfa_store.reg == (unsigned) regno)
2639 offset -= cfa_store.offset;
2642 gcc_assert (cfa_temp.reg == (unsigned) regno);
2643 offset -= cfa_temp.offset;
2649 /* Without an offset. */
2652 int regno = REGNO (XEXP (dest, 0));
2654 if (cfa.reg == (unsigned) regno)
2655 offset = -cfa.offset;
2656 else if (cfa_store.reg == (unsigned) regno)
2657 offset = -cfa_store.offset;
2660 gcc_assert (cfa_temp.reg == (unsigned) regno);
2661 offset = -cfa_temp.offset;
2668 gcc_assert (cfa_temp.reg
2669 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2670 offset = -cfa_temp.offset;
2671 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2679 /* If the source operand of this MEM operation is not a
2680 register, basically the source is return address. Here
2681 we only care how much stack grew and we don't save it. */
2685 if (REGNO (src) != STACK_POINTER_REGNUM
2686 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2687 && (unsigned) REGNO (src) == cfa.reg)
2689 /* We're storing the current CFA reg into the stack. */
2691 if (cfa.offset == 0)
2694 /* If stack is aligned, putting CFA reg into stack means
2695 we can no longer use reg + offset to represent CFA.
2696 Here we use DW_CFA_def_cfa_expression instead. The
2697 result of this expression equals to the original CFA
2700 && fde->stack_realign
2701 && cfa.indirect == 0
2702 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2704 dw_cfa_location cfa_exp;
2706 gcc_assert (fde->drap_reg == cfa.reg);
2708 cfa_exp.indirect = 1;
2709 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2710 cfa_exp.base_offset = offset;
2713 fde->drap_reg_saved = 1;
2715 def_cfa_1 (label, &cfa_exp);
2719 /* If the source register is exactly the CFA, assume
2720 we're saving SP like any other register; this happens
2722 def_cfa_1 (label, &cfa);
2723 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2728 /* Otherwise, we'll need to look in the stack to
2729 calculate the CFA. */
2730 rtx x = XEXP (dest, 0);
2734 gcc_assert (REG_P (x));
2736 cfa.reg = REGNO (x);
2737 cfa.base_offset = offset;
2739 def_cfa_1 (label, &cfa);
2744 def_cfa_1 (label, &cfa);
2746 span = targetm.dwarf_register_span (src);
2749 queue_reg_save (label, src, NULL_RTX, offset);
2752 /* We have a PARALLEL describing where the contents of SRC
2753 live. Queue register saves for each piece of the
2757 HOST_WIDE_INT span_offset = offset;
2759 gcc_assert (GET_CODE (span) == PARALLEL);
2761 limit = XVECLEN (span, 0);
2762 for (par_index = 0; par_index < limit; par_index++)
2764 rtx elem = XVECEXP (span, 0, par_index);
2766 queue_reg_save (label, elem, NULL_RTX, span_offset);
2767 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2778 /* Record call frame debugging information for INSN, which either
2779 sets SP or FP (adjusting how we calculate the frame address) or saves a
2780 register to the stack. If INSN is NULL_RTX, initialize our state.
2782 If AFTER_P is false, we're being called before the insn is emitted,
2783 otherwise after. Call instructions get invoked twice. */
2786 dwarf2out_frame_debug (rtx insn, bool after_p)
2790 bool handled_one = false;
2792 if (insn == NULL_RTX)
2796 /* Flush any queued register saves. */
2797 dwarf2out_flush_queued_reg_saves ();
2799 /* Set up state for generating call frame debug info. */
2802 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2804 cfa.reg = STACK_POINTER_REGNUM;
2807 cfa_temp.offset = 0;
2809 for (i = 0; i < num_regs_saved_in_regs; i++)
2811 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2812 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2814 num_regs_saved_in_regs = 0;
2816 if (barrier_args_size)
2818 XDELETEVEC (barrier_args_size);
2819 barrier_args_size = NULL;
2824 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2825 dwarf2out_flush_queued_reg_saves ();
2827 if (!RTX_FRAME_RELATED_P (insn))
2829 /* ??? This should be done unconditionally since stack adjustments
2830 matter if the stack pointer is not the CFA register anymore but
2831 is still used to save registers. */
2832 if (!ACCUMULATE_OUTGOING_ARGS)
2833 dwarf2out_notice_stack_adjust (insn, after_p);
2837 label = dwarf2out_cfi_label (false);
2838 any_cfis_emitted = false;
2840 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2841 switch (REG_NOTE_KIND (note))
2843 case REG_FRAME_RELATED_EXPR:
2844 insn = XEXP (note, 0);
2847 case REG_CFA_DEF_CFA:
2848 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2852 case REG_CFA_ADJUST_CFA:
2857 if (GET_CODE (n) == PARALLEL)
2858 n = XVECEXP (n, 0, 0);
2860 dwarf2out_frame_debug_adjust_cfa (n, label);
2864 case REG_CFA_OFFSET:
2867 n = single_set (insn);
2868 dwarf2out_frame_debug_cfa_offset (n, label);
2872 case REG_CFA_REGISTER:
2877 if (GET_CODE (n) == PARALLEL)
2878 n = XVECEXP (n, 0, 0);
2880 dwarf2out_frame_debug_cfa_register (n, label);
2884 case REG_CFA_EXPRESSION:
2887 n = single_set (insn);
2888 dwarf2out_frame_debug_cfa_expression (n, label);
2892 case REG_CFA_RESTORE:
2897 if (GET_CODE (n) == PARALLEL)
2898 n = XVECEXP (n, 0, 0);
2901 dwarf2out_frame_debug_cfa_restore (n, label);
2905 case REG_CFA_SET_VDRAP:
2909 dw_fde_ref fde = current_fde ();
2912 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2914 fde->vdrap_reg = REGNO (n);
2925 if (any_cfis_emitted)
2926 dwarf2out_flush_queued_reg_saves ();
2930 insn = PATTERN (insn);
2932 dwarf2out_frame_debug_expr (insn, label);
2934 /* Check again. A parallel can save and update the same register.
2935 We could probably check just once, here, but this is safer than
2936 removing the check above. */
2937 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2938 dwarf2out_flush_queued_reg_saves ();
2941 /* Determine if we need to save and restore CFI information around this
2942 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2943 we do need to save/restore, then emit the save now, and insert a
2944 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2947 dwarf2out_cfi_begin_epilogue (rtx insn)
2949 bool saw_frp = false;
2952 /* Scan forward to the return insn, noticing if there are possible
2953 frame related insns. */
2954 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2959 /* Look for both regular and sibcalls to end the block. */
2960 if (returnjump_p (i))
2962 if (CALL_P (i) && SIBLING_CALL_P (i))
2965 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2968 rtx seq = PATTERN (i);
2970 if (returnjump_p (XVECEXP (seq, 0, 0)))
2972 if (CALL_P (XVECEXP (seq, 0, 0))
2973 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2976 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2977 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2981 if (RTX_FRAME_RELATED_P (i))
2985 /* If the port doesn't emit epilogue unwind info, we don't need a
2986 save/restore pair. */
2990 /* Otherwise, search forward to see if the return insn was the last
2991 basic block of the function. If so, we don't need save/restore. */
2992 gcc_assert (i != NULL);
2993 i = next_real_insn (i);
2997 /* Insert the restore before that next real insn in the stream, and before
2998 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2999 properly nested. This should be after any label or alignment. This
3000 will be pushed into the CFI stream by the function below. */
3003 rtx p = PREV_INSN (i);
3006 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3010 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3012 emit_cfa_remember = true;
3014 /* And emulate the state save. */
3015 gcc_assert (!cfa_remember.in_use);
3017 cfa_remember.in_use = 1;
3020 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3024 dwarf2out_frame_debug_restore_state (void)
3026 dw_cfi_ref cfi = new_cfi ();
3027 const char *label = dwarf2out_cfi_label (false);
3029 cfi->dw_cfi_opc = DW_CFA_restore_state;
3030 add_fde_cfi (label, cfi);
3032 gcc_assert (cfa_remember.in_use);
3034 cfa_remember.in_use = 0;
3037 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3038 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3039 (enum dwarf_call_frame_info cfi);
3041 static enum dw_cfi_oprnd_type
3042 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3047 case DW_CFA_GNU_window_save:
3048 case DW_CFA_remember_state:
3049 case DW_CFA_restore_state:
3050 return dw_cfi_oprnd_unused;
3052 case DW_CFA_set_loc:
3053 case DW_CFA_advance_loc1:
3054 case DW_CFA_advance_loc2:
3055 case DW_CFA_advance_loc4:
3056 case DW_CFA_MIPS_advance_loc8:
3057 return dw_cfi_oprnd_addr;
3060 case DW_CFA_offset_extended:
3061 case DW_CFA_def_cfa:
3062 case DW_CFA_offset_extended_sf:
3063 case DW_CFA_def_cfa_sf:
3064 case DW_CFA_restore:
3065 case DW_CFA_restore_extended:
3066 case DW_CFA_undefined:
3067 case DW_CFA_same_value:
3068 case DW_CFA_def_cfa_register:
3069 case DW_CFA_register:
3070 case DW_CFA_expression:
3071 return dw_cfi_oprnd_reg_num;
3073 case DW_CFA_def_cfa_offset:
3074 case DW_CFA_GNU_args_size:
3075 case DW_CFA_def_cfa_offset_sf:
3076 return dw_cfi_oprnd_offset;
3078 case DW_CFA_def_cfa_expression:
3079 return dw_cfi_oprnd_loc;
3086 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3087 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3088 (enum dwarf_call_frame_info cfi);
3090 static enum dw_cfi_oprnd_type
3091 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3095 case DW_CFA_def_cfa:
3096 case DW_CFA_def_cfa_sf:
3098 case DW_CFA_offset_extended_sf:
3099 case DW_CFA_offset_extended:
3100 return dw_cfi_oprnd_offset;
3102 case DW_CFA_register:
3103 return dw_cfi_oprnd_reg_num;
3105 case DW_CFA_expression:
3106 return dw_cfi_oprnd_loc;
3109 return dw_cfi_oprnd_unused;
3113 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3114 switch to the data section instead, and write out a synthetic start label
3115 for collect2 the first time around. */
3118 switch_to_eh_frame_section (bool back)
3122 #ifdef EH_FRAME_SECTION_NAME
3123 if (eh_frame_section == 0)
3127 if (EH_TABLES_CAN_BE_READ_ONLY)
3133 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3135 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3137 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3139 flags = ((! flag_pic
3140 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3141 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3142 && (per_encoding & 0x70) != DW_EH_PE_absptr
3143 && (per_encoding & 0x70) != DW_EH_PE_aligned
3144 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3145 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3146 ? 0 : SECTION_WRITE);
3149 flags = SECTION_WRITE;
3150 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3152 #endif /* EH_FRAME_SECTION_NAME */
3154 if (eh_frame_section)
3155 switch_to_section (eh_frame_section);
3158 /* We have no special eh_frame section. Put the information in
3159 the data section and emit special labels to guide collect2. */
3160 switch_to_section (data_section);
3164 label = get_file_function_name ("F");
3165 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3166 targetm.asm_out.globalize_label (asm_out_file,
3167 IDENTIFIER_POINTER (label));
3168 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3173 /* Switch [BACK] to the eh or debug frame table section, depending on
3177 switch_to_frame_table_section (int for_eh, bool back)
3180 switch_to_eh_frame_section (back);
3183 if (!debug_frame_section)
3184 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3185 SECTION_DEBUG, NULL);
3186 switch_to_section (debug_frame_section);
3190 /* Output a Call Frame Information opcode and its operand(s). */
3193 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3198 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3199 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3200 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3201 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3202 ((unsigned HOST_WIDE_INT)
3203 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3204 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3206 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3207 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3208 "DW_CFA_offset, column %#lx", r);
3209 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3210 dw2_asm_output_data_uleb128 (off, NULL);
3212 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3214 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3215 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3216 "DW_CFA_restore, column %#lx", r);
3220 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3221 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3223 switch (cfi->dw_cfi_opc)
3225 case DW_CFA_set_loc:
3227 dw2_asm_output_encoded_addr_rtx (
3228 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3229 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3232 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3233 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3234 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3237 case DW_CFA_advance_loc1:
3238 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3239 fde->dw_fde_current_label, NULL);
3240 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3243 case DW_CFA_advance_loc2:
3244 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3245 fde->dw_fde_current_label, NULL);
3246 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3249 case DW_CFA_advance_loc4:
3250 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3251 fde->dw_fde_current_label, NULL);
3252 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3255 case DW_CFA_MIPS_advance_loc8:
3256 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3257 fde->dw_fde_current_label, NULL);
3258 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3261 case DW_CFA_offset_extended:
3262 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3263 dw2_asm_output_data_uleb128 (r, NULL);
3264 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3265 dw2_asm_output_data_uleb128 (off, NULL);
3268 case DW_CFA_def_cfa:
3269 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3270 dw2_asm_output_data_uleb128 (r, NULL);
3271 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3274 case DW_CFA_offset_extended_sf:
3275 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3276 dw2_asm_output_data_uleb128 (r, NULL);
3277 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3278 dw2_asm_output_data_sleb128 (off, NULL);
3281 case DW_CFA_def_cfa_sf:
3282 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3283 dw2_asm_output_data_uleb128 (r, NULL);
3284 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3285 dw2_asm_output_data_sleb128 (off, NULL);
3288 case DW_CFA_restore_extended:
3289 case DW_CFA_undefined:
3290 case DW_CFA_same_value:
3291 case DW_CFA_def_cfa_register:
3292 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3293 dw2_asm_output_data_uleb128 (r, NULL);
3296 case DW_CFA_register:
3297 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3298 dw2_asm_output_data_uleb128 (r, NULL);
3299 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3300 dw2_asm_output_data_uleb128 (r, NULL);
3303 case DW_CFA_def_cfa_offset:
3304 case DW_CFA_GNU_args_size:
3305 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3308 case DW_CFA_def_cfa_offset_sf:
3309 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3310 dw2_asm_output_data_sleb128 (off, NULL);
3313 case DW_CFA_GNU_window_save:
3316 case DW_CFA_def_cfa_expression:
3317 case DW_CFA_expression:
3318 output_cfa_loc (cfi, for_eh);
3321 case DW_CFA_GNU_negative_offset_extended:
3322 /* Obsoleted by DW_CFA_offset_extended_sf. */
3331 /* Similar, but do it via assembler directives instead. */
3334 output_cfi_directive (dw_cfi_ref cfi)
3336 unsigned long r, r2;
3338 switch (cfi->dw_cfi_opc)
3340 case DW_CFA_advance_loc:
3341 case DW_CFA_advance_loc1:
3342 case DW_CFA_advance_loc2:
3343 case DW_CFA_advance_loc4:
3344 case DW_CFA_MIPS_advance_loc8:
3345 case DW_CFA_set_loc:
3346 /* Should only be created by add_fde_cfi in a code path not
3347 followed when emitting via directives. The assembler is
3348 going to take care of this for us. */
3352 case DW_CFA_offset_extended:
3353 case DW_CFA_offset_extended_sf:
3354 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3355 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3356 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3359 case DW_CFA_restore:
3360 case DW_CFA_restore_extended:
3361 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3362 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3365 case DW_CFA_undefined:
3366 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3367 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3370 case DW_CFA_same_value:
3371 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3372 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3375 case DW_CFA_def_cfa:
3376 case DW_CFA_def_cfa_sf:
3377 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3378 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3379 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3382 case DW_CFA_def_cfa_register:
3383 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3384 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3387 case DW_CFA_register:
3388 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3389 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3390 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3393 case DW_CFA_def_cfa_offset:
3394 case DW_CFA_def_cfa_offset_sf:
3395 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3396 HOST_WIDE_INT_PRINT_DEC"\n",
3397 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3400 case DW_CFA_remember_state:
3401 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3403 case DW_CFA_restore_state:
3404 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3407 case DW_CFA_GNU_args_size:
3408 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3409 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3411 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3412 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3413 fputc ('\n', asm_out_file);
3416 case DW_CFA_GNU_window_save:
3417 fprintf (asm_out_file, "\t.cfi_window_save\n");
3420 case DW_CFA_def_cfa_expression:
3421 case DW_CFA_expression:
3422 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3423 output_cfa_loc_raw (cfi);
3424 fputc ('\n', asm_out_file);
3432 DEF_VEC_P (dw_cfi_ref);
3433 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3435 /* Output CFIs to bring current FDE to the same state as after executing
3436 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3437 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3438 other arguments to pass to output_cfi. */
3441 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3443 struct dw_cfi_struct cfi_buf;
3445 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3446 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3447 unsigned int len, idx;
3449 for (;; cfi = cfi->dw_cfi_next)
3450 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3452 case DW_CFA_advance_loc:
3453 case DW_CFA_advance_loc1:
3454 case DW_CFA_advance_loc2:
3455 case DW_CFA_advance_loc4:
3456 case DW_CFA_MIPS_advance_loc8:
3457 case DW_CFA_set_loc:
3458 /* All advances should be ignored. */
3460 case DW_CFA_remember_state:
3462 dw_cfi_ref args_size = cfi_args_size;
3464 /* Skip everything between .cfi_remember_state and
3465 .cfi_restore_state. */
3466 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3467 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3469 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3472 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3479 cfi_args_size = args_size;
3483 case DW_CFA_GNU_args_size:
3484 cfi_args_size = cfi;
3486 case DW_CFA_GNU_window_save:
3489 case DW_CFA_offset_extended:
3490 case DW_CFA_offset_extended_sf:
3491 case DW_CFA_restore:
3492 case DW_CFA_restore_extended:
3493 case DW_CFA_undefined:
3494 case DW_CFA_same_value:
3495 case DW_CFA_register:
3496 case DW_CFA_val_offset:
3497 case DW_CFA_val_offset_sf:
3498 case DW_CFA_expression:
3499 case DW_CFA_val_expression:
3500 case DW_CFA_GNU_negative_offset_extended:
3501 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3502 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3503 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3504 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3506 case DW_CFA_def_cfa:
3507 case DW_CFA_def_cfa_sf:
3508 case DW_CFA_def_cfa_expression:
3510 cfi_cfa_offset = cfi;
3512 case DW_CFA_def_cfa_register:
3515 case DW_CFA_def_cfa_offset:
3516 case DW_CFA_def_cfa_offset_sf:
3517 cfi_cfa_offset = cfi;
3520 gcc_assert (cfi == NULL);
3522 len = VEC_length (dw_cfi_ref, regs);
3523 for (idx = 0; idx < len; idx++)
3525 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3527 && cfi2->dw_cfi_opc != DW_CFA_restore
3528 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3531 output_cfi_directive (cfi2);
3533 output_cfi (cfi2, fde, for_eh);
3536 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3538 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3540 switch (cfi_cfa_offset->dw_cfi_opc)
3542 case DW_CFA_def_cfa_offset:
3543 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3544 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3546 case DW_CFA_def_cfa_offset_sf:
3547 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3548 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3550 case DW_CFA_def_cfa:
3551 case DW_CFA_def_cfa_sf:
3552 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3553 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3560 else if (cfi_cfa_offset)
3561 cfi_cfa = cfi_cfa_offset;
3565 output_cfi_directive (cfi_cfa);
3567 output_cfi (cfi_cfa, fde, for_eh);
3570 cfi_cfa_offset = NULL;
3572 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3575 output_cfi_directive (cfi_args_size);
3577 output_cfi (cfi_args_size, fde, for_eh);
3579 cfi_args_size = NULL;
3582 VEC_free (dw_cfi_ref, heap, regs);
3585 else if (do_cfi_asm)
3586 output_cfi_directive (cfi);
3588 output_cfi (cfi, fde, for_eh);
3595 /* Output one FDE. */
3598 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3599 char *section_start_label, int fde_encoding, char *augmentation,
3600 bool any_lsda_needed, int lsda_encoding)
3602 const char *begin, *end;
3603 static unsigned int j;
3604 char l1[20], l2[20];
3607 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3609 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3611 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3612 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3613 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3614 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3615 " indicating 64-bit DWARF extension");
3616 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3618 ASM_OUTPUT_LABEL (asm_out_file, l1);
3621 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3623 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3624 debug_frame_section, "FDE CIE offset");
3626 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
3627 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
3631 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3632 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3633 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3634 "FDE initial location");
3635 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3636 end, begin, "FDE address range");
3640 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3641 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3644 if (augmentation[0])
3646 if (any_lsda_needed)
3648 int size = size_of_encoded_value (lsda_encoding);
3650 if (lsda_encoding == DW_EH_PE_aligned)
3652 int offset = ( 4 /* Length */
3653 + 4 /* CIE offset */
3654 + 2 * size_of_encoded_value (fde_encoding)
3655 + 1 /* Augmentation size */ );
3656 int pad = -offset & (PTR_SIZE - 1);
3659 gcc_assert (size_of_uleb128 (size) == 1);
3662 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3664 if (fde->uses_eh_lsda)
3666 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3667 fde->funcdef_number);
3668 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3669 gen_rtx_SYMBOL_REF (Pmode, l1),
3671 "Language Specific Data Area");
3675 if (lsda_encoding == DW_EH_PE_aligned)
3676 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3677 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3678 "Language Specific Data Area (none)");
3682 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3685 /* Loop through the Call Frame Instructions associated with
3687 fde->dw_fde_current_label = begin;
3688 if (fde->dw_fde_second_begin == NULL)
3689 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3690 output_cfi (cfi, fde, for_eh);
3693 if (fde->dw_fde_switch_cfi)
3694 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3696 output_cfi (cfi, fde, for_eh);
3697 if (cfi == fde->dw_fde_switch_cfi)
3703 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3705 if (fde->dw_fde_switch_cfi)
3707 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3708 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3709 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3710 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3712 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3713 output_cfi (cfi, fde, for_eh);
3716 /* If we are to emit a ref/link from function bodies to their frame tables,
3717 do it now. This is typically performed to make sure that tables
3718 associated with functions are dragged with them and not discarded in
3719 garbage collecting links. We need to do this on a per function basis to
3720 cope with -ffunction-sections. */
3722 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3723 /* Switch to the function section, emit the ref to the tables, and
3724 switch *back* into the table section. */
3725 switch_to_section (function_section (fde->decl));
3726 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3727 switch_to_frame_table_section (for_eh, true);
3730 /* Pad the FDE out to an address sized boundary. */
3731 ASM_OUTPUT_ALIGN (asm_out_file,
3732 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3733 ASM_OUTPUT_LABEL (asm_out_file, l2);
3738 /* Return true if frame description entry FDE is needed for EH. */
3741 fde_needed_for_eh_p (dw_fde_ref fde)
3743 if (flag_asynchronous_unwind_tables)
3746 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3749 if (fde->uses_eh_lsda)
3752 /* If exceptions are enabled, we have collected nothrow info. */
3753 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3759 /* Output the call frame information used to record information
3760 that relates to calculating the frame pointer, and records the
3761 location of saved registers. */
3764 output_call_frame_info (int for_eh)
3769 char l1[20], l2[20], section_start_label[20];
3770 bool any_lsda_needed = false;
3771 char augmentation[6];
3772 int augmentation_size;
3773 int fde_encoding = DW_EH_PE_absptr;
3774 int per_encoding = DW_EH_PE_absptr;
3775 int lsda_encoding = DW_EH_PE_absptr;
3777 rtx personality = NULL;
3780 /* Don't emit a CIE if there won't be any FDEs. */
3781 if (fde_table_in_use == 0)
3784 /* Nothing to do if the assembler's doing it all. */
3785 if (dwarf2out_do_cfi_asm ())
3788 /* If we don't have any functions we'll want to unwind out of, don't emit
3789 any EH unwind information. If we make FDEs linkonce, we may have to
3790 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3791 want to avoid having an FDE kept around when the function it refers to
3792 is discarded. Example where this matters: a primary function template
3793 in C++ requires EH information, an explicit specialization doesn't. */
3796 bool any_eh_needed = false;
3798 for (i = 0; i < fde_table_in_use; i++)
3799 if (fde_table[i].uses_eh_lsda)
3800 any_eh_needed = any_lsda_needed = true;
3801 else if (fde_needed_for_eh_p (&fde_table[i]))
3802 any_eh_needed = true;
3803 else if (TARGET_USES_WEAK_UNWIND_INFO)
3804 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3811 /* We're going to be generating comments, so turn on app. */
3815 /* Switch to the proper frame section, first time. */
3816 switch_to_frame_table_section (for_eh, false);
3818 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3819 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3821 /* Output the CIE. */
3822 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3823 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3824 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3825 dw2_asm_output_data (4, 0xffffffff,
3826 "Initial length escape value indicating 64-bit DWARF extension");
3827 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3828 "Length of Common Information Entry");
3829 ASM_OUTPUT_LABEL (asm_out_file, l1);
3831 /* Now that the CIE pointer is PC-relative for EH,
3832 use 0 to identify the CIE. */
3833 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3834 (for_eh ? 0 : DWARF_CIE_ID),
3835 "CIE Identifier Tag");
3837 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3838 use CIE version 1, unless that would produce incorrect results
3839 due to overflowing the return register column. */
3840 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3842 if (return_reg >= 256 || dwarf_version > 2)
3844 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3846 augmentation[0] = 0;
3847 augmentation_size = 0;
3849 personality = current_unit_personality;
3855 z Indicates that a uleb128 is present to size the
3856 augmentation section.
3857 L Indicates the encoding (and thus presence) of
3858 an LSDA pointer in the FDE augmentation.
3859 R Indicates a non-default pointer encoding for
3861 P Indicates the presence of an encoding + language
3862 personality routine in the CIE augmentation. */
3864 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3865 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3866 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3868 p = augmentation + 1;
3872 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3873 assemble_external_libcall (personality);
3875 if (any_lsda_needed)
3878 augmentation_size += 1;
3880 if (fde_encoding != DW_EH_PE_absptr)
3883 augmentation_size += 1;
3885 if (p > augmentation + 1)
3887 augmentation[0] = 'z';
3891 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3892 if (personality && per_encoding == DW_EH_PE_aligned)
3894 int offset = ( 4 /* Length */
3896 + 1 /* CIE version */
3897 + strlen (augmentation) + 1 /* Augmentation */
3898 + size_of_uleb128 (1) /* Code alignment */
3899 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3901 + 1 /* Augmentation size */
3902 + 1 /* Personality encoding */ );
3903 int pad = -offset & (PTR_SIZE - 1);
3905 augmentation_size += pad;
3907 /* Augmentations should be small, so there's scarce need to
3908 iterate for a solution. Die if we exceed one uleb128 byte. */
3909 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3913 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3914 if (dw_cie_version >= 4)
3916 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3917 dw2_asm_output_data (1, 0, "CIE Segment Size");
3919 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3920 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3921 "CIE Data Alignment Factor");
3923 if (dw_cie_version == 1)
3924 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3926 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3928 if (augmentation[0])
3930 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3933 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3934 eh_data_format_name (per_encoding));
3935 dw2_asm_output_encoded_addr_rtx (per_encoding,
3940 if (any_lsda_needed)
3941 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3942 eh_data_format_name (lsda_encoding));
3944 if (fde_encoding != DW_EH_PE_absptr)
3945 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3946 eh_data_format_name (fde_encoding));
3949 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3950 output_cfi (cfi, NULL, for_eh);
3952 /* Pad the CIE out to an address sized boundary. */
3953 ASM_OUTPUT_ALIGN (asm_out_file,
3954 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3955 ASM_OUTPUT_LABEL (asm_out_file, l2);
3957 /* Loop through all of the FDE's. */
3958 for (i = 0; i < fde_table_in_use; i++)
3961 fde = &fde_table[i];
3963 /* Don't emit EH unwind info for leaf functions that don't need it. */
3964 if (for_eh && !fde_needed_for_eh_p (fde))
3967 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
3968 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3969 augmentation, any_lsda_needed, lsda_encoding);
3972 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3973 dw2_asm_output_data (4, 0, "End of Table");
3974 #ifdef MIPS_DEBUGGING_INFO
3975 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3976 get a value of 0. Putting .align 0 after the label fixes it. */
3977 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3980 /* Turn off app to make assembly quicker. */
3985 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3988 dwarf2out_do_cfi_startproc (bool second)
3992 rtx personality = get_personality_function (current_function_decl);
3994 fprintf (asm_out_file, "\t.cfi_startproc\n");
3998 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4001 /* ??? The GAS support isn't entirely consistent. We have to
4002 handle indirect support ourselves, but PC-relative is done
4003 in the assembler. Further, the assembler can't handle any
4004 of the weirder relocation types. */
4005 if (enc & DW_EH_PE_indirect)
4006 ref = dw2_force_const_mem (ref, true);
4008 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4009 output_addr_const (asm_out_file, ref);
4010 fputc ('\n', asm_out_file);
4013 if (crtl->uses_eh_lsda)
4017 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4018 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4019 current_function_funcdef_no);
4020 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4021 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4023 if (enc & DW_EH_PE_indirect)
4024 ref = dw2_force_const_mem (ref, true);
4026 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4027 output_addr_const (asm_out_file, ref);
4028 fputc ('\n', asm_out_file);
4032 /* Output a marker (i.e. a label) for the beginning of a function, before
4036 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4037 const char *file ATTRIBUTE_UNUSED)
4039 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4045 current_function_func_begin_label = NULL;
4047 do_frame = dwarf2out_do_frame ();
4049 /* ??? current_function_func_begin_label is also used by except.c for
4050 call-site information. We must emit this label if it might be used. */
4052 && (!flag_exceptions
4053 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4056 fnsec = function_section (current_function_decl);
4057 switch_to_section (fnsec);
4058 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4059 current_function_funcdef_no);
4060 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4061 current_function_funcdef_no);
4062 dup_label = xstrdup (label);
4063 current_function_func_begin_label = dup_label;
4065 /* We can elide the fde allocation if we're not emitting debug info. */
4069 /* Expand the fde table if necessary. */
4070 if (fde_table_in_use == fde_table_allocated)
4072 fde_table_allocated += FDE_TABLE_INCREMENT;
4073 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4074 memset (fde_table + fde_table_in_use, 0,
4075 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4078 /* Record the FDE associated with this function. */
4079 current_funcdef_fde = fde_table_in_use;
4081 /* Add the new FDE at the end of the fde_table. */
4082 fde = &fde_table[fde_table_in_use++];
4083 fde->decl = current_function_decl;
4084 fde->dw_fde_begin = dup_label;
4085 fde->dw_fde_end = NULL;
4086 fde->dw_fde_current_label = dup_label;
4087 fde->dw_fde_second_begin = NULL;
4088 fde->dw_fde_second_end = NULL;
4089 fde->dw_fde_vms_end_prologue = NULL;
4090 fde->dw_fde_vms_begin_epilogue = NULL;
4091 fde->dw_fde_cfi = NULL;
4092 fde->dw_fde_switch_cfi = NULL;
4093 fde->funcdef_number = current_function_funcdef_no;
4094 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4095 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4096 fde->nothrow = crtl->nothrow;
4097 fde->drap_reg = INVALID_REGNUM;
4098 fde->vdrap_reg = INVALID_REGNUM;
4099 fde->in_std_section = (fnsec == text_section
4100 || (cold_text_section && fnsec == cold_text_section));
4101 fde->second_in_std_section = 0;
4103 args_size = old_args_size = 0;
4105 /* We only want to output line number information for the genuine dwarf2
4106 prologue case, not the eh frame case. */
4107 #ifdef DWARF2_DEBUGGING_INFO
4109 dwarf2out_source_line (line, file, 0, true);
4112 if (dwarf2out_do_cfi_asm ())
4113 dwarf2out_do_cfi_startproc (false);
4116 rtx personality = get_personality_function (current_function_decl);
4117 if (!current_unit_personality)
4118 current_unit_personality = personality;
4120 /* We cannot keep a current personality per function as without CFI
4121 asm, at the point where we emit the CFI data, there is no current
4122 function anymore. */
4123 if (personality && current_unit_personality != personality)
4124 sorry ("multiple EH personalities are supported only with assemblers "
4125 "supporting .cfi_personality directive");
4129 /* Output a marker (i.e. a label) for the end of the generated code
4130 for a function prologue. This gets called *after* the prologue code has
4134 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4135 const char *file ATTRIBUTE_UNUSED)
4138 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4140 /* Output a label to mark the endpoint of the code generated for this
4142 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4143 current_function_funcdef_no);
4144 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4145 current_function_funcdef_no);
4146 fde = &fde_table[fde_table_in_use - 1];
4147 fde->dw_fde_vms_end_prologue = xstrdup (label);
4150 /* Output a marker (i.e. a label) for the beginning of the generated code
4151 for a function epilogue. This gets called *before* the prologue code has
4155 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4156 const char *file ATTRIBUTE_UNUSED)
4159 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4161 fde = &fde_table[fde_table_in_use - 1];
4162 if (fde->dw_fde_vms_begin_epilogue)
4165 /* Output a label to mark the endpoint of the code generated for this
4167 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4168 current_function_funcdef_no);
4169 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4170 current_function_funcdef_no);
4171 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4174 /* Output a marker (i.e. a label) for the absolute end of the generated code
4175 for a function definition. This gets called *after* the epilogue code has
4179 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4180 const char *file ATTRIBUTE_UNUSED)
4183 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4185 last_var_location_insn = NULL_RTX;
4187 if (dwarf2out_do_cfi_asm ())
4188 fprintf (asm_out_file, "\t.cfi_endproc\n");
4190 /* Output a label to mark the endpoint of the code generated for this
4192 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4193 current_function_funcdef_no);
4194 ASM_OUTPUT_LABEL (asm_out_file, label);
4195 fde = current_fde ();
4196 gcc_assert (fde != NULL);
4197 if (fde->dw_fde_second_begin == NULL)
4198 fde->dw_fde_end = xstrdup (label);
4202 dwarf2out_frame_init (void)
4204 /* Allocate the initial hunk of the fde_table. */
4205 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4206 fde_table_allocated = FDE_TABLE_INCREMENT;
4207 fde_table_in_use = 0;
4209 /* Generate the CFA instructions common to all FDE's. Do it now for the
4210 sake of lookup_cfa. */
4212 /* On entry, the Canonical Frame Address is at SP. */
4213 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4215 if (targetm.debug_unwind_info () == UI_DWARF2
4216 || targetm.except_unwind_info (&global_options) == UI_DWARF2)
4217 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4221 dwarf2out_frame_finish (void)
4223 /* Output call frame information. */
4224 if (targetm.debug_unwind_info () == UI_DWARF2)
4225 output_call_frame_info (0);
4227 /* Output another copy for the unwinder. */
4228 if ((flag_unwind_tables || flag_exceptions)
4229 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
4230 output_call_frame_info (1);
4233 /* Note that the current function section is being used for code. */
4236 dwarf2out_note_section_used (void)
4238 section *sec = current_function_section ();
4239 if (sec == text_section)
4240 text_section_used = true;
4241 else if (sec == cold_text_section)
4242 cold_text_section_used = true;
4245 static void var_location_switch_text_section (void);
4248 dwarf2out_switch_text_section (void)
4251 dw_fde_ref fde = current_fde ();
4254 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
4256 if (!in_cold_section_p)
4258 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
4259 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
4260 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
4264 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
4265 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
4266 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
4268 have_multiple_function_sections = true;
4270 /* Reset the current label on switching text sections, so that we
4271 don't attempt to advance_loc4 between labels in different sections. */
4272 fde->dw_fde_current_label = NULL;
4274 /* There is no need to mark used sections when not debugging. */
4275 if (cold_text_section != NULL)
4276 dwarf2out_note_section_used ();
4278 if (dwarf2out_do_cfi_asm ())
4279 fprintf (asm_out_file, "\t.cfi_endproc\n");
4281 /* Now do the real section switch. */
4282 sect = current_function_section ();
4283 switch_to_section (sect);
4285 fde->second_in_std_section
4286 = (sect == text_section
4287 || (cold_text_section && sect == cold_text_section));
4289 if (dwarf2out_do_cfi_asm ())
4291 dwarf2out_do_cfi_startproc (true);
4292 /* As this is a different FDE, insert all current CFI instructions
4294 output_cfis (fde->dw_fde_cfi, true, fde, true);
4296 cfi = fde->dw_fde_cfi;
4298 while (cfi->dw_cfi_next != NULL)
4299 cfi = cfi->dw_cfi_next;
4300 fde->dw_fde_switch_cfi = cfi;
4301 var_location_switch_text_section ();
4304 /* And now, the subset of the debugging information support code necessary
4305 for emitting location expressions. */
4307 /* Data about a single source file. */
4308 struct GTY(()) dwarf_file_data {
4309 const char * filename;
4313 typedef struct dw_val_struct *dw_val_ref;
4314 typedef struct die_struct *dw_die_ref;
4315 typedef const struct die_struct *const_dw_die_ref;
4316 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4317 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4319 typedef struct GTY(()) deferred_locations_struct
4323 } deferred_locations;
4325 DEF_VEC_O(deferred_locations);
4326 DEF_VEC_ALLOC_O(deferred_locations,gc);
4328 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4330 DEF_VEC_P(dw_die_ref);
4331 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4333 /* Each DIE may have a series of attribute/value pairs. Values
4334 can take on several forms. The forms that are used in this
4335 implementation are listed below. */
4340 dw_val_class_offset,
4342 dw_val_class_loc_list,
4343 dw_val_class_range_list,
4345 dw_val_class_unsigned_const,
4346 dw_val_class_const_double,
4349 dw_val_class_die_ref,
4350 dw_val_class_fde_ref,
4351 dw_val_class_lbl_id,
4352 dw_val_class_lineptr,
4354 dw_val_class_macptr,
4357 dw_val_class_decl_ref,
4358 dw_val_class_vms_delta
4361 /* Describe a floating point constant value, or a vector constant value. */
4363 typedef struct GTY(()) dw_vec_struct {
4364 unsigned char * GTY((length ("%h.length"))) array;
4370 /* The dw_val_node describes an attribute's value, as it is
4371 represented internally. */
4373 typedef struct GTY(()) dw_val_struct {
4374 enum dw_val_class val_class;
4375 union dw_val_struct_union
4377 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4378 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4379 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4380 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4381 HOST_WIDE_INT GTY ((default)) val_int;
4382 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4383 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4384 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4385 struct dw_val_die_union
4389 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4390 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4391 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4392 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4393 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4394 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4395 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4396 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4397 struct dw_val_vms_delta_union
4401 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4403 GTY ((desc ("%1.val_class"))) v;
4407 /* Locations in memory are described using a sequence of stack machine
4410 typedef struct GTY(()) dw_loc_descr_struct {
4411 dw_loc_descr_ref dw_loc_next;
4412 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4413 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4414 from DW_OP_addr with a dtp-relative symbol relocation. */
4415 unsigned int dtprel : 1;
4417 dw_val_node dw_loc_oprnd1;
4418 dw_val_node dw_loc_oprnd2;
4422 /* Location lists are ranges + location descriptions for that range,
4423 so you can track variables that are in different places over
4424 their entire life. */
4425 typedef struct GTY(()) dw_loc_list_struct {
4426 dw_loc_list_ref dw_loc_next;
4427 const char *begin; /* Label for begin address of range */
4428 const char *end; /* Label for end address of range */
4429 char *ll_symbol; /* Label for beginning of location list.
4430 Only on head of list */
4431 const char *section; /* Section this loclist is relative to */
4432 dw_loc_descr_ref expr;
4434 /* True if all addresses in this and subsequent lists are known to be
4437 /* True if this list has been replaced by dw_loc_next. */
4442 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4444 /* Convert a DWARF stack opcode into its string name. */
4447 dwarf_stack_op_name (unsigned int op)
4452 return "DW_OP_addr";
4454 return "DW_OP_deref";
4456 return "DW_OP_const1u";
4458 return "DW_OP_const1s";
4460 return "DW_OP_const2u";
4462 return "DW_OP_const2s";
4464 return "DW_OP_const4u";
4466 return "DW_OP_const4s";
4468 return "DW_OP_const8u";
4470 return "DW_OP_const8s";
4472 return "DW_OP_constu";
4474 return "DW_OP_consts";
4478 return "DW_OP_drop";
4480 return "DW_OP_over";
4482 return "DW_OP_pick";
4484 return "DW_OP_swap";
4488 return "DW_OP_xderef";
4496 return "DW_OP_minus";
4508 return "DW_OP_plus";
4509 case DW_OP_plus_uconst:
4510 return "DW_OP_plus_uconst";
4516 return "DW_OP_shra";
4534 return "DW_OP_skip";
4536 return "DW_OP_lit0";
4538 return "DW_OP_lit1";
4540 return "DW_OP_lit2";
4542 return "DW_OP_lit3";
4544 return "DW_OP_lit4";
4546 return "DW_OP_lit5";
4548 return "DW_OP_lit6";
4550 return "DW_OP_lit7";
4552 return "DW_OP_lit8";
4554 return "DW_OP_lit9";
4556 return "DW_OP_lit10";
4558 return "DW_OP_lit11";
4560 return "DW_OP_lit12";
4562 return "DW_OP_lit13";
4564 return "DW_OP_lit14";
4566 return "DW_OP_lit15";
4568 return "DW_OP_lit16";
4570 return "DW_OP_lit17";
4572 return "DW_OP_lit18";
4574 return "DW_OP_lit19";
4576 return "DW_OP_lit20";
4578 return "DW_OP_lit21";
4580 return "DW_OP_lit22";
4582 return "DW_OP_lit23";
4584 return "DW_OP_lit24";
4586 return "DW_OP_lit25";
4588 return "DW_OP_lit26";
4590 return "DW_OP_lit27";
4592 return "DW_OP_lit28";
4594 return "DW_OP_lit29";
4596 return "DW_OP_lit30";
4598 return "DW_OP_lit31";
4600 return "DW_OP_reg0";
4602 return "DW_OP_reg1";
4604 return "DW_OP_reg2";
4606 return "DW_OP_reg3";
4608 return "DW_OP_reg4";
4610 return "DW_OP_reg5";
4612 return "DW_OP_reg6";
4614 return "DW_OP_reg7";
4616 return "DW_OP_reg8";
4618 return "DW_OP_reg9";
4620 return "DW_OP_reg10";
4622 return "DW_OP_reg11";
4624 return "DW_OP_reg12";
4626 return "DW_OP_reg13";
4628 return "DW_OP_reg14";
4630 return "DW_OP_reg15";
4632 return "DW_OP_reg16";
4634 return "DW_OP_reg17";
4636 return "DW_OP_reg18";
4638 return "DW_OP_reg19";
4640 return "DW_OP_reg20";
4642 return "DW_OP_reg21";
4644 return "DW_OP_reg22";
4646 return "DW_OP_reg23";
4648 return "DW_OP_reg24";
4650 return "DW_OP_reg25";
4652 return "DW_OP_reg26";
4654 return "DW_OP_reg27";
4656 return "DW_OP_reg28";
4658 return "DW_OP_reg29";
4660 return "DW_OP_reg30";
4662 return "DW_OP_reg31";
4664 return "DW_OP_breg0";
4666 return "DW_OP_breg1";
4668 return "DW_OP_breg2";
4670 return "DW_OP_breg3";
4672 return "DW_OP_breg4";
4674 return "DW_OP_breg5";
4676 return "DW_OP_breg6";
4678 return "DW_OP_breg7";
4680 return "DW_OP_breg8";
4682 return "DW_OP_breg9";
4684 return "DW_OP_breg10";
4686 return "DW_OP_breg11";
4688 return "DW_OP_breg12";
4690 return "DW_OP_breg13";
4692 return "DW_OP_breg14";
4694 return "DW_OP_breg15";
4696 return "DW_OP_breg16";
4698 return "DW_OP_breg17";
4700 return "DW_OP_breg18";
4702 return "DW_OP_breg19";
4704 return "DW_OP_breg20";
4706 return "DW_OP_breg21";
4708 return "DW_OP_breg22";
4710 return "DW_OP_breg23";
4712 return "DW_OP_breg24";
4714 return "DW_OP_breg25";
4716 return "DW_OP_breg26";
4718 return "DW_OP_breg27";
4720 return "DW_OP_breg28";
4722 return "DW_OP_breg29";
4724 return "DW_OP_breg30";
4726 return "DW_OP_breg31";
4728 return "DW_OP_regx";
4730 return "DW_OP_fbreg";
4732 return "DW_OP_bregx";
4734 return "DW_OP_piece";
4735 case DW_OP_deref_size:
4736 return "DW_OP_deref_size";
4737 case DW_OP_xderef_size:
4738 return "DW_OP_xderef_size";
4742 case DW_OP_push_object_address:
4743 return "DW_OP_push_object_address";
4745 return "DW_OP_call2";
4747 return "DW_OP_call4";
4748 case DW_OP_call_ref:
4749 return "DW_OP_call_ref";
4750 case DW_OP_implicit_value:
4751 return "DW_OP_implicit_value";
4752 case DW_OP_stack_value:
4753 return "DW_OP_stack_value";
4754 case DW_OP_form_tls_address:
4755 return "DW_OP_form_tls_address";
4756 case DW_OP_call_frame_cfa:
4757 return "DW_OP_call_frame_cfa";
4758 case DW_OP_bit_piece:
4759 return "DW_OP_bit_piece";
4761 case DW_OP_GNU_push_tls_address:
4762 return "DW_OP_GNU_push_tls_address";
4763 case DW_OP_GNU_uninit:
4764 return "DW_OP_GNU_uninit";
4765 case DW_OP_GNU_encoded_addr:
4766 return "DW_OP_GNU_encoded_addr";
4767 case DW_OP_GNU_implicit_pointer:
4768 return "DW_OP_GNU_implicit_pointer";
4771 return "OP_<unknown>";
4775 /* Return a pointer to a newly allocated location description. Location
4776 descriptions are simple expression terms that can be strung
4777 together to form more complicated location (address) descriptions. */
4779 static inline dw_loc_descr_ref
4780 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4781 unsigned HOST_WIDE_INT oprnd2)
4783 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4785 descr->dw_loc_opc = op;
4786 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4787 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4788 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4789 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4794 /* Return a pointer to a newly allocated location description for
4797 static inline dw_loc_descr_ref
4798 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4801 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4804 return new_loc_descr (DW_OP_bregx, reg, offset);
4807 /* Add a location description term to a location description expression. */
4810 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4812 dw_loc_descr_ref *d;
4814 /* Find the end of the chain. */
4815 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4821 /* Add a constant OFFSET to a location expression. */
4824 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4826 dw_loc_descr_ref loc;
4829 gcc_assert (*list_head != NULL);
4834 /* Find the end of the chain. */
4835 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4839 if (loc->dw_loc_opc == DW_OP_fbreg
4840 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4841 p = &loc->dw_loc_oprnd1.v.val_int;
4842 else if (loc->dw_loc_opc == DW_OP_bregx)
4843 p = &loc->dw_loc_oprnd2.v.val_int;
4845 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4846 offset. Don't optimize if an signed integer overflow would happen. */
4848 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4849 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4852 else if (offset > 0)
4853 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4857 loc->dw_loc_next = int_loc_descriptor (-offset);
4858 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4862 /* Add a constant OFFSET to a location list. */
4865 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4868 for (d = list_head; d != NULL; d = d->dw_loc_next)
4869 loc_descr_plus_const (&d->expr, offset);
4872 #define DWARF_REF_SIZE \
4873 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4875 /* Return the size of a location descriptor. */
4877 static unsigned long
4878 size_of_loc_descr (dw_loc_descr_ref loc)
4880 unsigned long size = 1;
4882 switch (loc->dw_loc_opc)
4885 size += DWARF2_ADDR_SIZE;
4904 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4907 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4912 case DW_OP_plus_uconst:
4913 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4951 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4954 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4957 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4960 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4961 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4964 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4966 case DW_OP_bit_piece:
4967 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4968 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
4970 case DW_OP_deref_size:
4971 case DW_OP_xderef_size:
4980 case DW_OP_call_ref:
4981 size += DWARF_REF_SIZE;
4983 case DW_OP_implicit_value:
4984 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4985 + loc->dw_loc_oprnd1.v.val_unsigned;
4987 case DW_OP_GNU_implicit_pointer:
4988 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4997 /* Return the size of a series of location descriptors. */
4999 static unsigned long
5000 size_of_locs (dw_loc_descr_ref loc)
5005 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5006 field, to avoid writing to a PCH file. */
5007 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5009 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5011 size += size_of_loc_descr (l);
5016 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5018 l->dw_loc_addr = size;
5019 size += size_of_loc_descr (l);
5025 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5026 static void get_ref_die_offset_label (char *, dw_die_ref);
5028 /* Output location description stack opcode's operands (if any).
5029 The for_eh_or_skip parameter controls whether register numbers are
5030 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5031 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5032 info). This should be suppressed for the cases that have not been converted
5033 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5036 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5038 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5039 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5041 switch (loc->dw_loc_opc)
5043 #ifdef DWARF2_DEBUGGING_INFO
5046 dw2_asm_output_data (2, val1->v.val_int, NULL);
5051 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5052 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5054 fputc ('\n', asm_out_file);
5059 dw2_asm_output_data (4, val1->v.val_int, NULL);
5064 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5065 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5067 fputc ('\n', asm_out_file);
5072 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5073 dw2_asm_output_data (8, val1->v.val_int, NULL);
5080 gcc_assert (val1->val_class == dw_val_class_loc);
5081 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5083 dw2_asm_output_data (2, offset, NULL);
5086 case DW_OP_implicit_value:
5087 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5088 switch (val2->val_class)
5090 case dw_val_class_const:
5091 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5093 case dw_val_class_vec:
5095 unsigned int elt_size = val2->v.val_vec.elt_size;
5096 unsigned int len = val2->v.val_vec.length;
5100 if (elt_size > sizeof (HOST_WIDE_INT))
5105 for (i = 0, p = val2->v.val_vec.array;
5108 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5109 "fp or vector constant word %u", i);
5112 case dw_val_class_const_double:
5114 unsigned HOST_WIDE_INT first, second;
5116 if (WORDS_BIG_ENDIAN)
5118 first = val2->v.val_double.high;
5119 second = val2->v.val_double.low;
5123 first = val2->v.val_double.low;
5124 second = val2->v.val_double.high;
5126 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5128 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5132 case dw_val_class_addr:
5133 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5134 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5149 case DW_OP_implicit_value:
5150 /* We currently don't make any attempt to make sure these are
5151 aligned properly like we do for the main unwind info, so
5152 don't support emitting things larger than a byte if we're
5153 only doing unwinding. */
5158 dw2_asm_output_data (1, val1->v.val_int, NULL);
5161 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5164 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5167 dw2_asm_output_data (1, val1->v.val_int, NULL);
5169 case DW_OP_plus_uconst:
5170 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5204 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5208 unsigned r = val1->v.val_unsigned;
5209 if (for_eh_or_skip >= 0)
5210 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5211 gcc_assert (size_of_uleb128 (r)
5212 == size_of_uleb128 (val1->v.val_unsigned));
5213 dw2_asm_output_data_uleb128 (r, NULL);
5217 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5221 unsigned r = val1->v.val_unsigned;
5222 if (for_eh_or_skip >= 0)
5223 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5224 gcc_assert (size_of_uleb128 (r)
5225 == size_of_uleb128 (val1->v.val_unsigned));
5226 dw2_asm_output_data_uleb128 (r, NULL);
5227 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5231 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5233 case DW_OP_bit_piece:
5234 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5235 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5237 case DW_OP_deref_size:
5238 case DW_OP_xderef_size:
5239 dw2_asm_output_data (1, val1->v.val_int, NULL);
5245 if (targetm.asm_out.output_dwarf_dtprel)
5247 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5250 fputc ('\n', asm_out_file);
5257 #ifdef DWARF2_DEBUGGING_INFO
5258 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5265 case DW_OP_GNU_implicit_pointer:
5267 char label[MAX_ARTIFICIAL_LABEL_BYTES
5268 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5269 gcc_assert (val1->val_class == dw_val_class_die_ref);
5270 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5271 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5272 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5277 /* Other codes have no operands. */
5282 /* Output a sequence of location operations.
5283 The for_eh_or_skip parameter controls whether register numbers are
5284 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5285 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5286 info). This should be suppressed for the cases that have not been converted
5287 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5290 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5292 for (; loc != NULL; loc = loc->dw_loc_next)
5294 enum dwarf_location_atom opc = loc->dw_loc_opc;
5295 /* Output the opcode. */
5296 if (for_eh_or_skip >= 0
5297 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5299 unsigned r = (opc - DW_OP_breg0);
5300 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5301 gcc_assert (r <= 31);
5302 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5304 else if (for_eh_or_skip >= 0
5305 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5307 unsigned r = (opc - DW_OP_reg0);
5308 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5309 gcc_assert (r <= 31);
5310 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5313 dw2_asm_output_data (1, opc,
5314 "%s", dwarf_stack_op_name (opc));
5316 /* Output the operand(s) (if any). */
5317 output_loc_operands (loc, for_eh_or_skip);
5321 /* Output location description stack opcode's operands (if any).
5322 The output is single bytes on a line, suitable for .cfi_escape. */
5325 output_loc_operands_raw (dw_loc_descr_ref loc)
5327 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5328 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5330 switch (loc->dw_loc_opc)
5333 case DW_OP_implicit_value:
5334 /* We cannot output addresses in .cfi_escape, only bytes. */
5340 case DW_OP_deref_size:
5341 case DW_OP_xderef_size:
5342 fputc (',', asm_out_file);
5343 dw2_asm_output_data_raw (1, val1->v.val_int);
5348 fputc (',', asm_out_file);
5349 dw2_asm_output_data_raw (2, val1->v.val_int);
5354 fputc (',', asm_out_file);
5355 dw2_asm_output_data_raw (4, val1->v.val_int);
5360 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5361 fputc (',', asm_out_file);
5362 dw2_asm_output_data_raw (8, val1->v.val_int);
5370 gcc_assert (val1->val_class == dw_val_class_loc);
5371 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5373 fputc (',', asm_out_file);
5374 dw2_asm_output_data_raw (2, offset);
5380 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5381 gcc_assert (size_of_uleb128 (r)
5382 == size_of_uleb128 (val1->v.val_unsigned));
5383 fputc (',', asm_out_file);
5384 dw2_asm_output_data_uleb128_raw (r);
5389 case DW_OP_plus_uconst:
5391 fputc (',', asm_out_file);
5392 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5395 case DW_OP_bit_piece:
5396 fputc (',', asm_out_file);
5397 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5398 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5435 fputc (',', asm_out_file);
5436 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5441 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5442 gcc_assert (size_of_uleb128 (r)
5443 == size_of_uleb128 (val1->v.val_unsigned));
5444 fputc (',', asm_out_file);
5445 dw2_asm_output_data_uleb128_raw (r);
5446 fputc (',', asm_out_file);
5447 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5451 case DW_OP_GNU_implicit_pointer:
5456 /* Other codes have no operands. */
5462 output_loc_sequence_raw (dw_loc_descr_ref loc)
5466 enum dwarf_location_atom opc = loc->dw_loc_opc;
5467 /* Output the opcode. */
5468 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5470 unsigned r = (opc - DW_OP_breg0);
5471 r = DWARF2_FRAME_REG_OUT (r, 1);
5472 gcc_assert (r <= 31);
5473 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5475 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5477 unsigned r = (opc - DW_OP_reg0);
5478 r = DWARF2_FRAME_REG_OUT (r, 1);
5479 gcc_assert (r <= 31);
5480 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5482 /* Output the opcode. */
5483 fprintf (asm_out_file, "%#x", opc);
5484 output_loc_operands_raw (loc);
5486 if (!loc->dw_loc_next)
5488 loc = loc->dw_loc_next;
5490 fputc (',', asm_out_file);
5494 /* This routine will generate the correct assembly data for a location
5495 description based on a cfi entry with a complex address. */
5498 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5500 dw_loc_descr_ref loc;
5503 if (cfi->dw_cfi_opc == DW_CFA_expression)
5506 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5507 dw2_asm_output_data (1, r, NULL);
5508 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5511 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5513 /* Output the size of the block. */
5514 size = size_of_locs (loc);
5515 dw2_asm_output_data_uleb128 (size, NULL);
5517 /* Now output the operations themselves. */
5518 output_loc_sequence (loc, for_eh);
5521 /* Similar, but used for .cfi_escape. */
5524 output_cfa_loc_raw (dw_cfi_ref cfi)
5526 dw_loc_descr_ref loc;
5529 if (cfi->dw_cfi_opc == DW_CFA_expression)
5532 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5533 fprintf (asm_out_file, "%#x,", r);
5534 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5537 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5539 /* Output the size of the block. */
5540 size = size_of_locs (loc);
5541 dw2_asm_output_data_uleb128_raw (size);
5542 fputc (',', asm_out_file);
5544 /* Now output the operations themselves. */
5545 output_loc_sequence_raw (loc);
5548 /* This function builds a dwarf location descriptor sequence from a
5549 dw_cfa_location, adding the given OFFSET to the result of the
5552 static struct dw_loc_descr_struct *
5553 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5555 struct dw_loc_descr_struct *head, *tmp;
5557 offset += cfa->offset;
5561 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5562 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5563 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5564 add_loc_descr (&head, tmp);
5567 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5568 add_loc_descr (&head, tmp);
5572 head = new_reg_loc_descr (cfa->reg, offset);
5577 /* This function builds a dwarf location descriptor sequence for
5578 the address at OFFSET from the CFA when stack is aligned to
5581 static struct dw_loc_descr_struct *
5582 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5584 struct dw_loc_descr_struct *head;
5585 unsigned int dwarf_fp
5586 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5588 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5589 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5591 head = new_reg_loc_descr (dwarf_fp, 0);
5592 add_loc_descr (&head, int_loc_descriptor (alignment));
5593 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5594 loc_descr_plus_const (&head, offset);
5597 head = new_reg_loc_descr (dwarf_fp, offset);
5601 /* This function fills in aa dw_cfa_location structure from a dwarf location
5602 descriptor sequence. */
5605 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5607 struct dw_loc_descr_struct *ptr;
5609 cfa->base_offset = 0;
5613 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5615 enum dwarf_location_atom op = ptr->dw_loc_opc;
5651 cfa->reg = op - DW_OP_reg0;
5654 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5688 cfa->reg = op - DW_OP_breg0;
5689 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5692 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5693 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5698 case DW_OP_plus_uconst:
5699 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5702 internal_error ("DW_LOC_OP %s not implemented",
5703 dwarf_stack_op_name (ptr->dw_loc_opc));
5708 /* And now, the support for symbolic debugging information. */
5710 /* .debug_str support. */
5711 static int output_indirect_string (void **, void *);
5713 static void dwarf2out_init (const char *);
5714 static void dwarf2out_finish (const char *);
5715 static void dwarf2out_assembly_start (void);
5716 static void dwarf2out_define (unsigned int, const char *);
5717 static void dwarf2out_undef (unsigned int, const char *);
5718 static void dwarf2out_start_source_file (unsigned, const char *);
5719 static void dwarf2out_end_source_file (unsigned);
5720 static void dwarf2out_function_decl (tree);
5721 static void dwarf2out_begin_block (unsigned, unsigned);
5722 static void dwarf2out_end_block (unsigned, unsigned);
5723 static bool dwarf2out_ignore_block (const_tree);
5724 static void dwarf2out_global_decl (tree);
5725 static void dwarf2out_type_decl (tree, int);
5726 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5727 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5729 static void dwarf2out_abstract_function (tree);
5730 static void dwarf2out_var_location (rtx);
5731 static void dwarf2out_direct_call (tree);
5732 static void dwarf2out_virtual_call_token (tree, int);
5733 static void dwarf2out_copy_call_info (rtx, rtx);
5734 static void dwarf2out_virtual_call (int);
5735 static void dwarf2out_begin_function (tree);
5736 static void dwarf2out_set_name (tree, tree);
5738 /* The debug hooks structure. */
5740 const struct gcc_debug_hooks dwarf2_debug_hooks =
5744 dwarf2out_assembly_start,
5747 dwarf2out_start_source_file,
5748 dwarf2out_end_source_file,
5749 dwarf2out_begin_block,
5750 dwarf2out_end_block,
5751 dwarf2out_ignore_block,
5752 dwarf2out_source_line,
5753 dwarf2out_begin_prologue,
5754 #if VMS_DEBUGGING_INFO
5755 dwarf2out_vms_end_prologue,
5756 dwarf2out_vms_begin_epilogue,
5758 debug_nothing_int_charstar,
5759 debug_nothing_int_charstar,
5761 dwarf2out_end_epilogue,
5762 dwarf2out_begin_function,
5763 debug_nothing_int, /* end_function */
5764 dwarf2out_function_decl, /* function_decl */
5765 dwarf2out_global_decl,
5766 dwarf2out_type_decl, /* type_decl */
5767 dwarf2out_imported_module_or_decl,
5768 debug_nothing_tree, /* deferred_inline_function */
5769 /* The DWARF 2 backend tries to reduce debugging bloat by not
5770 emitting the abstract description of inline functions until
5771 something tries to reference them. */
5772 dwarf2out_abstract_function, /* outlining_inline_function */
5773 debug_nothing_rtx, /* label */
5774 debug_nothing_int, /* handle_pch */
5775 dwarf2out_var_location,
5776 dwarf2out_switch_text_section,
5777 dwarf2out_direct_call,
5778 dwarf2out_virtual_call_token,
5779 dwarf2out_copy_call_info,
5780 dwarf2out_virtual_call,
5782 1, /* start_end_main_source_file */
5783 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5786 /* NOTE: In the comments in this file, many references are made to
5787 "Debugging Information Entries". This term is abbreviated as `DIE'
5788 throughout the remainder of this file. */
5790 /* An internal representation of the DWARF output is built, and then
5791 walked to generate the DWARF debugging info. The walk of the internal
5792 representation is done after the entire program has been compiled.
5793 The types below are used to describe the internal representation. */
5795 /* Various DIE's use offsets relative to the beginning of the
5796 .debug_info section to refer to each other. */
5798 typedef long int dw_offset;
5800 /* Define typedefs here to avoid circular dependencies. */
5802 typedef struct dw_attr_struct *dw_attr_ref;
5803 typedef struct dw_line_info_struct *dw_line_info_ref;
5804 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5805 typedef struct pubname_struct *pubname_ref;
5806 typedef struct dw_ranges_struct *dw_ranges_ref;
5807 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5808 typedef struct comdat_type_struct *comdat_type_node_ref;
5810 /* Each entry in the line_info_table maintains the file and
5811 line number associated with the label generated for that
5812 entry. The label gives the PC value associated with
5813 the line number entry. */
5815 typedef struct GTY(()) dw_line_info_struct {
5816 unsigned long dw_file_num;
5817 unsigned long dw_line_num;
5821 /* Line information for functions in separate sections; each one gets its
5823 typedef struct GTY(()) dw_separate_line_info_struct {
5824 unsigned long dw_file_num;
5825 unsigned long dw_line_num;
5826 unsigned long function;
5828 dw_separate_line_info_entry;
5830 /* Each DIE attribute has a field specifying the attribute kind,
5831 a link to the next attribute in the chain, and an attribute value.
5832 Attributes are typically linked below the DIE they modify. */
5834 typedef struct GTY(()) dw_attr_struct {
5835 enum dwarf_attribute dw_attr;
5836 dw_val_node dw_attr_val;
5840 DEF_VEC_O(dw_attr_node);
5841 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5843 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5844 The children of each node form a circular list linked by
5845 die_sib. die_child points to the node *before* the "first" child node. */
5847 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5848 union die_symbol_or_type_node
5850 char * GTY ((tag ("0"))) die_symbol;
5851 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5853 GTY ((desc ("dwarf_version >= 4"))) die_id;
5854 VEC(dw_attr_node,gc) * die_attr;
5855 dw_die_ref die_parent;
5856 dw_die_ref die_child;
5858 dw_die_ref die_definition; /* ref from a specification to its definition */
5859 dw_offset die_offset;
5860 unsigned long die_abbrev;
5862 /* Die is used and must not be pruned as unused. */
5863 int die_perennial_p;
5864 unsigned int decl_id;
5865 enum dwarf_tag die_tag;
5869 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5870 #define FOR_EACH_CHILD(die, c, expr) do { \
5871 c = die->die_child; \
5875 } while (c != die->die_child); \
5878 /* The pubname structure */
5880 typedef struct GTY(()) pubname_struct {
5886 DEF_VEC_O(pubname_entry);
5887 DEF_VEC_ALLOC_O(pubname_entry, gc);
5889 struct GTY(()) dw_ranges_struct {
5890 /* If this is positive, it's a block number, otherwise it's a
5891 bitwise-negated index into dw_ranges_by_label. */
5895 /* A structure to hold a macinfo entry. */
5897 typedef struct GTY(()) macinfo_struct {
5898 unsigned HOST_WIDE_INT code;
5899 unsigned HOST_WIDE_INT lineno;
5904 DEF_VEC_O(macinfo_entry);
5905 DEF_VEC_ALLOC_O(macinfo_entry, gc);
5907 struct GTY(()) dw_ranges_by_label_struct {
5912 /* The comdat type node structure. */
5913 typedef struct GTY(()) comdat_type_struct
5915 dw_die_ref root_die;
5916 dw_die_ref type_die;
5917 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5918 struct comdat_type_struct *next;
5922 /* The limbo die list structure. */
5923 typedef struct GTY(()) limbo_die_struct {
5926 struct limbo_die_struct *next;
5930 typedef struct skeleton_chain_struct
5934 struct skeleton_chain_struct *parent;
5936 skeleton_chain_node;
5938 /* How to start an assembler comment. */
5939 #ifndef ASM_COMMENT_START
5940 #define ASM_COMMENT_START ";#"
5943 /* Define a macro which returns nonzero for a TYPE_DECL which was
5944 implicitly generated for a tagged type.
5946 Note that unlike the gcc front end (which generates a NULL named
5947 TYPE_DECL node for each complete tagged type, each array type, and
5948 each function type node created) the g++ front end generates a
5949 _named_ TYPE_DECL node for each tagged type node created.
5950 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5951 generate a DW_TAG_typedef DIE for them. */
5953 #define TYPE_DECL_IS_STUB(decl) \
5954 (DECL_NAME (decl) == NULL_TREE \
5955 || (DECL_ARTIFICIAL (decl) \
5956 && is_tagged_type (TREE_TYPE (decl)) \
5957 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5958 /* This is necessary for stub decls that \
5959 appear in nested inline functions. */ \
5960 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5961 && (decl_ultimate_origin (decl) \
5962 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5964 /* Information concerning the compilation unit's programming
5965 language, and compiler version. */
5967 /* Fixed size portion of the DWARF compilation unit header. */
5968 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5969 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5971 /* Fixed size portion of the DWARF comdat type unit header. */
5972 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
5973 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
5974 + DWARF_OFFSET_SIZE)
5976 /* Fixed size portion of public names info. */
5977 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5979 /* Fixed size portion of the address range info. */
5980 #define DWARF_ARANGES_HEADER_SIZE \
5981 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5982 DWARF2_ADDR_SIZE * 2) \
5983 - DWARF_INITIAL_LENGTH_SIZE)
5985 /* Size of padding portion in the address range info. It must be
5986 aligned to twice the pointer size. */
5987 #define DWARF_ARANGES_PAD_SIZE \
5988 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5989 DWARF2_ADDR_SIZE * 2) \
5990 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5992 /* Use assembler line directives if available. */
5993 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5994 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5995 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5997 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6001 /* Minimum line offset in a special line info. opcode.
6002 This value was chosen to give a reasonable range of values. */
6003 #define DWARF_LINE_BASE -10
6005 /* First special line opcode - leave room for the standard opcodes. */
6006 #define DWARF_LINE_OPCODE_BASE 10
6008 /* Range of line offsets in a special line info. opcode. */
6009 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6011 /* Flag that indicates the initial value of the is_stmt_start flag.
6012 In the present implementation, we do not mark any lines as
6013 the beginning of a source statement, because that information
6014 is not made available by the GCC front-end. */
6015 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6017 /* Maximum number of operations per instruction bundle. */
6018 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6019 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6022 /* This location is used by calc_die_sizes() to keep track
6023 the offset of each DIE within the .debug_info section. */
6024 static unsigned long next_die_offset;
6026 /* Record the root of the DIE's built for the current compilation unit. */
6027 static GTY(()) dw_die_ref single_comp_unit_die;
6029 /* A list of type DIEs that have been separated into comdat sections. */
6030 static GTY(()) comdat_type_node *comdat_type_list;
6032 /* A list of DIEs with a NULL parent waiting to be relocated. */
6033 static GTY(()) limbo_die_node *limbo_die_list;
6035 /* A list of DIEs for which we may have to generate
6036 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6037 static GTY(()) limbo_die_node *deferred_asm_name;
6039 /* Filenames referenced by this compilation unit. */
6040 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6042 /* A hash table of references to DIE's that describe declarations.
6043 The key is a DECL_UID() which is a unique number identifying each decl. */
6044 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6046 /* A hash table of references to DIE's that describe COMMON blocks.
6047 The key is DECL_UID() ^ die_parent. */
6048 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6050 typedef struct GTY(()) die_arg_entry_struct {
6055 DEF_VEC_O(die_arg_entry);
6056 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6058 /* Node of the variable location list. */
6059 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6060 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6061 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6062 in mode of the EXPR_LIST node and first EXPR_LIST operand
6063 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6064 location or NULL for padding. For larger bitsizes,
6065 mode is 0 and first operand is a CONCAT with bitsize
6066 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6067 NULL as second operand. */
6069 const char * GTY (()) label;
6070 struct var_loc_node * GTY (()) next;
6073 /* Variable location list. */
6074 struct GTY (()) var_loc_list_def {
6075 struct var_loc_node * GTY (()) first;
6077 /* Pointer to the last but one or last element of the
6078 chained list. If the list is empty, both first and
6079 last are NULL, if the list contains just one node
6080 or the last node certainly is not redundant, it points
6081 to the last node, otherwise points to the last but one.
6082 Do not mark it for GC because it is marked through the chain. */
6083 struct var_loc_node * GTY ((skip ("%h"))) last;
6085 /* Pointer to the last element before section switch,
6086 if NULL, either sections weren't switched or first
6087 is after section switch. */
6088 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
6090 /* DECL_UID of the variable decl. */
6091 unsigned int decl_id;
6093 typedef struct var_loc_list_def var_loc_list;
6096 /* Table of decl location linked lists. */
6097 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6099 /* A cached location list. */
6100 struct GTY (()) cached_dw_loc_list_def {
6101 /* The DECL_UID of the decl that this entry describes. */
6102 unsigned int decl_id;
6104 /* The cached location list. */
6105 dw_loc_list_ref loc_list;
6107 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
6109 /* Table of cached location lists. */
6110 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
6112 /* A pointer to the base of a list of references to DIE's that
6113 are uniquely identified by their tag, presence/absence of
6114 children DIE's, and list of attribute/value pairs. */
6115 static GTY((length ("abbrev_die_table_allocated")))
6116 dw_die_ref *abbrev_die_table;
6118 /* Number of elements currently allocated for abbrev_die_table. */
6119 static GTY(()) unsigned abbrev_die_table_allocated;
6121 /* Number of elements in type_die_table currently in use. */
6122 static GTY(()) unsigned abbrev_die_table_in_use;
6124 /* Size (in elements) of increments by which we may expand the
6125 abbrev_die_table. */
6126 #define ABBREV_DIE_TABLE_INCREMENT 256
6128 /* A pointer to the base of a table that contains line information
6129 for each source code line in .text in the compilation unit. */
6130 static GTY((length ("line_info_table_allocated")))
6131 dw_line_info_ref line_info_table;
6133 /* Number of elements currently allocated for line_info_table. */
6134 static GTY(()) unsigned line_info_table_allocated;
6136 /* Number of elements in line_info_table currently in use. */
6137 static GTY(()) unsigned line_info_table_in_use;
6139 /* A pointer to the base of a table that contains line information
6140 for each source code line outside of .text in the compilation unit. */
6141 static GTY ((length ("separate_line_info_table_allocated")))
6142 dw_separate_line_info_ref separate_line_info_table;
6144 /* Number of elements currently allocated for separate_line_info_table. */
6145 static GTY(()) unsigned separate_line_info_table_allocated;
6147 /* Number of elements in separate_line_info_table currently in use. */
6148 static GTY(()) unsigned separate_line_info_table_in_use;
6150 /* Size (in elements) of increments by which we may expand the
6152 #define LINE_INFO_TABLE_INCREMENT 1024
6154 /* A flag to tell pubnames/types export if there is an info section to
6156 static bool info_section_emitted;
6158 /* A pointer to the base of a table that contains a list of publicly
6159 accessible names. */
6160 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6162 /* A pointer to the base of a table that contains a list of publicly
6163 accessible types. */
6164 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6166 /* A pointer to the base of a table that contains a list of macro
6167 defines/undefines (and file start/end markers). */
6168 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6170 /* Array of dies for which we should generate .debug_ranges info. */
6171 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6173 /* Number of elements currently allocated for ranges_table. */
6174 static GTY(()) unsigned ranges_table_allocated;
6176 /* Number of elements in ranges_table currently in use. */
6177 static GTY(()) unsigned ranges_table_in_use;
6179 /* Array of pairs of labels referenced in ranges_table. */
6180 static GTY ((length ("ranges_by_label_allocated")))
6181 dw_ranges_by_label_ref ranges_by_label;
6183 /* Number of elements currently allocated for ranges_by_label. */
6184 static GTY(()) unsigned ranges_by_label_allocated;
6186 /* Number of elements in ranges_by_label currently in use. */
6187 static GTY(()) unsigned ranges_by_label_in_use;
6189 /* Size (in elements) of increments by which we may expand the
6191 #define RANGES_TABLE_INCREMENT 64
6193 /* Whether we have location lists that need outputting */
6194 static GTY(()) bool have_location_lists;
6196 /* Unique label counter. */
6197 static GTY(()) unsigned int loclabel_num;
6199 /* Unique label counter for point-of-call tables. */
6200 static GTY(()) unsigned int poc_label_num;
6202 /* The direct call table structure. */
6204 typedef struct GTY(()) dcall_struct {
6205 unsigned int poc_label_num;
6207 dw_die_ref targ_die;
6211 DEF_VEC_O(dcall_entry);
6212 DEF_VEC_ALLOC_O(dcall_entry, gc);
6214 /* The virtual call table structure. */
6216 typedef struct GTY(()) vcall_struct {
6217 unsigned int poc_label_num;
6218 unsigned int vtable_slot;
6222 DEF_VEC_O(vcall_entry);
6223 DEF_VEC_ALLOC_O(vcall_entry, gc);
6225 /* Pointers to the direct and virtual call tables. */
6226 static GTY (()) VEC (dcall_entry, gc) * dcall_table = NULL;
6227 static GTY (()) VEC (vcall_entry, gc) * vcall_table = NULL;
6229 /* A hash table to map INSN_UIDs to vtable slot indexes. */
6231 struct GTY (()) vcall_insn {
6233 unsigned int vtable_slot;
6236 static GTY ((param_is (struct vcall_insn))) htab_t vcall_insn_table;
6238 /* Record whether the function being analyzed contains inlined functions. */
6239 static int current_function_has_inlines;
6241 /* The last file entry emitted by maybe_emit_file(). */
6242 static GTY(()) struct dwarf_file_data * last_emitted_file;
6244 /* Number of internal labels generated by gen_internal_sym(). */
6245 static GTY(()) int label_num;
6247 /* Cached result of previous call to lookup_filename. */
6248 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6250 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6252 /* Instances of generic types for which we need to generate debug
6253 info that describe their generic parameters and arguments. That
6254 generation needs to happen once all types are properly laid out so
6255 we do it at the end of compilation. */
6256 static GTY(()) VEC(tree,gc) *generic_type_instances;
6258 /* Offset from the "steady-state frame pointer" to the frame base,
6259 within the current function. */
6260 static HOST_WIDE_INT frame_pointer_fb_offset;
6261 static bool frame_pointer_fb_offset_valid;
6263 /* Forward declarations for functions defined in this file. */
6265 static int is_pseudo_reg (const_rtx);
6266 static tree type_main_variant (tree);
6267 static int is_tagged_type (const_tree);
6268 static const char *dwarf_tag_name (unsigned);
6269 static const char *dwarf_attr_name (unsigned);
6270 static const char *dwarf_form_name (unsigned);
6271 static tree decl_ultimate_origin (const_tree);
6272 static tree decl_class_context (tree);
6273 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6274 static inline enum dw_val_class AT_class (dw_attr_ref);
6275 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6276 static inline unsigned AT_flag (dw_attr_ref);
6277 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6278 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6279 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6280 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6281 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6282 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6283 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6284 unsigned int, unsigned char *);
6285 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6286 static hashval_t debug_str_do_hash (const void *);
6287 static int debug_str_eq (const void *, const void *);
6288 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6289 static inline const char *AT_string (dw_attr_ref);
6290 static enum dwarf_form AT_string_form (dw_attr_ref);
6291 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6292 static void add_AT_specification (dw_die_ref, dw_die_ref);
6293 static inline dw_die_ref AT_ref (dw_attr_ref);
6294 static inline int AT_ref_external (dw_attr_ref);
6295 static inline void set_AT_ref_external (dw_attr_ref, int);
6296 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6297 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6298 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6299 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6301 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6302 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6303 static inline rtx AT_addr (dw_attr_ref);
6304 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6305 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6306 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6307 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6308 unsigned HOST_WIDE_INT);
6309 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6311 static inline const char *AT_lbl (dw_attr_ref);
6312 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6313 static const char *get_AT_low_pc (dw_die_ref);
6314 static const char *get_AT_hi_pc (dw_die_ref);
6315 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6316 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6317 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6318 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6319 static bool is_cxx (void);
6320 static bool is_fortran (void);
6321 static bool is_ada (void);
6322 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6323 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6324 static void add_child_die (dw_die_ref, dw_die_ref);
6325 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6326 static dw_die_ref lookup_type_die (tree);
6327 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6328 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6329 static void equate_type_number_to_die (tree, dw_die_ref);
6330 static hashval_t decl_die_table_hash (const void *);
6331 static int decl_die_table_eq (const void *, const void *);
6332 static dw_die_ref lookup_decl_die (tree);
6333 static hashval_t common_block_die_table_hash (const void *);
6334 static int common_block_die_table_eq (const void *, const void *);
6335 static hashval_t decl_loc_table_hash (const void *);
6336 static int decl_loc_table_eq (const void *, const void *);
6337 static var_loc_list *lookup_decl_loc (const_tree);
6338 static void equate_decl_number_to_die (tree, dw_die_ref);
6339 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6340 static void print_spaces (FILE *);
6341 static void print_die (dw_die_ref, FILE *);
6342 static void print_dwarf_line_table (FILE *);
6343 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6344 static dw_die_ref pop_compile_unit (dw_die_ref);
6345 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6346 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6347 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6348 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6349 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6350 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6351 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6352 struct md5_ctx *, int *);
6353 struct checksum_attributes;
6354 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6355 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6356 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6357 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6358 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6359 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6360 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6361 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6362 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6363 static void compute_section_prefix (dw_die_ref);
6364 static int is_type_die (dw_die_ref);
6365 static int is_comdat_die (dw_die_ref);
6366 static int is_symbol_die (dw_die_ref);
6367 static void assign_symbol_names (dw_die_ref);
6368 static void break_out_includes (dw_die_ref);
6369 static int is_declaration_die (dw_die_ref);
6370 static int should_move_die_to_comdat (dw_die_ref);
6371 static dw_die_ref clone_as_declaration (dw_die_ref);
6372 static dw_die_ref clone_die (dw_die_ref);
6373 static dw_die_ref clone_tree (dw_die_ref);
6374 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6375 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6376 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6377 static dw_die_ref generate_skeleton (dw_die_ref);
6378 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6380 static void break_out_comdat_types (dw_die_ref);
6381 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6382 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6383 static void copy_decls_for_unworthy_types (dw_die_ref);
6385 static hashval_t htab_cu_hash (const void *);
6386 static int htab_cu_eq (const void *, const void *);
6387 static void htab_cu_del (void *);
6388 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6389 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6390 static void add_sibling_attributes (dw_die_ref);
6391 static void build_abbrev_table (dw_die_ref);
6392 static void output_location_lists (dw_die_ref);
6393 static int constant_size (unsigned HOST_WIDE_INT);
6394 static unsigned long size_of_die (dw_die_ref);
6395 static void calc_die_sizes (dw_die_ref);
6396 static void mark_dies (dw_die_ref);
6397 static void unmark_dies (dw_die_ref);
6398 static void unmark_all_dies (dw_die_ref);
6399 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6400 static unsigned long size_of_aranges (void);
6401 static enum dwarf_form value_format (dw_attr_ref);
6402 static void output_value_format (dw_attr_ref);
6403 static void output_abbrev_section (void);
6404 static void output_die_symbol (dw_die_ref);
6405 static void output_die (dw_die_ref);
6406 static void output_compilation_unit_header (void);
6407 static void output_comp_unit (dw_die_ref, int);
6408 static void output_comdat_type_unit (comdat_type_node *);
6409 static const char *dwarf2_name (tree, int);
6410 static void add_pubname (tree, dw_die_ref);
6411 static void add_pubname_string (const char *, dw_die_ref);
6412 static void add_pubtype (tree, dw_die_ref);
6413 static void output_pubnames (VEC (pubname_entry,gc) *);
6414 static void output_aranges (unsigned long);
6415 static unsigned int add_ranges_num (int);
6416 static unsigned int add_ranges (const_tree);
6417 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6419 static void output_ranges (void);
6420 static void output_line_info (void);
6421 static void output_file_names (void);
6422 static dw_die_ref base_type_die (tree);
6423 static int is_base_type (tree);
6424 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6425 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6426 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6427 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6428 static int type_is_enum (const_tree);
6429 static unsigned int dbx_reg_number (const_rtx);
6430 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6431 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6432 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6433 enum var_init_status);
6434 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6435 enum var_init_status);
6436 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6437 enum var_init_status);
6438 static int is_based_loc (const_rtx);
6439 static int resolve_one_addr (rtx *, void *);
6440 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6441 enum var_init_status);
6442 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6443 enum var_init_status);
6444 static dw_loc_list_ref loc_list_from_tree (tree, int);
6445 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6446 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6447 static tree field_type (const_tree);
6448 static unsigned int simple_type_align_in_bits (const_tree);
6449 static unsigned int simple_decl_align_in_bits (const_tree);
6450 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6451 static HOST_WIDE_INT field_byte_offset (const_tree);
6452 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6454 static void add_data_member_location_attribute (dw_die_ref, tree);
6455 static bool add_const_value_attribute (dw_die_ref, rtx);
6456 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6457 static void insert_double (double_int, unsigned char *);
6458 static void insert_float (const_rtx, unsigned char *);
6459 static rtx rtl_for_decl_location (tree);
6460 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
6461 enum dwarf_attribute);
6462 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6463 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6464 static void add_name_attribute (dw_die_ref, const char *);
6465 static void add_comp_dir_attribute (dw_die_ref);
6466 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6467 static void add_subscript_info (dw_die_ref, tree, bool);
6468 static void add_byte_size_attribute (dw_die_ref, tree);
6469 static void add_bit_offset_attribute (dw_die_ref, tree);
6470 static void add_bit_size_attribute (dw_die_ref, tree);
6471 static void add_prototyped_attribute (dw_die_ref, tree);
6472 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6473 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6474 static void add_src_coords_attributes (dw_die_ref, tree);
6475 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6476 static void push_decl_scope (tree);
6477 static void pop_decl_scope (void);
6478 static dw_die_ref scope_die_for (tree, dw_die_ref);
6479 static inline int local_scope_p (dw_die_ref);
6480 static inline int class_scope_p (dw_die_ref);
6481 static inline int class_or_namespace_scope_p (dw_die_ref);
6482 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6483 static void add_calling_convention_attribute (dw_die_ref, tree);
6484 static const char *type_tag (const_tree);
6485 static tree member_declared_type (const_tree);
6487 static const char *decl_start_label (tree);
6489 static void gen_array_type_die (tree, dw_die_ref);
6490 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6492 static void gen_entry_point_die (tree, dw_die_ref);
6494 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6495 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6496 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6497 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6498 static void gen_formal_types_die (tree, dw_die_ref);
6499 static void gen_subprogram_die (tree, dw_die_ref);
6500 static void gen_variable_die (tree, tree, dw_die_ref);
6501 static void gen_const_die (tree, dw_die_ref);
6502 static void gen_label_die (tree, dw_die_ref);
6503 static void gen_lexical_block_die (tree, dw_die_ref, int);
6504 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6505 static void gen_field_die (tree, dw_die_ref);
6506 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6507 static dw_die_ref gen_compile_unit_die (const char *);
6508 static void gen_inheritance_die (tree, tree, dw_die_ref);
6509 static void gen_member_die (tree, dw_die_ref);
6510 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6511 enum debug_info_usage);
6512 static void gen_subroutine_type_die (tree, dw_die_ref);
6513 static void gen_typedef_die (tree, dw_die_ref);
6514 static void gen_type_die (tree, dw_die_ref);
6515 static void gen_block_die (tree, dw_die_ref, int);
6516 static void decls_for_scope (tree, dw_die_ref, int);
6517 static inline int is_redundant_typedef (const_tree);
6518 static bool is_naming_typedef_decl (const_tree);
6519 static inline dw_die_ref get_context_die (tree);
6520 static void gen_namespace_die (tree, dw_die_ref);
6521 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6522 static dw_die_ref force_decl_die (tree);
6523 static dw_die_ref force_type_die (tree);
6524 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6525 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6526 static struct dwarf_file_data * lookup_filename (const char *);
6527 static void retry_incomplete_types (void);
6528 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6529 static void gen_generic_params_dies (tree);
6530 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6531 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6532 static void splice_child_die (dw_die_ref, dw_die_ref);
6533 static int file_info_cmp (const void *, const void *);
6534 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6535 const char *, const char *);
6536 static void output_loc_list (dw_loc_list_ref);
6537 static char *gen_internal_sym (const char *);
6539 static void prune_unmark_dies (dw_die_ref);
6540 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6541 static void prune_unused_types_mark (dw_die_ref, int);
6542 static void prune_unused_types_walk (dw_die_ref);
6543 static void prune_unused_types_walk_attribs (dw_die_ref);
6544 static void prune_unused_types_prune (dw_die_ref);
6545 static void prune_unused_types (void);
6546 static int maybe_emit_file (struct dwarf_file_data *fd);
6547 static inline const char *AT_vms_delta1 (dw_attr_ref);
6548 static inline const char *AT_vms_delta2 (dw_attr_ref);
6549 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6550 const char *, const char *);
6551 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6552 static void gen_remaining_tmpl_value_param_die_attribute (void);
6553 static bool generic_type_p (tree);
6554 static void schedule_generic_params_dies_gen (tree t);
6555 static void gen_scheduled_generic_parms_dies (void);
6557 /* Section names used to hold DWARF debugging information. */
6558 #ifndef DEBUG_INFO_SECTION
6559 #define DEBUG_INFO_SECTION ".debug_info"
6561 #ifndef DEBUG_ABBREV_SECTION
6562 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6564 #ifndef DEBUG_ARANGES_SECTION
6565 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6567 #ifndef DEBUG_MACINFO_SECTION
6568 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6570 #ifndef DEBUG_LINE_SECTION
6571 #define DEBUG_LINE_SECTION ".debug_line"
6573 #ifndef DEBUG_LOC_SECTION
6574 #define DEBUG_LOC_SECTION ".debug_loc"
6576 #ifndef DEBUG_PUBNAMES_SECTION
6577 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6579 #ifndef DEBUG_PUBTYPES_SECTION
6580 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6582 #ifndef DEBUG_DCALL_SECTION
6583 #define DEBUG_DCALL_SECTION ".debug_dcall"
6585 #ifndef DEBUG_VCALL_SECTION
6586 #define DEBUG_VCALL_SECTION ".debug_vcall"
6588 #ifndef DEBUG_STR_SECTION
6589 #define DEBUG_STR_SECTION ".debug_str"
6591 #ifndef DEBUG_RANGES_SECTION
6592 #define DEBUG_RANGES_SECTION ".debug_ranges"
6595 /* Standard ELF section names for compiled code and data. */
6596 #ifndef TEXT_SECTION_NAME
6597 #define TEXT_SECTION_NAME ".text"
6600 /* Section flags for .debug_str section. */
6601 #define DEBUG_STR_SECTION_FLAGS \
6602 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6603 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6606 /* Labels we insert at beginning sections we can reference instead of
6607 the section names themselves. */
6609 #ifndef TEXT_SECTION_LABEL
6610 #define TEXT_SECTION_LABEL "Ltext"
6612 #ifndef COLD_TEXT_SECTION_LABEL
6613 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6615 #ifndef DEBUG_LINE_SECTION_LABEL
6616 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6618 #ifndef DEBUG_INFO_SECTION_LABEL
6619 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6621 #ifndef DEBUG_ABBREV_SECTION_LABEL
6622 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6624 #ifndef DEBUG_LOC_SECTION_LABEL
6625 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6627 #ifndef DEBUG_RANGES_SECTION_LABEL
6628 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6630 #ifndef DEBUG_MACINFO_SECTION_LABEL
6631 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6635 /* Definitions of defaults for formats and names of various special
6636 (artificial) labels which may be generated within this file (when the -g
6637 options is used and DWARF2_DEBUGGING_INFO is in effect.
6638 If necessary, these may be overridden from within the tm.h file, but
6639 typically, overriding these defaults is unnecessary. */
6641 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6642 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6643 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6644 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6645 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6646 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6647 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6648 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6649 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6650 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6652 #ifndef TEXT_END_LABEL
6653 #define TEXT_END_LABEL "Letext"
6655 #ifndef COLD_END_LABEL
6656 #define COLD_END_LABEL "Letext_cold"
6658 #ifndef BLOCK_BEGIN_LABEL
6659 #define BLOCK_BEGIN_LABEL "LBB"
6661 #ifndef BLOCK_END_LABEL
6662 #define BLOCK_END_LABEL "LBE"
6664 #ifndef LINE_CODE_LABEL
6665 #define LINE_CODE_LABEL "LM"
6667 #ifndef SEPARATE_LINE_CODE_LABEL
6668 #define SEPARATE_LINE_CODE_LABEL "LSM"
6672 /* Return the root of the DIE's built for the current compilation unit. */
6674 comp_unit_die (void)
6676 if (!single_comp_unit_die)
6677 single_comp_unit_die = gen_compile_unit_die (NULL);
6678 return single_comp_unit_die;
6681 /* We allow a language front-end to designate a function that is to be
6682 called to "demangle" any name before it is put into a DIE. */
6684 static const char *(*demangle_name_func) (const char *);
6687 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6689 demangle_name_func = func;
6692 /* Test if rtl node points to a pseudo register. */
6695 is_pseudo_reg (const_rtx rtl)
6697 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6698 || (GET_CODE (rtl) == SUBREG
6699 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6702 /* Return a reference to a type, with its const and volatile qualifiers
6706 type_main_variant (tree type)
6708 type = TYPE_MAIN_VARIANT (type);
6710 /* ??? There really should be only one main variant among any group of
6711 variants of a given type (and all of the MAIN_VARIANT values for all
6712 members of the group should point to that one type) but sometimes the C
6713 front-end messes this up for array types, so we work around that bug
6715 if (TREE_CODE (type) == ARRAY_TYPE)
6716 while (type != TYPE_MAIN_VARIANT (type))
6717 type = TYPE_MAIN_VARIANT (type);
6722 /* Return nonzero if the given type node represents a tagged type. */
6725 is_tagged_type (const_tree type)
6727 enum tree_code code = TREE_CODE (type);
6729 return (code == RECORD_TYPE || code == UNION_TYPE
6730 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6733 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6736 get_ref_die_offset_label (char *label, dw_die_ref ref)
6738 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6741 /* Convert a DIE tag into its string name. */
6744 dwarf_tag_name (unsigned int tag)
6748 case DW_TAG_padding:
6749 return "DW_TAG_padding";
6750 case DW_TAG_array_type:
6751 return "DW_TAG_array_type";
6752 case DW_TAG_class_type:
6753 return "DW_TAG_class_type";
6754 case DW_TAG_entry_point:
6755 return "DW_TAG_entry_point";
6756 case DW_TAG_enumeration_type:
6757 return "DW_TAG_enumeration_type";
6758 case DW_TAG_formal_parameter:
6759 return "DW_TAG_formal_parameter";
6760 case DW_TAG_imported_declaration:
6761 return "DW_TAG_imported_declaration";
6763 return "DW_TAG_label";
6764 case DW_TAG_lexical_block:
6765 return "DW_TAG_lexical_block";
6767 return "DW_TAG_member";
6768 case DW_TAG_pointer_type:
6769 return "DW_TAG_pointer_type";
6770 case DW_TAG_reference_type:
6771 return "DW_TAG_reference_type";
6772 case DW_TAG_compile_unit:
6773 return "DW_TAG_compile_unit";
6774 case DW_TAG_string_type:
6775 return "DW_TAG_string_type";
6776 case DW_TAG_structure_type:
6777 return "DW_TAG_structure_type";
6778 case DW_TAG_subroutine_type:
6779 return "DW_TAG_subroutine_type";
6780 case DW_TAG_typedef:
6781 return "DW_TAG_typedef";
6782 case DW_TAG_union_type:
6783 return "DW_TAG_union_type";
6784 case DW_TAG_unspecified_parameters:
6785 return "DW_TAG_unspecified_parameters";
6786 case DW_TAG_variant:
6787 return "DW_TAG_variant";
6788 case DW_TAG_common_block:
6789 return "DW_TAG_common_block";
6790 case DW_TAG_common_inclusion:
6791 return "DW_TAG_common_inclusion";
6792 case DW_TAG_inheritance:
6793 return "DW_TAG_inheritance";
6794 case DW_TAG_inlined_subroutine:
6795 return "DW_TAG_inlined_subroutine";
6797 return "DW_TAG_module";
6798 case DW_TAG_ptr_to_member_type:
6799 return "DW_TAG_ptr_to_member_type";
6800 case DW_TAG_set_type:
6801 return "DW_TAG_set_type";
6802 case DW_TAG_subrange_type:
6803 return "DW_TAG_subrange_type";
6804 case DW_TAG_with_stmt:
6805 return "DW_TAG_with_stmt";
6806 case DW_TAG_access_declaration:
6807 return "DW_TAG_access_declaration";
6808 case DW_TAG_base_type:
6809 return "DW_TAG_base_type";
6810 case DW_TAG_catch_block:
6811 return "DW_TAG_catch_block";
6812 case DW_TAG_const_type:
6813 return "DW_TAG_const_type";
6814 case DW_TAG_constant:
6815 return "DW_TAG_constant";
6816 case DW_TAG_enumerator:
6817 return "DW_TAG_enumerator";
6818 case DW_TAG_file_type:
6819 return "DW_TAG_file_type";
6821 return "DW_TAG_friend";
6822 case DW_TAG_namelist:
6823 return "DW_TAG_namelist";
6824 case DW_TAG_namelist_item:
6825 return "DW_TAG_namelist_item";
6826 case DW_TAG_packed_type:
6827 return "DW_TAG_packed_type";
6828 case DW_TAG_subprogram:
6829 return "DW_TAG_subprogram";
6830 case DW_TAG_template_type_param:
6831 return "DW_TAG_template_type_param";
6832 case DW_TAG_template_value_param:
6833 return "DW_TAG_template_value_param";
6834 case DW_TAG_thrown_type:
6835 return "DW_TAG_thrown_type";
6836 case DW_TAG_try_block:
6837 return "DW_TAG_try_block";
6838 case DW_TAG_variant_part:
6839 return "DW_TAG_variant_part";
6840 case DW_TAG_variable:
6841 return "DW_TAG_variable";
6842 case DW_TAG_volatile_type:
6843 return "DW_TAG_volatile_type";
6844 case DW_TAG_dwarf_procedure:
6845 return "DW_TAG_dwarf_procedure";
6846 case DW_TAG_restrict_type:
6847 return "DW_TAG_restrict_type";
6848 case DW_TAG_interface_type:
6849 return "DW_TAG_interface_type";
6850 case DW_TAG_namespace:
6851 return "DW_TAG_namespace";
6852 case DW_TAG_imported_module:
6853 return "DW_TAG_imported_module";
6854 case DW_TAG_unspecified_type:
6855 return "DW_TAG_unspecified_type";
6856 case DW_TAG_partial_unit:
6857 return "DW_TAG_partial_unit";
6858 case DW_TAG_imported_unit:
6859 return "DW_TAG_imported_unit";
6860 case DW_TAG_condition:
6861 return "DW_TAG_condition";
6862 case DW_TAG_shared_type:
6863 return "DW_TAG_shared_type";
6864 case DW_TAG_type_unit:
6865 return "DW_TAG_type_unit";
6866 case DW_TAG_rvalue_reference_type:
6867 return "DW_TAG_rvalue_reference_type";
6868 case DW_TAG_template_alias:
6869 return "DW_TAG_template_alias";
6870 case DW_TAG_GNU_template_parameter_pack:
6871 return "DW_TAG_GNU_template_parameter_pack";
6872 case DW_TAG_GNU_formal_parameter_pack:
6873 return "DW_TAG_GNU_formal_parameter_pack";
6874 case DW_TAG_MIPS_loop:
6875 return "DW_TAG_MIPS_loop";
6876 case DW_TAG_format_label:
6877 return "DW_TAG_format_label";
6878 case DW_TAG_function_template:
6879 return "DW_TAG_function_template";
6880 case DW_TAG_class_template:
6881 return "DW_TAG_class_template";
6882 case DW_TAG_GNU_BINCL:
6883 return "DW_TAG_GNU_BINCL";
6884 case DW_TAG_GNU_EINCL:
6885 return "DW_TAG_GNU_EINCL";
6886 case DW_TAG_GNU_template_template_param:
6887 return "DW_TAG_GNU_template_template_param";
6889 return "DW_TAG_<unknown>";
6893 /* Convert a DWARF attribute code into its string name. */
6896 dwarf_attr_name (unsigned int attr)
6901 return "DW_AT_sibling";
6902 case DW_AT_location:
6903 return "DW_AT_location";
6905 return "DW_AT_name";
6906 case DW_AT_ordering:
6907 return "DW_AT_ordering";
6908 case DW_AT_subscr_data:
6909 return "DW_AT_subscr_data";
6910 case DW_AT_byte_size:
6911 return "DW_AT_byte_size";
6912 case DW_AT_bit_offset:
6913 return "DW_AT_bit_offset";
6914 case DW_AT_bit_size:
6915 return "DW_AT_bit_size";
6916 case DW_AT_element_list:
6917 return "DW_AT_element_list";
6918 case DW_AT_stmt_list:
6919 return "DW_AT_stmt_list";
6921 return "DW_AT_low_pc";
6923 return "DW_AT_high_pc";
6924 case DW_AT_language:
6925 return "DW_AT_language";
6927 return "DW_AT_member";
6929 return "DW_AT_discr";
6930 case DW_AT_discr_value:
6931 return "DW_AT_discr_value";
6932 case DW_AT_visibility:
6933 return "DW_AT_visibility";
6935 return "DW_AT_import";
6936 case DW_AT_string_length:
6937 return "DW_AT_string_length";
6938 case DW_AT_common_reference:
6939 return "DW_AT_common_reference";
6940 case DW_AT_comp_dir:
6941 return "DW_AT_comp_dir";
6942 case DW_AT_const_value:
6943 return "DW_AT_const_value";
6944 case DW_AT_containing_type:
6945 return "DW_AT_containing_type";
6946 case DW_AT_default_value:
6947 return "DW_AT_default_value";
6949 return "DW_AT_inline";
6950 case DW_AT_is_optional:
6951 return "DW_AT_is_optional";
6952 case DW_AT_lower_bound:
6953 return "DW_AT_lower_bound";
6954 case DW_AT_producer:
6955 return "DW_AT_producer";
6956 case DW_AT_prototyped:
6957 return "DW_AT_prototyped";
6958 case DW_AT_return_addr:
6959 return "DW_AT_return_addr";
6960 case DW_AT_start_scope:
6961 return "DW_AT_start_scope";
6962 case DW_AT_bit_stride:
6963 return "DW_AT_bit_stride";
6964 case DW_AT_upper_bound:
6965 return "DW_AT_upper_bound";
6966 case DW_AT_abstract_origin:
6967 return "DW_AT_abstract_origin";
6968 case DW_AT_accessibility:
6969 return "DW_AT_accessibility";
6970 case DW_AT_address_class:
6971 return "DW_AT_address_class";
6972 case DW_AT_artificial:
6973 return "DW_AT_artificial";
6974 case DW_AT_base_types:
6975 return "DW_AT_base_types";
6976 case DW_AT_calling_convention:
6977 return "DW_AT_calling_convention";
6979 return "DW_AT_count";
6980 case DW_AT_data_member_location:
6981 return "DW_AT_data_member_location";
6982 case DW_AT_decl_column:
6983 return "DW_AT_decl_column";
6984 case DW_AT_decl_file:
6985 return "DW_AT_decl_file";
6986 case DW_AT_decl_line:
6987 return "DW_AT_decl_line";
6988 case DW_AT_declaration:
6989 return "DW_AT_declaration";
6990 case DW_AT_discr_list:
6991 return "DW_AT_discr_list";
6992 case DW_AT_encoding:
6993 return "DW_AT_encoding";
6994 case DW_AT_external:
6995 return "DW_AT_external";
6996 case DW_AT_explicit:
6997 return "DW_AT_explicit";
6998 case DW_AT_frame_base:
6999 return "DW_AT_frame_base";
7001 return "DW_AT_friend";
7002 case DW_AT_identifier_case:
7003 return "DW_AT_identifier_case";
7004 case DW_AT_macro_info:
7005 return "DW_AT_macro_info";
7006 case DW_AT_namelist_items:
7007 return "DW_AT_namelist_items";
7008 case DW_AT_priority:
7009 return "DW_AT_priority";
7011 return "DW_AT_segment";
7012 case DW_AT_specification:
7013 return "DW_AT_specification";
7014 case DW_AT_static_link:
7015 return "DW_AT_static_link";
7017 return "DW_AT_type";
7018 case DW_AT_use_location:
7019 return "DW_AT_use_location";
7020 case DW_AT_variable_parameter:
7021 return "DW_AT_variable_parameter";
7022 case DW_AT_virtuality:
7023 return "DW_AT_virtuality";
7024 case DW_AT_vtable_elem_location:
7025 return "DW_AT_vtable_elem_location";
7027 case DW_AT_allocated:
7028 return "DW_AT_allocated";
7029 case DW_AT_associated:
7030 return "DW_AT_associated";
7031 case DW_AT_data_location:
7032 return "DW_AT_data_location";
7033 case DW_AT_byte_stride:
7034 return "DW_AT_byte_stride";
7035 case DW_AT_entry_pc:
7036 return "DW_AT_entry_pc";
7037 case DW_AT_use_UTF8:
7038 return "DW_AT_use_UTF8";
7039 case DW_AT_extension:
7040 return "DW_AT_extension";
7042 return "DW_AT_ranges";
7043 case DW_AT_trampoline:
7044 return "DW_AT_trampoline";
7045 case DW_AT_call_column:
7046 return "DW_AT_call_column";
7047 case DW_AT_call_file:
7048 return "DW_AT_call_file";
7049 case DW_AT_call_line:
7050 return "DW_AT_call_line";
7051 case DW_AT_object_pointer:
7052 return "DW_AT_object_pointer";
7054 case DW_AT_signature:
7055 return "DW_AT_signature";
7056 case DW_AT_main_subprogram:
7057 return "DW_AT_main_subprogram";
7058 case DW_AT_data_bit_offset:
7059 return "DW_AT_data_bit_offset";
7060 case DW_AT_const_expr:
7061 return "DW_AT_const_expr";
7062 case DW_AT_enum_class:
7063 return "DW_AT_enum_class";
7064 case DW_AT_linkage_name:
7065 return "DW_AT_linkage_name";
7067 case DW_AT_MIPS_fde:
7068 return "DW_AT_MIPS_fde";
7069 case DW_AT_MIPS_loop_begin:
7070 return "DW_AT_MIPS_loop_begin";
7071 case DW_AT_MIPS_tail_loop_begin:
7072 return "DW_AT_MIPS_tail_loop_begin";
7073 case DW_AT_MIPS_epilog_begin:
7074 return "DW_AT_MIPS_epilog_begin";
7075 #if VMS_DEBUGGING_INFO
7076 case DW_AT_HP_prologue:
7077 return "DW_AT_HP_prologue";
7079 case DW_AT_MIPS_loop_unroll_factor:
7080 return "DW_AT_MIPS_loop_unroll_factor";
7082 case DW_AT_MIPS_software_pipeline_depth:
7083 return "DW_AT_MIPS_software_pipeline_depth";
7084 case DW_AT_MIPS_linkage_name:
7085 return "DW_AT_MIPS_linkage_name";
7086 #if VMS_DEBUGGING_INFO
7087 case DW_AT_HP_epilogue:
7088 return "DW_AT_HP_epilogue";
7090 case DW_AT_MIPS_stride:
7091 return "DW_AT_MIPS_stride";
7093 case DW_AT_MIPS_abstract_name:
7094 return "DW_AT_MIPS_abstract_name";
7095 case DW_AT_MIPS_clone_origin:
7096 return "DW_AT_MIPS_clone_origin";
7097 case DW_AT_MIPS_has_inlines:
7098 return "DW_AT_MIPS_has_inlines";
7100 case DW_AT_sf_names:
7101 return "DW_AT_sf_names";
7102 case DW_AT_src_info:
7103 return "DW_AT_src_info";
7104 case DW_AT_mac_info:
7105 return "DW_AT_mac_info";
7106 case DW_AT_src_coords:
7107 return "DW_AT_src_coords";
7108 case DW_AT_body_begin:
7109 return "DW_AT_body_begin";
7110 case DW_AT_body_end:
7111 return "DW_AT_body_end";
7112 case DW_AT_GNU_vector:
7113 return "DW_AT_GNU_vector";
7114 case DW_AT_GNU_guarded_by:
7115 return "DW_AT_GNU_guarded_by";
7116 case DW_AT_GNU_pt_guarded_by:
7117 return "DW_AT_GNU_pt_guarded_by";
7118 case DW_AT_GNU_guarded:
7119 return "DW_AT_GNU_guarded";
7120 case DW_AT_GNU_pt_guarded:
7121 return "DW_AT_GNU_pt_guarded";
7122 case DW_AT_GNU_locks_excluded:
7123 return "DW_AT_GNU_locks_excluded";
7124 case DW_AT_GNU_exclusive_locks_required:
7125 return "DW_AT_GNU_exclusive_locks_required";
7126 case DW_AT_GNU_shared_locks_required:
7127 return "DW_AT_GNU_shared_locks_required";
7128 case DW_AT_GNU_odr_signature:
7129 return "DW_AT_GNU_odr_signature";
7130 case DW_AT_GNU_template_name:
7131 return "DW_AT_GNU_template_name";
7133 case DW_AT_VMS_rtnbeg_pd_address:
7134 return "DW_AT_VMS_rtnbeg_pd_address";
7137 return "DW_AT_<unknown>";
7141 /* Convert a DWARF value form code into its string name. */
7144 dwarf_form_name (unsigned int form)
7149 return "DW_FORM_addr";
7150 case DW_FORM_block2:
7151 return "DW_FORM_block2";
7152 case DW_FORM_block4:
7153 return "DW_FORM_block4";
7155 return "DW_FORM_data2";
7157 return "DW_FORM_data4";
7159 return "DW_FORM_data8";
7160 case DW_FORM_string:
7161 return "DW_FORM_string";
7163 return "DW_FORM_block";
7164 case DW_FORM_block1:
7165 return "DW_FORM_block1";
7167 return "DW_FORM_data1";
7169 return "DW_FORM_flag";
7171 return "DW_FORM_sdata";
7173 return "DW_FORM_strp";
7175 return "DW_FORM_udata";
7176 case DW_FORM_ref_addr:
7177 return "DW_FORM_ref_addr";
7179 return "DW_FORM_ref1";
7181 return "DW_FORM_ref2";
7183 return "DW_FORM_ref4";
7185 return "DW_FORM_ref8";
7186 case DW_FORM_ref_udata:
7187 return "DW_FORM_ref_udata";
7188 case DW_FORM_indirect:
7189 return "DW_FORM_indirect";
7190 case DW_FORM_sec_offset:
7191 return "DW_FORM_sec_offset";
7192 case DW_FORM_exprloc:
7193 return "DW_FORM_exprloc";
7194 case DW_FORM_flag_present:
7195 return "DW_FORM_flag_present";
7196 case DW_FORM_ref_sig8:
7197 return "DW_FORM_ref_sig8";
7199 return "DW_FORM_<unknown>";
7203 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7204 instance of an inlined instance of a decl which is local to an inline
7205 function, so we have to trace all of the way back through the origin chain
7206 to find out what sort of node actually served as the original seed for the
7210 decl_ultimate_origin (const_tree decl)
7212 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7215 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7216 nodes in the function to point to themselves; ignore that if
7217 we're trying to output the abstract instance of this function. */
7218 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7221 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7222 most distant ancestor, this should never happen. */
7223 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7225 return DECL_ABSTRACT_ORIGIN (decl);
7228 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7229 of a virtual function may refer to a base class, so we check the 'this'
7233 decl_class_context (tree decl)
7235 tree context = NULL_TREE;
7237 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7238 context = DECL_CONTEXT (decl);
7240 context = TYPE_MAIN_VARIANT
7241 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7243 if (context && !TYPE_P (context))
7244 context = NULL_TREE;
7249 /* Add an attribute/value pair to a DIE. */
7252 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7254 /* Maybe this should be an assert? */
7258 if (die->die_attr == NULL)
7259 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7260 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7263 static inline enum dw_val_class
7264 AT_class (dw_attr_ref a)
7266 return a->dw_attr_val.val_class;
7269 /* Add a flag value attribute to a DIE. */
7272 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7276 attr.dw_attr = attr_kind;
7277 attr.dw_attr_val.val_class = dw_val_class_flag;
7278 attr.dw_attr_val.v.val_flag = flag;
7279 add_dwarf_attr (die, &attr);
7282 static inline unsigned
7283 AT_flag (dw_attr_ref a)
7285 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7286 return a->dw_attr_val.v.val_flag;
7289 /* Add a signed integer attribute value to a DIE. */
7292 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7296 attr.dw_attr = attr_kind;
7297 attr.dw_attr_val.val_class = dw_val_class_const;
7298 attr.dw_attr_val.v.val_int = int_val;
7299 add_dwarf_attr (die, &attr);
7302 static inline HOST_WIDE_INT
7303 AT_int (dw_attr_ref a)
7305 gcc_assert (a && AT_class (a) == dw_val_class_const);
7306 return a->dw_attr_val.v.val_int;
7309 /* Add an unsigned integer attribute value to a DIE. */
7312 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7313 unsigned HOST_WIDE_INT unsigned_val)
7317 attr.dw_attr = attr_kind;
7318 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7319 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7320 add_dwarf_attr (die, &attr);
7323 static inline unsigned HOST_WIDE_INT
7324 AT_unsigned (dw_attr_ref a)
7326 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7327 return a->dw_attr_val.v.val_unsigned;
7330 /* Add an unsigned double integer attribute value to a DIE. */
7333 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7334 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7338 attr.dw_attr = attr_kind;
7339 attr.dw_attr_val.val_class = dw_val_class_const_double;
7340 attr.dw_attr_val.v.val_double.high = high;
7341 attr.dw_attr_val.v.val_double.low = low;
7342 add_dwarf_attr (die, &attr);
7345 /* Add a floating point attribute value to a DIE and return it. */
7348 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7349 unsigned int length, unsigned int elt_size, unsigned char *array)
7353 attr.dw_attr = attr_kind;
7354 attr.dw_attr_val.val_class = dw_val_class_vec;
7355 attr.dw_attr_val.v.val_vec.length = length;
7356 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7357 attr.dw_attr_val.v.val_vec.array = array;
7358 add_dwarf_attr (die, &attr);
7361 /* Add an 8-byte data attribute value to a DIE. */
7364 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7365 unsigned char data8[8])
7369 attr.dw_attr = attr_kind;
7370 attr.dw_attr_val.val_class = dw_val_class_data8;
7371 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7372 add_dwarf_attr (die, &attr);
7375 /* Hash and equality functions for debug_str_hash. */
7378 debug_str_do_hash (const void *x)
7380 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7384 debug_str_eq (const void *x1, const void *x2)
7386 return strcmp ((((const struct indirect_string_node *)x1)->str),
7387 (const char *)x2) == 0;
7390 /* Add STR to the indirect string hash table. */
7392 static struct indirect_string_node *
7393 find_AT_string (const char *str)
7395 struct indirect_string_node *node;
7398 if (! debug_str_hash)
7399 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7400 debug_str_eq, NULL);
7402 slot = htab_find_slot_with_hash (debug_str_hash, str,
7403 htab_hash_string (str), INSERT);
7406 node = ggc_alloc_cleared_indirect_string_node ();
7407 node->str = ggc_strdup (str);
7411 node = (struct indirect_string_node *) *slot;
7417 /* Add a string attribute value to a DIE. */
7420 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7423 struct indirect_string_node *node;
7425 node = find_AT_string (str);
7427 attr.dw_attr = attr_kind;
7428 attr.dw_attr_val.val_class = dw_val_class_str;
7429 attr.dw_attr_val.v.val_str = node;
7430 add_dwarf_attr (die, &attr);
7433 /* Create a label for an indirect string node, ensuring it is going to
7434 be output, unless its reference count goes down to zero. */
7437 gen_label_for_indirect_string (struct indirect_string_node *node)
7444 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7445 ++dw2_string_counter;
7446 node->label = xstrdup (label);
7449 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7450 debug string STR. */
7453 get_debug_string_label (const char *str)
7455 struct indirect_string_node *node = find_AT_string (str);
7457 debug_str_hash_forced = true;
7459 gen_label_for_indirect_string (node);
7461 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7464 static inline const char *
7465 AT_string (dw_attr_ref a)
7467 gcc_assert (a && AT_class (a) == dw_val_class_str);
7468 return a->dw_attr_val.v.val_str->str;
7471 /* Find out whether a string should be output inline in DIE
7472 or out-of-line in .debug_str section. */
7474 static enum dwarf_form
7475 AT_string_form (dw_attr_ref a)
7477 struct indirect_string_node *node;
7480 gcc_assert (a && AT_class (a) == dw_val_class_str);
7482 node = a->dw_attr_val.v.val_str;
7486 len = strlen (node->str) + 1;
7488 /* If the string is shorter or equal to the size of the reference, it is
7489 always better to put it inline. */
7490 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7491 return node->form = DW_FORM_string;
7493 /* If we cannot expect the linker to merge strings in .debug_str
7494 section, only put it into .debug_str if it is worth even in this
7496 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7497 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7498 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7499 return node->form = DW_FORM_string;
7501 gen_label_for_indirect_string (node);
7503 return node->form = DW_FORM_strp;
7506 /* Add a DIE reference attribute value to a DIE. */
7509 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7513 #ifdef ENABLE_CHECKING
7514 gcc_assert (targ_die != NULL);
7516 /* With LTO we can end up trying to reference something we didn't create
7517 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7518 if (targ_die == NULL)
7522 attr.dw_attr = attr_kind;
7523 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7524 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7525 attr.dw_attr_val.v.val_die_ref.external = 0;
7526 add_dwarf_attr (die, &attr);
7529 /* Add an AT_specification attribute to a DIE, and also make the back
7530 pointer from the specification to the definition. */
7533 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7535 add_AT_die_ref (die, DW_AT_specification, targ_die);
7536 gcc_assert (!targ_die->die_definition);
7537 targ_die->die_definition = die;
7540 static inline dw_die_ref
7541 AT_ref (dw_attr_ref a)
7543 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7544 return a->dw_attr_val.v.val_die_ref.die;
7548 AT_ref_external (dw_attr_ref a)
7550 if (a && AT_class (a) == dw_val_class_die_ref)
7551 return a->dw_attr_val.v.val_die_ref.external;
7557 set_AT_ref_external (dw_attr_ref a, int i)
7559 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7560 a->dw_attr_val.v.val_die_ref.external = i;
7563 /* Add an FDE reference attribute value to a DIE. */
7566 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7570 attr.dw_attr = attr_kind;
7571 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7572 attr.dw_attr_val.v.val_fde_index = targ_fde;
7573 add_dwarf_attr (die, &attr);
7576 /* Add a location description attribute value to a DIE. */
7579 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7583 attr.dw_attr = attr_kind;
7584 attr.dw_attr_val.val_class = dw_val_class_loc;
7585 attr.dw_attr_val.v.val_loc = loc;
7586 add_dwarf_attr (die, &attr);
7589 static inline dw_loc_descr_ref
7590 AT_loc (dw_attr_ref a)
7592 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7593 return a->dw_attr_val.v.val_loc;
7597 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7601 attr.dw_attr = attr_kind;
7602 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7603 attr.dw_attr_val.v.val_loc_list = loc_list;
7604 add_dwarf_attr (die, &attr);
7605 have_location_lists = true;
7608 static inline dw_loc_list_ref
7609 AT_loc_list (dw_attr_ref a)
7611 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7612 return a->dw_attr_val.v.val_loc_list;
7615 static inline dw_loc_list_ref *
7616 AT_loc_list_ptr (dw_attr_ref a)
7618 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7619 return &a->dw_attr_val.v.val_loc_list;
7622 /* Add an address constant attribute value to a DIE. */
7625 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7629 attr.dw_attr = attr_kind;
7630 attr.dw_attr_val.val_class = dw_val_class_addr;
7631 attr.dw_attr_val.v.val_addr = addr;
7632 add_dwarf_attr (die, &attr);
7635 /* Get the RTX from to an address DIE attribute. */
7638 AT_addr (dw_attr_ref a)
7640 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7641 return a->dw_attr_val.v.val_addr;
7644 /* Add a file attribute value to a DIE. */
7647 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7648 struct dwarf_file_data *fd)
7652 attr.dw_attr = attr_kind;
7653 attr.dw_attr_val.val_class = dw_val_class_file;
7654 attr.dw_attr_val.v.val_file = fd;
7655 add_dwarf_attr (die, &attr);
7658 /* Get the dwarf_file_data from a file DIE attribute. */
7660 static inline struct dwarf_file_data *
7661 AT_file (dw_attr_ref a)
7663 gcc_assert (a && AT_class (a) == dw_val_class_file);
7664 return a->dw_attr_val.v.val_file;
7667 /* Add a vms delta attribute value to a DIE. */
7670 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7671 const char *lbl1, const char *lbl2)
7675 attr.dw_attr = attr_kind;
7676 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7677 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7678 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7679 add_dwarf_attr (die, &attr);
7682 /* Add a label identifier attribute value to a DIE. */
7685 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7689 attr.dw_attr = attr_kind;
7690 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7691 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7692 add_dwarf_attr (die, &attr);
7695 /* Add a section offset attribute value to a DIE, an offset into the
7696 debug_line section. */
7699 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7704 attr.dw_attr = attr_kind;
7705 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7706 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7707 add_dwarf_attr (die, &attr);
7710 /* Add a section offset attribute value to a DIE, an offset into the
7711 debug_macinfo section. */
7714 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7719 attr.dw_attr = attr_kind;
7720 attr.dw_attr_val.val_class = dw_val_class_macptr;
7721 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7722 add_dwarf_attr (die, &attr);
7725 /* Add an offset attribute value to a DIE. */
7728 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7729 unsigned HOST_WIDE_INT offset)
7733 attr.dw_attr = attr_kind;
7734 attr.dw_attr_val.val_class = dw_val_class_offset;
7735 attr.dw_attr_val.v.val_offset = offset;
7736 add_dwarf_attr (die, &attr);
7739 /* Add an range_list attribute value to a DIE. */
7742 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7743 long unsigned int offset)
7747 attr.dw_attr = attr_kind;
7748 attr.dw_attr_val.val_class = dw_val_class_range_list;
7749 attr.dw_attr_val.v.val_offset = offset;
7750 add_dwarf_attr (die, &attr);
7753 /* Return the start label of a delta attribute. */
7755 static inline const char *
7756 AT_vms_delta1 (dw_attr_ref a)
7758 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7759 return a->dw_attr_val.v.val_vms_delta.lbl1;
7762 /* Return the end label of a delta attribute. */
7764 static inline const char *
7765 AT_vms_delta2 (dw_attr_ref a)
7767 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7768 return a->dw_attr_val.v.val_vms_delta.lbl2;
7771 static inline const char *
7772 AT_lbl (dw_attr_ref a)
7774 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7775 || AT_class (a) == dw_val_class_lineptr
7776 || AT_class (a) == dw_val_class_macptr));
7777 return a->dw_attr_val.v.val_lbl_id;
7780 /* Get the attribute of type attr_kind. */
7783 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7787 dw_die_ref spec = NULL;
7792 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7793 if (a->dw_attr == attr_kind)
7795 else if (a->dw_attr == DW_AT_specification
7796 || a->dw_attr == DW_AT_abstract_origin)
7800 return get_AT (spec, attr_kind);
7805 /* Return the "low pc" attribute value, typically associated with a subprogram
7806 DIE. Return null if the "low pc" attribute is either not present, or if it
7807 cannot be represented as an assembler label identifier. */
7809 static inline const char *
7810 get_AT_low_pc (dw_die_ref die)
7812 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7814 return a ? AT_lbl (a) : NULL;
7817 /* Return the "high pc" attribute value, typically associated with a subprogram
7818 DIE. Return null if the "high pc" attribute is either not present, or if it
7819 cannot be represented as an assembler label identifier. */
7821 static inline const char *
7822 get_AT_hi_pc (dw_die_ref die)
7824 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7826 return a ? AT_lbl (a) : NULL;
7829 /* Return the value of the string attribute designated by ATTR_KIND, or
7830 NULL if it is not present. */
7832 static inline const char *
7833 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7835 dw_attr_ref a = get_AT (die, attr_kind);
7837 return a ? AT_string (a) : NULL;
7840 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7841 if it is not present. */
7844 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7846 dw_attr_ref a = get_AT (die, attr_kind);
7848 return a ? AT_flag (a) : 0;
7851 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7852 if it is not present. */
7854 static inline unsigned
7855 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7857 dw_attr_ref a = get_AT (die, attr_kind);
7859 return a ? AT_unsigned (a) : 0;
7862 static inline dw_die_ref
7863 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7865 dw_attr_ref a = get_AT (die, attr_kind);
7867 return a ? AT_ref (a) : NULL;
7870 static inline struct dwarf_file_data *
7871 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7873 dw_attr_ref a = get_AT (die, attr_kind);
7875 return a ? AT_file (a) : NULL;
7878 /* Return TRUE if the language is C++. */
7883 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7885 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7888 /* Return TRUE if the language is Fortran. */
7893 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7895 return (lang == DW_LANG_Fortran77
7896 || lang == DW_LANG_Fortran90
7897 || lang == DW_LANG_Fortran95);
7900 /* Return TRUE if the language is Ada. */
7905 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7907 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7910 /* Remove the specified attribute if present. */
7913 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7921 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7922 if (a->dw_attr == attr_kind)
7924 if (AT_class (a) == dw_val_class_str)
7925 if (a->dw_attr_val.v.val_str->refcount)
7926 a->dw_attr_val.v.val_str->refcount--;
7928 /* VEC_ordered_remove should help reduce the number of abbrevs
7930 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7935 /* Remove CHILD from its parent. PREV must have the property that
7936 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7939 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7941 gcc_assert (child->die_parent == prev->die_parent);
7942 gcc_assert (prev->die_sib == child);
7945 gcc_assert (child->die_parent->die_child == child);
7949 prev->die_sib = child->die_sib;
7950 if (child->die_parent->die_child == child)
7951 child->die_parent->die_child = prev;
7954 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7955 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7958 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
7960 dw_die_ref parent = old_child->die_parent;
7962 gcc_assert (parent == prev->die_parent);
7963 gcc_assert (prev->die_sib == old_child);
7965 new_child->die_parent = parent;
7966 if (prev == old_child)
7968 gcc_assert (parent->die_child == old_child);
7969 new_child->die_sib = new_child;
7973 prev->die_sib = new_child;
7974 new_child->die_sib = old_child->die_sib;
7976 if (old_child->die_parent->die_child == old_child)
7977 old_child->die_parent->die_child = new_child;
7980 /* Move all children from OLD_PARENT to NEW_PARENT. */
7983 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
7986 new_parent->die_child = old_parent->die_child;
7987 old_parent->die_child = NULL;
7988 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
7991 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7995 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8001 dw_die_ref prev = c;
8003 while (c->die_tag == tag)
8005 remove_child_with_prev (c, prev);
8006 /* Might have removed every child. */
8007 if (c == c->die_sib)
8011 } while (c != die->die_child);
8014 /* Add a CHILD_DIE as the last child of DIE. */
8017 add_child_die (dw_die_ref die, dw_die_ref child_die)
8019 /* FIXME this should probably be an assert. */
8020 if (! die || ! child_die)
8022 gcc_assert (die != child_die);
8024 child_die->die_parent = die;
8027 child_die->die_sib = die->die_child->die_sib;
8028 die->die_child->die_sib = child_die;
8031 child_die->die_sib = child_die;
8032 die->die_child = child_die;
8035 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8036 is the specification, to the end of PARENT's list of children.
8037 This is done by removing and re-adding it. */
8040 splice_child_die (dw_die_ref parent, dw_die_ref child)
8044 /* We want the declaration DIE from inside the class, not the
8045 specification DIE at toplevel. */
8046 if (child->die_parent != parent)
8048 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8054 gcc_assert (child->die_parent == parent
8055 || (child->die_parent
8056 == get_AT_ref (parent, DW_AT_specification)));
8058 for (p = child->die_parent->die_child; ; p = p->die_sib)
8059 if (p->die_sib == child)
8061 remove_child_with_prev (child, p);
8065 add_child_die (parent, child);
8068 /* Return a pointer to a newly created DIE node. */
8070 static inline dw_die_ref
8071 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8073 dw_die_ref die = ggc_alloc_cleared_die_node ();
8075 die->die_tag = tag_value;
8077 if (parent_die != NULL)
8078 add_child_die (parent_die, die);
8081 limbo_die_node *limbo_node;
8083 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8084 limbo_node->die = die;
8085 limbo_node->created_for = t;
8086 limbo_node->next = limbo_die_list;
8087 limbo_die_list = limbo_node;
8093 /* Return the DIE associated with the given type specifier. */
8095 static inline dw_die_ref
8096 lookup_type_die (tree type)
8098 return TYPE_SYMTAB_DIE (type);
8101 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8102 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8103 anonymous type instead the one of the naming typedef. */
8105 static inline dw_die_ref
8106 strip_naming_typedef (tree type, dw_die_ref type_die)
8109 && TREE_CODE (type) == RECORD_TYPE
8111 && type_die->die_tag == DW_TAG_typedef
8112 && is_naming_typedef_decl (TYPE_NAME (type)))
8113 type_die = get_AT_ref (type_die, DW_AT_type);
8117 /* Like lookup_type_die, but if type is an anonymous type named by a
8118 typedef[1], return the DIE of the anonymous type instead the one of
8119 the naming typedef. This is because in gen_typedef_die, we did
8120 equate the anonymous struct named by the typedef with the DIE of
8121 the naming typedef. So by default, lookup_type_die on an anonymous
8122 struct yields the DIE of the naming typedef.
8124 [1]: Read the comment of is_naming_typedef_decl to learn about what
8125 a naming typedef is. */
8127 static inline dw_die_ref
8128 lookup_type_die_strip_naming_typedef (tree type)
8130 dw_die_ref die = lookup_type_die (type);
8131 return strip_naming_typedef (type, die);
8134 /* Equate a DIE to a given type specifier. */
8137 equate_type_number_to_die (tree type, dw_die_ref type_die)
8139 TYPE_SYMTAB_DIE (type) = type_die;
8142 /* Returns a hash value for X (which really is a die_struct). */
8145 decl_die_table_hash (const void *x)
8147 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8150 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8153 decl_die_table_eq (const void *x, const void *y)
8155 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8158 /* Return the DIE associated with a given declaration. */
8160 static inline dw_die_ref
8161 lookup_decl_die (tree decl)
8163 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8166 /* Returns a hash value for X (which really is a var_loc_list). */
8169 decl_loc_table_hash (const void *x)
8171 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8174 /* Return nonzero if decl_id of var_loc_list X is the same as
8178 decl_loc_table_eq (const void *x, const void *y)
8180 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8183 /* Return the var_loc list associated with a given declaration. */
8185 static inline var_loc_list *
8186 lookup_decl_loc (const_tree decl)
8188 if (!decl_loc_table)
8190 return (var_loc_list *)
8191 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8194 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
8197 cached_dw_loc_list_table_hash (const void *x)
8199 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
8202 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
8206 cached_dw_loc_list_table_eq (const void *x, const void *y)
8208 return (((const cached_dw_loc_list *) x)->decl_id
8209 == DECL_UID ((const_tree) y));
8212 /* Equate a DIE to a particular declaration. */
8215 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8217 unsigned int decl_id = DECL_UID (decl);
8220 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8222 decl_die->decl_id = decl_id;
8225 /* Return how many bits covers PIECE EXPR_LIST. */
8228 decl_piece_bitsize (rtx piece)
8230 int ret = (int) GET_MODE (piece);
8233 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8234 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8235 return INTVAL (XEXP (XEXP (piece, 0), 0));
8238 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8241 decl_piece_varloc_ptr (rtx piece)
8243 if ((int) GET_MODE (piece))
8244 return &XEXP (piece, 0);
8246 return &XEXP (XEXP (piece, 0), 1);
8249 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8250 Next is the chain of following piece nodes. */
8253 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8255 if (bitsize <= (int) MAX_MACHINE_MODE)
8256 return alloc_EXPR_LIST (bitsize, loc_note, next);
8258 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8263 /* Return rtx that should be stored into loc field for
8264 LOC_NOTE and BITPOS/BITSIZE. */
8267 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8268 HOST_WIDE_INT bitsize)
8272 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8274 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8279 /* This function either modifies location piece list *DEST in
8280 place (if SRC and INNER is NULL), or copies location piece list
8281 *SRC to *DEST while modifying it. Location BITPOS is modified
8282 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8283 not copied and if needed some padding around it is added.
8284 When modifying in place, DEST should point to EXPR_LIST where
8285 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8286 to the start of the whole list and INNER points to the EXPR_LIST
8287 where earlier pieces cover PIECE_BITPOS bits. */
8290 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8291 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8292 HOST_WIDE_INT bitsize, rtx loc_note)
8295 bool copy = inner != NULL;
8299 /* First copy all nodes preceeding the current bitpos. */
8300 while (src != inner)
8302 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8303 decl_piece_bitsize (*src), NULL_RTX);
8304 dest = &XEXP (*dest, 1);
8305 src = &XEXP (*src, 1);
8308 /* Add padding if needed. */
8309 if (bitpos != piece_bitpos)
8311 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8312 copy ? NULL_RTX : *dest);
8313 dest = &XEXP (*dest, 1);
8315 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8318 /* A piece with correct bitpos and bitsize already exist,
8319 just update the location for it and return. */
8320 *decl_piece_varloc_ptr (*dest) = loc_note;
8323 /* Add the piece that changed. */
8324 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8325 dest = &XEXP (*dest, 1);
8326 /* Skip over pieces that overlap it. */
8327 diff = bitpos - piece_bitpos + bitsize;
8330 while (diff > 0 && *src)
8333 diff -= decl_piece_bitsize (piece);
8335 src = &XEXP (piece, 1);
8338 *src = XEXP (piece, 1);
8339 free_EXPR_LIST_node (piece);
8342 /* Add padding if needed. */
8343 if (diff < 0 && *src)
8347 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8348 dest = &XEXP (*dest, 1);
8352 /* Finally copy all nodes following it. */
8355 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8356 decl_piece_bitsize (*src), NULL_RTX);
8357 dest = &XEXP (*dest, 1);
8358 src = &XEXP (*src, 1);
8362 /* Add a variable location node to the linked list for DECL. */
8364 static struct var_loc_node *
8365 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8367 unsigned int decl_id;
8370 struct var_loc_node *loc = NULL;
8371 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8373 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8375 tree realdecl = DECL_DEBUG_EXPR (decl);
8376 if (realdecl && handled_component_p (realdecl))
8378 HOST_WIDE_INT maxsize;
8381 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8382 if (!DECL_P (innerdecl)
8383 || DECL_IGNORED_P (innerdecl)
8384 || TREE_STATIC (innerdecl)
8386 || bitpos + bitsize > 256
8387 || bitsize != maxsize)
8393 decl_id = DECL_UID (decl);
8394 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8397 temp = ggc_alloc_cleared_var_loc_list ();
8398 temp->decl_id = decl_id;
8402 temp = (var_loc_list *) *slot;
8406 struct var_loc_node *last = temp->last, *unused = NULL;
8407 rtx *piece_loc = NULL, last_loc_note;
8408 int piece_bitpos = 0;
8412 gcc_assert (last->next == NULL);
8414 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8416 piece_loc = &last->loc;
8419 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8420 if (piece_bitpos + cur_bitsize > bitpos)
8422 piece_bitpos += cur_bitsize;
8423 piece_loc = &XEXP (*piece_loc, 1);
8427 /* TEMP->LAST here is either pointer to the last but one or
8428 last element in the chained list, LAST is pointer to the
8430 if (label && strcmp (last->label, label) == 0)
8432 /* For SRA optimized variables if there weren't any real
8433 insns since last note, just modify the last node. */
8434 if (piece_loc != NULL)
8436 adjust_piece_list (piece_loc, NULL, NULL,
8437 bitpos, piece_bitpos, bitsize, loc_note);
8440 /* If the last note doesn't cover any instructions, remove it. */
8441 if (temp->last != last)
8443 temp->last->next = NULL;
8446 gcc_assert (strcmp (last->label, label) != 0);
8450 gcc_assert (temp->first == temp->last);
8451 memset (temp->last, '\0', sizeof (*temp->last));
8452 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8456 if (bitsize == -1 && NOTE_P (last->loc))
8457 last_loc_note = last->loc;
8458 else if (piece_loc != NULL
8459 && *piece_loc != NULL_RTX
8460 && piece_bitpos == bitpos
8461 && decl_piece_bitsize (*piece_loc) == bitsize)
8462 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8464 last_loc_note = NULL_RTX;
8465 /* If the current location is the same as the end of the list,
8466 and either both or neither of the locations is uninitialized,
8467 we have nothing to do. */
8468 if (last_loc_note == NULL_RTX
8469 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8470 NOTE_VAR_LOCATION_LOC (loc_note)))
8471 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8472 != NOTE_VAR_LOCATION_STATUS (loc_note))
8473 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8474 == VAR_INIT_STATUS_UNINITIALIZED)
8475 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8476 == VAR_INIT_STATUS_UNINITIALIZED))))
8478 /* Add LOC to the end of list and update LAST. If the last
8479 element of the list has been removed above, reuse its
8480 memory for the new node, otherwise allocate a new one. */
8484 memset (loc, '\0', sizeof (*loc));
8487 loc = ggc_alloc_cleared_var_loc_node ();
8488 if (bitsize == -1 || piece_loc == NULL)
8489 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8491 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8492 bitpos, piece_bitpos, bitsize, loc_note);
8494 /* Ensure TEMP->LAST will point either to the new last but one
8495 element of the chain, or to the last element in it. */
8496 if (last != temp->last)
8504 loc = ggc_alloc_cleared_var_loc_node ();
8507 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8512 /* Keep track of the number of spaces used to indent the
8513 output of the debugging routines that print the structure of
8514 the DIE internal representation. */
8515 static int print_indent;
8517 /* Indent the line the number of spaces given by print_indent. */
8520 print_spaces (FILE *outfile)
8522 fprintf (outfile, "%*s", print_indent, "");
8525 /* Print a type signature in hex. */
8528 print_signature (FILE *outfile, char *sig)
8532 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8533 fprintf (outfile, "%02x", sig[i] & 0xff);
8536 /* Print the information associated with a given DIE, and its children.
8537 This routine is a debugging aid only. */
8540 print_die (dw_die_ref die, FILE *outfile)
8546 print_spaces (outfile);
8547 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8548 die->die_offset, dwarf_tag_name (die->die_tag),
8550 print_spaces (outfile);
8551 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8552 fprintf (outfile, " offset: %ld", die->die_offset);
8553 fprintf (outfile, " mark: %d\n", die->die_mark);
8555 if (dwarf_version >= 4 && die->die_id.die_type_node)
8557 print_spaces (outfile);
8558 fprintf (outfile, " signature: ");
8559 print_signature (outfile, die->die_id.die_type_node->signature);
8560 fprintf (outfile, "\n");
8563 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8565 print_spaces (outfile);
8566 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8568 switch (AT_class (a))
8570 case dw_val_class_addr:
8571 fprintf (outfile, "address");
8573 case dw_val_class_offset:
8574 fprintf (outfile, "offset");
8576 case dw_val_class_loc:
8577 fprintf (outfile, "location descriptor");
8579 case dw_val_class_loc_list:
8580 fprintf (outfile, "location list -> label:%s",
8581 AT_loc_list (a)->ll_symbol);
8583 case dw_val_class_range_list:
8584 fprintf (outfile, "range list");
8586 case dw_val_class_const:
8587 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8589 case dw_val_class_unsigned_const:
8590 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8592 case dw_val_class_const_double:
8593 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8594 HOST_WIDE_INT_PRINT_UNSIGNED")",
8595 a->dw_attr_val.v.val_double.high,
8596 a->dw_attr_val.v.val_double.low);
8598 case dw_val_class_vec:
8599 fprintf (outfile, "floating-point or vector constant");
8601 case dw_val_class_flag:
8602 fprintf (outfile, "%u", AT_flag (a));
8604 case dw_val_class_die_ref:
8605 if (AT_ref (a) != NULL)
8607 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8609 fprintf (outfile, "die -> signature: ");
8610 print_signature (outfile,
8611 AT_ref (a)->die_id.die_type_node->signature);
8613 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8614 fprintf (outfile, "die -> label: %s",
8615 AT_ref (a)->die_id.die_symbol);
8617 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8618 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8621 fprintf (outfile, "die -> <null>");
8623 case dw_val_class_vms_delta:
8624 fprintf (outfile, "delta: @slotcount(%s-%s)",
8625 AT_vms_delta2 (a), AT_vms_delta1 (a));
8627 case dw_val_class_lbl_id:
8628 case dw_val_class_lineptr:
8629 case dw_val_class_macptr:
8630 fprintf (outfile, "label: %s", AT_lbl (a));
8632 case dw_val_class_str:
8633 if (AT_string (a) != NULL)
8634 fprintf (outfile, "\"%s\"", AT_string (a));
8636 fprintf (outfile, "<null>");
8638 case dw_val_class_file:
8639 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8640 AT_file (a)->emitted_number);
8642 case dw_val_class_data8:
8646 for (i = 0; i < 8; i++)
8647 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8654 fprintf (outfile, "\n");
8657 if (die->die_child != NULL)
8660 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8663 if (print_indent == 0)
8664 fprintf (outfile, "\n");
8667 /* Print the contents of the source code line number correspondence table.
8668 This routine is a debugging aid only. */
8671 print_dwarf_line_table (FILE *outfile)
8674 dw_line_info_ref line_info;
8676 fprintf (outfile, "\n\nDWARF source line information\n");
8677 for (i = 1; i < line_info_table_in_use; i++)
8679 line_info = &line_info_table[i];
8680 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8681 line_info->dw_file_num,
8682 line_info->dw_line_num);
8685 fprintf (outfile, "\n\n");
8688 /* Print the information collected for a given DIE. */
8691 debug_dwarf_die (dw_die_ref die)
8693 print_die (die, stderr);
8696 /* Print all DWARF information collected for the compilation unit.
8697 This routine is a debugging aid only. */
8703 print_die (comp_unit_die (), stderr);
8704 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8705 print_dwarf_line_table (stderr);
8708 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8709 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8710 DIE that marks the start of the DIEs for this include file. */
8713 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8715 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8716 dw_die_ref new_unit = gen_compile_unit_die (filename);
8718 new_unit->die_sib = old_unit;
8722 /* Close an include-file CU and reopen the enclosing one. */
8725 pop_compile_unit (dw_die_ref old_unit)
8727 dw_die_ref new_unit = old_unit->die_sib;
8729 old_unit->die_sib = NULL;
8733 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8734 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8736 /* Calculate the checksum of a location expression. */
8739 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8743 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8745 CHECKSUM (loc->dw_loc_oprnd1);
8746 CHECKSUM (loc->dw_loc_oprnd2);
8749 /* Calculate the checksum of an attribute. */
8752 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8754 dw_loc_descr_ref loc;
8757 CHECKSUM (at->dw_attr);
8759 /* We don't care that this was compiled with a different compiler
8760 snapshot; if the output is the same, that's what matters. */
8761 if (at->dw_attr == DW_AT_producer)
8764 switch (AT_class (at))
8766 case dw_val_class_const:
8767 CHECKSUM (at->dw_attr_val.v.val_int);
8769 case dw_val_class_unsigned_const:
8770 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8772 case dw_val_class_const_double:
8773 CHECKSUM (at->dw_attr_val.v.val_double);
8775 case dw_val_class_vec:
8776 CHECKSUM (at->dw_attr_val.v.val_vec);
8778 case dw_val_class_flag:
8779 CHECKSUM (at->dw_attr_val.v.val_flag);
8781 case dw_val_class_str:
8782 CHECKSUM_STRING (AT_string (at));
8785 case dw_val_class_addr:
8787 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8788 CHECKSUM_STRING (XSTR (r, 0));
8791 case dw_val_class_offset:
8792 CHECKSUM (at->dw_attr_val.v.val_offset);
8795 case dw_val_class_loc:
8796 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8797 loc_checksum (loc, ctx);
8800 case dw_val_class_die_ref:
8801 die_checksum (AT_ref (at), ctx, mark);
8804 case dw_val_class_fde_ref:
8805 case dw_val_class_vms_delta:
8806 case dw_val_class_lbl_id:
8807 case dw_val_class_lineptr:
8808 case dw_val_class_macptr:
8811 case dw_val_class_file:
8812 CHECKSUM_STRING (AT_file (at)->filename);
8815 case dw_val_class_data8:
8816 CHECKSUM (at->dw_attr_val.v.val_data8);
8824 /* Calculate the checksum of a DIE. */
8827 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8833 /* To avoid infinite recursion. */
8836 CHECKSUM (die->die_mark);
8839 die->die_mark = ++(*mark);
8841 CHECKSUM (die->die_tag);
8843 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8844 attr_checksum (a, ctx, mark);
8846 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8850 #undef CHECKSUM_STRING
8852 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8853 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8854 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8855 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8856 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8857 #define CHECKSUM_ATTR(FOO) \
8858 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8860 /* Calculate the checksum of a number in signed LEB128 format. */
8863 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8870 byte = (value & 0x7f);
8872 more = !((value == 0 && (byte & 0x40) == 0)
8873 || (value == -1 && (byte & 0x40) != 0));
8882 /* Calculate the checksum of a number in unsigned LEB128 format. */
8885 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8889 unsigned char byte = (value & 0x7f);
8892 /* More bytes to follow. */
8900 /* Checksum the context of the DIE. This adds the names of any
8901 surrounding namespaces or structures to the checksum. */
8904 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8908 int tag = die->die_tag;
8910 if (tag != DW_TAG_namespace
8911 && tag != DW_TAG_structure_type
8912 && tag != DW_TAG_class_type)
8915 name = get_AT_string (die, DW_AT_name);
8917 spec = get_AT_ref (die, DW_AT_specification);
8921 if (die->die_parent != NULL)
8922 checksum_die_context (die->die_parent, ctx);
8924 CHECKSUM_ULEB128 ('C');
8925 CHECKSUM_ULEB128 (tag);
8927 CHECKSUM_STRING (name);
8930 /* Calculate the checksum of a location expression. */
8933 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8935 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8936 were emitted as a DW_FORM_sdata instead of a location expression. */
8937 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8939 CHECKSUM_ULEB128 (DW_FORM_sdata);
8940 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8944 /* Otherwise, just checksum the raw location expression. */
8947 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8948 CHECKSUM (loc->dw_loc_oprnd1);
8949 CHECKSUM (loc->dw_loc_oprnd2);
8950 loc = loc->dw_loc_next;
8954 /* Calculate the checksum of an attribute. */
8957 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8958 struct md5_ctx *ctx, int *mark)
8960 dw_loc_descr_ref loc;
8963 if (AT_class (at) == dw_val_class_die_ref)
8965 dw_die_ref target_die = AT_ref (at);
8967 /* For pointer and reference types, we checksum only the (qualified)
8968 name of the target type (if there is a name). For friend entries,
8969 we checksum only the (qualified) name of the target type or function.
8970 This allows the checksum to remain the same whether the target type
8971 is complete or not. */
8972 if ((at->dw_attr == DW_AT_type
8973 && (tag == DW_TAG_pointer_type
8974 || tag == DW_TAG_reference_type
8975 || tag == DW_TAG_rvalue_reference_type
8976 || tag == DW_TAG_ptr_to_member_type))
8977 || (at->dw_attr == DW_AT_friend
8978 && tag == DW_TAG_friend))
8980 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
8982 if (name_attr != NULL)
8984 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8988 CHECKSUM_ULEB128 ('N');
8989 CHECKSUM_ULEB128 (at->dw_attr);
8990 if (decl->die_parent != NULL)
8991 checksum_die_context (decl->die_parent, ctx);
8992 CHECKSUM_ULEB128 ('E');
8993 CHECKSUM_STRING (AT_string (name_attr));
8998 /* For all other references to another DIE, we check to see if the
8999 target DIE has already been visited. If it has, we emit a
9000 backward reference; if not, we descend recursively. */
9001 if (target_die->die_mark > 0)
9003 CHECKSUM_ULEB128 ('R');
9004 CHECKSUM_ULEB128 (at->dw_attr);
9005 CHECKSUM_ULEB128 (target_die->die_mark);
9009 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9013 target_die->die_mark = ++(*mark);
9014 CHECKSUM_ULEB128 ('T');
9015 CHECKSUM_ULEB128 (at->dw_attr);
9016 if (decl->die_parent != NULL)
9017 checksum_die_context (decl->die_parent, ctx);
9018 die_checksum_ordered (target_die, ctx, mark);
9023 CHECKSUM_ULEB128 ('A');
9024 CHECKSUM_ULEB128 (at->dw_attr);
9026 switch (AT_class (at))
9028 case dw_val_class_const:
9029 CHECKSUM_ULEB128 (DW_FORM_sdata);
9030 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9033 case dw_val_class_unsigned_const:
9034 CHECKSUM_ULEB128 (DW_FORM_sdata);
9035 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9038 case dw_val_class_const_double:
9039 CHECKSUM_ULEB128 (DW_FORM_block);
9040 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9041 CHECKSUM (at->dw_attr_val.v.val_double);
9044 case dw_val_class_vec:
9045 CHECKSUM_ULEB128 (DW_FORM_block);
9046 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9047 CHECKSUM (at->dw_attr_val.v.val_vec);
9050 case dw_val_class_flag:
9051 CHECKSUM_ULEB128 (DW_FORM_flag);
9052 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9055 case dw_val_class_str:
9056 CHECKSUM_ULEB128 (DW_FORM_string);
9057 CHECKSUM_STRING (AT_string (at));
9060 case dw_val_class_addr:
9062 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9063 CHECKSUM_ULEB128 (DW_FORM_string);
9064 CHECKSUM_STRING (XSTR (r, 0));
9067 case dw_val_class_offset:
9068 CHECKSUM_ULEB128 (DW_FORM_sdata);
9069 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9072 case dw_val_class_loc:
9073 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9074 loc_checksum_ordered (loc, ctx);
9077 case dw_val_class_fde_ref:
9078 case dw_val_class_lbl_id:
9079 case dw_val_class_lineptr:
9080 case dw_val_class_macptr:
9083 case dw_val_class_file:
9084 CHECKSUM_ULEB128 (DW_FORM_string);
9085 CHECKSUM_STRING (AT_file (at)->filename);
9088 case dw_val_class_data8:
9089 CHECKSUM (at->dw_attr_val.v.val_data8);
9097 struct checksum_attributes
9099 dw_attr_ref at_name;
9100 dw_attr_ref at_type;
9101 dw_attr_ref at_friend;
9102 dw_attr_ref at_accessibility;
9103 dw_attr_ref at_address_class;
9104 dw_attr_ref at_allocated;
9105 dw_attr_ref at_artificial;
9106 dw_attr_ref at_associated;
9107 dw_attr_ref at_binary_scale;
9108 dw_attr_ref at_bit_offset;
9109 dw_attr_ref at_bit_size;
9110 dw_attr_ref at_bit_stride;
9111 dw_attr_ref at_byte_size;
9112 dw_attr_ref at_byte_stride;
9113 dw_attr_ref at_const_value;
9114 dw_attr_ref at_containing_type;
9115 dw_attr_ref at_count;
9116 dw_attr_ref at_data_location;
9117 dw_attr_ref at_data_member_location;
9118 dw_attr_ref at_decimal_scale;
9119 dw_attr_ref at_decimal_sign;
9120 dw_attr_ref at_default_value;
9121 dw_attr_ref at_digit_count;
9122 dw_attr_ref at_discr;
9123 dw_attr_ref at_discr_list;
9124 dw_attr_ref at_discr_value;
9125 dw_attr_ref at_encoding;
9126 dw_attr_ref at_endianity;
9127 dw_attr_ref at_explicit;
9128 dw_attr_ref at_is_optional;
9129 dw_attr_ref at_location;
9130 dw_attr_ref at_lower_bound;
9131 dw_attr_ref at_mutable;
9132 dw_attr_ref at_ordering;
9133 dw_attr_ref at_picture_string;
9134 dw_attr_ref at_prototyped;
9135 dw_attr_ref at_small;
9136 dw_attr_ref at_segment;
9137 dw_attr_ref at_string_length;
9138 dw_attr_ref at_threads_scaled;
9139 dw_attr_ref at_upper_bound;
9140 dw_attr_ref at_use_location;
9141 dw_attr_ref at_use_UTF8;
9142 dw_attr_ref at_variable_parameter;
9143 dw_attr_ref at_virtuality;
9144 dw_attr_ref at_visibility;
9145 dw_attr_ref at_vtable_elem_location;
9148 /* Collect the attributes that we will want to use for the checksum. */
9151 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9156 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9167 attrs->at_friend = a;
9169 case DW_AT_accessibility:
9170 attrs->at_accessibility = a;
9172 case DW_AT_address_class:
9173 attrs->at_address_class = a;
9175 case DW_AT_allocated:
9176 attrs->at_allocated = a;
9178 case DW_AT_artificial:
9179 attrs->at_artificial = a;
9181 case DW_AT_associated:
9182 attrs->at_associated = a;
9184 case DW_AT_binary_scale:
9185 attrs->at_binary_scale = a;
9187 case DW_AT_bit_offset:
9188 attrs->at_bit_offset = a;
9190 case DW_AT_bit_size:
9191 attrs->at_bit_size = a;
9193 case DW_AT_bit_stride:
9194 attrs->at_bit_stride = a;
9196 case DW_AT_byte_size:
9197 attrs->at_byte_size = a;
9199 case DW_AT_byte_stride:
9200 attrs->at_byte_stride = a;
9202 case DW_AT_const_value:
9203 attrs->at_const_value = a;
9205 case DW_AT_containing_type:
9206 attrs->at_containing_type = a;
9209 attrs->at_count = a;
9211 case DW_AT_data_location:
9212 attrs->at_data_location = a;
9214 case DW_AT_data_member_location:
9215 attrs->at_data_member_location = a;
9217 case DW_AT_decimal_scale:
9218 attrs->at_decimal_scale = a;
9220 case DW_AT_decimal_sign:
9221 attrs->at_decimal_sign = a;
9223 case DW_AT_default_value:
9224 attrs->at_default_value = a;
9226 case DW_AT_digit_count:
9227 attrs->at_digit_count = a;
9230 attrs->at_discr = a;
9232 case DW_AT_discr_list:
9233 attrs->at_discr_list = a;
9235 case DW_AT_discr_value:
9236 attrs->at_discr_value = a;
9238 case DW_AT_encoding:
9239 attrs->at_encoding = a;
9241 case DW_AT_endianity:
9242 attrs->at_endianity = a;
9244 case DW_AT_explicit:
9245 attrs->at_explicit = a;
9247 case DW_AT_is_optional:
9248 attrs->at_is_optional = a;
9250 case DW_AT_location:
9251 attrs->at_location = a;
9253 case DW_AT_lower_bound:
9254 attrs->at_lower_bound = a;
9257 attrs->at_mutable = a;
9259 case DW_AT_ordering:
9260 attrs->at_ordering = a;
9262 case DW_AT_picture_string:
9263 attrs->at_picture_string = a;
9265 case DW_AT_prototyped:
9266 attrs->at_prototyped = a;
9269 attrs->at_small = a;
9272 attrs->at_segment = a;
9274 case DW_AT_string_length:
9275 attrs->at_string_length = a;
9277 case DW_AT_threads_scaled:
9278 attrs->at_threads_scaled = a;
9280 case DW_AT_upper_bound:
9281 attrs->at_upper_bound = a;
9283 case DW_AT_use_location:
9284 attrs->at_use_location = a;
9286 case DW_AT_use_UTF8:
9287 attrs->at_use_UTF8 = a;
9289 case DW_AT_variable_parameter:
9290 attrs->at_variable_parameter = a;
9292 case DW_AT_virtuality:
9293 attrs->at_virtuality = a;
9295 case DW_AT_visibility:
9296 attrs->at_visibility = a;
9298 case DW_AT_vtable_elem_location:
9299 attrs->at_vtable_elem_location = a;
9307 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9310 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9314 struct checksum_attributes attrs;
9316 CHECKSUM_ULEB128 ('D');
9317 CHECKSUM_ULEB128 (die->die_tag);
9319 memset (&attrs, 0, sizeof (attrs));
9321 decl = get_AT_ref (die, DW_AT_specification);
9323 collect_checksum_attributes (&attrs, decl);
9324 collect_checksum_attributes (&attrs, die);
9326 CHECKSUM_ATTR (attrs.at_name);
9327 CHECKSUM_ATTR (attrs.at_accessibility);
9328 CHECKSUM_ATTR (attrs.at_address_class);
9329 CHECKSUM_ATTR (attrs.at_allocated);
9330 CHECKSUM_ATTR (attrs.at_artificial);
9331 CHECKSUM_ATTR (attrs.at_associated);
9332 CHECKSUM_ATTR (attrs.at_binary_scale);
9333 CHECKSUM_ATTR (attrs.at_bit_offset);
9334 CHECKSUM_ATTR (attrs.at_bit_size);
9335 CHECKSUM_ATTR (attrs.at_bit_stride);
9336 CHECKSUM_ATTR (attrs.at_byte_size);
9337 CHECKSUM_ATTR (attrs.at_byte_stride);
9338 CHECKSUM_ATTR (attrs.at_const_value);
9339 CHECKSUM_ATTR (attrs.at_containing_type);
9340 CHECKSUM_ATTR (attrs.at_count);
9341 CHECKSUM_ATTR (attrs.at_data_location);
9342 CHECKSUM_ATTR (attrs.at_data_member_location);
9343 CHECKSUM_ATTR (attrs.at_decimal_scale);
9344 CHECKSUM_ATTR (attrs.at_decimal_sign);
9345 CHECKSUM_ATTR (attrs.at_default_value);
9346 CHECKSUM_ATTR (attrs.at_digit_count);
9347 CHECKSUM_ATTR (attrs.at_discr);
9348 CHECKSUM_ATTR (attrs.at_discr_list);
9349 CHECKSUM_ATTR (attrs.at_discr_value);
9350 CHECKSUM_ATTR (attrs.at_encoding);
9351 CHECKSUM_ATTR (attrs.at_endianity);
9352 CHECKSUM_ATTR (attrs.at_explicit);
9353 CHECKSUM_ATTR (attrs.at_is_optional);
9354 CHECKSUM_ATTR (attrs.at_location);
9355 CHECKSUM_ATTR (attrs.at_lower_bound);
9356 CHECKSUM_ATTR (attrs.at_mutable);
9357 CHECKSUM_ATTR (attrs.at_ordering);
9358 CHECKSUM_ATTR (attrs.at_picture_string);
9359 CHECKSUM_ATTR (attrs.at_prototyped);
9360 CHECKSUM_ATTR (attrs.at_small);
9361 CHECKSUM_ATTR (attrs.at_segment);
9362 CHECKSUM_ATTR (attrs.at_string_length);
9363 CHECKSUM_ATTR (attrs.at_threads_scaled);
9364 CHECKSUM_ATTR (attrs.at_upper_bound);
9365 CHECKSUM_ATTR (attrs.at_use_location);
9366 CHECKSUM_ATTR (attrs.at_use_UTF8);
9367 CHECKSUM_ATTR (attrs.at_variable_parameter);
9368 CHECKSUM_ATTR (attrs.at_virtuality);
9369 CHECKSUM_ATTR (attrs.at_visibility);
9370 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9371 CHECKSUM_ATTR (attrs.at_type);
9372 CHECKSUM_ATTR (attrs.at_friend);
9374 /* Checksum the child DIEs, except for nested types and member functions. */
9377 dw_attr_ref name_attr;
9380 name_attr = get_AT (c, DW_AT_name);
9381 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9382 && name_attr != NULL)
9384 CHECKSUM_ULEB128 ('S');
9385 CHECKSUM_ULEB128 (c->die_tag);
9386 CHECKSUM_STRING (AT_string (name_attr));
9390 /* Mark this DIE so it gets processed when unmarking. */
9391 if (c->die_mark == 0)
9393 die_checksum_ordered (c, ctx, mark);
9395 } while (c != die->die_child);
9397 CHECKSUM_ULEB128 (0);
9401 #undef CHECKSUM_STRING
9402 #undef CHECKSUM_ATTR
9403 #undef CHECKSUM_LEB128
9404 #undef CHECKSUM_ULEB128
9406 /* Generate the type signature for DIE. This is computed by generating an
9407 MD5 checksum over the DIE's tag, its relevant attributes, and its
9408 children. Attributes that are references to other DIEs are processed
9409 by recursion, using the MARK field to prevent infinite recursion.
9410 If the DIE is nested inside a namespace or another type, we also
9411 need to include that context in the signature. The lower 64 bits
9412 of the resulting MD5 checksum comprise the signature. */
9415 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9419 unsigned char checksum[16];
9423 name = get_AT_string (die, DW_AT_name);
9424 decl = get_AT_ref (die, DW_AT_specification);
9426 /* First, compute a signature for just the type name (and its surrounding
9427 context, if any. This is stored in the type unit DIE for link-time
9428 ODR (one-definition rule) checking. */
9430 if (is_cxx() && name != NULL)
9432 md5_init_ctx (&ctx);
9434 /* Checksum the names of surrounding namespaces and structures. */
9435 if (decl != NULL && decl->die_parent != NULL)
9436 checksum_die_context (decl->die_parent, &ctx);
9438 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9439 md5_process_bytes (name, strlen (name) + 1, &ctx);
9440 md5_finish_ctx (&ctx, checksum);
9442 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9445 /* Next, compute the complete type signature. */
9447 md5_init_ctx (&ctx);
9449 die->die_mark = mark;
9451 /* Checksum the names of surrounding namespaces and structures. */
9452 if (decl != NULL && decl->die_parent != NULL)
9453 checksum_die_context (decl->die_parent, &ctx);
9455 /* Checksum the DIE and its children. */
9456 die_checksum_ordered (die, &ctx, &mark);
9457 unmark_all_dies (die);
9458 md5_finish_ctx (&ctx, checksum);
9460 /* Store the signature in the type node and link the type DIE and the
9461 type node together. */
9462 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9463 DWARF_TYPE_SIGNATURE_SIZE);
9464 die->die_id.die_type_node = type_node;
9465 type_node->type_die = die;
9467 /* If the DIE is a specification, link its declaration to the type node
9470 decl->die_id.die_type_node = type_node;
9473 /* Do the location expressions look same? */
9475 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9477 return loc1->dw_loc_opc == loc2->dw_loc_opc
9478 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9479 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9482 /* Do the values look the same? */
9484 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9486 dw_loc_descr_ref loc1, loc2;
9489 if (v1->val_class != v2->val_class)
9492 switch (v1->val_class)
9494 case dw_val_class_const:
9495 return v1->v.val_int == v2->v.val_int;
9496 case dw_val_class_unsigned_const:
9497 return v1->v.val_unsigned == v2->v.val_unsigned;
9498 case dw_val_class_const_double:
9499 return v1->v.val_double.high == v2->v.val_double.high
9500 && v1->v.val_double.low == v2->v.val_double.low;
9501 case dw_val_class_vec:
9502 if (v1->v.val_vec.length != v2->v.val_vec.length
9503 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9505 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9506 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9509 case dw_val_class_flag:
9510 return v1->v.val_flag == v2->v.val_flag;
9511 case dw_val_class_str:
9512 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9514 case dw_val_class_addr:
9515 r1 = v1->v.val_addr;
9516 r2 = v2->v.val_addr;
9517 if (GET_CODE (r1) != GET_CODE (r2))
9519 return !rtx_equal_p (r1, r2);
9521 case dw_val_class_offset:
9522 return v1->v.val_offset == v2->v.val_offset;
9524 case dw_val_class_loc:
9525 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9527 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9528 if (!same_loc_p (loc1, loc2, mark))
9530 return !loc1 && !loc2;
9532 case dw_val_class_die_ref:
9533 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9535 case dw_val_class_fde_ref:
9536 case dw_val_class_vms_delta:
9537 case dw_val_class_lbl_id:
9538 case dw_val_class_lineptr:
9539 case dw_val_class_macptr:
9542 case dw_val_class_file:
9543 return v1->v.val_file == v2->v.val_file;
9545 case dw_val_class_data8:
9546 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9553 /* Do the attributes look the same? */
9556 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9558 if (at1->dw_attr != at2->dw_attr)
9561 /* We don't care that this was compiled with a different compiler
9562 snapshot; if the output is the same, that's what matters. */
9563 if (at1->dw_attr == DW_AT_producer)
9566 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9569 /* Do the dies look the same? */
9572 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9578 /* To avoid infinite recursion. */
9580 return die1->die_mark == die2->die_mark;
9581 die1->die_mark = die2->die_mark = ++(*mark);
9583 if (die1->die_tag != die2->die_tag)
9586 if (VEC_length (dw_attr_node, die1->die_attr)
9587 != VEC_length (dw_attr_node, die2->die_attr))
9590 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9591 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9594 c1 = die1->die_child;
9595 c2 = die2->die_child;
9604 if (!same_die_p (c1, c2, mark))
9608 if (c1 == die1->die_child)
9610 if (c2 == die2->die_child)
9620 /* Do the dies look the same? Wrapper around same_die_p. */
9623 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9626 int ret = same_die_p (die1, die2, &mark);
9628 unmark_all_dies (die1);
9629 unmark_all_dies (die2);
9634 /* The prefix to attach to symbols on DIEs in the current comdat debug
9636 static char *comdat_symbol_id;
9638 /* The index of the current symbol within the current comdat CU. */
9639 static unsigned int comdat_symbol_number;
9641 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9642 children, and set comdat_symbol_id accordingly. */
9645 compute_section_prefix (dw_die_ref unit_die)
9647 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9648 const char *base = die_name ? lbasename (die_name) : "anonymous";
9649 char *name = XALLOCAVEC (char, strlen (base) + 64);
9652 unsigned char checksum[16];
9655 /* Compute the checksum of the DIE, then append part of it as hex digits to
9656 the name filename of the unit. */
9658 md5_init_ctx (&ctx);
9660 die_checksum (unit_die, &ctx, &mark);
9661 unmark_all_dies (unit_die);
9662 md5_finish_ctx (&ctx, checksum);
9664 sprintf (name, "%s.", base);
9665 clean_symbol_name (name);
9667 p = name + strlen (name);
9668 for (i = 0; i < 4; i++)
9670 sprintf (p, "%.2x", checksum[i]);
9674 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9675 comdat_symbol_number = 0;
9678 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9681 is_type_die (dw_die_ref die)
9683 switch (die->die_tag)
9685 case DW_TAG_array_type:
9686 case DW_TAG_class_type:
9687 case DW_TAG_interface_type:
9688 case DW_TAG_enumeration_type:
9689 case DW_TAG_pointer_type:
9690 case DW_TAG_reference_type:
9691 case DW_TAG_rvalue_reference_type:
9692 case DW_TAG_string_type:
9693 case DW_TAG_structure_type:
9694 case DW_TAG_subroutine_type:
9695 case DW_TAG_union_type:
9696 case DW_TAG_ptr_to_member_type:
9697 case DW_TAG_set_type:
9698 case DW_TAG_subrange_type:
9699 case DW_TAG_base_type:
9700 case DW_TAG_const_type:
9701 case DW_TAG_file_type:
9702 case DW_TAG_packed_type:
9703 case DW_TAG_volatile_type:
9704 case DW_TAG_typedef:
9711 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9712 Basically, we want to choose the bits that are likely to be shared between
9713 compilations (types) and leave out the bits that are specific to individual
9714 compilations (functions). */
9717 is_comdat_die (dw_die_ref c)
9719 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9720 we do for stabs. The advantage is a greater likelihood of sharing between
9721 objects that don't include headers in the same order (and therefore would
9722 put the base types in a different comdat). jason 8/28/00 */
9724 if (c->die_tag == DW_TAG_base_type)
9727 if (c->die_tag == DW_TAG_pointer_type
9728 || c->die_tag == DW_TAG_reference_type
9729 || c->die_tag == DW_TAG_rvalue_reference_type
9730 || c->die_tag == DW_TAG_const_type
9731 || c->die_tag == DW_TAG_volatile_type)
9733 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9735 return t ? is_comdat_die (t) : 0;
9738 return is_type_die (c);
9741 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9742 compilation unit. */
9745 is_symbol_die (dw_die_ref c)
9747 return (is_type_die (c)
9748 || is_declaration_die (c)
9749 || c->die_tag == DW_TAG_namespace
9750 || c->die_tag == DW_TAG_module);
9753 /* Returns true iff C is a compile-unit DIE. */
9756 is_cu_die (dw_die_ref c)
9758 return c && c->die_tag == DW_TAG_compile_unit;
9762 gen_internal_sym (const char *prefix)
9766 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9767 return xstrdup (buf);
9770 /* Assign symbols to all worthy DIEs under DIE. */
9773 assign_symbol_names (dw_die_ref die)
9777 if (is_symbol_die (die))
9779 if (comdat_symbol_id)
9781 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9783 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9784 comdat_symbol_id, comdat_symbol_number++);
9785 die->die_id.die_symbol = xstrdup (p);
9788 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9791 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9794 struct cu_hash_table_entry
9797 unsigned min_comdat_num, max_comdat_num;
9798 struct cu_hash_table_entry *next;
9801 /* Routines to manipulate hash table of CUs. */
9803 htab_cu_hash (const void *of)
9805 const struct cu_hash_table_entry *const entry =
9806 (const struct cu_hash_table_entry *) of;
9808 return htab_hash_string (entry->cu->die_id.die_symbol);
9812 htab_cu_eq (const void *of1, const void *of2)
9814 const struct cu_hash_table_entry *const entry1 =
9815 (const struct cu_hash_table_entry *) of1;
9816 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9818 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9822 htab_cu_del (void *what)
9824 struct cu_hash_table_entry *next,
9825 *entry = (struct cu_hash_table_entry *) what;
9835 /* Check whether we have already seen this CU and set up SYM_NUM
9838 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9840 struct cu_hash_table_entry dummy;
9841 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9843 dummy.max_comdat_num = 0;
9845 slot = (struct cu_hash_table_entry **)
9846 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9850 for (; entry; last = entry, entry = entry->next)
9852 if (same_die_p_wrap (cu, entry->cu))
9858 *sym_num = entry->min_comdat_num;
9862 entry = XCNEW (struct cu_hash_table_entry);
9864 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9865 entry->next = *slot;
9871 /* Record SYM_NUM to record of CU in HTABLE. */
9873 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9875 struct cu_hash_table_entry **slot, *entry;
9877 slot = (struct cu_hash_table_entry **)
9878 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9882 entry->max_comdat_num = sym_num;
9885 /* Traverse the DIE (which is always comp_unit_die), and set up
9886 additional compilation units for each of the include files we see
9887 bracketed by BINCL/EINCL. */
9890 break_out_includes (dw_die_ref die)
9893 dw_die_ref unit = NULL;
9894 limbo_die_node *node, **pnode;
9895 htab_t cu_hash_table;
9899 dw_die_ref prev = c;
9901 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9902 || (unit && is_comdat_die (c)))
9904 dw_die_ref next = c->die_sib;
9906 /* This DIE is for a secondary CU; remove it from the main one. */
9907 remove_child_with_prev (c, prev);
9909 if (c->die_tag == DW_TAG_GNU_BINCL)
9910 unit = push_new_compile_unit (unit, c);
9911 else if (c->die_tag == DW_TAG_GNU_EINCL)
9912 unit = pop_compile_unit (unit);
9914 add_child_die (unit, c);
9916 if (c == die->die_child)
9919 } while (c != die->die_child);
9922 /* We can only use this in debugging, since the frontend doesn't check
9923 to make sure that we leave every include file we enter. */
9927 assign_symbol_names (die);
9928 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9929 for (node = limbo_die_list, pnode = &limbo_die_list;
9935 compute_section_prefix (node->die);
9936 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9937 &comdat_symbol_number);
9938 assign_symbol_names (node->die);
9940 *pnode = node->next;
9943 pnode = &node->next;
9944 record_comdat_symbol_number (node->die, cu_hash_table,
9945 comdat_symbol_number);
9948 htab_delete (cu_hash_table);
9951 /* Return non-zero if this DIE is a declaration. */
9954 is_declaration_die (dw_die_ref die)
9959 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9960 if (a->dw_attr == DW_AT_declaration)
9966 /* Return non-zero if this DIE is nested inside a subprogram. */
9969 is_nested_in_subprogram (dw_die_ref die)
9971 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
9975 return local_scope_p (decl);
9978 /* Return non-zero if this is a type DIE that should be moved to a
9979 COMDAT .debug_types section. */
9982 should_move_die_to_comdat (dw_die_ref die)
9984 switch (die->die_tag)
9986 case DW_TAG_class_type:
9987 case DW_TAG_structure_type:
9988 case DW_TAG_enumeration_type:
9989 case DW_TAG_union_type:
9990 /* Don't move declarations, inlined instances, or types nested in a
9992 if (is_declaration_die (die)
9993 || get_AT (die, DW_AT_abstract_origin)
9994 || is_nested_in_subprogram (die))
9997 case DW_TAG_array_type:
9998 case DW_TAG_interface_type:
9999 case DW_TAG_pointer_type:
10000 case DW_TAG_reference_type:
10001 case DW_TAG_rvalue_reference_type:
10002 case DW_TAG_string_type:
10003 case DW_TAG_subroutine_type:
10004 case DW_TAG_ptr_to_member_type:
10005 case DW_TAG_set_type:
10006 case DW_TAG_subrange_type:
10007 case DW_TAG_base_type:
10008 case DW_TAG_const_type:
10009 case DW_TAG_file_type:
10010 case DW_TAG_packed_type:
10011 case DW_TAG_volatile_type:
10012 case DW_TAG_typedef:
10018 /* Make a clone of DIE. */
10021 clone_die (dw_die_ref die)
10027 clone = ggc_alloc_cleared_die_node ();
10028 clone->die_tag = die->die_tag;
10030 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10031 add_dwarf_attr (clone, a);
10036 /* Make a clone of the tree rooted at DIE. */
10039 clone_tree (dw_die_ref die)
10042 dw_die_ref clone = clone_die (die);
10044 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10049 /* Make a clone of DIE as a declaration. */
10052 clone_as_declaration (dw_die_ref die)
10059 /* If the DIE is already a declaration, just clone it. */
10060 if (is_declaration_die (die))
10061 return clone_die (die);
10063 /* If the DIE is a specification, just clone its declaration DIE. */
10064 decl = get_AT_ref (die, DW_AT_specification);
10066 return clone_die (decl);
10068 clone = ggc_alloc_cleared_die_node ();
10069 clone->die_tag = die->die_tag;
10071 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10073 /* We don't want to copy over all attributes.
10074 For example we don't want DW_AT_byte_size because otherwise we will no
10075 longer have a declaration and GDB will treat it as a definition. */
10077 switch (a->dw_attr)
10079 case DW_AT_artificial:
10080 case DW_AT_containing_type:
10081 case DW_AT_external:
10084 case DW_AT_virtuality:
10085 case DW_AT_linkage_name:
10086 case DW_AT_MIPS_linkage_name:
10087 add_dwarf_attr (clone, a);
10089 case DW_AT_byte_size:
10095 if (die->die_id.die_type_node)
10096 add_AT_die_ref (clone, DW_AT_signature, die);
10098 add_AT_flag (clone, DW_AT_declaration, 1);
10102 /* Copy the declaration context to the new compile unit DIE. This includes
10103 any surrounding namespace or type declarations. If the DIE has an
10104 AT_specification attribute, it also includes attributes and children
10105 attached to the specification. */
10108 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10111 dw_die_ref new_decl;
10113 decl = get_AT_ref (die, DW_AT_specification);
10122 /* Copy the type node pointer from the new DIE to the original
10123 declaration DIE so we can forward references later. */
10124 decl->die_id.die_type_node = die->die_id.die_type_node;
10126 remove_AT (die, DW_AT_specification);
10128 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10130 if (a->dw_attr != DW_AT_name
10131 && a->dw_attr != DW_AT_declaration
10132 && a->dw_attr != DW_AT_external)
10133 add_dwarf_attr (die, a);
10136 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10139 if (decl->die_parent != NULL
10140 && decl->die_parent->die_tag != DW_TAG_compile_unit
10141 && decl->die_parent->die_tag != DW_TAG_type_unit)
10143 new_decl = copy_ancestor_tree (unit, decl, NULL);
10144 if (new_decl != NULL)
10146 remove_AT (new_decl, DW_AT_signature);
10147 add_AT_specification (die, new_decl);
10152 /* Generate the skeleton ancestor tree for the given NODE, then clone
10153 the DIE and add the clone into the tree. */
10156 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10158 if (node->new_die != NULL)
10161 node->new_die = clone_as_declaration (node->old_die);
10163 if (node->parent != NULL)
10165 generate_skeleton_ancestor_tree (node->parent);
10166 add_child_die (node->parent->new_die, node->new_die);
10170 /* Generate a skeleton tree of DIEs containing any declarations that are
10171 found in the original tree. We traverse the tree looking for declaration
10172 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10175 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10177 skeleton_chain_node node;
10180 dw_die_ref prev = NULL;
10181 dw_die_ref next = NULL;
10183 node.parent = parent;
10185 first = c = parent->old_die->die_child;
10189 if (prev == NULL || prev->die_sib == c)
10192 next = (c == first ? NULL : c->die_sib);
10194 node.new_die = NULL;
10195 if (is_declaration_die (c))
10197 /* Clone the existing DIE, move the original to the skeleton
10198 tree (which is in the main CU), and put the clone, with
10199 all the original's children, where the original came from. */
10200 dw_die_ref clone = clone_die (c);
10201 move_all_children (c, clone);
10203 replace_child (c, clone, prev);
10204 generate_skeleton_ancestor_tree (parent);
10205 add_child_die (parent->new_die, c);
10209 generate_skeleton_bottom_up (&node);
10210 } while (next != NULL);
10213 /* Wrapper function for generate_skeleton_bottom_up. */
10216 generate_skeleton (dw_die_ref die)
10218 skeleton_chain_node node;
10220 node.old_die = die;
10221 node.new_die = NULL;
10222 node.parent = NULL;
10224 /* If this type definition is nested inside another type,
10225 always leave at least a declaration in its place. */
10226 if (die->die_parent != NULL && is_type_die (die->die_parent))
10227 node.new_die = clone_as_declaration (die);
10229 generate_skeleton_bottom_up (&node);
10230 return node.new_die;
10233 /* Remove the DIE from its parent, possibly replacing it with a cloned
10234 declaration. The original DIE will be moved to a new compile unit
10235 so that existing references to it follow it to the new location. If
10236 any of the original DIE's descendants is a declaration, we need to
10237 replace the original DIE with a skeleton tree and move the
10238 declarations back into the skeleton tree. */
10241 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10243 dw_die_ref skeleton;
10245 skeleton = generate_skeleton (child);
10246 if (skeleton == NULL)
10247 remove_child_with_prev (child, prev);
10250 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10251 replace_child (child, skeleton, prev);
10257 /* Traverse the DIE and set up additional .debug_types sections for each
10258 type worthy of being placed in a COMDAT section. */
10261 break_out_comdat_types (dw_die_ref die)
10265 dw_die_ref prev = NULL;
10266 dw_die_ref next = NULL;
10267 dw_die_ref unit = NULL;
10269 first = c = die->die_child;
10273 if (prev == NULL || prev->die_sib == c)
10276 next = (c == first ? NULL : c->die_sib);
10277 if (should_move_die_to_comdat (c))
10279 dw_die_ref replacement;
10280 comdat_type_node_ref type_node;
10282 /* Create a new type unit DIE as the root for the new tree, and
10283 add it to the list of comdat types. */
10284 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10285 add_AT_unsigned (unit, DW_AT_language,
10286 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10287 type_node = ggc_alloc_cleared_comdat_type_node ();
10288 type_node->root_die = unit;
10289 type_node->next = comdat_type_list;
10290 comdat_type_list = type_node;
10292 /* Generate the type signature. */
10293 generate_type_signature (c, type_node);
10295 /* Copy the declaration context, attributes, and children of the
10296 declaration into the new compile unit DIE. */
10297 copy_declaration_context (unit, c);
10299 /* Remove this DIE from the main CU. */
10300 replacement = remove_child_or_replace_with_skeleton (c, prev);
10302 /* Break out nested types into their own type units. */
10303 break_out_comdat_types (c);
10305 /* Add the DIE to the new compunit. */
10306 add_child_die (unit, c);
10308 if (replacement != NULL)
10311 else if (c->die_tag == DW_TAG_namespace
10312 || c->die_tag == DW_TAG_class_type
10313 || c->die_tag == DW_TAG_structure_type
10314 || c->die_tag == DW_TAG_union_type)
10316 /* Look for nested types that can be broken out. */
10317 break_out_comdat_types (c);
10319 } while (next != NULL);
10322 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10324 struct decl_table_entry
10330 /* Routines to manipulate hash table of copied declarations. */
10333 htab_decl_hash (const void *of)
10335 const struct decl_table_entry *const entry =
10336 (const struct decl_table_entry *) of;
10338 return htab_hash_pointer (entry->orig);
10342 htab_decl_eq (const void *of1, const void *of2)
10344 const struct decl_table_entry *const entry1 =
10345 (const struct decl_table_entry *) of1;
10346 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10348 return entry1->orig == entry2;
10352 htab_decl_del (void *what)
10354 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10359 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10360 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10361 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10362 to check if the ancestor has already been copied into UNIT. */
10365 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10367 dw_die_ref parent = die->die_parent;
10368 dw_die_ref new_parent = unit;
10370 void **slot = NULL;
10371 struct decl_table_entry *entry = NULL;
10375 /* Check if the entry has already been copied to UNIT. */
10376 slot = htab_find_slot_with_hash (decl_table, die,
10377 htab_hash_pointer (die), INSERT);
10378 if (*slot != HTAB_EMPTY_ENTRY)
10380 entry = (struct decl_table_entry *) *slot;
10381 return entry->copy;
10384 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10385 entry = XCNEW (struct decl_table_entry);
10387 entry->copy = NULL;
10391 if (parent != NULL)
10393 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10396 if (parent->die_tag != DW_TAG_compile_unit
10397 && parent->die_tag != DW_TAG_type_unit)
10398 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10401 copy = clone_as_declaration (die);
10402 add_child_die (new_parent, copy);
10404 if (decl_table != NULL)
10406 /* Record the pointer to the copy. */
10407 entry->copy = copy;
10413 /* Like clone_tree, but additionally enter all the children into
10414 the hash table decl_table. */
10417 clone_tree_hash (dw_die_ref die, htab_t decl_table)
10420 dw_die_ref clone = clone_die (die);
10421 struct decl_table_entry *entry;
10422 void **slot = htab_find_slot_with_hash (decl_table, die,
10423 htab_hash_pointer (die), INSERT);
10424 /* Assert that DIE isn't in the hash table yet. If it would be there
10425 before, the ancestors would be necessarily there as well, therefore
10426 clone_tree_hash wouldn't be called. */
10427 gcc_assert (*slot == HTAB_EMPTY_ENTRY);
10428 entry = XCNEW (struct decl_table_entry);
10430 entry->copy = clone;
10433 FOR_EACH_CHILD (die, c,
10434 add_child_die (clone, clone_tree_hash (c, decl_table)));
10439 /* Walk the DIE and its children, looking for references to incomplete
10440 or trivial types that are unmarked (i.e., that are not in the current
10444 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10450 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10452 if (AT_class (a) == dw_val_class_die_ref)
10454 dw_die_ref targ = AT_ref (a);
10455 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10457 struct decl_table_entry *entry;
10459 if (targ->die_mark != 0 || type_node != NULL)
10462 slot = htab_find_slot_with_hash (decl_table, targ,
10463 htab_hash_pointer (targ), INSERT);
10465 if (*slot != HTAB_EMPTY_ENTRY)
10467 /* TARG has already been copied, so we just need to
10468 modify the reference to point to the copy. */
10469 entry = (struct decl_table_entry *) *slot;
10470 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10474 dw_die_ref parent = unit;
10475 dw_die_ref copy = clone_die (targ);
10477 /* Record in DECL_TABLE that TARG has been copied.
10478 Need to do this now, before the recursive call,
10479 because DECL_TABLE may be expanded and SLOT
10480 would no longer be a valid pointer. */
10481 entry = XCNEW (struct decl_table_entry);
10482 entry->orig = targ;
10483 entry->copy = copy;
10486 FOR_EACH_CHILD (targ, c,
10487 add_child_die (copy,
10488 clone_tree_hash (c, decl_table)));
10490 /* Make sure the cloned tree is marked as part of the
10494 /* If TARG has surrounding context, copy its ancestor tree
10495 into the new type unit. */
10496 if (targ->die_parent != NULL
10497 && targ->die_parent->die_tag != DW_TAG_compile_unit
10498 && targ->die_parent->die_tag != DW_TAG_type_unit)
10499 parent = copy_ancestor_tree (unit, targ->die_parent,
10502 add_child_die (parent, copy);
10503 a->dw_attr_val.v.val_die_ref.die = copy;
10505 /* Make sure the newly-copied DIE is walked. If it was
10506 installed in a previously-added context, it won't
10507 get visited otherwise. */
10508 if (parent != unit)
10510 /* Find the highest point of the newly-added tree,
10511 mark each node along the way, and walk from there. */
10512 parent->die_mark = 1;
10513 while (parent->die_parent
10514 && parent->die_parent->die_mark == 0)
10516 parent = parent->die_parent;
10517 parent->die_mark = 1;
10519 copy_decls_walk (unit, parent, decl_table);
10525 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10528 /* Copy declarations for "unworthy" types into the new comdat section.
10529 Incomplete types, modified types, and certain other types aren't broken
10530 out into comdat sections of their own, so they don't have a signature,
10531 and we need to copy the declaration into the same section so that we
10532 don't have an external reference. */
10535 copy_decls_for_unworthy_types (dw_die_ref unit)
10540 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10541 copy_decls_walk (unit, unit, decl_table);
10542 htab_delete (decl_table);
10543 unmark_dies (unit);
10546 /* Traverse the DIE and add a sibling attribute if it may have the
10547 effect of speeding up access to siblings. To save some space,
10548 avoid generating sibling attributes for DIE's without children. */
10551 add_sibling_attributes (dw_die_ref die)
10555 if (! die->die_child)
10558 if (die->die_parent && die != die->die_parent->die_child)
10559 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10561 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10564 /* Output all location lists for the DIE and its children. */
10567 output_location_lists (dw_die_ref die)
10573 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10574 if (AT_class (a) == dw_val_class_loc_list)
10575 output_loc_list (AT_loc_list (a));
10577 FOR_EACH_CHILD (die, c, output_location_lists (c));
10580 /* The format of each DIE (and its attribute value pairs) is encoded in an
10581 abbreviation table. This routine builds the abbreviation table and assigns
10582 a unique abbreviation id for each abbreviation entry. The children of each
10583 die are visited recursively. */
10586 build_abbrev_table (dw_die_ref die)
10588 unsigned long abbrev_id;
10589 unsigned int n_alloc;
10594 /* Scan the DIE references, and mark as external any that refer to
10595 DIEs from other CUs (i.e. those which are not marked). */
10596 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10597 if (AT_class (a) == dw_val_class_die_ref
10598 && AT_ref (a)->die_mark == 0)
10600 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10601 set_AT_ref_external (a, 1);
10604 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10606 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10607 dw_attr_ref die_a, abbrev_a;
10611 if (abbrev->die_tag != die->die_tag)
10613 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10616 if (VEC_length (dw_attr_node, abbrev->die_attr)
10617 != VEC_length (dw_attr_node, die->die_attr))
10620 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10622 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10623 if ((abbrev_a->dw_attr != die_a->dw_attr)
10624 || (value_format (abbrev_a) != value_format (die_a)))
10634 if (abbrev_id >= abbrev_die_table_in_use)
10636 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10638 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10639 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10642 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10643 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10644 abbrev_die_table_allocated = n_alloc;
10647 ++abbrev_die_table_in_use;
10648 abbrev_die_table[abbrev_id] = die;
10651 die->die_abbrev = abbrev_id;
10652 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10655 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10658 constant_size (unsigned HOST_WIDE_INT value)
10665 log = floor_log2 (value);
10668 log = 1 << (floor_log2 (log) + 1);
10673 /* Return the size of a DIE as it is represented in the
10674 .debug_info section. */
10676 static unsigned long
10677 size_of_die (dw_die_ref die)
10679 unsigned long size = 0;
10683 size += size_of_uleb128 (die->die_abbrev);
10684 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10686 switch (AT_class (a))
10688 case dw_val_class_addr:
10689 size += DWARF2_ADDR_SIZE;
10691 case dw_val_class_offset:
10692 size += DWARF_OFFSET_SIZE;
10694 case dw_val_class_loc:
10696 unsigned long lsize = size_of_locs (AT_loc (a));
10698 /* Block length. */
10699 if (dwarf_version >= 4)
10700 size += size_of_uleb128 (lsize);
10702 size += constant_size (lsize);
10706 case dw_val_class_loc_list:
10707 size += DWARF_OFFSET_SIZE;
10709 case dw_val_class_range_list:
10710 size += DWARF_OFFSET_SIZE;
10712 case dw_val_class_const:
10713 size += size_of_sleb128 (AT_int (a));
10715 case dw_val_class_unsigned_const:
10717 int csize = constant_size (AT_unsigned (a));
10718 if (dwarf_version == 3
10719 && a->dw_attr == DW_AT_data_member_location
10721 size += size_of_uleb128 (AT_unsigned (a));
10726 case dw_val_class_const_double:
10727 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10728 if (HOST_BITS_PER_WIDE_INT >= 64)
10729 size++; /* block */
10731 case dw_val_class_vec:
10732 size += constant_size (a->dw_attr_val.v.val_vec.length
10733 * a->dw_attr_val.v.val_vec.elt_size)
10734 + a->dw_attr_val.v.val_vec.length
10735 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10737 case dw_val_class_flag:
10738 if (dwarf_version >= 4)
10739 /* Currently all add_AT_flag calls pass in 1 as last argument,
10740 so DW_FORM_flag_present can be used. If that ever changes,
10741 we'll need to use DW_FORM_flag and have some optimization
10742 in build_abbrev_table that will change those to
10743 DW_FORM_flag_present if it is set to 1 in all DIEs using
10744 the same abbrev entry. */
10745 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10749 case dw_val_class_die_ref:
10750 if (AT_ref_external (a))
10752 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10753 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10754 is sized by target address length, whereas in DWARF3
10755 it's always sized as an offset. */
10756 if (dwarf_version >= 4)
10757 size += DWARF_TYPE_SIGNATURE_SIZE;
10758 else if (dwarf_version == 2)
10759 size += DWARF2_ADDR_SIZE;
10761 size += DWARF_OFFSET_SIZE;
10764 size += DWARF_OFFSET_SIZE;
10766 case dw_val_class_fde_ref:
10767 size += DWARF_OFFSET_SIZE;
10769 case dw_val_class_lbl_id:
10770 size += DWARF2_ADDR_SIZE;
10772 case dw_val_class_lineptr:
10773 case dw_val_class_macptr:
10774 size += DWARF_OFFSET_SIZE;
10776 case dw_val_class_str:
10777 if (AT_string_form (a) == DW_FORM_strp)
10778 size += DWARF_OFFSET_SIZE;
10780 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10782 case dw_val_class_file:
10783 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10785 case dw_val_class_data8:
10788 case dw_val_class_vms_delta:
10789 size += DWARF_OFFSET_SIZE;
10792 gcc_unreachable ();
10799 /* Size the debugging information associated with a given DIE. Visits the
10800 DIE's children recursively. Updates the global variable next_die_offset, on
10801 each time through. Uses the current value of next_die_offset to update the
10802 die_offset field in each DIE. */
10805 calc_die_sizes (dw_die_ref die)
10809 die->die_offset = next_die_offset;
10810 next_die_offset += size_of_die (die);
10812 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10814 if (die->die_child != NULL)
10815 /* Count the null byte used to terminate sibling lists. */
10816 next_die_offset += 1;
10819 /* Set the marks for a die and its children. We do this so
10820 that we know whether or not a reference needs to use FORM_ref_addr; only
10821 DIEs in the same CU will be marked. We used to clear out the offset
10822 and use that as the flag, but ran into ordering problems. */
10825 mark_dies (dw_die_ref die)
10829 gcc_assert (!die->die_mark);
10832 FOR_EACH_CHILD (die, c, mark_dies (c));
10835 /* Clear the marks for a die and its children. */
10838 unmark_dies (dw_die_ref die)
10842 if (dwarf_version < 4)
10843 gcc_assert (die->die_mark);
10846 FOR_EACH_CHILD (die, c, unmark_dies (c));
10849 /* Clear the marks for a die, its children and referred dies. */
10852 unmark_all_dies (dw_die_ref die)
10858 if (!die->die_mark)
10862 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10864 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10865 if (AT_class (a) == dw_val_class_die_ref)
10866 unmark_all_dies (AT_ref (a));
10869 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10870 generated for the compilation unit. */
10872 static unsigned long
10873 size_of_pubnames (VEC (pubname_entry, gc) * names)
10875 unsigned long size;
10879 size = DWARF_PUBNAMES_HEADER_SIZE;
10880 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10881 if (names != pubtype_table
10882 || p->die->die_offset != 0
10883 || !flag_eliminate_unused_debug_types)
10884 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10886 size += DWARF_OFFSET_SIZE;
10890 /* Return the size of the information in the .debug_aranges section. */
10892 static unsigned long
10893 size_of_aranges (void)
10895 unsigned long size;
10897 size = DWARF_ARANGES_HEADER_SIZE;
10899 /* Count the address/length pair for this compilation unit. */
10900 if (text_section_used)
10901 size += 2 * DWARF2_ADDR_SIZE;
10902 if (cold_text_section_used)
10903 size += 2 * DWARF2_ADDR_SIZE;
10904 if (have_multiple_function_sections)
10906 unsigned fde_idx = 0;
10908 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
10910 dw_fde_ref fde = &fde_table[fde_idx];
10912 if (!fde->in_std_section)
10913 size += 2 * DWARF2_ADDR_SIZE;
10914 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
10915 size += 2 * DWARF2_ADDR_SIZE;
10919 /* Count the two zero words used to terminated the address range table. */
10920 size += 2 * DWARF2_ADDR_SIZE;
10924 /* Select the encoding of an attribute value. */
10926 static enum dwarf_form
10927 value_format (dw_attr_ref a)
10929 switch (a->dw_attr_val.val_class)
10931 case dw_val_class_addr:
10932 /* Only very few attributes allow DW_FORM_addr. */
10933 switch (a->dw_attr)
10936 case DW_AT_high_pc:
10937 case DW_AT_entry_pc:
10938 case DW_AT_trampoline:
10939 return DW_FORM_addr;
10943 switch (DWARF2_ADDR_SIZE)
10946 return DW_FORM_data1;
10948 return DW_FORM_data2;
10950 return DW_FORM_data4;
10952 return DW_FORM_data8;
10954 gcc_unreachable ();
10956 case dw_val_class_range_list:
10957 case dw_val_class_loc_list:
10958 if (dwarf_version >= 4)
10959 return DW_FORM_sec_offset;
10961 case dw_val_class_vms_delta:
10962 case dw_val_class_offset:
10963 switch (DWARF_OFFSET_SIZE)
10966 return DW_FORM_data4;
10968 return DW_FORM_data8;
10970 gcc_unreachable ();
10972 case dw_val_class_loc:
10973 if (dwarf_version >= 4)
10974 return DW_FORM_exprloc;
10975 switch (constant_size (size_of_locs (AT_loc (a))))
10978 return DW_FORM_block1;
10980 return DW_FORM_block2;
10982 gcc_unreachable ();
10984 case dw_val_class_const:
10985 return DW_FORM_sdata;
10986 case dw_val_class_unsigned_const:
10987 switch (constant_size (AT_unsigned (a)))
10990 return DW_FORM_data1;
10992 return DW_FORM_data2;
10994 /* In DWARF3 DW_AT_data_member_location with
10995 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
10996 constant, so we need to use DW_FORM_udata if we need
10997 a large constant. */
10998 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
10999 return DW_FORM_udata;
11000 return DW_FORM_data4;
11002 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
11003 return DW_FORM_udata;
11004 return DW_FORM_data8;
11006 gcc_unreachable ();
11008 case dw_val_class_const_double:
11009 switch (HOST_BITS_PER_WIDE_INT)
11012 return DW_FORM_data2;
11014 return DW_FORM_data4;
11016 return DW_FORM_data8;
11019 return DW_FORM_block1;
11021 case dw_val_class_vec:
11022 switch (constant_size (a->dw_attr_val.v.val_vec.length
11023 * a->dw_attr_val.v.val_vec.elt_size))
11026 return DW_FORM_block1;
11028 return DW_FORM_block2;
11030 return DW_FORM_block4;
11032 gcc_unreachable ();
11034 case dw_val_class_flag:
11035 if (dwarf_version >= 4)
11037 /* Currently all add_AT_flag calls pass in 1 as last argument,
11038 so DW_FORM_flag_present can be used. If that ever changes,
11039 we'll need to use DW_FORM_flag and have some optimization
11040 in build_abbrev_table that will change those to
11041 DW_FORM_flag_present if it is set to 1 in all DIEs using
11042 the same abbrev entry. */
11043 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11044 return DW_FORM_flag_present;
11046 return DW_FORM_flag;
11047 case dw_val_class_die_ref:
11048 if (AT_ref_external (a))
11049 return dwarf_version >= 4 ? DW_FORM_sig8 : DW_FORM_ref_addr;
11051 return DW_FORM_ref;
11052 case dw_val_class_fde_ref:
11053 return DW_FORM_data;
11054 case dw_val_class_lbl_id:
11055 return DW_FORM_addr;
11056 case dw_val_class_lineptr:
11057 case dw_val_class_macptr:
11058 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11059 case dw_val_class_str:
11060 return AT_string_form (a);
11061 case dw_val_class_file:
11062 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11065 return DW_FORM_data1;
11067 return DW_FORM_data2;
11069 return DW_FORM_data4;
11071 gcc_unreachable ();
11074 case dw_val_class_data8:
11075 return DW_FORM_data8;
11078 gcc_unreachable ();
11082 /* Output the encoding of an attribute value. */
11085 output_value_format (dw_attr_ref a)
11087 enum dwarf_form form = value_format (a);
11089 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11092 /* Output the .debug_abbrev section which defines the DIE abbreviation
11096 output_abbrev_section (void)
11098 unsigned long abbrev_id;
11100 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11102 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11104 dw_attr_ref a_attr;
11106 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11107 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11108 dwarf_tag_name (abbrev->die_tag));
11110 if (abbrev->die_child != NULL)
11111 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11113 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11115 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11118 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11119 dwarf_attr_name (a_attr->dw_attr));
11120 output_value_format (a_attr);
11123 dw2_asm_output_data (1, 0, NULL);
11124 dw2_asm_output_data (1, 0, NULL);
11127 /* Terminate the table. */
11128 dw2_asm_output_data (1, 0, NULL);
11131 /* Output a symbol we can use to refer to this DIE from another CU. */
11134 output_die_symbol (dw_die_ref die)
11136 char *sym = die->die_id.die_symbol;
11141 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11142 /* We make these global, not weak; if the target doesn't support
11143 .linkonce, it doesn't support combining the sections, so debugging
11145 targetm.asm_out.globalize_label (asm_out_file, sym);
11147 ASM_OUTPUT_LABEL (asm_out_file, sym);
11150 /* Return a new location list, given the begin and end range, and the
11153 static inline dw_loc_list_ref
11154 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11155 const char *section)
11157 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11159 retlist->begin = begin;
11160 retlist->end = end;
11161 retlist->expr = expr;
11162 retlist->section = section;
11167 /* Generate a new internal symbol for this location list node, if it
11168 hasn't got one yet. */
11171 gen_llsym (dw_loc_list_ref list)
11173 gcc_assert (!list->ll_symbol);
11174 list->ll_symbol = gen_internal_sym ("LLST");
11177 /* Output the location list given to us. */
11180 output_loc_list (dw_loc_list_ref list_head)
11182 dw_loc_list_ref curr = list_head;
11184 if (list_head->emitted)
11186 list_head->emitted = true;
11188 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11190 /* Walk the location list, and output each range + expression. */
11191 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11193 unsigned long size;
11194 /* Don't output an entry that starts and ends at the same address. */
11195 if (strcmp (curr->begin, curr->end) == 0)
11197 size = size_of_locs (curr->expr);
11198 /* If the expression is too large, drop it on the floor. We could
11199 perhaps put it into DW_TAG_dwarf_procedure and refer to that
11200 in the expression, but >= 64KB expressions for a single value
11201 in a single range are unlikely very useful. */
11204 if (!have_multiple_function_sections)
11206 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11207 "Location list begin address (%s)",
11208 list_head->ll_symbol);
11209 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11210 "Location list end address (%s)",
11211 list_head->ll_symbol);
11215 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11216 "Location list begin address (%s)",
11217 list_head->ll_symbol);
11218 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11219 "Location list end address (%s)",
11220 list_head->ll_symbol);
11223 /* Output the block length for this list of location operations. */
11224 gcc_assert (size <= 0xffff);
11225 dw2_asm_output_data (2, size, "%s", "Location expression size");
11227 output_loc_sequence (curr->expr, -1);
11230 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11231 "Location list terminator begin (%s)",
11232 list_head->ll_symbol);
11233 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11234 "Location list terminator end (%s)",
11235 list_head->ll_symbol);
11238 /* Output a type signature. */
11241 output_signature (const char *sig, const char *name)
11245 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11246 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11249 /* Output the DIE and its attributes. Called recursively to generate
11250 the definitions of each child DIE. */
11253 output_die (dw_die_ref die)
11257 unsigned long size;
11260 /* If someone in another CU might refer to us, set up a symbol for
11261 them to point to. */
11262 if (dwarf_version < 4 && die->die_id.die_symbol)
11263 output_die_symbol (die);
11265 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11266 (unsigned long)die->die_offset,
11267 dwarf_tag_name (die->die_tag));
11269 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11271 const char *name = dwarf_attr_name (a->dw_attr);
11273 switch (AT_class (a))
11275 case dw_val_class_addr:
11276 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11279 case dw_val_class_offset:
11280 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11284 case dw_val_class_range_list:
11286 char *p = strchr (ranges_section_label, '\0');
11288 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11289 a->dw_attr_val.v.val_offset);
11290 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11291 debug_ranges_section, "%s", name);
11296 case dw_val_class_loc:
11297 size = size_of_locs (AT_loc (a));
11299 /* Output the block length for this list of location operations. */
11300 if (dwarf_version >= 4)
11301 dw2_asm_output_data_uleb128 (size, "%s", name);
11303 dw2_asm_output_data (constant_size (size), size, "%s", name);
11305 output_loc_sequence (AT_loc (a), -1);
11308 case dw_val_class_const:
11309 /* ??? It would be slightly more efficient to use a scheme like is
11310 used for unsigned constants below, but gdb 4.x does not sign
11311 extend. Gdb 5.x does sign extend. */
11312 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11315 case dw_val_class_unsigned_const:
11317 int csize = constant_size (AT_unsigned (a));
11318 if (dwarf_version == 3
11319 && a->dw_attr == DW_AT_data_member_location
11321 dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
11323 dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
11327 case dw_val_class_const_double:
11329 unsigned HOST_WIDE_INT first, second;
11331 if (HOST_BITS_PER_WIDE_INT >= 64)
11332 dw2_asm_output_data (1,
11333 2 * HOST_BITS_PER_WIDE_INT
11334 / HOST_BITS_PER_CHAR,
11337 if (WORDS_BIG_ENDIAN)
11339 first = a->dw_attr_val.v.val_double.high;
11340 second = a->dw_attr_val.v.val_double.low;
11344 first = a->dw_attr_val.v.val_double.low;
11345 second = a->dw_attr_val.v.val_double.high;
11348 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11350 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11355 case dw_val_class_vec:
11357 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11358 unsigned int len = a->dw_attr_val.v.val_vec.length;
11362 dw2_asm_output_data (constant_size (len * elt_size),
11363 len * elt_size, "%s", name);
11364 if (elt_size > sizeof (HOST_WIDE_INT))
11369 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11371 i++, p += elt_size)
11372 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11373 "fp or vector constant word %u", i);
11377 case dw_val_class_flag:
11378 if (dwarf_version >= 4)
11380 /* Currently all add_AT_flag calls pass in 1 as last argument,
11381 so DW_FORM_flag_present can be used. If that ever changes,
11382 we'll need to use DW_FORM_flag and have some optimization
11383 in build_abbrev_table that will change those to
11384 DW_FORM_flag_present if it is set to 1 in all DIEs using
11385 the same abbrev entry. */
11386 gcc_assert (AT_flag (a) == 1);
11387 if (flag_debug_asm)
11388 fprintf (asm_out_file, "\t\t\t%s %s\n",
11389 ASM_COMMENT_START, name);
11392 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11395 case dw_val_class_loc_list:
11397 char *sym = AT_loc_list (a)->ll_symbol;
11400 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11405 case dw_val_class_die_ref:
11406 if (AT_ref_external (a))
11408 if (dwarf_version >= 4)
11410 comdat_type_node_ref type_node =
11411 AT_ref (a)->die_id.die_type_node;
11413 gcc_assert (type_node);
11414 output_signature (type_node->signature, name);
11418 char *sym = AT_ref (a)->die_id.die_symbol;
11422 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11423 length, whereas in DWARF3 it's always sized as an
11425 if (dwarf_version == 2)
11426 size = DWARF2_ADDR_SIZE;
11428 size = DWARF_OFFSET_SIZE;
11429 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11435 gcc_assert (AT_ref (a)->die_offset);
11436 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11441 case dw_val_class_fde_ref:
11445 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11446 a->dw_attr_val.v.val_fde_index * 2);
11447 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11452 case dw_val_class_vms_delta:
11453 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11454 AT_vms_delta2 (a), AT_vms_delta1 (a),
11458 case dw_val_class_lbl_id:
11459 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11462 case dw_val_class_lineptr:
11463 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11464 debug_line_section, "%s", name);
11467 case dw_val_class_macptr:
11468 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11469 debug_macinfo_section, "%s", name);
11472 case dw_val_class_str:
11473 if (AT_string_form (a) == DW_FORM_strp)
11474 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11475 a->dw_attr_val.v.val_str->label,
11477 "%s: \"%s\"", name, AT_string (a));
11479 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11482 case dw_val_class_file:
11484 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11486 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11487 a->dw_attr_val.v.val_file->filename);
11491 case dw_val_class_data8:
11495 for (i = 0; i < 8; i++)
11496 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11497 i == 0 ? "%s" : NULL, name);
11502 gcc_unreachable ();
11506 FOR_EACH_CHILD (die, c, output_die (c));
11508 /* Add null byte to terminate sibling list. */
11509 if (die->die_child != NULL)
11510 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11511 (unsigned long) die->die_offset);
11514 /* Output the compilation unit that appears at the beginning of the
11515 .debug_info section, and precedes the DIE descriptions. */
11518 output_compilation_unit_header (void)
11520 int ver = dwarf_version;
11522 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11523 dw2_asm_output_data (4, 0xffffffff,
11524 "Initial length escape value indicating 64-bit DWARF extension");
11525 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11526 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11527 "Length of Compilation Unit Info");
11528 dw2_asm_output_data (2, ver, "DWARF version number");
11529 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11530 debug_abbrev_section,
11531 "Offset Into Abbrev. Section");
11532 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11535 /* Output the compilation unit DIE and its children. */
11538 output_comp_unit (dw_die_ref die, int output_if_empty)
11540 const char *secname;
11541 char *oldsym, *tmp;
11543 /* Unless we are outputting main CU, we may throw away empty ones. */
11544 if (!output_if_empty && die->die_child == NULL)
11547 /* Even if there are no children of this DIE, we must output the information
11548 about the compilation unit. Otherwise, on an empty translation unit, we
11549 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11550 will then complain when examining the file. First mark all the DIEs in
11551 this CU so we know which get local refs. */
11554 build_abbrev_table (die);
11556 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11557 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11558 calc_die_sizes (die);
11560 oldsym = die->die_id.die_symbol;
11563 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11565 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11567 die->die_id.die_symbol = NULL;
11568 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11572 switch_to_section (debug_info_section);
11573 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11574 info_section_emitted = true;
11577 /* Output debugging information. */
11578 output_compilation_unit_header ();
11581 /* Leave the marks on the main CU, so we can check them in
11582 output_pubnames. */
11586 die->die_id.die_symbol = oldsym;
11590 /* Output a comdat type unit DIE and its children. */
11593 output_comdat_type_unit (comdat_type_node *node)
11595 const char *secname;
11598 #if defined (OBJECT_FORMAT_ELF)
11602 /* First mark all the DIEs in this CU so we know which get local refs. */
11603 mark_dies (node->root_die);
11605 build_abbrev_table (node->root_die);
11607 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11608 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11609 calc_die_sizes (node->root_die);
11611 #if defined (OBJECT_FORMAT_ELF)
11612 secname = ".debug_types";
11613 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11614 sprintf (tmp, "wt.");
11615 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11616 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11617 comdat_key = get_identifier (tmp);
11618 targetm.asm_out.named_section (secname,
11619 SECTION_DEBUG | SECTION_LINKONCE,
11622 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11623 sprintf (tmp, ".gnu.linkonce.wt.");
11624 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11625 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11627 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11630 /* Output debugging information. */
11631 output_compilation_unit_header ();
11632 output_signature (node->signature, "Type Signature");
11633 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11634 "Offset to Type DIE");
11635 output_die (node->root_die);
11637 unmark_dies (node->root_die);
11640 /* Return the DWARF2/3 pubname associated with a decl. */
11642 static const char *
11643 dwarf2_name (tree decl, int scope)
11645 if (DECL_NAMELESS (decl))
11647 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11650 /* Add a new entry to .debug_pubnames if appropriate. */
11653 add_pubname_string (const char *str, dw_die_ref die)
11655 if (targetm.want_debug_pub_sections)
11660 e.name = xstrdup (str);
11661 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11666 add_pubname (tree decl, dw_die_ref die)
11668 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11670 const char *name = dwarf2_name (decl, 1);
11672 add_pubname_string (name, die);
11676 /* Add a new entry to .debug_pubtypes if appropriate. */
11679 add_pubtype (tree decl, dw_die_ref die)
11683 if (!targetm.want_debug_pub_sections)
11687 if ((TREE_PUBLIC (decl)
11688 || is_cu_die (die->die_parent))
11689 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11694 if (TYPE_NAME (decl))
11696 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11697 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11698 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11699 && DECL_NAME (TYPE_NAME (decl)))
11700 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11702 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11707 e.name = dwarf2_name (decl, 1);
11709 e.name = xstrdup (e.name);
11712 /* If we don't have a name for the type, there's no point in adding
11713 it to the table. */
11714 if (e.name && e.name[0] != '\0')
11715 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11719 /* Output the public names table used to speed up access to externally
11720 visible names; or the public types table used to find type definitions. */
11723 output_pubnames (VEC (pubname_entry, gc) * names)
11726 unsigned long pubnames_length = size_of_pubnames (names);
11729 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11730 dw2_asm_output_data (4, 0xffffffff,
11731 "Initial length escape value indicating 64-bit DWARF extension");
11732 if (names == pubname_table)
11733 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11734 "Length of Public Names Info");
11736 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11737 "Length of Public Type Names Info");
11738 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11739 dw2_asm_output_data (2, 2, "DWARF Version");
11740 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11741 debug_info_section,
11742 "Offset of Compilation Unit Info");
11743 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11744 "Compilation Unit Length");
11746 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11748 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11749 if (names == pubname_table)
11750 gcc_assert (pub->die->die_mark);
11752 if (names != pubtype_table
11753 || pub->die->die_offset != 0
11754 || !flag_eliminate_unused_debug_types)
11756 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11759 dw2_asm_output_nstring (pub->name, -1, "external name");
11763 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11766 /* Output the information that goes into the .debug_aranges table.
11767 Namely, define the beginning and ending address range of the
11768 text section generated for this compilation unit. */
11771 output_aranges (unsigned long aranges_length)
11775 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11776 dw2_asm_output_data (4, 0xffffffff,
11777 "Initial length escape value indicating 64-bit DWARF extension");
11778 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11779 "Length of Address Ranges Info");
11780 /* Version number for aranges is still 2, even in DWARF3. */
11781 dw2_asm_output_data (2, 2, "DWARF Version");
11782 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11783 debug_info_section,
11784 "Offset of Compilation Unit Info");
11785 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11786 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11788 /* We need to align to twice the pointer size here. */
11789 if (DWARF_ARANGES_PAD_SIZE)
11791 /* Pad using a 2 byte words so that padding is correct for any
11793 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11794 2 * DWARF2_ADDR_SIZE);
11795 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11796 dw2_asm_output_data (2, 0, NULL);
11799 /* It is necessary not to output these entries if the sections were
11800 not used; if the sections were not used, the length will be 0 and
11801 the address may end up as 0 if the section is discarded by ld
11802 --gc-sections, leaving an invalid (0, 0) entry that can be
11803 confused with the terminator. */
11804 if (text_section_used)
11806 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11807 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11808 text_section_label, "Length");
11810 if (cold_text_section_used)
11812 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11814 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11815 cold_text_section_label, "Length");
11818 if (have_multiple_function_sections)
11820 unsigned fde_idx = 0;
11822 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
11824 dw_fde_ref fde = &fde_table[fde_idx];
11826 if (!fde->in_std_section)
11828 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
11830 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
11831 fde->dw_fde_begin, "Length");
11833 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11835 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
11837 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
11838 fde->dw_fde_second_begin, "Length");
11843 /* Output the terminator words. */
11844 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11845 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11848 /* Add a new entry to .debug_ranges. Return the offset at which it
11851 static unsigned int
11852 add_ranges_num (int num)
11854 unsigned int in_use = ranges_table_in_use;
11856 if (in_use == ranges_table_allocated)
11858 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11859 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11860 ranges_table_allocated);
11861 memset (ranges_table + ranges_table_in_use, 0,
11862 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11865 ranges_table[in_use].num = num;
11866 ranges_table_in_use = in_use + 1;
11868 return in_use * 2 * DWARF2_ADDR_SIZE;
11871 /* Add a new entry to .debug_ranges corresponding to a block, or a
11872 range terminator if BLOCK is NULL. */
11874 static unsigned int
11875 add_ranges (const_tree block)
11877 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11880 /* Add a new entry to .debug_ranges corresponding to a pair of
11884 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11887 unsigned int in_use = ranges_by_label_in_use;
11888 unsigned int offset;
11890 if (in_use == ranges_by_label_allocated)
11892 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11893 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11895 ranges_by_label_allocated);
11896 memset (ranges_by_label + ranges_by_label_in_use, 0,
11897 RANGES_TABLE_INCREMENT
11898 * sizeof (struct dw_ranges_by_label_struct));
11901 ranges_by_label[in_use].begin = begin;
11902 ranges_by_label[in_use].end = end;
11903 ranges_by_label_in_use = in_use + 1;
11905 offset = add_ranges_num (-(int)in_use - 1);
11908 add_AT_range_list (die, DW_AT_ranges, offset);
11914 output_ranges (void)
11917 static const char *const start_fmt = "Offset %#x";
11918 const char *fmt = start_fmt;
11920 for (i = 0; i < ranges_table_in_use; i++)
11922 int block_num = ranges_table[i].num;
11926 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11927 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11929 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11930 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11932 /* If all code is in the text section, then the compilation
11933 unit base address defaults to DW_AT_low_pc, which is the
11934 base of the text section. */
11935 if (!have_multiple_function_sections)
11937 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11938 text_section_label,
11939 fmt, i * 2 * DWARF2_ADDR_SIZE);
11940 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11941 text_section_label, NULL);
11944 /* Otherwise, the compilation unit base address is zero,
11945 which allows us to use absolute addresses, and not worry
11946 about whether the target supports cross-section
11950 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11951 fmt, i * 2 * DWARF2_ADDR_SIZE);
11952 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11958 /* Negative block_num stands for an index into ranges_by_label. */
11959 else if (block_num < 0)
11961 int lab_idx = - block_num - 1;
11963 if (!have_multiple_function_sections)
11965 gcc_unreachable ();
11967 /* If we ever use add_ranges_by_labels () for a single
11968 function section, all we have to do is to take out
11969 the #if 0 above. */
11970 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11971 ranges_by_label[lab_idx].begin,
11972 text_section_label,
11973 fmt, i * 2 * DWARF2_ADDR_SIZE);
11974 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11975 ranges_by_label[lab_idx].end,
11976 text_section_label, NULL);
11981 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11982 ranges_by_label[lab_idx].begin,
11983 fmt, i * 2 * DWARF2_ADDR_SIZE);
11984 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11985 ranges_by_label[lab_idx].end,
11991 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11992 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11998 /* Data structure containing information about input files. */
12001 const char *path; /* Complete file name. */
12002 const char *fname; /* File name part. */
12003 int length; /* Length of entire string. */
12004 struct dwarf_file_data * file_idx; /* Index in input file table. */
12005 int dir_idx; /* Index in directory table. */
12008 /* Data structure containing information about directories with source
12012 const char *path; /* Path including directory name. */
12013 int length; /* Path length. */
12014 int prefix; /* Index of directory entry which is a prefix. */
12015 int count; /* Number of files in this directory. */
12016 int dir_idx; /* Index of directory used as base. */
12019 /* Callback function for file_info comparison. We sort by looking at
12020 the directories in the path. */
12023 file_info_cmp (const void *p1, const void *p2)
12025 const struct file_info *const s1 = (const struct file_info *) p1;
12026 const struct file_info *const s2 = (const struct file_info *) p2;
12027 const unsigned char *cp1;
12028 const unsigned char *cp2;
12030 /* Take care of file names without directories. We need to make sure that
12031 we return consistent values to qsort since some will get confused if
12032 we return the same value when identical operands are passed in opposite
12033 orders. So if neither has a directory, return 0 and otherwise return
12034 1 or -1 depending on which one has the directory. */
12035 if ((s1->path == s1->fname || s2->path == s2->fname))
12036 return (s2->path == s2->fname) - (s1->path == s1->fname);
12038 cp1 = (const unsigned char *) s1->path;
12039 cp2 = (const unsigned char *) s2->path;
12045 /* Reached the end of the first path? If so, handle like above. */
12046 if ((cp1 == (const unsigned char *) s1->fname)
12047 || (cp2 == (const unsigned char *) s2->fname))
12048 return ((cp2 == (const unsigned char *) s2->fname)
12049 - (cp1 == (const unsigned char *) s1->fname));
12051 /* Character of current path component the same? */
12052 else if (*cp1 != *cp2)
12053 return *cp1 - *cp2;
12057 struct file_name_acquire_data
12059 struct file_info *files;
12064 /* Traversal function for the hash table. */
12067 file_name_acquire (void ** slot, void *data)
12069 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12070 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12071 struct file_info *fi;
12074 gcc_assert (fnad->max_files >= d->emitted_number);
12076 if (! d->emitted_number)
12079 gcc_assert (fnad->max_files != fnad->used_files);
12081 fi = fnad->files + fnad->used_files++;
12083 /* Skip all leading "./". */
12085 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12088 /* Create a new array entry. */
12090 fi->length = strlen (f);
12093 /* Search for the file name part. */
12094 f = strrchr (f, DIR_SEPARATOR);
12095 #if defined (DIR_SEPARATOR_2)
12097 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12101 if (f == NULL || f < g)
12107 fi->fname = f == NULL ? fi->path : f + 1;
12111 /* Output the directory table and the file name table. We try to minimize
12112 the total amount of memory needed. A heuristic is used to avoid large
12113 slowdowns with many input files. */
12116 output_file_names (void)
12118 struct file_name_acquire_data fnad;
12120 struct file_info *files;
12121 struct dir_info *dirs;
12129 if (!last_emitted_file)
12131 dw2_asm_output_data (1, 0, "End directory table");
12132 dw2_asm_output_data (1, 0, "End file name table");
12136 numfiles = last_emitted_file->emitted_number;
12138 /* Allocate the various arrays we need. */
12139 files = XALLOCAVEC (struct file_info, numfiles);
12140 dirs = XALLOCAVEC (struct dir_info, numfiles);
12142 fnad.files = files;
12143 fnad.used_files = 0;
12144 fnad.max_files = numfiles;
12145 htab_traverse (file_table, file_name_acquire, &fnad);
12146 gcc_assert (fnad.used_files == fnad.max_files);
12148 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12150 /* Find all the different directories used. */
12151 dirs[0].path = files[0].path;
12152 dirs[0].length = files[0].fname - files[0].path;
12153 dirs[0].prefix = -1;
12155 dirs[0].dir_idx = 0;
12156 files[0].dir_idx = 0;
12159 for (i = 1; i < numfiles; i++)
12160 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12161 && memcmp (dirs[ndirs - 1].path, files[i].path,
12162 dirs[ndirs - 1].length) == 0)
12164 /* Same directory as last entry. */
12165 files[i].dir_idx = ndirs - 1;
12166 ++dirs[ndirs - 1].count;
12172 /* This is a new directory. */
12173 dirs[ndirs].path = files[i].path;
12174 dirs[ndirs].length = files[i].fname - files[i].path;
12175 dirs[ndirs].count = 1;
12176 dirs[ndirs].dir_idx = ndirs;
12177 files[i].dir_idx = ndirs;
12179 /* Search for a prefix. */
12180 dirs[ndirs].prefix = -1;
12181 for (j = 0; j < ndirs; j++)
12182 if (dirs[j].length < dirs[ndirs].length
12183 && dirs[j].length > 1
12184 && (dirs[ndirs].prefix == -1
12185 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12186 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12187 dirs[ndirs].prefix = j;
12192 /* Now to the actual work. We have to find a subset of the directories which
12193 allow expressing the file name using references to the directory table
12194 with the least amount of characters. We do not do an exhaustive search
12195 where we would have to check out every combination of every single
12196 possible prefix. Instead we use a heuristic which provides nearly optimal
12197 results in most cases and never is much off. */
12198 saved = XALLOCAVEC (int, ndirs);
12199 savehere = XALLOCAVEC (int, ndirs);
12201 memset (saved, '\0', ndirs * sizeof (saved[0]));
12202 for (i = 0; i < ndirs; i++)
12207 /* We can always save some space for the current directory. But this
12208 does not mean it will be enough to justify adding the directory. */
12209 savehere[i] = dirs[i].length;
12210 total = (savehere[i] - saved[i]) * dirs[i].count;
12212 for (j = i + 1; j < ndirs; j++)
12215 if (saved[j] < dirs[i].length)
12217 /* Determine whether the dirs[i] path is a prefix of the
12221 k = dirs[j].prefix;
12222 while (k != -1 && k != (int) i)
12223 k = dirs[k].prefix;
12227 /* Yes it is. We can possibly save some memory by
12228 writing the filenames in dirs[j] relative to
12230 savehere[j] = dirs[i].length;
12231 total += (savehere[j] - saved[j]) * dirs[j].count;
12236 /* Check whether we can save enough to justify adding the dirs[i]
12238 if (total > dirs[i].length + 1)
12240 /* It's worthwhile adding. */
12241 for (j = i; j < ndirs; j++)
12242 if (savehere[j] > 0)
12244 /* Remember how much we saved for this directory so far. */
12245 saved[j] = savehere[j];
12247 /* Remember the prefix directory. */
12248 dirs[j].dir_idx = i;
12253 /* Emit the directory name table. */
12254 idx_offset = dirs[0].length > 0 ? 1 : 0;
12255 for (i = 1 - idx_offset; i < ndirs; i++)
12256 dw2_asm_output_nstring (dirs[i].path,
12258 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12259 "Directory Entry: %#x", i + idx_offset);
12261 dw2_asm_output_data (1, 0, "End directory table");
12263 /* We have to emit them in the order of emitted_number since that's
12264 used in the debug info generation. To do this efficiently we
12265 generate a back-mapping of the indices first. */
12266 backmap = XALLOCAVEC (int, numfiles);
12267 for (i = 0; i < numfiles; i++)
12268 backmap[files[i].file_idx->emitted_number - 1] = i;
12270 /* Now write all the file names. */
12271 for (i = 0; i < numfiles; i++)
12273 int file_idx = backmap[i];
12274 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12276 #ifdef VMS_DEBUGGING_INFO
12277 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12279 /* Setting these fields can lead to debugger miscomparisons,
12280 but VMS Debug requires them to be set correctly. */
12285 int maxfilelen = strlen (files[file_idx].path)
12286 + dirs[dir_idx].length
12287 + MAX_VMS_VERSION_LEN + 1;
12288 char *filebuf = XALLOCAVEC (char, maxfilelen);
12290 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12291 snprintf (filebuf, maxfilelen, "%s;%d",
12292 files[file_idx].path + dirs[dir_idx].length, ver);
12294 dw2_asm_output_nstring
12295 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12297 /* Include directory index. */
12298 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12300 /* Modification time. */
12301 dw2_asm_output_data_uleb128
12302 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12306 /* File length in bytes. */
12307 dw2_asm_output_data_uleb128
12308 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12312 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12313 "File Entry: %#x", (unsigned) i + 1);
12315 /* Include directory index. */
12316 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12318 /* Modification time. */
12319 dw2_asm_output_data_uleb128 (0, NULL);
12321 /* File length in bytes. */
12322 dw2_asm_output_data_uleb128 (0, NULL);
12323 #endif /* VMS_DEBUGGING_INFO */
12326 dw2_asm_output_data (1, 0, "End file name table");
12330 /* Output the source line number correspondence information. This
12331 information goes into the .debug_line section. */
12334 output_line_info (void)
12336 char l1[20], l2[20], p1[20], p2[20];
12337 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12338 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12340 unsigned n_op_args;
12341 unsigned long lt_index;
12342 unsigned long current_line;
12345 unsigned long current_file;
12346 unsigned long function;
12347 int ver = dwarf_version;
12349 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12350 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12351 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12352 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12354 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12355 dw2_asm_output_data (4, 0xffffffff,
12356 "Initial length escape value indicating 64-bit DWARF extension");
12357 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12358 "Length of Source Line Info");
12359 ASM_OUTPUT_LABEL (asm_out_file, l1);
12361 dw2_asm_output_data (2, ver, "DWARF Version");
12362 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12363 ASM_OUTPUT_LABEL (asm_out_file, p1);
12365 /* Define the architecture-dependent minimum instruction length (in
12366 bytes). In this implementation of DWARF, this field is used for
12367 information purposes only. Since GCC generates assembly language,
12368 we have no a priori knowledge of how many instruction bytes are
12369 generated for each source line, and therefore can use only the
12370 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12371 commands. Accordingly, we fix this as `1', which is "correct
12372 enough" for all architectures, and don't let the target override. */
12373 dw2_asm_output_data (1, 1,
12374 "Minimum Instruction Length");
12377 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12378 "Maximum Operations Per Instruction");
12379 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12380 "Default is_stmt_start flag");
12381 dw2_asm_output_data (1, DWARF_LINE_BASE,
12382 "Line Base Value (Special Opcodes)");
12383 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12384 "Line Range Value (Special Opcodes)");
12385 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12386 "Special Opcode Base");
12388 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12392 case DW_LNS_advance_pc:
12393 case DW_LNS_advance_line:
12394 case DW_LNS_set_file:
12395 case DW_LNS_set_column:
12396 case DW_LNS_fixed_advance_pc:
12404 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12408 /* Write out the information about the files we use. */
12409 output_file_names ();
12410 ASM_OUTPUT_LABEL (asm_out_file, p2);
12412 /* We used to set the address register to the first location in the text
12413 section here, but that didn't accomplish anything since we already
12414 have a line note for the opening brace of the first function. */
12416 /* Generate the line number to PC correspondence table, encoded as
12417 a series of state machine operations. */
12421 if (cfun && in_cold_section_p)
12422 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12424 strcpy (prev_line_label, text_section_label);
12425 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12427 dw_line_info_ref line_info = &line_info_table[lt_index];
12430 /* Disable this optimization for now; GDB wants to see two line notes
12431 at the beginning of a function so it can find the end of the
12434 /* Don't emit anything for redundant notes. Just updating the
12435 address doesn't accomplish anything, because we already assume
12436 that anything after the last address is this line. */
12437 if (line_info->dw_line_num == current_line
12438 && line_info->dw_file_num == current_file)
12442 /* Emit debug info for the address of the current line.
12444 Unfortunately, we have little choice here currently, and must always
12445 use the most general form. GCC does not know the address delta
12446 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12447 attributes which will give an upper bound on the address range. We
12448 could perhaps use length attributes to determine when it is safe to
12449 use DW_LNS_fixed_advance_pc. */
12451 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12454 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12455 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12456 "DW_LNS_fixed_advance_pc");
12457 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12461 /* This can handle any delta. This takes
12462 4+DWARF2_ADDR_SIZE bytes. */
12463 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12464 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12465 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12466 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12469 strcpy (prev_line_label, line_label);
12471 /* Emit debug info for the source file of the current line, if
12472 different from the previous line. */
12473 if (line_info->dw_file_num != current_file)
12475 current_file = line_info->dw_file_num;
12476 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12477 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12480 /* Emit debug info for the current line number, choosing the encoding
12481 that uses the least amount of space. */
12482 if (line_info->dw_line_num != current_line)
12484 line_offset = line_info->dw_line_num - current_line;
12485 line_delta = line_offset - DWARF_LINE_BASE;
12486 current_line = line_info->dw_line_num;
12487 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12488 /* This can handle deltas from -10 to 234, using the current
12489 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12491 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12492 "line %lu", current_line);
12495 /* This can handle any delta. This takes at least 4 bytes,
12496 depending on the value being encoded. */
12497 dw2_asm_output_data (1, DW_LNS_advance_line,
12498 "advance to line %lu", current_line);
12499 dw2_asm_output_data_sleb128 (line_offset, NULL);
12500 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12504 /* We still need to start a new row, so output a copy insn. */
12505 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12508 /* Emit debug info for the address of the end of the function. */
12511 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12512 "DW_LNS_fixed_advance_pc");
12513 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12517 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12518 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12519 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12520 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12523 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12524 dw2_asm_output_data_uleb128 (1, NULL);
12525 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12530 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12532 dw_separate_line_info_ref line_info
12533 = &separate_line_info_table[lt_index];
12536 /* Don't emit anything for redundant notes. */
12537 if (line_info->dw_line_num == current_line
12538 && line_info->dw_file_num == current_file
12539 && line_info->function == function)
12543 /* Emit debug info for the address of the current line. If this is
12544 a new function, or the first line of a function, then we need
12545 to handle it differently. */
12546 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12548 if (function != line_info->function)
12550 function = line_info->function;
12552 /* Set the address register to the first line in the function. */
12553 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12554 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12555 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12556 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12560 /* ??? See the DW_LNS_advance_pc comment above. */
12563 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12564 "DW_LNS_fixed_advance_pc");
12565 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12569 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12570 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12571 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12572 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12576 strcpy (prev_line_label, line_label);
12578 /* Emit debug info for the source file of the current line, if
12579 different from the previous line. */
12580 if (line_info->dw_file_num != current_file)
12582 current_file = line_info->dw_file_num;
12583 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12584 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12587 /* Emit debug info for the current line number, choosing the encoding
12588 that uses the least amount of space. */
12589 if (line_info->dw_line_num != current_line)
12591 line_offset = line_info->dw_line_num - current_line;
12592 line_delta = line_offset - DWARF_LINE_BASE;
12593 current_line = line_info->dw_line_num;
12594 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12595 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12596 "line %lu", current_line);
12599 dw2_asm_output_data (1, DW_LNS_advance_line,
12600 "advance to line %lu", current_line);
12601 dw2_asm_output_data_sleb128 (line_offset, NULL);
12602 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12606 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12614 /* If we're done with a function, end its sequence. */
12615 if (lt_index == separate_line_info_table_in_use
12616 || separate_line_info_table[lt_index].function != function)
12621 /* Emit debug info for the address of the end of the function. */
12622 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12625 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12626 "DW_LNS_fixed_advance_pc");
12627 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12631 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12632 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12633 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12634 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12637 /* Output the marker for the end of this sequence. */
12638 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12639 dw2_asm_output_data_uleb128 (1, NULL);
12640 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12644 /* Output the marker for the end of the line number info. */
12645 ASM_OUTPUT_LABEL (asm_out_file, l2);
12648 /* Return the size of the .debug_dcall table for the compilation unit. */
12650 static unsigned long
12651 size_of_dcall_table (void)
12653 unsigned long size;
12656 tree last_poc_decl = NULL;
12658 /* Header: version + debug info section pointer + pointer size. */
12659 size = 2 + DWARF_OFFSET_SIZE + 1;
12661 /* Each entry: code label + DIE offset. */
12662 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12664 gcc_assert (p->targ_die != NULL);
12665 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12666 if (p->poc_decl != last_poc_decl)
12668 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12669 gcc_assert (poc_die);
12670 last_poc_decl = p->poc_decl;
12672 size += (DWARF_OFFSET_SIZE
12673 + size_of_uleb128 (poc_die->die_offset));
12675 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->targ_die->die_offset);
12681 /* Output the direct call table used to disambiguate PC values when
12682 identical function have been merged. */
12685 output_dcall_table (void)
12688 unsigned long dcall_length = size_of_dcall_table ();
12690 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12691 tree last_poc_decl = NULL;
12693 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12694 dw2_asm_output_data (4, 0xffffffff,
12695 "Initial length escape value indicating 64-bit DWARF extension");
12696 dw2_asm_output_data (DWARF_OFFSET_SIZE, dcall_length,
12697 "Length of Direct Call Table");
12698 dw2_asm_output_data (2, 4, "Version number");
12699 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12700 debug_info_section,
12701 "Offset of Compilation Unit Info");
12702 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12704 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12706 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12707 if (p->poc_decl != last_poc_decl)
12709 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12710 last_poc_decl = p->poc_decl;
12713 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "New caller");
12714 dw2_asm_output_data_uleb128 (poc_die->die_offset,
12715 "Caller DIE offset");
12718 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12719 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12720 dw2_asm_output_data_uleb128 (p->targ_die->die_offset,
12721 "Callee DIE offset");
12725 /* Return the size of the .debug_vcall table for the compilation unit. */
12727 static unsigned long
12728 size_of_vcall_table (void)
12730 unsigned long size;
12734 /* Header: version + pointer size. */
12737 /* Each entry: code label + vtable slot index. */
12738 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12739 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->vtable_slot);
12744 /* Output the virtual call table used to disambiguate PC values when
12745 identical function have been merged. */
12748 output_vcall_table (void)
12751 unsigned long vcall_length = size_of_vcall_table ();
12753 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12755 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12756 dw2_asm_output_data (4, 0xffffffff,
12757 "Initial length escape value indicating 64-bit DWARF extension");
12758 dw2_asm_output_data (DWARF_OFFSET_SIZE, vcall_length,
12759 "Length of Virtual Call Table");
12760 dw2_asm_output_data (2, 4, "Version number");
12761 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12763 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12765 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12766 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12767 dw2_asm_output_data_uleb128 (p->vtable_slot, "Vtable slot");
12771 /* Given a pointer to a tree node for some base type, return a pointer to
12772 a DIE that describes the given type.
12774 This routine must only be called for GCC type nodes that correspond to
12775 Dwarf base (fundamental) types. */
12778 base_type_die (tree type)
12780 dw_die_ref base_type_result;
12781 enum dwarf_type encoding;
12783 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12786 /* If this is a subtype that should not be emitted as a subrange type,
12787 use the base type. See subrange_type_for_debug_p. */
12788 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12789 type = TREE_TYPE (type);
12791 switch (TREE_CODE (type))
12794 if ((dwarf_version >= 4 || !dwarf_strict)
12795 && TYPE_NAME (type)
12796 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12797 && DECL_IS_BUILTIN (TYPE_NAME (type))
12798 && DECL_NAME (TYPE_NAME (type)))
12800 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12801 if (strcmp (name, "char16_t") == 0
12802 || strcmp (name, "char32_t") == 0)
12804 encoding = DW_ATE_UTF;
12808 if (TYPE_STRING_FLAG (type))
12810 if (TYPE_UNSIGNED (type))
12811 encoding = DW_ATE_unsigned_char;
12813 encoding = DW_ATE_signed_char;
12815 else if (TYPE_UNSIGNED (type))
12816 encoding = DW_ATE_unsigned;
12818 encoding = DW_ATE_signed;
12822 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12824 if (dwarf_version >= 3 || !dwarf_strict)
12825 encoding = DW_ATE_decimal_float;
12827 encoding = DW_ATE_lo_user;
12830 encoding = DW_ATE_float;
12833 case FIXED_POINT_TYPE:
12834 if (!(dwarf_version >= 3 || !dwarf_strict))
12835 encoding = DW_ATE_lo_user;
12836 else if (TYPE_UNSIGNED (type))
12837 encoding = DW_ATE_unsigned_fixed;
12839 encoding = DW_ATE_signed_fixed;
12842 /* Dwarf2 doesn't know anything about complex ints, so use
12843 a user defined type for it. */
12845 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12846 encoding = DW_ATE_complex_float;
12848 encoding = DW_ATE_lo_user;
12852 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12853 encoding = DW_ATE_boolean;
12857 /* No other TREE_CODEs are Dwarf fundamental types. */
12858 gcc_unreachable ();
12861 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12863 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12864 int_size_in_bytes (type));
12865 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12867 return base_type_result;
12870 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12871 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12874 is_base_type (tree type)
12876 switch (TREE_CODE (type))
12882 case FIXED_POINT_TYPE:
12890 case QUAL_UNION_TYPE:
12891 case ENUMERAL_TYPE:
12892 case FUNCTION_TYPE:
12895 case REFERENCE_TYPE:
12903 gcc_unreachable ();
12909 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12910 node, return the size in bits for the type if it is a constant, or else
12911 return the alignment for the type if the type's size is not constant, or
12912 else return BITS_PER_WORD if the type actually turns out to be an
12913 ERROR_MARK node. */
12915 static inline unsigned HOST_WIDE_INT
12916 simple_type_size_in_bits (const_tree type)
12918 if (TREE_CODE (type) == ERROR_MARK)
12919 return BITS_PER_WORD;
12920 else if (TYPE_SIZE (type) == NULL_TREE)
12922 else if (host_integerp (TYPE_SIZE (type), 1))
12923 return tree_low_cst (TYPE_SIZE (type), 1);
12925 return TYPE_ALIGN (type);
12928 /* Similarly, but return a double_int instead of UHWI. */
12930 static inline double_int
12931 double_int_type_size_in_bits (const_tree type)
12933 if (TREE_CODE (type) == ERROR_MARK)
12934 return uhwi_to_double_int (BITS_PER_WORD);
12935 else if (TYPE_SIZE (type) == NULL_TREE)
12936 return double_int_zero;
12937 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12938 return tree_to_double_int (TYPE_SIZE (type));
12940 return uhwi_to_double_int (TYPE_ALIGN (type));
12943 /* Given a pointer to a tree node for a subrange type, return a pointer
12944 to a DIE that describes the given type. */
12947 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12949 dw_die_ref subrange_die;
12950 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12952 if (context_die == NULL)
12953 context_die = comp_unit_die ();
12955 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12957 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12959 /* The size of the subrange type and its base type do not match,
12960 so we need to generate a size attribute for the subrange type. */
12961 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12965 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12967 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12969 return subrange_die;
12972 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12973 entry that chains various modifiers in front of the given type. */
12976 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12977 dw_die_ref context_die)
12979 enum tree_code code = TREE_CODE (type);
12980 dw_die_ref mod_type_die;
12981 dw_die_ref sub_die = NULL;
12982 tree item_type = NULL;
12983 tree qualified_type;
12984 tree name, low, high;
12986 if (code == ERROR_MARK)
12989 /* See if we already have the appropriately qualified variant of
12992 = get_qualified_type (type,
12993 ((is_const_type ? TYPE_QUAL_CONST : 0)
12994 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12996 if (qualified_type == sizetype
12997 && TYPE_NAME (qualified_type)
12998 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
13000 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
13002 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
13003 && TYPE_PRECISION (t)
13004 == TYPE_PRECISION (qualified_type)
13005 && TYPE_UNSIGNED (t)
13006 == TYPE_UNSIGNED (qualified_type));
13007 qualified_type = t;
13010 /* If we do, then we can just use its DIE, if it exists. */
13011 if (qualified_type)
13013 mod_type_die = lookup_type_die (qualified_type);
13015 return mod_type_die;
13018 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
13020 /* Handle C typedef types. */
13021 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
13022 && !DECL_ARTIFICIAL (name))
13024 tree dtype = TREE_TYPE (name);
13026 if (qualified_type == dtype)
13028 /* For a named type, use the typedef. */
13029 gen_type_die (qualified_type, context_die);
13030 return lookup_type_die (qualified_type);
13032 else if (is_const_type < TYPE_READONLY (dtype)
13033 || is_volatile_type < TYPE_VOLATILE (dtype)
13034 || (is_const_type <= TYPE_READONLY (dtype)
13035 && is_volatile_type <= TYPE_VOLATILE (dtype)
13036 && DECL_ORIGINAL_TYPE (name) != type))
13037 /* cv-unqualified version of named type. Just use the unnamed
13038 type to which it refers. */
13039 return modified_type_die (DECL_ORIGINAL_TYPE (name),
13040 is_const_type, is_volatile_type,
13042 /* Else cv-qualified version of named type; fall through. */
13046 /* If both is_const_type and is_volatile_type, prefer the path
13047 which leads to a qualified type. */
13048 && (!is_volatile_type
13049 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
13050 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
13052 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
13053 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
13055 else if (is_volatile_type)
13057 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
13058 sub_die = modified_type_die (type, is_const_type, 0, context_die);
13060 else if (code == POINTER_TYPE)
13062 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
13063 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13064 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13065 item_type = TREE_TYPE (type);
13066 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13067 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13068 TYPE_ADDR_SPACE (item_type));
13070 else if (code == REFERENCE_TYPE)
13072 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
13073 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
13076 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
13077 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13078 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13079 item_type = TREE_TYPE (type);
13080 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13081 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13082 TYPE_ADDR_SPACE (item_type));
13084 else if (code == INTEGER_TYPE
13085 && TREE_TYPE (type) != NULL_TREE
13086 && subrange_type_for_debug_p (type, &low, &high))
13088 mod_type_die = subrange_type_die (type, low, high, context_die);
13089 item_type = TREE_TYPE (type);
13091 else if (is_base_type (type))
13092 mod_type_die = base_type_die (type);
13095 gen_type_die (type, context_die);
13097 /* We have to get the type_main_variant here (and pass that to the
13098 `lookup_type_die' routine) because the ..._TYPE node we have
13099 might simply be a *copy* of some original type node (where the
13100 copy was created to help us keep track of typedef names) and
13101 that copy might have a different TYPE_UID from the original
13103 if (TREE_CODE (type) != VECTOR_TYPE)
13104 return lookup_type_die (type_main_variant (type));
13106 /* Vectors have the debugging information in the type,
13107 not the main variant. */
13108 return lookup_type_die (type);
13111 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
13112 don't output a DW_TAG_typedef, since there isn't one in the
13113 user's program; just attach a DW_AT_name to the type.
13114 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
13115 if the base type already has the same name. */
13117 && ((TREE_CODE (name) != TYPE_DECL
13118 && (qualified_type == TYPE_MAIN_VARIANT (type)
13119 || (!is_const_type && !is_volatile_type)))
13120 || (TREE_CODE (name) == TYPE_DECL
13121 && TREE_TYPE (name) == qualified_type
13122 && DECL_NAME (name))))
13124 if (TREE_CODE (name) == TYPE_DECL)
13125 /* Could just call add_name_and_src_coords_attributes here,
13126 but since this is a builtin type it doesn't have any
13127 useful source coordinates anyway. */
13128 name = DECL_NAME (name);
13129 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
13131 /* This probably indicates a bug. */
13132 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
13133 add_name_attribute (mod_type_die, "__unknown__");
13135 if (qualified_type)
13136 equate_type_number_to_die (qualified_type, mod_type_die);
13139 /* We must do this after the equate_type_number_to_die call, in case
13140 this is a recursive type. This ensures that the modified_type_die
13141 recursion will terminate even if the type is recursive. Recursive
13142 types are possible in Ada. */
13143 sub_die = modified_type_die (item_type,
13144 TYPE_READONLY (item_type),
13145 TYPE_VOLATILE (item_type),
13148 if (sub_die != NULL)
13149 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
13151 return mod_type_die;
13154 /* Generate DIEs for the generic parameters of T.
13155 T must be either a generic type or a generic function.
13156 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13159 gen_generic_params_dies (tree t)
13163 dw_die_ref die = NULL;
13165 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13169 die = lookup_type_die (t);
13170 else if (DECL_P (t))
13171 die = lookup_decl_die (t);
13175 parms = lang_hooks.get_innermost_generic_parms (t);
13177 /* T has no generic parameter. It means T is neither a generic type
13178 or function. End of story. */
13181 parms_num = TREE_VEC_LENGTH (parms);
13182 args = lang_hooks.get_innermost_generic_args (t);
13183 for (i = 0; i < parms_num; i++)
13185 tree parm, arg, arg_pack_elems;
13187 parm = TREE_VEC_ELT (parms, i);
13188 arg = TREE_VEC_ELT (args, i);
13189 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13190 gcc_assert (parm && TREE_VALUE (parm) && arg);
13192 if (parm && TREE_VALUE (parm) && arg)
13194 /* If PARM represents a template parameter pack,
13195 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13196 by DW_TAG_template_*_parameter DIEs for the argument
13197 pack elements of ARG. Note that ARG would then be
13198 an argument pack. */
13199 if (arg_pack_elems)
13200 template_parameter_pack_die (TREE_VALUE (parm),
13204 generic_parameter_die (TREE_VALUE (parm), arg,
13205 true /* Emit DW_AT_name */, die);
13210 /* Create and return a DIE for PARM which should be
13211 the representation of a generic type parameter.
13212 For instance, in the C++ front end, PARM would be a template parameter.
13213 ARG is the argument to PARM.
13214 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13216 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13217 as a child node. */
13220 generic_parameter_die (tree parm, tree arg,
13222 dw_die_ref parent_die)
13224 dw_die_ref tmpl_die = NULL;
13225 const char *name = NULL;
13227 if (!parm || !DECL_NAME (parm) || !arg)
13230 /* We support non-type generic parameters and arguments,
13231 type generic parameters and arguments, as well as
13232 generic generic parameters (a.k.a. template template parameters in C++)
13234 if (TREE_CODE (parm) == PARM_DECL)
13235 /* PARM is a nontype generic parameter */
13236 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13237 else if (TREE_CODE (parm) == TYPE_DECL)
13238 /* PARM is a type generic parameter. */
13239 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13240 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13241 /* PARM is a generic generic parameter.
13242 Its DIE is a GNU extension. It shall have a
13243 DW_AT_name attribute to represent the name of the template template
13244 parameter, and a DW_AT_GNU_template_name attribute to represent the
13245 name of the template template argument. */
13246 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13249 gcc_unreachable ();
13255 /* If PARM is a generic parameter pack, it means we are
13256 emitting debug info for a template argument pack element.
13257 In other terms, ARG is a template argument pack element.
13258 In that case, we don't emit any DW_AT_name attribute for
13262 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13264 add_AT_string (tmpl_die, DW_AT_name, name);
13267 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13269 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13270 TMPL_DIE should have a child DW_AT_type attribute that is set
13271 to the type of the argument to PARM, which is ARG.
13272 If PARM is a type generic parameter, TMPL_DIE should have a
13273 child DW_AT_type that is set to ARG. */
13274 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13275 add_type_attribute (tmpl_die, tmpl_type, 0,
13276 TREE_THIS_VOLATILE (tmpl_type),
13281 /* So TMPL_DIE is a DIE representing a
13282 a generic generic template parameter, a.k.a template template
13283 parameter in C++ and arg is a template. */
13285 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13286 to the name of the argument. */
13287 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13289 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13292 if (TREE_CODE (parm) == PARM_DECL)
13293 /* So PARM is a non-type generic parameter.
13294 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13295 attribute of TMPL_DIE which value represents the value
13297 We must be careful here:
13298 The value of ARG might reference some function decls.
13299 We might currently be emitting debug info for a generic
13300 type and types are emitted before function decls, we don't
13301 know if the function decls referenced by ARG will actually be
13302 emitted after cgraph computations.
13303 So must defer the generation of the DW_AT_const_value to
13304 after cgraph is ready. */
13305 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13311 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13312 PARM_PACK must be a template parameter pack. The returned DIE
13313 will be child DIE of PARENT_DIE. */
13316 template_parameter_pack_die (tree parm_pack,
13317 tree parm_pack_args,
13318 dw_die_ref parent_die)
13323 gcc_assert (parent_die && parm_pack);
13325 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13326 add_name_and_src_coords_attributes (die, parm_pack);
13327 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13328 generic_parameter_die (parm_pack,
13329 TREE_VEC_ELT (parm_pack_args, j),
13330 false /* Don't emit DW_AT_name */,
13335 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13336 an enumerated type. */
13339 type_is_enum (const_tree type)
13341 return TREE_CODE (type) == ENUMERAL_TYPE;
13344 /* Return the DBX register number described by a given RTL node. */
13346 static unsigned int
13347 dbx_reg_number (const_rtx rtl)
13349 unsigned regno = REGNO (rtl);
13351 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13353 #ifdef LEAF_REG_REMAP
13354 if (current_function_uses_only_leaf_regs)
13356 int leaf_reg = LEAF_REG_REMAP (regno);
13357 if (leaf_reg != -1)
13358 regno = (unsigned) leaf_reg;
13362 return DBX_REGISTER_NUMBER (regno);
13365 /* Optionally add a DW_OP_piece term to a location description expression.
13366 DW_OP_piece is only added if the location description expression already
13367 doesn't end with DW_OP_piece. */
13370 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13372 dw_loc_descr_ref loc;
13374 if (*list_head != NULL)
13376 /* Find the end of the chain. */
13377 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13380 if (loc->dw_loc_opc != DW_OP_piece)
13381 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13385 /* Return a location descriptor that designates a machine register or
13386 zero if there is none. */
13388 static dw_loc_descr_ref
13389 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13393 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13396 /* We only use "frame base" when we're sure we're talking about the
13397 post-prologue local stack frame. We do this by *not* running
13398 register elimination until this point, and recognizing the special
13399 argument pointer and soft frame pointer rtx's.
13400 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13401 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13402 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13404 dw_loc_descr_ref result = NULL;
13406 if (dwarf_version >= 4 || !dwarf_strict)
13408 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13410 add_loc_descr (&result,
13411 new_loc_descr (DW_OP_stack_value, 0, 0));
13416 regs = targetm.dwarf_register_span (rtl);
13418 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13419 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13421 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13424 /* Return a location descriptor that designates a machine register for
13425 a given hard register number. */
13427 static dw_loc_descr_ref
13428 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13430 dw_loc_descr_ref reg_loc_descr;
13434 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13436 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13438 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13439 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13441 return reg_loc_descr;
13444 /* Given an RTL of a register, return a location descriptor that
13445 designates a value that spans more than one register. */
13447 static dw_loc_descr_ref
13448 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13449 enum var_init_status initialized)
13451 int nregs, size, i;
13453 dw_loc_descr_ref loc_result = NULL;
13456 #ifdef LEAF_REG_REMAP
13457 if (current_function_uses_only_leaf_regs)
13459 int leaf_reg = LEAF_REG_REMAP (reg);
13460 if (leaf_reg != -1)
13461 reg = (unsigned) leaf_reg;
13464 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13465 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13467 /* Simple, contiguous registers. */
13468 if (regs == NULL_RTX)
13470 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13475 dw_loc_descr_ref t;
13477 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13478 VAR_INIT_STATUS_INITIALIZED);
13479 add_loc_descr (&loc_result, t);
13480 add_loc_descr_op_piece (&loc_result, size);
13486 /* Now onto stupid register sets in non contiguous locations. */
13488 gcc_assert (GET_CODE (regs) == PARALLEL);
13490 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13493 for (i = 0; i < XVECLEN (regs, 0); ++i)
13495 dw_loc_descr_ref t;
13497 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13498 VAR_INIT_STATUS_INITIALIZED);
13499 add_loc_descr (&loc_result, t);
13500 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13501 add_loc_descr_op_piece (&loc_result, size);
13504 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13505 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13509 /* Return a location descriptor that designates a constant. */
13511 static dw_loc_descr_ref
13512 int_loc_descriptor (HOST_WIDE_INT i)
13514 enum dwarf_location_atom op;
13516 /* Pick the smallest representation of a constant, rather than just
13517 defaulting to the LEB encoding. */
13521 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13522 else if (i <= 0xff)
13523 op = DW_OP_const1u;
13524 else if (i <= 0xffff)
13525 op = DW_OP_const2u;
13526 else if (HOST_BITS_PER_WIDE_INT == 32
13527 || i <= 0xffffffff)
13528 op = DW_OP_const4u;
13535 op = DW_OP_const1s;
13536 else if (i >= -0x8000)
13537 op = DW_OP_const2s;
13538 else if (HOST_BITS_PER_WIDE_INT == 32
13539 || i >= -0x80000000)
13540 op = DW_OP_const4s;
13545 return new_loc_descr (op, i, 0);
13548 /* Return loc description representing "address" of integer value.
13549 This can appear only as toplevel expression. */
13551 static dw_loc_descr_ref
13552 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13555 dw_loc_descr_ref loc_result = NULL;
13557 if (!(dwarf_version >= 4 || !dwarf_strict))
13564 else if (i <= 0xff)
13566 else if (i <= 0xffff)
13568 else if (HOST_BITS_PER_WIDE_INT == 32
13569 || i <= 0xffffffff)
13572 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13578 else if (i >= -0x8000)
13580 else if (HOST_BITS_PER_WIDE_INT == 32
13581 || i >= -0x80000000)
13584 litsize = 1 + size_of_sleb128 (i);
13586 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13587 is more compact. For DW_OP_stack_value we need:
13588 litsize + 1 (DW_OP_stack_value)
13589 and for DW_OP_implicit_value:
13590 1 (DW_OP_implicit_value) + 1 (length) + size. */
13591 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13593 loc_result = int_loc_descriptor (i);
13594 add_loc_descr (&loc_result,
13595 new_loc_descr (DW_OP_stack_value, 0, 0));
13599 loc_result = new_loc_descr (DW_OP_implicit_value,
13601 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13602 loc_result->dw_loc_oprnd2.v.val_int = i;
13606 /* Return a location descriptor that designates a base+offset location. */
13608 static dw_loc_descr_ref
13609 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13610 enum var_init_status initialized)
13612 unsigned int regno;
13613 dw_loc_descr_ref result;
13614 dw_fde_ref fde = current_fde ();
13616 /* We only use "frame base" when we're sure we're talking about the
13617 post-prologue local stack frame. We do this by *not* running
13618 register elimination until this point, and recognizing the special
13619 argument pointer and soft frame pointer rtx's. */
13620 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13622 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13626 if (GET_CODE (elim) == PLUS)
13628 offset += INTVAL (XEXP (elim, 1));
13629 elim = XEXP (elim, 0);
13631 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13632 && (elim == hard_frame_pointer_rtx
13633 || elim == stack_pointer_rtx))
13634 || elim == (frame_pointer_needed
13635 ? hard_frame_pointer_rtx
13636 : stack_pointer_rtx));
13638 /* If drap register is used to align stack, use frame
13639 pointer + offset to access stack variables. If stack
13640 is aligned without drap, use stack pointer + offset to
13641 access stack variables. */
13642 if (crtl->stack_realign_tried
13643 && reg == frame_pointer_rtx)
13646 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13647 ? HARD_FRAME_POINTER_REGNUM
13649 return new_reg_loc_descr (base_reg, offset);
13652 gcc_assert (frame_pointer_fb_offset_valid);
13653 offset += frame_pointer_fb_offset;
13654 return new_loc_descr (DW_OP_fbreg, offset, 0);
13659 && (fde->drap_reg == REGNO (reg)
13660 || fde->vdrap_reg == REGNO (reg)))
13662 /* Use cfa+offset to represent the location of arguments passed
13663 on the stack when drap is used to align stack.
13664 Only do this when not optimizing, for optimized code var-tracking
13665 is supposed to track where the arguments live and the register
13666 used as vdrap or drap in some spot might be used for something
13667 else in other part of the routine. */
13668 return new_loc_descr (DW_OP_fbreg, offset, 0);
13671 regno = dbx_reg_number (reg);
13673 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13676 result = new_loc_descr (DW_OP_bregx, regno, offset);
13678 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13679 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13684 /* Return true if this RTL expression describes a base+offset calculation. */
13687 is_based_loc (const_rtx rtl)
13689 return (GET_CODE (rtl) == PLUS
13690 && ((REG_P (XEXP (rtl, 0))
13691 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13692 && CONST_INT_P (XEXP (rtl, 1)))));
13695 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13698 static dw_loc_descr_ref
13699 tls_mem_loc_descriptor (rtx mem)
13702 dw_loc_descr_ref loc_result;
13704 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13707 base = get_base_address (MEM_EXPR (mem));
13709 || TREE_CODE (base) != VAR_DECL
13710 || !DECL_THREAD_LOCAL_P (base))
13713 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13714 if (loc_result == NULL)
13717 if (INTVAL (MEM_OFFSET (mem)))
13718 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13723 /* Output debug info about reason why we failed to expand expression as dwarf
13727 expansion_failed (tree expr, rtx rtl, char const *reason)
13729 if (dump_file && (dump_flags & TDF_DETAILS))
13731 fprintf (dump_file, "Failed to expand as dwarf: ");
13733 print_generic_expr (dump_file, expr, dump_flags);
13736 fprintf (dump_file, "\n");
13737 print_rtl (dump_file, rtl);
13739 fprintf (dump_file, "\nReason: %s\n", reason);
13743 /* Helper function for const_ok_for_output, called either directly
13744 or via for_each_rtx. */
13747 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13751 if (GET_CODE (rtl) == UNSPEC)
13753 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13754 we can't express it in the debug info. */
13755 #ifdef ENABLE_CHECKING
13756 /* Don't complain about TLS UNSPECs, those are just too hard to
13758 if (XVECLEN (rtl, 0) != 1
13759 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13760 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13761 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13762 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13763 inform (current_function_decl
13764 ? DECL_SOURCE_LOCATION (current_function_decl)
13765 : UNKNOWN_LOCATION,
13766 "non-delegitimized UNSPEC %d found in variable location",
13769 expansion_failed (NULL_TREE, rtl,
13770 "UNSPEC hasn't been delegitimized.\n");
13774 if (GET_CODE (rtl) != SYMBOL_REF)
13777 if (CONSTANT_POOL_ADDRESS_P (rtl))
13780 get_pool_constant_mark (rtl, &marked);
13781 /* If all references to this pool constant were optimized away,
13782 it was not output and thus we can't represent it. */
13785 expansion_failed (NULL_TREE, rtl,
13786 "Constant was removed from constant pool.\n");
13791 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13794 /* Avoid references to external symbols in debug info, on several targets
13795 the linker might even refuse to link when linking a shared library,
13796 and in many other cases the relocations for .debug_info/.debug_loc are
13797 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13798 to be defined within the same shared library or executable are fine. */
13799 if (SYMBOL_REF_EXTERNAL_P (rtl))
13801 tree decl = SYMBOL_REF_DECL (rtl);
13803 if (decl == NULL || !targetm.binds_local_p (decl))
13805 expansion_failed (NULL_TREE, rtl,
13806 "Symbol not defined in current TU.\n");
13814 /* Return true if constant RTL can be emitted in DW_OP_addr or
13815 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13816 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13819 const_ok_for_output (rtx rtl)
13821 if (GET_CODE (rtl) == SYMBOL_REF)
13822 return const_ok_for_output_1 (&rtl, NULL) == 0;
13824 if (GET_CODE (rtl) == CONST)
13825 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13830 /* The following routine converts the RTL for a variable or parameter
13831 (resident in memory) into an equivalent Dwarf representation of a
13832 mechanism for getting the address of that same variable onto the top of a
13833 hypothetical "address evaluation" stack.
13835 When creating memory location descriptors, we are effectively transforming
13836 the RTL for a memory-resident object into its Dwarf postfix expression
13837 equivalent. This routine recursively descends an RTL tree, turning
13838 it into Dwarf postfix code as it goes.
13840 MODE is the mode of the memory reference, needed to handle some
13841 autoincrement addressing modes.
13843 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13844 location list for RTL.
13846 Return 0 if we can't represent the location. */
13848 static dw_loc_descr_ref
13849 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13850 enum var_init_status initialized)
13852 dw_loc_descr_ref mem_loc_result = NULL;
13853 enum dwarf_location_atom op;
13854 dw_loc_descr_ref op0, op1;
13856 /* Note that for a dynamically sized array, the location we will generate a
13857 description of here will be the lowest numbered location which is
13858 actually within the array. That's *not* necessarily the same as the
13859 zeroth element of the array. */
13861 rtl = targetm.delegitimize_address (rtl);
13863 switch (GET_CODE (rtl))
13868 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13871 /* The case of a subreg may arise when we have a local (register)
13872 variable or a formal (register) parameter which doesn't quite fill
13873 up an entire register. For now, just assume that it is
13874 legitimate to make the Dwarf info refer to the whole register which
13875 contains the given subreg. */
13876 if (!subreg_lowpart_p (rtl))
13878 rtl = SUBREG_REG (rtl);
13879 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13881 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13883 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13887 /* Whenever a register number forms a part of the description of the
13888 method for calculating the (dynamic) address of a memory resident
13889 object, DWARF rules require the register number be referred to as
13890 a "base register". This distinction is not based in any way upon
13891 what category of register the hardware believes the given register
13892 belongs to. This is strictly DWARF terminology we're dealing with
13893 here. Note that in cases where the location of a memory-resident
13894 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13895 OP_CONST (0)) the actual DWARF location descriptor that we generate
13896 may just be OP_BASEREG (basereg). This may look deceptively like
13897 the object in question was allocated to a register (rather than in
13898 memory) so DWARF consumers need to be aware of the subtle
13899 distinction between OP_REG and OP_BASEREG. */
13900 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13901 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13902 else if (stack_realign_drap
13904 && crtl->args.internal_arg_pointer == rtl
13905 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13907 /* If RTL is internal_arg_pointer, which has been optimized
13908 out, use DRAP instead. */
13909 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13910 VAR_INIT_STATUS_INITIALIZED);
13916 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13917 VAR_INIT_STATUS_INITIALIZED);
13922 int shift = DWARF2_ADDR_SIZE
13923 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13924 shift *= BITS_PER_UNIT;
13925 if (GET_CODE (rtl) == SIGN_EXTEND)
13929 mem_loc_result = op0;
13930 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13931 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13932 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13933 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13938 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13939 VAR_INIT_STATUS_INITIALIZED);
13940 if (mem_loc_result == NULL)
13941 mem_loc_result = tls_mem_loc_descriptor (rtl);
13942 if (mem_loc_result != 0)
13944 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13946 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13949 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13950 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13952 add_loc_descr (&mem_loc_result,
13953 new_loc_descr (DW_OP_deref_size,
13954 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13958 rtx new_rtl = avoid_constant_pool_reference (rtl);
13959 if (new_rtl != rtl)
13960 return mem_loc_descriptor (new_rtl, mode, initialized);
13965 rtl = XEXP (rtl, 1);
13967 /* ... fall through ... */
13970 /* Some ports can transform a symbol ref into a label ref, because
13971 the symbol ref is too far away and has to be dumped into a constant
13975 if (GET_CODE (rtl) == SYMBOL_REF
13976 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13978 dw_loc_descr_ref temp;
13980 /* If this is not defined, we have no way to emit the data. */
13981 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13984 /* We used to emit DW_OP_addr here, but that's wrong, since
13985 DW_OP_addr should be relocated by the debug info consumer,
13986 while DW_OP_GNU_push_tls_address operand should not. */
13987 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13988 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13989 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13990 temp->dw_loc_oprnd1.v.val_addr = rtl;
13991 temp->dtprel = true;
13993 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13994 add_loc_descr (&mem_loc_result, temp);
13999 if (!const_ok_for_output (rtl))
14003 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14004 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14005 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14006 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14012 case DEBUG_IMPLICIT_PTR:
14013 expansion_failed (NULL_TREE, rtl,
14014 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14018 /* Extract the PLUS expression nested inside and fall into
14019 PLUS code below. */
14020 rtl = XEXP (rtl, 1);
14025 /* Turn these into a PLUS expression and fall into the PLUS code
14027 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
14028 GEN_INT (GET_CODE (rtl) == PRE_INC
14029 ? GET_MODE_UNIT_SIZE (mode)
14030 : -GET_MODE_UNIT_SIZE (mode)));
14032 /* ... fall through ... */
14036 if (is_based_loc (rtl))
14037 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
14038 INTVAL (XEXP (rtl, 1)),
14039 VAR_INIT_STATUS_INITIALIZED);
14042 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
14043 VAR_INIT_STATUS_INITIALIZED);
14044 if (mem_loc_result == 0)
14047 if (CONST_INT_P (XEXP (rtl, 1)))
14048 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
14051 dw_loc_descr_ref mem_loc_result2
14052 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14053 VAR_INIT_STATUS_INITIALIZED);
14054 if (mem_loc_result2 == 0)
14056 add_loc_descr (&mem_loc_result, mem_loc_result2);
14057 add_loc_descr (&mem_loc_result,
14058 new_loc_descr (DW_OP_plus, 0, 0));
14063 /* If a pseudo-reg is optimized away, it is possible for it to
14064 be replaced with a MEM containing a multiply or shift. */
14106 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14107 VAR_INIT_STATUS_INITIALIZED);
14108 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14109 VAR_INIT_STATUS_INITIALIZED);
14111 if (op0 == 0 || op1 == 0)
14114 mem_loc_result = op0;
14115 add_loc_descr (&mem_loc_result, op1);
14116 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14120 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14121 VAR_INIT_STATUS_INITIALIZED);
14122 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14123 VAR_INIT_STATUS_INITIALIZED);
14125 if (op0 == 0 || op1 == 0)
14128 mem_loc_result = op0;
14129 add_loc_descr (&mem_loc_result, op1);
14130 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14131 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14132 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
14133 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14134 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
14150 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14151 VAR_INIT_STATUS_INITIALIZED);
14156 mem_loc_result = op0;
14157 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14161 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
14189 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14190 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14194 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14196 if (op_mode == VOIDmode)
14197 op_mode = GET_MODE (XEXP (rtl, 1));
14198 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14201 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14202 VAR_INIT_STATUS_INITIALIZED);
14203 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14204 VAR_INIT_STATUS_INITIALIZED);
14206 if (op0 == 0 || op1 == 0)
14209 if (op_mode != VOIDmode
14210 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14212 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
14213 shift *= BITS_PER_UNIT;
14214 /* For eq/ne, if the operands are known to be zero-extended,
14215 there is no need to do the fancy shifting up. */
14216 if (op == DW_OP_eq || op == DW_OP_ne)
14218 dw_loc_descr_ref last0, last1;
14220 last0->dw_loc_next != NULL;
14221 last0 = last0->dw_loc_next)
14224 last1->dw_loc_next != NULL;
14225 last1 = last1->dw_loc_next)
14227 /* deref_size zero extends, and for constants we can check
14228 whether they are zero extended or not. */
14229 if (((last0->dw_loc_opc == DW_OP_deref_size
14230 && last0->dw_loc_oprnd1.v.val_int
14231 <= GET_MODE_SIZE (op_mode))
14232 || (CONST_INT_P (XEXP (rtl, 0))
14233 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14234 == (INTVAL (XEXP (rtl, 0))
14235 & GET_MODE_MASK (op_mode))))
14236 && ((last1->dw_loc_opc == DW_OP_deref_size
14237 && last1->dw_loc_oprnd1.v.val_int
14238 <= GET_MODE_SIZE (op_mode))
14239 || (CONST_INT_P (XEXP (rtl, 1))
14240 && (unsigned HOST_WIDE_INT)
14241 INTVAL (XEXP (rtl, 1))
14242 == (INTVAL (XEXP (rtl, 1))
14243 & GET_MODE_MASK (op_mode)))))
14246 add_loc_descr (&op0, int_loc_descriptor (shift));
14247 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14248 if (CONST_INT_P (XEXP (rtl, 1)))
14249 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14252 add_loc_descr (&op1, int_loc_descriptor (shift));
14253 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14259 mem_loc_result = op0;
14260 add_loc_descr (&mem_loc_result, op1);
14261 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14262 if (STORE_FLAG_VALUE != 1)
14264 add_loc_descr (&mem_loc_result,
14265 int_loc_descriptor (STORE_FLAG_VALUE));
14266 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14287 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14288 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14292 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14294 if (op_mode == VOIDmode)
14295 op_mode = GET_MODE (XEXP (rtl, 1));
14296 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14299 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14300 VAR_INIT_STATUS_INITIALIZED);
14301 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14302 VAR_INIT_STATUS_INITIALIZED);
14304 if (op0 == 0 || op1 == 0)
14307 if (op_mode != VOIDmode
14308 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14310 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14311 dw_loc_descr_ref last0, last1;
14313 last0->dw_loc_next != NULL;
14314 last0 = last0->dw_loc_next)
14317 last1->dw_loc_next != NULL;
14318 last1 = last1->dw_loc_next)
14320 if (CONST_INT_P (XEXP (rtl, 0)))
14321 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14322 /* deref_size zero extends, so no need to mask it again. */
14323 else if (last0->dw_loc_opc != DW_OP_deref_size
14324 || last0->dw_loc_oprnd1.v.val_int
14325 > GET_MODE_SIZE (op_mode))
14327 add_loc_descr (&op0, int_loc_descriptor (mask));
14328 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14330 if (CONST_INT_P (XEXP (rtl, 1)))
14331 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14332 /* deref_size zero extends, so no need to mask it again. */
14333 else if (last1->dw_loc_opc != DW_OP_deref_size
14334 || last1->dw_loc_oprnd1.v.val_int
14335 > GET_MODE_SIZE (op_mode))
14337 add_loc_descr (&op1, int_loc_descriptor (mask));
14338 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14343 HOST_WIDE_INT bias = 1;
14344 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14345 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14346 if (CONST_INT_P (XEXP (rtl, 1)))
14347 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14348 + INTVAL (XEXP (rtl, 1)));
14350 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14360 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14361 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14362 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14365 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14366 VAR_INIT_STATUS_INITIALIZED);
14367 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14368 VAR_INIT_STATUS_INITIALIZED);
14370 if (op0 == 0 || op1 == 0)
14373 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14374 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14375 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14376 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14378 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14380 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14381 add_loc_descr (&op0, int_loc_descriptor (mask));
14382 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14383 add_loc_descr (&op1, int_loc_descriptor (mask));
14384 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14388 HOST_WIDE_INT bias = 1;
14389 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14390 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14391 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14394 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14396 int shift = DWARF2_ADDR_SIZE
14397 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14398 shift *= BITS_PER_UNIT;
14399 add_loc_descr (&op0, int_loc_descriptor (shift));
14400 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14401 add_loc_descr (&op1, int_loc_descriptor (shift));
14402 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14405 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14409 mem_loc_result = op0;
14410 add_loc_descr (&mem_loc_result, op1);
14411 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14413 dw_loc_descr_ref bra_node, drop_node;
14415 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14416 add_loc_descr (&mem_loc_result, bra_node);
14417 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14418 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14419 add_loc_descr (&mem_loc_result, drop_node);
14420 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14421 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14427 if (CONST_INT_P (XEXP (rtl, 1))
14428 && CONST_INT_P (XEXP (rtl, 2))
14429 && ((unsigned) INTVAL (XEXP (rtl, 1))
14430 + (unsigned) INTVAL (XEXP (rtl, 2))
14431 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14432 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14433 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14436 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14437 VAR_INIT_STATUS_INITIALIZED);
14440 if (GET_CODE (rtl) == SIGN_EXTRACT)
14444 mem_loc_result = op0;
14445 size = INTVAL (XEXP (rtl, 1));
14446 shift = INTVAL (XEXP (rtl, 2));
14447 if (BITS_BIG_ENDIAN)
14448 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14450 if (shift + size != (int) DWARF2_ADDR_SIZE)
14452 add_loc_descr (&mem_loc_result,
14453 int_loc_descriptor (DWARF2_ADDR_SIZE
14455 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14457 if (size != (int) DWARF2_ADDR_SIZE)
14459 add_loc_descr (&mem_loc_result,
14460 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14461 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14468 dw_loc_descr_ref op2, bra_node, drop_node;
14469 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14470 VAR_INIT_STATUS_INITIALIZED);
14471 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14472 VAR_INIT_STATUS_INITIALIZED);
14473 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
14474 VAR_INIT_STATUS_INITIALIZED);
14475 if (op0 == NULL || op1 == NULL || op2 == NULL)
14478 mem_loc_result = op1;
14479 add_loc_descr (&mem_loc_result, op2);
14480 add_loc_descr (&mem_loc_result, op0);
14481 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14482 add_loc_descr (&mem_loc_result, bra_node);
14483 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14484 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14485 add_loc_descr (&mem_loc_result, drop_node);
14486 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14487 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14495 /* In theory, we could implement the above. */
14496 /* DWARF cannot represent the unsigned compare operations
14523 case FLOAT_TRUNCATE:
14525 case UNSIGNED_FLOAT:
14528 case FRACT_CONVERT:
14529 case UNSIGNED_FRACT_CONVERT:
14531 case UNSIGNED_SAT_FRACT:
14543 case VEC_DUPLICATE:
14546 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14547 can't express it in the debug info. This can happen e.g. with some
14552 resolve_one_addr (&rtl, NULL);
14556 #ifdef ENABLE_CHECKING
14557 print_rtl (stderr, rtl);
14558 gcc_unreachable ();
14564 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14565 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14567 return mem_loc_result;
14570 /* Return a descriptor that describes the concatenation of two locations.
14571 This is typically a complex variable. */
14573 static dw_loc_descr_ref
14574 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14576 dw_loc_descr_ref cc_loc_result = NULL;
14577 dw_loc_descr_ref x0_ref
14578 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14579 dw_loc_descr_ref x1_ref
14580 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14582 if (x0_ref == 0 || x1_ref == 0)
14585 cc_loc_result = x0_ref;
14586 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14588 add_loc_descr (&cc_loc_result, x1_ref);
14589 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14591 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14592 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14594 return cc_loc_result;
14597 /* Return a descriptor that describes the concatenation of N
14600 static dw_loc_descr_ref
14601 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14604 dw_loc_descr_ref cc_loc_result = NULL;
14605 unsigned int n = XVECLEN (concatn, 0);
14607 for (i = 0; i < n; ++i)
14609 dw_loc_descr_ref ref;
14610 rtx x = XVECEXP (concatn, 0, i);
14612 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14616 add_loc_descr (&cc_loc_result, ref);
14617 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14620 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14621 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14623 return cc_loc_result;
14626 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14627 for DEBUG_IMPLICIT_PTR RTL. */
14629 static dw_loc_descr_ref
14630 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14632 dw_loc_descr_ref ret;
14637 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14638 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14639 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14640 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14641 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14642 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14645 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14646 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14647 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14651 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14652 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14657 /* Output a proper Dwarf location descriptor for a variable or parameter
14658 which is either allocated in a register or in a memory location. For a
14659 register, we just generate an OP_REG and the register number. For a
14660 memory location we provide a Dwarf postfix expression describing how to
14661 generate the (dynamic) address of the object onto the address stack.
14663 MODE is mode of the decl if this loc_descriptor is going to be used in
14664 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14665 allowed, VOIDmode otherwise.
14667 If we don't know how to describe it, return 0. */
14669 static dw_loc_descr_ref
14670 loc_descriptor (rtx rtl, enum machine_mode mode,
14671 enum var_init_status initialized)
14673 dw_loc_descr_ref loc_result = NULL;
14675 switch (GET_CODE (rtl))
14678 /* The case of a subreg may arise when we have a local (register)
14679 variable or a formal (register) parameter which doesn't quite fill
14680 up an entire register. For now, just assume that it is
14681 legitimate to make the Dwarf info refer to the whole register which
14682 contains the given subreg. */
14683 loc_result = loc_descriptor (SUBREG_REG (rtl),
14684 GET_MODE (SUBREG_REG (rtl)), initialized);
14688 loc_result = reg_loc_descriptor (rtl, initialized);
14692 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14694 if (loc_result == NULL)
14695 loc_result = tls_mem_loc_descriptor (rtl);
14696 if (loc_result == NULL)
14698 rtx new_rtl = avoid_constant_pool_reference (rtl);
14699 if (new_rtl != rtl)
14700 loc_result = loc_descriptor (new_rtl, mode, initialized);
14705 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14710 loc_result = concatn_loc_descriptor (rtl, initialized);
14715 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14717 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14718 if (GET_CODE (loc) == EXPR_LIST)
14719 loc = XEXP (loc, 0);
14720 loc_result = loc_descriptor (loc, mode, initialized);
14724 rtl = XEXP (rtl, 1);
14729 rtvec par_elems = XVEC (rtl, 0);
14730 int num_elem = GET_NUM_ELEM (par_elems);
14731 enum machine_mode mode;
14734 /* Create the first one, so we have something to add to. */
14735 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14736 VOIDmode, initialized);
14737 if (loc_result == NULL)
14739 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14740 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14741 for (i = 1; i < num_elem; i++)
14743 dw_loc_descr_ref temp;
14745 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14746 VOIDmode, initialized);
14749 add_loc_descr (&loc_result, temp);
14750 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14751 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14757 if (mode != VOIDmode && mode != BLKmode)
14758 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14763 if (mode == VOIDmode)
14764 mode = GET_MODE (rtl);
14766 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14768 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14770 /* Note that a CONST_DOUBLE rtx could represent either an integer
14771 or a floating-point constant. A CONST_DOUBLE is used whenever
14772 the constant requires more than one word in order to be
14773 adequately represented. We output CONST_DOUBLEs as blocks. */
14774 loc_result = new_loc_descr (DW_OP_implicit_value,
14775 GET_MODE_SIZE (mode), 0);
14776 if (SCALAR_FLOAT_MODE_P (mode))
14778 unsigned int length = GET_MODE_SIZE (mode);
14779 unsigned char *array
14780 = (unsigned char*) ggc_alloc_atomic (length);
14782 insert_float (rtl, array);
14783 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14784 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14785 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14786 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14790 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14791 loc_result->dw_loc_oprnd2.v.val_double
14792 = rtx_to_double_int (rtl);
14798 if (mode == VOIDmode)
14799 mode = GET_MODE (rtl);
14801 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14803 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14804 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14805 unsigned char *array = (unsigned char *)
14806 ggc_alloc_atomic (length * elt_size);
14810 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14811 switch (GET_MODE_CLASS (mode))
14813 case MODE_VECTOR_INT:
14814 for (i = 0, p = array; i < length; i++, p += elt_size)
14816 rtx elt = CONST_VECTOR_ELT (rtl, i);
14817 double_int val = rtx_to_double_int (elt);
14819 if (elt_size <= sizeof (HOST_WIDE_INT))
14820 insert_int (double_int_to_shwi (val), elt_size, p);
14823 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14824 insert_double (val, p);
14829 case MODE_VECTOR_FLOAT:
14830 for (i = 0, p = array; i < length; i++, p += elt_size)
14832 rtx elt = CONST_VECTOR_ELT (rtl, i);
14833 insert_float (elt, p);
14838 gcc_unreachable ();
14841 loc_result = new_loc_descr (DW_OP_implicit_value,
14842 length * elt_size, 0);
14843 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14844 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14845 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14846 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14851 if (mode == VOIDmode
14852 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14853 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14854 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14856 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14861 if (!const_ok_for_output (rtl))
14864 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14865 && (dwarf_version >= 4 || !dwarf_strict))
14867 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14868 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14869 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14870 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14871 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14875 case DEBUG_IMPLICIT_PTR:
14876 loc_result = implicit_ptr_descriptor (rtl, 0);
14880 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14881 && CONST_INT_P (XEXP (rtl, 1)))
14884 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14889 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14890 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14891 && (dwarf_version >= 4 || !dwarf_strict))
14893 /* Value expression. */
14894 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14896 add_loc_descr (&loc_result,
14897 new_loc_descr (DW_OP_stack_value, 0, 0));
14905 /* We need to figure out what section we should use as the base for the
14906 address ranges where a given location is valid.
14907 1. If this particular DECL has a section associated with it, use that.
14908 2. If this function has a section associated with it, use that.
14909 3. Otherwise, use the text section.
14910 XXX: If you split a variable across multiple sections, we won't notice. */
14912 static const char *
14913 secname_for_decl (const_tree decl)
14915 const char *secname;
14917 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14919 tree sectree = DECL_SECTION_NAME (decl);
14920 secname = TREE_STRING_POINTER (sectree);
14922 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14924 tree sectree = DECL_SECTION_NAME (current_function_decl);
14925 secname = TREE_STRING_POINTER (sectree);
14927 else if (cfun && in_cold_section_p)
14928 secname = crtl->subsections.cold_section_label;
14930 secname = text_section_label;
14935 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14938 decl_by_reference_p (tree decl)
14940 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14941 || TREE_CODE (decl) == VAR_DECL)
14942 && DECL_BY_REFERENCE (decl));
14945 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14948 static dw_loc_descr_ref
14949 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14950 enum var_init_status initialized)
14952 int have_address = 0;
14953 dw_loc_descr_ref descr;
14954 enum machine_mode mode;
14956 if (want_address != 2)
14958 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14960 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14962 varloc = PAT_VAR_LOCATION_LOC (varloc);
14963 if (GET_CODE (varloc) == EXPR_LIST)
14964 varloc = XEXP (varloc, 0);
14965 mode = GET_MODE (varloc);
14966 if (MEM_P (varloc))
14968 rtx addr = XEXP (varloc, 0);
14969 descr = mem_loc_descriptor (addr, mode, initialized);
14974 rtx x = avoid_constant_pool_reference (varloc);
14976 descr = mem_loc_descriptor (x, mode, initialized);
14980 descr = mem_loc_descriptor (varloc, mode, initialized);
14987 if (GET_CODE (varloc) == VAR_LOCATION)
14988 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14990 mode = DECL_MODE (loc);
14991 descr = loc_descriptor (varloc, mode, initialized);
14998 if (want_address == 2 && !have_address
14999 && (dwarf_version >= 4 || !dwarf_strict))
15001 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15003 expansion_failed (loc, NULL_RTX,
15004 "DWARF address size mismatch");
15007 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
15010 /* Show if we can't fill the request for an address. */
15011 if (want_address && !have_address)
15013 expansion_failed (loc, NULL_RTX,
15014 "Want address and only have value");
15018 /* If we've got an address and don't want one, dereference. */
15019 if (!want_address && have_address)
15021 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15022 enum dwarf_location_atom op;
15024 if (size > DWARF2_ADDR_SIZE || size == -1)
15026 expansion_failed (loc, NULL_RTX,
15027 "DWARF address size mismatch");
15030 else if (size == DWARF2_ADDR_SIZE)
15033 op = DW_OP_deref_size;
15035 add_loc_descr (&descr, new_loc_descr (op, size, 0));
15041 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
15042 if it is not possible. */
15044 static dw_loc_descr_ref
15045 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
15047 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
15048 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
15049 else if (dwarf_version >= 3 || !dwarf_strict)
15050 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
15055 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15056 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
15058 static dw_loc_descr_ref
15059 dw_sra_loc_expr (tree decl, rtx loc)
15062 unsigned int padsize = 0;
15063 dw_loc_descr_ref descr, *descr_tail;
15064 unsigned HOST_WIDE_INT decl_size;
15066 enum var_init_status initialized;
15068 if (DECL_SIZE (decl) == NULL
15069 || !host_integerp (DECL_SIZE (decl), 1))
15072 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
15074 descr_tail = &descr;
15076 for (p = loc; p; p = XEXP (p, 1))
15078 unsigned int bitsize = decl_piece_bitsize (p);
15079 rtx loc_note = *decl_piece_varloc_ptr (p);
15080 dw_loc_descr_ref cur_descr;
15081 dw_loc_descr_ref *tail, last = NULL;
15082 unsigned int opsize = 0;
15084 if (loc_note == NULL_RTX
15085 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
15087 padsize += bitsize;
15090 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
15091 varloc = NOTE_VAR_LOCATION (loc_note);
15092 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
15093 if (cur_descr == NULL)
15095 padsize += bitsize;
15099 /* Check that cur_descr either doesn't use
15100 DW_OP_*piece operations, or their sum is equal
15101 to bitsize. Otherwise we can't embed it. */
15102 for (tail = &cur_descr; *tail != NULL;
15103 tail = &(*tail)->dw_loc_next)
15104 if ((*tail)->dw_loc_opc == DW_OP_piece)
15106 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
15110 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
15112 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
15116 if (last != NULL && opsize != bitsize)
15118 padsize += bitsize;
15122 /* If there is a hole, add DW_OP_*piece after empty DWARF
15123 expression, which means that those bits are optimized out. */
15126 if (padsize > decl_size)
15128 decl_size -= padsize;
15129 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
15130 if (*descr_tail == NULL)
15132 descr_tail = &(*descr_tail)->dw_loc_next;
15135 *descr_tail = cur_descr;
15137 if (bitsize > decl_size)
15139 decl_size -= bitsize;
15142 HOST_WIDE_INT offset = 0;
15143 if (GET_CODE (varloc) == VAR_LOCATION
15144 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15146 varloc = PAT_VAR_LOCATION_LOC (varloc);
15147 if (GET_CODE (varloc) == EXPR_LIST)
15148 varloc = XEXP (varloc, 0);
15152 if (GET_CODE (varloc) == CONST
15153 || GET_CODE (varloc) == SIGN_EXTEND
15154 || GET_CODE (varloc) == ZERO_EXTEND)
15155 varloc = XEXP (varloc, 0);
15156 else if (GET_CODE (varloc) == SUBREG)
15157 varloc = SUBREG_REG (varloc);
15162 /* DW_OP_bit_size offset should be zero for register
15163 or implicit location descriptions and empty location
15164 descriptions, but for memory addresses needs big endian
15166 if (MEM_P (varloc))
15168 unsigned HOST_WIDE_INT memsize
15169 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
15170 if (memsize != bitsize)
15172 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
15173 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
15175 if (memsize < bitsize)
15177 if (BITS_BIG_ENDIAN)
15178 offset = memsize - bitsize;
15182 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
15183 if (*descr_tail == NULL)
15185 descr_tail = &(*descr_tail)->dw_loc_next;
15189 /* If there were any non-empty expressions, add padding till the end of
15191 if (descr != NULL && decl_size != 0)
15193 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
15194 if (*descr_tail == NULL)
15200 /* Return the dwarf representation of the location list LOC_LIST of
15201 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
15204 static dw_loc_list_ref
15205 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
15207 const char *endname, *secname;
15209 enum var_init_status initialized;
15210 struct var_loc_node *node;
15211 dw_loc_descr_ref descr;
15212 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15213 dw_loc_list_ref list = NULL;
15214 dw_loc_list_ref *listp = &list;
15216 /* Now that we know what section we are using for a base,
15217 actually construct the list of locations.
15218 The first location information is what is passed to the
15219 function that creates the location list, and the remaining
15220 locations just get added on to that list.
15221 Note that we only know the start address for a location
15222 (IE location changes), so to build the range, we use
15223 the range [current location start, next location start].
15224 This means we have to special case the last node, and generate
15225 a range of [last location start, end of function label]. */
15227 secname = secname_for_decl (decl);
15229 for (node = loc_list->first; node; node = node->next)
15230 if (GET_CODE (node->loc) == EXPR_LIST
15231 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
15233 if (GET_CODE (node->loc) == EXPR_LIST)
15235 /* This requires DW_OP_{,bit_}piece, which is not usable
15236 inside DWARF expressions. */
15237 if (want_address != 2)
15239 descr = dw_sra_loc_expr (decl, node->loc);
15245 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15246 varloc = NOTE_VAR_LOCATION (node->loc);
15247 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15251 bool range_across_switch = false;
15252 /* If section switch happens in between node->label
15253 and node->next->label (or end of function) and
15254 we can't emit it as a single entry list,
15255 emit two ranges, first one ending at the end
15256 of first partition and second one starting at the
15257 beginning of second partition. */
15258 if (node == loc_list->last_before_switch
15259 && (node != loc_list->first || loc_list->first->next)
15260 && current_function_decl)
15262 endname = current_fde ()->dw_fde_end;
15263 range_across_switch = true;
15265 /* The variable has a location between NODE->LABEL and
15266 NODE->NEXT->LABEL. */
15267 else if (node->next)
15268 endname = node->next->label;
15269 /* If the variable has a location at the last label
15270 it keeps its location until the end of function. */
15271 else if (!current_function_decl)
15272 endname = text_end_label;
15275 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15276 current_function_funcdef_no);
15277 endname = ggc_strdup (label_id);
15280 *listp = new_loc_list (descr, node->label, endname, secname);
15281 listp = &(*listp)->dw_loc_next;
15283 if (range_across_switch)
15285 if (GET_CODE (node->loc) == EXPR_LIST)
15286 descr = dw_sra_loc_expr (decl, node->loc);
15289 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15290 varloc = NOTE_VAR_LOCATION (node->loc);
15291 descr = dw_loc_list_1 (decl, varloc, want_address,
15294 gcc_assert (descr);
15295 /* The variable has a location between NODE->LABEL and
15296 NODE->NEXT->LABEL. */
15298 endname = node->next->label;
15300 endname = current_fde ()->dw_fde_second_end;
15301 *listp = new_loc_list (descr,
15302 current_fde ()->dw_fde_second_begin,
15304 listp = &(*listp)->dw_loc_next;
15309 /* Try to avoid the overhead of a location list emitting a location
15310 expression instead, but only if we didn't have more than one
15311 location entry in the first place. If some entries were not
15312 representable, we don't want to pretend a single entry that was
15313 applies to the entire scope in which the variable is
15315 if (list && loc_list->first->next)
15321 /* Return if the loc_list has only single element and thus can be represented
15322 as location description. */
15325 single_element_loc_list_p (dw_loc_list_ref list)
15327 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15328 return !list->ll_symbol;
15331 /* To each location in list LIST add loc descr REF. */
15334 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15336 dw_loc_descr_ref copy;
15337 add_loc_descr (&list->expr, ref);
15338 list = list->dw_loc_next;
15341 copy = ggc_alloc_dw_loc_descr_node ();
15342 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15343 add_loc_descr (&list->expr, copy);
15344 while (copy->dw_loc_next)
15346 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15347 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15348 copy->dw_loc_next = new_copy;
15351 list = list->dw_loc_next;
15355 /* Given two lists RET and LIST
15356 produce location list that is result of adding expression in LIST
15357 to expression in RET on each possition in program.
15358 Might be destructive on both RET and LIST.
15360 TODO: We handle only simple cases of RET or LIST having at most one
15361 element. General case would inolve sorting the lists in program order
15362 and merging them that will need some additional work.
15363 Adding that will improve quality of debug info especially for SRA-ed
15367 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15376 if (!list->dw_loc_next)
15378 add_loc_descr_to_each (*ret, list->expr);
15381 if (!(*ret)->dw_loc_next)
15383 add_loc_descr_to_each (list, (*ret)->expr);
15387 expansion_failed (NULL_TREE, NULL_RTX,
15388 "Don't know how to merge two non-trivial"
15389 " location lists.\n");
15394 /* LOC is constant expression. Try a luck, look it up in constant
15395 pool and return its loc_descr of its address. */
15397 static dw_loc_descr_ref
15398 cst_pool_loc_descr (tree loc)
15400 /* Get an RTL for this, if something has been emitted. */
15401 rtx rtl = lookup_constant_def (loc);
15402 enum machine_mode mode;
15404 if (!rtl || !MEM_P (rtl))
15409 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15411 /* TODO: We might get more coverage if we was actually delaying expansion
15412 of all expressions till end of compilation when constant pools are fully
15414 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15416 expansion_failed (loc, NULL_RTX,
15417 "CST value in contant pool but not marked.");
15420 mode = GET_MODE (rtl);
15421 rtl = XEXP (rtl, 0);
15422 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15425 /* Return dw_loc_list representing address of addr_expr LOC
15426 by looking for innder INDIRECT_REF expression and turing it
15427 into simple arithmetics. */
15429 static dw_loc_list_ref
15430 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15433 HOST_WIDE_INT bitsize, bitpos, bytepos;
15434 enum machine_mode mode;
15436 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15437 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15439 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15440 &bitsize, &bitpos, &offset, &mode,
15441 &unsignedp, &volatilep, false);
15443 if (bitpos % BITS_PER_UNIT)
15445 expansion_failed (loc, NULL_RTX, "bitfield access");
15448 if (!INDIRECT_REF_P (obj))
15450 expansion_failed (obj,
15451 NULL_RTX, "no indirect ref in inner refrence");
15454 if (!offset && !bitpos)
15455 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15457 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15458 && (dwarf_version >= 4 || !dwarf_strict))
15460 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15465 /* Variable offset. */
15466 list_ret1 = loc_list_from_tree (offset, 0);
15467 if (list_ret1 == 0)
15469 add_loc_list (&list_ret, list_ret1);
15472 add_loc_descr_to_each (list_ret,
15473 new_loc_descr (DW_OP_plus, 0, 0));
15475 bytepos = bitpos / BITS_PER_UNIT;
15477 add_loc_descr_to_each (list_ret,
15478 new_loc_descr (DW_OP_plus_uconst,
15480 else if (bytepos < 0)
15481 loc_list_plus_const (list_ret, bytepos);
15482 add_loc_descr_to_each (list_ret,
15483 new_loc_descr (DW_OP_stack_value, 0, 0));
15489 /* Generate Dwarf location list representing LOC.
15490 If WANT_ADDRESS is false, expression computing LOC will be computed
15491 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15492 if WANT_ADDRESS is 2, expression computing address useable in location
15493 will be returned (i.e. DW_OP_reg can be used
15494 to refer to register values). */
15496 static dw_loc_list_ref
15497 loc_list_from_tree (tree loc, int want_address)
15499 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15500 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15501 int have_address = 0;
15502 enum dwarf_location_atom op;
15504 /* ??? Most of the time we do not take proper care for sign/zero
15505 extending the values properly. Hopefully this won't be a real
15508 switch (TREE_CODE (loc))
15511 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15514 case PLACEHOLDER_EXPR:
15515 /* This case involves extracting fields from an object to determine the
15516 position of other fields. We don't try to encode this here. The
15517 only user of this is Ada, which encodes the needed information using
15518 the names of types. */
15519 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15523 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15524 /* There are no opcodes for these operations. */
15527 case PREINCREMENT_EXPR:
15528 case PREDECREMENT_EXPR:
15529 case POSTINCREMENT_EXPR:
15530 case POSTDECREMENT_EXPR:
15531 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15532 /* There are no opcodes for these operations. */
15536 /* If we already want an address, see if there is INDIRECT_REF inside
15537 e.g. for &this->field. */
15540 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15541 (loc, want_address == 2);
15544 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15545 && (ret = cst_pool_loc_descr (loc)))
15548 /* Otherwise, process the argument and look for the address. */
15549 if (!list_ret && !ret)
15550 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15554 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15560 if (DECL_THREAD_LOCAL_P (loc))
15563 enum dwarf_location_atom first_op;
15564 enum dwarf_location_atom second_op;
15565 bool dtprel = false;
15567 if (targetm.have_tls)
15569 /* If this is not defined, we have no way to emit the
15571 if (!targetm.asm_out.output_dwarf_dtprel)
15574 /* The way DW_OP_GNU_push_tls_address is specified, we
15575 can only look up addresses of objects in the current
15576 module. We used DW_OP_addr as first op, but that's
15577 wrong, because DW_OP_addr is relocated by the debug
15578 info consumer, while DW_OP_GNU_push_tls_address
15579 operand shouldn't be. */
15580 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15582 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15584 second_op = DW_OP_GNU_push_tls_address;
15588 if (!targetm.emutls.debug_form_tls_address
15589 || !(dwarf_version >= 3 || !dwarf_strict))
15591 /* We stuffed the control variable into the DECL_VALUE_EXPR
15592 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15593 no longer appear in gimple code. We used the control
15594 variable in specific so that we could pick it up here. */
15595 loc = DECL_VALUE_EXPR (loc);
15596 first_op = DW_OP_addr;
15597 second_op = DW_OP_form_tls_address;
15600 rtl = rtl_for_decl_location (loc);
15601 if (rtl == NULL_RTX)
15606 rtl = XEXP (rtl, 0);
15607 if (! CONSTANT_P (rtl))
15610 ret = new_loc_descr (first_op, 0, 0);
15611 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15612 ret->dw_loc_oprnd1.v.val_addr = rtl;
15613 ret->dtprel = dtprel;
15615 ret1 = new_loc_descr (second_op, 0, 0);
15616 add_loc_descr (&ret, ret1);
15625 if (DECL_HAS_VALUE_EXPR_P (loc))
15626 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15630 case FUNCTION_DECL:
15633 var_loc_list *loc_list = lookup_decl_loc (loc);
15635 if (loc_list && loc_list->first)
15637 list_ret = dw_loc_list (loc_list, loc, want_address);
15638 have_address = want_address != 0;
15641 rtl = rtl_for_decl_location (loc);
15642 if (rtl == NULL_RTX)
15644 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15647 else if (CONST_INT_P (rtl))
15649 HOST_WIDE_INT val = INTVAL (rtl);
15650 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15651 val &= GET_MODE_MASK (DECL_MODE (loc));
15652 ret = int_loc_descriptor (val);
15654 else if (GET_CODE (rtl) == CONST_STRING)
15656 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15659 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15661 ret = new_loc_descr (DW_OP_addr, 0, 0);
15662 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15663 ret->dw_loc_oprnd1.v.val_addr = rtl;
15667 enum machine_mode mode;
15669 /* Certain constructs can only be represented at top-level. */
15670 if (want_address == 2)
15672 ret = loc_descriptor (rtl, VOIDmode,
15673 VAR_INIT_STATUS_INITIALIZED);
15678 mode = GET_MODE (rtl);
15681 rtl = XEXP (rtl, 0);
15684 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15687 expansion_failed (loc, rtl,
15688 "failed to produce loc descriptor for rtl");
15695 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15699 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15703 case COMPOUND_EXPR:
15704 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15707 case VIEW_CONVERT_EXPR:
15710 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15712 case COMPONENT_REF:
15713 case BIT_FIELD_REF:
15715 case ARRAY_RANGE_REF:
15716 case REALPART_EXPR:
15717 case IMAGPART_EXPR:
15720 HOST_WIDE_INT bitsize, bitpos, bytepos;
15721 enum machine_mode mode;
15723 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15725 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15726 &unsignedp, &volatilep, false);
15728 gcc_assert (obj != loc);
15730 list_ret = loc_list_from_tree (obj,
15732 && !bitpos && !offset ? 2 : 1);
15733 /* TODO: We can extract value of the small expression via shifting even
15734 for nonzero bitpos. */
15737 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15739 expansion_failed (loc, NULL_RTX,
15740 "bitfield access");
15744 if (offset != NULL_TREE)
15746 /* Variable offset. */
15747 list_ret1 = loc_list_from_tree (offset, 0);
15748 if (list_ret1 == 0)
15750 add_loc_list (&list_ret, list_ret1);
15753 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15756 bytepos = bitpos / BITS_PER_UNIT;
15758 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15759 else if (bytepos < 0)
15760 loc_list_plus_const (list_ret, bytepos);
15767 if ((want_address || !host_integerp (loc, 0))
15768 && (ret = cst_pool_loc_descr (loc)))
15770 else if (want_address == 2
15771 && host_integerp (loc, 0)
15772 && (ret = address_of_int_loc_descriptor
15773 (int_size_in_bytes (TREE_TYPE (loc)),
15774 tree_low_cst (loc, 0))))
15776 else if (host_integerp (loc, 0))
15777 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15780 expansion_failed (loc, NULL_RTX,
15781 "Integer operand is not host integer");
15790 if ((ret = cst_pool_loc_descr (loc)))
15793 /* We can construct small constants here using int_loc_descriptor. */
15794 expansion_failed (loc, NULL_RTX,
15795 "constructor or constant not in constant pool");
15798 case TRUTH_AND_EXPR:
15799 case TRUTH_ANDIF_EXPR:
15804 case TRUTH_XOR_EXPR:
15809 case TRUTH_OR_EXPR:
15810 case TRUTH_ORIF_EXPR:
15815 case FLOOR_DIV_EXPR:
15816 case CEIL_DIV_EXPR:
15817 case ROUND_DIV_EXPR:
15818 case TRUNC_DIV_EXPR:
15819 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15828 case FLOOR_MOD_EXPR:
15829 case CEIL_MOD_EXPR:
15830 case ROUND_MOD_EXPR:
15831 case TRUNC_MOD_EXPR:
15832 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15837 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15838 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15839 if (list_ret == 0 || list_ret1 == 0)
15842 add_loc_list (&list_ret, list_ret1);
15845 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15846 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15847 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15848 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15849 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15861 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15864 case POINTER_PLUS_EXPR:
15866 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15868 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15872 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15880 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15887 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15894 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15901 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15916 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15917 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15918 if (list_ret == 0 || list_ret1 == 0)
15921 add_loc_list (&list_ret, list_ret1);
15924 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15927 case TRUTH_NOT_EXPR:
15941 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15945 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15951 const enum tree_code code =
15952 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15954 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15955 build2 (code, integer_type_node,
15956 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15957 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15960 /* ... fall through ... */
15964 dw_loc_descr_ref lhs
15965 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15966 dw_loc_list_ref rhs
15967 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15968 dw_loc_descr_ref bra_node, jump_node, tmp;
15970 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15971 if (list_ret == 0 || lhs == 0 || rhs == 0)
15974 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15975 add_loc_descr_to_each (list_ret, bra_node);
15977 add_loc_list (&list_ret, rhs);
15978 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15979 add_loc_descr_to_each (list_ret, jump_node);
15981 add_loc_descr_to_each (list_ret, lhs);
15982 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15983 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15985 /* ??? Need a node to point the skip at. Use a nop. */
15986 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15987 add_loc_descr_to_each (list_ret, tmp);
15988 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15989 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15993 case FIX_TRUNC_EXPR:
15997 /* Leave front-end specific codes as simply unknown. This comes
15998 up, for instance, with the C STMT_EXPR. */
15999 if ((unsigned int) TREE_CODE (loc)
16000 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
16002 expansion_failed (loc, NULL_RTX,
16003 "language specific tree node");
16007 #ifdef ENABLE_CHECKING
16008 /* Otherwise this is a generic code; we should just lists all of
16009 these explicitly. We forgot one. */
16010 gcc_unreachable ();
16012 /* In a release build, we want to degrade gracefully: better to
16013 generate incomplete debugging information than to crash. */
16018 if (!ret && !list_ret)
16021 if (want_address == 2 && !have_address
16022 && (dwarf_version >= 4 || !dwarf_strict))
16024 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
16026 expansion_failed (loc, NULL_RTX,
16027 "DWARF address size mismatch");
16031 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
16033 add_loc_descr_to_each (list_ret,
16034 new_loc_descr (DW_OP_stack_value, 0, 0));
16037 /* Show if we can't fill the request for an address. */
16038 if (want_address && !have_address)
16040 expansion_failed (loc, NULL_RTX,
16041 "Want address and only have value");
16045 gcc_assert (!ret || !list_ret);
16047 /* If we've got an address and don't want one, dereference. */
16048 if (!want_address && have_address)
16050 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
16052 if (size > DWARF2_ADDR_SIZE || size == -1)
16054 expansion_failed (loc, NULL_RTX,
16055 "DWARF address size mismatch");
16058 else if (size == DWARF2_ADDR_SIZE)
16061 op = DW_OP_deref_size;
16064 add_loc_descr (&ret, new_loc_descr (op, size, 0));
16066 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
16069 list_ret = new_loc_list (ret, NULL, NULL, NULL);
16074 /* Same as above but return only single location expression. */
16075 static dw_loc_descr_ref
16076 loc_descriptor_from_tree (tree loc, int want_address)
16078 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
16081 if (ret->dw_loc_next)
16083 expansion_failed (loc, NULL_RTX,
16084 "Location list where only loc descriptor needed");
16090 /* Given a value, round it up to the lowest multiple of `boundary'
16091 which is not less than the value itself. */
16093 static inline HOST_WIDE_INT
16094 ceiling (HOST_WIDE_INT value, unsigned int boundary)
16096 return (((value + boundary - 1) / boundary) * boundary);
16099 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
16100 pointer to the declared type for the relevant field variable, or return
16101 `integer_type_node' if the given node turns out to be an
16102 ERROR_MARK node. */
16105 field_type (const_tree decl)
16109 if (TREE_CODE (decl) == ERROR_MARK)
16110 return integer_type_node;
16112 type = DECL_BIT_FIELD_TYPE (decl);
16113 if (type == NULL_TREE)
16114 type = TREE_TYPE (decl);
16119 /* Given a pointer to a tree node, return the alignment in bits for
16120 it, or else return BITS_PER_WORD if the node actually turns out to
16121 be an ERROR_MARK node. */
16123 static inline unsigned
16124 simple_type_align_in_bits (const_tree type)
16126 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
16129 static inline unsigned
16130 simple_decl_align_in_bits (const_tree decl)
16132 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
16135 /* Return the result of rounding T up to ALIGN. */
16137 static inline double_int
16138 round_up_to_align (double_int t, unsigned int align)
16140 double_int alignd = uhwi_to_double_int (align);
16141 t = double_int_add (t, alignd);
16142 t = double_int_add (t, double_int_minus_one);
16143 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
16144 t = double_int_mul (t, alignd);
16148 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
16149 lowest addressed byte of the "containing object" for the given FIELD_DECL,
16150 or return 0 if we are unable to determine what that offset is, either
16151 because the argument turns out to be a pointer to an ERROR_MARK node, or
16152 because the offset is actually variable. (We can't handle the latter case
16155 static HOST_WIDE_INT
16156 field_byte_offset (const_tree decl)
16158 double_int object_offset_in_bits;
16159 double_int object_offset_in_bytes;
16160 double_int bitpos_int;
16162 if (TREE_CODE (decl) == ERROR_MARK)
16165 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
16167 /* We cannot yet cope with fields whose positions are variable, so
16168 for now, when we see such things, we simply return 0. Someday, we may
16169 be able to handle such cases, but it will be damn difficult. */
16170 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
16173 bitpos_int = tree_to_double_int (bit_position (decl));
16175 #ifdef PCC_BITFIELD_TYPE_MATTERS
16176 if (PCC_BITFIELD_TYPE_MATTERS)
16179 tree field_size_tree;
16180 double_int deepest_bitpos;
16181 double_int field_size_in_bits;
16182 unsigned int type_align_in_bits;
16183 unsigned int decl_align_in_bits;
16184 double_int type_size_in_bits;
16186 type = field_type (decl);
16187 type_size_in_bits = double_int_type_size_in_bits (type);
16188 type_align_in_bits = simple_type_align_in_bits (type);
16190 field_size_tree = DECL_SIZE (decl);
16192 /* The size could be unspecified if there was an error, or for
16193 a flexible array member. */
16194 if (!field_size_tree)
16195 field_size_tree = bitsize_zero_node;
16197 /* If the size of the field is not constant, use the type size. */
16198 if (TREE_CODE (field_size_tree) == INTEGER_CST)
16199 field_size_in_bits = tree_to_double_int (field_size_tree);
16201 field_size_in_bits = type_size_in_bits;
16203 decl_align_in_bits = simple_decl_align_in_bits (decl);
16205 /* The GCC front-end doesn't make any attempt to keep track of the
16206 starting bit offset (relative to the start of the containing
16207 structure type) of the hypothetical "containing object" for a
16208 bit-field. Thus, when computing the byte offset value for the
16209 start of the "containing object" of a bit-field, we must deduce
16210 this information on our own. This can be rather tricky to do in
16211 some cases. For example, handling the following structure type
16212 definition when compiling for an i386/i486 target (which only
16213 aligns long long's to 32-bit boundaries) can be very tricky:
16215 struct S { int field1; long long field2:31; };
16217 Fortunately, there is a simple rule-of-thumb which can be used
16218 in such cases. When compiling for an i386/i486, GCC will
16219 allocate 8 bytes for the structure shown above. It decides to
16220 do this based upon one simple rule for bit-field allocation.
16221 GCC allocates each "containing object" for each bit-field at
16222 the first (i.e. lowest addressed) legitimate alignment boundary
16223 (based upon the required minimum alignment for the declared
16224 type of the field) which it can possibly use, subject to the
16225 condition that there is still enough available space remaining
16226 in the containing object (when allocated at the selected point)
16227 to fully accommodate all of the bits of the bit-field itself.
16229 This simple rule makes it obvious why GCC allocates 8 bytes for
16230 each object of the structure type shown above. When looking
16231 for a place to allocate the "containing object" for `field2',
16232 the compiler simply tries to allocate a 64-bit "containing
16233 object" at each successive 32-bit boundary (starting at zero)
16234 until it finds a place to allocate that 64- bit field such that
16235 at least 31 contiguous (and previously unallocated) bits remain
16236 within that selected 64 bit field. (As it turns out, for the
16237 example above, the compiler finds it is OK to allocate the
16238 "containing object" 64-bit field at bit-offset zero within the
16241 Here we attempt to work backwards from the limited set of facts
16242 we're given, and we try to deduce from those facts, where GCC
16243 must have believed that the containing object started (within
16244 the structure type). The value we deduce is then used (by the
16245 callers of this routine) to generate DW_AT_location and
16246 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16247 the case of DW_AT_location, regular fields as well). */
16249 /* Figure out the bit-distance from the start of the structure to
16250 the "deepest" bit of the bit-field. */
16251 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16253 /* This is the tricky part. Use some fancy footwork to deduce
16254 where the lowest addressed bit of the containing object must
16256 object_offset_in_bits
16257 = double_int_sub (deepest_bitpos, type_size_in_bits);
16259 /* Round up to type_align by default. This works best for
16261 object_offset_in_bits
16262 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16264 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16266 object_offset_in_bits
16267 = double_int_sub (deepest_bitpos, type_size_in_bits);
16269 /* Round up to decl_align instead. */
16270 object_offset_in_bits
16271 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16275 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16276 object_offset_in_bits = bitpos_int;
16278 object_offset_in_bytes
16279 = double_int_div (object_offset_in_bits,
16280 uhwi_to_double_int (BITS_PER_UNIT), true,
16282 return double_int_to_shwi (object_offset_in_bytes);
16285 /* The following routines define various Dwarf attributes and any data
16286 associated with them. */
16288 /* Add a location description attribute value to a DIE.
16290 This emits location attributes suitable for whole variables and
16291 whole parameters. Note that the location attributes for struct fields are
16292 generated by the routine `data_member_location_attribute' below. */
16295 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16296 dw_loc_list_ref descr)
16300 if (single_element_loc_list_p (descr))
16301 add_AT_loc (die, attr_kind, descr->expr);
16303 add_AT_loc_list (die, attr_kind, descr);
16306 /* Add DW_AT_accessibility attribute to DIE if needed. */
16309 add_accessibility_attribute (dw_die_ref die, tree decl)
16311 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16312 children, otherwise the default is DW_ACCESS_public. In DWARF2
16313 the default has always been DW_ACCESS_public. */
16314 if (TREE_PROTECTED (decl))
16315 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16316 else if (TREE_PRIVATE (decl))
16318 if (dwarf_version == 2
16319 || die->die_parent == NULL
16320 || die->die_parent->die_tag != DW_TAG_class_type)
16321 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16323 else if (dwarf_version > 2
16325 && die->die_parent->die_tag == DW_TAG_class_type)
16326 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16329 /* Attach the specialized form of location attribute used for data members of
16330 struct and union types. In the special case of a FIELD_DECL node which
16331 represents a bit-field, the "offset" part of this special location
16332 descriptor must indicate the distance in bytes from the lowest-addressed
16333 byte of the containing struct or union type to the lowest-addressed byte of
16334 the "containing object" for the bit-field. (See the `field_byte_offset'
16337 For any given bit-field, the "containing object" is a hypothetical object
16338 (of some integral or enum type) within which the given bit-field lives. The
16339 type of this hypothetical "containing object" is always the same as the
16340 declared type of the individual bit-field itself (for GCC anyway... the
16341 DWARF spec doesn't actually mandate this). Note that it is the size (in
16342 bytes) of the hypothetical "containing object" which will be given in the
16343 DW_AT_byte_size attribute for this bit-field. (See the
16344 `byte_size_attribute' function below.) It is also used when calculating the
16345 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16346 function below.) */
16349 add_data_member_location_attribute (dw_die_ref die, tree decl)
16351 HOST_WIDE_INT offset;
16352 dw_loc_descr_ref loc_descr = 0;
16354 if (TREE_CODE (decl) == TREE_BINFO)
16356 /* We're working on the TAG_inheritance for a base class. */
16357 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16359 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16360 aren't at a fixed offset from all (sub)objects of the same
16361 type. We need to extract the appropriate offset from our
16362 vtable. The following dwarf expression means
16364 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16366 This is specific to the V3 ABI, of course. */
16368 dw_loc_descr_ref tmp;
16370 /* Make a copy of the object address. */
16371 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16372 add_loc_descr (&loc_descr, tmp);
16374 /* Extract the vtable address. */
16375 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16376 add_loc_descr (&loc_descr, tmp);
16378 /* Calculate the address of the offset. */
16379 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16380 gcc_assert (offset < 0);
16382 tmp = int_loc_descriptor (-offset);
16383 add_loc_descr (&loc_descr, tmp);
16384 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16385 add_loc_descr (&loc_descr, tmp);
16387 /* Extract the offset. */
16388 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16389 add_loc_descr (&loc_descr, tmp);
16391 /* Add it to the object address. */
16392 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16393 add_loc_descr (&loc_descr, tmp);
16396 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16399 offset = field_byte_offset (decl);
16403 if (dwarf_version > 2)
16405 /* Don't need to output a location expression, just the constant. */
16407 add_AT_int (die, DW_AT_data_member_location, offset);
16409 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16414 enum dwarf_location_atom op;
16416 /* The DWARF2 standard says that we should assume that the structure
16417 address is already on the stack, so we can specify a structure
16418 field address by using DW_OP_plus_uconst. */
16420 #ifdef MIPS_DEBUGGING_INFO
16421 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16422 operator correctly. It works only if we leave the offset on the
16426 op = DW_OP_plus_uconst;
16429 loc_descr = new_loc_descr (op, offset, 0);
16433 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16436 /* Writes integer values to dw_vec_const array. */
16439 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16443 *dest++ = val & 0xff;
16449 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16451 static HOST_WIDE_INT
16452 extract_int (const unsigned char *src, unsigned int size)
16454 HOST_WIDE_INT val = 0;
16460 val |= *--src & 0xff;
16466 /* Writes double_int values to dw_vec_const array. */
16469 insert_double (double_int val, unsigned char *dest)
16471 unsigned char *p0 = dest;
16472 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16474 if (WORDS_BIG_ENDIAN)
16480 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16481 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16484 /* Writes floating point values to dw_vec_const array. */
16487 insert_float (const_rtx rtl, unsigned char *array)
16489 REAL_VALUE_TYPE rv;
16493 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16494 real_to_target (val, &rv, GET_MODE (rtl));
16496 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16497 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16499 insert_int (val[i], 4, array);
16504 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16505 does not have a "location" either in memory or in a register. These
16506 things can arise in GNU C when a constant is passed as an actual parameter
16507 to an inlined function. They can also arise in C++ where declared
16508 constants do not necessarily get memory "homes". */
16511 add_const_value_attribute (dw_die_ref die, rtx rtl)
16513 switch (GET_CODE (rtl))
16517 HOST_WIDE_INT val = INTVAL (rtl);
16520 add_AT_int (die, DW_AT_const_value, val);
16522 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16527 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16528 floating-point constant. A CONST_DOUBLE is used whenever the
16529 constant requires more than one word in order to be adequately
16532 enum machine_mode mode = GET_MODE (rtl);
16534 if (SCALAR_FLOAT_MODE_P (mode))
16536 unsigned int length = GET_MODE_SIZE (mode);
16537 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16539 insert_float (rtl, array);
16540 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16543 add_AT_double (die, DW_AT_const_value,
16544 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16550 enum machine_mode mode = GET_MODE (rtl);
16551 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16552 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16553 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16554 (length * elt_size);
16558 switch (GET_MODE_CLASS (mode))
16560 case MODE_VECTOR_INT:
16561 for (i = 0, p = array; i < length; i++, p += elt_size)
16563 rtx elt = CONST_VECTOR_ELT (rtl, i);
16564 double_int val = rtx_to_double_int (elt);
16566 if (elt_size <= sizeof (HOST_WIDE_INT))
16567 insert_int (double_int_to_shwi (val), elt_size, p);
16570 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16571 insert_double (val, p);
16576 case MODE_VECTOR_FLOAT:
16577 for (i = 0, p = array; i < length; i++, p += elt_size)
16579 rtx elt = CONST_VECTOR_ELT (rtl, i);
16580 insert_float (elt, p);
16585 gcc_unreachable ();
16588 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16593 if (dwarf_version >= 4 || !dwarf_strict)
16595 dw_loc_descr_ref loc_result;
16596 resolve_one_addr (&rtl, NULL);
16598 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16599 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16600 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16601 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16602 add_AT_loc (die, DW_AT_location, loc_result);
16603 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16609 if (CONSTANT_P (XEXP (rtl, 0)))
16610 return add_const_value_attribute (die, XEXP (rtl, 0));
16613 if (!const_ok_for_output (rtl))
16616 if (dwarf_version >= 4 || !dwarf_strict)
16621 /* In cases where an inlined instance of an inline function is passed
16622 the address of an `auto' variable (which is local to the caller) we
16623 can get a situation where the DECL_RTL of the artificial local
16624 variable (for the inlining) which acts as a stand-in for the
16625 corresponding formal parameter (of the inline function) will look
16626 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16627 exactly a compile-time constant expression, but it isn't the address
16628 of the (artificial) local variable either. Rather, it represents the
16629 *value* which the artificial local variable always has during its
16630 lifetime. We currently have no way to represent such quasi-constant
16631 values in Dwarf, so for now we just punt and generate nothing. */
16639 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16640 && MEM_READONLY_P (rtl)
16641 && GET_MODE (rtl) == BLKmode)
16643 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16649 /* No other kinds of rtx should be possible here. */
16650 gcc_unreachable ();
16655 /* Determine whether the evaluation of EXPR references any variables
16656 or functions which aren't otherwise used (and therefore may not be
16659 reference_to_unused (tree * tp, int * walk_subtrees,
16660 void * data ATTRIBUTE_UNUSED)
16662 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16663 *walk_subtrees = 0;
16665 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16666 && ! TREE_ASM_WRITTEN (*tp))
16668 /* ??? The C++ FE emits debug information for using decls, so
16669 putting gcc_unreachable here falls over. See PR31899. For now
16670 be conservative. */
16671 else if (!cgraph_global_info_ready
16672 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16674 else if (TREE_CODE (*tp) == VAR_DECL)
16676 struct varpool_node *node = varpool_get_node (*tp);
16677 if (!node || !node->needed)
16680 else if (TREE_CODE (*tp) == FUNCTION_DECL
16681 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16683 /* The call graph machinery must have finished analyzing,
16684 optimizing and gimplifying the CU by now.
16685 So if *TP has no call graph node associated
16686 to it, it means *TP will not be emitted. */
16687 if (!cgraph_get_node (*tp))
16690 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16696 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16697 for use in a later add_const_value_attribute call. */
16700 rtl_for_decl_init (tree init, tree type)
16702 rtx rtl = NULL_RTX;
16706 /* If a variable is initialized with a string constant without embedded
16707 zeros, build CONST_STRING. */
16708 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16710 tree enttype = TREE_TYPE (type);
16711 tree domain = TYPE_DOMAIN (type);
16712 enum machine_mode mode = TYPE_MODE (enttype);
16714 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16716 && integer_zerop (TYPE_MIN_VALUE (domain))
16717 && compare_tree_int (TYPE_MAX_VALUE (domain),
16718 TREE_STRING_LENGTH (init) - 1) == 0
16719 && ((size_t) TREE_STRING_LENGTH (init)
16720 == strlen (TREE_STRING_POINTER (init)) + 1))
16722 rtl = gen_rtx_CONST_STRING (VOIDmode,
16723 ggc_strdup (TREE_STRING_POINTER (init)));
16724 rtl = gen_rtx_MEM (BLKmode, rtl);
16725 MEM_READONLY_P (rtl) = 1;
16728 /* Other aggregates, and complex values, could be represented using
16730 else if (AGGREGATE_TYPE_P (type)
16731 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
16732 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
16733 || TREE_CODE (type) == COMPLEX_TYPE)
16735 /* Vectors only work if their mode is supported by the target.
16736 FIXME: generic vectors ought to work too. */
16737 else if (TREE_CODE (type) == VECTOR_TYPE
16738 && !VECTOR_MODE_P (TYPE_MODE (type)))
16740 /* If the initializer is something that we know will expand into an
16741 immediate RTL constant, expand it now. We must be careful not to
16742 reference variables which won't be output. */
16743 else if (initializer_constant_valid_p (init, type)
16744 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16746 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16748 if (TREE_CODE (type) == VECTOR_TYPE)
16749 switch (TREE_CODE (init))
16754 if (TREE_CONSTANT (init))
16756 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16757 bool constant_p = true;
16759 unsigned HOST_WIDE_INT ix;
16761 /* Even when ctor is constant, it might contain non-*_CST
16762 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16763 belong into VECTOR_CST nodes. */
16764 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16765 if (!CONSTANT_CLASS_P (value))
16767 constant_p = false;
16773 init = build_vector_from_ctor (type, elts);
16783 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16785 /* If expand_expr returns a MEM, it wasn't immediate. */
16786 gcc_assert (!rtl || !MEM_P (rtl));
16792 /* Generate RTL for the variable DECL to represent its location. */
16795 rtl_for_decl_location (tree decl)
16799 /* Here we have to decide where we are going to say the parameter "lives"
16800 (as far as the debugger is concerned). We only have a couple of
16801 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16803 DECL_RTL normally indicates where the parameter lives during most of the
16804 activation of the function. If optimization is enabled however, this
16805 could be either NULL or else a pseudo-reg. Both of those cases indicate
16806 that the parameter doesn't really live anywhere (as far as the code
16807 generation parts of GCC are concerned) during most of the function's
16808 activation. That will happen (for example) if the parameter is never
16809 referenced within the function.
16811 We could just generate a location descriptor here for all non-NULL
16812 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16813 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16814 where DECL_RTL is NULL or is a pseudo-reg.
16816 Note however that we can only get away with using DECL_INCOMING_RTL as
16817 a backup substitute for DECL_RTL in certain limited cases. In cases
16818 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16819 we can be sure that the parameter was passed using the same type as it is
16820 declared to have within the function, and that its DECL_INCOMING_RTL
16821 points us to a place where a value of that type is passed.
16823 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16824 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16825 because in these cases DECL_INCOMING_RTL points us to a value of some
16826 type which is *different* from the type of the parameter itself. Thus,
16827 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16828 such cases, the debugger would end up (for example) trying to fetch a
16829 `float' from a place which actually contains the first part of a
16830 `double'. That would lead to really incorrect and confusing
16831 output at debug-time.
16833 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16834 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16835 are a couple of exceptions however. On little-endian machines we can
16836 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16837 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16838 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16839 when (on a little-endian machine) a non-prototyped function has a
16840 parameter declared to be of type `short' or `char'. In such cases,
16841 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16842 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16843 passed `int' value. If the debugger then uses that address to fetch
16844 a `short' or a `char' (on a little-endian machine) the result will be
16845 the correct data, so we allow for such exceptional cases below.
16847 Note that our goal here is to describe the place where the given formal
16848 parameter lives during most of the function's activation (i.e. between the
16849 end of the prologue and the start of the epilogue). We'll do that as best
16850 as we can. Note however that if the given formal parameter is modified
16851 sometime during the execution of the function, then a stack backtrace (at
16852 debug-time) will show the function as having been called with the *new*
16853 value rather than the value which was originally passed in. This happens
16854 rarely enough that it is not a major problem, but it *is* a problem, and
16855 I'd like to fix it.
16857 A future version of dwarf2out.c may generate two additional attributes for
16858 any given DW_TAG_formal_parameter DIE which will describe the "passed
16859 type" and the "passed location" for the given formal parameter in addition
16860 to the attributes we now generate to indicate the "declared type" and the
16861 "active location" for each parameter. This additional set of attributes
16862 could be used by debuggers for stack backtraces. Separately, note that
16863 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16864 This happens (for example) for inlined-instances of inline function formal
16865 parameters which are never referenced. This really shouldn't be
16866 happening. All PARM_DECL nodes should get valid non-NULL
16867 DECL_INCOMING_RTL values. FIXME. */
16869 /* Use DECL_RTL as the "location" unless we find something better. */
16870 rtl = DECL_RTL_IF_SET (decl);
16872 /* When generating abstract instances, ignore everything except
16873 constants, symbols living in memory, and symbols living in
16874 fixed registers. */
16875 if (! reload_completed)
16878 && (CONSTANT_P (rtl)
16880 && CONSTANT_P (XEXP (rtl, 0)))
16882 && TREE_CODE (decl) == VAR_DECL
16883 && TREE_STATIC (decl))))
16885 rtl = targetm.delegitimize_address (rtl);
16890 else if (TREE_CODE (decl) == PARM_DECL)
16892 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
16894 tree declared_type = TREE_TYPE (decl);
16895 tree passed_type = DECL_ARG_TYPE (decl);
16896 enum machine_mode dmode = TYPE_MODE (declared_type);
16897 enum machine_mode pmode = TYPE_MODE (passed_type);
16899 /* This decl represents a formal parameter which was optimized out.
16900 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16901 all cases where (rtl == NULL_RTX) just below. */
16902 if (dmode == pmode)
16903 rtl = DECL_INCOMING_RTL (decl);
16904 else if (SCALAR_INT_MODE_P (dmode)
16905 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16906 && DECL_INCOMING_RTL (decl))
16908 rtx inc = DECL_INCOMING_RTL (decl);
16911 else if (MEM_P (inc))
16913 if (BYTES_BIG_ENDIAN)
16914 rtl = adjust_address_nv (inc, dmode,
16915 GET_MODE_SIZE (pmode)
16916 - GET_MODE_SIZE (dmode));
16923 /* If the parm was passed in registers, but lives on the stack, then
16924 make a big endian correction if the mode of the type of the
16925 parameter is not the same as the mode of the rtl. */
16926 /* ??? This is the same series of checks that are made in dbxout.c before
16927 we reach the big endian correction code there. It isn't clear if all
16928 of these checks are necessary here, but keeping them all is the safe
16930 else if (MEM_P (rtl)
16931 && XEXP (rtl, 0) != const0_rtx
16932 && ! CONSTANT_P (XEXP (rtl, 0))
16933 /* Not passed in memory. */
16934 && !MEM_P (DECL_INCOMING_RTL (decl))
16935 /* Not passed by invisible reference. */
16936 && (!REG_P (XEXP (rtl, 0))
16937 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16938 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16939 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16940 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16943 /* Big endian correction check. */
16944 && BYTES_BIG_ENDIAN
16945 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16946 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16949 int offset = (UNITS_PER_WORD
16950 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16952 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16953 plus_constant (XEXP (rtl, 0), offset));
16956 else if (TREE_CODE (decl) == VAR_DECL
16959 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16960 && BYTES_BIG_ENDIAN)
16962 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16963 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16965 /* If a variable is declared "register" yet is smaller than
16966 a register, then if we store the variable to memory, it
16967 looks like we're storing a register-sized value, when in
16968 fact we are not. We need to adjust the offset of the
16969 storage location to reflect the actual value's bytes,
16970 else gdb will not be able to display it. */
16972 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16973 plus_constant (XEXP (rtl, 0), rsize-dsize));
16976 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16977 and will have been substituted directly into all expressions that use it.
16978 C does not have such a concept, but C++ and other languages do. */
16979 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16980 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16983 rtl = targetm.delegitimize_address (rtl);
16985 /* If we don't look past the constant pool, we risk emitting a
16986 reference to a constant pool entry that isn't referenced from
16987 code, and thus is not emitted. */
16989 rtl = avoid_constant_pool_reference (rtl);
16991 /* Try harder to get a rtl. If this symbol ends up not being emitted
16992 in the current CU, resolve_addr will remove the expression referencing
16994 if (rtl == NULL_RTX
16995 && TREE_CODE (decl) == VAR_DECL
16996 && !DECL_EXTERNAL (decl)
16997 && TREE_STATIC (decl)
16998 && DECL_NAME (decl)
16999 && !DECL_HARD_REGISTER (decl)
17000 && DECL_MODE (decl) != VOIDmode)
17002 rtl = make_decl_rtl_for_debug (decl);
17004 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
17005 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
17012 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17013 returned. If so, the decl for the COMMON block is returned, and the
17014 value is the offset into the common block for the symbol. */
17017 fortran_common (tree decl, HOST_WIDE_INT *value)
17019 tree val_expr, cvar;
17020 enum machine_mode mode;
17021 HOST_WIDE_INT bitsize, bitpos;
17023 int volatilep = 0, unsignedp = 0;
17025 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
17026 it does not have a value (the offset into the common area), or if it
17027 is thread local (as opposed to global) then it isn't common, and shouldn't
17028 be handled as such. */
17029 if (TREE_CODE (decl) != VAR_DECL
17030 || !TREE_STATIC (decl)
17031 || !DECL_HAS_VALUE_EXPR_P (decl)
17035 val_expr = DECL_VALUE_EXPR (decl);
17036 if (TREE_CODE (val_expr) != COMPONENT_REF)
17039 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
17040 &mode, &unsignedp, &volatilep, true);
17042 if (cvar == NULL_TREE
17043 || TREE_CODE (cvar) != VAR_DECL
17044 || DECL_ARTIFICIAL (cvar)
17045 || !TREE_PUBLIC (cvar))
17049 if (offset != NULL)
17051 if (!host_integerp (offset, 0))
17053 *value = tree_low_cst (offset, 0);
17056 *value += bitpos / BITS_PER_UNIT;
17061 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
17062 data attribute for a variable or a parameter. We generate the
17063 DW_AT_const_value attribute only in those cases where the given variable
17064 or parameter does not have a true "location" either in memory or in a
17065 register. This can happen (for example) when a constant is passed as an
17066 actual argument in a call to an inline function. (It's possible that
17067 these things can crop up in other ways also.) Note that one type of
17068 constant value which can be passed into an inlined function is a constant
17069 pointer. This can happen for example if an actual argument in an inlined
17070 function call evaluates to a compile-time constant address.
17072 CACHE_P is true if it is worth caching the location list for DECL,
17073 so that future calls can reuse it rather than regenerate it from scratch.
17074 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
17075 since we will need to refer to them each time the function is inlined. */
17078 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
17079 enum dwarf_attribute attr)
17082 dw_loc_list_ref list;
17083 var_loc_list *loc_list;
17084 cached_dw_loc_list *cache;
17087 if (TREE_CODE (decl) == ERROR_MARK)
17090 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
17091 || TREE_CODE (decl) == RESULT_DECL);
17093 /* Try to get some constant RTL for this decl, and use that as the value of
17096 rtl = rtl_for_decl_location (decl);
17097 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17098 && add_const_value_attribute (die, rtl))
17101 /* See if we have single element location list that is equivalent to
17102 a constant value. That way we are better to use add_const_value_attribute
17103 rather than expanding constant value equivalent. */
17104 loc_list = lookup_decl_loc (decl);
17107 && loc_list->first->next == NULL
17108 && NOTE_P (loc_list->first->loc)
17109 && NOTE_VAR_LOCATION (loc_list->first->loc)
17110 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
17112 struct var_loc_node *node;
17114 node = loc_list->first;
17115 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
17116 if (GET_CODE (rtl) == EXPR_LIST)
17117 rtl = XEXP (rtl, 0);
17118 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17119 && add_const_value_attribute (die, rtl))
17122 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
17123 list several times. See if we've already cached the contents. */
17125 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
17129 cache = (cached_dw_loc_list *)
17130 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
17132 list = cache->loc_list;
17136 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
17137 /* It is usually worth caching this result if the decl is from
17138 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
17139 if (cache_p && list && list->dw_loc_next)
17141 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
17142 DECL_UID (decl), INSERT);
17143 cache = ggc_alloc_cleared_cached_dw_loc_list ();
17144 cache->decl_id = DECL_UID (decl);
17145 cache->loc_list = list;
17151 add_AT_location_description (die, attr, list);
17154 /* None of that worked, so it must not really have a location;
17155 try adding a constant value attribute from the DECL_INITIAL. */
17156 return tree_add_const_value_attribute_for_decl (die, decl);
17159 /* Add VARIABLE and DIE into deferred locations list. */
17162 defer_location (tree variable, dw_die_ref die)
17164 deferred_locations entry;
17165 entry.variable = variable;
17167 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
17170 /* Helper function for tree_add_const_value_attribute. Natively encode
17171 initializer INIT into an array. Return true if successful. */
17174 native_encode_initializer (tree init, unsigned char *array, int size)
17178 if (init == NULL_TREE)
17182 switch (TREE_CODE (init))
17185 type = TREE_TYPE (init);
17186 if (TREE_CODE (type) == ARRAY_TYPE)
17188 tree enttype = TREE_TYPE (type);
17189 enum machine_mode mode = TYPE_MODE (enttype);
17191 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
17193 if (int_size_in_bytes (type) != size)
17195 if (size > TREE_STRING_LENGTH (init))
17197 memcpy (array, TREE_STRING_POINTER (init),
17198 TREE_STRING_LENGTH (init));
17199 memset (array + TREE_STRING_LENGTH (init),
17200 '\0', size - TREE_STRING_LENGTH (init));
17203 memcpy (array, TREE_STRING_POINTER (init), size);
17208 type = TREE_TYPE (init);
17209 if (int_size_in_bytes (type) != size)
17211 if (TREE_CODE (type) == ARRAY_TYPE)
17213 HOST_WIDE_INT min_index;
17214 unsigned HOST_WIDE_INT cnt;
17215 int curpos = 0, fieldsize;
17216 constructor_elt *ce;
17218 if (TYPE_DOMAIN (type) == NULL_TREE
17219 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
17222 fieldsize = int_size_in_bytes (TREE_TYPE (type));
17223 if (fieldsize <= 0)
17226 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
17227 memset (array, '\0', size);
17228 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17230 tree val = ce->value;
17231 tree index = ce->index;
17233 if (index && TREE_CODE (index) == RANGE_EXPR)
17234 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
17237 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
17242 if (!native_encode_initializer (val, array + pos, fieldsize))
17245 curpos = pos + fieldsize;
17246 if (index && TREE_CODE (index) == RANGE_EXPR)
17248 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17249 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17250 while (count-- > 0)
17253 memcpy (array + curpos, array + pos, fieldsize);
17254 curpos += fieldsize;
17257 gcc_assert (curpos <= size);
17261 else if (TREE_CODE (type) == RECORD_TYPE
17262 || TREE_CODE (type) == UNION_TYPE)
17264 tree field = NULL_TREE;
17265 unsigned HOST_WIDE_INT cnt;
17266 constructor_elt *ce;
17268 if (int_size_in_bytes (type) != size)
17271 if (TREE_CODE (type) == RECORD_TYPE)
17272 field = TYPE_FIELDS (type);
17274 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17276 tree val = ce->value;
17277 int pos, fieldsize;
17279 if (ce->index != 0)
17285 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17288 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17289 && TYPE_DOMAIN (TREE_TYPE (field))
17290 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17292 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17293 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17295 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17296 pos = int_byte_position (field);
17297 gcc_assert (pos + fieldsize <= size);
17299 && !native_encode_initializer (val, array + pos, fieldsize))
17305 case VIEW_CONVERT_EXPR:
17306 case NON_LVALUE_EXPR:
17307 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17309 return native_encode_expr (init, array, size) == size;
17313 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17314 attribute is the const value T. */
17317 tree_add_const_value_attribute (dw_die_ref die, tree t)
17320 tree type = TREE_TYPE (t);
17323 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17327 gcc_assert (!DECL_P (init));
17329 rtl = rtl_for_decl_init (init, type);
17331 return add_const_value_attribute (die, rtl);
17332 /* If the host and target are sane, try harder. */
17333 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17334 && initializer_constant_valid_p (init, type))
17336 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17337 if (size > 0 && (int) size == size)
17339 unsigned char *array = (unsigned char *)
17340 ggc_alloc_cleared_atomic (size);
17342 if (native_encode_initializer (init, array, size))
17344 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17352 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17353 attribute is the const value of T, where T is an integral constant
17354 variable with static storage duration
17355 (so it can't be a PARM_DECL or a RESULT_DECL). */
17358 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17362 || (TREE_CODE (decl) != VAR_DECL
17363 && TREE_CODE (decl) != CONST_DECL))
17366 if (TREE_READONLY (decl)
17367 && ! TREE_THIS_VOLATILE (decl)
17368 && DECL_INITIAL (decl))
17373 /* Don't add DW_AT_const_value if abstract origin already has one. */
17374 if (get_AT (var_die, DW_AT_const_value))
17377 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17380 /* Convert the CFI instructions for the current function into a
17381 location list. This is used for DW_AT_frame_base when we targeting
17382 a dwarf2 consumer that does not support the dwarf3
17383 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17386 static dw_loc_list_ref
17387 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17390 dw_loc_list_ref list, *list_tail;
17392 dw_cfa_location last_cfa, next_cfa;
17393 const char *start_label, *last_label, *section;
17394 dw_cfa_location remember;
17396 fde = current_fde ();
17397 gcc_assert (fde != NULL);
17399 section = secname_for_decl (current_function_decl);
17403 memset (&next_cfa, 0, sizeof (next_cfa));
17404 next_cfa.reg = INVALID_REGNUM;
17405 remember = next_cfa;
17407 start_label = fde->dw_fde_begin;
17409 /* ??? Bald assumption that the CIE opcode list does not contain
17410 advance opcodes. */
17411 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
17412 lookup_cfa_1 (cfi, &next_cfa, &remember);
17414 last_cfa = next_cfa;
17415 last_label = start_label;
17417 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi == NULL)
17419 /* If the first partition contained no CFI adjustments, the
17420 CIE opcodes apply to the whole first partition. */
17421 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17422 fde->dw_fde_begin, fde->dw_fde_end, section);
17423 list_tail =&(*list_tail)->dw_loc_next;
17424 start_label = last_label = fde->dw_fde_second_begin;
17427 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17429 switch (cfi->dw_cfi_opc)
17431 case DW_CFA_set_loc:
17432 case DW_CFA_advance_loc1:
17433 case DW_CFA_advance_loc2:
17434 case DW_CFA_advance_loc4:
17435 if (!cfa_equal_p (&last_cfa, &next_cfa))
17437 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17438 start_label, last_label, section);
17440 list_tail = &(*list_tail)->dw_loc_next;
17441 last_cfa = next_cfa;
17442 start_label = last_label;
17444 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17447 case DW_CFA_advance_loc:
17448 /* The encoding is complex enough that we should never emit this. */
17449 gcc_unreachable ();
17452 lookup_cfa_1 (cfi, &next_cfa, &remember);
17455 if (cfi == fde->dw_fde_switch_cfi)
17457 if (!cfa_equal_p (&last_cfa, &next_cfa))
17459 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17460 start_label, last_label, section);
17462 list_tail = &(*list_tail)->dw_loc_next;
17463 last_cfa = next_cfa;
17464 start_label = last_label;
17466 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17467 start_label, fde->dw_fde_end, section);
17468 list_tail = &(*list_tail)->dw_loc_next;
17469 start_label = last_label = fde->dw_fde_second_begin;
17473 if (!cfa_equal_p (&last_cfa, &next_cfa))
17475 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17476 start_label, last_label, section);
17477 list_tail = &(*list_tail)->dw_loc_next;
17478 start_label = last_label;
17481 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17483 fde->dw_fde_second_begin
17484 ? fde->dw_fde_second_end : fde->dw_fde_end,
17487 if (list && list->dw_loc_next)
17493 /* Compute a displacement from the "steady-state frame pointer" to the
17494 frame base (often the same as the CFA), and store it in
17495 frame_pointer_fb_offset. OFFSET is added to the displacement
17496 before the latter is negated. */
17499 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17503 #ifdef FRAME_POINTER_CFA_OFFSET
17504 reg = frame_pointer_rtx;
17505 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17507 reg = arg_pointer_rtx;
17508 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17511 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17512 if (GET_CODE (elim) == PLUS)
17514 offset += INTVAL (XEXP (elim, 1));
17515 elim = XEXP (elim, 0);
17518 frame_pointer_fb_offset = -offset;
17520 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
17521 in which to eliminate. This is because it's stack pointer isn't
17522 directly accessible as a register within the ISA. To work around
17523 this, assume that while we cannot provide a proper value for
17524 frame_pointer_fb_offset, we won't need one either. */
17525 frame_pointer_fb_offset_valid
17526 = ((SUPPORTS_STACK_ALIGNMENT
17527 && (elim == hard_frame_pointer_rtx
17528 || elim == stack_pointer_rtx))
17529 || elim == (frame_pointer_needed
17530 ? hard_frame_pointer_rtx
17531 : stack_pointer_rtx));
17534 /* Generate a DW_AT_name attribute given some string value to be included as
17535 the value of the attribute. */
17538 add_name_attribute (dw_die_ref die, const char *name_string)
17540 if (name_string != NULL && *name_string != 0)
17542 if (demangle_name_func)
17543 name_string = (*demangle_name_func) (name_string);
17545 add_AT_string (die, DW_AT_name, name_string);
17549 /* Generate a DW_AT_comp_dir attribute for DIE. */
17552 add_comp_dir_attribute (dw_die_ref die)
17554 const char *wd = get_src_pwd ();
17560 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17564 wdlen = strlen (wd);
17565 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17567 wd1 [wdlen] = DIR_SEPARATOR;
17568 wd1 [wdlen + 1] = 0;
17572 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17575 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17579 lower_bound_default (void)
17581 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17586 case DW_LANG_C_plus_plus:
17588 case DW_LANG_ObjC_plus_plus:
17591 case DW_LANG_Fortran77:
17592 case DW_LANG_Fortran90:
17593 case DW_LANG_Fortran95:
17597 case DW_LANG_Python:
17598 return dwarf_version >= 4 ? 0 : -1;
17599 case DW_LANG_Ada95:
17600 case DW_LANG_Ada83:
17601 case DW_LANG_Cobol74:
17602 case DW_LANG_Cobol85:
17603 case DW_LANG_Pascal83:
17604 case DW_LANG_Modula2:
17606 return dwarf_version >= 4 ? 1 : -1;
17612 /* Given a tree node describing an array bound (either lower or upper) output
17613 a representation for that bound. */
17616 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17618 switch (TREE_CODE (bound))
17623 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17626 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17629 /* Use the default if possible. */
17630 if (bound_attr == DW_AT_lower_bound
17631 && host_integerp (bound, 0)
17632 && (dflt = lower_bound_default ()) != -1
17633 && tree_low_cst (bound, 0) == dflt)
17636 /* Otherwise represent the bound as an unsigned value with the
17637 precision of its type. The precision and signedness of the
17638 type will be necessary to re-interpret it unambiguously. */
17639 else if (prec < HOST_BITS_PER_WIDE_INT)
17641 unsigned HOST_WIDE_INT mask
17642 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17643 add_AT_unsigned (subrange_die, bound_attr,
17644 TREE_INT_CST_LOW (bound) & mask);
17646 else if (prec == HOST_BITS_PER_WIDE_INT
17647 || TREE_INT_CST_HIGH (bound) == 0)
17648 add_AT_unsigned (subrange_die, bound_attr,
17649 TREE_INT_CST_LOW (bound));
17651 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17652 TREE_INT_CST_LOW (bound));
17657 case VIEW_CONVERT_EXPR:
17658 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17668 dw_die_ref decl_die = lookup_decl_die (bound);
17670 /* ??? Can this happen, or should the variable have been bound
17671 first? Probably it can, since I imagine that we try to create
17672 the types of parameters in the order in which they exist in
17673 the list, and won't have created a forward reference to a
17674 later parameter. */
17675 if (decl_die != NULL)
17677 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17685 /* Otherwise try to create a stack operation procedure to
17686 evaluate the value of the array bound. */
17688 dw_die_ref ctx, decl_die;
17689 dw_loc_list_ref list;
17691 list = loc_list_from_tree (bound, 2);
17692 if (list == NULL || single_element_loc_list_p (list))
17694 /* If DW_AT_*bound is not a reference nor constant, it is
17695 a DWARF expression rather than location description.
17696 For that loc_list_from_tree (bound, 0) is needed.
17697 If that fails to give a single element list,
17698 fall back to outputting this as a reference anyway. */
17699 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17700 if (list2 && single_element_loc_list_p (list2))
17702 add_AT_loc (subrange_die, bound_attr, list2->expr);
17709 if (current_function_decl == 0)
17710 ctx = comp_unit_die ();
17712 ctx = lookup_decl_die (current_function_decl);
17714 decl_die = new_die (DW_TAG_variable, ctx, bound);
17715 add_AT_flag (decl_die, DW_AT_artificial, 1);
17716 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17717 add_AT_location_description (decl_die, DW_AT_location, list);
17718 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17724 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17725 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17726 Note that the block of subscript information for an array type also
17727 includes information about the element type of the given array type. */
17730 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17732 unsigned dimension_number;
17734 dw_die_ref subrange_die;
17736 for (dimension_number = 0;
17737 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17738 type = TREE_TYPE (type), dimension_number++)
17740 tree domain = TYPE_DOMAIN (type);
17742 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17745 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17746 and (in GNU C only) variable bounds. Handle all three forms
17748 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17751 /* We have an array type with specified bounds. */
17752 lower = TYPE_MIN_VALUE (domain);
17753 upper = TYPE_MAX_VALUE (domain);
17755 /* Define the index type. */
17756 if (TREE_TYPE (domain))
17758 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17759 TREE_TYPE field. We can't emit debug info for this
17760 because it is an unnamed integral type. */
17761 if (TREE_CODE (domain) == INTEGER_TYPE
17762 && TYPE_NAME (domain) == NULL_TREE
17763 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17764 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17767 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17771 /* ??? If upper is NULL, the array has unspecified length,
17772 but it does have a lower bound. This happens with Fortran
17774 Since the debugger is definitely going to need to know N
17775 to produce useful results, go ahead and output the lower
17776 bound solo, and hope the debugger can cope. */
17778 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17780 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17783 /* Otherwise we have an array type with an unspecified length. The
17784 DWARF-2 spec does not say how to handle this; let's just leave out the
17790 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17794 switch (TREE_CODE (tree_node))
17799 case ENUMERAL_TYPE:
17802 case QUAL_UNION_TYPE:
17803 size = int_size_in_bytes (tree_node);
17806 /* For a data member of a struct or union, the DW_AT_byte_size is
17807 generally given as the number of bytes normally allocated for an
17808 object of the *declared* type of the member itself. This is true
17809 even for bit-fields. */
17810 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17813 gcc_unreachable ();
17816 /* Note that `size' might be -1 when we get to this point. If it is, that
17817 indicates that the byte size of the entity in question is variable. We
17818 have no good way of expressing this fact in Dwarf at the present time,
17819 so just let the -1 pass on through. */
17820 add_AT_unsigned (die, DW_AT_byte_size, size);
17823 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17824 which specifies the distance in bits from the highest order bit of the
17825 "containing object" for the bit-field to the highest order bit of the
17828 For any given bit-field, the "containing object" is a hypothetical object
17829 (of some integral or enum type) within which the given bit-field lives. The
17830 type of this hypothetical "containing object" is always the same as the
17831 declared type of the individual bit-field itself. The determination of the
17832 exact location of the "containing object" for a bit-field is rather
17833 complicated. It's handled by the `field_byte_offset' function (above).
17835 Note that it is the size (in bytes) of the hypothetical "containing object"
17836 which will be given in the DW_AT_byte_size attribute for this bit-field.
17837 (See `byte_size_attribute' above). */
17840 add_bit_offset_attribute (dw_die_ref die, tree decl)
17842 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17843 tree type = DECL_BIT_FIELD_TYPE (decl);
17844 HOST_WIDE_INT bitpos_int;
17845 HOST_WIDE_INT highest_order_object_bit_offset;
17846 HOST_WIDE_INT highest_order_field_bit_offset;
17847 HOST_WIDE_INT unsigned bit_offset;
17849 /* Must be a field and a bit field. */
17850 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17852 /* We can't yet handle bit-fields whose offsets are variable, so if we
17853 encounter such things, just return without generating any attribute
17854 whatsoever. Likewise for variable or too large size. */
17855 if (! host_integerp (bit_position (decl), 0)
17856 || ! host_integerp (DECL_SIZE (decl), 1))
17859 bitpos_int = int_bit_position (decl);
17861 /* Note that the bit offset is always the distance (in bits) from the
17862 highest-order bit of the "containing object" to the highest-order bit of
17863 the bit-field itself. Since the "high-order end" of any object or field
17864 is different on big-endian and little-endian machines, the computation
17865 below must take account of these differences. */
17866 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17867 highest_order_field_bit_offset = bitpos_int;
17869 if (! BYTES_BIG_ENDIAN)
17871 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17872 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17876 = (! BYTES_BIG_ENDIAN
17877 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17878 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17880 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
17883 /* For a FIELD_DECL node which represents a bit field, output an attribute
17884 which specifies the length in bits of the given field. */
17887 add_bit_size_attribute (dw_die_ref die, tree decl)
17889 /* Must be a field and a bit field. */
17890 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17891 && DECL_BIT_FIELD_TYPE (decl));
17893 if (host_integerp (DECL_SIZE (decl), 1))
17894 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17897 /* If the compiled language is ANSI C, then add a 'prototyped'
17898 attribute, if arg types are given for the parameters of a function. */
17901 add_prototyped_attribute (dw_die_ref die, tree func_type)
17903 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
17904 && prototype_p (func_type))
17905 add_AT_flag (die, DW_AT_prototyped, 1);
17908 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17909 by looking in either the type declaration or object declaration
17912 static inline dw_die_ref
17913 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17915 dw_die_ref origin_die = NULL;
17917 if (TREE_CODE (origin) != FUNCTION_DECL)
17919 /* We may have gotten separated from the block for the inlined
17920 function, if we're in an exception handler or some such; make
17921 sure that the abstract function has been written out.
17923 Doing this for nested functions is wrong, however; functions are
17924 distinct units, and our context might not even be inline. */
17928 fn = TYPE_STUB_DECL (fn);
17930 fn = decl_function_context (fn);
17932 dwarf2out_abstract_function (fn);
17935 if (DECL_P (origin))
17936 origin_die = lookup_decl_die (origin);
17937 else if (TYPE_P (origin))
17938 origin_die = lookup_type_die (origin);
17940 /* XXX: Functions that are never lowered don't always have correct block
17941 trees (in the case of java, they simply have no block tree, in some other
17942 languages). For these functions, there is nothing we can really do to
17943 output correct debug info for inlined functions in all cases. Rather
17944 than die, we'll just produce deficient debug info now, in that we will
17945 have variables without a proper abstract origin. In the future, when all
17946 functions are lowered, we should re-add a gcc_assert (origin_die)
17950 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17954 /* We do not currently support the pure_virtual attribute. */
17957 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17959 if (DECL_VINDEX (func_decl))
17961 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17963 if (host_integerp (DECL_VINDEX (func_decl), 0))
17964 add_AT_loc (die, DW_AT_vtable_elem_location,
17965 new_loc_descr (DW_OP_constu,
17966 tree_low_cst (DECL_VINDEX (func_decl), 0),
17969 /* GNU extension: Record what type this method came from originally. */
17970 if (debug_info_level > DINFO_LEVEL_TERSE
17971 && DECL_CONTEXT (func_decl))
17972 add_AT_die_ref (die, DW_AT_containing_type,
17973 lookup_type_die (DECL_CONTEXT (func_decl)));
17977 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17978 given decl. This used to be a vendor extension until after DWARF 4
17979 standardized it. */
17982 add_linkage_attr (dw_die_ref die, tree decl)
17984 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17986 /* Mimic what assemble_name_raw does with a leading '*'. */
17987 if (name[0] == '*')
17990 if (dwarf_version >= 4)
17991 add_AT_string (die, DW_AT_linkage_name, name);
17993 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17996 /* Add source coordinate attributes for the given decl. */
17999 add_src_coords_attributes (dw_die_ref die, tree decl)
18001 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18003 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
18004 add_AT_unsigned (die, DW_AT_decl_line, s.line);
18007 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
18010 add_linkage_name (dw_die_ref die, tree decl)
18012 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
18013 && TREE_PUBLIC (decl)
18014 && !DECL_ABSTRACT (decl)
18015 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
18016 && die->die_tag != DW_TAG_member)
18018 /* Defer until we have an assembler name set. */
18019 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
18021 limbo_die_node *asm_name;
18023 asm_name = ggc_alloc_cleared_limbo_die_node ();
18024 asm_name->die = die;
18025 asm_name->created_for = decl;
18026 asm_name->next = deferred_asm_name;
18027 deferred_asm_name = asm_name;
18029 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
18030 add_linkage_attr (die, decl);
18034 /* Add a DW_AT_name attribute and source coordinate attribute for the
18035 given decl, but only if it actually has a name. */
18038 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
18042 decl_name = DECL_NAME (decl);
18043 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
18045 const char *name = dwarf2_name (decl, 0);
18047 add_name_attribute (die, name);
18048 if (! DECL_ARTIFICIAL (decl))
18049 add_src_coords_attributes (die, decl);
18051 add_linkage_name (die, decl);
18054 #ifdef VMS_DEBUGGING_INFO
18055 /* Get the function's name, as described by its RTL. This may be different
18056 from the DECL_NAME name used in the source file. */
18057 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
18059 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
18060 XEXP (DECL_RTL (decl), 0));
18061 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
18063 #endif /* VMS_DEBUGGING_INFO */
18066 #ifdef VMS_DEBUGGING_INFO
18067 /* Output the debug main pointer die for VMS */
18070 dwarf2out_vms_debug_main_pointer (void)
18072 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18075 /* Allocate the VMS debug main subprogram die. */
18076 die = ggc_alloc_cleared_die_node ();
18077 die->die_tag = DW_TAG_subprogram;
18078 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
18079 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
18080 current_function_funcdef_no);
18081 add_AT_lbl_id (die, DW_AT_entry_pc, label);
18083 /* Make it the first child of comp_unit_die (). */
18084 die->die_parent = comp_unit_die ();
18085 if (comp_unit_die ()->die_child)
18087 die->die_sib = comp_unit_die ()->die_child->die_sib;
18088 comp_unit_die ()->die_child->die_sib = die;
18092 die->die_sib = die;
18093 comp_unit_die ()->die_child = die;
18096 #endif /* VMS_DEBUGGING_INFO */
18098 /* Push a new declaration scope. */
18101 push_decl_scope (tree scope)
18103 VEC_safe_push (tree, gc, decl_scope_table, scope);
18106 /* Pop a declaration scope. */
18109 pop_decl_scope (void)
18111 VEC_pop (tree, decl_scope_table);
18114 /* Return the DIE for the scope that immediately contains this type.
18115 Non-named types get global scope. Named types nested in other
18116 types get their containing scope if it's open, or global scope
18117 otherwise. All other types (i.e. function-local named types) get
18118 the current active scope. */
18121 scope_die_for (tree t, dw_die_ref context_die)
18123 dw_die_ref scope_die = NULL;
18124 tree containing_scope;
18127 /* Non-types always go in the current scope. */
18128 gcc_assert (TYPE_P (t));
18130 containing_scope = TYPE_CONTEXT (t);
18132 /* Use the containing namespace if it was passed in (for a declaration). */
18133 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
18135 if (context_die == lookup_decl_die (containing_scope))
18138 containing_scope = NULL_TREE;
18141 /* Ignore function type "scopes" from the C frontend. They mean that
18142 a tagged type is local to a parmlist of a function declarator, but
18143 that isn't useful to DWARF. */
18144 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
18145 containing_scope = NULL_TREE;
18147 if (SCOPE_FILE_SCOPE_P (containing_scope))
18148 scope_die = comp_unit_die ();
18149 else if (TYPE_P (containing_scope))
18151 /* For types, we can just look up the appropriate DIE. But
18152 first we check to see if we're in the middle of emitting it
18153 so we know where the new DIE should go. */
18154 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
18155 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
18160 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
18161 || TREE_ASM_WRITTEN (containing_scope));
18162 /*We are not in the middle of emitting the type
18163 CONTAINING_SCOPE. Let's see if it's emitted already. */
18164 scope_die = lookup_type_die (containing_scope);
18166 /* If none of the current dies are suitable, we get file scope. */
18167 if (scope_die == NULL)
18168 scope_die = comp_unit_die ();
18171 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
18174 scope_die = context_die;
18179 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
18182 local_scope_p (dw_die_ref context_die)
18184 for (; context_die; context_die = context_die->die_parent)
18185 if (context_die->die_tag == DW_TAG_inlined_subroutine
18186 || context_die->die_tag == DW_TAG_subprogram)
18192 /* Returns nonzero if CONTEXT_DIE is a class. */
18195 class_scope_p (dw_die_ref context_die)
18197 return (context_die
18198 && (context_die->die_tag == DW_TAG_structure_type
18199 || context_die->die_tag == DW_TAG_class_type
18200 || context_die->die_tag == DW_TAG_interface_type
18201 || context_die->die_tag == DW_TAG_union_type));
18204 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
18205 whether or not to treat a DIE in this context as a declaration. */
18208 class_or_namespace_scope_p (dw_die_ref context_die)
18210 return (class_scope_p (context_die)
18211 || (context_die && context_die->die_tag == DW_TAG_namespace));
18214 /* Many forms of DIEs require a "type description" attribute. This
18215 routine locates the proper "type descriptor" die for the type given
18216 by 'type', and adds a DW_AT_type attribute below the given die. */
18219 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
18220 int decl_volatile, dw_die_ref context_die)
18222 enum tree_code code = TREE_CODE (type);
18223 dw_die_ref type_die = NULL;
18225 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18226 or fixed-point type, use the inner type. This is because we have no
18227 support for unnamed types in base_type_die. This can happen if this is
18228 an Ada subrange type. Correct solution is emit a subrange type die. */
18229 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
18230 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
18231 type = TREE_TYPE (type), code = TREE_CODE (type);
18233 if (code == ERROR_MARK
18234 /* Handle a special case. For functions whose return type is void, we
18235 generate *no* type attribute. (Note that no object may have type
18236 `void', so this only applies to function return types). */
18237 || code == VOID_TYPE)
18240 type_die = modified_type_die (type,
18241 decl_const || TYPE_READONLY (type),
18242 decl_volatile || TYPE_VOLATILE (type),
18245 if (type_die != NULL)
18246 add_AT_die_ref (object_die, DW_AT_type, type_die);
18249 /* Given an object die, add the calling convention attribute for the
18250 function call type. */
18252 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
18254 enum dwarf_calling_convention value = DW_CC_normal;
18256 value = ((enum dwarf_calling_convention)
18257 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
18260 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
18262 /* DWARF 2 doesn't provide a way to identify a program's source-level
18263 entry point. DW_AT_calling_convention attributes are only meant
18264 to describe functions' calling conventions. However, lacking a
18265 better way to signal the Fortran main program, we used this for
18266 a long time, following existing custom. Now, DWARF 4 has
18267 DW_AT_main_subprogram, which we add below, but some tools still
18268 rely on the old way, which we thus keep. */
18269 value = DW_CC_program;
18271 if (dwarf_version >= 4 || !dwarf_strict)
18272 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
18275 /* Only add the attribute if the backend requests it, and
18276 is not DW_CC_normal. */
18277 if (value && (value != DW_CC_normal))
18278 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18281 /* Given a tree pointer to a struct, class, union, or enum type node, return
18282 a pointer to the (string) tag name for the given type, or zero if the type
18283 was declared without a tag. */
18285 static const char *
18286 type_tag (const_tree type)
18288 const char *name = 0;
18290 if (TYPE_NAME (type) != 0)
18294 /* Find the IDENTIFIER_NODE for the type name. */
18295 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18296 && !TYPE_NAMELESS (type))
18297 t = TYPE_NAME (type);
18299 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18300 a TYPE_DECL node, regardless of whether or not a `typedef' was
18302 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18303 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18305 /* We want to be extra verbose. Don't call dwarf_name if
18306 DECL_NAME isn't set. The default hook for decl_printable_name
18307 doesn't like that, and in this context it's correct to return
18308 0, instead of "<anonymous>" or the like. */
18309 if (DECL_NAME (TYPE_NAME (type))
18310 && !DECL_NAMELESS (TYPE_NAME (type)))
18311 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18314 /* Now get the name as a string, or invent one. */
18315 if (!name && t != 0)
18316 name = IDENTIFIER_POINTER (t);
18319 return (name == 0 || *name == '\0') ? 0 : name;
18322 /* Return the type associated with a data member, make a special check
18323 for bit field types. */
18326 member_declared_type (const_tree member)
18328 return (DECL_BIT_FIELD_TYPE (member)
18329 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18332 /* Get the decl's label, as described by its RTL. This may be different
18333 from the DECL_NAME name used in the source file. */
18336 static const char *
18337 decl_start_label (tree decl)
18340 const char *fnname;
18342 x = DECL_RTL (decl);
18343 gcc_assert (MEM_P (x));
18346 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18348 fnname = XSTR (x, 0);
18353 /* These routines generate the internal representation of the DIE's for
18354 the compilation unit. Debugging information is collected by walking
18355 the declaration trees passed in from dwarf2out_decl(). */
18358 gen_array_type_die (tree type, dw_die_ref context_die)
18360 dw_die_ref scope_die = scope_die_for (type, context_die);
18361 dw_die_ref array_die;
18363 /* GNU compilers represent multidimensional array types as sequences of one
18364 dimensional array types whose element types are themselves array types.
18365 We sometimes squish that down to a single array_type DIE with multiple
18366 subscripts in the Dwarf debugging info. The draft Dwarf specification
18367 say that we are allowed to do this kind of compression in C, because
18368 there is no difference between an array of arrays and a multidimensional
18369 array. We don't do this for Ada to remain as close as possible to the
18370 actual representation, which is especially important against the language
18371 flexibilty wrt arrays of variable size. */
18373 bool collapse_nested_arrays = !is_ada ();
18376 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18377 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18378 if (TYPE_STRING_FLAG (type)
18379 && TREE_CODE (type) == ARRAY_TYPE
18381 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18383 HOST_WIDE_INT size;
18385 array_die = new_die (DW_TAG_string_type, scope_die, type);
18386 add_name_attribute (array_die, type_tag (type));
18387 equate_type_number_to_die (type, array_die);
18388 size = int_size_in_bytes (type);
18390 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18391 else if (TYPE_DOMAIN (type) != NULL_TREE
18392 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18393 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18395 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18396 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18398 size = int_size_in_bytes (TREE_TYPE (szdecl));
18399 if (loc && size > 0)
18401 add_AT_location_description (array_die, DW_AT_string_length, loc);
18402 if (size != DWARF2_ADDR_SIZE)
18403 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18409 /* ??? The SGI dwarf reader fails for array of array of enum types
18410 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18411 array type comes before the outer array type. We thus call gen_type_die
18412 before we new_die and must prevent nested array types collapsing for this
18415 #ifdef MIPS_DEBUGGING_INFO
18416 gen_type_die (TREE_TYPE (type), context_die);
18417 collapse_nested_arrays = false;
18420 array_die = new_die (DW_TAG_array_type, scope_die, type);
18421 add_name_attribute (array_die, type_tag (type));
18422 equate_type_number_to_die (type, array_die);
18424 if (TREE_CODE (type) == VECTOR_TYPE)
18425 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18427 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18429 && TREE_CODE (type) == ARRAY_TYPE
18430 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18431 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18432 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18435 /* We default the array ordering. SDB will probably do
18436 the right things even if DW_AT_ordering is not present. It's not even
18437 an issue until we start to get into multidimensional arrays anyway. If
18438 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18439 then we'll have to put the DW_AT_ordering attribute back in. (But if
18440 and when we find out that we need to put these in, we will only do so
18441 for multidimensional arrays. */
18442 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18445 #ifdef MIPS_DEBUGGING_INFO
18446 /* The SGI compilers handle arrays of unknown bound by setting
18447 AT_declaration and not emitting any subrange DIEs. */
18448 if (TREE_CODE (type) == ARRAY_TYPE
18449 && ! TYPE_DOMAIN (type))
18450 add_AT_flag (array_die, DW_AT_declaration, 1);
18453 if (TREE_CODE (type) == VECTOR_TYPE)
18455 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18456 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18457 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18458 add_bound_info (subrange_die, DW_AT_upper_bound,
18459 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18462 add_subscript_info (array_die, type, collapse_nested_arrays);
18464 /* Add representation of the type of the elements of this array type and
18465 emit the corresponding DIE if we haven't done it already. */
18466 element_type = TREE_TYPE (type);
18467 if (collapse_nested_arrays)
18468 while (TREE_CODE (element_type) == ARRAY_TYPE)
18470 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18472 element_type = TREE_TYPE (element_type);
18475 #ifndef MIPS_DEBUGGING_INFO
18476 gen_type_die (element_type, context_die);
18479 add_type_attribute (array_die, element_type, 0, 0, context_die);
18481 if (get_AT (array_die, DW_AT_name))
18482 add_pubtype (type, array_die);
18485 static dw_loc_descr_ref
18486 descr_info_loc (tree val, tree base_decl)
18488 HOST_WIDE_INT size;
18489 dw_loc_descr_ref loc, loc2;
18490 enum dwarf_location_atom op;
18492 if (val == base_decl)
18493 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18495 switch (TREE_CODE (val))
18498 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18500 return loc_descriptor_from_tree (val, 0);
18502 if (host_integerp (val, 0))
18503 return int_loc_descriptor (tree_low_cst (val, 0));
18506 size = int_size_in_bytes (TREE_TYPE (val));
18509 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18512 if (size == DWARF2_ADDR_SIZE)
18513 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18515 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18517 case POINTER_PLUS_EXPR:
18519 if (host_integerp (TREE_OPERAND (val, 1), 1)
18520 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18523 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18526 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18532 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18535 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18538 add_loc_descr (&loc, loc2);
18539 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18561 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18562 tree val, tree base_decl)
18564 dw_loc_descr_ref loc;
18566 if (host_integerp (val, 0))
18568 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18572 loc = descr_info_loc (val, base_decl);
18576 add_AT_loc (die, attr, loc);
18579 /* This routine generates DIE for array with hidden descriptor, details
18580 are filled into *info by a langhook. */
18583 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18584 dw_die_ref context_die)
18586 dw_die_ref scope_die = scope_die_for (type, context_die);
18587 dw_die_ref array_die;
18590 array_die = new_die (DW_TAG_array_type, scope_die, type);
18591 add_name_attribute (array_die, type_tag (type));
18592 equate_type_number_to_die (type, array_die);
18594 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18596 && info->ndimensions >= 2)
18597 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18599 if (info->data_location)
18600 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18602 if (info->associated)
18603 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18605 if (info->allocated)
18606 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18609 for (dim = 0; dim < info->ndimensions; dim++)
18611 dw_die_ref subrange_die
18612 = new_die (DW_TAG_subrange_type, array_die, NULL);
18614 if (info->dimen[dim].lower_bound)
18616 /* If it is the default value, omit it. */
18619 if (host_integerp (info->dimen[dim].lower_bound, 0)
18620 && (dflt = lower_bound_default ()) != -1
18621 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18624 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18625 info->dimen[dim].lower_bound,
18628 if (info->dimen[dim].upper_bound)
18629 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18630 info->dimen[dim].upper_bound,
18632 if (info->dimen[dim].stride)
18633 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18634 info->dimen[dim].stride,
18638 gen_type_die (info->element_type, context_die);
18639 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18641 if (get_AT (array_die, DW_AT_name))
18642 add_pubtype (type, array_die);
18647 gen_entry_point_die (tree decl, dw_die_ref context_die)
18649 tree origin = decl_ultimate_origin (decl);
18650 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18652 if (origin != NULL)
18653 add_abstract_origin_attribute (decl_die, origin);
18656 add_name_and_src_coords_attributes (decl_die, decl);
18657 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18658 0, 0, context_die);
18661 if (DECL_ABSTRACT (decl))
18662 equate_decl_number_to_die (decl, decl_die);
18664 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18668 /* Walk through the list of incomplete types again, trying once more to
18669 emit full debugging info for them. */
18672 retry_incomplete_types (void)
18676 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18677 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18678 DINFO_USAGE_DIR_USE))
18679 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
18682 /* Determine what tag to use for a record type. */
18684 static enum dwarf_tag
18685 record_type_tag (tree type)
18687 if (! lang_hooks.types.classify_record)
18688 return DW_TAG_structure_type;
18690 switch (lang_hooks.types.classify_record (type))
18692 case RECORD_IS_STRUCT:
18693 return DW_TAG_structure_type;
18695 case RECORD_IS_CLASS:
18696 return DW_TAG_class_type;
18698 case RECORD_IS_INTERFACE:
18699 if (dwarf_version >= 3 || !dwarf_strict)
18700 return DW_TAG_interface_type;
18701 return DW_TAG_structure_type;
18704 gcc_unreachable ();
18708 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18709 include all of the information about the enumeration values also. Each
18710 enumerated type name/value is listed as a child of the enumerated type
18714 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18716 dw_die_ref type_die = lookup_type_die (type);
18718 if (type_die == NULL)
18720 type_die = new_die (DW_TAG_enumeration_type,
18721 scope_die_for (type, context_die), type);
18722 equate_type_number_to_die (type, type_die);
18723 add_name_attribute (type_die, type_tag (type));
18724 if (dwarf_version >= 4 || !dwarf_strict)
18726 if (ENUM_IS_SCOPED (type))
18727 add_AT_flag (type_die, DW_AT_enum_class, 1);
18728 if (ENUM_IS_OPAQUE (type))
18729 add_AT_flag (type_die, DW_AT_declaration, 1);
18732 else if (! TYPE_SIZE (type))
18735 remove_AT (type_die, DW_AT_declaration);
18737 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18738 given enum type is incomplete, do not generate the DW_AT_byte_size
18739 attribute or the DW_AT_element_list attribute. */
18740 if (TYPE_SIZE (type))
18744 TREE_ASM_WRITTEN (type) = 1;
18745 add_byte_size_attribute (type_die, type);
18746 if (TYPE_STUB_DECL (type) != NULL_TREE)
18748 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18749 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18752 /* If the first reference to this type was as the return type of an
18753 inline function, then it may not have a parent. Fix this now. */
18754 if (type_die->die_parent == NULL)
18755 add_child_die (scope_die_for (type, context_die), type_die);
18757 for (link = TYPE_VALUES (type);
18758 link != NULL; link = TREE_CHAIN (link))
18760 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18761 tree value = TREE_VALUE (link);
18763 add_name_attribute (enum_die,
18764 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18766 if (TREE_CODE (value) == CONST_DECL)
18767 value = DECL_INITIAL (value);
18769 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18770 /* DWARF2 does not provide a way of indicating whether or
18771 not enumeration constants are signed or unsigned. GDB
18772 always assumes the values are signed, so we output all
18773 values as if they were signed. That means that
18774 enumeration constants with very large unsigned values
18775 will appear to have negative values in the debugger. */
18776 add_AT_int (enum_die, DW_AT_const_value,
18777 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18781 add_AT_flag (type_die, DW_AT_declaration, 1);
18783 if (get_AT (type_die, DW_AT_name))
18784 add_pubtype (type, type_die);
18789 /* Generate a DIE to represent either a real live formal parameter decl or to
18790 represent just the type of some formal parameter position in some function
18793 Note that this routine is a bit unusual because its argument may be a
18794 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18795 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18796 node. If it's the former then this function is being called to output a
18797 DIE to represent a formal parameter object (or some inlining thereof). If
18798 it's the latter, then this function is only being called to output a
18799 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18800 argument type of some subprogram type.
18801 If EMIT_NAME_P is true, name and source coordinate attributes
18805 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18806 dw_die_ref context_die)
18808 tree node_or_origin = node ? node : origin;
18809 tree ultimate_origin;
18810 dw_die_ref parm_die
18811 = new_die (DW_TAG_formal_parameter, context_die, node);
18813 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18815 case tcc_declaration:
18816 ultimate_origin = decl_ultimate_origin (node_or_origin);
18817 if (node || ultimate_origin)
18818 origin = ultimate_origin;
18819 if (origin != NULL)
18820 add_abstract_origin_attribute (parm_die, origin);
18821 else if (emit_name_p)
18822 add_name_and_src_coords_attributes (parm_die, node);
18824 || (! DECL_ABSTRACT (node_or_origin)
18825 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18826 decl_function_context
18827 (node_or_origin))))
18829 tree type = TREE_TYPE (node_or_origin);
18830 if (decl_by_reference_p (node_or_origin))
18831 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18834 add_type_attribute (parm_die, type,
18835 TREE_READONLY (node_or_origin),
18836 TREE_THIS_VOLATILE (node_or_origin),
18839 if (origin == NULL && DECL_ARTIFICIAL (node))
18840 add_AT_flag (parm_die, DW_AT_artificial, 1);
18842 if (node && node != origin)
18843 equate_decl_number_to_die (node, parm_die);
18844 if (! DECL_ABSTRACT (node_or_origin))
18845 add_location_or_const_value_attribute (parm_die, node_or_origin,
18846 node == NULL, DW_AT_location);
18851 /* We were called with some kind of a ..._TYPE node. */
18852 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18856 gcc_unreachable ();
18862 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18863 children DW_TAG_formal_parameter DIEs representing the arguments of the
18866 PARM_PACK must be a function parameter pack.
18867 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18868 must point to the subsequent arguments of the function PACK_ARG belongs to.
18869 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18870 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18871 following the last one for which a DIE was generated. */
18874 gen_formal_parameter_pack_die (tree parm_pack,
18876 dw_die_ref subr_die,
18880 dw_die_ref parm_pack_die;
18882 gcc_assert (parm_pack
18883 && lang_hooks.function_parameter_pack_p (parm_pack)
18886 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18887 add_src_coords_attributes (parm_pack_die, parm_pack);
18889 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18891 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18894 gen_formal_parameter_die (arg, NULL,
18895 false /* Don't emit name attribute. */,
18900 return parm_pack_die;
18903 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18904 at the end of an (ANSI prototyped) formal parameters list. */
18907 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18909 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18912 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18913 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18914 parameters as specified in some function type specification (except for
18915 those which appear as part of a function *definition*). */
18918 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18921 tree formal_type = NULL;
18922 tree first_parm_type;
18925 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18927 arg = DECL_ARGUMENTS (function_or_method_type);
18928 function_or_method_type = TREE_TYPE (function_or_method_type);
18933 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18935 /* Make our first pass over the list of formal parameter types and output a
18936 DW_TAG_formal_parameter DIE for each one. */
18937 for (link = first_parm_type; link; )
18939 dw_die_ref parm_die;
18941 formal_type = TREE_VALUE (link);
18942 if (formal_type == void_type_node)
18945 /* Output a (nameless) DIE to represent the formal parameter itself. */
18946 parm_die = gen_formal_parameter_die (formal_type, NULL,
18947 true /* Emit name attribute. */,
18949 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18950 && link == first_parm_type)
18952 add_AT_flag (parm_die, DW_AT_artificial, 1);
18953 if (dwarf_version >= 3 || !dwarf_strict)
18954 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18956 else if (arg && DECL_ARTIFICIAL (arg))
18957 add_AT_flag (parm_die, DW_AT_artificial, 1);
18959 link = TREE_CHAIN (link);
18961 arg = DECL_CHAIN (arg);
18964 /* If this function type has an ellipsis, add a
18965 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18966 if (formal_type != void_type_node)
18967 gen_unspecified_parameters_die (function_or_method_type, context_die);
18969 /* Make our second (and final) pass over the list of formal parameter types
18970 and output DIEs to represent those types (as necessary). */
18971 for (link = TYPE_ARG_TYPES (function_or_method_type);
18972 link && TREE_VALUE (link);
18973 link = TREE_CHAIN (link))
18974 gen_type_die (TREE_VALUE (link), context_die);
18977 /* We want to generate the DIE for TYPE so that we can generate the
18978 die for MEMBER, which has been defined; we will need to refer back
18979 to the member declaration nested within TYPE. If we're trying to
18980 generate minimal debug info for TYPE, processing TYPE won't do the
18981 trick; we need to attach the member declaration by hand. */
18984 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18986 gen_type_die (type, context_die);
18988 /* If we're trying to avoid duplicate debug info, we may not have
18989 emitted the member decl for this function. Emit it now. */
18990 if (TYPE_STUB_DECL (type)
18991 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18992 && ! lookup_decl_die (member))
18994 dw_die_ref type_die;
18995 gcc_assert (!decl_ultimate_origin (member));
18997 push_decl_scope (type);
18998 type_die = lookup_type_die_strip_naming_typedef (type);
18999 if (TREE_CODE (member) == FUNCTION_DECL)
19000 gen_subprogram_die (member, type_die);
19001 else if (TREE_CODE (member) == FIELD_DECL)
19003 /* Ignore the nameless fields that are used to skip bits but handle
19004 C++ anonymous unions and structs. */
19005 if (DECL_NAME (member) != NULL_TREE
19006 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
19007 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
19009 gen_type_die (member_declared_type (member), type_die);
19010 gen_field_die (member, type_die);
19014 gen_variable_die (member, NULL_TREE, type_die);
19020 /* Generate the DWARF2 info for the "abstract" instance of a function which we
19021 may later generate inlined and/or out-of-line instances of. */
19024 dwarf2out_abstract_function (tree decl)
19026 dw_die_ref old_die;
19030 htab_t old_decl_loc_table;
19031 htab_t old_cached_dw_loc_list_table;
19033 /* Make sure we have the actual abstract inline, not a clone. */
19034 decl = DECL_ORIGIN (decl);
19036 old_die = lookup_decl_die (decl);
19037 if (old_die && get_AT (old_die, DW_AT_inline))
19038 /* We've already generated the abstract instance. */
19041 /* We can be called while recursively when seeing block defining inlined subroutine
19042 DIE. Be sure to not clobber the outer location table nor use it or we would
19043 get locations in abstract instantces. */
19044 old_decl_loc_table = decl_loc_table;
19045 decl_loc_table = NULL;
19046 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
19047 cached_dw_loc_list_table = NULL;
19049 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
19050 we don't get confused by DECL_ABSTRACT. */
19051 if (debug_info_level > DINFO_LEVEL_TERSE)
19053 context = decl_class_context (decl);
19055 gen_type_die_for_member
19056 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
19059 /* Pretend we've just finished compiling this function. */
19060 save_fn = current_function_decl;
19061 current_function_decl = decl;
19062 push_cfun (DECL_STRUCT_FUNCTION (decl));
19064 was_abstract = DECL_ABSTRACT (decl);
19065 set_decl_abstract_flags (decl, 1);
19066 dwarf2out_decl (decl);
19067 if (! was_abstract)
19068 set_decl_abstract_flags (decl, 0);
19070 current_function_decl = save_fn;
19071 decl_loc_table = old_decl_loc_table;
19072 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
19076 /* Helper function of premark_used_types() which gets called through
19079 Marks the DIE of a given type in *SLOT as perennial, so it never gets
19080 marked as unused by prune_unused_types. */
19083 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
19088 type = (tree) *slot;
19089 die = lookup_type_die (type);
19091 die->die_perennial_p = 1;
19095 /* Helper function of premark_types_used_by_global_vars which gets called
19096 through htab_traverse.
19098 Marks the DIE of a given type in *SLOT as perennial, so it never gets
19099 marked as unused by prune_unused_types. The DIE of the type is marked
19100 only if the global variable using the type will actually be emitted. */
19103 premark_types_used_by_global_vars_helper (void **slot,
19104 void *data ATTRIBUTE_UNUSED)
19106 struct types_used_by_vars_entry *entry;
19109 entry = (struct types_used_by_vars_entry *) *slot;
19110 gcc_assert (entry->type != NULL
19111 && entry->var_decl != NULL);
19112 die = lookup_type_die (entry->type);
19115 /* Ask cgraph if the global variable really is to be emitted.
19116 If yes, then we'll keep the DIE of ENTRY->TYPE. */
19117 struct varpool_node *node = varpool_get_node (entry->var_decl);
19118 if (node && node->needed)
19120 die->die_perennial_p = 1;
19121 /* Keep the parent DIEs as well. */
19122 while ((die = die->die_parent) && die->die_perennial_p == 0)
19123 die->die_perennial_p = 1;
19129 /* Mark all members of used_types_hash as perennial. */
19132 premark_used_types (void)
19134 if (cfun && cfun->used_types_hash)
19135 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
19138 /* Mark all members of types_used_by_vars_entry as perennial. */
19141 premark_types_used_by_global_vars (void)
19143 if (types_used_by_vars_hash)
19144 htab_traverse (types_used_by_vars_hash,
19145 premark_types_used_by_global_vars_helper, NULL);
19148 /* Generate a DIE to represent a declared function (either file-scope or
19152 gen_subprogram_die (tree decl, dw_die_ref context_die)
19154 tree origin = decl_ultimate_origin (decl);
19155 dw_die_ref subr_die;
19157 dw_die_ref old_die = lookup_decl_die (decl);
19158 int declaration = (current_function_decl != decl
19159 || class_or_namespace_scope_p (context_die));
19161 premark_used_types ();
19163 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
19164 started to generate the abstract instance of an inline, decided to output
19165 its containing class, and proceeded to emit the declaration of the inline
19166 from the member list for the class. If so, DECLARATION takes priority;
19167 we'll get back to the abstract instance when done with the class. */
19169 /* The class-scope declaration DIE must be the primary DIE. */
19170 if (origin && declaration && class_or_namespace_scope_p (context_die))
19173 gcc_assert (!old_die);
19176 /* Now that the C++ front end lazily declares artificial member fns, we
19177 might need to retrofit the declaration into its class. */
19178 if (!declaration && !origin && !old_die
19179 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
19180 && !class_or_namespace_scope_p (context_die)
19181 && debug_info_level > DINFO_LEVEL_TERSE)
19182 old_die = force_decl_die (decl);
19184 if (origin != NULL)
19186 gcc_assert (!declaration || local_scope_p (context_die));
19188 /* Fixup die_parent for the abstract instance of a nested
19189 inline function. */
19190 if (old_die && old_die->die_parent == NULL)
19191 add_child_die (context_die, old_die);
19193 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19194 add_abstract_origin_attribute (subr_die, origin);
19198 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19199 struct dwarf_file_data * file_index = lookup_filename (s.file);
19201 if (!get_AT_flag (old_die, DW_AT_declaration)
19202 /* We can have a normal definition following an inline one in the
19203 case of redefinition of GNU C extern inlines.
19204 It seems reasonable to use AT_specification in this case. */
19205 && !get_AT (old_die, DW_AT_inline))
19207 /* Detect and ignore this case, where we are trying to output
19208 something we have already output. */
19212 /* If the definition comes from the same place as the declaration,
19213 maybe use the old DIE. We always want the DIE for this function
19214 that has the *_pc attributes to be under comp_unit_die so the
19215 debugger can find it. We also need to do this for abstract
19216 instances of inlines, since the spec requires the out-of-line copy
19217 to have the same parent. For local class methods, this doesn't
19218 apply; we just use the old DIE. */
19219 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
19220 && (DECL_ARTIFICIAL (decl)
19221 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
19222 && (get_AT_unsigned (old_die, DW_AT_decl_line)
19223 == (unsigned) s.line))))
19225 subr_die = old_die;
19227 /* Clear out the declaration attribute and the formal parameters.
19228 Do not remove all children, because it is possible that this
19229 declaration die was forced using force_decl_die(). In such
19230 cases die that forced declaration die (e.g. TAG_imported_module)
19231 is one of the children that we do not want to remove. */
19232 remove_AT (subr_die, DW_AT_declaration);
19233 remove_AT (subr_die, DW_AT_object_pointer);
19234 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
19238 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19239 add_AT_specification (subr_die, old_die);
19240 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19241 add_AT_file (subr_die, DW_AT_decl_file, file_index);
19242 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19243 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
19248 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19250 if (TREE_PUBLIC (decl))
19251 add_AT_flag (subr_die, DW_AT_external, 1);
19253 add_name_and_src_coords_attributes (subr_die, decl);
19254 if (debug_info_level > DINFO_LEVEL_TERSE)
19256 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
19257 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
19258 0, 0, context_die);
19261 add_pure_or_virtual_attribute (subr_die, decl);
19262 if (DECL_ARTIFICIAL (decl))
19263 add_AT_flag (subr_die, DW_AT_artificial, 1);
19265 add_accessibility_attribute (subr_die, decl);
19270 if (!old_die || !get_AT (old_die, DW_AT_inline))
19272 add_AT_flag (subr_die, DW_AT_declaration, 1);
19274 /* If this is an explicit function declaration then generate
19275 a DW_AT_explicit attribute. */
19276 if (lang_hooks.decls.function_decl_explicit_p (decl)
19277 && (dwarf_version >= 3 || !dwarf_strict))
19278 add_AT_flag (subr_die, DW_AT_explicit, 1);
19280 /* The first time we see a member function, it is in the context of
19281 the class to which it belongs. We make sure of this by emitting
19282 the class first. The next time is the definition, which is
19283 handled above. The two may come from the same source text.
19285 Note that force_decl_die() forces function declaration die. It is
19286 later reused to represent definition. */
19287 equate_decl_number_to_die (decl, subr_die);
19290 else if (DECL_ABSTRACT (decl))
19292 if (DECL_DECLARED_INLINE_P (decl))
19294 if (cgraph_function_possibly_inlined_p (decl))
19295 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19297 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19301 if (cgraph_function_possibly_inlined_p (decl))
19302 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19304 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19307 if (DECL_DECLARED_INLINE_P (decl)
19308 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19309 add_AT_flag (subr_die, DW_AT_artificial, 1);
19311 equate_decl_number_to_die (decl, subr_die);
19313 else if (!DECL_EXTERNAL (decl))
19315 HOST_WIDE_INT cfa_fb_offset;
19317 if (!old_die || !get_AT (old_die, DW_AT_inline))
19318 equate_decl_number_to_die (decl, subr_die);
19320 if (!flag_reorder_blocks_and_partition)
19322 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19323 if (fde->dw_fde_begin)
19325 /* We have already generated the labels. */
19326 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19327 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19331 /* Create start/end labels and add the range. */
19332 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
19333 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19334 current_function_funcdef_no);
19335 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19336 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19337 current_function_funcdef_no);
19338 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19341 #if VMS_DEBUGGING_INFO
19342 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19343 Section 2.3 Prologue and Epilogue Attributes:
19344 When a breakpoint is set on entry to a function, it is generally
19345 desirable for execution to be suspended, not on the very first
19346 instruction of the function, but rather at a point after the
19347 function's frame has been set up, after any language defined local
19348 declaration processing has been completed, and before execution of
19349 the first statement of the function begins. Debuggers generally
19350 cannot properly determine where this point is. Similarly for a
19351 breakpoint set on exit from a function. The prologue and epilogue
19352 attributes allow a compiler to communicate the location(s) to use. */
19355 if (fde->dw_fde_vms_end_prologue)
19356 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19357 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19359 if (fde->dw_fde_vms_begin_epilogue)
19360 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19361 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19365 add_pubname (decl, subr_die);
19368 { /* Generate pubnames entries for the split function code
19370 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19372 if (fde->dw_fde_second_begin)
19374 if (dwarf_version >= 3 || !dwarf_strict)
19376 /* We should use ranges for non-contiguous code section
19377 addresses. Use the actual code range for the initial
19378 section, since the HOT/COLD labels might precede an
19379 alignment offset. */
19380 bool range_list_added = false;
19381 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
19382 fde->dw_fde_end, &range_list_added);
19383 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
19384 fde->dw_fde_second_end,
19385 &range_list_added);
19386 add_pubname (decl, subr_die);
19387 if (range_list_added)
19392 /* There is no real support in DW2 for this .. so we make
19393 a work-around. First, emit the pub name for the segment
19394 containing the function label. Then make and emit a
19395 simplified subprogram DIE for the second segment with the
19396 name pre-fixed by __hot/cold_sect_of_. We use the same
19397 linkage name for the second die so that gdb will find both
19398 sections when given "b foo". */
19399 const char *name = NULL;
19400 tree decl_name = DECL_NAME (decl);
19401 dw_die_ref seg_die;
19403 /* Do the 'primary' section. */
19404 add_AT_lbl_id (subr_die, DW_AT_low_pc,
19405 fde->dw_fde_begin);
19406 add_AT_lbl_id (subr_die, DW_AT_high_pc,
19409 add_pubname (decl, subr_die);
19411 /* Build a minimal DIE for the secondary section. */
19412 seg_die = new_die (DW_TAG_subprogram,
19413 subr_die->die_parent, decl);
19415 if (TREE_PUBLIC (decl))
19416 add_AT_flag (seg_die, DW_AT_external, 1);
19418 if (decl_name != NULL
19419 && IDENTIFIER_POINTER (decl_name) != NULL)
19421 name = dwarf2_name (decl, 1);
19422 if (! DECL_ARTIFICIAL (decl))
19423 add_src_coords_attributes (seg_die, decl);
19425 add_linkage_name (seg_die, decl);
19427 gcc_assert (name != NULL);
19428 add_pure_or_virtual_attribute (seg_die, decl);
19429 if (DECL_ARTIFICIAL (decl))
19430 add_AT_flag (seg_die, DW_AT_artificial, 1);
19432 name = concat ("__second_sect_of_", name, NULL);
19433 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19434 fde->dw_fde_second_begin);
19435 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19436 fde->dw_fde_second_end);
19437 add_name_attribute (seg_die, name);
19438 add_pubname_string (name, seg_die);
19443 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19444 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19445 add_pubname (decl, subr_die);
19449 #ifdef MIPS_DEBUGGING_INFO
19450 /* Add a reference to the FDE for this routine. */
19451 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19454 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19456 /* We define the "frame base" as the function's CFA. This is more
19457 convenient for several reasons: (1) It's stable across the prologue
19458 and epilogue, which makes it better than just a frame pointer,
19459 (2) With dwarf3, there exists a one-byte encoding that allows us
19460 to reference the .debug_frame data by proxy, but failing that,
19461 (3) We can at least reuse the code inspection and interpretation
19462 code that determines the CFA position at various points in the
19464 if (dwarf_version >= 3)
19466 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19467 add_AT_loc (subr_die, DW_AT_frame_base, op);
19471 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19472 if (list->dw_loc_next)
19473 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19475 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19478 /* Compute a displacement from the "steady-state frame pointer" to
19479 the CFA. The former is what all stack slots and argument slots
19480 will reference in the rtl; the later is what we've told the
19481 debugger about. We'll need to adjust all frame_base references
19482 by this displacement. */
19483 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19485 if (cfun->static_chain_decl)
19486 add_AT_location_description (subr_die, DW_AT_static_link,
19487 loc_list_from_tree (cfun->static_chain_decl, 2));
19490 /* Generate child dies for template paramaters. */
19491 if (debug_info_level > DINFO_LEVEL_TERSE)
19492 gen_generic_params_dies (decl);
19494 /* Now output descriptions of the arguments for this function. This gets
19495 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19496 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19497 `...' at the end of the formal parameter list. In order to find out if
19498 there was a trailing ellipsis or not, we must instead look at the type
19499 associated with the FUNCTION_DECL. This will be a node of type
19500 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19501 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19502 an ellipsis at the end. */
19504 /* In the case where we are describing a mere function declaration, all we
19505 need to do here (and all we *can* do here) is to describe the *types* of
19506 its formal parameters. */
19507 if (debug_info_level <= DINFO_LEVEL_TERSE)
19509 else if (declaration)
19510 gen_formal_types_die (decl, subr_die);
19513 /* Generate DIEs to represent all known formal parameters. */
19514 tree parm = DECL_ARGUMENTS (decl);
19515 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19516 tree generic_decl_parm = generic_decl
19517 ? DECL_ARGUMENTS (generic_decl)
19520 /* Now we want to walk the list of parameters of the function and
19521 emit their relevant DIEs.
19523 We consider the case of DECL being an instance of a generic function
19524 as well as it being a normal function.
19526 If DECL is an instance of a generic function we walk the
19527 parameters of the generic function declaration _and_ the parameters of
19528 DECL itself. This is useful because we want to emit specific DIEs for
19529 function parameter packs and those are declared as part of the
19530 generic function declaration. In that particular case,
19531 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19532 That DIE has children DIEs representing the set of arguments
19533 of the pack. Note that the set of pack arguments can be empty.
19534 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19537 Otherwise, we just consider the parameters of DECL. */
19538 while (generic_decl_parm || parm)
19540 if (generic_decl_parm
19541 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19542 gen_formal_parameter_pack_die (generic_decl_parm,
19547 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19549 if (parm == DECL_ARGUMENTS (decl)
19550 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19552 && (dwarf_version >= 3 || !dwarf_strict))
19553 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19555 parm = DECL_CHAIN (parm);
19558 if (generic_decl_parm)
19559 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19562 /* Decide whether we need an unspecified_parameters DIE at the end.
19563 There are 2 more cases to do this for: 1) the ansi ... declaration -
19564 this is detectable when the end of the arg list is not a
19565 void_type_node 2) an unprototyped function declaration (not a
19566 definition). This just means that we have no info about the
19567 parameters at all. */
19568 if (prototype_p (TREE_TYPE (decl)))
19570 /* This is the prototyped case, check for.... */
19571 if (stdarg_p (TREE_TYPE (decl)))
19572 gen_unspecified_parameters_die (decl, subr_die);
19574 else if (DECL_INITIAL (decl) == NULL_TREE)
19575 gen_unspecified_parameters_die (decl, subr_die);
19578 /* Output Dwarf info for all of the stuff within the body of the function
19579 (if it has one - it may be just a declaration). */
19580 outer_scope = DECL_INITIAL (decl);
19582 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19583 a function. This BLOCK actually represents the outermost binding contour
19584 for the function, i.e. the contour in which the function's formal
19585 parameters and labels get declared. Curiously, it appears that the front
19586 end doesn't actually put the PARM_DECL nodes for the current function onto
19587 the BLOCK_VARS list for this outer scope, but are strung off of the
19588 DECL_ARGUMENTS list for the function instead.
19590 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19591 the LABEL_DECL nodes for the function however, and we output DWARF info
19592 for those in decls_for_scope. Just within the `outer_scope' there will be
19593 a BLOCK node representing the function's outermost pair of curly braces,
19594 and any blocks used for the base and member initializers of a C++
19595 constructor function. */
19596 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19598 /* Emit a DW_TAG_variable DIE for a named return value. */
19599 if (DECL_NAME (DECL_RESULT (decl)))
19600 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19602 current_function_has_inlines = 0;
19603 decls_for_scope (outer_scope, subr_die, 0);
19605 /* Add the calling convention attribute if requested. */
19606 add_calling_convention_attribute (subr_die, decl);
19610 /* Returns a hash value for X (which really is a die_struct). */
19613 common_block_die_table_hash (const void *x)
19615 const_dw_die_ref d = (const_dw_die_ref) x;
19616 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19619 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19620 as decl_id and die_parent of die_struct Y. */
19623 common_block_die_table_eq (const void *x, const void *y)
19625 const_dw_die_ref d = (const_dw_die_ref) x;
19626 const_dw_die_ref e = (const_dw_die_ref) y;
19627 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19630 /* Generate a DIE to represent a declared data object.
19631 Either DECL or ORIGIN must be non-null. */
19634 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19638 tree decl_or_origin = decl ? decl : origin;
19639 tree ultimate_origin;
19640 dw_die_ref var_die;
19641 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19642 dw_die_ref origin_die;
19643 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19644 || class_or_namespace_scope_p (context_die));
19645 bool specialization_p = false;
19647 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19648 if (decl || ultimate_origin)
19649 origin = ultimate_origin;
19650 com_decl = fortran_common (decl_or_origin, &off);
19652 /* Symbol in common gets emitted as a child of the common block, in the form
19653 of a data member. */
19656 dw_die_ref com_die;
19657 dw_loc_list_ref loc;
19658 die_node com_die_arg;
19660 var_die = lookup_decl_die (decl_or_origin);
19663 if (get_AT (var_die, DW_AT_location) == NULL)
19665 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19670 /* Optimize the common case. */
19671 if (single_element_loc_list_p (loc)
19672 && loc->expr->dw_loc_opc == DW_OP_addr
19673 && loc->expr->dw_loc_next == NULL
19674 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19676 loc->expr->dw_loc_oprnd1.v.val_addr
19677 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19679 loc_list_plus_const (loc, off);
19681 add_AT_location_description (var_die, DW_AT_location, loc);
19682 remove_AT (var_die, DW_AT_declaration);
19688 if (common_block_die_table == NULL)
19689 common_block_die_table
19690 = htab_create_ggc (10, common_block_die_table_hash,
19691 common_block_die_table_eq, NULL);
19693 com_die_arg.decl_id = DECL_UID (com_decl);
19694 com_die_arg.die_parent = context_die;
19695 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19696 loc = loc_list_from_tree (com_decl, 2);
19697 if (com_die == NULL)
19700 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19703 com_die = new_die (DW_TAG_common_block, context_die, decl);
19704 add_name_and_src_coords_attributes (com_die, com_decl);
19707 add_AT_location_description (com_die, DW_AT_location, loc);
19708 /* Avoid sharing the same loc descriptor between
19709 DW_TAG_common_block and DW_TAG_variable. */
19710 loc = loc_list_from_tree (com_decl, 2);
19712 else if (DECL_EXTERNAL (decl))
19713 add_AT_flag (com_die, DW_AT_declaration, 1);
19714 add_pubname_string (cnam, com_die); /* ??? needed? */
19715 com_die->decl_id = DECL_UID (com_decl);
19716 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19717 *slot = (void *) com_die;
19719 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19721 add_AT_location_description (com_die, DW_AT_location, loc);
19722 loc = loc_list_from_tree (com_decl, 2);
19723 remove_AT (com_die, DW_AT_declaration);
19725 var_die = new_die (DW_TAG_variable, com_die, decl);
19726 add_name_and_src_coords_attributes (var_die, decl);
19727 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19728 TREE_THIS_VOLATILE (decl), context_die);
19729 add_AT_flag (var_die, DW_AT_external, 1);
19734 /* Optimize the common case. */
19735 if (single_element_loc_list_p (loc)
19736 && loc->expr->dw_loc_opc == DW_OP_addr
19737 && loc->expr->dw_loc_next == NULL
19738 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19739 loc->expr->dw_loc_oprnd1.v.val_addr
19740 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19742 loc_list_plus_const (loc, off);
19744 add_AT_location_description (var_die, DW_AT_location, loc);
19746 else if (DECL_EXTERNAL (decl))
19747 add_AT_flag (var_die, DW_AT_declaration, 1);
19748 equate_decl_number_to_die (decl, var_die);
19752 /* If the compiler emitted a definition for the DECL declaration
19753 and if we already emitted a DIE for it, don't emit a second
19754 DIE for it again. Allow re-declarations of DECLs that are
19755 inside functions, though. */
19756 if (old_die && declaration && !local_scope_p (context_die))
19759 /* For static data members, the declaration in the class is supposed
19760 to have DW_TAG_member tag; the specification should still be
19761 DW_TAG_variable referencing the DW_TAG_member DIE. */
19762 if (declaration && class_scope_p (context_die))
19763 var_die = new_die (DW_TAG_member, context_die, decl);
19765 var_die = new_die (DW_TAG_variable, context_die, decl);
19768 if (origin != NULL)
19769 origin_die = add_abstract_origin_attribute (var_die, origin);
19771 /* Loop unrolling can create multiple blocks that refer to the same
19772 static variable, so we must test for the DW_AT_declaration flag.
19774 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19775 copy decls and set the DECL_ABSTRACT flag on them instead of
19778 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19780 ??? The declare_in_namespace support causes us to get two DIEs for one
19781 variable, both of which are declarations. We want to avoid considering
19782 one to be a specification, so we must test that this DIE is not a
19784 else if (old_die && TREE_STATIC (decl) && ! declaration
19785 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19787 /* This is a definition of a C++ class level static. */
19788 add_AT_specification (var_die, old_die);
19789 specialization_p = true;
19790 if (DECL_NAME (decl))
19792 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19793 struct dwarf_file_data * file_index = lookup_filename (s.file);
19795 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19796 add_AT_file (var_die, DW_AT_decl_file, file_index);
19798 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19799 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19801 if (old_die->die_tag == DW_TAG_member)
19802 add_linkage_name (var_die, decl);
19806 add_name_and_src_coords_attributes (var_die, decl);
19808 if ((origin == NULL && !specialization_p)
19810 && !DECL_ABSTRACT (decl_or_origin)
19811 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19812 decl_function_context
19813 (decl_or_origin))))
19815 tree type = TREE_TYPE (decl_or_origin);
19817 if (decl_by_reference_p (decl_or_origin))
19818 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19820 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19821 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19824 if (origin == NULL && !specialization_p)
19826 if (TREE_PUBLIC (decl))
19827 add_AT_flag (var_die, DW_AT_external, 1);
19829 if (DECL_ARTIFICIAL (decl))
19830 add_AT_flag (var_die, DW_AT_artificial, 1);
19832 add_accessibility_attribute (var_die, decl);
19836 add_AT_flag (var_die, DW_AT_declaration, 1);
19838 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19839 equate_decl_number_to_die (decl, var_die);
19842 && (! DECL_ABSTRACT (decl_or_origin)
19843 /* Local static vars are shared between all clones/inlines,
19844 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19846 || (TREE_CODE (decl_or_origin) == VAR_DECL
19847 && TREE_STATIC (decl_or_origin)
19848 && DECL_RTL_SET_P (decl_or_origin)))
19849 /* When abstract origin already has DW_AT_location attribute, no need
19850 to add it again. */
19851 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19853 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19854 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19855 defer_location (decl_or_origin, var_die);
19857 add_location_or_const_value_attribute (var_die, decl_or_origin,
19858 decl == NULL, DW_AT_location);
19859 add_pubname (decl_or_origin, var_die);
19862 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19865 /* Generate a DIE to represent a named constant. */
19868 gen_const_die (tree decl, dw_die_ref context_die)
19870 dw_die_ref const_die;
19871 tree type = TREE_TYPE (decl);
19873 const_die = new_die (DW_TAG_constant, context_die, decl);
19874 add_name_and_src_coords_attributes (const_die, decl);
19875 add_type_attribute (const_die, type, 1, 0, context_die);
19876 if (TREE_PUBLIC (decl))
19877 add_AT_flag (const_die, DW_AT_external, 1);
19878 if (DECL_ARTIFICIAL (decl))
19879 add_AT_flag (const_die, DW_AT_artificial, 1);
19880 tree_add_const_value_attribute_for_decl (const_die, decl);
19883 /* Generate a DIE to represent a label identifier. */
19886 gen_label_die (tree decl, dw_die_ref context_die)
19888 tree origin = decl_ultimate_origin (decl);
19889 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19891 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19893 if (origin != NULL)
19894 add_abstract_origin_attribute (lbl_die, origin);
19896 add_name_and_src_coords_attributes (lbl_die, decl);
19898 if (DECL_ABSTRACT (decl))
19899 equate_decl_number_to_die (decl, lbl_die);
19902 insn = DECL_RTL_IF_SET (decl);
19904 /* Deleted labels are programmer specified labels which have been
19905 eliminated because of various optimizations. We still emit them
19906 here so that it is possible to put breakpoints on them. */
19910 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19912 /* When optimization is enabled (via -O) some parts of the compiler
19913 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19914 represent source-level labels which were explicitly declared by
19915 the user. This really shouldn't be happening though, so catch
19916 it if it ever does happen. */
19917 gcc_assert (!INSN_DELETED_P (insn));
19919 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19920 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19925 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19926 attributes to the DIE for a block STMT, to describe where the inlined
19927 function was called from. This is similar to add_src_coords_attributes. */
19930 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19932 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19934 if (dwarf_version >= 3 || !dwarf_strict)
19936 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19937 add_AT_unsigned (die, DW_AT_call_line, s.line);
19942 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19943 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19946 add_high_low_attributes (tree stmt, dw_die_ref die)
19948 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19950 if (BLOCK_FRAGMENT_CHAIN (stmt)
19951 && (dwarf_version >= 3 || !dwarf_strict))
19955 if (inlined_function_outer_scope_p (stmt))
19957 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19958 BLOCK_NUMBER (stmt));
19959 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19962 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19964 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19967 add_ranges (chain);
19968 chain = BLOCK_FRAGMENT_CHAIN (chain);
19975 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19976 BLOCK_NUMBER (stmt));
19977 add_AT_lbl_id (die, DW_AT_low_pc, label);
19978 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
19979 BLOCK_NUMBER (stmt));
19980 add_AT_lbl_id (die, DW_AT_high_pc, label);
19984 /* Generate a DIE for a lexical block. */
19987 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
19989 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19991 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19992 add_high_low_attributes (stmt, stmt_die);
19994 decls_for_scope (stmt, stmt_die, depth);
19997 /* Generate a DIE for an inlined subprogram. */
20000 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
20004 /* The instance of function that is effectively being inlined shall not
20006 gcc_assert (! BLOCK_ABSTRACT (stmt));
20008 decl = block_ultimate_origin (stmt);
20010 /* Emit info for the abstract instance first, if we haven't yet. We
20011 must emit this even if the block is abstract, otherwise when we
20012 emit the block below (or elsewhere), we may end up trying to emit
20013 a die whose origin die hasn't been emitted, and crashing. */
20014 dwarf2out_abstract_function (decl);
20016 if (! BLOCK_ABSTRACT (stmt))
20018 dw_die_ref subr_die
20019 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
20021 add_abstract_origin_attribute (subr_die, decl);
20022 if (TREE_ASM_WRITTEN (stmt))
20023 add_high_low_attributes (stmt, subr_die);
20024 add_call_src_coords_attributes (stmt, subr_die);
20026 decls_for_scope (stmt, subr_die, depth);
20027 current_function_has_inlines = 1;
20031 /* Generate a DIE for a field in a record, or structure. */
20034 gen_field_die (tree decl, dw_die_ref context_die)
20036 dw_die_ref decl_die;
20038 if (TREE_TYPE (decl) == error_mark_node)
20041 decl_die = new_die (DW_TAG_member, context_die, decl);
20042 add_name_and_src_coords_attributes (decl_die, decl);
20043 add_type_attribute (decl_die, member_declared_type (decl),
20044 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
20047 if (DECL_BIT_FIELD_TYPE (decl))
20049 add_byte_size_attribute (decl_die, decl);
20050 add_bit_size_attribute (decl_die, decl);
20051 add_bit_offset_attribute (decl_die, decl);
20054 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
20055 add_data_member_location_attribute (decl_die, decl);
20057 if (DECL_ARTIFICIAL (decl))
20058 add_AT_flag (decl_die, DW_AT_artificial, 1);
20060 add_accessibility_attribute (decl_die, decl);
20062 /* Equate decl number to die, so that we can look up this decl later on. */
20063 equate_decl_number_to_die (decl, decl_die);
20067 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20068 Use modified_type_die instead.
20069 We keep this code here just in case these types of DIEs may be needed to
20070 represent certain things in other languages (e.g. Pascal) someday. */
20073 gen_pointer_type_die (tree type, dw_die_ref context_die)
20076 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20078 equate_type_number_to_die (type, ptr_die);
20079 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20080 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20083 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20084 Use modified_type_die instead.
20085 We keep this code here just in case these types of DIEs may be needed to
20086 represent certain things in other languages (e.g. Pascal) someday. */
20089 gen_reference_type_die (tree type, dw_die_ref context_die)
20091 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20093 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
20094 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20096 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20098 equate_type_number_to_die (type, ref_die);
20099 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
20100 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20104 /* Generate a DIE for a pointer to a member type. */
20107 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20110 = new_die (DW_TAG_ptr_to_member_type,
20111 scope_die_for (type, context_die), type);
20113 equate_type_number_to_die (type, ptr_die);
20114 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20115 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20116 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20119 /* Generate the DIE for the compilation unit. */
20122 gen_compile_unit_die (const char *filename)
20125 char producer[250];
20126 const char *language_string = lang_hooks.name;
20129 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20133 add_name_attribute (die, filename);
20134 /* Don't add cwd for <built-in>. */
20135 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20136 add_comp_dir_attribute (die);
20139 sprintf (producer, "%s %s", language_string, version_string);
20141 #ifdef MIPS_DEBUGGING_INFO
20142 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20143 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20144 not appear in the producer string, the debugger reaches the conclusion
20145 that the object file is stripped and has no debugging information.
20146 To get the MIPS/SGI debugger to believe that there is debugging
20147 information in the object file, we add a -g to the producer string. */
20148 if (debug_info_level > DINFO_LEVEL_TERSE)
20149 strcat (producer, " -g");
20152 add_AT_string (die, DW_AT_producer, producer);
20154 /* If our producer is LTO try to figure out a common language to use
20155 from the global list of translation units. */
20156 if (strcmp (language_string, "GNU GIMPLE") == 0)
20160 const char *common_lang = NULL;
20162 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
20164 if (!TRANSLATION_UNIT_LANGUAGE (t))
20167 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20168 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20170 else if (strncmp (common_lang, "GNU C", 5) == 0
20171 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20172 /* Mixing C and C++ is ok, use C++ in that case. */
20173 common_lang = "GNU C++";
20176 /* Fall back to C. */
20177 common_lang = NULL;
20183 language_string = common_lang;
20186 language = DW_LANG_C89;
20187 if (strcmp (language_string, "GNU C++") == 0)
20188 language = DW_LANG_C_plus_plus;
20189 else if (strcmp (language_string, "GNU F77") == 0)
20190 language = DW_LANG_Fortran77;
20191 else if (strcmp (language_string, "GNU Pascal") == 0)
20192 language = DW_LANG_Pascal83;
20193 else if (dwarf_version >= 3 || !dwarf_strict)
20195 if (strcmp (language_string, "GNU Ada") == 0)
20196 language = DW_LANG_Ada95;
20197 else if (strcmp (language_string, "GNU Fortran") == 0)
20198 language = DW_LANG_Fortran95;
20199 else if (strcmp (language_string, "GNU Java") == 0)
20200 language = DW_LANG_Java;
20201 else if (strcmp (language_string, "GNU Objective-C") == 0)
20202 language = DW_LANG_ObjC;
20203 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20204 language = DW_LANG_ObjC_plus_plus;
20207 add_AT_unsigned (die, DW_AT_language, language);
20211 case DW_LANG_Fortran77:
20212 case DW_LANG_Fortran90:
20213 case DW_LANG_Fortran95:
20214 /* Fortran has case insensitive identifiers and the front-end
20215 lowercases everything. */
20216 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20219 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20225 /* Generate the DIE for a base class. */
20228 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20230 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20232 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
20233 add_data_member_location_attribute (die, binfo);
20235 if (BINFO_VIRTUAL_P (binfo))
20236 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20238 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20239 children, otherwise the default is DW_ACCESS_public. In DWARF2
20240 the default has always been DW_ACCESS_private. */
20241 if (access == access_public_node)
20243 if (dwarf_version == 2
20244 || context_die->die_tag == DW_TAG_class_type)
20245 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20247 else if (access == access_protected_node)
20248 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20249 else if (dwarf_version > 2
20250 && context_die->die_tag != DW_TAG_class_type)
20251 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20254 /* Generate a DIE for a class member. */
20257 gen_member_die (tree type, dw_die_ref context_die)
20260 tree binfo = TYPE_BINFO (type);
20263 /* If this is not an incomplete type, output descriptions of each of its
20264 members. Note that as we output the DIEs necessary to represent the
20265 members of this record or union type, we will also be trying to output
20266 DIEs to represent the *types* of those members. However the `type'
20267 function (above) will specifically avoid generating type DIEs for member
20268 types *within* the list of member DIEs for this (containing) type except
20269 for those types (of members) which are explicitly marked as also being
20270 members of this (containing) type themselves. The g++ front- end can
20271 force any given type to be treated as a member of some other (containing)
20272 type by setting the TYPE_CONTEXT of the given (member) type to point to
20273 the TREE node representing the appropriate (containing) type. */
20275 /* First output info about the base classes. */
20278 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
20282 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20283 gen_inheritance_die (base,
20284 (accesses ? VEC_index (tree, accesses, i)
20285 : access_public_node), context_die);
20288 /* Now output info about the data members and type members. */
20289 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20291 /* If we thought we were generating minimal debug info for TYPE
20292 and then changed our minds, some of the member declarations
20293 may have already been defined. Don't define them again, but
20294 do put them in the right order. */
20296 child = lookup_decl_die (member);
20298 splice_child_die (context_die, child);
20300 gen_decl_die (member, NULL, context_die);
20303 /* Now output info about the function members (if any). */
20304 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20306 /* Don't include clones in the member list. */
20307 if (DECL_ABSTRACT_ORIGIN (member))
20310 child = lookup_decl_die (member);
20312 splice_child_die (context_die, child);
20314 gen_decl_die (member, NULL, context_die);
20318 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20319 is set, we pretend that the type was never defined, so we only get the
20320 member DIEs needed by later specification DIEs. */
20323 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20324 enum debug_info_usage usage)
20326 dw_die_ref type_die = lookup_type_die (type);
20327 dw_die_ref scope_die = 0;
20329 int complete = (TYPE_SIZE (type)
20330 && (! TYPE_STUB_DECL (type)
20331 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20332 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20333 complete = complete && should_emit_struct_debug (type, usage);
20335 if (type_die && ! complete)
20338 if (TYPE_CONTEXT (type) != NULL_TREE
20339 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20340 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20343 scope_die = scope_die_for (type, context_die);
20345 if (! type_die || (nested && is_cu_die (scope_die)))
20346 /* First occurrence of type or toplevel definition of nested class. */
20348 dw_die_ref old_die = type_die;
20350 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20351 ? record_type_tag (type) : DW_TAG_union_type,
20353 equate_type_number_to_die (type, type_die);
20355 add_AT_specification (type_die, old_die);
20357 add_name_attribute (type_die, type_tag (type));
20360 remove_AT (type_die, DW_AT_declaration);
20362 /* Generate child dies for template paramaters. */
20363 if (debug_info_level > DINFO_LEVEL_TERSE
20364 && COMPLETE_TYPE_P (type))
20365 schedule_generic_params_dies_gen (type);
20367 /* If this type has been completed, then give it a byte_size attribute and
20368 then give a list of members. */
20369 if (complete && !ns_decl)
20371 /* Prevent infinite recursion in cases where the type of some member of
20372 this type is expressed in terms of this type itself. */
20373 TREE_ASM_WRITTEN (type) = 1;
20374 add_byte_size_attribute (type_die, type);
20375 if (TYPE_STUB_DECL (type) != NULL_TREE)
20377 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20378 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20381 /* If the first reference to this type was as the return type of an
20382 inline function, then it may not have a parent. Fix this now. */
20383 if (type_die->die_parent == NULL)
20384 add_child_die (scope_die, type_die);
20386 push_decl_scope (type);
20387 gen_member_die (type, type_die);
20390 /* GNU extension: Record what type our vtable lives in. */
20391 if (TYPE_VFIELD (type))
20393 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20395 gen_type_die (vtype, context_die);
20396 add_AT_die_ref (type_die, DW_AT_containing_type,
20397 lookup_type_die (vtype));
20402 add_AT_flag (type_die, DW_AT_declaration, 1);
20404 /* We don't need to do this for function-local types. */
20405 if (TYPE_STUB_DECL (type)
20406 && ! decl_function_context (TYPE_STUB_DECL (type)))
20407 VEC_safe_push (tree, gc, incomplete_types, type);
20410 if (get_AT (type_die, DW_AT_name))
20411 add_pubtype (type, type_die);
20414 /* Generate a DIE for a subroutine _type_. */
20417 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20419 tree return_type = TREE_TYPE (type);
20420 dw_die_ref subr_die
20421 = new_die (DW_TAG_subroutine_type,
20422 scope_die_for (type, context_die), type);
20424 equate_type_number_to_die (type, subr_die);
20425 add_prototyped_attribute (subr_die, type);
20426 add_type_attribute (subr_die, return_type, 0, 0, context_die);
20427 gen_formal_types_die (type, subr_die);
20429 if (get_AT (subr_die, DW_AT_name))
20430 add_pubtype (type, subr_die);
20433 /* Generate a DIE for a type definition. */
20436 gen_typedef_die (tree decl, dw_die_ref context_die)
20438 dw_die_ref type_die;
20441 if (TREE_ASM_WRITTEN (decl))
20444 TREE_ASM_WRITTEN (decl) = 1;
20445 type_die = new_die (DW_TAG_typedef, context_die, decl);
20446 origin = decl_ultimate_origin (decl);
20447 if (origin != NULL)
20448 add_abstract_origin_attribute (type_die, origin);
20453 add_name_and_src_coords_attributes (type_die, decl);
20454 if (DECL_ORIGINAL_TYPE (decl))
20456 type = DECL_ORIGINAL_TYPE (decl);
20458 gcc_assert (type != TREE_TYPE (decl));
20459 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20463 type = TREE_TYPE (decl);
20465 if (is_naming_typedef_decl (TYPE_NAME (type)))
20467 /* Here, we are in the case of decl being a typedef naming
20468 an anonymous type, e.g:
20469 typedef struct {...} foo;
20470 In that case TREE_TYPE (decl) is not a typedef variant
20471 type and TYPE_NAME of the anonymous type is set to the
20472 TYPE_DECL of the typedef. This construct is emitted by
20475 TYPE is the anonymous struct named by the typedef
20476 DECL. As we need the DW_AT_type attribute of the
20477 DW_TAG_typedef to point to the DIE of TYPE, let's
20478 generate that DIE right away. add_type_attribute
20479 called below will then pick (via lookup_type_die) that
20480 anonymous struct DIE. */
20481 if (!TREE_ASM_WRITTEN (type))
20482 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20484 /* This is a GNU Extension. We are adding a
20485 DW_AT_linkage_name attribute to the DIE of the
20486 anonymous struct TYPE. The value of that attribute
20487 is the name of the typedef decl naming the anonymous
20488 struct. This greatly eases the work of consumers of
20489 this debug info. */
20490 add_linkage_attr (lookup_type_die (type), decl);
20494 add_type_attribute (type_die, type, TREE_READONLY (decl),
20495 TREE_THIS_VOLATILE (decl), context_die);
20497 if (is_naming_typedef_decl (decl))
20498 /* We want that all subsequent calls to lookup_type_die with
20499 TYPE in argument yield the DW_TAG_typedef we have just
20501 equate_type_number_to_die (type, type_die);
20503 add_accessibility_attribute (type_die, decl);
20506 if (DECL_ABSTRACT (decl))
20507 equate_decl_number_to_die (decl, type_die);
20509 if (get_AT (type_die, DW_AT_name))
20510 add_pubtype (decl, type_die);
20513 /* Generate a DIE for a struct, class, enum or union type. */
20516 gen_tagged_type_die (tree type,
20517 dw_die_ref context_die,
20518 enum debug_info_usage usage)
20522 if (type == NULL_TREE
20523 || !is_tagged_type (type))
20526 /* If this is a nested type whose containing class hasn't been written
20527 out yet, writing it out will cover this one, too. This does not apply
20528 to instantiations of member class templates; they need to be added to
20529 the containing class as they are generated. FIXME: This hurts the
20530 idea of combining type decls from multiple TUs, since we can't predict
20531 what set of template instantiations we'll get. */
20532 if (TYPE_CONTEXT (type)
20533 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20534 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20536 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20538 if (TREE_ASM_WRITTEN (type))
20541 /* If that failed, attach ourselves to the stub. */
20542 push_decl_scope (TYPE_CONTEXT (type));
20543 context_die = lookup_type_die (TYPE_CONTEXT (type));
20546 else if (TYPE_CONTEXT (type) != NULL_TREE
20547 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20549 /* If this type is local to a function that hasn't been written
20550 out yet, use a NULL context for now; it will be fixed up in
20551 decls_for_scope. */
20552 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20553 /* A declaration DIE doesn't count; nested types need to go in the
20555 if (context_die && is_declaration_die (context_die))
20556 context_die = NULL;
20561 context_die = declare_in_namespace (type, context_die);
20565 if (TREE_CODE (type) == ENUMERAL_TYPE)
20567 /* This might have been written out by the call to
20568 declare_in_namespace. */
20569 if (!TREE_ASM_WRITTEN (type))
20570 gen_enumeration_type_die (type, context_die);
20573 gen_struct_or_union_type_die (type, context_die, usage);
20578 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20579 it up if it is ever completed. gen_*_type_die will set it for us
20580 when appropriate. */
20583 /* Generate a type description DIE. */
20586 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20587 enum debug_info_usage usage)
20589 struct array_descr_info info;
20591 if (type == NULL_TREE || type == error_mark_node)
20594 if (TYPE_NAME (type) != NULL_TREE
20595 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
20596 && is_redundant_typedef (TYPE_NAME (type))
20597 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
20598 /* The DECL of this type is a typedef we don't want to emit debug
20599 info for but we want debug info for its underlying typedef.
20600 This can happen for e.g, the injected-class-name of a C++
20602 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
20604 /* If TYPE is a typedef type variant, let's generate debug info
20605 for the parent typedef which TYPE is a type of. */
20606 if (typedef_variant_p (type))
20608 if (TREE_ASM_WRITTEN (type))
20611 /* Prevent broken recursion; we can't hand off to the same type. */
20612 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20614 /* Use the DIE of the containing namespace as the parent DIE of
20615 the type description DIE we want to generate. */
20616 if (DECL_CONTEXT (TYPE_NAME (type))
20617 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20618 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20620 TREE_ASM_WRITTEN (type) = 1;
20622 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20626 /* If type is an anonymous tagged type named by a typedef, let's
20627 generate debug info for the typedef. */
20628 if (is_naming_typedef_decl (TYPE_NAME (type)))
20630 /* Use the DIE of the containing namespace as the parent DIE of
20631 the type description DIE we want to generate. */
20632 if (DECL_CONTEXT (TYPE_NAME (type))
20633 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20634 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20636 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20640 /* If this is an array type with hidden descriptor, handle it first. */
20641 if (!TREE_ASM_WRITTEN (type)
20642 && lang_hooks.types.get_array_descr_info
20643 && lang_hooks.types.get_array_descr_info (type, &info)
20644 && (dwarf_version >= 3 || !dwarf_strict))
20646 gen_descr_array_type_die (type, &info, context_die);
20647 TREE_ASM_WRITTEN (type) = 1;
20651 /* We are going to output a DIE to represent the unqualified version
20652 of this type (i.e. without any const or volatile qualifiers) so
20653 get the main variant (i.e. the unqualified version) of this type
20654 now. (Vectors are special because the debugging info is in the
20655 cloned type itself). */
20656 if (TREE_CODE (type) != VECTOR_TYPE)
20657 type = type_main_variant (type);
20659 if (TREE_ASM_WRITTEN (type))
20662 switch (TREE_CODE (type))
20668 case REFERENCE_TYPE:
20669 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20670 ensures that the gen_type_die recursion will terminate even if the
20671 type is recursive. Recursive types are possible in Ada. */
20672 /* ??? We could perhaps do this for all types before the switch
20674 TREE_ASM_WRITTEN (type) = 1;
20676 /* For these types, all that is required is that we output a DIE (or a
20677 set of DIEs) to represent the "basis" type. */
20678 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20679 DINFO_USAGE_IND_USE);
20683 /* This code is used for C++ pointer-to-data-member types.
20684 Output a description of the relevant class type. */
20685 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20686 DINFO_USAGE_IND_USE);
20688 /* Output a description of the type of the object pointed to. */
20689 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20690 DINFO_USAGE_IND_USE);
20692 /* Now output a DIE to represent this pointer-to-data-member type
20694 gen_ptr_to_mbr_type_die (type, context_die);
20697 case FUNCTION_TYPE:
20698 /* Force out return type (in case it wasn't forced out already). */
20699 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20700 DINFO_USAGE_DIR_USE);
20701 gen_subroutine_type_die (type, context_die);
20705 /* Force out return type (in case it wasn't forced out already). */
20706 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20707 DINFO_USAGE_DIR_USE);
20708 gen_subroutine_type_die (type, context_die);
20712 gen_array_type_die (type, context_die);
20716 gen_array_type_die (type, context_die);
20719 case ENUMERAL_TYPE:
20722 case QUAL_UNION_TYPE:
20723 gen_tagged_type_die (type, context_die, usage);
20729 case FIXED_POINT_TYPE:
20732 /* No DIEs needed for fundamental types. */
20737 /* Just use DW_TAG_unspecified_type. */
20739 dw_die_ref type_die = lookup_type_die (type);
20740 if (type_die == NULL)
20742 tree name = TYPE_NAME (type);
20743 if (TREE_CODE (name) == TYPE_DECL)
20744 name = DECL_NAME (name);
20745 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
20746 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20747 equate_type_number_to_die (type, type_die);
20753 gcc_unreachable ();
20756 TREE_ASM_WRITTEN (type) = 1;
20760 gen_type_die (tree type, dw_die_ref context_die)
20762 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20765 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20766 things which are local to the given block. */
20769 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20771 int must_output_die = 0;
20774 /* Ignore blocks that are NULL. */
20775 if (stmt == NULL_TREE)
20778 inlined_func = inlined_function_outer_scope_p (stmt);
20780 /* If the block is one fragment of a non-contiguous block, do not
20781 process the variables, since they will have been done by the
20782 origin block. Do process subblocks. */
20783 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20787 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20788 gen_block_die (sub, context_die, depth + 1);
20793 /* Determine if we need to output any Dwarf DIEs at all to represent this
20796 /* The outer scopes for inlinings *must* always be represented. We
20797 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20798 must_output_die = 1;
20801 /* Determine if this block directly contains any "significant"
20802 local declarations which we will need to output DIEs for. */
20803 if (debug_info_level > DINFO_LEVEL_TERSE)
20804 /* We are not in terse mode so *any* local declaration counts
20805 as being a "significant" one. */
20806 must_output_die = ((BLOCK_VARS (stmt) != NULL
20807 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20808 && (TREE_USED (stmt)
20809 || TREE_ASM_WRITTEN (stmt)
20810 || BLOCK_ABSTRACT (stmt)));
20811 else if ((TREE_USED (stmt)
20812 || TREE_ASM_WRITTEN (stmt)
20813 || BLOCK_ABSTRACT (stmt))
20814 && !dwarf2out_ignore_block (stmt))
20815 must_output_die = 1;
20818 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20819 DIE for any block which contains no significant local declarations at
20820 all. Rather, in such cases we just call `decls_for_scope' so that any
20821 needed Dwarf info for any sub-blocks will get properly generated. Note
20822 that in terse mode, our definition of what constitutes a "significant"
20823 local declaration gets restricted to include only inlined function
20824 instances and local (nested) function definitions. */
20825 if (must_output_die)
20829 /* If STMT block is abstract, that means we have been called
20830 indirectly from dwarf2out_abstract_function.
20831 That function rightfully marks the descendent blocks (of
20832 the abstract function it is dealing with) as being abstract,
20833 precisely to prevent us from emitting any
20834 DW_TAG_inlined_subroutine DIE as a descendent
20835 of an abstract function instance. So in that case, we should
20836 not call gen_inlined_subroutine_die.
20838 Later though, when cgraph asks dwarf2out to emit info
20839 for the concrete instance of the function decl into which
20840 the concrete instance of STMT got inlined, the later will lead
20841 to the generation of a DW_TAG_inlined_subroutine DIE. */
20842 if (! BLOCK_ABSTRACT (stmt))
20843 gen_inlined_subroutine_die (stmt, context_die, depth);
20846 gen_lexical_block_die (stmt, context_die, depth);
20849 decls_for_scope (stmt, context_die, depth);
20852 /* Process variable DECL (or variable with origin ORIGIN) within
20853 block STMT and add it to CONTEXT_DIE. */
20855 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20858 tree decl_or_origin = decl ? decl : origin;
20860 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20861 die = lookup_decl_die (decl_or_origin);
20862 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20863 && TYPE_DECL_IS_STUB (decl_or_origin))
20864 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20868 if (die != NULL && die->die_parent == NULL)
20869 add_child_die (context_die, die);
20870 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20871 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20872 stmt, context_die);
20874 gen_decl_die (decl, origin, context_die);
20877 /* Generate all of the decls declared within a given scope and (recursively)
20878 all of its sub-blocks. */
20881 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20887 /* Ignore NULL blocks. */
20888 if (stmt == NULL_TREE)
20891 /* Output the DIEs to represent all of the data objects and typedefs
20892 declared directly within this block but not within any nested
20893 sub-blocks. Also, nested function and tag DIEs have been
20894 generated with a parent of NULL; fix that up now. */
20895 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20896 process_scope_var (stmt, decl, NULL_TREE, context_die);
20897 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20898 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20901 /* If we're at -g1, we're not interested in subblocks. */
20902 if (debug_info_level <= DINFO_LEVEL_TERSE)
20905 /* Output the DIEs to represent all sub-blocks (and the items declared
20906 therein) of this block. */
20907 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20909 subblocks = BLOCK_CHAIN (subblocks))
20910 gen_block_die (subblocks, context_die, depth + 1);
20913 /* Is this a typedef we can avoid emitting? */
20916 is_redundant_typedef (const_tree decl)
20918 if (TYPE_DECL_IS_STUB (decl))
20921 if (DECL_ARTIFICIAL (decl)
20922 && DECL_CONTEXT (decl)
20923 && is_tagged_type (DECL_CONTEXT (decl))
20924 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20925 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20926 /* Also ignore the artificial member typedef for the class name. */
20932 /* Return TRUE if TYPE is a typedef that names a type for linkage
20933 purposes. This kind of typedefs is produced by the C++ FE for
20936 typedef struct {...} foo;
20938 In that case, there is no typedef variant type produced for foo.
20939 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20943 is_naming_typedef_decl (const_tree decl)
20945 if (decl == NULL_TREE
20946 || TREE_CODE (decl) != TYPE_DECL
20947 || !is_tagged_type (TREE_TYPE (decl))
20948 || DECL_IS_BUILTIN (decl)
20949 || is_redundant_typedef (decl)
20950 /* It looks like Ada produces TYPE_DECLs that are very similar
20951 to C++ naming typedefs but that have different
20952 semantics. Let's be specific to c++ for now. */
20956 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
20957 && TYPE_NAME (TREE_TYPE (decl)) == decl
20958 && (TYPE_STUB_DECL (TREE_TYPE (decl))
20959 != TYPE_NAME (TREE_TYPE (decl))));
20962 /* Returns the DIE for a context. */
20964 static inline dw_die_ref
20965 get_context_die (tree context)
20969 /* Find die that represents this context. */
20970 if (TYPE_P (context))
20972 context = TYPE_MAIN_VARIANT (context);
20973 return strip_naming_typedef (context, force_type_die (context));
20976 return force_decl_die (context);
20978 return comp_unit_die ();
20981 /* Returns the DIE for decl. A DIE will always be returned. */
20984 force_decl_die (tree decl)
20986 dw_die_ref decl_die;
20987 unsigned saved_external_flag;
20988 tree save_fn = NULL_TREE;
20989 decl_die = lookup_decl_die (decl);
20992 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
20994 decl_die = lookup_decl_die (decl);
20998 switch (TREE_CODE (decl))
21000 case FUNCTION_DECL:
21001 /* Clear current_function_decl, so that gen_subprogram_die thinks
21002 that this is a declaration. At this point, we just want to force
21003 declaration die. */
21004 save_fn = current_function_decl;
21005 current_function_decl = NULL_TREE;
21006 gen_subprogram_die (decl, context_die);
21007 current_function_decl = save_fn;
21011 /* Set external flag to force declaration die. Restore it after
21012 gen_decl_die() call. */
21013 saved_external_flag = DECL_EXTERNAL (decl);
21014 DECL_EXTERNAL (decl) = 1;
21015 gen_decl_die (decl, NULL, context_die);
21016 DECL_EXTERNAL (decl) = saved_external_flag;
21019 case NAMESPACE_DECL:
21020 if (dwarf_version >= 3 || !dwarf_strict)
21021 dwarf2out_decl (decl);
21023 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21024 decl_die = comp_unit_die ();
21027 case TRANSLATION_UNIT_DECL:
21028 decl_die = comp_unit_die ();
21032 gcc_unreachable ();
21035 /* We should be able to find the DIE now. */
21037 decl_die = lookup_decl_die (decl);
21038 gcc_assert (decl_die);
21044 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21045 always returned. */
21048 force_type_die (tree type)
21050 dw_die_ref type_die;
21052 type_die = lookup_type_die (type);
21055 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21057 type_die = modified_type_die (type, TYPE_READONLY (type),
21058 TYPE_VOLATILE (type), context_die);
21059 gcc_assert (type_die);
21064 /* Force out any required namespaces to be able to output DECL,
21065 and return the new context_die for it, if it's changed. */
21068 setup_namespace_context (tree thing, dw_die_ref context_die)
21070 tree context = (DECL_P (thing)
21071 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21072 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21073 /* Force out the namespace. */
21074 context_die = force_decl_die (context);
21076 return context_die;
21079 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21080 type) within its namespace, if appropriate.
21082 For compatibility with older debuggers, namespace DIEs only contain
21083 declarations; all definitions are emitted at CU scope. */
21086 declare_in_namespace (tree thing, dw_die_ref context_die)
21088 dw_die_ref ns_context;
21090 if (debug_info_level <= DINFO_LEVEL_TERSE)
21091 return context_die;
21093 /* If this decl is from an inlined function, then don't try to emit it in its
21094 namespace, as we will get confused. It would have already been emitted
21095 when the abstract instance of the inline function was emitted anyways. */
21096 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21097 return context_die;
21099 ns_context = setup_namespace_context (thing, context_die);
21101 if (ns_context != context_die)
21105 if (DECL_P (thing))
21106 gen_decl_die (thing, NULL, ns_context);
21108 gen_type_die (thing, ns_context);
21110 return context_die;
21113 /* Generate a DIE for a namespace or namespace alias. */
21116 gen_namespace_die (tree decl, dw_die_ref context_die)
21118 dw_die_ref namespace_die;
21120 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21121 they are an alias of. */
21122 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21124 /* Output a real namespace or module. */
21125 context_die = setup_namespace_context (decl, comp_unit_die ());
21126 namespace_die = new_die (is_fortran ()
21127 ? DW_TAG_module : DW_TAG_namespace,
21128 context_die, decl);
21129 /* For Fortran modules defined in different CU don't add src coords. */
21130 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21132 const char *name = dwarf2_name (decl, 0);
21134 add_name_attribute (namespace_die, name);
21137 add_name_and_src_coords_attributes (namespace_die, decl);
21138 if (DECL_EXTERNAL (decl))
21139 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21140 equate_decl_number_to_die (decl, namespace_die);
21144 /* Output a namespace alias. */
21146 /* Force out the namespace we are an alias of, if necessary. */
21147 dw_die_ref origin_die
21148 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21150 if (DECL_FILE_SCOPE_P (decl)
21151 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21152 context_die = setup_namespace_context (decl, comp_unit_die ());
21153 /* Now create the namespace alias DIE. */
21154 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21155 add_name_and_src_coords_attributes (namespace_die, decl);
21156 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21157 equate_decl_number_to_die (decl, namespace_die);
21161 /* Generate Dwarf debug information for a decl described by DECL.
21162 The return value is currently only meaningful for PARM_DECLs,
21163 for all other decls it returns NULL. */
21166 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21168 tree decl_or_origin = decl ? decl : origin;
21169 tree class_origin = NULL, ultimate_origin;
21171 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21174 switch (TREE_CODE (decl_or_origin))
21180 if (!is_fortran () && !is_ada ())
21182 /* The individual enumerators of an enum type get output when we output
21183 the Dwarf representation of the relevant enum type itself. */
21187 /* Emit its type. */
21188 gen_type_die (TREE_TYPE (decl), context_die);
21190 /* And its containing namespace. */
21191 context_die = declare_in_namespace (decl, context_die);
21193 gen_const_die (decl, context_die);
21196 case FUNCTION_DECL:
21197 /* Don't output any DIEs to represent mere function declarations,
21198 unless they are class members or explicit block externs. */
21199 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21200 && DECL_FILE_SCOPE_P (decl_or_origin)
21201 && (current_function_decl == NULL_TREE
21202 || DECL_ARTIFICIAL (decl_or_origin)))
21207 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21208 on local redeclarations of global functions. That seems broken. */
21209 if (current_function_decl != decl)
21210 /* This is only a declaration. */;
21213 /* If we're emitting a clone, emit info for the abstract instance. */
21214 if (origin || DECL_ORIGIN (decl) != decl)
21215 dwarf2out_abstract_function (origin
21216 ? DECL_ORIGIN (origin)
21217 : DECL_ABSTRACT_ORIGIN (decl));
21219 /* If we're emitting an out-of-line copy of an inline function,
21220 emit info for the abstract instance and set up to refer to it. */
21221 else if (cgraph_function_possibly_inlined_p (decl)
21222 && ! DECL_ABSTRACT (decl)
21223 && ! class_or_namespace_scope_p (context_die)
21224 /* dwarf2out_abstract_function won't emit a die if this is just
21225 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21226 that case, because that works only if we have a die. */
21227 && DECL_INITIAL (decl) != NULL_TREE)
21229 dwarf2out_abstract_function (decl);
21230 set_decl_origin_self (decl);
21233 /* Otherwise we're emitting the primary DIE for this decl. */
21234 else if (debug_info_level > DINFO_LEVEL_TERSE)
21236 /* Before we describe the FUNCTION_DECL itself, make sure that we
21237 have its containing type. */
21239 origin = decl_class_context (decl);
21240 if (origin != NULL_TREE)
21241 gen_type_die (origin, context_die);
21243 /* And its return type. */
21244 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21246 /* And its virtual context. */
21247 if (DECL_VINDEX (decl) != NULL_TREE)
21248 gen_type_die (DECL_CONTEXT (decl), context_die);
21250 /* Make sure we have a member DIE for decl. */
21251 if (origin != NULL_TREE)
21252 gen_type_die_for_member (origin, decl, context_die);
21254 /* And its containing namespace. */
21255 context_die = declare_in_namespace (decl, context_die);
21258 /* Now output a DIE to represent the function itself. */
21260 gen_subprogram_die (decl, context_die);
21264 /* If we are in terse mode, don't generate any DIEs to represent any
21265 actual typedefs. */
21266 if (debug_info_level <= DINFO_LEVEL_TERSE)
21269 /* In the special case of a TYPE_DECL node representing the declaration
21270 of some type tag, if the given TYPE_DECL is marked as having been
21271 instantiated from some other (original) TYPE_DECL node (e.g. one which
21272 was generated within the original definition of an inline function) we
21273 used to generate a special (abbreviated) DW_TAG_structure_type,
21274 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21275 should be actually referencing those DIEs, as variable DIEs with that
21276 type would be emitted already in the abstract origin, so it was always
21277 removed during unused type prunning. Don't add anything in this
21279 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21282 if (is_redundant_typedef (decl))
21283 gen_type_die (TREE_TYPE (decl), context_die);
21285 /* Output a DIE to represent the typedef itself. */
21286 gen_typedef_die (decl, context_die);
21290 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21291 gen_label_die (decl, context_die);
21296 /* If we are in terse mode, don't generate any DIEs to represent any
21297 variable declarations or definitions. */
21298 if (debug_info_level <= DINFO_LEVEL_TERSE)
21301 /* Output any DIEs that are needed to specify the type of this data
21303 if (decl_by_reference_p (decl_or_origin))
21304 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21306 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21308 /* And its containing type. */
21309 class_origin = decl_class_context (decl_or_origin);
21310 if (class_origin != NULL_TREE)
21311 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21313 /* And its containing namespace. */
21314 context_die = declare_in_namespace (decl_or_origin, context_die);
21316 /* Now output the DIE to represent the data object itself. This gets
21317 complicated because of the possibility that the VAR_DECL really
21318 represents an inlined instance of a formal parameter for an inline
21320 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21321 if (ultimate_origin != NULL_TREE
21322 && TREE_CODE (ultimate_origin) == PARM_DECL)
21323 gen_formal_parameter_die (decl, origin,
21324 true /* Emit name attribute. */,
21327 gen_variable_die (decl, origin, context_die);
21331 /* Ignore the nameless fields that are used to skip bits but handle C++
21332 anonymous unions and structs. */
21333 if (DECL_NAME (decl) != NULL_TREE
21334 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21335 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21337 gen_type_die (member_declared_type (decl), context_die);
21338 gen_field_die (decl, context_die);
21343 if (DECL_BY_REFERENCE (decl_or_origin))
21344 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21346 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21347 return gen_formal_parameter_die (decl, origin,
21348 true /* Emit name attribute. */,
21351 case NAMESPACE_DECL:
21352 case IMPORTED_DECL:
21353 if (dwarf_version >= 3 || !dwarf_strict)
21354 gen_namespace_die (decl, context_die);
21358 /* Probably some frontend-internal decl. Assume we don't care. */
21359 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21366 /* Output debug information for global decl DECL. Called from toplev.c after
21367 compilation proper has finished. */
21370 dwarf2out_global_decl (tree decl)
21372 /* Output DWARF2 information for file-scope tentative data object
21373 declarations, file-scope (extern) function declarations (which
21374 had no corresponding body) and file-scope tagged type declarations
21375 and definitions which have not yet been forced out. */
21376 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
21377 dwarf2out_decl (decl);
21380 /* Output debug information for type decl DECL. Called from toplev.c
21381 and from language front ends (to record built-in types). */
21383 dwarf2out_type_decl (tree decl, int local)
21386 dwarf2out_decl (decl);
21389 /* Output debug information for imported module or decl DECL.
21390 NAME is non-NULL name in the lexical block if the decl has been renamed.
21391 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21392 that DECL belongs to.
21393 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21395 dwarf2out_imported_module_or_decl_1 (tree decl,
21397 tree lexical_block,
21398 dw_die_ref lexical_block_die)
21400 expanded_location xloc;
21401 dw_die_ref imported_die = NULL;
21402 dw_die_ref at_import_die;
21404 if (TREE_CODE (decl) == IMPORTED_DECL)
21406 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21407 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21411 xloc = expand_location (input_location);
21413 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21415 at_import_die = force_type_die (TREE_TYPE (decl));
21416 /* For namespace N { typedef void T; } using N::T; base_type_die
21417 returns NULL, but DW_TAG_imported_declaration requires
21418 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21419 if (!at_import_die)
21421 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21422 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21423 at_import_die = lookup_type_die (TREE_TYPE (decl));
21424 gcc_assert (at_import_die);
21429 at_import_die = lookup_decl_die (decl);
21430 if (!at_import_die)
21432 /* If we're trying to avoid duplicate debug info, we may not have
21433 emitted the member decl for this field. Emit it now. */
21434 if (TREE_CODE (decl) == FIELD_DECL)
21436 tree type = DECL_CONTEXT (decl);
21438 if (TYPE_CONTEXT (type)
21439 && TYPE_P (TYPE_CONTEXT (type))
21440 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21441 DINFO_USAGE_DIR_USE))
21443 gen_type_die_for_member (type, decl,
21444 get_context_die (TYPE_CONTEXT (type)));
21446 at_import_die = force_decl_die (decl);
21450 if (TREE_CODE (decl) == NAMESPACE_DECL)
21452 if (dwarf_version >= 3 || !dwarf_strict)
21453 imported_die = new_die (DW_TAG_imported_module,
21460 imported_die = new_die (DW_TAG_imported_declaration,
21464 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21465 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21467 add_AT_string (imported_die, DW_AT_name,
21468 IDENTIFIER_POINTER (name));
21469 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21472 /* Output debug information for imported module or decl DECL.
21473 NAME is non-NULL name in context if the decl has been renamed.
21474 CHILD is true if decl is one of the renamed decls as part of
21475 importing whole module. */
21478 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21481 /* dw_die_ref at_import_die; */
21482 dw_die_ref scope_die;
21484 if (debug_info_level <= DINFO_LEVEL_TERSE)
21489 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21490 We need decl DIE for reference and scope die. First, get DIE for the decl
21493 /* Get the scope die for decl context. Use comp_unit_die for global module
21494 or decl. If die is not found for non globals, force new die. */
21496 && TYPE_P (context)
21497 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21500 if (!(dwarf_version >= 3 || !dwarf_strict))
21503 scope_die = get_context_die (context);
21507 gcc_assert (scope_die->die_child);
21508 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21509 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21510 scope_die = scope_die->die_child;
21513 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21514 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21518 /* Write the debugging output for DECL. */
21521 dwarf2out_decl (tree decl)
21523 dw_die_ref context_die = comp_unit_die ();
21525 switch (TREE_CODE (decl))
21530 case FUNCTION_DECL:
21531 /* What we would really like to do here is to filter out all mere
21532 file-scope declarations of file-scope functions which are never
21533 referenced later within this translation unit (and keep all of ones
21534 that *are* referenced later on) but we aren't clairvoyant, so we have
21535 no idea which functions will be referenced in the future (i.e. later
21536 on within the current translation unit). So here we just ignore all
21537 file-scope function declarations which are not also definitions. If
21538 and when the debugger needs to know something about these functions,
21539 it will have to hunt around and find the DWARF information associated
21540 with the definition of the function.
21542 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21543 nodes represent definitions and which ones represent mere
21544 declarations. We have to check DECL_INITIAL instead. That's because
21545 the C front-end supports some weird semantics for "extern inline"
21546 function definitions. These can get inlined within the current
21547 translation unit (and thus, we need to generate Dwarf info for their
21548 abstract instances so that the Dwarf info for the concrete inlined
21549 instances can have something to refer to) but the compiler never
21550 generates any out-of-lines instances of such things (despite the fact
21551 that they *are* definitions).
21553 The important point is that the C front-end marks these "extern
21554 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21555 them anyway. Note that the C++ front-end also plays some similar games
21556 for inline function definitions appearing within include files which
21557 also contain `#pragma interface' pragmas. */
21558 if (DECL_INITIAL (decl) == NULL_TREE)
21561 /* If we're a nested function, initially use a parent of NULL; if we're
21562 a plain function, this will be fixed up in decls_for_scope. If
21563 we're a method, it will be ignored, since we already have a DIE. */
21564 if (decl_function_context (decl)
21565 /* But if we're in terse mode, we don't care about scope. */
21566 && debug_info_level > DINFO_LEVEL_TERSE)
21567 context_die = NULL;
21571 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21572 declaration and if the declaration was never even referenced from
21573 within this entire compilation unit. We suppress these DIEs in
21574 order to save space in the .debug section (by eliminating entries
21575 which are probably useless). Note that we must not suppress
21576 block-local extern declarations (whether used or not) because that
21577 would screw-up the debugger's name lookup mechanism and cause it to
21578 miss things which really ought to be in scope at a given point. */
21579 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
21582 /* For local statics lookup proper context die. */
21583 if (TREE_STATIC (decl) && decl_function_context (decl))
21584 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21586 /* If we are in terse mode, don't generate any DIEs to represent any
21587 variable declarations or definitions. */
21588 if (debug_info_level <= DINFO_LEVEL_TERSE)
21593 if (debug_info_level <= DINFO_LEVEL_TERSE)
21595 if (!is_fortran () && !is_ada ())
21597 if (TREE_STATIC (decl) && decl_function_context (decl))
21598 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21601 case NAMESPACE_DECL:
21602 case IMPORTED_DECL:
21603 if (debug_info_level <= DINFO_LEVEL_TERSE)
21605 if (lookup_decl_die (decl) != NULL)
21610 /* Don't emit stubs for types unless they are needed by other DIEs. */
21611 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21614 /* Don't bother trying to generate any DIEs to represent any of the
21615 normal built-in types for the language we are compiling. */
21616 if (DECL_IS_BUILTIN (decl))
21619 /* If we are in terse mode, don't generate any DIEs for types. */
21620 if (debug_info_level <= DINFO_LEVEL_TERSE)
21623 /* If we're a function-scope tag, initially use a parent of NULL;
21624 this will be fixed up in decls_for_scope. */
21625 if (decl_function_context (decl))
21626 context_die = NULL;
21634 gen_decl_die (decl, NULL, context_die);
21637 /* Write the debugging output for DECL. */
21640 dwarf2out_function_decl (tree decl)
21642 dwarf2out_decl (decl);
21644 htab_empty (decl_loc_table);
21645 htab_empty (cached_dw_loc_list_table);
21648 /* Output a marker (i.e. a label) for the beginning of the generated code for
21649 a lexical block. */
21652 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21653 unsigned int blocknum)
21655 switch_to_section (current_function_section ());
21656 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21659 /* Output a marker (i.e. a label) for the end of the generated code for a
21663 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21665 switch_to_section (current_function_section ());
21666 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21669 /* Returns nonzero if it is appropriate not to emit any debugging
21670 information for BLOCK, because it doesn't contain any instructions.
21672 Don't allow this for blocks with nested functions or local classes
21673 as we would end up with orphans, and in the presence of scheduling
21674 we may end up calling them anyway. */
21677 dwarf2out_ignore_block (const_tree block)
21682 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21683 if (TREE_CODE (decl) == FUNCTION_DECL
21684 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21686 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21688 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21689 if (TREE_CODE (decl) == FUNCTION_DECL
21690 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21697 /* Hash table routines for file_hash. */
21700 file_table_eq (const void *p1_p, const void *p2_p)
21702 const struct dwarf_file_data *const p1 =
21703 (const struct dwarf_file_data *) p1_p;
21704 const char *const p2 = (const char *) p2_p;
21705 return filename_cmp (p1->filename, p2) == 0;
21709 file_table_hash (const void *p_p)
21711 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21712 return htab_hash_string (p->filename);
21715 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21716 dwarf2out.c) and return its "index". The index of each (known) filename is
21717 just a unique number which is associated with only that one filename. We
21718 need such numbers for the sake of generating labels (in the .debug_sfnames
21719 section) and references to those files numbers (in the .debug_srcinfo
21720 and.debug_macinfo sections). If the filename given as an argument is not
21721 found in our current list, add it to the list and assign it the next
21722 available unique index number. In order to speed up searches, we remember
21723 the index of the filename was looked up last. This handles the majority of
21726 static struct dwarf_file_data *
21727 lookup_filename (const char *file_name)
21730 struct dwarf_file_data * created;
21732 /* Check to see if the file name that was searched on the previous
21733 call matches this file name. If so, return the index. */
21734 if (file_table_last_lookup
21735 && (file_name == file_table_last_lookup->filename
21736 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
21737 return file_table_last_lookup;
21739 /* Didn't match the previous lookup, search the table. */
21740 slot = htab_find_slot_with_hash (file_table, file_name,
21741 htab_hash_string (file_name), INSERT);
21743 return (struct dwarf_file_data *) *slot;
21745 created = ggc_alloc_dwarf_file_data ();
21746 created->filename = file_name;
21747 created->emitted_number = 0;
21752 /* If the assembler will construct the file table, then translate the compiler
21753 internal file table number into the assembler file table number, and emit
21754 a .file directive if we haven't already emitted one yet. The file table
21755 numbers are different because we prune debug info for unused variables and
21756 types, which may include filenames. */
21759 maybe_emit_file (struct dwarf_file_data * fd)
21761 if (! fd->emitted_number)
21763 if (last_emitted_file)
21764 fd->emitted_number = last_emitted_file->emitted_number + 1;
21766 fd->emitted_number = 1;
21767 last_emitted_file = fd;
21769 if (DWARF2_ASM_LINE_DEBUG_INFO)
21771 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21772 output_quoted_string (asm_out_file,
21773 remap_debug_filename (fd->filename));
21774 fputc ('\n', asm_out_file);
21778 return fd->emitted_number;
21781 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21782 That generation should happen after function debug info has been
21783 generated. The value of the attribute is the constant value of ARG. */
21786 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21788 die_arg_entry entry;
21793 if (!tmpl_value_parm_die_table)
21794 tmpl_value_parm_die_table
21795 = VEC_alloc (die_arg_entry, gc, 32);
21799 VEC_safe_push (die_arg_entry, gc,
21800 tmpl_value_parm_die_table,
21804 /* Return TRUE if T is an instance of generic type, FALSE
21808 generic_type_p (tree t)
21810 if (t == NULL_TREE || !TYPE_P (t))
21812 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
21815 /* Schedule the generation of the generic parameter dies for the
21816 instance of generic type T. The proper generation itself is later
21817 done by gen_scheduled_generic_parms_dies. */
21820 schedule_generic_params_dies_gen (tree t)
21822 if (!generic_type_p (t))
21825 if (generic_type_instances == NULL)
21826 generic_type_instances = VEC_alloc (tree, gc, 256);
21828 VEC_safe_push (tree, gc, generic_type_instances, t);
21831 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21832 by append_entry_to_tmpl_value_parm_die_table. This function must
21833 be called after function DIEs have been generated. */
21836 gen_remaining_tmpl_value_param_die_attribute (void)
21838 if (tmpl_value_parm_die_table)
21843 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21844 tree_add_const_value_attribute (e->die, e->arg);
21848 /* Generate generic parameters DIEs for instances of generic types
21849 that have been previously scheduled by
21850 schedule_generic_params_dies_gen. This function must be called
21851 after all the types of the CU have been laid out. */
21854 gen_scheduled_generic_parms_dies (void)
21859 if (generic_type_instances == NULL)
21862 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
21863 gen_generic_params_dies (t);
21867 /* Replace DW_AT_name for the decl with name. */
21870 dwarf2out_set_name (tree decl, tree name)
21876 die = TYPE_SYMTAB_DIE (decl);
21880 dname = dwarf2_name (name, 0);
21884 attr = get_AT (die, DW_AT_name);
21887 struct indirect_string_node *node;
21889 node = find_AT_string (dname);
21890 /* replace the string. */
21891 attr->dw_attr_val.v.val_str = node;
21895 add_name_attribute (die, dname);
21898 /* Called by the final INSN scan whenever we see a direct function call.
21899 Make an entry into the direct call table, recording the point of call
21900 and a reference to the target function's debug entry. */
21903 dwarf2out_direct_call (tree targ)
21906 tree origin = decl_ultimate_origin (targ);
21908 /* If this is a clone, use the abstract origin as the target. */
21912 e.poc_label_num = poc_label_num++;
21913 e.poc_decl = current_function_decl;
21914 e.targ_die = force_decl_die (targ);
21915 VEC_safe_push (dcall_entry, gc, dcall_table, &e);
21917 /* Drop a label at the return point to mark the point of call. */
21918 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21921 /* Returns a hash value for X (which really is a struct vcall_insn). */
21924 vcall_insn_table_hash (const void *x)
21926 return (hashval_t) ((const struct vcall_insn *) x)->insn_uid;
21929 /* Return nonzero if insn_uid of struct vcall_insn *X is the same as
21930 insnd_uid of *Y. */
21933 vcall_insn_table_eq (const void *x, const void *y)
21935 return (((const struct vcall_insn *) x)->insn_uid
21936 == ((const struct vcall_insn *) y)->insn_uid);
21939 /* Associate VTABLE_SLOT with INSN_UID in the VCALL_INSN_TABLE. */
21942 store_vcall_insn (unsigned int vtable_slot, int insn_uid)
21944 struct vcall_insn *item = ggc_alloc_vcall_insn ();
21945 struct vcall_insn **slot;
21948 item->insn_uid = insn_uid;
21949 item->vtable_slot = vtable_slot;
21950 slot = (struct vcall_insn **)
21951 htab_find_slot_with_hash (vcall_insn_table, &item,
21952 (hashval_t) insn_uid, INSERT);
21956 /* Return the VTABLE_SLOT associated with INSN_UID. */
21958 static unsigned int
21959 lookup_vcall_insn (unsigned int insn_uid)
21961 struct vcall_insn item;
21962 struct vcall_insn *p;
21964 item.insn_uid = insn_uid;
21965 item.vtable_slot = 0;
21966 p = (struct vcall_insn *) htab_find_with_hash (vcall_insn_table,
21968 (hashval_t) insn_uid);
21970 return (unsigned int) -1;
21971 return p->vtable_slot;
21975 /* Called when lowering indirect calls to RTL. We make a note of INSN_UID
21976 and the OBJ_TYPE_REF_TOKEN from ADDR. For C++ virtual calls, the token
21977 is the vtable slot index that we will need to put in the virtual call
21981 dwarf2out_virtual_call_token (tree addr, int insn_uid)
21983 if (is_cxx() && TREE_CODE (addr) == OBJ_TYPE_REF)
21985 tree token = OBJ_TYPE_REF_TOKEN (addr);
21986 if (TREE_CODE (token) == INTEGER_CST)
21987 store_vcall_insn (TREE_INT_CST_LOW (token), insn_uid);
21991 /* Called when scheduling RTL, when a CALL_INSN is split. Copies the
21992 OBJ_TYPE_REF_TOKEN previously associated with OLD_INSN and associates it
21996 dwarf2out_copy_call_info (rtx old_insn, rtx new_insn)
21998 unsigned int vtable_slot = lookup_vcall_insn (INSN_UID (old_insn));
22000 if (vtable_slot != (unsigned int) -1)
22001 store_vcall_insn (vtable_slot, INSN_UID (new_insn));
22004 /* Called by the final INSN scan whenever we see a virtual function call.
22005 Make an entry into the virtual call table, recording the point of call
22006 and the slot index of the vtable entry used to call the virtual member
22007 function. The slot index was associated with the INSN_UID during the
22008 lowering to RTL. */
22011 dwarf2out_virtual_call (int insn_uid)
22013 unsigned int vtable_slot = lookup_vcall_insn (insn_uid);
22016 if (vtable_slot == (unsigned int) -1)
22019 e.poc_label_num = poc_label_num++;
22020 e.vtable_slot = vtable_slot;
22021 VEC_safe_push (vcall_entry, gc, vcall_table, &e);
22023 /* Drop a label at the return point to mark the point of call. */
22024 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
22027 /* Called by the final INSN scan whenever we see a var location. We
22028 use it to drop labels in the right places, and throw the location in
22029 our lookup table. */
22032 dwarf2out_var_location (rtx loc_note)
22034 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
22035 struct var_loc_node *newloc;
22037 static const char *last_label;
22038 static const char *last_postcall_label;
22039 static bool last_in_cold_section_p;
22042 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
22045 next_real = next_real_insn (loc_note);
22046 /* If there are no instructions which would be affected by this note,
22047 don't do anything. */
22048 if (next_real == NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
22051 /* If there were any real insns between note we processed last time
22052 and this note (or if it is the first note), clear
22053 last_{,postcall_}label so that they are not reused this time. */
22054 if (last_var_location_insn == NULL_RTX
22055 || last_var_location_insn != next_real
22056 || last_in_cold_section_p != in_cold_section_p)
22059 last_postcall_label = NULL;
22062 decl = NOTE_VAR_LOCATION_DECL (loc_note);
22063 newloc = add_var_loc_to_decl (decl, loc_note,
22064 NOTE_DURING_CALL_P (loc_note)
22065 ? last_postcall_label : last_label);
22066 if (newloc == NULL)
22069 /* If there were no real insns between note we processed last time
22070 and this note, use the label we emitted last time. Otherwise
22071 create a new label and emit it. */
22072 if (last_label == NULL)
22074 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
22075 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
22077 last_label = ggc_strdup (loclabel);
22080 if (!NOTE_DURING_CALL_P (loc_note))
22081 newloc->label = last_label;
22084 if (!last_postcall_label)
22086 sprintf (loclabel, "%s-1", last_label);
22087 last_postcall_label = ggc_strdup (loclabel);
22089 newloc->label = last_postcall_label;
22092 last_var_location_insn = next_real;
22093 last_in_cold_section_p = in_cold_section_p;
22096 /* Note in one location list that text section has changed. */
22099 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
22101 var_loc_list *list = (var_loc_list *) *slot;
22103 list->last_before_switch
22104 = list->last->next ? list->last->next : list->last;
22108 /* Note in all location lists that text section has changed. */
22111 var_location_switch_text_section (void)
22113 if (decl_loc_table == NULL)
22116 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
22119 /* We need to reset the locations at the beginning of each
22120 function. We can't do this in the end_function hook, because the
22121 declarations that use the locations won't have been output when
22122 that hook is called. Also compute have_multiple_function_sections here. */
22125 dwarf2out_begin_function (tree fun)
22127 if (function_section (fun) != text_section)
22128 have_multiple_function_sections = true;
22129 if (flag_reorder_blocks_and_partition && !cold_text_section)
22131 gcc_assert (current_function_decl == fun);
22132 cold_text_section = unlikely_text_section ();
22133 switch_to_section (cold_text_section);
22134 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22135 switch_to_section (current_function_section ());
22138 dwarf2out_note_section_used ();
22141 /* Output a label to mark the beginning of a source code line entry
22142 and record information relating to this source line, in
22143 'line_info_table' for later output of the .debug_line section. */
22146 dwarf2out_source_line (unsigned int line, const char *filename,
22147 int discriminator, bool is_stmt)
22149 static bool last_is_stmt = true;
22151 if (debug_info_level >= DINFO_LEVEL_NORMAL
22154 int file_num = maybe_emit_file (lookup_filename (filename));
22156 switch_to_section (current_function_section ());
22158 /* If requested, emit something human-readable. */
22159 if (flag_debug_asm)
22160 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
22163 if (DWARF2_ASM_LINE_DEBUG_INFO)
22165 /* Emit the .loc directive understood by GNU as. */
22166 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
22167 if (is_stmt != last_is_stmt)
22169 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
22170 last_is_stmt = is_stmt;
22172 if (SUPPORTS_DISCRIMINATOR && discriminator != 0
22173 && (dwarf_version >= 4 || !dwarf_strict))
22174 fprintf (asm_out_file, " discriminator %d", discriminator);
22175 fputc ('\n', asm_out_file);
22177 /* Indicate that line number info exists. */
22178 line_info_table_in_use++;
22180 else if (function_section (current_function_decl) != text_section)
22182 dw_separate_line_info_ref line_info;
22183 targetm.asm_out.internal_label (asm_out_file,
22184 SEPARATE_LINE_CODE_LABEL,
22185 separate_line_info_table_in_use);
22187 /* Expand the line info table if necessary. */
22188 if (separate_line_info_table_in_use
22189 == separate_line_info_table_allocated)
22191 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22192 separate_line_info_table
22193 = GGC_RESIZEVEC (dw_separate_line_info_entry,
22194 separate_line_info_table,
22195 separate_line_info_table_allocated);
22196 memset (separate_line_info_table
22197 + separate_line_info_table_in_use,
22199 (LINE_INFO_TABLE_INCREMENT
22200 * sizeof (dw_separate_line_info_entry)));
22203 /* Add the new entry at the end of the line_info_table. */
22205 = &separate_line_info_table[separate_line_info_table_in_use++];
22206 line_info->dw_file_num = file_num;
22207 line_info->dw_line_num = line;
22208 line_info->function = current_function_funcdef_no;
22212 dw_line_info_ref line_info;
22214 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
22215 line_info_table_in_use);
22217 /* Expand the line info table if necessary. */
22218 if (line_info_table_in_use == line_info_table_allocated)
22220 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22222 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
22223 line_info_table_allocated);
22224 memset (line_info_table + line_info_table_in_use, 0,
22225 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
22228 /* Add the new entry at the end of the line_info_table. */
22229 line_info = &line_info_table[line_info_table_in_use++];
22230 line_info->dw_file_num = file_num;
22231 line_info->dw_line_num = line;
22236 /* Record the beginning of a new source file. */
22239 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22241 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22243 /* Record the beginning of the file for break_out_includes. */
22244 dw_die_ref bincl_die;
22246 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22247 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22250 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22253 e.code = DW_MACINFO_start_file;
22255 e.info = xstrdup (filename);
22256 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22260 /* Record the end of a source file. */
22263 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22265 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22266 /* Record the end of the file for break_out_includes. */
22267 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22269 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22272 e.code = DW_MACINFO_end_file;
22275 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22279 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22280 the tail part of the directive line, i.e. the part which is past the
22281 initial whitespace, #, whitespace, directive-name, whitespace part. */
22284 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22285 const char *buffer ATTRIBUTE_UNUSED)
22287 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22290 e.code = DW_MACINFO_define;
22292 e.info = xstrdup (buffer);;
22293 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22297 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22298 the tail part of the directive line, i.e. the part which is past the
22299 initial whitespace, #, whitespace, directive-name, whitespace part. */
22302 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22303 const char *buffer ATTRIBUTE_UNUSED)
22305 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22308 e.code = DW_MACINFO_undef;
22310 e.info = xstrdup (buffer);;
22311 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22316 output_macinfo (void)
22319 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
22320 macinfo_entry *ref;
22325 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
22329 case DW_MACINFO_start_file:
22331 int file_num = maybe_emit_file (lookup_filename (ref->info));
22332 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22333 dw2_asm_output_data_uleb128
22334 (ref->lineno, "Included from line number %lu",
22335 (unsigned long)ref->lineno);
22336 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22339 case DW_MACINFO_end_file:
22340 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22342 case DW_MACINFO_define:
22343 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
22344 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22345 (unsigned long)ref->lineno);
22346 dw2_asm_output_nstring (ref->info, -1, "The macro");
22348 case DW_MACINFO_undef:
22349 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
22350 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22351 (unsigned long)ref->lineno);
22352 dw2_asm_output_nstring (ref->info, -1, "The macro");
22355 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22356 ASM_COMMENT_START, (unsigned long)ref->code);
22362 /* Set up for Dwarf output at the start of compilation. */
22365 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
22367 /* Allocate the file_table. */
22368 file_table = htab_create_ggc (50, file_table_hash,
22369 file_table_eq, NULL);
22371 /* Allocate the decl_die_table. */
22372 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
22373 decl_die_table_eq, NULL);
22375 /* Allocate the decl_loc_table. */
22376 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
22377 decl_loc_table_eq, NULL);
22379 /* Allocate the cached_dw_loc_list_table. */
22380 cached_dw_loc_list_table
22381 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
22382 cached_dw_loc_list_table_eq, NULL);
22384 /* Allocate the initial hunk of the decl_scope_table. */
22385 decl_scope_table = VEC_alloc (tree, gc, 256);
22387 /* Allocate the initial hunk of the abbrev_die_table. */
22388 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
22389 (ABBREV_DIE_TABLE_INCREMENT);
22390 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
22391 /* Zero-th entry is allocated, but unused. */
22392 abbrev_die_table_in_use = 1;
22394 /* Allocate the initial hunk of the line_info_table. */
22395 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
22396 (LINE_INFO_TABLE_INCREMENT);
22397 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
22399 /* Zero-th entry is allocated, but unused. */
22400 line_info_table_in_use = 1;
22402 /* Allocate the pubtypes and pubnames vectors. */
22403 pubname_table = VEC_alloc (pubname_entry, gc, 32);
22404 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
22406 /* Allocate the table that maps insn UIDs to vtable slot indexes. */
22407 vcall_insn_table = htab_create_ggc (10, vcall_insn_table_hash,
22408 vcall_insn_table_eq, NULL);
22410 incomplete_types = VEC_alloc (tree, gc, 64);
22412 used_rtx_array = VEC_alloc (rtx, gc, 32);
22414 debug_info_section = get_section (DEBUG_INFO_SECTION,
22415 SECTION_DEBUG, NULL);
22416 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
22417 SECTION_DEBUG, NULL);
22418 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
22419 SECTION_DEBUG, NULL);
22420 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
22421 SECTION_DEBUG, NULL);
22422 debug_line_section = get_section (DEBUG_LINE_SECTION,
22423 SECTION_DEBUG, NULL);
22424 debug_loc_section = get_section (DEBUG_LOC_SECTION,
22425 SECTION_DEBUG, NULL);
22426 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
22427 SECTION_DEBUG, NULL);
22428 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
22429 SECTION_DEBUG, NULL);
22430 debug_dcall_section = get_section (DEBUG_DCALL_SECTION,
22431 SECTION_DEBUG, NULL);
22432 debug_vcall_section = get_section (DEBUG_VCALL_SECTION,
22433 SECTION_DEBUG, NULL);
22434 debug_str_section = get_section (DEBUG_STR_SECTION,
22435 DEBUG_STR_SECTION_FLAGS, NULL);
22436 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
22437 SECTION_DEBUG, NULL);
22438 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
22439 SECTION_DEBUG, NULL);
22441 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
22442 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
22443 DEBUG_ABBREV_SECTION_LABEL, 0);
22444 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
22445 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
22446 COLD_TEXT_SECTION_LABEL, 0);
22447 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
22449 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
22450 DEBUG_INFO_SECTION_LABEL, 0);
22451 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
22452 DEBUG_LINE_SECTION_LABEL, 0);
22453 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
22454 DEBUG_RANGES_SECTION_LABEL, 0);
22455 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
22456 DEBUG_MACINFO_SECTION_LABEL, 0);
22458 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22459 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
22461 switch_to_section (text_section);
22462 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
22465 /* Called before cgraph_optimize starts outputtting functions, variables
22466 and toplevel asms into assembly. */
22469 dwarf2out_assembly_start (void)
22471 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22472 && dwarf2out_do_cfi_asm ()
22473 && (!(flag_unwind_tables || flag_exceptions)
22474 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
22475 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
22478 /* A helper function for dwarf2out_finish called through
22479 htab_traverse. Emit one queued .debug_str string. */
22482 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22484 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22486 if (node->label && node->refcount)
22488 switch_to_section (debug_str_section);
22489 ASM_OUTPUT_LABEL (asm_out_file, node->label);
22490 assemble_string (node->str, strlen (node->str) + 1);
22496 #if ENABLE_ASSERT_CHECKING
22497 /* Verify that all marks are clear. */
22500 verify_marks_clear (dw_die_ref die)
22504 gcc_assert (! die->die_mark);
22505 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
22507 #endif /* ENABLE_ASSERT_CHECKING */
22509 /* Clear the marks for a die and its children.
22510 Be cool if the mark isn't set. */
22513 prune_unmark_dies (dw_die_ref die)
22519 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
22522 /* Given DIE that we're marking as used, find any other dies
22523 it references as attributes and mark them as used. */
22526 prune_unused_types_walk_attribs (dw_die_ref die)
22531 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22533 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
22535 /* A reference to another DIE.
22536 Make sure that it will get emitted.
22537 If it was broken out into a comdat group, don't follow it. */
22538 if (dwarf_version < 4
22539 || a->dw_attr == DW_AT_specification
22540 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
22541 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
22543 /* Set the string's refcount to 0 so that prune_unused_types_mark
22544 accounts properly for it. */
22545 if (AT_class (a) == dw_val_class_str)
22546 a->dw_attr_val.v.val_str->refcount = 0;
22550 /* Mark the generic parameters and arguments children DIEs of DIE. */
22553 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
22557 if (die == NULL || die->die_child == NULL)
22559 c = die->die_child;
22562 switch (c->die_tag)
22564 case DW_TAG_template_type_param:
22565 case DW_TAG_template_value_param:
22566 case DW_TAG_GNU_template_template_param:
22567 case DW_TAG_GNU_template_parameter_pack:
22568 prune_unused_types_mark (c, 1);
22574 } while (c && c != die->die_child);
22577 /* Mark DIE as being used. If DOKIDS is true, then walk down
22578 to DIE's children. */
22581 prune_unused_types_mark (dw_die_ref die, int dokids)
22585 if (die->die_mark == 0)
22587 /* We haven't done this node yet. Mark it as used. */
22589 /* If this is the DIE of a generic type instantiation,
22590 mark the children DIEs that describe its generic parms and
22592 prune_unused_types_mark_generic_parms_dies (die);
22594 /* We also have to mark its parents as used.
22595 (But we don't want to mark our parents' kids due to this.) */
22596 if (die->die_parent)
22597 prune_unused_types_mark (die->die_parent, 0);
22599 /* Mark any referenced nodes. */
22600 prune_unused_types_walk_attribs (die);
22602 /* If this node is a specification,
22603 also mark the definition, if it exists. */
22604 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
22605 prune_unused_types_mark (die->die_definition, 1);
22608 if (dokids && die->die_mark != 2)
22610 /* We need to walk the children, but haven't done so yet.
22611 Remember that we've walked the kids. */
22614 /* If this is an array type, we need to make sure our
22615 kids get marked, even if they're types. If we're
22616 breaking out types into comdat sections, do this
22617 for all type definitions. */
22618 if (die->die_tag == DW_TAG_array_type
22619 || (dwarf_version >= 4
22620 && is_type_die (die) && ! is_declaration_die (die)))
22621 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
22623 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22627 /* For local classes, look if any static member functions were emitted
22628 and if so, mark them. */
22631 prune_unused_types_walk_local_classes (dw_die_ref die)
22635 if (die->die_mark == 2)
22638 switch (die->die_tag)
22640 case DW_TAG_structure_type:
22641 case DW_TAG_union_type:
22642 case DW_TAG_class_type:
22645 case DW_TAG_subprogram:
22646 if (!get_AT_flag (die, DW_AT_declaration)
22647 || die->die_definition != NULL)
22648 prune_unused_types_mark (die, 1);
22655 /* Mark children. */
22656 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
22659 /* Walk the tree DIE and mark types that we actually use. */
22662 prune_unused_types_walk (dw_die_ref die)
22666 /* Don't do anything if this node is already marked and
22667 children have been marked as well. */
22668 if (die->die_mark == 2)
22671 switch (die->die_tag)
22673 case DW_TAG_structure_type:
22674 case DW_TAG_union_type:
22675 case DW_TAG_class_type:
22676 if (die->die_perennial_p)
22679 for (c = die->die_parent; c; c = c->die_parent)
22680 if (c->die_tag == DW_TAG_subprogram)
22683 /* Finding used static member functions inside of classes
22684 is needed just for local classes, because for other classes
22685 static member function DIEs with DW_AT_specification
22686 are emitted outside of the DW_TAG_*_type. If we ever change
22687 it, we'd need to call this even for non-local classes. */
22689 prune_unused_types_walk_local_classes (die);
22691 /* It's a type node --- don't mark it. */
22694 case DW_TAG_const_type:
22695 case DW_TAG_packed_type:
22696 case DW_TAG_pointer_type:
22697 case DW_TAG_reference_type:
22698 case DW_TAG_rvalue_reference_type:
22699 case DW_TAG_volatile_type:
22700 case DW_TAG_typedef:
22701 case DW_TAG_array_type:
22702 case DW_TAG_interface_type:
22703 case DW_TAG_friend:
22704 case DW_TAG_variant_part:
22705 case DW_TAG_enumeration_type:
22706 case DW_TAG_subroutine_type:
22707 case DW_TAG_string_type:
22708 case DW_TAG_set_type:
22709 case DW_TAG_subrange_type:
22710 case DW_TAG_ptr_to_member_type:
22711 case DW_TAG_file_type:
22712 if (die->die_perennial_p)
22715 /* It's a type node --- don't mark it. */
22719 /* Mark everything else. */
22723 if (die->die_mark == 0)
22727 /* Now, mark any dies referenced from here. */
22728 prune_unused_types_walk_attribs (die);
22733 /* Mark children. */
22734 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22737 /* Increment the string counts on strings referred to from DIE's
22741 prune_unused_types_update_strings (dw_die_ref die)
22746 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22747 if (AT_class (a) == dw_val_class_str)
22749 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22751 /* Avoid unnecessarily putting strings that are used less than
22752 twice in the hash table. */
22754 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22757 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22758 htab_hash_string (s->str),
22760 gcc_assert (*slot == NULL);
22766 /* Remove from the tree DIE any dies that aren't marked. */
22769 prune_unused_types_prune (dw_die_ref die)
22773 gcc_assert (die->die_mark);
22774 prune_unused_types_update_strings (die);
22776 if (! die->die_child)
22779 c = die->die_child;
22781 dw_die_ref prev = c;
22782 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22783 if (c == die->die_child)
22785 /* No marked children between 'prev' and the end of the list. */
22787 /* No marked children at all. */
22788 die->die_child = NULL;
22791 prev->die_sib = c->die_sib;
22792 die->die_child = prev;
22797 if (c != prev->die_sib)
22799 prune_unused_types_prune (c);
22800 } while (c != die->die_child);
22803 /* A helper function for dwarf2out_finish called through
22804 htab_traverse. Clear .debug_str strings that we haven't already
22805 decided to emit. */
22808 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22810 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22812 if (!node->label || !node->refcount)
22813 htab_clear_slot (debug_str_hash, h);
22818 /* Remove dies representing declarations that we never use. */
22821 prune_unused_types (void)
22824 limbo_die_node *node;
22825 comdat_type_node *ctnode;
22827 dcall_entry *dcall;
22829 #if ENABLE_ASSERT_CHECKING
22830 /* All the marks should already be clear. */
22831 verify_marks_clear (comp_unit_die ());
22832 for (node = limbo_die_list; node; node = node->next)
22833 verify_marks_clear (node->die);
22834 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22835 verify_marks_clear (ctnode->root_die);
22836 #endif /* ENABLE_ASSERT_CHECKING */
22838 /* Mark types that are used in global variables. */
22839 premark_types_used_by_global_vars ();
22841 /* Set the mark on nodes that are actually used. */
22842 prune_unused_types_walk (comp_unit_die ());
22843 for (node = limbo_die_list; node; node = node->next)
22844 prune_unused_types_walk (node->die);
22845 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22847 prune_unused_types_walk (ctnode->root_die);
22848 prune_unused_types_mark (ctnode->type_die, 1);
22851 /* Also set the mark on nodes referenced from the
22853 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22854 prune_unused_types_mark (pub->die, 1);
22856 /* Mark nodes referenced from the direct call table. */
22857 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, dcall)
22858 prune_unused_types_mark (dcall->targ_die, 1);
22860 /* Get rid of nodes that aren't marked; and update the string counts. */
22861 if (debug_str_hash && debug_str_hash_forced)
22862 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22863 else if (debug_str_hash)
22864 htab_empty (debug_str_hash);
22865 prune_unused_types_prune (comp_unit_die ());
22866 for (node = limbo_die_list; node; node = node->next)
22867 prune_unused_types_prune (node->die);
22868 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22869 prune_unused_types_prune (ctnode->root_die);
22871 /* Leave the marks clear. */
22872 prune_unmark_dies (comp_unit_die ());
22873 for (node = limbo_die_list; node; node = node->next)
22874 prune_unmark_dies (node->die);
22875 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22876 prune_unmark_dies (ctnode->root_die);
22879 /* Set the parameter to true if there are any relative pathnames in
22882 file_table_relative_p (void ** slot, void *param)
22884 bool *p = (bool *) param;
22885 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22886 if (!IS_ABSOLUTE_PATH (d->filename))
22894 /* Routines to manipulate hash table of comdat type units. */
22897 htab_ct_hash (const void *of)
22900 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22902 memcpy (&h, type_node->signature, sizeof (h));
22907 htab_ct_eq (const void *of1, const void *of2)
22909 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22910 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22912 return (! memcmp (type_node_1->signature, type_node_2->signature,
22913 DWARF_TYPE_SIGNATURE_SIZE));
22916 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22917 to the location it would have been added, should we know its
22918 DECL_ASSEMBLER_NAME when we added other attributes. This will
22919 probably improve compactness of debug info, removing equivalent
22920 abbrevs, and hide any differences caused by deferring the
22921 computation of the assembler name, triggered by e.g. PCH. */
22924 move_linkage_attr (dw_die_ref die)
22926 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22927 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22929 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22930 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22934 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22936 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22940 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22942 VEC_pop (dw_attr_node, die->die_attr);
22943 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22947 /* Helper function for resolve_addr, attempt to resolve
22948 one CONST_STRING, return non-zero if not successful. Similarly verify that
22949 SYMBOL_REFs refer to variables emitted in the current CU. */
22952 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22956 if (GET_CODE (rtl) == CONST_STRING)
22958 size_t len = strlen (XSTR (rtl, 0)) + 1;
22959 tree t = build_string (len, XSTR (rtl, 0));
22960 tree tlen = build_int_cst (NULL_TREE, len - 1);
22962 = build_array_type (char_type_node, build_index_type (tlen));
22963 rtl = lookup_constant_def (t);
22964 if (!rtl || !MEM_P (rtl))
22966 rtl = XEXP (rtl, 0);
22967 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22972 if (GET_CODE (rtl) == SYMBOL_REF
22973 && SYMBOL_REF_DECL (rtl)
22974 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22977 if (GET_CODE (rtl) == CONST
22978 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22984 /* Helper function for resolve_addr, handle one location
22985 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22986 the location list couldn't be resolved. */
22989 resolve_addr_in_expr (dw_loc_descr_ref loc)
22991 for (; loc; loc = loc->dw_loc_next)
22992 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22993 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22994 || (loc->dw_loc_opc == DW_OP_implicit_value
22995 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22996 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22998 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
22999 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
23002 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
23005 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
23006 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
23007 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
23012 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23013 an address in .rodata section if the string literal is emitted there,
23014 or remove the containing location list or replace DW_AT_const_value
23015 with DW_AT_location and empty location expression, if it isn't found
23016 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23017 to something that has been emitted in the current CU. */
23020 resolve_addr (dw_die_ref die)
23024 dw_loc_list_ref *curr, *start, loc;
23027 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23028 switch (AT_class (a))
23030 case dw_val_class_loc_list:
23031 start = curr = AT_loc_list_ptr (a);
23034 /* The same list can be referenced more than once. See if we have
23035 already recorded the result from a previous pass. */
23037 *curr = loc->dw_loc_next;
23038 else if (!loc->resolved_addr)
23040 /* As things stand, we do not expect or allow one die to
23041 reference a suffix of another die's location list chain.
23042 References must be identical or completely separate.
23043 There is therefore no need to cache the result of this
23044 pass on any list other than the first; doing so
23045 would lead to unnecessary writes. */
23048 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
23049 if (!resolve_addr_in_expr ((*curr)->expr))
23051 dw_loc_list_ref next = (*curr)->dw_loc_next;
23052 if (next && (*curr)->ll_symbol)
23054 gcc_assert (!next->ll_symbol);
23055 next->ll_symbol = (*curr)->ll_symbol;
23060 curr = &(*curr)->dw_loc_next;
23063 loc->resolved_addr = 1;
23067 loc->dw_loc_next = *start;
23072 remove_AT (die, a->dw_attr);
23076 case dw_val_class_loc:
23077 if (!resolve_addr_in_expr (AT_loc (a)))
23079 remove_AT (die, a->dw_attr);
23083 case dw_val_class_addr:
23084 if (a->dw_attr == DW_AT_const_value
23085 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
23087 remove_AT (die, a->dw_attr);
23095 FOR_EACH_CHILD (die, c, resolve_addr (c));
23098 /* Helper routines for optimize_location_lists.
23099 This pass tries to share identical local lists in .debug_loc
23102 /* Iteratively hash operands of LOC opcode. */
23104 static inline hashval_t
23105 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
23107 dw_val_ref val1 = &loc->dw_loc_oprnd1;
23108 dw_val_ref val2 = &loc->dw_loc_oprnd2;
23110 switch (loc->dw_loc_opc)
23112 case DW_OP_const4u:
23113 case DW_OP_const8u:
23117 case DW_OP_const1u:
23118 case DW_OP_const1s:
23119 case DW_OP_const2u:
23120 case DW_OP_const2s:
23121 case DW_OP_const4s:
23122 case DW_OP_const8s:
23126 case DW_OP_plus_uconst:
23162 case DW_OP_deref_size:
23163 case DW_OP_xderef_size:
23164 hash = iterative_hash_object (val1->v.val_int, hash);
23171 gcc_assert (val1->val_class == dw_val_class_loc);
23172 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
23173 hash = iterative_hash_object (offset, hash);
23176 case DW_OP_implicit_value:
23177 hash = iterative_hash_object (val1->v.val_unsigned, hash);
23178 switch (val2->val_class)
23180 case dw_val_class_const:
23181 hash = iterative_hash_object (val2->v.val_int, hash);
23183 case dw_val_class_vec:
23185 unsigned int elt_size = val2->v.val_vec.elt_size;
23186 unsigned int len = val2->v.val_vec.length;
23188 hash = iterative_hash_object (elt_size, hash);
23189 hash = iterative_hash_object (len, hash);
23190 hash = iterative_hash (val2->v.val_vec.array,
23191 len * elt_size, hash);
23194 case dw_val_class_const_double:
23195 hash = iterative_hash_object (val2->v.val_double.low, hash);
23196 hash = iterative_hash_object (val2->v.val_double.high, hash);
23198 case dw_val_class_addr:
23199 hash = iterative_hash_rtx (val2->v.val_addr, hash);
23202 gcc_unreachable ();
23206 case DW_OP_bit_piece:
23207 hash = iterative_hash_object (val1->v.val_int, hash);
23208 hash = iterative_hash_object (val2->v.val_int, hash);
23214 unsigned char dtprel = 0xd1;
23215 hash = iterative_hash_object (dtprel, hash);
23217 hash = iterative_hash_rtx (val1->v.val_addr, hash);
23219 case DW_OP_GNU_implicit_pointer:
23220 hash = iterative_hash_object (val2->v.val_int, hash);
23224 /* Other codes have no operands. */
23230 /* Iteratively hash the whole DWARF location expression LOC. */
23232 static inline hashval_t
23233 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
23235 dw_loc_descr_ref l;
23236 bool sizes_computed = false;
23237 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23238 size_of_locs (loc);
23240 for (l = loc; l != NULL; l = l->dw_loc_next)
23242 enum dwarf_location_atom opc = l->dw_loc_opc;
23243 hash = iterative_hash_object (opc, hash);
23244 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
23246 size_of_locs (loc);
23247 sizes_computed = true;
23249 hash = hash_loc_operands (l, hash);
23254 /* Compute hash of the whole location list LIST_HEAD. */
23257 hash_loc_list (dw_loc_list_ref list_head)
23259 dw_loc_list_ref curr = list_head;
23260 hashval_t hash = 0;
23262 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
23264 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
23265 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
23267 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
23269 hash = hash_locs (curr->expr, hash);
23271 list_head->hash = hash;
23274 /* Return true if X and Y opcodes have the same operands. */
23277 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
23279 dw_val_ref valx1 = &x->dw_loc_oprnd1;
23280 dw_val_ref valx2 = &x->dw_loc_oprnd2;
23281 dw_val_ref valy1 = &y->dw_loc_oprnd1;
23282 dw_val_ref valy2 = &y->dw_loc_oprnd2;
23284 switch (x->dw_loc_opc)
23286 case DW_OP_const4u:
23287 case DW_OP_const8u:
23291 case DW_OP_const1u:
23292 case DW_OP_const1s:
23293 case DW_OP_const2u:
23294 case DW_OP_const2s:
23295 case DW_OP_const4s:
23296 case DW_OP_const8s:
23300 case DW_OP_plus_uconst:
23336 case DW_OP_deref_size:
23337 case DW_OP_xderef_size:
23338 return valx1->v.val_int == valy1->v.val_int;
23341 gcc_assert (valx1->val_class == dw_val_class_loc
23342 && valy1->val_class == dw_val_class_loc
23343 && x->dw_loc_addr == y->dw_loc_addr);
23344 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
23345 case DW_OP_implicit_value:
23346 if (valx1->v.val_unsigned != valy1->v.val_unsigned
23347 || valx2->val_class != valy2->val_class)
23349 switch (valx2->val_class)
23351 case dw_val_class_const:
23352 return valx2->v.val_int == valy2->v.val_int;
23353 case dw_val_class_vec:
23354 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
23355 && valx2->v.val_vec.length == valy2->v.val_vec.length
23356 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
23357 valx2->v.val_vec.elt_size
23358 * valx2->v.val_vec.length) == 0;
23359 case dw_val_class_const_double:
23360 return valx2->v.val_double.low == valy2->v.val_double.low
23361 && valx2->v.val_double.high == valy2->v.val_double.high;
23362 case dw_val_class_addr:
23363 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
23365 gcc_unreachable ();
23368 case DW_OP_bit_piece:
23369 return valx1->v.val_int == valy1->v.val_int
23370 && valx2->v.val_int == valy2->v.val_int;
23373 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
23374 case DW_OP_GNU_implicit_pointer:
23375 return valx1->val_class == dw_val_class_die_ref
23376 && valx1->val_class == valy1->val_class
23377 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
23378 && valx2->v.val_int == valy2->v.val_int;
23380 /* Other codes have no operands. */
23385 /* Return true if DWARF location expressions X and Y are the same. */
23388 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
23390 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
23391 if (x->dw_loc_opc != y->dw_loc_opc
23392 || x->dtprel != y->dtprel
23393 || !compare_loc_operands (x, y))
23395 return x == NULL && y == NULL;
23398 /* Return precomputed hash of location list X. */
23401 loc_list_hash (const void *x)
23403 return ((const struct dw_loc_list_struct *) x)->hash;
23406 /* Return 1 if location lists X and Y are the same. */
23409 loc_list_eq (const void *x, const void *y)
23411 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
23412 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
23415 if (a->hash != b->hash)
23417 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
23418 if (strcmp (a->begin, b->begin) != 0
23419 || strcmp (a->end, b->end) != 0
23420 || (a->section == NULL) != (b->section == NULL)
23421 || (a->section && strcmp (a->section, b->section) != 0)
23422 || !compare_locs (a->expr, b->expr))
23424 return a == NULL && b == NULL;
23427 /* Recursively optimize location lists referenced from DIE
23428 children and share them whenever possible. */
23431 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
23438 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23439 if (AT_class (a) == dw_val_class_loc_list)
23441 dw_loc_list_ref list = AT_loc_list (a);
23442 /* TODO: perform some optimizations here, before hashing
23443 it and storing into the hash table. */
23444 hash_loc_list (list);
23445 slot = htab_find_slot_with_hash (htab, list, list->hash,
23448 *slot = (void *) list;
23450 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
23453 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
23456 /* Optimize location lists referenced from DIE
23457 children and share them whenever possible. */
23460 optimize_location_lists (dw_die_ref die)
23462 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
23463 optimize_location_lists_1 (die, htab);
23464 htab_delete (htab);
23467 /* Output stuff that dwarf requires at the end of every file,
23468 and generate the DWARF-2 debugging info. */
23471 dwarf2out_finish (const char *filename)
23473 limbo_die_node *node, *next_node;
23474 comdat_type_node *ctnode;
23475 htab_t comdat_type_table;
23478 gen_scheduled_generic_parms_dies ();
23479 gen_remaining_tmpl_value_param_die_attribute ();
23481 /* Add the name for the main input file now. We delayed this from
23482 dwarf2out_init to avoid complications with PCH. */
23483 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
23484 if (!IS_ABSOLUTE_PATH (filename))
23485 add_comp_dir_attribute (comp_unit_die ());
23486 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
23489 htab_traverse (file_table, file_table_relative_p, &p);
23491 add_comp_dir_attribute (comp_unit_die ());
23494 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
23496 add_location_or_const_value_attribute (
23497 VEC_index (deferred_locations, deferred_locations_list, i)->die,
23498 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
23503 /* Traverse the limbo die list, and add parent/child links. The only
23504 dies without parents that should be here are concrete instances of
23505 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23506 For concrete instances, we can get the parent die from the abstract
23508 for (node = limbo_die_list; node; node = next_node)
23510 dw_die_ref die = node->die;
23511 next_node = node->next;
23513 if (die->die_parent == NULL)
23515 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
23518 add_child_die (origin->die_parent, die);
23519 else if (is_cu_die (die))
23521 else if (seen_error ())
23522 /* It's OK to be confused by errors in the input. */
23523 add_child_die (comp_unit_die (), die);
23526 /* In certain situations, the lexical block containing a
23527 nested function can be optimized away, which results
23528 in the nested function die being orphaned. Likewise
23529 with the return type of that nested function. Force
23530 this to be a child of the containing function.
23532 It may happen that even the containing function got fully
23533 inlined and optimized out. In that case we are lost and
23534 assign the empty child. This should not be big issue as
23535 the function is likely unreachable too. */
23536 tree context = NULL_TREE;
23538 gcc_assert (node->created_for);
23540 if (DECL_P (node->created_for))
23541 context = DECL_CONTEXT (node->created_for);
23542 else if (TYPE_P (node->created_for))
23543 context = TYPE_CONTEXT (node->created_for);
23545 gcc_assert (context
23546 && (TREE_CODE (context) == FUNCTION_DECL
23547 || TREE_CODE (context) == NAMESPACE_DECL));
23549 origin = lookup_decl_die (context);
23551 add_child_die (origin, die);
23553 add_child_die (comp_unit_die (), die);
23558 limbo_die_list = NULL;
23560 resolve_addr (comp_unit_die ());
23562 for (node = deferred_asm_name; node; node = node->next)
23564 tree decl = node->created_for;
23565 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
23567 add_linkage_attr (node->die, decl);
23568 move_linkage_attr (node->die);
23572 deferred_asm_name = NULL;
23574 /* Walk through the list of incomplete types again, trying once more to
23575 emit full debugging info for them. */
23576 retry_incomplete_types ();
23578 if (flag_eliminate_unused_debug_types)
23579 prune_unused_types ();
23581 /* Generate separate CUs for each of the include files we've seen.
23582 They will go into limbo_die_list. */
23583 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
23584 break_out_includes (comp_unit_die ());
23586 /* Generate separate COMDAT sections for type DIEs. */
23587 if (dwarf_version >= 4)
23589 break_out_comdat_types (comp_unit_die ());
23591 /* Each new type_unit DIE was added to the limbo die list when created.
23592 Since these have all been added to comdat_type_list, clear the
23594 limbo_die_list = NULL;
23596 /* For each new comdat type unit, copy declarations for incomplete
23597 types to make the new unit self-contained (i.e., no direct
23598 references to the main compile unit). */
23599 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23600 copy_decls_for_unworthy_types (ctnode->root_die);
23601 copy_decls_for_unworthy_types (comp_unit_die ());
23603 /* In the process of copying declarations from one unit to another,
23604 we may have left some declarations behind that are no longer
23605 referenced. Prune them. */
23606 prune_unused_types ();
23609 /* Traverse the DIE's and add add sibling attributes to those DIE's
23610 that have children. */
23611 add_sibling_attributes (comp_unit_die ());
23612 for (node = limbo_die_list; node; node = node->next)
23613 add_sibling_attributes (node->die);
23614 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23615 add_sibling_attributes (ctnode->root_die);
23617 /* Output a terminator label for the .text section. */
23618 switch_to_section (text_section);
23619 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
23620 if (cold_text_section)
23622 switch_to_section (cold_text_section);
23623 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
23626 /* We can only use the low/high_pc attributes if all of the code was
23628 if (!have_multiple_function_sections
23629 || (dwarf_version < 3 && dwarf_strict))
23631 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
23632 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
23637 unsigned fde_idx = 0;
23638 bool range_list_added = false;
23640 /* We need to give .debug_loc and .debug_ranges an appropriate
23641 "base address". Use zero so that these addresses become
23642 absolute. Historically, we've emitted the unexpected
23643 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23644 Emit both to give time for other tools to adapt. */
23645 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
23646 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
23648 if (text_section_used)
23649 add_ranges_by_labels (comp_unit_die (), text_section_label,
23650 text_end_label, &range_list_added);
23651 if (cold_text_section_used)
23652 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
23653 cold_end_label, &range_list_added);
23655 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
23657 dw_fde_ref fde = &fde_table[fde_idx];
23659 if (!fde->in_std_section)
23660 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
23661 fde->dw_fde_end, &range_list_added);
23662 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
23663 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
23664 fde->dw_fde_second_end, &range_list_added);
23667 if (range_list_added)
23671 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23672 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
23673 debug_line_section_label);
23675 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23676 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
23678 if (have_location_lists)
23679 optimize_location_lists (comp_unit_die ());
23681 /* Output all of the compilation units. We put the main one last so that
23682 the offsets are available to output_pubnames. */
23683 for (node = limbo_die_list; node; node = node->next)
23684 output_comp_unit (node->die, 0);
23686 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
23687 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23689 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
23691 /* Don't output duplicate types. */
23692 if (*slot != HTAB_EMPTY_ENTRY)
23695 /* Add a pointer to the line table for the main compilation unit
23696 so that the debugger can make sense of DW_AT_decl_file
23698 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23699 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
23700 debug_line_section_label);
23702 output_comdat_type_unit (ctnode);
23705 htab_delete (comdat_type_table);
23707 /* Output the main compilation unit if non-empty or if .debug_macinfo
23708 will be emitted. */
23709 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
23711 /* Output the abbreviation table. */
23712 switch_to_section (debug_abbrev_section);
23713 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
23714 output_abbrev_section ();
23716 /* Output location list section if necessary. */
23717 if (have_location_lists)
23719 /* Output the location lists info. */
23720 switch_to_section (debug_loc_section);
23721 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
23722 DEBUG_LOC_SECTION_LABEL, 0);
23723 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
23724 output_location_lists (comp_unit_die ());
23727 /* Output public names table if necessary. */
23728 if (!VEC_empty (pubname_entry, pubname_table))
23730 gcc_assert (info_section_emitted);
23731 switch_to_section (debug_pubnames_section);
23732 output_pubnames (pubname_table);
23735 /* Output public types table if necessary. */
23736 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23737 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23738 simply won't look for the section. */
23739 if (!VEC_empty (pubname_entry, pubtype_table))
23741 bool empty = false;
23743 if (flag_eliminate_unused_debug_types)
23745 /* The pubtypes table might be emptied by pruning unused items. */
23749 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
23750 if (p->die->die_offset != 0)
23758 gcc_assert (info_section_emitted);
23759 switch_to_section (debug_pubtypes_section);
23760 output_pubnames (pubtype_table);
23764 /* Output direct and virtual call tables if necessary. */
23765 if (!VEC_empty (dcall_entry, dcall_table))
23767 switch_to_section (debug_dcall_section);
23768 output_dcall_table ();
23770 if (!VEC_empty (vcall_entry, vcall_table))
23772 switch_to_section (debug_vcall_section);
23773 output_vcall_table ();
23776 /* Output the address range information. We only put functions in the
23777 arange table, so don't write it out if we don't have any. */
23778 if (info_section_emitted)
23780 unsigned long aranges_length = size_of_aranges ();
23782 /* Empty .debug_aranges would contain just header and
23783 terminating 0,0. */
23785 != (unsigned long) (DWARF_ARANGES_HEADER_SIZE
23786 + 2 * DWARF2_ADDR_SIZE))
23788 switch_to_section (debug_aranges_section);
23789 output_aranges (aranges_length);
23793 /* Output ranges section if necessary. */
23794 if (ranges_table_in_use)
23796 switch_to_section (debug_ranges_section);
23797 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
23801 /* Output the source line correspondence table. We must do this
23802 even if there is no line information. Otherwise, on an empty
23803 translation unit, we will generate a present, but empty,
23804 .debug_info section. IRIX 6.5 `nm' will then complain when
23805 examining the file. This is done late so that any filenames
23806 used by the debug_info section are marked as 'used'. */
23807 switch_to_section (debug_line_section);
23808 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
23809 if (! DWARF2_ASM_LINE_DEBUG_INFO)
23810 output_line_info ();
23812 /* Have to end the macro section. */
23813 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23815 switch_to_section (debug_macinfo_section);
23816 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
23817 if (!VEC_empty (macinfo_entry, macinfo_table))
23819 dw2_asm_output_data (1, 0, "End compilation unit");
23822 /* If we emitted any DW_FORM_strp form attribute, output the string
23824 if (debug_str_hash)
23825 htab_traverse (debug_str_hash, output_indirect_string, NULL);
23828 #include "gt-dwarf2out.h"