1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "langhooks.h"
93 #include "tree-pass.h"
94 #include "tree-flow.h"
95 #include "cfglayout.h"
97 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
98 static rtx last_var_location_insn;
100 #ifdef VMS_DEBUGGING_INFO
101 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
103 /* Define this macro to be a nonzero value if the directory specifications
104 which are output in the debug info should end with a separator. */
105 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
106 /* Define this macro to evaluate to a nonzero value if GCC should refrain
107 from generating indirect strings in DWARF2 debug information, for instance
108 if your target is stuck with an old version of GDB that is unable to
109 process them properly or uses VMS Debug. */
110 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
116 /* ??? Poison these here until it can be done generically. They've been
117 totally replaced in this file; make sure it stays that way. */
118 #undef DWARF2_UNWIND_INFO
119 #undef DWARF2_FRAME_INFO
120 #if (GCC_VERSION >= 3000)
121 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
124 #ifndef INCOMING_RETURN_ADDR_RTX
125 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
128 /* Map register numbers held in the call frame info that gcc has
129 collected using DWARF_FRAME_REGNUM to those that should be output in
130 .debug_frame and .eh_frame. */
131 #ifndef DWARF2_FRAME_REG_OUT
132 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
135 /* Save the result of dwarf2out_do_frame across PCH. */
136 static GTY(()) bool saved_do_cfi_asm = 0;
138 /* Decide whether we want to emit frame unwind information for the current
142 dwarf2out_do_frame (void)
144 /* We want to emit correct CFA location expressions or lists, so we
145 have to return true if we're going to output debug info, even if
146 we're not going to output frame or unwind info. */
147 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
150 if (saved_do_cfi_asm)
153 if (targetm.debug_unwind_info () == UI_DWARF2)
156 if ((flag_unwind_tables || flag_exceptions)
157 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
163 /* Decide whether to emit frame unwind via assembler directives. */
166 dwarf2out_do_cfi_asm (void)
170 #ifdef MIPS_DEBUGGING_INFO
173 if (saved_do_cfi_asm)
175 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
177 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
180 /* Make sure the personality encoding is one the assembler can support.
181 In particular, aligned addresses can't be handled. */
182 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
183 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
185 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
186 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
189 /* If we can't get the assembler to emit only .debug_frame, and we don't need
190 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
191 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
192 && !flag_unwind_tables && !flag_exceptions
193 && targetm.except_unwind_info (&global_options) != UI_DWARF2)
196 saved_do_cfi_asm = true;
200 /* The size of the target's pointer type. */
202 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
205 /* Array of RTXes referenced by the debugging information, which therefore
206 must be kept around forever. */
207 static GTY(()) VEC(rtx,gc) *used_rtx_array;
209 /* A pointer to the base of a list of incomplete types which might be
210 completed at some later time. incomplete_types_list needs to be a
211 VEC(tree,gc) because we want to tell the garbage collector about
213 static GTY(()) VEC(tree,gc) *incomplete_types;
215 /* A pointer to the base of a table of references to declaration
216 scopes. This table is a display which tracks the nesting
217 of declaration scopes at the current scope and containing
218 scopes. This table is used to find the proper place to
219 define type declaration DIE's. */
220 static GTY(()) VEC(tree,gc) *decl_scope_table;
222 /* Pointers to various DWARF2 sections. */
223 static GTY(()) section *debug_info_section;
224 static GTY(()) section *debug_abbrev_section;
225 static GTY(()) section *debug_aranges_section;
226 static GTY(()) section *debug_macinfo_section;
227 static GTY(()) section *debug_line_section;
228 static GTY(()) section *debug_loc_section;
229 static GTY(()) section *debug_pubnames_section;
230 static GTY(()) section *debug_pubtypes_section;
231 static GTY(()) section *debug_str_section;
232 static GTY(()) section *debug_ranges_section;
233 static GTY(()) section *debug_frame_section;
235 /* Personality decl of current unit. Used only when assembler does not support
237 static GTY(()) rtx current_unit_personality;
239 /* How to start an assembler comment. */
240 #ifndef ASM_COMMENT_START
241 #define ASM_COMMENT_START ";#"
244 typedef struct dw_cfi_struct *dw_cfi_ref;
245 typedef struct dw_fde_struct *dw_fde_ref;
246 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
248 /* Call frames are described using a sequence of Call Frame
249 Information instructions. The register number, offset
250 and address fields are provided as possible operands;
251 their use is selected by the opcode field. */
253 enum dw_cfi_oprnd_type {
255 dw_cfi_oprnd_reg_num,
261 typedef union GTY(()) dw_cfi_oprnd_struct {
262 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
263 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
264 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
265 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
269 typedef struct GTY(()) dw_cfi_struct {
270 dw_cfi_ref dw_cfi_next;
271 enum dwarf_call_frame_info dw_cfi_opc;
272 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
274 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
279 /* This is how we define the location of the CFA. We use to handle it
280 as REG + OFFSET all the time, but now it can be more complex.
281 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
282 Instead of passing around REG and OFFSET, we pass a copy
283 of this structure. */
284 typedef struct cfa_loc {
285 HOST_WIDE_INT offset;
286 HOST_WIDE_INT base_offset;
288 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
289 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
292 /* All call frame descriptions (FDE's) in the GCC generated DWARF
293 refer to a single Common Information Entry (CIE), defined at
294 the beginning of the .debug_frame section. This use of a single
295 CIE obviates the need to keep track of multiple CIE's
296 in the DWARF generation routines below. */
298 typedef struct GTY(()) dw_fde_struct {
300 const char *dw_fde_begin;
301 const char *dw_fde_current_label;
302 const char *dw_fde_end;
303 const char *dw_fde_vms_end_prologue;
304 const char *dw_fde_vms_begin_epilogue;
305 const char *dw_fde_hot_section_label;
306 const char *dw_fde_hot_section_end_label;
307 const char *dw_fde_unlikely_section_label;
308 const char *dw_fde_unlikely_section_end_label;
309 dw_cfi_ref dw_fde_cfi;
310 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
311 HOST_WIDE_INT stack_realignment;
312 unsigned funcdef_number;
313 /* Dynamic realign argument pointer register. */
314 unsigned int drap_reg;
315 /* Virtual dynamic realign argument pointer register. */
316 unsigned int vdrap_reg;
317 /* These 3 flags are copied from rtl_data in function.h. */
318 unsigned all_throwers_are_sibcalls : 1;
319 unsigned uses_eh_lsda : 1;
320 unsigned nothrow : 1;
321 /* Whether we did stack realign in this call frame. */
322 unsigned stack_realign : 1;
323 /* Whether dynamic realign argument pointer register has been saved. */
324 unsigned drap_reg_saved: 1;
325 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
326 unsigned in_std_section : 1;
327 /* True iff dw_fde_unlikely_section_label is in text_section or
328 cold_text_section. */
329 unsigned cold_in_std_section : 1;
330 /* True iff switched sections. */
331 unsigned dw_fde_switched_sections : 1;
332 /* True iff switching from cold to hot section. */
333 unsigned dw_fde_switched_cold_to_hot : 1;
337 /* Maximum size (in bytes) of an artificially generated label. */
338 #define MAX_ARTIFICIAL_LABEL_BYTES 30
340 /* The size of addresses as they appear in the Dwarf 2 data.
341 Some architectures use word addresses to refer to code locations,
342 but Dwarf 2 info always uses byte addresses. On such machines,
343 Dwarf 2 addresses need to be larger than the architecture's
345 #ifndef DWARF2_ADDR_SIZE
346 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
349 /* The size in bytes of a DWARF field indicating an offset or length
350 relative to a debug info section, specified to be 4 bytes in the
351 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
354 #ifndef DWARF_OFFSET_SIZE
355 #define DWARF_OFFSET_SIZE 4
358 /* The size in bytes of a DWARF 4 type signature. */
360 #ifndef DWARF_TYPE_SIGNATURE_SIZE
361 #define DWARF_TYPE_SIGNATURE_SIZE 8
364 /* According to the (draft) DWARF 3 specification, the initial length
365 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
366 bytes are 0xffffffff, followed by the length stored in the next 8
369 However, the SGI/MIPS ABI uses an initial length which is equal to
370 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
372 #ifndef DWARF_INITIAL_LENGTH_SIZE
373 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
376 /* Round SIZE up to the nearest BOUNDARY. */
377 #define DWARF_ROUND(SIZE,BOUNDARY) \
378 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
380 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
381 #ifndef DWARF_CIE_DATA_ALIGNMENT
382 #ifdef STACK_GROWS_DOWNWARD
383 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
385 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
389 /* CIE identifier. */
390 #if HOST_BITS_PER_WIDE_INT >= 64
391 #define DWARF_CIE_ID \
392 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
394 #define DWARF_CIE_ID DW_CIE_ID
397 /* A pointer to the base of a table that contains frame description
398 information for each routine. */
399 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
401 /* Number of elements currently allocated for fde_table. */
402 static GTY(()) unsigned fde_table_allocated;
404 /* Number of elements in fde_table currently in use. */
405 static GTY(()) unsigned fde_table_in_use;
407 /* Size (in elements) of increments by which we may expand the
409 #define FDE_TABLE_INCREMENT 256
411 /* Get the current fde_table entry we should use. */
413 static inline dw_fde_ref
416 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
419 /* A list of call frame insns for the CIE. */
420 static GTY(()) dw_cfi_ref cie_cfi_head;
422 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
423 attribute that accelerates the lookup of the FDE associated
424 with the subprogram. This variable holds the table index of the FDE
425 associated with the current function (body) definition. */
426 static unsigned current_funcdef_fde;
428 struct GTY(()) indirect_string_node {
430 unsigned int refcount;
431 enum dwarf_form form;
435 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
437 /* True if the compilation unit has location entries that reference
439 static GTY(()) bool debug_str_hash_forced = false;
441 static GTY(()) int dw2_string_counter;
442 static GTY(()) unsigned long dwarf2out_cfi_label_num;
444 /* True if the compilation unit places functions in more than one section. */
445 static GTY(()) bool have_multiple_function_sections = false;
447 /* Whether the default text and cold text sections have been used at all. */
449 static GTY(()) bool text_section_used = false;
450 static GTY(()) bool cold_text_section_used = false;
452 /* The default cold text section. */
453 static GTY(()) section *cold_text_section;
455 /* Forward declarations for functions defined in this file. */
457 static char *stripattributes (const char *);
458 static const char *dwarf_cfi_name (unsigned);
459 static dw_cfi_ref new_cfi (void);
460 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
461 static void add_fde_cfi (const char *, dw_cfi_ref);
462 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
463 static void lookup_cfa (dw_cfa_location *);
464 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
465 static void initial_return_save (rtx);
466 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
468 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
469 static void output_cfi_directive (dw_cfi_ref);
470 static void output_call_frame_info (int);
471 static void dwarf2out_note_section_used (void);
472 static bool clobbers_queued_reg_save (const_rtx);
473 static void dwarf2out_frame_debug_expr (rtx, const char *);
475 /* Support for complex CFA locations. */
476 static void output_cfa_loc (dw_cfi_ref, int);
477 static void output_cfa_loc_raw (dw_cfi_ref);
478 static void get_cfa_from_loc_descr (dw_cfa_location *,
479 struct dw_loc_descr_struct *);
480 static struct dw_loc_descr_struct *build_cfa_loc
481 (dw_cfa_location *, HOST_WIDE_INT);
482 static struct dw_loc_descr_struct *build_cfa_aligned_loc
483 (HOST_WIDE_INT, HOST_WIDE_INT);
484 static void def_cfa_1 (const char *, dw_cfa_location *);
485 static struct dw_loc_descr_struct *mem_loc_descriptor
486 (rtx, enum machine_mode mode, enum var_init_status);
488 /* How to start an assembler comment. */
489 #ifndef ASM_COMMENT_START
490 #define ASM_COMMENT_START ";#"
493 /* Data and reference forms for relocatable data. */
494 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
495 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
497 #ifndef DEBUG_FRAME_SECTION
498 #define DEBUG_FRAME_SECTION ".debug_frame"
501 #ifndef FUNC_BEGIN_LABEL
502 #define FUNC_BEGIN_LABEL "LFB"
505 #ifndef FUNC_END_LABEL
506 #define FUNC_END_LABEL "LFE"
509 #ifndef PROLOGUE_END_LABEL
510 #define PROLOGUE_END_LABEL "LPE"
513 #ifndef EPILOGUE_BEGIN_LABEL
514 #define EPILOGUE_BEGIN_LABEL "LEB"
517 #ifndef FRAME_BEGIN_LABEL
518 #define FRAME_BEGIN_LABEL "Lframe"
520 #define CIE_AFTER_SIZE_LABEL "LSCIE"
521 #define CIE_END_LABEL "LECIE"
522 #define FDE_LABEL "LSFDE"
523 #define FDE_AFTER_SIZE_LABEL "LASFDE"
524 #define FDE_END_LABEL "LEFDE"
525 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
526 #define LINE_NUMBER_END_LABEL "LELT"
527 #define LN_PROLOG_AS_LABEL "LASLTP"
528 #define LN_PROLOG_END_LABEL "LELTP"
529 #define DIE_LABEL_PREFIX "DW"
531 /* The DWARF 2 CFA column which tracks the return address. Normally this
532 is the column for PC, or the first column after all of the hard
534 #ifndef DWARF_FRAME_RETURN_COLUMN
536 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
538 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
542 /* The mapping from gcc register number to DWARF 2 CFA column number. By
543 default, we just provide columns for all registers. */
544 #ifndef DWARF_FRAME_REGNUM
545 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
548 /* Match the base name of a file to the base name of a compilation unit. */
551 matches_main_base (const char *path)
553 /* Cache the last query. */
554 static const char *last_path = NULL;
555 static int last_match = 0;
556 if (path != last_path)
559 int length = base_of_path (path, &base);
561 last_match = (length == main_input_baselength
562 && memcmp (base, main_input_basename, length) == 0);
567 #ifdef DEBUG_DEBUG_STRUCT
570 dump_struct_debug (tree type, enum debug_info_usage usage,
571 enum debug_struct_file criterion, int generic,
572 int matches, int result)
574 /* Find the type name. */
575 tree type_decl = TYPE_STUB_DECL (type);
577 const char *name = 0;
578 if (TREE_CODE (t) == TYPE_DECL)
581 name = IDENTIFIER_POINTER (t);
583 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
585 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
586 matches ? "bas" : "hdr",
587 generic ? "gen" : "ord",
588 usage == DINFO_USAGE_DFN ? ";" :
589 usage == DINFO_USAGE_DIR_USE ? "." : "*",
591 (void*) type_decl, name);
594 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
595 dump_struct_debug (type, usage, criterion, generic, matches, result)
599 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
605 should_emit_struct_debug (tree type, enum debug_info_usage usage)
607 enum debug_struct_file criterion;
609 bool generic = lang_hooks.types.generic_p (type);
612 criterion = debug_struct_generic[usage];
614 criterion = debug_struct_ordinary[usage];
616 if (criterion == DINFO_STRUCT_FILE_NONE)
617 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
618 if (criterion == DINFO_STRUCT_FILE_ANY)
619 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
621 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
623 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
624 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
626 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
627 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
628 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
631 /* Hook used by __throw. */
634 expand_builtin_dwarf_sp_column (void)
636 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
637 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
640 /* Return a pointer to a copy of the section string name S with all
641 attributes stripped off, and an asterisk prepended (for assemble_name). */
644 stripattributes (const char *s)
646 char *stripped = XNEWVEC (char, strlen (s) + 2);
651 while (*s && *s != ',')
658 /* MEM is a memory reference for the register size table, each element of
659 which has mode MODE. Initialize column C as a return address column. */
662 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
664 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
665 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
666 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
669 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
671 static inline HOST_WIDE_INT
672 div_data_align (HOST_WIDE_INT off)
674 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
675 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
679 /* Return true if we need a signed version of a given opcode
680 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
683 need_data_align_sf_opcode (HOST_WIDE_INT off)
685 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
688 /* Generate code to initialize the register size table. */
691 expand_builtin_init_dwarf_reg_sizes (tree address)
694 enum machine_mode mode = TYPE_MODE (char_type_node);
695 rtx addr = expand_normal (address);
696 rtx mem = gen_rtx_MEM (BLKmode, addr);
697 bool wrote_return_column = false;
699 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
701 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
703 if (rnum < DWARF_FRAME_REGISTERS)
705 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
706 enum machine_mode save_mode = reg_raw_mode[i];
709 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
710 save_mode = choose_hard_reg_mode (i, 1, true);
711 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
713 if (save_mode == VOIDmode)
715 wrote_return_column = true;
717 size = GET_MODE_SIZE (save_mode);
721 emit_move_insn (adjust_address (mem, mode, offset),
722 gen_int_mode (size, mode));
726 if (!wrote_return_column)
727 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
729 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
730 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
733 targetm.init_dwarf_reg_sizes_extra (address);
736 /* Convert a DWARF call frame info. operation to its string name */
739 dwarf_cfi_name (unsigned int cfi_opc)
743 case DW_CFA_advance_loc:
744 return "DW_CFA_advance_loc";
746 return "DW_CFA_offset";
748 return "DW_CFA_restore";
752 return "DW_CFA_set_loc";
753 case DW_CFA_advance_loc1:
754 return "DW_CFA_advance_loc1";
755 case DW_CFA_advance_loc2:
756 return "DW_CFA_advance_loc2";
757 case DW_CFA_advance_loc4:
758 return "DW_CFA_advance_loc4";
759 case DW_CFA_offset_extended:
760 return "DW_CFA_offset_extended";
761 case DW_CFA_restore_extended:
762 return "DW_CFA_restore_extended";
763 case DW_CFA_undefined:
764 return "DW_CFA_undefined";
765 case DW_CFA_same_value:
766 return "DW_CFA_same_value";
767 case DW_CFA_register:
768 return "DW_CFA_register";
769 case DW_CFA_remember_state:
770 return "DW_CFA_remember_state";
771 case DW_CFA_restore_state:
772 return "DW_CFA_restore_state";
774 return "DW_CFA_def_cfa";
775 case DW_CFA_def_cfa_register:
776 return "DW_CFA_def_cfa_register";
777 case DW_CFA_def_cfa_offset:
778 return "DW_CFA_def_cfa_offset";
781 case DW_CFA_def_cfa_expression:
782 return "DW_CFA_def_cfa_expression";
783 case DW_CFA_expression:
784 return "DW_CFA_expression";
785 case DW_CFA_offset_extended_sf:
786 return "DW_CFA_offset_extended_sf";
787 case DW_CFA_def_cfa_sf:
788 return "DW_CFA_def_cfa_sf";
789 case DW_CFA_def_cfa_offset_sf:
790 return "DW_CFA_def_cfa_offset_sf";
792 /* SGI/MIPS specific */
793 case DW_CFA_MIPS_advance_loc8:
794 return "DW_CFA_MIPS_advance_loc8";
797 case DW_CFA_GNU_window_save:
798 return "DW_CFA_GNU_window_save";
799 case DW_CFA_GNU_args_size:
800 return "DW_CFA_GNU_args_size";
801 case DW_CFA_GNU_negative_offset_extended:
802 return "DW_CFA_GNU_negative_offset_extended";
805 return "DW_CFA_<unknown>";
809 /* Return a pointer to a newly allocated Call Frame Instruction. */
811 static inline dw_cfi_ref
814 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
816 cfi->dw_cfi_next = NULL;
817 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
818 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
823 /* Add a Call Frame Instruction to list of instructions. */
826 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
829 dw_fde_ref fde = current_fde ();
831 /* When DRAP is used, CFA is defined with an expression. Redefine
832 CFA may lead to a different CFA value. */
833 /* ??? Of course, this heuristic fails when we're annotating epilogues,
834 because of course we'll always want to redefine the CFA back to the
835 stack pointer on the way out. Where should we move this check? */
836 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
837 switch (cfi->dw_cfi_opc)
839 case DW_CFA_def_cfa_register:
840 case DW_CFA_def_cfa_offset:
841 case DW_CFA_def_cfa_offset_sf:
843 case DW_CFA_def_cfa_sf:
850 /* Find the end of the chain. */
851 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
857 /* Generate a new label for the CFI info to refer to. FORCE is true
858 if a label needs to be output even when using .cfi_* directives. */
861 dwarf2out_cfi_label (bool force)
863 static char label[20];
865 if (!force && dwarf2out_do_cfi_asm ())
867 /* In this case, we will be emitting the asm directive instead of
868 the label, so just return a placeholder to keep the rest of the
870 strcpy (label, "<do not output>");
874 int num = dwarf2out_cfi_label_num++;
875 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
876 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
882 /* True if remember_state should be emitted before following CFI directive. */
883 static bool emit_cfa_remember;
885 /* True if any CFI directives were emitted at the current insn. */
886 static bool any_cfis_emitted;
888 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
889 or to the CIE if LABEL is NULL. */
892 add_fde_cfi (const char *label, dw_cfi_ref cfi)
894 dw_cfi_ref *list_head;
896 if (emit_cfa_remember)
898 dw_cfi_ref cfi_remember;
900 /* Emit the state save. */
901 emit_cfa_remember = false;
902 cfi_remember = new_cfi ();
903 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
904 add_fde_cfi (label, cfi_remember);
907 list_head = &cie_cfi_head;
909 if (dwarf2out_do_cfi_asm ())
913 dw_fde_ref fde = current_fde ();
915 gcc_assert (fde != NULL);
917 /* We still have to add the cfi to the list so that lookup_cfa
918 works later on. When -g2 and above we even need to force
919 emitting of CFI labels and add to list a DW_CFA_set_loc for
920 convert_cfa_to_fb_loc_list purposes. If we're generating
921 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
922 convert_cfa_to_fb_loc_list. */
923 if (dwarf_version == 2
924 && debug_info_level > DINFO_LEVEL_TERSE
925 && (write_symbols == DWARF2_DEBUG
926 || write_symbols == VMS_AND_DWARF2_DEBUG))
928 switch (cfi->dw_cfi_opc)
930 case DW_CFA_def_cfa_offset:
931 case DW_CFA_def_cfa_offset_sf:
932 case DW_CFA_def_cfa_register:
934 case DW_CFA_def_cfa_sf:
935 case DW_CFA_def_cfa_expression:
936 case DW_CFA_restore_state:
937 if (*label == 0 || strcmp (label, "<do not output>") == 0)
938 label = dwarf2out_cfi_label (true);
940 if (fde->dw_fde_current_label == NULL
941 || strcmp (label, fde->dw_fde_current_label) != 0)
945 label = xstrdup (label);
947 /* Set the location counter to the new label. */
949 /* It doesn't metter whether DW_CFA_set_loc
950 or DW_CFA_advance_loc4 is added here, those aren't
951 emitted into assembly, only looked up by
952 convert_cfa_to_fb_loc_list. */
953 xcfi->dw_cfi_opc = DW_CFA_set_loc;
954 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
955 add_cfi (&fde->dw_fde_cfi, xcfi);
956 fde->dw_fde_current_label = label;
964 output_cfi_directive (cfi);
966 list_head = &fde->dw_fde_cfi;
967 any_cfis_emitted = true;
969 /* ??? If this is a CFI for the CIE, we don't emit. This
970 assumes that the standard CIE contents that the assembler
971 uses matches the standard CIE contents that the compiler
972 uses. This is probably a bad assumption. I'm not quite
973 sure how to address this for now. */
977 dw_fde_ref fde = current_fde ();
979 gcc_assert (fde != NULL);
982 label = dwarf2out_cfi_label (false);
984 if (fde->dw_fde_current_label == NULL
985 || strcmp (label, fde->dw_fde_current_label) != 0)
989 label = xstrdup (label);
991 /* Set the location counter to the new label. */
993 /* If we have a current label, advance from there, otherwise
994 set the location directly using set_loc. */
995 xcfi->dw_cfi_opc = fde->dw_fde_current_label
996 ? DW_CFA_advance_loc4
998 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
999 add_cfi (&fde->dw_fde_cfi, xcfi);
1001 fde->dw_fde_current_label = label;
1004 list_head = &fde->dw_fde_cfi;
1005 any_cfis_emitted = true;
1008 add_cfi (list_head, cfi);
1011 /* Subroutine of lookup_cfa. */
1014 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
1016 switch (cfi->dw_cfi_opc)
1018 case DW_CFA_def_cfa_offset:
1019 case DW_CFA_def_cfa_offset_sf:
1020 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
1022 case DW_CFA_def_cfa_register:
1023 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1025 case DW_CFA_def_cfa:
1026 case DW_CFA_def_cfa_sf:
1027 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1028 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
1030 case DW_CFA_def_cfa_expression:
1031 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
1034 case DW_CFA_remember_state:
1035 gcc_assert (!remember->in_use);
1037 remember->in_use = 1;
1039 case DW_CFA_restore_state:
1040 gcc_assert (remember->in_use);
1042 remember->in_use = 0;
1050 /* Find the previous value for the CFA. */
1053 lookup_cfa (dw_cfa_location *loc)
1057 dw_cfa_location remember;
1059 memset (loc, 0, sizeof (*loc));
1060 loc->reg = INVALID_REGNUM;
1063 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
1064 lookup_cfa_1 (cfi, loc, &remember);
1066 fde = current_fde ();
1068 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
1069 lookup_cfa_1 (cfi, loc, &remember);
1072 /* The current rule for calculating the DWARF2 canonical frame address. */
1073 static dw_cfa_location cfa;
1075 /* The register used for saving registers to the stack, and its offset
1077 static dw_cfa_location cfa_store;
1079 /* The current save location around an epilogue. */
1080 static dw_cfa_location cfa_remember;
1082 /* The running total of the size of arguments pushed onto the stack. */
1083 static HOST_WIDE_INT args_size;
1085 /* The last args_size we actually output. */
1086 static HOST_WIDE_INT old_args_size;
1088 /* Entry point to update the canonical frame address (CFA).
1089 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1090 calculated from REG+OFFSET. */
1093 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1095 dw_cfa_location loc;
1097 loc.base_offset = 0;
1099 loc.offset = offset;
1100 def_cfa_1 (label, &loc);
1103 /* Determine if two dw_cfa_location structures define the same data. */
1106 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1108 return (loc1->reg == loc2->reg
1109 && loc1->offset == loc2->offset
1110 && loc1->indirect == loc2->indirect
1111 && (loc1->indirect == 0
1112 || loc1->base_offset == loc2->base_offset));
1115 /* This routine does the actual work. The CFA is now calculated from
1116 the dw_cfa_location structure. */
1119 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1122 dw_cfa_location old_cfa, loc;
1127 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1128 cfa_store.offset = loc.offset;
1130 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1131 lookup_cfa (&old_cfa);
1133 /* If nothing changed, no need to issue any call frame instructions. */
1134 if (cfa_equal_p (&loc, &old_cfa))
1139 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1141 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1142 the CFA register did not change but the offset did. The data
1143 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1144 in the assembler via the .cfi_def_cfa_offset directive. */
1146 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1148 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1149 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1152 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1153 else if (loc.offset == old_cfa.offset
1154 && old_cfa.reg != INVALID_REGNUM
1156 && !old_cfa.indirect)
1158 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1159 indicating the CFA register has changed to <register> but the
1160 offset has not changed. */
1161 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1162 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1166 else if (loc.indirect == 0)
1168 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1169 indicating the CFA register has changed to <register> with
1170 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1171 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1174 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1176 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1177 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1178 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1182 /* Construct a DW_CFA_def_cfa_expression instruction to
1183 calculate the CFA using a full location expression since no
1184 register-offset pair is available. */
1185 struct dw_loc_descr_struct *loc_list;
1187 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1188 loc_list = build_cfa_loc (&loc, 0);
1189 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1192 add_fde_cfi (label, cfi);
1195 /* Add the CFI for saving a register. REG is the CFA column number.
1196 LABEL is passed to add_fde_cfi.
1197 If SREG is -1, the register is saved at OFFSET from the CFA;
1198 otherwise it is saved in SREG. */
1201 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1203 dw_cfi_ref cfi = new_cfi ();
1204 dw_fde_ref fde = current_fde ();
1206 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1208 /* When stack is aligned, store REG using DW_CFA_expression with
1211 && fde->stack_realign
1212 && sreg == INVALID_REGNUM)
1214 cfi->dw_cfi_opc = DW_CFA_expression;
1215 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1216 cfi->dw_cfi_oprnd2.dw_cfi_loc
1217 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1219 else if (sreg == INVALID_REGNUM)
1221 if (need_data_align_sf_opcode (offset))
1222 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1223 else if (reg & ~0x3f)
1224 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1226 cfi->dw_cfi_opc = DW_CFA_offset;
1227 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1229 else if (sreg == reg)
1230 cfi->dw_cfi_opc = DW_CFA_same_value;
1233 cfi->dw_cfi_opc = DW_CFA_register;
1234 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1237 add_fde_cfi (label, cfi);
1240 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1241 This CFI tells the unwinder that it needs to restore the window registers
1242 from the previous frame's window save area.
1244 ??? Perhaps we should note in the CIE where windows are saved (instead of
1245 assuming 0(cfa)) and what registers are in the window. */
1248 dwarf2out_window_save (const char *label)
1250 dw_cfi_ref cfi = new_cfi ();
1252 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1253 add_fde_cfi (label, cfi);
1256 /* Entry point for saving a register to the stack. REG is the GCC register
1257 number. LABEL and OFFSET are passed to reg_save. */
1260 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1262 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1265 /* Entry point for saving the return address in the stack.
1266 LABEL and OFFSET are passed to reg_save. */
1269 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1271 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1274 /* Entry point for saving the return address in a register.
1275 LABEL and SREG are passed to reg_save. */
1278 dwarf2out_return_reg (const char *label, unsigned int sreg)
1280 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1283 /* Record the initial position of the return address. RTL is
1284 INCOMING_RETURN_ADDR_RTX. */
1287 initial_return_save (rtx rtl)
1289 unsigned int reg = INVALID_REGNUM;
1290 HOST_WIDE_INT offset = 0;
1292 switch (GET_CODE (rtl))
1295 /* RA is in a register. */
1296 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1300 /* RA is on the stack. */
1301 rtl = XEXP (rtl, 0);
1302 switch (GET_CODE (rtl))
1305 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1310 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1311 offset = INTVAL (XEXP (rtl, 1));
1315 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1316 offset = -INTVAL (XEXP (rtl, 1));
1326 /* The return address is at some offset from any value we can
1327 actually load. For instance, on the SPARC it is in %i7+8. Just
1328 ignore the offset for now; it doesn't matter for unwinding frames. */
1329 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1330 initial_return_save (XEXP (rtl, 0));
1337 if (reg != DWARF_FRAME_RETURN_COLUMN)
1338 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1341 /* Given a SET, calculate the amount of stack adjustment it
1344 static HOST_WIDE_INT
1345 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1346 HOST_WIDE_INT cur_offset)
1348 const_rtx src = SET_SRC (pattern);
1349 const_rtx dest = SET_DEST (pattern);
1350 HOST_WIDE_INT offset = 0;
1353 if (dest == stack_pointer_rtx)
1355 code = GET_CODE (src);
1357 /* Assume (set (reg sp) (reg whatever)) sets args_size
1359 if (code == REG && src != stack_pointer_rtx)
1361 offset = -cur_args_size;
1362 #ifndef STACK_GROWS_DOWNWARD
1365 return offset - cur_offset;
1368 if (! (code == PLUS || code == MINUS)
1369 || XEXP (src, 0) != stack_pointer_rtx
1370 || !CONST_INT_P (XEXP (src, 1)))
1373 /* (set (reg sp) (plus (reg sp) (const_int))) */
1374 offset = INTVAL (XEXP (src, 1));
1380 if (MEM_P (src) && !MEM_P (dest))
1384 /* (set (mem (pre_dec (reg sp))) (foo)) */
1385 src = XEXP (dest, 0);
1386 code = GET_CODE (src);
1392 if (XEXP (src, 0) == stack_pointer_rtx)
1394 rtx val = XEXP (XEXP (src, 1), 1);
1395 /* We handle only adjustments by constant amount. */
1396 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1397 && CONST_INT_P (val));
1398 offset = -INTVAL (val);
1405 if (XEXP (src, 0) == stack_pointer_rtx)
1407 offset = GET_MODE_SIZE (GET_MODE (dest));
1414 if (XEXP (src, 0) == stack_pointer_rtx)
1416 offset = -GET_MODE_SIZE (GET_MODE (dest));
1431 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1432 indexed by INSN_UID. */
1434 static HOST_WIDE_INT *barrier_args_size;
1436 /* Helper function for compute_barrier_args_size. Handle one insn. */
1438 static HOST_WIDE_INT
1439 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1440 VEC (rtx, heap) **next)
1442 HOST_WIDE_INT offset = 0;
1445 if (! RTX_FRAME_RELATED_P (insn))
1447 if (prologue_epilogue_contains (insn))
1449 else if (GET_CODE (PATTERN (insn)) == SET)
1450 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1451 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1452 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1454 /* There may be stack adjustments inside compound insns. Search
1456 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1457 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1458 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1459 cur_args_size, offset);
1464 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1468 expr = XEXP (expr, 0);
1469 if (GET_CODE (expr) == PARALLEL
1470 || GET_CODE (expr) == SEQUENCE)
1471 for (i = 1; i < XVECLEN (expr, 0); i++)
1473 rtx elem = XVECEXP (expr, 0, i);
1475 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1476 offset += stack_adjust_offset (elem, cur_args_size, offset);
1481 #ifndef STACK_GROWS_DOWNWARD
1485 cur_args_size += offset;
1486 if (cur_args_size < 0)
1491 rtx dest = JUMP_LABEL (insn);
1495 if (barrier_args_size [INSN_UID (dest)] < 0)
1497 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1498 VEC_safe_push (rtx, heap, *next, dest);
1503 return cur_args_size;
1506 /* Walk the whole function and compute args_size on BARRIERs. */
1509 compute_barrier_args_size (void)
1511 int max_uid = get_max_uid (), i;
1513 VEC (rtx, heap) *worklist, *next, *tmp;
1515 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1516 for (i = 0; i < max_uid; i++)
1517 barrier_args_size[i] = -1;
1519 worklist = VEC_alloc (rtx, heap, 20);
1520 next = VEC_alloc (rtx, heap, 20);
1521 insn = get_insns ();
1522 barrier_args_size[INSN_UID (insn)] = 0;
1523 VEC_quick_push (rtx, worklist, insn);
1526 while (!VEC_empty (rtx, worklist))
1528 rtx prev, body, first_insn;
1529 HOST_WIDE_INT cur_args_size;
1531 first_insn = insn = VEC_pop (rtx, worklist);
1532 cur_args_size = barrier_args_size[INSN_UID (insn)];
1533 prev = prev_nonnote_insn (insn);
1534 if (prev && BARRIER_P (prev))
1535 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1537 for (; insn; insn = NEXT_INSN (insn))
1539 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1541 if (BARRIER_P (insn))
1546 if (insn == first_insn)
1548 else if (barrier_args_size[INSN_UID (insn)] < 0)
1550 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1555 /* The insns starting with this label have been
1556 already scanned or are in the worklist. */
1561 body = PATTERN (insn);
1562 if (GET_CODE (body) == SEQUENCE)
1564 HOST_WIDE_INT dest_args_size = cur_args_size;
1565 for (i = 1; i < XVECLEN (body, 0); i++)
1566 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1567 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1569 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1570 dest_args_size, &next);
1573 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1574 cur_args_size, &next);
1576 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1577 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1578 dest_args_size, &next);
1581 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1582 cur_args_size, &next);
1586 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1590 if (VEC_empty (rtx, next))
1593 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1597 VEC_truncate (rtx, next, 0);
1600 VEC_free (rtx, heap, worklist);
1601 VEC_free (rtx, heap, next);
1604 /* Add a CFI to update the running total of the size of arguments
1605 pushed onto the stack. */
1608 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1612 if (size == old_args_size)
1615 old_args_size = size;
1618 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1619 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1620 add_fde_cfi (label, cfi);
1623 /* Record a stack adjustment of OFFSET bytes. */
1626 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1628 if (cfa.reg == STACK_POINTER_REGNUM)
1629 cfa.offset += offset;
1631 if (cfa_store.reg == STACK_POINTER_REGNUM)
1632 cfa_store.offset += offset;
1634 if (ACCUMULATE_OUTGOING_ARGS)
1637 #ifndef STACK_GROWS_DOWNWARD
1641 args_size += offset;
1645 def_cfa_1 (label, &cfa);
1646 if (flag_asynchronous_unwind_tables)
1647 dwarf2out_args_size (label, args_size);
1650 /* Check INSN to see if it looks like a push or a stack adjustment, and
1651 make a note of it if it does. EH uses this information to find out
1652 how much extra space it needs to pop off the stack. */
1655 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1657 HOST_WIDE_INT offset;
1661 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1662 with this function. Proper support would require all frame-related
1663 insns to be marked, and to be able to handle saving state around
1664 epilogues textually in the middle of the function. */
1665 if (prologue_epilogue_contains (insn))
1668 /* If INSN is an instruction from target of an annulled branch, the
1669 effects are for the target only and so current argument size
1670 shouldn't change at all. */
1672 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1673 && INSN_FROM_TARGET_P (insn))
1676 /* If only calls can throw, and we have a frame pointer,
1677 save up adjustments until we see the CALL_INSN. */
1678 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1680 if (CALL_P (insn) && !after_p)
1682 /* Extract the size of the args from the CALL rtx itself. */
1683 insn = PATTERN (insn);
1684 if (GET_CODE (insn) == PARALLEL)
1685 insn = XVECEXP (insn, 0, 0);
1686 if (GET_CODE (insn) == SET)
1687 insn = SET_SRC (insn);
1688 gcc_assert (GET_CODE (insn) == CALL);
1689 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1694 if (CALL_P (insn) && !after_p)
1696 if (!flag_asynchronous_unwind_tables)
1697 dwarf2out_args_size ("", args_size);
1700 else if (BARRIER_P (insn))
1702 /* Don't call compute_barrier_args_size () if the only
1703 BARRIER is at the end of function. */
1704 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1705 compute_barrier_args_size ();
1706 if (barrier_args_size == NULL)
1710 offset = barrier_args_size[INSN_UID (insn)];
1715 offset -= args_size;
1716 #ifndef STACK_GROWS_DOWNWARD
1720 else if (GET_CODE (PATTERN (insn)) == SET)
1721 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1722 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1723 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1725 /* There may be stack adjustments inside compound insns. Search
1727 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1728 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1729 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1738 label = dwarf2out_cfi_label (false);
1739 dwarf2out_stack_adjust (offset, label);
1742 /* We delay emitting a register save until either (a) we reach the end
1743 of the prologue or (b) the register is clobbered. This clusters
1744 register saves so that there are fewer pc advances. */
1746 struct GTY(()) queued_reg_save {
1747 struct queued_reg_save *next;
1749 HOST_WIDE_INT cfa_offset;
1753 static GTY(()) struct queued_reg_save *queued_reg_saves;
1755 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1756 struct GTY(()) reg_saved_in_data {
1761 /* A list of registers saved in other registers.
1762 The list intentionally has a small maximum capacity of 4; if your
1763 port needs more than that, you might consider implementing a
1764 more efficient data structure. */
1765 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1766 static GTY(()) size_t num_regs_saved_in_regs;
1768 static const char *last_reg_save_label;
1770 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1771 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1774 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1776 struct queued_reg_save *q;
1778 /* Duplicates waste space, but it's also necessary to remove them
1779 for correctness, since the queue gets output in reverse
1781 for (q = queued_reg_saves; q != NULL; q = q->next)
1782 if (REGNO (q->reg) == REGNO (reg))
1787 q = ggc_alloc_queued_reg_save ();
1788 q->next = queued_reg_saves;
1789 queued_reg_saves = q;
1793 q->cfa_offset = offset;
1794 q->saved_reg = sreg;
1796 last_reg_save_label = label;
1799 /* Output all the entries in QUEUED_REG_SAVES. */
1802 dwarf2out_flush_queued_reg_saves (void)
1804 struct queued_reg_save *q;
1806 for (q = queued_reg_saves; q; q = q->next)
1809 unsigned int reg, sreg;
1811 for (i = 0; i < num_regs_saved_in_regs; i++)
1812 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1814 if (q->saved_reg && i == num_regs_saved_in_regs)
1816 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1817 num_regs_saved_in_regs++;
1819 if (i != num_regs_saved_in_regs)
1821 regs_saved_in_regs[i].orig_reg = q->reg;
1822 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1825 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1827 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1829 sreg = INVALID_REGNUM;
1830 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1833 queued_reg_saves = NULL;
1834 last_reg_save_label = NULL;
1837 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1838 location for? Or, does it clobber a register which we've previously
1839 said that some other register is saved in, and for which we now
1840 have a new location for? */
1843 clobbers_queued_reg_save (const_rtx insn)
1845 struct queued_reg_save *q;
1847 for (q = queued_reg_saves; q; q = q->next)
1850 if (modified_in_p (q->reg, insn))
1852 for (i = 0; i < num_regs_saved_in_regs; i++)
1853 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1854 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1861 /* Entry point for saving the first register into the second. */
1864 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1867 unsigned int regno, sregno;
1869 for (i = 0; i < num_regs_saved_in_regs; i++)
1870 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1872 if (i == num_regs_saved_in_regs)
1874 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1875 num_regs_saved_in_regs++;
1877 regs_saved_in_regs[i].orig_reg = reg;
1878 regs_saved_in_regs[i].saved_in_reg = sreg;
1880 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1881 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1882 reg_save (label, regno, sregno, 0);
1885 /* What register, if any, is currently saved in REG? */
1888 reg_saved_in (rtx reg)
1890 unsigned int regn = REGNO (reg);
1892 struct queued_reg_save *q;
1894 for (q = queued_reg_saves; q; q = q->next)
1895 if (q->saved_reg && regn == REGNO (q->saved_reg))
1898 for (i = 0; i < num_regs_saved_in_regs; i++)
1899 if (regs_saved_in_regs[i].saved_in_reg
1900 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1901 return regs_saved_in_regs[i].orig_reg;
1907 /* A temporary register holding an integral value used in adjusting SP
1908 or setting up the store_reg. The "offset" field holds the integer
1909 value, not an offset. */
1910 static dw_cfa_location cfa_temp;
1912 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1915 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1917 memset (&cfa, 0, sizeof (cfa));
1919 switch (GET_CODE (pat))
1922 cfa.reg = REGNO (XEXP (pat, 0));
1923 cfa.offset = INTVAL (XEXP (pat, 1));
1927 cfa.reg = REGNO (pat);
1932 pat = XEXP (pat, 0);
1933 if (GET_CODE (pat) == PLUS)
1935 cfa.base_offset = INTVAL (XEXP (pat, 1));
1936 pat = XEXP (pat, 0);
1938 cfa.reg = REGNO (pat);
1942 /* Recurse and define an expression. */
1946 def_cfa_1 (label, &cfa);
1949 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1952 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1956 gcc_assert (GET_CODE (pat) == SET);
1957 dest = XEXP (pat, 0);
1958 src = XEXP (pat, 1);
1960 switch (GET_CODE (src))
1963 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1964 cfa.offset -= INTVAL (XEXP (src, 1));
1974 cfa.reg = REGNO (dest);
1975 gcc_assert (cfa.indirect == 0);
1977 def_cfa_1 (label, &cfa);
1980 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1983 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1985 HOST_WIDE_INT offset;
1986 rtx src, addr, span;
1988 src = XEXP (set, 1);
1989 addr = XEXP (set, 0);
1990 gcc_assert (MEM_P (addr));
1991 addr = XEXP (addr, 0);
1993 /* As documented, only consider extremely simple addresses. */
1994 switch (GET_CODE (addr))
1997 gcc_assert (REGNO (addr) == cfa.reg);
1998 offset = -cfa.offset;
2001 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
2002 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2008 span = targetm.dwarf_register_span (src);
2010 /* ??? We'd like to use queue_reg_save, but we need to come up with
2011 a different flushing heuristic for epilogues. */
2013 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2016 /* We have a PARALLEL describing where the contents of SRC live.
2017 Queue register saves for each piece of the PARALLEL. */
2020 HOST_WIDE_INT span_offset = offset;
2022 gcc_assert (GET_CODE (span) == PARALLEL);
2024 limit = XVECLEN (span, 0);
2025 for (par_index = 0; par_index < limit; par_index++)
2027 rtx elem = XVECEXP (span, 0, par_index);
2029 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2030 INVALID_REGNUM, span_offset);
2031 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2036 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2039 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2042 unsigned sregno, dregno;
2044 src = XEXP (set, 1);
2045 dest = XEXP (set, 0);
2048 sregno = DWARF_FRAME_RETURN_COLUMN;
2050 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2052 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2054 /* ??? We'd like to use queue_reg_save, but we need to come up with
2055 a different flushing heuristic for epilogues. */
2056 reg_save (label, sregno, dregno, 0);
2059 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2062 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2064 rtx src, dest, span;
2065 dw_cfi_ref cfi = new_cfi ();
2067 dest = SET_DEST (set);
2068 src = SET_SRC (set);
2070 gcc_assert (REG_P (src));
2071 gcc_assert (MEM_P (dest));
2073 span = targetm.dwarf_register_span (src);
2076 cfi->dw_cfi_opc = DW_CFA_expression;
2077 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2078 cfi->dw_cfi_oprnd2.dw_cfi_loc
2079 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
2080 VAR_INIT_STATUS_INITIALIZED);
2082 /* ??? We'd like to use queue_reg_save, were the interface different,
2083 and, as above, we could manage flushing for epilogues. */
2084 add_fde_cfi (label, cfi);
2087 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2090 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2092 dw_cfi_ref cfi = new_cfi ();
2093 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2095 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2096 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2098 add_fde_cfi (label, cfi);
2101 /* Record call frame debugging information for an expression EXPR,
2102 which either sets SP or FP (adjusting how we calculate the frame
2103 address) or saves a register to the stack or another register.
2104 LABEL indicates the address of EXPR.
2106 This function encodes a state machine mapping rtxes to actions on
2107 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2108 users need not read the source code.
2110 The High-Level Picture
2112 Changes in the register we use to calculate the CFA: Currently we
2113 assume that if you copy the CFA register into another register, we
2114 should take the other one as the new CFA register; this seems to
2115 work pretty well. If it's wrong for some target, it's simple
2116 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2118 Changes in the register we use for saving registers to the stack:
2119 This is usually SP, but not always. Again, we deduce that if you
2120 copy SP into another register (and SP is not the CFA register),
2121 then the new register is the one we will be using for register
2122 saves. This also seems to work.
2124 Register saves: There's not much guesswork about this one; if
2125 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2126 register save, and the register used to calculate the destination
2127 had better be the one we think we're using for this purpose.
2128 It's also assumed that a copy from a call-saved register to another
2129 register is saving that register if RTX_FRAME_RELATED_P is set on
2130 that instruction. If the copy is from a call-saved register to
2131 the *same* register, that means that the register is now the same
2132 value as in the caller.
2134 Except: If the register being saved is the CFA register, and the
2135 offset is nonzero, we are saving the CFA, so we assume we have to
2136 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2137 the intent is to save the value of SP from the previous frame.
2139 In addition, if a register has previously been saved to a different
2142 Invariants / Summaries of Rules
2144 cfa current rule for calculating the CFA. It usually
2145 consists of a register and an offset.
2146 cfa_store register used by prologue code to save things to the stack
2147 cfa_store.offset is the offset from the value of
2148 cfa_store.reg to the actual CFA
2149 cfa_temp register holding an integral value. cfa_temp.offset
2150 stores the value, which will be used to adjust the
2151 stack pointer. cfa_temp is also used like cfa_store,
2152 to track stores to the stack via fp or a temp reg.
2154 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2155 with cfa.reg as the first operand changes the cfa.reg and its
2156 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2159 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2160 expression yielding a constant. This sets cfa_temp.reg
2161 and cfa_temp.offset.
2163 Rule 5: Create a new register cfa_store used to save items to the
2166 Rules 10-14: Save a register to the stack. Define offset as the
2167 difference of the original location and cfa_store's
2168 location (or cfa_temp's location if cfa_temp is used).
2170 Rules 16-20: If AND operation happens on sp in prologue, we assume
2171 stack is realigned. We will use a group of DW_OP_XXX
2172 expressions to represent the location of the stored
2173 register instead of CFA+offset.
2177 "{a,b}" indicates a choice of a xor b.
2178 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2181 (set <reg1> <reg2>:cfa.reg)
2182 effects: cfa.reg = <reg1>
2183 cfa.offset unchanged
2184 cfa_temp.reg = <reg1>
2185 cfa_temp.offset = cfa.offset
2188 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2189 {<const_int>,<reg>:cfa_temp.reg}))
2190 effects: cfa.reg = sp if fp used
2191 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2192 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2193 if cfa_store.reg==sp
2196 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2197 effects: cfa.reg = fp
2198 cfa_offset += +/- <const_int>
2201 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2202 constraints: <reg1> != fp
2204 effects: cfa.reg = <reg1>
2205 cfa_temp.reg = <reg1>
2206 cfa_temp.offset = cfa.offset
2209 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2210 constraints: <reg1> != fp
2212 effects: cfa_store.reg = <reg1>
2213 cfa_store.offset = cfa.offset - cfa_temp.offset
2216 (set <reg> <const_int>)
2217 effects: cfa_temp.reg = <reg>
2218 cfa_temp.offset = <const_int>
2221 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2222 effects: cfa_temp.reg = <reg1>
2223 cfa_temp.offset |= <const_int>
2226 (set <reg> (high <exp>))
2230 (set <reg> (lo_sum <exp> <const_int>))
2231 effects: cfa_temp.reg = <reg>
2232 cfa_temp.offset = <const_int>
2235 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2236 effects: cfa_store.offset -= <const_int>
2237 cfa.offset = cfa_store.offset if cfa.reg == sp
2239 cfa.base_offset = -cfa_store.offset
2242 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2243 effects: cfa_store.offset += -/+ mode_size(mem)
2244 cfa.offset = cfa_store.offset if cfa.reg == sp
2246 cfa.base_offset = -cfa_store.offset
2249 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2252 effects: cfa.reg = <reg1>
2253 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2256 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2257 effects: cfa.reg = <reg1>
2258 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2261 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2262 effects: cfa.reg = <reg1>
2263 cfa.base_offset = -cfa_temp.offset
2264 cfa_temp.offset -= mode_size(mem)
2267 (set <reg> {unspec, unspec_volatile})
2268 effects: target-dependent
2271 (set sp (and: sp <const_int>))
2272 constraints: cfa_store.reg == sp
2273 effects: current_fde.stack_realign = 1
2274 cfa_store.offset = 0
2275 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2278 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2279 effects: cfa_store.offset += -/+ mode_size(mem)
2282 (set (mem ({pre_inc, pre_dec} sp)) fp)
2283 constraints: fde->stack_realign == 1
2284 effects: cfa_store.offset = 0
2285 cfa.reg != HARD_FRAME_POINTER_REGNUM
2288 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2289 constraints: fde->stack_realign == 1
2291 && cfa.indirect == 0
2292 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2293 effects: Use DW_CFA_def_cfa_expression to define cfa
2294 cfa.reg == fde->drap_reg */
2297 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2299 rtx src, dest, span;
2300 HOST_WIDE_INT offset;
2303 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2304 the PARALLEL independently. The first element is always processed if
2305 it is a SET. This is for backward compatibility. Other elements
2306 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2307 flag is set in them. */
2308 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2311 int limit = XVECLEN (expr, 0);
2314 /* PARALLELs have strict read-modify-write semantics, so we
2315 ought to evaluate every rvalue before changing any lvalue.
2316 It's cumbersome to do that in general, but there's an
2317 easy approximation that is enough for all current users:
2318 handle register saves before register assignments. */
2319 if (GET_CODE (expr) == PARALLEL)
2320 for (par_index = 0; par_index < limit; par_index++)
2322 elem = XVECEXP (expr, 0, par_index);
2323 if (GET_CODE (elem) == SET
2324 && MEM_P (SET_DEST (elem))
2325 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2326 dwarf2out_frame_debug_expr (elem, label);
2329 for (par_index = 0; par_index < limit; par_index++)
2331 elem = XVECEXP (expr, 0, par_index);
2332 if (GET_CODE (elem) == SET
2333 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2334 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2335 dwarf2out_frame_debug_expr (elem, label);
2336 else if (GET_CODE (elem) == SET
2338 && !RTX_FRAME_RELATED_P (elem))
2340 /* Stack adjustment combining might combine some post-prologue
2341 stack adjustment into a prologue stack adjustment. */
2342 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2345 dwarf2out_stack_adjust (offset, label);
2351 gcc_assert (GET_CODE (expr) == SET);
2353 src = SET_SRC (expr);
2354 dest = SET_DEST (expr);
2358 rtx rsi = reg_saved_in (src);
2363 fde = current_fde ();
2365 switch (GET_CODE (dest))
2368 switch (GET_CODE (src))
2370 /* Setting FP from SP. */
2372 if (cfa.reg == (unsigned) REGNO (src))
2375 /* Update the CFA rule wrt SP or FP. Make sure src is
2376 relative to the current CFA register.
2378 We used to require that dest be either SP or FP, but the
2379 ARM copies SP to a temporary register, and from there to
2380 FP. So we just rely on the backends to only set
2381 RTX_FRAME_RELATED_P on appropriate insns. */
2382 cfa.reg = REGNO (dest);
2383 cfa_temp.reg = cfa.reg;
2384 cfa_temp.offset = cfa.offset;
2388 /* Saving a register in a register. */
2389 gcc_assert (!fixed_regs [REGNO (dest)]
2390 /* For the SPARC and its register window. */
2391 || (DWARF_FRAME_REGNUM (REGNO (src))
2392 == DWARF_FRAME_RETURN_COLUMN));
2394 /* After stack is aligned, we can only save SP in FP
2395 if drap register is used. In this case, we have
2396 to restore stack pointer with the CFA value and we
2397 don't generate this DWARF information. */
2399 && fde->stack_realign
2400 && REGNO (src) == STACK_POINTER_REGNUM)
2401 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2402 && fde->drap_reg != INVALID_REGNUM
2403 && cfa.reg != REGNO (src));
2405 queue_reg_save (label, src, dest, 0);
2412 if (dest == stack_pointer_rtx)
2416 switch (GET_CODE (XEXP (src, 1)))
2419 offset = INTVAL (XEXP (src, 1));
2422 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2424 offset = cfa_temp.offset;
2430 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2432 /* Restoring SP from FP in the epilogue. */
2433 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2434 cfa.reg = STACK_POINTER_REGNUM;
2436 else if (GET_CODE (src) == LO_SUM)
2437 /* Assume we've set the source reg of the LO_SUM from sp. */
2440 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2442 if (GET_CODE (src) != MINUS)
2444 if (cfa.reg == STACK_POINTER_REGNUM)
2445 cfa.offset += offset;
2446 if (cfa_store.reg == STACK_POINTER_REGNUM)
2447 cfa_store.offset += offset;
2449 else if (dest == hard_frame_pointer_rtx)
2452 /* Either setting the FP from an offset of the SP,
2453 or adjusting the FP */
2454 gcc_assert (frame_pointer_needed);
2456 gcc_assert (REG_P (XEXP (src, 0))
2457 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2458 && CONST_INT_P (XEXP (src, 1)));
2459 offset = INTVAL (XEXP (src, 1));
2460 if (GET_CODE (src) != MINUS)
2462 cfa.offset += offset;
2463 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2467 gcc_assert (GET_CODE (src) != MINUS);
2470 if (REG_P (XEXP (src, 0))
2471 && REGNO (XEXP (src, 0)) == cfa.reg
2472 && CONST_INT_P (XEXP (src, 1)))
2474 /* Setting a temporary CFA register that will be copied
2475 into the FP later on. */
2476 offset = - INTVAL (XEXP (src, 1));
2477 cfa.offset += offset;
2478 cfa.reg = REGNO (dest);
2479 /* Or used to save regs to the stack. */
2480 cfa_temp.reg = cfa.reg;
2481 cfa_temp.offset = cfa.offset;
2485 else if (REG_P (XEXP (src, 0))
2486 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2487 && XEXP (src, 1) == stack_pointer_rtx)
2489 /* Setting a scratch register that we will use instead
2490 of SP for saving registers to the stack. */
2491 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2492 cfa_store.reg = REGNO (dest);
2493 cfa_store.offset = cfa.offset - cfa_temp.offset;
2497 else if (GET_CODE (src) == LO_SUM
2498 && CONST_INT_P (XEXP (src, 1)))
2500 cfa_temp.reg = REGNO (dest);
2501 cfa_temp.offset = INTVAL (XEXP (src, 1));
2510 cfa_temp.reg = REGNO (dest);
2511 cfa_temp.offset = INTVAL (src);
2516 gcc_assert (REG_P (XEXP (src, 0))
2517 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2518 && CONST_INT_P (XEXP (src, 1)));
2520 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2521 cfa_temp.reg = REGNO (dest);
2522 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2525 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2526 which will fill in all of the bits. */
2533 case UNSPEC_VOLATILE:
2534 gcc_assert (targetm.dwarf_handle_frame_unspec);
2535 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2540 /* If this AND operation happens on stack pointer in prologue,
2541 we assume the stack is realigned and we extract the
2543 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2545 /* We interpret reg_save differently with stack_realign set.
2546 Thus we must flush whatever we have queued first. */
2547 dwarf2out_flush_queued_reg_saves ();
2549 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2550 fde->stack_realign = 1;
2551 fde->stack_realignment = INTVAL (XEXP (src, 1));
2552 cfa_store.offset = 0;
2554 if (cfa.reg != STACK_POINTER_REGNUM
2555 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2556 fde->drap_reg = cfa.reg;
2564 def_cfa_1 (label, &cfa);
2569 /* Saving a register to the stack. Make sure dest is relative to the
2571 switch (GET_CODE (XEXP (dest, 0)))
2576 /* We can't handle variable size modifications. */
2577 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2579 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2581 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2582 && cfa_store.reg == STACK_POINTER_REGNUM);
2584 cfa_store.offset += offset;
2585 if (cfa.reg == STACK_POINTER_REGNUM)
2586 cfa.offset = cfa_store.offset;
2588 offset = -cfa_store.offset;
2595 offset = GET_MODE_SIZE (GET_MODE (dest));
2596 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2599 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2600 == STACK_POINTER_REGNUM)
2601 && cfa_store.reg == STACK_POINTER_REGNUM);
2603 cfa_store.offset += offset;
2605 /* Rule 18: If stack is aligned, we will use FP as a
2606 reference to represent the address of the stored
2609 && fde->stack_realign
2610 && src == hard_frame_pointer_rtx)
2612 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2613 cfa_store.offset = 0;
2616 if (cfa.reg == STACK_POINTER_REGNUM)
2617 cfa.offset = cfa_store.offset;
2619 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
2620 offset += -cfa_store.offset;
2622 offset = -cfa_store.offset;
2626 /* With an offset. */
2633 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2634 && REG_P (XEXP (XEXP (dest, 0), 0)));
2635 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2636 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2639 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2641 if (cfa.reg == (unsigned) regno)
2642 offset -= cfa.offset;
2643 else if (cfa_store.reg == (unsigned) regno)
2644 offset -= cfa_store.offset;
2647 gcc_assert (cfa_temp.reg == (unsigned) regno);
2648 offset -= cfa_temp.offset;
2654 /* Without an offset. */
2657 int regno = REGNO (XEXP (dest, 0));
2659 if (cfa.reg == (unsigned) regno)
2660 offset = -cfa.offset;
2661 else if (cfa_store.reg == (unsigned) regno)
2662 offset = -cfa_store.offset;
2665 gcc_assert (cfa_temp.reg == (unsigned) regno);
2666 offset = -cfa_temp.offset;
2673 gcc_assert (cfa_temp.reg
2674 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2675 offset = -cfa_temp.offset;
2676 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2684 /* If the source operand of this MEM operation is not a
2685 register, basically the source is return address. Here
2686 we only care how much stack grew and we don't save it. */
2690 if (REGNO (src) != STACK_POINTER_REGNUM
2691 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2692 && (unsigned) REGNO (src) == cfa.reg)
2694 /* We're storing the current CFA reg into the stack. */
2696 if (cfa.offset == 0)
2699 /* If stack is aligned, putting CFA reg into stack means
2700 we can no longer use reg + offset to represent CFA.
2701 Here we use DW_CFA_def_cfa_expression instead. The
2702 result of this expression equals to the original CFA
2705 && fde->stack_realign
2706 && cfa.indirect == 0
2707 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2709 dw_cfa_location cfa_exp;
2711 gcc_assert (fde->drap_reg == cfa.reg);
2713 cfa_exp.indirect = 1;
2714 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2715 cfa_exp.base_offset = offset;
2718 fde->drap_reg_saved = 1;
2720 def_cfa_1 (label, &cfa_exp);
2724 /* If the source register is exactly the CFA, assume
2725 we're saving SP like any other register; this happens
2727 def_cfa_1 (label, &cfa);
2728 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2733 /* Otherwise, we'll need to look in the stack to
2734 calculate the CFA. */
2735 rtx x = XEXP (dest, 0);
2739 gcc_assert (REG_P (x));
2741 cfa.reg = REGNO (x);
2742 cfa.base_offset = offset;
2744 def_cfa_1 (label, &cfa);
2749 def_cfa_1 (label, &cfa);
2751 span = targetm.dwarf_register_span (src);
2754 queue_reg_save (label, src, NULL_RTX, offset);
2757 /* We have a PARALLEL describing where the contents of SRC
2758 live. Queue register saves for each piece of the
2762 HOST_WIDE_INT span_offset = offset;
2764 gcc_assert (GET_CODE (span) == PARALLEL);
2766 limit = XVECLEN (span, 0);
2767 for (par_index = 0; par_index < limit; par_index++)
2769 rtx elem = XVECEXP (span, 0, par_index);
2771 queue_reg_save (label, elem, NULL_RTX, span_offset);
2772 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2783 /* Record call frame debugging information for INSN, which either
2784 sets SP or FP (adjusting how we calculate the frame address) or saves a
2785 register to the stack. If INSN is NULL_RTX, initialize our state.
2787 If AFTER_P is false, we're being called before the insn is emitted,
2788 otherwise after. Call instructions get invoked twice. */
2791 dwarf2out_frame_debug (rtx insn, bool after_p)
2795 bool handled_one = false;
2797 if (insn == NULL_RTX)
2801 /* Flush any queued register saves. */
2802 dwarf2out_flush_queued_reg_saves ();
2804 /* Set up state for generating call frame debug info. */
2807 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2809 cfa.reg = STACK_POINTER_REGNUM;
2812 cfa_temp.offset = 0;
2814 for (i = 0; i < num_regs_saved_in_regs; i++)
2816 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2817 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2819 num_regs_saved_in_regs = 0;
2821 if (barrier_args_size)
2823 XDELETEVEC (barrier_args_size);
2824 barrier_args_size = NULL;
2829 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2830 dwarf2out_flush_queued_reg_saves ();
2832 if (!RTX_FRAME_RELATED_P (insn))
2834 /* ??? This should be done unconditionally since stack adjustments
2835 matter if the stack pointer is not the CFA register anymore but
2836 is still used to save registers. */
2837 if (!ACCUMULATE_OUTGOING_ARGS)
2838 dwarf2out_notice_stack_adjust (insn, after_p);
2842 label = dwarf2out_cfi_label (false);
2843 any_cfis_emitted = false;
2845 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2846 switch (REG_NOTE_KIND (note))
2848 case REG_FRAME_RELATED_EXPR:
2849 insn = XEXP (note, 0);
2852 case REG_CFA_DEF_CFA:
2853 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2857 case REG_CFA_ADJUST_CFA:
2862 if (GET_CODE (n) == PARALLEL)
2863 n = XVECEXP (n, 0, 0);
2865 dwarf2out_frame_debug_adjust_cfa (n, label);
2869 case REG_CFA_OFFSET:
2872 n = single_set (insn);
2873 dwarf2out_frame_debug_cfa_offset (n, label);
2877 case REG_CFA_REGISTER:
2882 if (GET_CODE (n) == PARALLEL)
2883 n = XVECEXP (n, 0, 0);
2885 dwarf2out_frame_debug_cfa_register (n, label);
2889 case REG_CFA_EXPRESSION:
2892 n = single_set (insn);
2893 dwarf2out_frame_debug_cfa_expression (n, label);
2897 case REG_CFA_RESTORE:
2902 if (GET_CODE (n) == PARALLEL)
2903 n = XVECEXP (n, 0, 0);
2906 dwarf2out_frame_debug_cfa_restore (n, label);
2910 case REG_CFA_SET_VDRAP:
2914 dw_fde_ref fde = current_fde ();
2917 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2919 fde->vdrap_reg = REGNO (n);
2930 if (any_cfis_emitted)
2931 dwarf2out_flush_queued_reg_saves ();
2935 insn = PATTERN (insn);
2937 dwarf2out_frame_debug_expr (insn, label);
2939 /* Check again. A parallel can save and update the same register.
2940 We could probably check just once, here, but this is safer than
2941 removing the check above. */
2942 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2943 dwarf2out_flush_queued_reg_saves ();
2946 /* Determine if we need to save and restore CFI information around this
2947 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2948 we do need to save/restore, then emit the save now, and insert a
2949 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2952 dwarf2out_cfi_begin_epilogue (rtx insn)
2954 bool saw_frp = false;
2957 /* Scan forward to the return insn, noticing if there are possible
2958 frame related insns. */
2959 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2964 /* Look for both regular and sibcalls to end the block. */
2965 if (returnjump_p (i))
2967 if (CALL_P (i) && SIBLING_CALL_P (i))
2970 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2973 rtx seq = PATTERN (i);
2975 if (returnjump_p (XVECEXP (seq, 0, 0)))
2977 if (CALL_P (XVECEXP (seq, 0, 0))
2978 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2981 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2982 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2986 if (RTX_FRAME_RELATED_P (i))
2990 /* If the port doesn't emit epilogue unwind info, we don't need a
2991 save/restore pair. */
2995 /* Otherwise, search forward to see if the return insn was the last
2996 basic block of the function. If so, we don't need save/restore. */
2997 gcc_assert (i != NULL);
2998 i = next_real_insn (i);
3002 /* Insert the restore before that next real insn in the stream, and before
3003 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3004 properly nested. This should be after any label or alignment. This
3005 will be pushed into the CFI stream by the function below. */
3008 rtx p = PREV_INSN (i);
3011 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3015 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3017 emit_cfa_remember = true;
3019 /* And emulate the state save. */
3020 gcc_assert (!cfa_remember.in_use);
3022 cfa_remember.in_use = 1;
3025 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3029 dwarf2out_frame_debug_restore_state (void)
3031 dw_cfi_ref cfi = new_cfi ();
3032 const char *label = dwarf2out_cfi_label (false);
3034 cfi->dw_cfi_opc = DW_CFA_restore_state;
3035 add_fde_cfi (label, cfi);
3037 gcc_assert (cfa_remember.in_use);
3039 cfa_remember.in_use = 0;
3042 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3043 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3044 (enum dwarf_call_frame_info cfi);
3046 static enum dw_cfi_oprnd_type
3047 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3052 case DW_CFA_GNU_window_save:
3053 case DW_CFA_remember_state:
3054 case DW_CFA_restore_state:
3055 return dw_cfi_oprnd_unused;
3057 case DW_CFA_set_loc:
3058 case DW_CFA_advance_loc1:
3059 case DW_CFA_advance_loc2:
3060 case DW_CFA_advance_loc4:
3061 case DW_CFA_MIPS_advance_loc8:
3062 return dw_cfi_oprnd_addr;
3065 case DW_CFA_offset_extended:
3066 case DW_CFA_def_cfa:
3067 case DW_CFA_offset_extended_sf:
3068 case DW_CFA_def_cfa_sf:
3069 case DW_CFA_restore:
3070 case DW_CFA_restore_extended:
3071 case DW_CFA_undefined:
3072 case DW_CFA_same_value:
3073 case DW_CFA_def_cfa_register:
3074 case DW_CFA_register:
3075 case DW_CFA_expression:
3076 return dw_cfi_oprnd_reg_num;
3078 case DW_CFA_def_cfa_offset:
3079 case DW_CFA_GNU_args_size:
3080 case DW_CFA_def_cfa_offset_sf:
3081 return dw_cfi_oprnd_offset;
3083 case DW_CFA_def_cfa_expression:
3084 return dw_cfi_oprnd_loc;
3091 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3092 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3093 (enum dwarf_call_frame_info cfi);
3095 static enum dw_cfi_oprnd_type
3096 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3100 case DW_CFA_def_cfa:
3101 case DW_CFA_def_cfa_sf:
3103 case DW_CFA_offset_extended_sf:
3104 case DW_CFA_offset_extended:
3105 return dw_cfi_oprnd_offset;
3107 case DW_CFA_register:
3108 return dw_cfi_oprnd_reg_num;
3110 case DW_CFA_expression:
3111 return dw_cfi_oprnd_loc;
3114 return dw_cfi_oprnd_unused;
3118 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3119 switch to the data section instead, and write out a synthetic start label
3120 for collect2 the first time around. */
3123 switch_to_eh_frame_section (bool back)
3127 #ifdef EH_FRAME_SECTION_NAME
3128 if (eh_frame_section == 0)
3132 if (EH_TABLES_CAN_BE_READ_ONLY)
3138 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3140 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3142 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3144 flags = ((! flag_pic
3145 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3146 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3147 && (per_encoding & 0x70) != DW_EH_PE_absptr
3148 && (per_encoding & 0x70) != DW_EH_PE_aligned
3149 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3150 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3151 ? 0 : SECTION_WRITE);
3154 flags = SECTION_WRITE;
3155 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3157 #endif /* EH_FRAME_SECTION_NAME */
3159 if (eh_frame_section)
3160 switch_to_section (eh_frame_section);
3163 /* We have no special eh_frame section. Put the information in
3164 the data section and emit special labels to guide collect2. */
3165 switch_to_section (data_section);
3169 label = get_file_function_name ("F");
3170 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3171 targetm.asm_out.globalize_label (asm_out_file,
3172 IDENTIFIER_POINTER (label));
3173 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3178 /* Switch [BACK] to the eh or debug frame table section, depending on
3182 switch_to_frame_table_section (int for_eh, bool back)
3185 switch_to_eh_frame_section (back);
3188 if (!debug_frame_section)
3189 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3190 SECTION_DEBUG, NULL);
3191 switch_to_section (debug_frame_section);
3195 /* Output a Call Frame Information opcode and its operand(s). */
3198 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3203 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3204 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3205 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3206 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3207 ((unsigned HOST_WIDE_INT)
3208 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3209 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3211 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3212 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3213 "DW_CFA_offset, column %#lx", r);
3214 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3215 dw2_asm_output_data_uleb128 (off, NULL);
3217 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3219 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3220 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3221 "DW_CFA_restore, column %#lx", r);
3225 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3226 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3228 switch (cfi->dw_cfi_opc)
3230 case DW_CFA_set_loc:
3232 dw2_asm_output_encoded_addr_rtx (
3233 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3234 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3237 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3238 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3239 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3242 case DW_CFA_advance_loc1:
3243 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3244 fde->dw_fde_current_label, NULL);
3245 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3248 case DW_CFA_advance_loc2:
3249 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3250 fde->dw_fde_current_label, NULL);
3251 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3254 case DW_CFA_advance_loc4:
3255 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3256 fde->dw_fde_current_label, NULL);
3257 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3260 case DW_CFA_MIPS_advance_loc8:
3261 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3262 fde->dw_fde_current_label, NULL);
3263 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3266 case DW_CFA_offset_extended:
3267 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3268 dw2_asm_output_data_uleb128 (r, NULL);
3269 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3270 dw2_asm_output_data_uleb128 (off, NULL);
3273 case DW_CFA_def_cfa:
3274 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3275 dw2_asm_output_data_uleb128 (r, NULL);
3276 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3279 case DW_CFA_offset_extended_sf:
3280 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3281 dw2_asm_output_data_uleb128 (r, NULL);
3282 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3283 dw2_asm_output_data_sleb128 (off, NULL);
3286 case DW_CFA_def_cfa_sf:
3287 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3288 dw2_asm_output_data_uleb128 (r, NULL);
3289 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3290 dw2_asm_output_data_sleb128 (off, NULL);
3293 case DW_CFA_restore_extended:
3294 case DW_CFA_undefined:
3295 case DW_CFA_same_value:
3296 case DW_CFA_def_cfa_register:
3297 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3298 dw2_asm_output_data_uleb128 (r, NULL);
3301 case DW_CFA_register:
3302 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3303 dw2_asm_output_data_uleb128 (r, NULL);
3304 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3305 dw2_asm_output_data_uleb128 (r, NULL);
3308 case DW_CFA_def_cfa_offset:
3309 case DW_CFA_GNU_args_size:
3310 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3313 case DW_CFA_def_cfa_offset_sf:
3314 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3315 dw2_asm_output_data_sleb128 (off, NULL);
3318 case DW_CFA_GNU_window_save:
3321 case DW_CFA_def_cfa_expression:
3322 case DW_CFA_expression:
3323 output_cfa_loc (cfi, for_eh);
3326 case DW_CFA_GNU_negative_offset_extended:
3327 /* Obsoleted by DW_CFA_offset_extended_sf. */
3336 /* Similar, but do it via assembler directives instead. */
3339 output_cfi_directive (dw_cfi_ref cfi)
3341 unsigned long r, r2;
3343 switch (cfi->dw_cfi_opc)
3345 case DW_CFA_advance_loc:
3346 case DW_CFA_advance_loc1:
3347 case DW_CFA_advance_loc2:
3348 case DW_CFA_advance_loc4:
3349 case DW_CFA_MIPS_advance_loc8:
3350 case DW_CFA_set_loc:
3351 /* Should only be created by add_fde_cfi in a code path not
3352 followed when emitting via directives. The assembler is
3353 going to take care of this for us. */
3357 case DW_CFA_offset_extended:
3358 case DW_CFA_offset_extended_sf:
3359 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3360 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3361 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3364 case DW_CFA_restore:
3365 case DW_CFA_restore_extended:
3366 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3367 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3370 case DW_CFA_undefined:
3371 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3372 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3375 case DW_CFA_same_value:
3376 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3377 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3380 case DW_CFA_def_cfa:
3381 case DW_CFA_def_cfa_sf:
3382 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3383 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3384 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3387 case DW_CFA_def_cfa_register:
3388 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3389 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3392 case DW_CFA_register:
3393 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3394 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3395 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3398 case DW_CFA_def_cfa_offset:
3399 case DW_CFA_def_cfa_offset_sf:
3400 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3401 HOST_WIDE_INT_PRINT_DEC"\n",
3402 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3405 case DW_CFA_remember_state:
3406 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3408 case DW_CFA_restore_state:
3409 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3412 case DW_CFA_GNU_args_size:
3413 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3414 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3416 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3417 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3418 fputc ('\n', asm_out_file);
3421 case DW_CFA_GNU_window_save:
3422 fprintf (asm_out_file, "\t.cfi_window_save\n");
3425 case DW_CFA_def_cfa_expression:
3426 case DW_CFA_expression:
3427 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3428 output_cfa_loc_raw (cfi);
3429 fputc ('\n', asm_out_file);
3437 DEF_VEC_P (dw_cfi_ref);
3438 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3440 /* Output CFIs to bring current FDE to the same state as after executing
3441 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3442 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3443 other arguments to pass to output_cfi. */
3446 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3448 struct dw_cfi_struct cfi_buf;
3450 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3451 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3452 unsigned int len, idx;
3454 for (;; cfi = cfi->dw_cfi_next)
3455 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3457 case DW_CFA_advance_loc:
3458 case DW_CFA_advance_loc1:
3459 case DW_CFA_advance_loc2:
3460 case DW_CFA_advance_loc4:
3461 case DW_CFA_MIPS_advance_loc8:
3462 case DW_CFA_set_loc:
3463 /* All advances should be ignored. */
3465 case DW_CFA_remember_state:
3467 dw_cfi_ref args_size = cfi_args_size;
3469 /* Skip everything between .cfi_remember_state and
3470 .cfi_restore_state. */
3471 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3472 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3474 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3477 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3484 cfi_args_size = args_size;
3488 case DW_CFA_GNU_args_size:
3489 cfi_args_size = cfi;
3491 case DW_CFA_GNU_window_save:
3494 case DW_CFA_offset_extended:
3495 case DW_CFA_offset_extended_sf:
3496 case DW_CFA_restore:
3497 case DW_CFA_restore_extended:
3498 case DW_CFA_undefined:
3499 case DW_CFA_same_value:
3500 case DW_CFA_register:
3501 case DW_CFA_val_offset:
3502 case DW_CFA_val_offset_sf:
3503 case DW_CFA_expression:
3504 case DW_CFA_val_expression:
3505 case DW_CFA_GNU_negative_offset_extended:
3506 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3507 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3508 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3509 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3511 case DW_CFA_def_cfa:
3512 case DW_CFA_def_cfa_sf:
3513 case DW_CFA_def_cfa_expression:
3515 cfi_cfa_offset = cfi;
3517 case DW_CFA_def_cfa_register:
3520 case DW_CFA_def_cfa_offset:
3521 case DW_CFA_def_cfa_offset_sf:
3522 cfi_cfa_offset = cfi;
3525 gcc_assert (cfi == NULL);
3527 len = VEC_length (dw_cfi_ref, regs);
3528 for (idx = 0; idx < len; idx++)
3530 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3532 && cfi2->dw_cfi_opc != DW_CFA_restore
3533 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3536 output_cfi_directive (cfi2);
3538 output_cfi (cfi2, fde, for_eh);
3541 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3543 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3545 switch (cfi_cfa_offset->dw_cfi_opc)
3547 case DW_CFA_def_cfa_offset:
3548 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3549 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3551 case DW_CFA_def_cfa_offset_sf:
3552 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3553 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3555 case DW_CFA_def_cfa:
3556 case DW_CFA_def_cfa_sf:
3557 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3558 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3565 else if (cfi_cfa_offset)
3566 cfi_cfa = cfi_cfa_offset;
3570 output_cfi_directive (cfi_cfa);
3572 output_cfi (cfi_cfa, fde, for_eh);
3575 cfi_cfa_offset = NULL;
3577 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3580 output_cfi_directive (cfi_args_size);
3582 output_cfi (cfi_args_size, fde, for_eh);
3584 cfi_args_size = NULL;
3587 VEC_free (dw_cfi_ref, heap, regs);
3590 else if (do_cfi_asm)
3591 output_cfi_directive (cfi);
3593 output_cfi (cfi, fde, for_eh);
3600 /* Output one FDE. */
3603 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3604 char *section_start_label, int fde_encoding, char *augmentation,
3605 bool any_lsda_needed, int lsda_encoding)
3607 const char *begin, *end;
3608 static unsigned int j;
3609 char l1[20], l2[20];
3612 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3614 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3616 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3617 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3618 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3619 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3620 " indicating 64-bit DWARF extension");
3621 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3623 ASM_OUTPUT_LABEL (asm_out_file, l1);
3626 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3628 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3629 debug_frame_section, "FDE CIE offset");
3631 if (!fde->dw_fde_switched_sections)
3633 begin = fde->dw_fde_begin;
3634 end = fde->dw_fde_end;
3638 /* For the first section, prefer dw_fde_begin over
3639 dw_fde_{hot,cold}_section_label, as the latter
3640 might be separated from the real start of the
3641 function by alignment padding. */
3643 begin = fde->dw_fde_begin;
3644 else if (fde->dw_fde_switched_cold_to_hot)
3645 begin = fde->dw_fde_hot_section_label;
3647 begin = fde->dw_fde_unlikely_section_label;
3648 if (second ^ fde->dw_fde_switched_cold_to_hot)
3649 end = fde->dw_fde_unlikely_section_end_label;
3651 end = fde->dw_fde_hot_section_end_label;
3656 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3657 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3658 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3659 "FDE initial location");
3660 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3661 end, begin, "FDE address range");
3665 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3666 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3669 if (augmentation[0])
3671 if (any_lsda_needed)
3673 int size = size_of_encoded_value (lsda_encoding);
3675 if (lsda_encoding == DW_EH_PE_aligned)
3677 int offset = ( 4 /* Length */
3678 + 4 /* CIE offset */
3679 + 2 * size_of_encoded_value (fde_encoding)
3680 + 1 /* Augmentation size */ );
3681 int pad = -offset & (PTR_SIZE - 1);
3684 gcc_assert (size_of_uleb128 (size) == 1);
3687 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3689 if (fde->uses_eh_lsda)
3691 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3692 fde->funcdef_number);
3693 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3694 gen_rtx_SYMBOL_REF (Pmode, l1),
3696 "Language Specific Data Area");
3700 if (lsda_encoding == DW_EH_PE_aligned)
3701 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3702 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3703 "Language Specific Data Area (none)");
3707 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3710 /* Loop through the Call Frame Instructions associated with
3712 fde->dw_fde_current_label = begin;
3713 if (!fde->dw_fde_switched_sections)
3714 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3715 output_cfi (cfi, fde, for_eh);
3718 if (fde->dw_fde_switch_cfi)
3719 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3721 output_cfi (cfi, fde, for_eh);
3722 if (cfi == fde->dw_fde_switch_cfi)
3728 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3730 if (fde->dw_fde_switch_cfi)
3732 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3733 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3734 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3735 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3737 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3738 output_cfi (cfi, fde, for_eh);
3741 /* If we are to emit a ref/link from function bodies to their frame tables,
3742 do it now. This is typically performed to make sure that tables
3743 associated with functions are dragged with them and not discarded in
3744 garbage collecting links. We need to do this on a per function basis to
3745 cope with -ffunction-sections. */
3747 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3748 /* Switch to the function section, emit the ref to the tables, and
3749 switch *back* into the table section. */
3750 switch_to_section (function_section (fde->decl));
3751 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3752 switch_to_frame_table_section (for_eh, true);
3755 /* Pad the FDE out to an address sized boundary. */
3756 ASM_OUTPUT_ALIGN (asm_out_file,
3757 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3758 ASM_OUTPUT_LABEL (asm_out_file, l2);
3763 /* Return true if frame description entry FDE is needed for EH. */
3766 fde_needed_for_eh_p (dw_fde_ref fde)
3768 if (flag_asynchronous_unwind_tables)
3771 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3774 if (fde->uses_eh_lsda)
3777 /* If exceptions are enabled, we have collected nothrow info. */
3778 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3784 /* Output the call frame information used to record information
3785 that relates to calculating the frame pointer, and records the
3786 location of saved registers. */
3789 output_call_frame_info (int for_eh)
3794 char l1[20], l2[20], section_start_label[20];
3795 bool any_lsda_needed = false;
3796 char augmentation[6];
3797 int augmentation_size;
3798 int fde_encoding = DW_EH_PE_absptr;
3799 int per_encoding = DW_EH_PE_absptr;
3800 int lsda_encoding = DW_EH_PE_absptr;
3802 rtx personality = NULL;
3805 /* Don't emit a CIE if there won't be any FDEs. */
3806 if (fde_table_in_use == 0)
3809 /* Nothing to do if the assembler's doing it all. */
3810 if (dwarf2out_do_cfi_asm ())
3813 /* If we don't have any functions we'll want to unwind out of, don't emit
3814 any EH unwind information. If we make FDEs linkonce, we may have to
3815 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3816 want to avoid having an FDE kept around when the function it refers to
3817 is discarded. Example where this matters: a primary function template
3818 in C++ requires EH information, an explicit specialization doesn't. */
3821 bool any_eh_needed = false;
3823 for (i = 0; i < fde_table_in_use; i++)
3824 if (fde_table[i].uses_eh_lsda)
3825 any_eh_needed = any_lsda_needed = true;
3826 else if (fde_needed_for_eh_p (&fde_table[i]))
3827 any_eh_needed = true;
3828 else if (TARGET_USES_WEAK_UNWIND_INFO)
3829 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3836 /* We're going to be generating comments, so turn on app. */
3840 /* Switch to the proper frame section, first time. */
3841 switch_to_frame_table_section (for_eh, false);
3843 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3844 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3846 /* Output the CIE. */
3847 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3848 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3849 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3850 dw2_asm_output_data (4, 0xffffffff,
3851 "Initial length escape value indicating 64-bit DWARF extension");
3852 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3853 "Length of Common Information Entry");
3854 ASM_OUTPUT_LABEL (asm_out_file, l1);
3856 /* Now that the CIE pointer is PC-relative for EH,
3857 use 0 to identify the CIE. */
3858 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3859 (for_eh ? 0 : DWARF_CIE_ID),
3860 "CIE Identifier Tag");
3862 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3863 use CIE version 1, unless that would produce incorrect results
3864 due to overflowing the return register column. */
3865 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3867 if (return_reg >= 256 || dwarf_version > 2)
3869 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3871 augmentation[0] = 0;
3872 augmentation_size = 0;
3874 personality = current_unit_personality;
3880 z Indicates that a uleb128 is present to size the
3881 augmentation section.
3882 L Indicates the encoding (and thus presence) of
3883 an LSDA pointer in the FDE augmentation.
3884 R Indicates a non-default pointer encoding for
3886 P Indicates the presence of an encoding + language
3887 personality routine in the CIE augmentation. */
3889 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3890 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3891 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3893 p = augmentation + 1;
3897 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3898 assemble_external_libcall (personality);
3900 if (any_lsda_needed)
3903 augmentation_size += 1;
3905 if (fde_encoding != DW_EH_PE_absptr)
3908 augmentation_size += 1;
3910 if (p > augmentation + 1)
3912 augmentation[0] = 'z';
3916 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3917 if (personality && per_encoding == DW_EH_PE_aligned)
3919 int offset = ( 4 /* Length */
3921 + 1 /* CIE version */
3922 + strlen (augmentation) + 1 /* Augmentation */
3923 + size_of_uleb128 (1) /* Code alignment */
3924 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3926 + 1 /* Augmentation size */
3927 + 1 /* Personality encoding */ );
3928 int pad = -offset & (PTR_SIZE - 1);
3930 augmentation_size += pad;
3932 /* Augmentations should be small, so there's scarce need to
3933 iterate for a solution. Die if we exceed one uleb128 byte. */
3934 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3938 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3939 if (dw_cie_version >= 4)
3941 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3942 dw2_asm_output_data (1, 0, "CIE Segment Size");
3944 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3945 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3946 "CIE Data Alignment Factor");
3948 if (dw_cie_version == 1)
3949 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3951 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3953 if (augmentation[0])
3955 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3958 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3959 eh_data_format_name (per_encoding));
3960 dw2_asm_output_encoded_addr_rtx (per_encoding,
3965 if (any_lsda_needed)
3966 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3967 eh_data_format_name (lsda_encoding));
3969 if (fde_encoding != DW_EH_PE_absptr)
3970 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3971 eh_data_format_name (fde_encoding));
3974 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3975 output_cfi (cfi, NULL, for_eh);
3977 /* Pad the CIE out to an address sized boundary. */
3978 ASM_OUTPUT_ALIGN (asm_out_file,
3979 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3980 ASM_OUTPUT_LABEL (asm_out_file, l2);
3982 /* Loop through all of the FDE's. */
3983 for (i = 0; i < fde_table_in_use; i++)
3986 fde = &fde_table[i];
3988 /* Don't emit EH unwind info for leaf functions that don't need it. */
3989 if (for_eh && !fde_needed_for_eh_p (fde))
3992 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3993 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3994 augmentation, any_lsda_needed, lsda_encoding);
3997 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3998 dw2_asm_output_data (4, 0, "End of Table");
3999 #ifdef MIPS_DEBUGGING_INFO
4000 /* Work around Irix 6 assembler bug whereby labels at the end of a section
4001 get a value of 0. Putting .align 0 after the label fixes it. */
4002 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4005 /* Turn off app to make assembly quicker. */
4010 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4013 dwarf2out_do_cfi_startproc (bool second)
4017 rtx personality = get_personality_function (current_function_decl);
4019 fprintf (asm_out_file, "\t.cfi_startproc\n");
4023 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4026 /* ??? The GAS support isn't entirely consistent. We have to
4027 handle indirect support ourselves, but PC-relative is done
4028 in the assembler. Further, the assembler can't handle any
4029 of the weirder relocation types. */
4030 if (enc & DW_EH_PE_indirect)
4031 ref = dw2_force_const_mem (ref, true);
4033 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4034 output_addr_const (asm_out_file, ref);
4035 fputc ('\n', asm_out_file);
4038 if (crtl->uses_eh_lsda)
4042 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4043 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4044 current_function_funcdef_no);
4045 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4046 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4048 if (enc & DW_EH_PE_indirect)
4049 ref = dw2_force_const_mem (ref, true);
4051 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4052 output_addr_const (asm_out_file, ref);
4053 fputc ('\n', asm_out_file);
4057 /* Output a marker (i.e. a label) for the beginning of a function, before
4061 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4062 const char *file ATTRIBUTE_UNUSED)
4064 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4070 current_function_func_begin_label = NULL;
4072 do_frame = dwarf2out_do_frame ();
4074 /* ??? current_function_func_begin_label is also used by except.c for
4075 call-site information. We must emit this label if it might be used. */
4077 && (!flag_exceptions
4078 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4081 fnsec = function_section (current_function_decl);
4082 switch_to_section (fnsec);
4083 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4084 current_function_funcdef_no);
4085 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4086 current_function_funcdef_no);
4087 dup_label = xstrdup (label);
4088 current_function_func_begin_label = dup_label;
4090 /* We can elide the fde allocation if we're not emitting debug info. */
4094 /* Expand the fde table if necessary. */
4095 if (fde_table_in_use == fde_table_allocated)
4097 fde_table_allocated += FDE_TABLE_INCREMENT;
4098 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4099 memset (fde_table + fde_table_in_use, 0,
4100 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4103 /* Record the FDE associated with this function. */
4104 current_funcdef_fde = fde_table_in_use;
4106 /* Add the new FDE at the end of the fde_table. */
4107 fde = &fde_table[fde_table_in_use++];
4108 fde->decl = current_function_decl;
4109 fde->dw_fde_begin = dup_label;
4110 fde->dw_fde_current_label = dup_label;
4111 fde->dw_fde_hot_section_label = NULL;
4112 fde->dw_fde_hot_section_end_label = NULL;
4113 fde->dw_fde_unlikely_section_label = NULL;
4114 fde->dw_fde_unlikely_section_end_label = NULL;
4115 fde->dw_fde_switched_sections = 0;
4116 fde->dw_fde_switched_cold_to_hot = 0;
4117 fde->dw_fde_end = NULL;
4118 fde->dw_fde_vms_end_prologue = NULL;
4119 fde->dw_fde_vms_begin_epilogue = NULL;
4120 fde->dw_fde_cfi = NULL;
4121 fde->dw_fde_switch_cfi = NULL;
4122 fde->funcdef_number = current_function_funcdef_no;
4123 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4124 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4125 fde->nothrow = crtl->nothrow;
4126 fde->drap_reg = INVALID_REGNUM;
4127 fde->vdrap_reg = INVALID_REGNUM;
4128 if (flag_reorder_blocks_and_partition)
4130 section *unlikelysec;
4131 if (first_function_block_is_cold)
4132 fde->in_std_section = 1;
4135 = (fnsec == text_section
4136 || (cold_text_section && fnsec == cold_text_section));
4137 unlikelysec = unlikely_text_section ();
4138 fde->cold_in_std_section
4139 = (unlikelysec == text_section
4140 || (cold_text_section && unlikelysec == cold_text_section));
4145 = (fnsec == text_section
4146 || (cold_text_section && fnsec == cold_text_section));
4147 fde->cold_in_std_section = 0;
4150 args_size = old_args_size = 0;
4152 /* We only want to output line number information for the genuine dwarf2
4153 prologue case, not the eh frame case. */
4154 #ifdef DWARF2_DEBUGGING_INFO
4156 dwarf2out_source_line (line, file, 0, true);
4159 if (dwarf2out_do_cfi_asm ())
4160 dwarf2out_do_cfi_startproc (false);
4163 rtx personality = get_personality_function (current_function_decl);
4164 if (!current_unit_personality)
4165 current_unit_personality = personality;
4167 /* We cannot keep a current personality per function as without CFI
4168 asm, at the point where we emit the CFI data, there is no current
4169 function anymore. */
4170 if (personality && current_unit_personality != personality)
4171 sorry ("multiple EH personalities are supported only with assemblers "
4172 "supporting .cfi_personality directive");
4176 /* Output a marker (i.e. a label) for the end of the generated code
4177 for a function prologue. This gets called *after* the prologue code has
4181 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4182 const char *file ATTRIBUTE_UNUSED)
4185 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4187 /* Output a label to mark the endpoint of the code generated for this
4189 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4190 current_function_funcdef_no);
4191 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4192 current_function_funcdef_no);
4193 fde = &fde_table[fde_table_in_use - 1];
4194 fde->dw_fde_vms_end_prologue = xstrdup (label);
4197 /* Output a marker (i.e. a label) for the beginning of the generated code
4198 for a function epilogue. This gets called *before* the prologue code has
4202 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4203 const char *file ATTRIBUTE_UNUSED)
4206 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4208 fde = &fde_table[fde_table_in_use - 1];
4209 if (fde->dw_fde_vms_begin_epilogue)
4212 /* Output a label to mark the endpoint of the code generated for this
4214 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4215 current_function_funcdef_no);
4216 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4217 current_function_funcdef_no);
4218 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4221 /* Output a marker (i.e. a label) for the absolute end of the generated code
4222 for a function definition. This gets called *after* the epilogue code has
4226 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4227 const char *file ATTRIBUTE_UNUSED)
4230 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4232 last_var_location_insn = NULL_RTX;
4234 if (dwarf2out_do_cfi_asm ())
4235 fprintf (asm_out_file, "\t.cfi_endproc\n");
4237 /* Output a label to mark the endpoint of the code generated for this
4239 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4240 current_function_funcdef_no);
4241 ASM_OUTPUT_LABEL (asm_out_file, label);
4242 fde = current_fde ();
4243 gcc_assert (fde != NULL);
4244 fde->dw_fde_end = xstrdup (label);
4248 dwarf2out_frame_init (void)
4250 /* Allocate the initial hunk of the fde_table. */
4251 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4252 fde_table_allocated = FDE_TABLE_INCREMENT;
4253 fde_table_in_use = 0;
4255 /* Generate the CFA instructions common to all FDE's. Do it now for the
4256 sake of lookup_cfa. */
4258 /* On entry, the Canonical Frame Address is at SP. */
4259 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4261 if (targetm.debug_unwind_info () == UI_DWARF2
4262 || targetm.except_unwind_info (&global_options) == UI_DWARF2)
4263 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4267 dwarf2out_frame_finish (void)
4269 /* Output call frame information. */
4270 if (targetm.debug_unwind_info () == UI_DWARF2)
4271 output_call_frame_info (0);
4273 /* Output another copy for the unwinder. */
4274 if ((flag_unwind_tables || flag_exceptions)
4275 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
4276 output_call_frame_info (1);
4279 /* Note that the current function section is being used for code. */
4282 dwarf2out_note_section_used (void)
4284 section *sec = current_function_section ();
4285 if (sec == text_section)
4286 text_section_used = true;
4287 else if (sec == cold_text_section)
4288 cold_text_section_used = true;
4292 dwarf2out_switch_text_section (void)
4294 dw_fde_ref fde = current_fde ();
4296 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4298 fde->dw_fde_switched_sections = 1;
4299 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4301 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4302 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4303 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4304 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4305 have_multiple_function_sections = true;
4307 /* Reset the current label on switching text sections, so that we
4308 don't attempt to advance_loc4 between labels in different sections. */
4309 fde->dw_fde_current_label = NULL;
4311 /* There is no need to mark used sections when not debugging. */
4312 if (cold_text_section != NULL)
4313 dwarf2out_note_section_used ();
4315 if (dwarf2out_do_cfi_asm ())
4316 fprintf (asm_out_file, "\t.cfi_endproc\n");
4318 /* Now do the real section switch. */
4319 switch_to_section (current_function_section ());
4321 if (dwarf2out_do_cfi_asm ())
4323 dwarf2out_do_cfi_startproc (true);
4324 /* As this is a different FDE, insert all current CFI instructions
4326 output_cfis (fde->dw_fde_cfi, true, fde, true);
4330 dw_cfi_ref cfi = fde->dw_fde_cfi;
4332 cfi = fde->dw_fde_cfi;
4334 while (cfi->dw_cfi_next != NULL)
4335 cfi = cfi->dw_cfi_next;
4336 fde->dw_fde_switch_cfi = cfi;
4340 /* And now, the subset of the debugging information support code necessary
4341 for emitting location expressions. */
4343 /* Data about a single source file. */
4344 struct GTY(()) dwarf_file_data {
4345 const char * filename;
4349 typedef struct dw_val_struct *dw_val_ref;
4350 typedef struct die_struct *dw_die_ref;
4351 typedef const struct die_struct *const_dw_die_ref;
4352 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4353 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4355 typedef struct GTY(()) deferred_locations_struct
4359 } deferred_locations;
4361 DEF_VEC_O(deferred_locations);
4362 DEF_VEC_ALLOC_O(deferred_locations,gc);
4364 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4366 DEF_VEC_P(dw_die_ref);
4367 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4369 /* Each DIE may have a series of attribute/value pairs. Values
4370 can take on several forms. The forms that are used in this
4371 implementation are listed below. */
4376 dw_val_class_offset,
4378 dw_val_class_loc_list,
4379 dw_val_class_range_list,
4381 dw_val_class_unsigned_const,
4382 dw_val_class_const_double,
4385 dw_val_class_die_ref,
4386 dw_val_class_fde_ref,
4387 dw_val_class_lbl_id,
4388 dw_val_class_lineptr,
4390 dw_val_class_macptr,
4393 dw_val_class_decl_ref,
4394 dw_val_class_vms_delta
4397 /* Describe a floating point constant value, or a vector constant value. */
4399 typedef struct GTY(()) dw_vec_struct {
4400 unsigned char * GTY((length ("%h.length"))) array;
4406 /* The dw_val_node describes an attribute's value, as it is
4407 represented internally. */
4409 typedef struct GTY(()) dw_val_struct {
4410 enum dw_val_class val_class;
4411 union dw_val_struct_union
4413 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4414 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4415 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4416 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4417 HOST_WIDE_INT GTY ((default)) val_int;
4418 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4419 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4420 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4421 struct dw_val_die_union
4425 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4426 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4427 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4428 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4429 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4430 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4431 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4432 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4433 struct dw_val_vms_delta_union
4437 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4439 GTY ((desc ("%1.val_class"))) v;
4443 /* Locations in memory are described using a sequence of stack machine
4446 typedef struct GTY(()) dw_loc_descr_struct {
4447 dw_loc_descr_ref dw_loc_next;
4448 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4449 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4450 from DW_OP_addr with a dtp-relative symbol relocation. */
4451 unsigned int dtprel : 1;
4453 dw_val_node dw_loc_oprnd1;
4454 dw_val_node dw_loc_oprnd2;
4458 /* Location lists are ranges + location descriptions for that range,
4459 so you can track variables that are in different places over
4460 their entire life. */
4461 typedef struct GTY(()) dw_loc_list_struct {
4462 dw_loc_list_ref dw_loc_next;
4463 const char *begin; /* Label for begin address of range */
4464 const char *end; /* Label for end address of range */
4465 char *ll_symbol; /* Label for beginning of location list.
4466 Only on head of list */
4467 const char *section; /* Section this loclist is relative to */
4468 dw_loc_descr_ref expr;
4473 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4475 /* Convert a DWARF stack opcode into its string name. */
4478 dwarf_stack_op_name (unsigned int op)
4483 return "DW_OP_addr";
4485 return "DW_OP_deref";
4487 return "DW_OP_const1u";
4489 return "DW_OP_const1s";
4491 return "DW_OP_const2u";
4493 return "DW_OP_const2s";
4495 return "DW_OP_const4u";
4497 return "DW_OP_const4s";
4499 return "DW_OP_const8u";
4501 return "DW_OP_const8s";
4503 return "DW_OP_constu";
4505 return "DW_OP_consts";
4509 return "DW_OP_drop";
4511 return "DW_OP_over";
4513 return "DW_OP_pick";
4515 return "DW_OP_swap";
4519 return "DW_OP_xderef";
4527 return "DW_OP_minus";
4539 return "DW_OP_plus";
4540 case DW_OP_plus_uconst:
4541 return "DW_OP_plus_uconst";
4547 return "DW_OP_shra";
4565 return "DW_OP_skip";
4567 return "DW_OP_lit0";
4569 return "DW_OP_lit1";
4571 return "DW_OP_lit2";
4573 return "DW_OP_lit3";
4575 return "DW_OP_lit4";
4577 return "DW_OP_lit5";
4579 return "DW_OP_lit6";
4581 return "DW_OP_lit7";
4583 return "DW_OP_lit8";
4585 return "DW_OP_lit9";
4587 return "DW_OP_lit10";
4589 return "DW_OP_lit11";
4591 return "DW_OP_lit12";
4593 return "DW_OP_lit13";
4595 return "DW_OP_lit14";
4597 return "DW_OP_lit15";
4599 return "DW_OP_lit16";
4601 return "DW_OP_lit17";
4603 return "DW_OP_lit18";
4605 return "DW_OP_lit19";
4607 return "DW_OP_lit20";
4609 return "DW_OP_lit21";
4611 return "DW_OP_lit22";
4613 return "DW_OP_lit23";
4615 return "DW_OP_lit24";
4617 return "DW_OP_lit25";
4619 return "DW_OP_lit26";
4621 return "DW_OP_lit27";
4623 return "DW_OP_lit28";
4625 return "DW_OP_lit29";
4627 return "DW_OP_lit30";
4629 return "DW_OP_lit31";
4631 return "DW_OP_reg0";
4633 return "DW_OP_reg1";
4635 return "DW_OP_reg2";
4637 return "DW_OP_reg3";
4639 return "DW_OP_reg4";
4641 return "DW_OP_reg5";
4643 return "DW_OP_reg6";
4645 return "DW_OP_reg7";
4647 return "DW_OP_reg8";
4649 return "DW_OP_reg9";
4651 return "DW_OP_reg10";
4653 return "DW_OP_reg11";
4655 return "DW_OP_reg12";
4657 return "DW_OP_reg13";
4659 return "DW_OP_reg14";
4661 return "DW_OP_reg15";
4663 return "DW_OP_reg16";
4665 return "DW_OP_reg17";
4667 return "DW_OP_reg18";
4669 return "DW_OP_reg19";
4671 return "DW_OP_reg20";
4673 return "DW_OP_reg21";
4675 return "DW_OP_reg22";
4677 return "DW_OP_reg23";
4679 return "DW_OP_reg24";
4681 return "DW_OP_reg25";
4683 return "DW_OP_reg26";
4685 return "DW_OP_reg27";
4687 return "DW_OP_reg28";
4689 return "DW_OP_reg29";
4691 return "DW_OP_reg30";
4693 return "DW_OP_reg31";
4695 return "DW_OP_breg0";
4697 return "DW_OP_breg1";
4699 return "DW_OP_breg2";
4701 return "DW_OP_breg3";
4703 return "DW_OP_breg4";
4705 return "DW_OP_breg5";
4707 return "DW_OP_breg6";
4709 return "DW_OP_breg7";
4711 return "DW_OP_breg8";
4713 return "DW_OP_breg9";
4715 return "DW_OP_breg10";
4717 return "DW_OP_breg11";
4719 return "DW_OP_breg12";
4721 return "DW_OP_breg13";
4723 return "DW_OP_breg14";
4725 return "DW_OP_breg15";
4727 return "DW_OP_breg16";
4729 return "DW_OP_breg17";
4731 return "DW_OP_breg18";
4733 return "DW_OP_breg19";
4735 return "DW_OP_breg20";
4737 return "DW_OP_breg21";
4739 return "DW_OP_breg22";
4741 return "DW_OP_breg23";
4743 return "DW_OP_breg24";
4745 return "DW_OP_breg25";
4747 return "DW_OP_breg26";
4749 return "DW_OP_breg27";
4751 return "DW_OP_breg28";
4753 return "DW_OP_breg29";
4755 return "DW_OP_breg30";
4757 return "DW_OP_breg31";
4759 return "DW_OP_regx";
4761 return "DW_OP_fbreg";
4763 return "DW_OP_bregx";
4765 return "DW_OP_piece";
4766 case DW_OP_deref_size:
4767 return "DW_OP_deref_size";
4768 case DW_OP_xderef_size:
4769 return "DW_OP_xderef_size";
4773 case DW_OP_push_object_address:
4774 return "DW_OP_push_object_address";
4776 return "DW_OP_call2";
4778 return "DW_OP_call4";
4779 case DW_OP_call_ref:
4780 return "DW_OP_call_ref";
4781 case DW_OP_implicit_value:
4782 return "DW_OP_implicit_value";
4783 case DW_OP_stack_value:
4784 return "DW_OP_stack_value";
4785 case DW_OP_form_tls_address:
4786 return "DW_OP_form_tls_address";
4787 case DW_OP_call_frame_cfa:
4788 return "DW_OP_call_frame_cfa";
4789 case DW_OP_bit_piece:
4790 return "DW_OP_bit_piece";
4792 case DW_OP_GNU_push_tls_address:
4793 return "DW_OP_GNU_push_tls_address";
4794 case DW_OP_GNU_uninit:
4795 return "DW_OP_GNU_uninit";
4796 case DW_OP_GNU_encoded_addr:
4797 return "DW_OP_GNU_encoded_addr";
4798 case DW_OP_GNU_implicit_pointer:
4799 return "DW_OP_GNU_implicit_pointer";
4800 case DW_OP_GNU_entry_value:
4801 return "DW_OP_GNU_entry_value";
4804 return "OP_<unknown>";
4808 /* Return a pointer to a newly allocated location description. Location
4809 descriptions are simple expression terms that can be strung
4810 together to form more complicated location (address) descriptions. */
4812 static inline dw_loc_descr_ref
4813 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4814 unsigned HOST_WIDE_INT oprnd2)
4816 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4818 descr->dw_loc_opc = op;
4819 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4820 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4821 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4822 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4827 /* Return a pointer to a newly allocated location description for
4830 static inline dw_loc_descr_ref
4831 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4834 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4837 return new_loc_descr (DW_OP_bregx, reg, offset);
4840 /* Add a location description term to a location description expression. */
4843 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4845 dw_loc_descr_ref *d;
4847 /* Find the end of the chain. */
4848 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4854 /* Add a constant OFFSET to a location expression. */
4857 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4859 dw_loc_descr_ref loc;
4862 gcc_assert (*list_head != NULL);
4867 /* Find the end of the chain. */
4868 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4872 if (loc->dw_loc_opc == DW_OP_fbreg
4873 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4874 p = &loc->dw_loc_oprnd1.v.val_int;
4875 else if (loc->dw_loc_opc == DW_OP_bregx)
4876 p = &loc->dw_loc_oprnd2.v.val_int;
4878 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4879 offset. Don't optimize if an signed integer overflow would happen. */
4881 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4882 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4885 else if (offset > 0)
4886 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4890 loc->dw_loc_next = int_loc_descriptor (-offset);
4891 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4895 /* Add a constant OFFSET to a location list. */
4898 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4901 for (d = list_head; d != NULL; d = d->dw_loc_next)
4902 loc_descr_plus_const (&d->expr, offset);
4905 #define DWARF_REF_SIZE \
4906 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4908 static unsigned long size_of_locs (dw_loc_descr_ref);
4910 /* Return the size of a location descriptor. */
4912 static unsigned long
4913 size_of_loc_descr (dw_loc_descr_ref loc)
4915 unsigned long size = 1;
4917 switch (loc->dw_loc_opc)
4920 size += DWARF2_ADDR_SIZE;
4939 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4942 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4947 case DW_OP_plus_uconst:
4948 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4986 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4989 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4992 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4995 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4996 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4999 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5001 case DW_OP_bit_piece:
5002 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5003 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
5005 case DW_OP_deref_size:
5006 case DW_OP_xderef_size:
5015 case DW_OP_call_ref:
5016 size += DWARF_REF_SIZE;
5018 case DW_OP_implicit_value:
5019 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5020 + loc->dw_loc_oprnd1.v.val_unsigned;
5022 case DW_OP_GNU_implicit_pointer:
5023 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5025 case DW_OP_GNU_entry_value:
5027 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
5028 size += size_of_uleb128 (op_size) + op_size;
5038 /* Return the size of a series of location descriptors. */
5040 static unsigned long
5041 size_of_locs (dw_loc_descr_ref loc)
5046 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5047 field, to avoid writing to a PCH file. */
5048 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5050 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5052 size += size_of_loc_descr (l);
5057 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5059 l->dw_loc_addr = size;
5060 size += size_of_loc_descr (l);
5066 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5067 static void get_ref_die_offset_label (char *, dw_die_ref);
5068 static void output_loc_sequence (dw_loc_descr_ref, int);
5070 /* Output location description stack opcode's operands (if any).
5071 The for_eh_or_skip parameter controls whether register numbers are
5072 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5073 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5074 info). This should be suppressed for the cases that have not been converted
5075 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5078 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5080 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5081 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5083 switch (loc->dw_loc_opc)
5085 #ifdef DWARF2_DEBUGGING_INFO
5088 dw2_asm_output_data (2, val1->v.val_int, NULL);
5093 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5094 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5096 fputc ('\n', asm_out_file);
5101 dw2_asm_output_data (4, val1->v.val_int, NULL);
5106 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5107 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5109 fputc ('\n', asm_out_file);
5114 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5115 dw2_asm_output_data (8, val1->v.val_int, NULL);
5122 gcc_assert (val1->val_class == dw_val_class_loc);
5123 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5125 dw2_asm_output_data (2, offset, NULL);
5128 case DW_OP_implicit_value:
5129 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5130 switch (val2->val_class)
5132 case dw_val_class_const:
5133 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5135 case dw_val_class_vec:
5137 unsigned int elt_size = val2->v.val_vec.elt_size;
5138 unsigned int len = val2->v.val_vec.length;
5142 if (elt_size > sizeof (HOST_WIDE_INT))
5147 for (i = 0, p = val2->v.val_vec.array;
5150 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5151 "fp or vector constant word %u", i);
5154 case dw_val_class_const_double:
5156 unsigned HOST_WIDE_INT first, second;
5158 if (WORDS_BIG_ENDIAN)
5160 first = val2->v.val_double.high;
5161 second = val2->v.val_double.low;
5165 first = val2->v.val_double.low;
5166 second = val2->v.val_double.high;
5168 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5170 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5174 case dw_val_class_addr:
5175 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5176 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5191 case DW_OP_implicit_value:
5192 /* We currently don't make any attempt to make sure these are
5193 aligned properly like we do for the main unwind info, so
5194 don't support emitting things larger than a byte if we're
5195 only doing unwinding. */
5200 dw2_asm_output_data (1, val1->v.val_int, NULL);
5203 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5206 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5209 dw2_asm_output_data (1, val1->v.val_int, NULL);
5211 case DW_OP_plus_uconst:
5212 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5246 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5250 unsigned r = val1->v.val_unsigned;
5251 if (for_eh_or_skip >= 0)
5252 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5253 gcc_assert (size_of_uleb128 (r)
5254 == size_of_uleb128 (val1->v.val_unsigned));
5255 dw2_asm_output_data_uleb128 (r, NULL);
5259 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5263 unsigned r = val1->v.val_unsigned;
5264 if (for_eh_or_skip >= 0)
5265 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5266 gcc_assert (size_of_uleb128 (r)
5267 == size_of_uleb128 (val1->v.val_unsigned));
5268 dw2_asm_output_data_uleb128 (r, NULL);
5269 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5273 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5275 case DW_OP_bit_piece:
5276 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5277 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5279 case DW_OP_deref_size:
5280 case DW_OP_xderef_size:
5281 dw2_asm_output_data (1, val1->v.val_int, NULL);
5287 if (targetm.asm_out.output_dwarf_dtprel)
5289 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5292 fputc ('\n', asm_out_file);
5299 #ifdef DWARF2_DEBUGGING_INFO
5300 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5307 case DW_OP_GNU_implicit_pointer:
5309 char label[MAX_ARTIFICIAL_LABEL_BYTES
5310 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5311 gcc_assert (val1->val_class == dw_val_class_die_ref);
5312 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5313 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5314 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5318 case DW_OP_GNU_entry_value:
5319 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5320 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5324 /* Other codes have no operands. */
5329 /* Output a sequence of location operations.
5330 The for_eh_or_skip parameter controls whether register numbers are
5331 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5332 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5333 info). This should be suppressed for the cases that have not been converted
5334 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5337 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5339 for (; loc != NULL; loc = loc->dw_loc_next)
5341 enum dwarf_location_atom opc = loc->dw_loc_opc;
5342 /* Output the opcode. */
5343 if (for_eh_or_skip >= 0
5344 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5346 unsigned r = (opc - DW_OP_breg0);
5347 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5348 gcc_assert (r <= 31);
5349 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5351 else if (for_eh_or_skip >= 0
5352 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5354 unsigned r = (opc - DW_OP_reg0);
5355 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5356 gcc_assert (r <= 31);
5357 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5360 dw2_asm_output_data (1, opc,
5361 "%s", dwarf_stack_op_name (opc));
5363 /* Output the operand(s) (if any). */
5364 output_loc_operands (loc, for_eh_or_skip);
5368 /* Output location description stack opcode's operands (if any).
5369 The output is single bytes on a line, suitable for .cfi_escape. */
5372 output_loc_operands_raw (dw_loc_descr_ref loc)
5374 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5375 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5377 switch (loc->dw_loc_opc)
5380 case DW_OP_implicit_value:
5381 /* We cannot output addresses in .cfi_escape, only bytes. */
5387 case DW_OP_deref_size:
5388 case DW_OP_xderef_size:
5389 fputc (',', asm_out_file);
5390 dw2_asm_output_data_raw (1, val1->v.val_int);
5395 fputc (',', asm_out_file);
5396 dw2_asm_output_data_raw (2, val1->v.val_int);
5401 fputc (',', asm_out_file);
5402 dw2_asm_output_data_raw (4, val1->v.val_int);
5407 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5408 fputc (',', asm_out_file);
5409 dw2_asm_output_data_raw (8, val1->v.val_int);
5417 gcc_assert (val1->val_class == dw_val_class_loc);
5418 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5420 fputc (',', asm_out_file);
5421 dw2_asm_output_data_raw (2, offset);
5427 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5428 gcc_assert (size_of_uleb128 (r)
5429 == size_of_uleb128 (val1->v.val_unsigned));
5430 fputc (',', asm_out_file);
5431 dw2_asm_output_data_uleb128_raw (r);
5436 case DW_OP_plus_uconst:
5438 fputc (',', asm_out_file);
5439 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5442 case DW_OP_bit_piece:
5443 fputc (',', asm_out_file);
5444 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5445 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5482 fputc (',', asm_out_file);
5483 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5488 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5489 gcc_assert (size_of_uleb128 (r)
5490 == size_of_uleb128 (val1->v.val_unsigned));
5491 fputc (',', asm_out_file);
5492 dw2_asm_output_data_uleb128_raw (r);
5493 fputc (',', asm_out_file);
5494 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5498 case DW_OP_GNU_implicit_pointer:
5499 case DW_OP_GNU_entry_value:
5504 /* Other codes have no operands. */
5510 output_loc_sequence_raw (dw_loc_descr_ref loc)
5514 enum dwarf_location_atom opc = loc->dw_loc_opc;
5515 /* Output the opcode. */
5516 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5518 unsigned r = (opc - DW_OP_breg0);
5519 r = DWARF2_FRAME_REG_OUT (r, 1);
5520 gcc_assert (r <= 31);
5521 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5523 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5525 unsigned r = (opc - DW_OP_reg0);
5526 r = DWARF2_FRAME_REG_OUT (r, 1);
5527 gcc_assert (r <= 31);
5528 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5530 /* Output the opcode. */
5531 fprintf (asm_out_file, "%#x", opc);
5532 output_loc_operands_raw (loc);
5534 if (!loc->dw_loc_next)
5536 loc = loc->dw_loc_next;
5538 fputc (',', asm_out_file);
5542 /* This routine will generate the correct assembly data for a location
5543 description based on a cfi entry with a complex address. */
5546 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5548 dw_loc_descr_ref loc;
5551 if (cfi->dw_cfi_opc == DW_CFA_expression)
5554 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5555 dw2_asm_output_data (1, r, NULL);
5556 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5559 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5561 /* Output the size of the block. */
5562 size = size_of_locs (loc);
5563 dw2_asm_output_data_uleb128 (size, NULL);
5565 /* Now output the operations themselves. */
5566 output_loc_sequence (loc, for_eh);
5569 /* Similar, but used for .cfi_escape. */
5572 output_cfa_loc_raw (dw_cfi_ref cfi)
5574 dw_loc_descr_ref loc;
5577 if (cfi->dw_cfi_opc == DW_CFA_expression)
5580 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5581 fprintf (asm_out_file, "%#x,", r);
5582 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5585 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5587 /* Output the size of the block. */
5588 size = size_of_locs (loc);
5589 dw2_asm_output_data_uleb128_raw (size);
5590 fputc (',', asm_out_file);
5592 /* Now output the operations themselves. */
5593 output_loc_sequence_raw (loc);
5596 /* This function builds a dwarf location descriptor sequence from a
5597 dw_cfa_location, adding the given OFFSET to the result of the
5600 static struct dw_loc_descr_struct *
5601 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5603 struct dw_loc_descr_struct *head, *tmp;
5605 offset += cfa->offset;
5609 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5610 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5611 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5612 add_loc_descr (&head, tmp);
5615 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5616 add_loc_descr (&head, tmp);
5620 head = new_reg_loc_descr (cfa->reg, offset);
5625 /* This function builds a dwarf location descriptor sequence for
5626 the address at OFFSET from the CFA when stack is aligned to
5629 static struct dw_loc_descr_struct *
5630 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5632 struct dw_loc_descr_struct *head;
5633 unsigned int dwarf_fp
5634 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5636 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5637 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5639 head = new_reg_loc_descr (dwarf_fp, 0);
5640 add_loc_descr (&head, int_loc_descriptor (alignment));
5641 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5642 loc_descr_plus_const (&head, offset);
5645 head = new_reg_loc_descr (dwarf_fp, offset);
5649 /* This function fills in aa dw_cfa_location structure from a dwarf location
5650 descriptor sequence. */
5653 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5655 struct dw_loc_descr_struct *ptr;
5657 cfa->base_offset = 0;
5661 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5663 enum dwarf_location_atom op = ptr->dw_loc_opc;
5699 cfa->reg = op - DW_OP_reg0;
5702 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5736 cfa->reg = op - DW_OP_breg0;
5737 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5740 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5741 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5746 case DW_OP_plus_uconst:
5747 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5750 internal_error ("DW_LOC_OP %s not implemented",
5751 dwarf_stack_op_name (ptr->dw_loc_opc));
5756 /* And now, the support for symbolic debugging information. */
5758 /* .debug_str support. */
5759 static int output_indirect_string (void **, void *);
5761 static void dwarf2out_init (const char *);
5762 static void dwarf2out_finish (const char *);
5763 static void dwarf2out_assembly_start (void);
5764 static void dwarf2out_define (unsigned int, const char *);
5765 static void dwarf2out_undef (unsigned int, const char *);
5766 static void dwarf2out_start_source_file (unsigned, const char *);
5767 static void dwarf2out_end_source_file (unsigned);
5768 static void dwarf2out_function_decl (tree);
5769 static void dwarf2out_begin_block (unsigned, unsigned);
5770 static void dwarf2out_end_block (unsigned, unsigned);
5771 static bool dwarf2out_ignore_block (const_tree);
5772 static void dwarf2out_global_decl (tree);
5773 static void dwarf2out_type_decl (tree, int);
5774 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5775 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5777 static void dwarf2out_abstract_function (tree);
5778 static void dwarf2out_var_location (rtx);
5779 static void dwarf2out_begin_function (tree);
5780 static void dwarf2out_set_name (tree, tree);
5782 /* The debug hooks structure. */
5784 const struct gcc_debug_hooks dwarf2_debug_hooks =
5788 dwarf2out_assembly_start,
5791 dwarf2out_start_source_file,
5792 dwarf2out_end_source_file,
5793 dwarf2out_begin_block,
5794 dwarf2out_end_block,
5795 dwarf2out_ignore_block,
5796 dwarf2out_source_line,
5797 dwarf2out_begin_prologue,
5798 #if VMS_DEBUGGING_INFO
5799 dwarf2out_vms_end_prologue,
5800 dwarf2out_vms_begin_epilogue,
5802 debug_nothing_int_charstar,
5803 debug_nothing_int_charstar,
5805 dwarf2out_end_epilogue,
5806 dwarf2out_begin_function,
5807 debug_nothing_int, /* end_function */
5808 dwarf2out_function_decl, /* function_decl */
5809 dwarf2out_global_decl,
5810 dwarf2out_type_decl, /* type_decl */
5811 dwarf2out_imported_module_or_decl,
5812 debug_nothing_tree, /* deferred_inline_function */
5813 /* The DWARF 2 backend tries to reduce debugging bloat by not
5814 emitting the abstract description of inline functions until
5815 something tries to reference them. */
5816 dwarf2out_abstract_function, /* outlining_inline_function */
5817 debug_nothing_rtx, /* label */
5818 debug_nothing_int, /* handle_pch */
5819 dwarf2out_var_location,
5820 dwarf2out_switch_text_section,
5822 1, /* start_end_main_source_file */
5823 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5826 /* NOTE: In the comments in this file, many references are made to
5827 "Debugging Information Entries". This term is abbreviated as `DIE'
5828 throughout the remainder of this file. */
5830 /* An internal representation of the DWARF output is built, and then
5831 walked to generate the DWARF debugging info. The walk of the internal
5832 representation is done after the entire program has been compiled.
5833 The types below are used to describe the internal representation. */
5835 /* Various DIE's use offsets relative to the beginning of the
5836 .debug_info section to refer to each other. */
5838 typedef long int dw_offset;
5840 /* Define typedefs here to avoid circular dependencies. */
5842 typedef struct dw_attr_struct *dw_attr_ref;
5843 typedef struct dw_line_info_struct *dw_line_info_ref;
5844 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5845 typedef struct pubname_struct *pubname_ref;
5846 typedef struct dw_ranges_struct *dw_ranges_ref;
5847 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5848 typedef struct comdat_type_struct *comdat_type_node_ref;
5850 /* Each entry in the line_info_table maintains the file and
5851 line number associated with the label generated for that
5852 entry. The label gives the PC value associated with
5853 the line number entry. */
5855 typedef struct GTY(()) dw_line_info_struct {
5856 unsigned long dw_file_num;
5857 unsigned long dw_line_num;
5861 /* Line information for functions in separate sections; each one gets its
5863 typedef struct GTY(()) dw_separate_line_info_struct {
5864 unsigned long dw_file_num;
5865 unsigned long dw_line_num;
5866 unsigned long function;
5868 dw_separate_line_info_entry;
5870 /* Each DIE attribute has a field specifying the attribute kind,
5871 a link to the next attribute in the chain, and an attribute value.
5872 Attributes are typically linked below the DIE they modify. */
5874 typedef struct GTY(()) dw_attr_struct {
5875 enum dwarf_attribute dw_attr;
5876 dw_val_node dw_attr_val;
5880 DEF_VEC_O(dw_attr_node);
5881 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5883 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5884 The children of each node form a circular list linked by
5885 die_sib. die_child points to the node *before* the "first" child node. */
5887 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5888 union die_symbol_or_type_node
5890 char * GTY ((tag ("0"))) die_symbol;
5891 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5893 GTY ((desc ("dwarf_version >= 4"))) die_id;
5894 VEC(dw_attr_node,gc) * die_attr;
5895 dw_die_ref die_parent;
5896 dw_die_ref die_child;
5898 dw_die_ref die_definition; /* ref from a specification to its definition */
5899 dw_offset die_offset;
5900 unsigned long die_abbrev;
5902 /* Die is used and must not be pruned as unused. */
5903 int die_perennial_p;
5904 unsigned int decl_id;
5905 enum dwarf_tag die_tag;
5909 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5910 #define FOR_EACH_CHILD(die, c, expr) do { \
5911 c = die->die_child; \
5915 } while (c != die->die_child); \
5918 /* The pubname structure */
5920 typedef struct GTY(()) pubname_struct {
5926 DEF_VEC_O(pubname_entry);
5927 DEF_VEC_ALLOC_O(pubname_entry, gc);
5929 struct GTY(()) dw_ranges_struct {
5930 /* If this is positive, it's a block number, otherwise it's a
5931 bitwise-negated index into dw_ranges_by_label. */
5935 /* A structure to hold a macinfo entry. */
5937 typedef struct GTY(()) macinfo_struct {
5938 unsigned HOST_WIDE_INT code;
5939 unsigned HOST_WIDE_INT lineno;
5944 DEF_VEC_O(macinfo_entry);
5945 DEF_VEC_ALLOC_O(macinfo_entry, gc);
5947 struct GTY(()) dw_ranges_by_label_struct {
5952 /* The comdat type node structure. */
5953 typedef struct GTY(()) comdat_type_struct
5955 dw_die_ref root_die;
5956 dw_die_ref type_die;
5957 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5958 struct comdat_type_struct *next;
5962 /* The limbo die list structure. */
5963 typedef struct GTY(()) limbo_die_struct {
5966 struct limbo_die_struct *next;
5970 typedef struct skeleton_chain_struct
5974 struct skeleton_chain_struct *parent;
5976 skeleton_chain_node;
5978 /* How to start an assembler comment. */
5979 #ifndef ASM_COMMENT_START
5980 #define ASM_COMMENT_START ";#"
5983 /* Define a macro which returns nonzero for a TYPE_DECL which was
5984 implicitly generated for a tagged type.
5986 Note that unlike the gcc front end (which generates a NULL named
5987 TYPE_DECL node for each complete tagged type, each array type, and
5988 each function type node created) the g++ front end generates a
5989 _named_ TYPE_DECL node for each tagged type node created.
5990 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5991 generate a DW_TAG_typedef DIE for them. */
5993 #define TYPE_DECL_IS_STUB(decl) \
5994 (DECL_NAME (decl) == NULL_TREE \
5995 || (DECL_ARTIFICIAL (decl) \
5996 && is_tagged_type (TREE_TYPE (decl)) \
5997 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5998 /* This is necessary for stub decls that \
5999 appear in nested inline functions. */ \
6000 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6001 && (decl_ultimate_origin (decl) \
6002 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6004 /* Information concerning the compilation unit's programming
6005 language, and compiler version. */
6007 /* Fixed size portion of the DWARF compilation unit header. */
6008 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6009 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6011 /* Fixed size portion of the DWARF comdat type unit header. */
6012 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6013 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6014 + DWARF_OFFSET_SIZE)
6016 /* Fixed size portion of public names info. */
6017 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6019 /* Fixed size portion of the address range info. */
6020 #define DWARF_ARANGES_HEADER_SIZE \
6021 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6022 DWARF2_ADDR_SIZE * 2) \
6023 - DWARF_INITIAL_LENGTH_SIZE)
6025 /* Size of padding portion in the address range info. It must be
6026 aligned to twice the pointer size. */
6027 #define DWARF_ARANGES_PAD_SIZE \
6028 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6029 DWARF2_ADDR_SIZE * 2) \
6030 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6032 /* Use assembler line directives if available. */
6033 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6034 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6035 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6037 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6041 /* Minimum line offset in a special line info. opcode.
6042 This value was chosen to give a reasonable range of values. */
6043 #define DWARF_LINE_BASE -10
6045 /* First special line opcode - leave room for the standard opcodes. */
6046 #define DWARF_LINE_OPCODE_BASE 10
6048 /* Range of line offsets in a special line info. opcode. */
6049 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6051 /* Flag that indicates the initial value of the is_stmt_start flag.
6052 In the present implementation, we do not mark any lines as
6053 the beginning of a source statement, because that information
6054 is not made available by the GCC front-end. */
6055 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6057 /* Maximum number of operations per instruction bundle. */
6058 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6059 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6062 /* This location is used by calc_die_sizes() to keep track
6063 the offset of each DIE within the .debug_info section. */
6064 static unsigned long next_die_offset;
6066 /* Record the root of the DIE's built for the current compilation unit. */
6067 static GTY(()) dw_die_ref single_comp_unit_die;
6069 /* A list of type DIEs that have been separated into comdat sections. */
6070 static GTY(()) comdat_type_node *comdat_type_list;
6072 /* A list of DIEs with a NULL parent waiting to be relocated. */
6073 static GTY(()) limbo_die_node *limbo_die_list;
6075 /* A list of DIEs for which we may have to generate
6076 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6077 static GTY(()) limbo_die_node *deferred_asm_name;
6079 /* Filenames referenced by this compilation unit. */
6080 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6082 /* A hash table of references to DIE's that describe declarations.
6083 The key is a DECL_UID() which is a unique number identifying each decl. */
6084 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6086 /* A hash table of references to DIE's that describe COMMON blocks.
6087 The key is DECL_UID() ^ die_parent. */
6088 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6090 typedef struct GTY(()) die_arg_entry_struct {
6095 DEF_VEC_O(die_arg_entry);
6096 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6098 /* Node of the variable location list. */
6099 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6100 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6101 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6102 in mode of the EXPR_LIST node and first EXPR_LIST operand
6103 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6104 location or NULL for padding. For larger bitsizes,
6105 mode is 0 and first operand is a CONCAT with bitsize
6106 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6107 NULL as second operand. */
6109 const char * GTY (()) label;
6110 struct var_loc_node * GTY (()) next;
6113 /* Variable location list. */
6114 struct GTY (()) var_loc_list_def {
6115 struct var_loc_node * GTY (()) first;
6117 /* Pointer to the last but one or last element of the
6118 chained list. If the list is empty, both first and
6119 last are NULL, if the list contains just one node
6120 or the last node certainly is not redundant, it points
6121 to the last node, otherwise points to the last but one.
6122 Do not mark it for GC because it is marked through the chain. */
6123 struct var_loc_node * GTY ((skip ("%h"))) last;
6125 /* DECL_UID of the variable decl. */
6126 unsigned int decl_id;
6128 typedef struct var_loc_list_def var_loc_list;
6130 /* Call argument location list. */
6131 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6132 rtx GTY (()) call_arg_loc_note;
6133 const char * GTY (()) label;
6134 tree GTY (()) block;
6136 rtx GTY (()) symbol_ref;
6137 struct call_arg_loc_node * GTY (()) next;
6141 /* Table of decl location linked lists. */
6142 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6144 /* Head and tail of call_arg_loc chain. */
6145 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6146 static struct call_arg_loc_node *call_arg_loc_last;
6148 /* Number of call sites in the current function. */
6149 static int call_site_count = -1;
6150 /* Number of tail call sites in the current function. */
6151 static int tail_call_site_count = -1;
6153 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6155 static VEC (dw_die_ref, heap) *block_map;
6157 /* A pointer to the base of a list of references to DIE's that
6158 are uniquely identified by their tag, presence/absence of
6159 children DIE's, and list of attribute/value pairs. */
6160 static GTY((length ("abbrev_die_table_allocated")))
6161 dw_die_ref *abbrev_die_table;
6163 /* Number of elements currently allocated for abbrev_die_table. */
6164 static GTY(()) unsigned abbrev_die_table_allocated;
6166 /* Number of elements in type_die_table currently in use. */
6167 static GTY(()) unsigned abbrev_die_table_in_use;
6169 /* Size (in elements) of increments by which we may expand the
6170 abbrev_die_table. */
6171 #define ABBREV_DIE_TABLE_INCREMENT 256
6173 /* A pointer to the base of a table that contains line information
6174 for each source code line in .text in the compilation unit. */
6175 static GTY((length ("line_info_table_allocated")))
6176 dw_line_info_ref line_info_table;
6178 /* Number of elements currently allocated for line_info_table. */
6179 static GTY(()) unsigned line_info_table_allocated;
6181 /* Number of elements in line_info_table currently in use. */
6182 static GTY(()) unsigned line_info_table_in_use;
6184 /* A pointer to the base of a table that contains line information
6185 for each source code line outside of .text in the compilation unit. */
6186 static GTY ((length ("separate_line_info_table_allocated")))
6187 dw_separate_line_info_ref separate_line_info_table;
6189 /* Number of elements currently allocated for separate_line_info_table. */
6190 static GTY(()) unsigned separate_line_info_table_allocated;
6192 /* Number of elements in separate_line_info_table currently in use. */
6193 static GTY(()) unsigned separate_line_info_table_in_use;
6195 /* Size (in elements) of increments by which we may expand the
6197 #define LINE_INFO_TABLE_INCREMENT 1024
6199 /* A flag to tell pubnames/types export if there is an info section to
6201 static bool info_section_emitted;
6203 /* A pointer to the base of a table that contains a list of publicly
6204 accessible names. */
6205 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6207 /* A pointer to the base of a table that contains a list of publicly
6208 accessible types. */
6209 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6211 /* A pointer to the base of a table that contains a list of macro
6212 defines/undefines (and file start/end markers). */
6213 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6215 /* Array of dies for which we should generate .debug_arange info. */
6216 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
6218 /* Number of elements currently allocated for arange_table. */
6219 static GTY(()) unsigned arange_table_allocated;
6221 /* Number of elements in arange_table currently in use. */
6222 static GTY(()) unsigned arange_table_in_use;
6224 /* Size (in elements) of increments by which we may expand the
6226 #define ARANGE_TABLE_INCREMENT 64
6228 /* Array of dies for which we should generate .debug_ranges info. */
6229 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6231 /* Number of elements currently allocated for ranges_table. */
6232 static GTY(()) unsigned ranges_table_allocated;
6234 /* Number of elements in ranges_table currently in use. */
6235 static GTY(()) unsigned ranges_table_in_use;
6237 /* Array of pairs of labels referenced in ranges_table. */
6238 static GTY ((length ("ranges_by_label_allocated")))
6239 dw_ranges_by_label_ref ranges_by_label;
6241 /* Number of elements currently allocated for ranges_by_label. */
6242 static GTY(()) unsigned ranges_by_label_allocated;
6244 /* Number of elements in ranges_by_label currently in use. */
6245 static GTY(()) unsigned ranges_by_label_in_use;
6247 /* Size (in elements) of increments by which we may expand the
6249 #define RANGES_TABLE_INCREMENT 64
6251 /* Whether we have location lists that need outputting */
6252 static GTY(()) bool have_location_lists;
6254 /* Unique label counter. */
6255 static GTY(()) unsigned int loclabel_num;
6257 /* Unique label counter for point-of-call tables. */
6258 static GTY(()) unsigned int poc_label_num;
6260 /* Record whether the function being analyzed contains inlined functions. */
6261 static int current_function_has_inlines;
6263 /* The last file entry emitted by maybe_emit_file(). */
6264 static GTY(()) struct dwarf_file_data * last_emitted_file;
6266 /* Number of internal labels generated by gen_internal_sym(). */
6267 static GTY(()) int label_num;
6269 /* Cached result of previous call to lookup_filename. */
6270 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6272 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6274 /* Instances of generic types for which we need to generate debug
6275 info that describe their generic parameters and arguments. That
6276 generation needs to happen once all types are properly laid out so
6277 we do it at the end of compilation. */
6278 static GTY(()) VEC(tree,gc) *generic_type_instances;
6280 /* Offset from the "steady-state frame pointer" to the frame base,
6281 within the current function. */
6282 static HOST_WIDE_INT frame_pointer_fb_offset;
6284 /* Forward declarations for functions defined in this file. */
6286 static int is_pseudo_reg (const_rtx);
6287 static tree type_main_variant (tree);
6288 static int is_tagged_type (const_tree);
6289 static const char *dwarf_tag_name (unsigned);
6290 static const char *dwarf_attr_name (unsigned);
6291 static const char *dwarf_form_name (unsigned);
6292 static tree decl_ultimate_origin (const_tree);
6293 static tree decl_class_context (tree);
6294 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6295 static inline enum dw_val_class AT_class (dw_attr_ref);
6296 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6297 static inline unsigned AT_flag (dw_attr_ref);
6298 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6299 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6300 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6301 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6302 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6303 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6304 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6305 unsigned int, unsigned char *);
6306 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6307 static hashval_t debug_str_do_hash (const void *);
6308 static int debug_str_eq (const void *, const void *);
6309 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6310 static inline const char *AT_string (dw_attr_ref);
6311 static enum dwarf_form AT_string_form (dw_attr_ref);
6312 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6313 static void add_AT_specification (dw_die_ref, dw_die_ref);
6314 static inline dw_die_ref AT_ref (dw_attr_ref);
6315 static inline int AT_ref_external (dw_attr_ref);
6316 static inline void set_AT_ref_external (dw_attr_ref, int);
6317 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6318 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6319 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6320 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6322 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6323 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6324 static inline rtx AT_addr (dw_attr_ref);
6325 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6326 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6327 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6328 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6329 unsigned HOST_WIDE_INT);
6330 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6332 static inline const char *AT_lbl (dw_attr_ref);
6333 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6334 static const char *get_AT_low_pc (dw_die_ref);
6335 static const char *get_AT_hi_pc (dw_die_ref);
6336 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6337 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6338 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6339 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6340 static bool is_cxx (void);
6341 static bool is_fortran (void);
6342 static bool is_ada (void);
6343 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6344 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6345 static void add_child_die (dw_die_ref, dw_die_ref);
6346 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6347 static dw_die_ref lookup_type_die (tree);
6348 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6349 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6350 static void equate_type_number_to_die (tree, dw_die_ref);
6351 static hashval_t decl_die_table_hash (const void *);
6352 static int decl_die_table_eq (const void *, const void *);
6353 static dw_die_ref lookup_decl_die (tree);
6354 static hashval_t common_block_die_table_hash (const void *);
6355 static int common_block_die_table_eq (const void *, const void *);
6356 static hashval_t decl_loc_table_hash (const void *);
6357 static int decl_loc_table_eq (const void *, const void *);
6358 static var_loc_list *lookup_decl_loc (const_tree);
6359 static void equate_decl_number_to_die (tree, dw_die_ref);
6360 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6361 static void print_spaces (FILE *);
6362 static void print_die (dw_die_ref, FILE *);
6363 static void print_dwarf_line_table (FILE *);
6364 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6365 static dw_die_ref pop_compile_unit (dw_die_ref);
6366 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6367 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6368 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6369 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6370 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6371 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6372 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6373 struct md5_ctx *, int *);
6374 struct checksum_attributes;
6375 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6376 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6377 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6378 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6379 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6380 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6381 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6382 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6383 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6384 static void compute_section_prefix (dw_die_ref);
6385 static int is_type_die (dw_die_ref);
6386 static int is_comdat_die (dw_die_ref);
6387 static int is_symbol_die (dw_die_ref);
6388 static void assign_symbol_names (dw_die_ref);
6389 static void break_out_includes (dw_die_ref);
6390 static int is_declaration_die (dw_die_ref);
6391 static int should_move_die_to_comdat (dw_die_ref);
6392 static dw_die_ref clone_as_declaration (dw_die_ref);
6393 static dw_die_ref clone_die (dw_die_ref);
6394 static dw_die_ref clone_tree (dw_die_ref);
6395 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6396 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6397 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6398 static dw_die_ref generate_skeleton (dw_die_ref);
6399 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6401 static void break_out_comdat_types (dw_die_ref);
6402 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6403 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6404 static void copy_decls_for_unworthy_types (dw_die_ref);
6406 static hashval_t htab_cu_hash (const void *);
6407 static int htab_cu_eq (const void *, const void *);
6408 static void htab_cu_del (void *);
6409 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6410 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6411 static void add_sibling_attributes (dw_die_ref);
6412 static void build_abbrev_table (dw_die_ref);
6413 static void output_location_lists (dw_die_ref);
6414 static int constant_size (unsigned HOST_WIDE_INT);
6415 static unsigned long size_of_die (dw_die_ref);
6416 static void calc_die_sizes (dw_die_ref);
6417 static void mark_dies (dw_die_ref);
6418 static void unmark_dies (dw_die_ref);
6419 static void unmark_all_dies (dw_die_ref);
6420 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6421 static unsigned long size_of_aranges (void);
6422 static enum dwarf_form value_format (dw_attr_ref);
6423 static void output_value_format (dw_attr_ref);
6424 static void output_abbrev_section (void);
6425 static void output_die_symbol (dw_die_ref);
6426 static void output_die (dw_die_ref);
6427 static void output_compilation_unit_header (void);
6428 static void output_comp_unit (dw_die_ref, int);
6429 static void output_comdat_type_unit (comdat_type_node *);
6430 static const char *dwarf2_name (tree, int);
6431 static void add_pubname (tree, dw_die_ref);
6432 static void add_pubname_string (const char *, dw_die_ref);
6433 static void add_pubtype (tree, dw_die_ref);
6434 static void output_pubnames (VEC (pubname_entry,gc) *);
6435 static void add_arange (tree, dw_die_ref);
6436 static void output_aranges (void);
6437 static unsigned int add_ranges_num (int);
6438 static unsigned int add_ranges (const_tree);
6439 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6441 static void output_ranges (void);
6442 static void output_line_info (void);
6443 static void output_file_names (void);
6444 static dw_die_ref base_type_die (tree);
6445 static int is_base_type (tree);
6446 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6447 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6448 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6449 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6450 static int type_is_enum (const_tree);
6451 static unsigned int dbx_reg_number (const_rtx);
6452 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6453 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6454 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6455 enum var_init_status);
6456 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6457 enum var_init_status);
6458 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6459 enum var_init_status);
6460 static int is_based_loc (const_rtx);
6461 static int resolve_one_addr (rtx *, void *);
6462 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6463 enum var_init_status);
6464 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6465 enum var_init_status);
6466 static dw_loc_list_ref loc_list_from_tree (tree, int);
6467 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6468 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6469 static tree field_type (const_tree);
6470 static unsigned int simple_type_align_in_bits (const_tree);
6471 static unsigned int simple_decl_align_in_bits (const_tree);
6472 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6473 static HOST_WIDE_INT field_byte_offset (const_tree);
6474 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6476 static void add_data_member_location_attribute (dw_die_ref, tree);
6477 static bool add_const_value_attribute (dw_die_ref, rtx);
6478 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6479 static void insert_double (double_int, unsigned char *);
6480 static void insert_float (const_rtx, unsigned char *);
6481 static rtx rtl_for_decl_location (tree);
6482 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
6483 enum dwarf_attribute);
6484 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6485 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6486 static void add_name_attribute (dw_die_ref, const char *);
6487 static void add_comp_dir_attribute (dw_die_ref);
6488 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6489 static void add_subscript_info (dw_die_ref, tree, bool);
6490 static void add_byte_size_attribute (dw_die_ref, tree);
6491 static void add_bit_offset_attribute (dw_die_ref, tree);
6492 static void add_bit_size_attribute (dw_die_ref, tree);
6493 static void add_prototyped_attribute (dw_die_ref, tree);
6494 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6495 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6496 static void add_src_coords_attributes (dw_die_ref, tree);
6497 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6498 static void push_decl_scope (tree);
6499 static void pop_decl_scope (void);
6500 static dw_die_ref scope_die_for (tree, dw_die_ref);
6501 static inline int local_scope_p (dw_die_ref);
6502 static inline int class_scope_p (dw_die_ref);
6503 static inline int class_or_namespace_scope_p (dw_die_ref);
6504 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6505 static void add_calling_convention_attribute (dw_die_ref, tree);
6506 static const char *type_tag (const_tree);
6507 static tree member_declared_type (const_tree);
6509 static const char *decl_start_label (tree);
6511 static void gen_array_type_die (tree, dw_die_ref);
6512 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6514 static void gen_entry_point_die (tree, dw_die_ref);
6516 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6517 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6518 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6519 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6520 static void gen_formal_types_die (tree, dw_die_ref);
6521 static void gen_subprogram_die (tree, dw_die_ref);
6522 static void gen_variable_die (tree, tree, dw_die_ref);
6523 static void gen_const_die (tree, dw_die_ref);
6524 static void gen_label_die (tree, dw_die_ref);
6525 static void gen_lexical_block_die (tree, dw_die_ref, int);
6526 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6527 static void gen_field_die (tree, dw_die_ref);
6528 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6529 static dw_die_ref gen_compile_unit_die (const char *);
6530 static void gen_inheritance_die (tree, tree, dw_die_ref);
6531 static void gen_member_die (tree, dw_die_ref);
6532 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6533 enum debug_info_usage);
6534 static void gen_subroutine_type_die (tree, dw_die_ref);
6535 static void gen_typedef_die (tree, dw_die_ref);
6536 static void gen_type_die (tree, dw_die_ref);
6537 static void gen_block_die (tree, dw_die_ref, int);
6538 static void decls_for_scope (tree, dw_die_ref, int);
6539 static int is_redundant_typedef (const_tree);
6540 static bool is_naming_typedef_decl (const_tree);
6541 static inline dw_die_ref get_context_die (tree);
6542 static void gen_namespace_die (tree, dw_die_ref);
6543 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6544 static dw_die_ref force_decl_die (tree);
6545 static dw_die_ref force_type_die (tree);
6546 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6547 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6548 static struct dwarf_file_data * lookup_filename (const char *);
6549 static void retry_incomplete_types (void);
6550 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6551 static void gen_generic_params_dies (tree);
6552 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6553 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6554 static void splice_child_die (dw_die_ref, dw_die_ref);
6555 static int file_info_cmp (const void *, const void *);
6556 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6557 const char *, const char *);
6558 static void output_loc_list (dw_loc_list_ref);
6559 static char *gen_internal_sym (const char *);
6561 static void prune_unmark_dies (dw_die_ref);
6562 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6563 static void prune_unused_types_mark (dw_die_ref, int);
6564 static void prune_unused_types_walk (dw_die_ref);
6565 static void prune_unused_types_walk_attribs (dw_die_ref);
6566 static void prune_unused_types_prune (dw_die_ref);
6567 static void prune_unused_types (void);
6568 static int maybe_emit_file (struct dwarf_file_data *fd);
6569 static inline const char *AT_vms_delta1 (dw_attr_ref);
6570 static inline const char *AT_vms_delta2 (dw_attr_ref);
6571 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6572 const char *, const char *);
6573 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6574 static void gen_remaining_tmpl_value_param_die_attribute (void);
6575 static bool generic_type_p (tree);
6576 static void schedule_generic_params_dies_gen (tree t);
6577 static void gen_scheduled_generic_parms_dies (void);
6579 /* Section names used to hold DWARF debugging information. */
6580 #ifndef DEBUG_INFO_SECTION
6581 #define DEBUG_INFO_SECTION ".debug_info"
6583 #ifndef DEBUG_ABBREV_SECTION
6584 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6586 #ifndef DEBUG_ARANGES_SECTION
6587 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6589 #ifndef DEBUG_MACINFO_SECTION
6590 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6592 #ifndef DEBUG_LINE_SECTION
6593 #define DEBUG_LINE_SECTION ".debug_line"
6595 #ifndef DEBUG_LOC_SECTION
6596 #define DEBUG_LOC_SECTION ".debug_loc"
6598 #ifndef DEBUG_PUBNAMES_SECTION
6599 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6601 #ifndef DEBUG_PUBTYPES_SECTION
6602 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6604 #ifndef DEBUG_STR_SECTION
6605 #define DEBUG_STR_SECTION ".debug_str"
6607 #ifndef DEBUG_RANGES_SECTION
6608 #define DEBUG_RANGES_SECTION ".debug_ranges"
6611 /* Standard ELF section names for compiled code and data. */
6612 #ifndef TEXT_SECTION_NAME
6613 #define TEXT_SECTION_NAME ".text"
6616 /* Section flags for .debug_str section. */
6617 #define DEBUG_STR_SECTION_FLAGS \
6618 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6619 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6622 /* Labels we insert at beginning sections we can reference instead of
6623 the section names themselves. */
6625 #ifndef TEXT_SECTION_LABEL
6626 #define TEXT_SECTION_LABEL "Ltext"
6628 #ifndef COLD_TEXT_SECTION_LABEL
6629 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6631 #ifndef DEBUG_LINE_SECTION_LABEL
6632 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6634 #ifndef DEBUG_INFO_SECTION_LABEL
6635 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6637 #ifndef DEBUG_ABBREV_SECTION_LABEL
6638 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6640 #ifndef DEBUG_LOC_SECTION_LABEL
6641 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6643 #ifndef DEBUG_RANGES_SECTION_LABEL
6644 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6646 #ifndef DEBUG_MACINFO_SECTION_LABEL
6647 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6651 /* Definitions of defaults for formats and names of various special
6652 (artificial) labels which may be generated within this file (when the -g
6653 options is used and DWARF2_DEBUGGING_INFO is in effect.
6654 If necessary, these may be overridden from within the tm.h file, but
6655 typically, overriding these defaults is unnecessary. */
6657 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6658 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6659 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6660 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6661 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6662 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6663 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6664 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6665 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6666 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6668 #ifndef TEXT_END_LABEL
6669 #define TEXT_END_LABEL "Letext"
6671 #ifndef COLD_END_LABEL
6672 #define COLD_END_LABEL "Letext_cold"
6674 #ifndef BLOCK_BEGIN_LABEL
6675 #define BLOCK_BEGIN_LABEL "LBB"
6677 #ifndef BLOCK_END_LABEL
6678 #define BLOCK_END_LABEL "LBE"
6680 #ifndef LINE_CODE_LABEL
6681 #define LINE_CODE_LABEL "LM"
6683 #ifndef SEPARATE_LINE_CODE_LABEL
6684 #define SEPARATE_LINE_CODE_LABEL "LSM"
6688 /* Return the root of the DIE's built for the current compilation unit. */
6690 comp_unit_die (void)
6692 if (!single_comp_unit_die)
6693 single_comp_unit_die = gen_compile_unit_die (NULL);
6694 return single_comp_unit_die;
6697 /* We allow a language front-end to designate a function that is to be
6698 called to "demangle" any name before it is put into a DIE. */
6700 static const char *(*demangle_name_func) (const char *);
6703 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6705 demangle_name_func = func;
6708 /* Test if rtl node points to a pseudo register. */
6711 is_pseudo_reg (const_rtx rtl)
6713 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6714 || (GET_CODE (rtl) == SUBREG
6715 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6718 /* Return a reference to a type, with its const and volatile qualifiers
6722 type_main_variant (tree type)
6724 type = TYPE_MAIN_VARIANT (type);
6726 /* ??? There really should be only one main variant among any group of
6727 variants of a given type (and all of the MAIN_VARIANT values for all
6728 members of the group should point to that one type) but sometimes the C
6729 front-end messes this up for array types, so we work around that bug
6731 if (TREE_CODE (type) == ARRAY_TYPE)
6732 while (type != TYPE_MAIN_VARIANT (type))
6733 type = TYPE_MAIN_VARIANT (type);
6738 /* Return nonzero if the given type node represents a tagged type. */
6741 is_tagged_type (const_tree type)
6743 enum tree_code code = TREE_CODE (type);
6745 return (code == RECORD_TYPE || code == UNION_TYPE
6746 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6749 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6752 get_ref_die_offset_label (char *label, dw_die_ref ref)
6754 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6757 /* Convert a DIE tag into its string name. */
6760 dwarf_tag_name (unsigned int tag)
6764 case DW_TAG_padding:
6765 return "DW_TAG_padding";
6766 case DW_TAG_array_type:
6767 return "DW_TAG_array_type";
6768 case DW_TAG_class_type:
6769 return "DW_TAG_class_type";
6770 case DW_TAG_entry_point:
6771 return "DW_TAG_entry_point";
6772 case DW_TAG_enumeration_type:
6773 return "DW_TAG_enumeration_type";
6774 case DW_TAG_formal_parameter:
6775 return "DW_TAG_formal_parameter";
6776 case DW_TAG_imported_declaration:
6777 return "DW_TAG_imported_declaration";
6779 return "DW_TAG_label";
6780 case DW_TAG_lexical_block:
6781 return "DW_TAG_lexical_block";
6783 return "DW_TAG_member";
6784 case DW_TAG_pointer_type:
6785 return "DW_TAG_pointer_type";
6786 case DW_TAG_reference_type:
6787 return "DW_TAG_reference_type";
6788 case DW_TAG_compile_unit:
6789 return "DW_TAG_compile_unit";
6790 case DW_TAG_string_type:
6791 return "DW_TAG_string_type";
6792 case DW_TAG_structure_type:
6793 return "DW_TAG_structure_type";
6794 case DW_TAG_subroutine_type:
6795 return "DW_TAG_subroutine_type";
6796 case DW_TAG_typedef:
6797 return "DW_TAG_typedef";
6798 case DW_TAG_union_type:
6799 return "DW_TAG_union_type";
6800 case DW_TAG_unspecified_parameters:
6801 return "DW_TAG_unspecified_parameters";
6802 case DW_TAG_variant:
6803 return "DW_TAG_variant";
6804 case DW_TAG_common_block:
6805 return "DW_TAG_common_block";
6806 case DW_TAG_common_inclusion:
6807 return "DW_TAG_common_inclusion";
6808 case DW_TAG_inheritance:
6809 return "DW_TAG_inheritance";
6810 case DW_TAG_inlined_subroutine:
6811 return "DW_TAG_inlined_subroutine";
6813 return "DW_TAG_module";
6814 case DW_TAG_ptr_to_member_type:
6815 return "DW_TAG_ptr_to_member_type";
6816 case DW_TAG_set_type:
6817 return "DW_TAG_set_type";
6818 case DW_TAG_subrange_type:
6819 return "DW_TAG_subrange_type";
6820 case DW_TAG_with_stmt:
6821 return "DW_TAG_with_stmt";
6822 case DW_TAG_access_declaration:
6823 return "DW_TAG_access_declaration";
6824 case DW_TAG_base_type:
6825 return "DW_TAG_base_type";
6826 case DW_TAG_catch_block:
6827 return "DW_TAG_catch_block";
6828 case DW_TAG_const_type:
6829 return "DW_TAG_const_type";
6830 case DW_TAG_constant:
6831 return "DW_TAG_constant";
6832 case DW_TAG_enumerator:
6833 return "DW_TAG_enumerator";
6834 case DW_TAG_file_type:
6835 return "DW_TAG_file_type";
6837 return "DW_TAG_friend";
6838 case DW_TAG_namelist:
6839 return "DW_TAG_namelist";
6840 case DW_TAG_namelist_item:
6841 return "DW_TAG_namelist_item";
6842 case DW_TAG_packed_type:
6843 return "DW_TAG_packed_type";
6844 case DW_TAG_subprogram:
6845 return "DW_TAG_subprogram";
6846 case DW_TAG_template_type_param:
6847 return "DW_TAG_template_type_param";
6848 case DW_TAG_template_value_param:
6849 return "DW_TAG_template_value_param";
6850 case DW_TAG_thrown_type:
6851 return "DW_TAG_thrown_type";
6852 case DW_TAG_try_block:
6853 return "DW_TAG_try_block";
6854 case DW_TAG_variant_part:
6855 return "DW_TAG_variant_part";
6856 case DW_TAG_variable:
6857 return "DW_TAG_variable";
6858 case DW_TAG_volatile_type:
6859 return "DW_TAG_volatile_type";
6860 case DW_TAG_dwarf_procedure:
6861 return "DW_TAG_dwarf_procedure";
6862 case DW_TAG_restrict_type:
6863 return "DW_TAG_restrict_type";
6864 case DW_TAG_interface_type:
6865 return "DW_TAG_interface_type";
6866 case DW_TAG_namespace:
6867 return "DW_TAG_namespace";
6868 case DW_TAG_imported_module:
6869 return "DW_TAG_imported_module";
6870 case DW_TAG_unspecified_type:
6871 return "DW_TAG_unspecified_type";
6872 case DW_TAG_partial_unit:
6873 return "DW_TAG_partial_unit";
6874 case DW_TAG_imported_unit:
6875 return "DW_TAG_imported_unit";
6876 case DW_TAG_condition:
6877 return "DW_TAG_condition";
6878 case DW_TAG_shared_type:
6879 return "DW_TAG_shared_type";
6880 case DW_TAG_type_unit:
6881 return "DW_TAG_type_unit";
6882 case DW_TAG_rvalue_reference_type:
6883 return "DW_TAG_rvalue_reference_type";
6884 case DW_TAG_template_alias:
6885 return "DW_TAG_template_alias";
6886 case DW_TAG_GNU_template_parameter_pack:
6887 return "DW_TAG_GNU_template_parameter_pack";
6888 case DW_TAG_GNU_formal_parameter_pack:
6889 return "DW_TAG_GNU_formal_parameter_pack";
6890 case DW_TAG_MIPS_loop:
6891 return "DW_TAG_MIPS_loop";
6892 case DW_TAG_format_label:
6893 return "DW_TAG_format_label";
6894 case DW_TAG_function_template:
6895 return "DW_TAG_function_template";
6896 case DW_TAG_class_template:
6897 return "DW_TAG_class_template";
6898 case DW_TAG_GNU_BINCL:
6899 return "DW_TAG_GNU_BINCL";
6900 case DW_TAG_GNU_EINCL:
6901 return "DW_TAG_GNU_EINCL";
6902 case DW_TAG_GNU_template_template_param:
6903 return "DW_TAG_GNU_template_template_param";
6904 case DW_TAG_GNU_call_site:
6905 return "DW_TAG_GNU_call_site";
6906 case DW_TAG_GNU_call_site_parameter:
6907 return "DW_TAG_GNU_call_site_parameter";
6909 return "DW_TAG_<unknown>";
6913 /* Convert a DWARF attribute code into its string name. */
6916 dwarf_attr_name (unsigned int attr)
6921 return "DW_AT_sibling";
6922 case DW_AT_location:
6923 return "DW_AT_location";
6925 return "DW_AT_name";
6926 case DW_AT_ordering:
6927 return "DW_AT_ordering";
6928 case DW_AT_subscr_data:
6929 return "DW_AT_subscr_data";
6930 case DW_AT_byte_size:
6931 return "DW_AT_byte_size";
6932 case DW_AT_bit_offset:
6933 return "DW_AT_bit_offset";
6934 case DW_AT_bit_size:
6935 return "DW_AT_bit_size";
6936 case DW_AT_element_list:
6937 return "DW_AT_element_list";
6938 case DW_AT_stmt_list:
6939 return "DW_AT_stmt_list";
6941 return "DW_AT_low_pc";
6943 return "DW_AT_high_pc";
6944 case DW_AT_language:
6945 return "DW_AT_language";
6947 return "DW_AT_member";
6949 return "DW_AT_discr";
6950 case DW_AT_discr_value:
6951 return "DW_AT_discr_value";
6952 case DW_AT_visibility:
6953 return "DW_AT_visibility";
6955 return "DW_AT_import";
6956 case DW_AT_string_length:
6957 return "DW_AT_string_length";
6958 case DW_AT_common_reference:
6959 return "DW_AT_common_reference";
6960 case DW_AT_comp_dir:
6961 return "DW_AT_comp_dir";
6962 case DW_AT_const_value:
6963 return "DW_AT_const_value";
6964 case DW_AT_containing_type:
6965 return "DW_AT_containing_type";
6966 case DW_AT_default_value:
6967 return "DW_AT_default_value";
6969 return "DW_AT_inline";
6970 case DW_AT_is_optional:
6971 return "DW_AT_is_optional";
6972 case DW_AT_lower_bound:
6973 return "DW_AT_lower_bound";
6974 case DW_AT_producer:
6975 return "DW_AT_producer";
6976 case DW_AT_prototyped:
6977 return "DW_AT_prototyped";
6978 case DW_AT_return_addr:
6979 return "DW_AT_return_addr";
6980 case DW_AT_start_scope:
6981 return "DW_AT_start_scope";
6982 case DW_AT_bit_stride:
6983 return "DW_AT_bit_stride";
6984 case DW_AT_upper_bound:
6985 return "DW_AT_upper_bound";
6986 case DW_AT_abstract_origin:
6987 return "DW_AT_abstract_origin";
6988 case DW_AT_accessibility:
6989 return "DW_AT_accessibility";
6990 case DW_AT_address_class:
6991 return "DW_AT_address_class";
6992 case DW_AT_artificial:
6993 return "DW_AT_artificial";
6994 case DW_AT_base_types:
6995 return "DW_AT_base_types";
6996 case DW_AT_calling_convention:
6997 return "DW_AT_calling_convention";
6999 return "DW_AT_count";
7000 case DW_AT_data_member_location:
7001 return "DW_AT_data_member_location";
7002 case DW_AT_decl_column:
7003 return "DW_AT_decl_column";
7004 case DW_AT_decl_file:
7005 return "DW_AT_decl_file";
7006 case DW_AT_decl_line:
7007 return "DW_AT_decl_line";
7008 case DW_AT_declaration:
7009 return "DW_AT_declaration";
7010 case DW_AT_discr_list:
7011 return "DW_AT_discr_list";
7012 case DW_AT_encoding:
7013 return "DW_AT_encoding";
7014 case DW_AT_external:
7015 return "DW_AT_external";
7016 case DW_AT_explicit:
7017 return "DW_AT_explicit";
7018 case DW_AT_frame_base:
7019 return "DW_AT_frame_base";
7021 return "DW_AT_friend";
7022 case DW_AT_identifier_case:
7023 return "DW_AT_identifier_case";
7024 case DW_AT_macro_info:
7025 return "DW_AT_macro_info";
7026 case DW_AT_namelist_items:
7027 return "DW_AT_namelist_items";
7028 case DW_AT_priority:
7029 return "DW_AT_priority";
7031 return "DW_AT_segment";
7032 case DW_AT_specification:
7033 return "DW_AT_specification";
7034 case DW_AT_static_link:
7035 return "DW_AT_static_link";
7037 return "DW_AT_type";
7038 case DW_AT_use_location:
7039 return "DW_AT_use_location";
7040 case DW_AT_variable_parameter:
7041 return "DW_AT_variable_parameter";
7042 case DW_AT_virtuality:
7043 return "DW_AT_virtuality";
7044 case DW_AT_vtable_elem_location:
7045 return "DW_AT_vtable_elem_location";
7047 case DW_AT_allocated:
7048 return "DW_AT_allocated";
7049 case DW_AT_associated:
7050 return "DW_AT_associated";
7051 case DW_AT_data_location:
7052 return "DW_AT_data_location";
7053 case DW_AT_byte_stride:
7054 return "DW_AT_byte_stride";
7055 case DW_AT_entry_pc:
7056 return "DW_AT_entry_pc";
7057 case DW_AT_use_UTF8:
7058 return "DW_AT_use_UTF8";
7059 case DW_AT_extension:
7060 return "DW_AT_extension";
7062 return "DW_AT_ranges";
7063 case DW_AT_trampoline:
7064 return "DW_AT_trampoline";
7065 case DW_AT_call_column:
7066 return "DW_AT_call_column";
7067 case DW_AT_call_file:
7068 return "DW_AT_call_file";
7069 case DW_AT_call_line:
7070 return "DW_AT_call_line";
7071 case DW_AT_object_pointer:
7072 return "DW_AT_object_pointer";
7074 case DW_AT_signature:
7075 return "DW_AT_signature";
7076 case DW_AT_main_subprogram:
7077 return "DW_AT_main_subprogram";
7078 case DW_AT_data_bit_offset:
7079 return "DW_AT_data_bit_offset";
7080 case DW_AT_const_expr:
7081 return "DW_AT_const_expr";
7082 case DW_AT_enum_class:
7083 return "DW_AT_enum_class";
7084 case DW_AT_linkage_name:
7085 return "DW_AT_linkage_name";
7087 case DW_AT_MIPS_fde:
7088 return "DW_AT_MIPS_fde";
7089 case DW_AT_MIPS_loop_begin:
7090 return "DW_AT_MIPS_loop_begin";
7091 case DW_AT_MIPS_tail_loop_begin:
7092 return "DW_AT_MIPS_tail_loop_begin";
7093 case DW_AT_MIPS_epilog_begin:
7094 return "DW_AT_MIPS_epilog_begin";
7095 #if VMS_DEBUGGING_INFO
7096 case DW_AT_HP_prologue:
7097 return "DW_AT_HP_prologue";
7099 case DW_AT_MIPS_loop_unroll_factor:
7100 return "DW_AT_MIPS_loop_unroll_factor";
7102 case DW_AT_MIPS_software_pipeline_depth:
7103 return "DW_AT_MIPS_software_pipeline_depth";
7104 case DW_AT_MIPS_linkage_name:
7105 return "DW_AT_MIPS_linkage_name";
7106 #if VMS_DEBUGGING_INFO
7107 case DW_AT_HP_epilogue:
7108 return "DW_AT_HP_epilogue";
7110 case DW_AT_MIPS_stride:
7111 return "DW_AT_MIPS_stride";
7113 case DW_AT_MIPS_abstract_name:
7114 return "DW_AT_MIPS_abstract_name";
7115 case DW_AT_MIPS_clone_origin:
7116 return "DW_AT_MIPS_clone_origin";
7117 case DW_AT_MIPS_has_inlines:
7118 return "DW_AT_MIPS_has_inlines";
7120 case DW_AT_sf_names:
7121 return "DW_AT_sf_names";
7122 case DW_AT_src_info:
7123 return "DW_AT_src_info";
7124 case DW_AT_mac_info:
7125 return "DW_AT_mac_info";
7126 case DW_AT_src_coords:
7127 return "DW_AT_src_coords";
7128 case DW_AT_body_begin:
7129 return "DW_AT_body_begin";
7130 case DW_AT_body_end:
7131 return "DW_AT_body_end";
7132 case DW_AT_GNU_vector:
7133 return "DW_AT_GNU_vector";
7134 case DW_AT_GNU_guarded_by:
7135 return "DW_AT_GNU_guarded_by";
7136 case DW_AT_GNU_pt_guarded_by:
7137 return "DW_AT_GNU_pt_guarded_by";
7138 case DW_AT_GNU_guarded:
7139 return "DW_AT_GNU_guarded";
7140 case DW_AT_GNU_pt_guarded:
7141 return "DW_AT_GNU_pt_guarded";
7142 case DW_AT_GNU_locks_excluded:
7143 return "DW_AT_GNU_locks_excluded";
7144 case DW_AT_GNU_exclusive_locks_required:
7145 return "DW_AT_GNU_exclusive_locks_required";
7146 case DW_AT_GNU_shared_locks_required:
7147 return "DW_AT_GNU_shared_locks_required";
7148 case DW_AT_GNU_odr_signature:
7149 return "DW_AT_GNU_odr_signature";
7150 case DW_AT_GNU_template_name:
7151 return "DW_AT_GNU_template_name";
7152 case DW_AT_GNU_call_site_value:
7153 return "DW_AT_GNU_call_site_value";
7154 case DW_AT_GNU_call_site_data_value:
7155 return "DW_AT_GNU_call_site_data_value";
7156 case DW_AT_GNU_call_site_target:
7157 return "DW_AT_GNU_call_site_target";
7158 case DW_AT_GNU_call_site_target_clobbered:
7159 return "DW_AT_GNU_call_site_target_clobbered";
7160 case DW_AT_GNU_tail_call:
7161 return "DW_AT_GNU_tail_call";
7162 case DW_AT_GNU_all_tail_call_sites:
7163 return "DW_AT_GNU_all_tail_call_sites";
7164 case DW_AT_GNU_all_call_sites:
7165 return "DW_AT_GNU_all_call_sites";
7166 case DW_AT_GNU_all_source_call_sites:
7167 return "DW_AT_GNU_all_source_call_sites";
7169 case DW_AT_VMS_rtnbeg_pd_address:
7170 return "DW_AT_VMS_rtnbeg_pd_address";
7173 return "DW_AT_<unknown>";
7177 /* Convert a DWARF value form code into its string name. */
7180 dwarf_form_name (unsigned int form)
7185 return "DW_FORM_addr";
7186 case DW_FORM_block2:
7187 return "DW_FORM_block2";
7188 case DW_FORM_block4:
7189 return "DW_FORM_block4";
7191 return "DW_FORM_data2";
7193 return "DW_FORM_data4";
7195 return "DW_FORM_data8";
7196 case DW_FORM_string:
7197 return "DW_FORM_string";
7199 return "DW_FORM_block";
7200 case DW_FORM_block1:
7201 return "DW_FORM_block1";
7203 return "DW_FORM_data1";
7205 return "DW_FORM_flag";
7207 return "DW_FORM_sdata";
7209 return "DW_FORM_strp";
7211 return "DW_FORM_udata";
7212 case DW_FORM_ref_addr:
7213 return "DW_FORM_ref_addr";
7215 return "DW_FORM_ref1";
7217 return "DW_FORM_ref2";
7219 return "DW_FORM_ref4";
7221 return "DW_FORM_ref8";
7222 case DW_FORM_ref_udata:
7223 return "DW_FORM_ref_udata";
7224 case DW_FORM_indirect:
7225 return "DW_FORM_indirect";
7226 case DW_FORM_sec_offset:
7227 return "DW_FORM_sec_offset";
7228 case DW_FORM_exprloc:
7229 return "DW_FORM_exprloc";
7230 case DW_FORM_flag_present:
7231 return "DW_FORM_flag_present";
7232 case DW_FORM_ref_sig8:
7233 return "DW_FORM_ref_sig8";
7235 return "DW_FORM_<unknown>";
7239 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7240 instance of an inlined instance of a decl which is local to an inline
7241 function, so we have to trace all of the way back through the origin chain
7242 to find out what sort of node actually served as the original seed for the
7246 decl_ultimate_origin (const_tree decl)
7248 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7251 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7252 nodes in the function to point to themselves; ignore that if
7253 we're trying to output the abstract instance of this function. */
7254 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7257 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7258 most distant ancestor, this should never happen. */
7259 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7261 return DECL_ABSTRACT_ORIGIN (decl);
7264 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7265 of a virtual function may refer to a base class, so we check the 'this'
7269 decl_class_context (tree decl)
7271 tree context = NULL_TREE;
7273 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7274 context = DECL_CONTEXT (decl);
7276 context = TYPE_MAIN_VARIANT
7277 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7279 if (context && !TYPE_P (context))
7280 context = NULL_TREE;
7285 /* Add an attribute/value pair to a DIE. */
7288 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7290 /* Maybe this should be an assert? */
7294 if (die->die_attr == NULL)
7295 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7296 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7299 static inline enum dw_val_class
7300 AT_class (dw_attr_ref a)
7302 return a->dw_attr_val.val_class;
7305 /* Add a flag value attribute to a DIE. */
7308 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7312 attr.dw_attr = attr_kind;
7313 attr.dw_attr_val.val_class = dw_val_class_flag;
7314 attr.dw_attr_val.v.val_flag = flag;
7315 add_dwarf_attr (die, &attr);
7318 static inline unsigned
7319 AT_flag (dw_attr_ref a)
7321 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7322 return a->dw_attr_val.v.val_flag;
7325 /* Add a signed integer attribute value to a DIE. */
7328 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7332 attr.dw_attr = attr_kind;
7333 attr.dw_attr_val.val_class = dw_val_class_const;
7334 attr.dw_attr_val.v.val_int = int_val;
7335 add_dwarf_attr (die, &attr);
7338 static inline HOST_WIDE_INT
7339 AT_int (dw_attr_ref a)
7341 gcc_assert (a && AT_class (a) == dw_val_class_const);
7342 return a->dw_attr_val.v.val_int;
7345 /* Add an unsigned integer attribute value to a DIE. */
7348 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7349 unsigned HOST_WIDE_INT unsigned_val)
7353 attr.dw_attr = attr_kind;
7354 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7355 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7356 add_dwarf_attr (die, &attr);
7359 static inline unsigned HOST_WIDE_INT
7360 AT_unsigned (dw_attr_ref a)
7362 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7363 return a->dw_attr_val.v.val_unsigned;
7366 /* Add an unsigned double integer attribute value to a DIE. */
7369 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7370 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7374 attr.dw_attr = attr_kind;
7375 attr.dw_attr_val.val_class = dw_val_class_const_double;
7376 attr.dw_attr_val.v.val_double.high = high;
7377 attr.dw_attr_val.v.val_double.low = low;
7378 add_dwarf_attr (die, &attr);
7381 /* Add a floating point attribute value to a DIE and return it. */
7384 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7385 unsigned int length, unsigned int elt_size, unsigned char *array)
7389 attr.dw_attr = attr_kind;
7390 attr.dw_attr_val.val_class = dw_val_class_vec;
7391 attr.dw_attr_val.v.val_vec.length = length;
7392 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7393 attr.dw_attr_val.v.val_vec.array = array;
7394 add_dwarf_attr (die, &attr);
7397 /* Add an 8-byte data attribute value to a DIE. */
7400 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7401 unsigned char data8[8])
7405 attr.dw_attr = attr_kind;
7406 attr.dw_attr_val.val_class = dw_val_class_data8;
7407 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7408 add_dwarf_attr (die, &attr);
7411 /* Hash and equality functions for debug_str_hash. */
7414 debug_str_do_hash (const void *x)
7416 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7420 debug_str_eq (const void *x1, const void *x2)
7422 return strcmp ((((const struct indirect_string_node *)x1)->str),
7423 (const char *)x2) == 0;
7426 /* Add STR to the indirect string hash table. */
7428 static struct indirect_string_node *
7429 find_AT_string (const char *str)
7431 struct indirect_string_node *node;
7434 if (! debug_str_hash)
7435 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7436 debug_str_eq, NULL);
7438 slot = htab_find_slot_with_hash (debug_str_hash, str,
7439 htab_hash_string (str), INSERT);
7442 node = ggc_alloc_cleared_indirect_string_node ();
7443 node->str = ggc_strdup (str);
7447 node = (struct indirect_string_node *) *slot;
7453 /* Add a string attribute value to a DIE. */
7456 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7459 struct indirect_string_node *node;
7461 node = find_AT_string (str);
7463 attr.dw_attr = attr_kind;
7464 attr.dw_attr_val.val_class = dw_val_class_str;
7465 attr.dw_attr_val.v.val_str = node;
7466 add_dwarf_attr (die, &attr);
7469 /* Create a label for an indirect string node, ensuring it is going to
7470 be output, unless its reference count goes down to zero. */
7473 gen_label_for_indirect_string (struct indirect_string_node *node)
7480 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7481 ++dw2_string_counter;
7482 node->label = xstrdup (label);
7485 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7486 debug string STR. */
7489 get_debug_string_label (const char *str)
7491 struct indirect_string_node *node = find_AT_string (str);
7493 debug_str_hash_forced = true;
7495 gen_label_for_indirect_string (node);
7497 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7500 static inline const char *
7501 AT_string (dw_attr_ref a)
7503 gcc_assert (a && AT_class (a) == dw_val_class_str);
7504 return a->dw_attr_val.v.val_str->str;
7507 /* Find out whether a string should be output inline in DIE
7508 or out-of-line in .debug_str section. */
7510 static enum dwarf_form
7511 AT_string_form (dw_attr_ref a)
7513 struct indirect_string_node *node;
7516 gcc_assert (a && AT_class (a) == dw_val_class_str);
7518 node = a->dw_attr_val.v.val_str;
7522 len = strlen (node->str) + 1;
7524 /* If the string is shorter or equal to the size of the reference, it is
7525 always better to put it inline. */
7526 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7527 return node->form = DW_FORM_string;
7529 /* If we cannot expect the linker to merge strings in .debug_str
7530 section, only put it into .debug_str if it is worth even in this
7532 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7533 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7534 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7535 return node->form = DW_FORM_string;
7537 gen_label_for_indirect_string (node);
7539 return node->form = DW_FORM_strp;
7542 /* Add a DIE reference attribute value to a DIE. */
7545 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7549 #ifdef ENABLE_CHECKING
7550 gcc_assert (targ_die != NULL);
7552 /* With LTO we can end up trying to reference something we didn't create
7553 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7554 if (targ_die == NULL)
7558 attr.dw_attr = attr_kind;
7559 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7560 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7561 attr.dw_attr_val.v.val_die_ref.external = 0;
7562 add_dwarf_attr (die, &attr);
7565 /* Add an AT_specification attribute to a DIE, and also make the back
7566 pointer from the specification to the definition. */
7569 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7571 add_AT_die_ref (die, DW_AT_specification, targ_die);
7572 gcc_assert (!targ_die->die_definition);
7573 targ_die->die_definition = die;
7576 static inline dw_die_ref
7577 AT_ref (dw_attr_ref a)
7579 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7580 return a->dw_attr_val.v.val_die_ref.die;
7584 AT_ref_external (dw_attr_ref a)
7586 if (a && AT_class (a) == dw_val_class_die_ref)
7587 return a->dw_attr_val.v.val_die_ref.external;
7593 set_AT_ref_external (dw_attr_ref a, int i)
7595 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7596 a->dw_attr_val.v.val_die_ref.external = i;
7599 /* Add an FDE reference attribute value to a DIE. */
7602 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7606 attr.dw_attr = attr_kind;
7607 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7608 attr.dw_attr_val.v.val_fde_index = targ_fde;
7609 add_dwarf_attr (die, &attr);
7612 /* Add a location description attribute value to a DIE. */
7615 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7619 attr.dw_attr = attr_kind;
7620 attr.dw_attr_val.val_class = dw_val_class_loc;
7621 attr.dw_attr_val.v.val_loc = loc;
7622 add_dwarf_attr (die, &attr);
7625 static inline dw_loc_descr_ref
7626 AT_loc (dw_attr_ref a)
7628 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7629 return a->dw_attr_val.v.val_loc;
7633 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7637 attr.dw_attr = attr_kind;
7638 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7639 attr.dw_attr_val.v.val_loc_list = loc_list;
7640 add_dwarf_attr (die, &attr);
7641 have_location_lists = true;
7644 static inline dw_loc_list_ref
7645 AT_loc_list (dw_attr_ref a)
7647 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7648 return a->dw_attr_val.v.val_loc_list;
7651 static inline dw_loc_list_ref *
7652 AT_loc_list_ptr (dw_attr_ref a)
7654 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7655 return &a->dw_attr_val.v.val_loc_list;
7658 /* Add an address constant attribute value to a DIE. */
7661 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7665 attr.dw_attr = attr_kind;
7666 attr.dw_attr_val.val_class = dw_val_class_addr;
7667 attr.dw_attr_val.v.val_addr = addr;
7668 add_dwarf_attr (die, &attr);
7671 /* Get the RTX from to an address DIE attribute. */
7674 AT_addr (dw_attr_ref a)
7676 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7677 return a->dw_attr_val.v.val_addr;
7680 /* Add a file attribute value to a DIE. */
7683 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7684 struct dwarf_file_data *fd)
7688 attr.dw_attr = attr_kind;
7689 attr.dw_attr_val.val_class = dw_val_class_file;
7690 attr.dw_attr_val.v.val_file = fd;
7691 add_dwarf_attr (die, &attr);
7694 /* Get the dwarf_file_data from a file DIE attribute. */
7696 static inline struct dwarf_file_data *
7697 AT_file (dw_attr_ref a)
7699 gcc_assert (a && AT_class (a) == dw_val_class_file);
7700 return a->dw_attr_val.v.val_file;
7703 /* Add a vms delta attribute value to a DIE. */
7706 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7707 const char *lbl1, const char *lbl2)
7711 attr.dw_attr = attr_kind;
7712 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7713 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7714 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7715 add_dwarf_attr (die, &attr);
7718 /* Add a label identifier attribute value to a DIE. */
7721 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7725 attr.dw_attr = attr_kind;
7726 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7727 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7728 add_dwarf_attr (die, &attr);
7731 /* Add a section offset attribute value to a DIE, an offset into the
7732 debug_line section. */
7735 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7740 attr.dw_attr = attr_kind;
7741 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7742 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7743 add_dwarf_attr (die, &attr);
7746 /* Add a section offset attribute value to a DIE, an offset into the
7747 debug_macinfo section. */
7750 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7755 attr.dw_attr = attr_kind;
7756 attr.dw_attr_val.val_class = dw_val_class_macptr;
7757 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7758 add_dwarf_attr (die, &attr);
7761 /* Add an offset attribute value to a DIE. */
7764 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7765 unsigned HOST_WIDE_INT offset)
7769 attr.dw_attr = attr_kind;
7770 attr.dw_attr_val.val_class = dw_val_class_offset;
7771 attr.dw_attr_val.v.val_offset = offset;
7772 add_dwarf_attr (die, &attr);
7775 /* Add an range_list attribute value to a DIE. */
7778 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7779 long unsigned int offset)
7783 attr.dw_attr = attr_kind;
7784 attr.dw_attr_val.val_class = dw_val_class_range_list;
7785 attr.dw_attr_val.v.val_offset = offset;
7786 add_dwarf_attr (die, &attr);
7789 /* Return the start label of a delta attribute. */
7791 static inline const char *
7792 AT_vms_delta1 (dw_attr_ref a)
7794 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7795 return a->dw_attr_val.v.val_vms_delta.lbl1;
7798 /* Return the end label of a delta attribute. */
7800 static inline const char *
7801 AT_vms_delta2 (dw_attr_ref a)
7803 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7804 return a->dw_attr_val.v.val_vms_delta.lbl2;
7807 static inline const char *
7808 AT_lbl (dw_attr_ref a)
7810 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7811 || AT_class (a) == dw_val_class_lineptr
7812 || AT_class (a) == dw_val_class_macptr));
7813 return a->dw_attr_val.v.val_lbl_id;
7816 /* Get the attribute of type attr_kind. */
7819 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7823 dw_die_ref spec = NULL;
7828 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7829 if (a->dw_attr == attr_kind)
7831 else if (a->dw_attr == DW_AT_specification
7832 || a->dw_attr == DW_AT_abstract_origin)
7836 return get_AT (spec, attr_kind);
7841 /* Return the "low pc" attribute value, typically associated with a subprogram
7842 DIE. Return null if the "low pc" attribute is either not present, or if it
7843 cannot be represented as an assembler label identifier. */
7845 static inline const char *
7846 get_AT_low_pc (dw_die_ref die)
7848 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7850 return a ? AT_lbl (a) : NULL;
7853 /* Return the "high pc" attribute value, typically associated with a subprogram
7854 DIE. Return null if the "high pc" attribute is either not present, or if it
7855 cannot be represented as an assembler label identifier. */
7857 static inline const char *
7858 get_AT_hi_pc (dw_die_ref die)
7860 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7862 return a ? AT_lbl (a) : NULL;
7865 /* Return the value of the string attribute designated by ATTR_KIND, or
7866 NULL if it is not present. */
7868 static inline const char *
7869 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7871 dw_attr_ref a = get_AT (die, attr_kind);
7873 return a ? AT_string (a) : NULL;
7876 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7877 if it is not present. */
7880 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7882 dw_attr_ref a = get_AT (die, attr_kind);
7884 return a ? AT_flag (a) : 0;
7887 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7888 if it is not present. */
7890 static inline unsigned
7891 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7893 dw_attr_ref a = get_AT (die, attr_kind);
7895 return a ? AT_unsigned (a) : 0;
7898 static inline dw_die_ref
7899 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7901 dw_attr_ref a = get_AT (die, attr_kind);
7903 return a ? AT_ref (a) : NULL;
7906 static inline struct dwarf_file_data *
7907 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7909 dw_attr_ref a = get_AT (die, attr_kind);
7911 return a ? AT_file (a) : NULL;
7914 /* Return TRUE if the language is C++. */
7919 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7921 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7924 /* Return TRUE if the language is Fortran. */
7929 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7931 return (lang == DW_LANG_Fortran77
7932 || lang == DW_LANG_Fortran90
7933 || lang == DW_LANG_Fortran95);
7936 /* Return TRUE if the language is Ada. */
7941 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7943 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7946 /* Remove the specified attribute if present. */
7949 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7957 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7958 if (a->dw_attr == attr_kind)
7960 if (AT_class (a) == dw_val_class_str)
7961 if (a->dw_attr_val.v.val_str->refcount)
7962 a->dw_attr_val.v.val_str->refcount--;
7964 /* VEC_ordered_remove should help reduce the number of abbrevs
7966 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7971 /* Remove CHILD from its parent. PREV must have the property that
7972 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7975 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7977 gcc_assert (child->die_parent == prev->die_parent);
7978 gcc_assert (prev->die_sib == child);
7981 gcc_assert (child->die_parent->die_child == child);
7985 prev->die_sib = child->die_sib;
7986 if (child->die_parent->die_child == child)
7987 child->die_parent->die_child = prev;
7990 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7991 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7994 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
7996 dw_die_ref parent = old_child->die_parent;
7998 gcc_assert (parent == prev->die_parent);
7999 gcc_assert (prev->die_sib == old_child);
8001 new_child->die_parent = parent;
8002 if (prev == old_child)
8004 gcc_assert (parent->die_child == old_child);
8005 new_child->die_sib = new_child;
8009 prev->die_sib = new_child;
8010 new_child->die_sib = old_child->die_sib;
8012 if (old_child->die_parent->die_child == old_child)
8013 old_child->die_parent->die_child = new_child;
8016 /* Move all children from OLD_PARENT to NEW_PARENT. */
8019 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
8022 new_parent->die_child = old_parent->die_child;
8023 old_parent->die_child = NULL;
8024 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
8027 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8031 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8037 dw_die_ref prev = c;
8039 while (c->die_tag == tag)
8041 remove_child_with_prev (c, prev);
8042 /* Might have removed every child. */
8043 if (c == c->die_sib)
8047 } while (c != die->die_child);
8050 /* Add a CHILD_DIE as the last child of DIE. */
8053 add_child_die (dw_die_ref die, dw_die_ref child_die)
8055 /* FIXME this should probably be an assert. */
8056 if (! die || ! child_die)
8058 gcc_assert (die != child_die);
8060 child_die->die_parent = die;
8063 child_die->die_sib = die->die_child->die_sib;
8064 die->die_child->die_sib = child_die;
8067 child_die->die_sib = child_die;
8068 die->die_child = child_die;
8071 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8072 is the specification, to the end of PARENT's list of children.
8073 This is done by removing and re-adding it. */
8076 splice_child_die (dw_die_ref parent, dw_die_ref child)
8080 /* We want the declaration DIE from inside the class, not the
8081 specification DIE at toplevel. */
8082 if (child->die_parent != parent)
8084 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8090 gcc_assert (child->die_parent == parent
8091 || (child->die_parent
8092 == get_AT_ref (parent, DW_AT_specification)));
8094 for (p = child->die_parent->die_child; ; p = p->die_sib)
8095 if (p->die_sib == child)
8097 remove_child_with_prev (child, p);
8101 add_child_die (parent, child);
8104 /* Return a pointer to a newly created DIE node. */
8106 static inline dw_die_ref
8107 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8109 dw_die_ref die = ggc_alloc_cleared_die_node ();
8111 die->die_tag = tag_value;
8113 if (parent_die != NULL)
8114 add_child_die (parent_die, die);
8117 limbo_die_node *limbo_node;
8119 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8120 limbo_node->die = die;
8121 limbo_node->created_for = t;
8122 limbo_node->next = limbo_die_list;
8123 limbo_die_list = limbo_node;
8129 /* Return the DIE associated with the given type specifier. */
8131 static inline dw_die_ref
8132 lookup_type_die (tree type)
8134 return TYPE_SYMTAB_DIE (type);
8137 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8138 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8139 anonymous type instead the one of the naming typedef. */
8141 static inline dw_die_ref
8142 strip_naming_typedef (tree type, dw_die_ref type_die)
8145 && TREE_CODE (type) == RECORD_TYPE
8147 && type_die->die_tag == DW_TAG_typedef
8148 && is_naming_typedef_decl (TYPE_NAME (type)))
8149 type_die = get_AT_ref (type_die, DW_AT_type);
8153 /* Like lookup_type_die, but if type is an anonymous type named by a
8154 typedef[1], return the DIE of the anonymous type instead the one of
8155 the naming typedef. This is because in gen_typedef_die, we did
8156 equate the anonymous struct named by the typedef with the DIE of
8157 the naming typedef. So by default, lookup_type_die on an anonymous
8158 struct yields the DIE of the naming typedef.
8160 [1]: Read the comment of is_naming_typedef_decl to learn about what
8161 a naming typedef is. */
8163 static inline dw_die_ref
8164 lookup_type_die_strip_naming_typedef (tree type)
8166 dw_die_ref die = lookup_type_die (type);
8167 return strip_naming_typedef (type, die);
8170 /* Equate a DIE to a given type specifier. */
8173 equate_type_number_to_die (tree type, dw_die_ref type_die)
8175 TYPE_SYMTAB_DIE (type) = type_die;
8178 /* Returns a hash value for X (which really is a die_struct). */
8181 decl_die_table_hash (const void *x)
8183 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8186 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8189 decl_die_table_eq (const void *x, const void *y)
8191 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8194 /* Return the DIE associated with a given declaration. */
8196 static inline dw_die_ref
8197 lookup_decl_die (tree decl)
8199 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8202 /* Returns a hash value for X (which really is a var_loc_list). */
8205 decl_loc_table_hash (const void *x)
8207 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8210 /* Return nonzero if decl_id of var_loc_list X is the same as
8214 decl_loc_table_eq (const void *x, const void *y)
8216 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8219 /* Return the var_loc list associated with a given declaration. */
8221 static inline var_loc_list *
8222 lookup_decl_loc (const_tree decl)
8224 if (!decl_loc_table)
8226 return (var_loc_list *)
8227 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8230 /* Equate a DIE to a particular declaration. */
8233 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8235 unsigned int decl_id = DECL_UID (decl);
8238 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8240 decl_die->decl_id = decl_id;
8243 /* Return how many bits covers PIECE EXPR_LIST. */
8246 decl_piece_bitsize (rtx piece)
8248 int ret = (int) GET_MODE (piece);
8251 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8252 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8253 return INTVAL (XEXP (XEXP (piece, 0), 0));
8256 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8259 decl_piece_varloc_ptr (rtx piece)
8261 if ((int) GET_MODE (piece))
8262 return &XEXP (piece, 0);
8264 return &XEXP (XEXP (piece, 0), 1);
8267 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8268 Next is the chain of following piece nodes. */
8271 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8273 if (bitsize <= (int) MAX_MACHINE_MODE)
8274 return alloc_EXPR_LIST (bitsize, loc_note, next);
8276 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8281 /* Return rtx that should be stored into loc field for
8282 LOC_NOTE and BITPOS/BITSIZE. */
8285 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8286 HOST_WIDE_INT bitsize)
8290 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8292 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8297 /* This function either modifies location piece list *DEST in
8298 place (if SRC and INNER is NULL), or copies location piece list
8299 *SRC to *DEST while modifying it. Location BITPOS is modified
8300 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8301 not copied and if needed some padding around it is added.
8302 When modifying in place, DEST should point to EXPR_LIST where
8303 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8304 to the start of the whole list and INNER points to the EXPR_LIST
8305 where earlier pieces cover PIECE_BITPOS bits. */
8308 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8309 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8310 HOST_WIDE_INT bitsize, rtx loc_note)
8313 bool copy = inner != NULL;
8317 /* First copy all nodes preceeding the current bitpos. */
8318 while (src != inner)
8320 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8321 decl_piece_bitsize (*src), NULL_RTX);
8322 dest = &XEXP (*dest, 1);
8323 src = &XEXP (*src, 1);
8326 /* Add padding if needed. */
8327 if (bitpos != piece_bitpos)
8329 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8330 copy ? NULL_RTX : *dest);
8331 dest = &XEXP (*dest, 1);
8333 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8336 /* A piece with correct bitpos and bitsize already exist,
8337 just update the location for it and return. */
8338 *decl_piece_varloc_ptr (*dest) = loc_note;
8341 /* Add the piece that changed. */
8342 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8343 dest = &XEXP (*dest, 1);
8344 /* Skip over pieces that overlap it. */
8345 diff = bitpos - piece_bitpos + bitsize;
8348 while (diff > 0 && *src)
8351 diff -= decl_piece_bitsize (piece);
8353 src = &XEXP (piece, 1);
8356 *src = XEXP (piece, 1);
8357 free_EXPR_LIST_node (piece);
8360 /* Add padding if needed. */
8361 if (diff < 0 && *src)
8365 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8366 dest = &XEXP (*dest, 1);
8370 /* Finally copy all nodes following it. */
8373 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8374 decl_piece_bitsize (*src), NULL_RTX);
8375 dest = &XEXP (*dest, 1);
8376 src = &XEXP (*src, 1);
8380 /* Add a variable location node to the linked list for DECL. */
8382 static struct var_loc_node *
8383 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8385 unsigned int decl_id;
8388 struct var_loc_node *loc = NULL;
8389 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8391 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8393 tree realdecl = DECL_DEBUG_EXPR (decl);
8394 if (realdecl && handled_component_p (realdecl))
8396 HOST_WIDE_INT maxsize;
8399 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8400 if (!DECL_P (innerdecl)
8401 || DECL_IGNORED_P (innerdecl)
8402 || TREE_STATIC (innerdecl)
8404 || bitpos + bitsize > 256
8405 || bitsize != maxsize)
8411 decl_id = DECL_UID (decl);
8412 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8415 temp = ggc_alloc_cleared_var_loc_list ();
8416 temp->decl_id = decl_id;
8420 temp = (var_loc_list *) *slot;
8424 struct var_loc_node *last = temp->last, *unused = NULL;
8425 rtx *piece_loc = NULL, last_loc_note;
8426 int piece_bitpos = 0;
8430 gcc_assert (last->next == NULL);
8432 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8434 piece_loc = &last->loc;
8437 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8438 if (piece_bitpos + cur_bitsize > bitpos)
8440 piece_bitpos += cur_bitsize;
8441 piece_loc = &XEXP (*piece_loc, 1);
8445 /* TEMP->LAST here is either pointer to the last but one or
8446 last element in the chained list, LAST is pointer to the
8448 if (label && strcmp (last->label, label) == 0)
8450 /* For SRA optimized variables if there weren't any real
8451 insns since last note, just modify the last node. */
8452 if (piece_loc != NULL)
8454 adjust_piece_list (piece_loc, NULL, NULL,
8455 bitpos, piece_bitpos, bitsize, loc_note);
8458 /* If the last note doesn't cover any instructions, remove it. */
8459 if (temp->last != last)
8461 temp->last->next = NULL;
8464 gcc_assert (strcmp (last->label, label) != 0);
8468 gcc_assert (temp->first == temp->last);
8469 memset (temp->last, '\0', sizeof (*temp->last));
8470 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8474 if (bitsize == -1 && NOTE_P (last->loc))
8475 last_loc_note = last->loc;
8476 else if (piece_loc != NULL
8477 && *piece_loc != NULL_RTX
8478 && piece_bitpos == bitpos
8479 && decl_piece_bitsize (*piece_loc) == bitsize)
8480 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8482 last_loc_note = NULL_RTX;
8483 /* If the current location is the same as the end of the list,
8484 and either both or neither of the locations is uninitialized,
8485 we have nothing to do. */
8486 if (last_loc_note == NULL_RTX
8487 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8488 NOTE_VAR_LOCATION_LOC (loc_note)))
8489 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8490 != NOTE_VAR_LOCATION_STATUS (loc_note))
8491 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8492 == VAR_INIT_STATUS_UNINITIALIZED)
8493 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8494 == VAR_INIT_STATUS_UNINITIALIZED))))
8496 /* Add LOC to the end of list and update LAST. If the last
8497 element of the list has been removed above, reuse its
8498 memory for the new node, otherwise allocate a new one. */
8502 memset (loc, '\0', sizeof (*loc));
8505 loc = ggc_alloc_cleared_var_loc_node ();
8506 if (bitsize == -1 || piece_loc == NULL)
8507 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8509 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8510 bitpos, piece_bitpos, bitsize, loc_note);
8512 /* Ensure TEMP->LAST will point either to the new last but one
8513 element of the chain, or to the last element in it. */
8514 if (last != temp->last)
8522 loc = ggc_alloc_cleared_var_loc_node ();
8525 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8530 /* Keep track of the number of spaces used to indent the
8531 output of the debugging routines that print the structure of
8532 the DIE internal representation. */
8533 static int print_indent;
8535 /* Indent the line the number of spaces given by print_indent. */
8538 print_spaces (FILE *outfile)
8540 fprintf (outfile, "%*s", print_indent, "");
8543 /* Print a type signature in hex. */
8546 print_signature (FILE *outfile, char *sig)
8550 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8551 fprintf (outfile, "%02x", sig[i] & 0xff);
8554 /* Print the information associated with a given DIE, and its children.
8555 This routine is a debugging aid only. */
8558 print_die (dw_die_ref die, FILE *outfile)
8564 print_spaces (outfile);
8565 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8566 die->die_offset, dwarf_tag_name (die->die_tag),
8568 print_spaces (outfile);
8569 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8570 fprintf (outfile, " offset: %ld", die->die_offset);
8571 fprintf (outfile, " mark: %d\n", die->die_mark);
8573 if (dwarf_version >= 4 && die->die_id.die_type_node)
8575 print_spaces (outfile);
8576 fprintf (outfile, " signature: ");
8577 print_signature (outfile, die->die_id.die_type_node->signature);
8578 fprintf (outfile, "\n");
8581 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8583 print_spaces (outfile);
8584 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8586 switch (AT_class (a))
8588 case dw_val_class_addr:
8589 fprintf (outfile, "address");
8591 case dw_val_class_offset:
8592 fprintf (outfile, "offset");
8594 case dw_val_class_loc:
8595 fprintf (outfile, "location descriptor");
8597 case dw_val_class_loc_list:
8598 fprintf (outfile, "location list -> label:%s",
8599 AT_loc_list (a)->ll_symbol);
8601 case dw_val_class_range_list:
8602 fprintf (outfile, "range list");
8604 case dw_val_class_const:
8605 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8607 case dw_val_class_unsigned_const:
8608 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8610 case dw_val_class_const_double:
8611 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8612 HOST_WIDE_INT_PRINT_UNSIGNED")",
8613 a->dw_attr_val.v.val_double.high,
8614 a->dw_attr_val.v.val_double.low);
8616 case dw_val_class_vec:
8617 fprintf (outfile, "floating-point or vector constant");
8619 case dw_val_class_flag:
8620 fprintf (outfile, "%u", AT_flag (a));
8622 case dw_val_class_die_ref:
8623 if (AT_ref (a) != NULL)
8625 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8627 fprintf (outfile, "die -> signature: ");
8628 print_signature (outfile,
8629 AT_ref (a)->die_id.die_type_node->signature);
8631 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8632 fprintf (outfile, "die -> label: %s",
8633 AT_ref (a)->die_id.die_symbol);
8635 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8636 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8639 fprintf (outfile, "die -> <null>");
8641 case dw_val_class_vms_delta:
8642 fprintf (outfile, "delta: @slotcount(%s-%s)",
8643 AT_vms_delta2 (a), AT_vms_delta1 (a));
8645 case dw_val_class_lbl_id:
8646 case dw_val_class_lineptr:
8647 case dw_val_class_macptr:
8648 fprintf (outfile, "label: %s", AT_lbl (a));
8650 case dw_val_class_str:
8651 if (AT_string (a) != NULL)
8652 fprintf (outfile, "\"%s\"", AT_string (a));
8654 fprintf (outfile, "<null>");
8656 case dw_val_class_file:
8657 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8658 AT_file (a)->emitted_number);
8660 case dw_val_class_data8:
8664 for (i = 0; i < 8; i++)
8665 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8672 fprintf (outfile, "\n");
8675 if (die->die_child != NULL)
8678 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8681 if (print_indent == 0)
8682 fprintf (outfile, "\n");
8685 /* Print the contents of the source code line number correspondence table.
8686 This routine is a debugging aid only. */
8689 print_dwarf_line_table (FILE *outfile)
8692 dw_line_info_ref line_info;
8694 fprintf (outfile, "\n\nDWARF source line information\n");
8695 for (i = 1; i < line_info_table_in_use; i++)
8697 line_info = &line_info_table[i];
8698 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8699 line_info->dw_file_num,
8700 line_info->dw_line_num);
8703 fprintf (outfile, "\n\n");
8706 /* Print the information collected for a given DIE. */
8709 debug_dwarf_die (dw_die_ref die)
8711 print_die (die, stderr);
8714 /* Print all DWARF information collected for the compilation unit.
8715 This routine is a debugging aid only. */
8721 print_die (comp_unit_die (), stderr);
8722 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8723 print_dwarf_line_table (stderr);
8726 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8727 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8728 DIE that marks the start of the DIEs for this include file. */
8731 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8733 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8734 dw_die_ref new_unit = gen_compile_unit_die (filename);
8736 new_unit->die_sib = old_unit;
8740 /* Close an include-file CU and reopen the enclosing one. */
8743 pop_compile_unit (dw_die_ref old_unit)
8745 dw_die_ref new_unit = old_unit->die_sib;
8747 old_unit->die_sib = NULL;
8751 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8752 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8754 /* Calculate the checksum of a location expression. */
8757 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8761 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8763 CHECKSUM (loc->dw_loc_oprnd1);
8764 CHECKSUM (loc->dw_loc_oprnd2);
8767 /* Calculate the checksum of an attribute. */
8770 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8772 dw_loc_descr_ref loc;
8775 CHECKSUM (at->dw_attr);
8777 /* We don't care that this was compiled with a different compiler
8778 snapshot; if the output is the same, that's what matters. */
8779 if (at->dw_attr == DW_AT_producer)
8782 switch (AT_class (at))
8784 case dw_val_class_const:
8785 CHECKSUM (at->dw_attr_val.v.val_int);
8787 case dw_val_class_unsigned_const:
8788 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8790 case dw_val_class_const_double:
8791 CHECKSUM (at->dw_attr_val.v.val_double);
8793 case dw_val_class_vec:
8794 CHECKSUM (at->dw_attr_val.v.val_vec);
8796 case dw_val_class_flag:
8797 CHECKSUM (at->dw_attr_val.v.val_flag);
8799 case dw_val_class_str:
8800 CHECKSUM_STRING (AT_string (at));
8803 case dw_val_class_addr:
8805 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8806 CHECKSUM_STRING (XSTR (r, 0));
8809 case dw_val_class_offset:
8810 CHECKSUM (at->dw_attr_val.v.val_offset);
8813 case dw_val_class_loc:
8814 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8815 loc_checksum (loc, ctx);
8818 case dw_val_class_die_ref:
8819 die_checksum (AT_ref (at), ctx, mark);
8822 case dw_val_class_fde_ref:
8823 case dw_val_class_vms_delta:
8824 case dw_val_class_lbl_id:
8825 case dw_val_class_lineptr:
8826 case dw_val_class_macptr:
8829 case dw_val_class_file:
8830 CHECKSUM_STRING (AT_file (at)->filename);
8833 case dw_val_class_data8:
8834 CHECKSUM (at->dw_attr_val.v.val_data8);
8842 /* Calculate the checksum of a DIE. */
8845 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8851 /* To avoid infinite recursion. */
8854 CHECKSUM (die->die_mark);
8857 die->die_mark = ++(*mark);
8859 CHECKSUM (die->die_tag);
8861 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8862 attr_checksum (a, ctx, mark);
8864 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8868 #undef CHECKSUM_STRING
8870 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8871 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8872 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8873 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8874 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8875 #define CHECKSUM_ATTR(FOO) \
8876 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8878 /* Calculate the checksum of a number in signed LEB128 format. */
8881 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8888 byte = (value & 0x7f);
8890 more = !((value == 0 && (byte & 0x40) == 0)
8891 || (value == -1 && (byte & 0x40) != 0));
8900 /* Calculate the checksum of a number in unsigned LEB128 format. */
8903 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8907 unsigned char byte = (value & 0x7f);
8910 /* More bytes to follow. */
8918 /* Checksum the context of the DIE. This adds the names of any
8919 surrounding namespaces or structures to the checksum. */
8922 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8926 int tag = die->die_tag;
8928 if (tag != DW_TAG_namespace
8929 && tag != DW_TAG_structure_type
8930 && tag != DW_TAG_class_type)
8933 name = get_AT_string (die, DW_AT_name);
8935 spec = get_AT_ref (die, DW_AT_specification);
8939 if (die->die_parent != NULL)
8940 checksum_die_context (die->die_parent, ctx);
8942 CHECKSUM_ULEB128 ('C');
8943 CHECKSUM_ULEB128 (tag);
8945 CHECKSUM_STRING (name);
8948 /* Calculate the checksum of a location expression. */
8951 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8953 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8954 were emitted as a DW_FORM_sdata instead of a location expression. */
8955 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8957 CHECKSUM_ULEB128 (DW_FORM_sdata);
8958 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8962 /* Otherwise, just checksum the raw location expression. */
8965 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8966 CHECKSUM (loc->dw_loc_oprnd1);
8967 CHECKSUM (loc->dw_loc_oprnd2);
8968 loc = loc->dw_loc_next;
8972 /* Calculate the checksum of an attribute. */
8975 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8976 struct md5_ctx *ctx, int *mark)
8978 dw_loc_descr_ref loc;
8981 if (AT_class (at) == dw_val_class_die_ref)
8983 dw_die_ref target_die = AT_ref (at);
8985 /* For pointer and reference types, we checksum only the (qualified)
8986 name of the target type (if there is a name). For friend entries,
8987 we checksum only the (qualified) name of the target type or function.
8988 This allows the checksum to remain the same whether the target type
8989 is complete or not. */
8990 if ((at->dw_attr == DW_AT_type
8991 && (tag == DW_TAG_pointer_type
8992 || tag == DW_TAG_reference_type
8993 || tag == DW_TAG_rvalue_reference_type
8994 || tag == DW_TAG_ptr_to_member_type))
8995 || (at->dw_attr == DW_AT_friend
8996 && tag == DW_TAG_friend))
8998 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
9000 if (name_attr != NULL)
9002 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9006 CHECKSUM_ULEB128 ('N');
9007 CHECKSUM_ULEB128 (at->dw_attr);
9008 if (decl->die_parent != NULL)
9009 checksum_die_context (decl->die_parent, ctx);
9010 CHECKSUM_ULEB128 ('E');
9011 CHECKSUM_STRING (AT_string (name_attr));
9016 /* For all other references to another DIE, we check to see if the
9017 target DIE has already been visited. If it has, we emit a
9018 backward reference; if not, we descend recursively. */
9019 if (target_die->die_mark > 0)
9021 CHECKSUM_ULEB128 ('R');
9022 CHECKSUM_ULEB128 (at->dw_attr);
9023 CHECKSUM_ULEB128 (target_die->die_mark);
9027 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9031 target_die->die_mark = ++(*mark);
9032 CHECKSUM_ULEB128 ('T');
9033 CHECKSUM_ULEB128 (at->dw_attr);
9034 if (decl->die_parent != NULL)
9035 checksum_die_context (decl->die_parent, ctx);
9036 die_checksum_ordered (target_die, ctx, mark);
9041 CHECKSUM_ULEB128 ('A');
9042 CHECKSUM_ULEB128 (at->dw_attr);
9044 switch (AT_class (at))
9046 case dw_val_class_const:
9047 CHECKSUM_ULEB128 (DW_FORM_sdata);
9048 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9051 case dw_val_class_unsigned_const:
9052 CHECKSUM_ULEB128 (DW_FORM_sdata);
9053 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9056 case dw_val_class_const_double:
9057 CHECKSUM_ULEB128 (DW_FORM_block);
9058 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9059 CHECKSUM (at->dw_attr_val.v.val_double);
9062 case dw_val_class_vec:
9063 CHECKSUM_ULEB128 (DW_FORM_block);
9064 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9065 CHECKSUM (at->dw_attr_val.v.val_vec);
9068 case dw_val_class_flag:
9069 CHECKSUM_ULEB128 (DW_FORM_flag);
9070 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9073 case dw_val_class_str:
9074 CHECKSUM_ULEB128 (DW_FORM_string);
9075 CHECKSUM_STRING (AT_string (at));
9078 case dw_val_class_addr:
9080 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9081 CHECKSUM_ULEB128 (DW_FORM_string);
9082 CHECKSUM_STRING (XSTR (r, 0));
9085 case dw_val_class_offset:
9086 CHECKSUM_ULEB128 (DW_FORM_sdata);
9087 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9090 case dw_val_class_loc:
9091 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9092 loc_checksum_ordered (loc, ctx);
9095 case dw_val_class_fde_ref:
9096 case dw_val_class_lbl_id:
9097 case dw_val_class_lineptr:
9098 case dw_val_class_macptr:
9101 case dw_val_class_file:
9102 CHECKSUM_ULEB128 (DW_FORM_string);
9103 CHECKSUM_STRING (AT_file (at)->filename);
9106 case dw_val_class_data8:
9107 CHECKSUM (at->dw_attr_val.v.val_data8);
9115 struct checksum_attributes
9117 dw_attr_ref at_name;
9118 dw_attr_ref at_type;
9119 dw_attr_ref at_friend;
9120 dw_attr_ref at_accessibility;
9121 dw_attr_ref at_address_class;
9122 dw_attr_ref at_allocated;
9123 dw_attr_ref at_artificial;
9124 dw_attr_ref at_associated;
9125 dw_attr_ref at_binary_scale;
9126 dw_attr_ref at_bit_offset;
9127 dw_attr_ref at_bit_size;
9128 dw_attr_ref at_bit_stride;
9129 dw_attr_ref at_byte_size;
9130 dw_attr_ref at_byte_stride;
9131 dw_attr_ref at_const_value;
9132 dw_attr_ref at_containing_type;
9133 dw_attr_ref at_count;
9134 dw_attr_ref at_data_location;
9135 dw_attr_ref at_data_member_location;
9136 dw_attr_ref at_decimal_scale;
9137 dw_attr_ref at_decimal_sign;
9138 dw_attr_ref at_default_value;
9139 dw_attr_ref at_digit_count;
9140 dw_attr_ref at_discr;
9141 dw_attr_ref at_discr_list;
9142 dw_attr_ref at_discr_value;
9143 dw_attr_ref at_encoding;
9144 dw_attr_ref at_endianity;
9145 dw_attr_ref at_explicit;
9146 dw_attr_ref at_is_optional;
9147 dw_attr_ref at_location;
9148 dw_attr_ref at_lower_bound;
9149 dw_attr_ref at_mutable;
9150 dw_attr_ref at_ordering;
9151 dw_attr_ref at_picture_string;
9152 dw_attr_ref at_prototyped;
9153 dw_attr_ref at_small;
9154 dw_attr_ref at_segment;
9155 dw_attr_ref at_string_length;
9156 dw_attr_ref at_threads_scaled;
9157 dw_attr_ref at_upper_bound;
9158 dw_attr_ref at_use_location;
9159 dw_attr_ref at_use_UTF8;
9160 dw_attr_ref at_variable_parameter;
9161 dw_attr_ref at_virtuality;
9162 dw_attr_ref at_visibility;
9163 dw_attr_ref at_vtable_elem_location;
9166 /* Collect the attributes that we will want to use for the checksum. */
9169 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9174 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9185 attrs->at_friend = a;
9187 case DW_AT_accessibility:
9188 attrs->at_accessibility = a;
9190 case DW_AT_address_class:
9191 attrs->at_address_class = a;
9193 case DW_AT_allocated:
9194 attrs->at_allocated = a;
9196 case DW_AT_artificial:
9197 attrs->at_artificial = a;
9199 case DW_AT_associated:
9200 attrs->at_associated = a;
9202 case DW_AT_binary_scale:
9203 attrs->at_binary_scale = a;
9205 case DW_AT_bit_offset:
9206 attrs->at_bit_offset = a;
9208 case DW_AT_bit_size:
9209 attrs->at_bit_size = a;
9211 case DW_AT_bit_stride:
9212 attrs->at_bit_stride = a;
9214 case DW_AT_byte_size:
9215 attrs->at_byte_size = a;
9217 case DW_AT_byte_stride:
9218 attrs->at_byte_stride = a;
9220 case DW_AT_const_value:
9221 attrs->at_const_value = a;
9223 case DW_AT_containing_type:
9224 attrs->at_containing_type = a;
9227 attrs->at_count = a;
9229 case DW_AT_data_location:
9230 attrs->at_data_location = a;
9232 case DW_AT_data_member_location:
9233 attrs->at_data_member_location = a;
9235 case DW_AT_decimal_scale:
9236 attrs->at_decimal_scale = a;
9238 case DW_AT_decimal_sign:
9239 attrs->at_decimal_sign = a;
9241 case DW_AT_default_value:
9242 attrs->at_default_value = a;
9244 case DW_AT_digit_count:
9245 attrs->at_digit_count = a;
9248 attrs->at_discr = a;
9250 case DW_AT_discr_list:
9251 attrs->at_discr_list = a;
9253 case DW_AT_discr_value:
9254 attrs->at_discr_value = a;
9256 case DW_AT_encoding:
9257 attrs->at_encoding = a;
9259 case DW_AT_endianity:
9260 attrs->at_endianity = a;
9262 case DW_AT_explicit:
9263 attrs->at_explicit = a;
9265 case DW_AT_is_optional:
9266 attrs->at_is_optional = a;
9268 case DW_AT_location:
9269 attrs->at_location = a;
9271 case DW_AT_lower_bound:
9272 attrs->at_lower_bound = a;
9275 attrs->at_mutable = a;
9277 case DW_AT_ordering:
9278 attrs->at_ordering = a;
9280 case DW_AT_picture_string:
9281 attrs->at_picture_string = a;
9283 case DW_AT_prototyped:
9284 attrs->at_prototyped = a;
9287 attrs->at_small = a;
9290 attrs->at_segment = a;
9292 case DW_AT_string_length:
9293 attrs->at_string_length = a;
9295 case DW_AT_threads_scaled:
9296 attrs->at_threads_scaled = a;
9298 case DW_AT_upper_bound:
9299 attrs->at_upper_bound = a;
9301 case DW_AT_use_location:
9302 attrs->at_use_location = a;
9304 case DW_AT_use_UTF8:
9305 attrs->at_use_UTF8 = a;
9307 case DW_AT_variable_parameter:
9308 attrs->at_variable_parameter = a;
9310 case DW_AT_virtuality:
9311 attrs->at_virtuality = a;
9313 case DW_AT_visibility:
9314 attrs->at_visibility = a;
9316 case DW_AT_vtable_elem_location:
9317 attrs->at_vtable_elem_location = a;
9325 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9328 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9332 struct checksum_attributes attrs;
9334 CHECKSUM_ULEB128 ('D');
9335 CHECKSUM_ULEB128 (die->die_tag);
9337 memset (&attrs, 0, sizeof (attrs));
9339 decl = get_AT_ref (die, DW_AT_specification);
9341 collect_checksum_attributes (&attrs, decl);
9342 collect_checksum_attributes (&attrs, die);
9344 CHECKSUM_ATTR (attrs.at_name);
9345 CHECKSUM_ATTR (attrs.at_accessibility);
9346 CHECKSUM_ATTR (attrs.at_address_class);
9347 CHECKSUM_ATTR (attrs.at_allocated);
9348 CHECKSUM_ATTR (attrs.at_artificial);
9349 CHECKSUM_ATTR (attrs.at_associated);
9350 CHECKSUM_ATTR (attrs.at_binary_scale);
9351 CHECKSUM_ATTR (attrs.at_bit_offset);
9352 CHECKSUM_ATTR (attrs.at_bit_size);
9353 CHECKSUM_ATTR (attrs.at_bit_stride);
9354 CHECKSUM_ATTR (attrs.at_byte_size);
9355 CHECKSUM_ATTR (attrs.at_byte_stride);
9356 CHECKSUM_ATTR (attrs.at_const_value);
9357 CHECKSUM_ATTR (attrs.at_containing_type);
9358 CHECKSUM_ATTR (attrs.at_count);
9359 CHECKSUM_ATTR (attrs.at_data_location);
9360 CHECKSUM_ATTR (attrs.at_data_member_location);
9361 CHECKSUM_ATTR (attrs.at_decimal_scale);
9362 CHECKSUM_ATTR (attrs.at_decimal_sign);
9363 CHECKSUM_ATTR (attrs.at_default_value);
9364 CHECKSUM_ATTR (attrs.at_digit_count);
9365 CHECKSUM_ATTR (attrs.at_discr);
9366 CHECKSUM_ATTR (attrs.at_discr_list);
9367 CHECKSUM_ATTR (attrs.at_discr_value);
9368 CHECKSUM_ATTR (attrs.at_encoding);
9369 CHECKSUM_ATTR (attrs.at_endianity);
9370 CHECKSUM_ATTR (attrs.at_explicit);
9371 CHECKSUM_ATTR (attrs.at_is_optional);
9372 CHECKSUM_ATTR (attrs.at_location);
9373 CHECKSUM_ATTR (attrs.at_lower_bound);
9374 CHECKSUM_ATTR (attrs.at_mutable);
9375 CHECKSUM_ATTR (attrs.at_ordering);
9376 CHECKSUM_ATTR (attrs.at_picture_string);
9377 CHECKSUM_ATTR (attrs.at_prototyped);
9378 CHECKSUM_ATTR (attrs.at_small);
9379 CHECKSUM_ATTR (attrs.at_segment);
9380 CHECKSUM_ATTR (attrs.at_string_length);
9381 CHECKSUM_ATTR (attrs.at_threads_scaled);
9382 CHECKSUM_ATTR (attrs.at_upper_bound);
9383 CHECKSUM_ATTR (attrs.at_use_location);
9384 CHECKSUM_ATTR (attrs.at_use_UTF8);
9385 CHECKSUM_ATTR (attrs.at_variable_parameter);
9386 CHECKSUM_ATTR (attrs.at_virtuality);
9387 CHECKSUM_ATTR (attrs.at_visibility);
9388 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9389 CHECKSUM_ATTR (attrs.at_type);
9390 CHECKSUM_ATTR (attrs.at_friend);
9392 /* Checksum the child DIEs, except for nested types and member functions. */
9395 dw_attr_ref name_attr;
9398 name_attr = get_AT (c, DW_AT_name);
9399 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9400 && name_attr != NULL)
9402 CHECKSUM_ULEB128 ('S');
9403 CHECKSUM_ULEB128 (c->die_tag);
9404 CHECKSUM_STRING (AT_string (name_attr));
9408 /* Mark this DIE so it gets processed when unmarking. */
9409 if (c->die_mark == 0)
9411 die_checksum_ordered (c, ctx, mark);
9413 } while (c != die->die_child);
9415 CHECKSUM_ULEB128 (0);
9419 #undef CHECKSUM_STRING
9420 #undef CHECKSUM_ATTR
9421 #undef CHECKSUM_LEB128
9422 #undef CHECKSUM_ULEB128
9424 /* Generate the type signature for DIE. This is computed by generating an
9425 MD5 checksum over the DIE's tag, its relevant attributes, and its
9426 children. Attributes that are references to other DIEs are processed
9427 by recursion, using the MARK field to prevent infinite recursion.
9428 If the DIE is nested inside a namespace or another type, we also
9429 need to include that context in the signature. The lower 64 bits
9430 of the resulting MD5 checksum comprise the signature. */
9433 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9437 unsigned char checksum[16];
9441 name = get_AT_string (die, DW_AT_name);
9442 decl = get_AT_ref (die, DW_AT_specification);
9444 /* First, compute a signature for just the type name (and its surrounding
9445 context, if any. This is stored in the type unit DIE for link-time
9446 ODR (one-definition rule) checking. */
9448 if (is_cxx() && name != NULL)
9450 md5_init_ctx (&ctx);
9452 /* Checksum the names of surrounding namespaces and structures. */
9453 if (decl != NULL && decl->die_parent != NULL)
9454 checksum_die_context (decl->die_parent, &ctx);
9456 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9457 md5_process_bytes (name, strlen (name) + 1, &ctx);
9458 md5_finish_ctx (&ctx, checksum);
9460 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9463 /* Next, compute the complete type signature. */
9465 md5_init_ctx (&ctx);
9467 die->die_mark = mark;
9469 /* Checksum the names of surrounding namespaces and structures. */
9470 if (decl != NULL && decl->die_parent != NULL)
9471 checksum_die_context (decl->die_parent, &ctx);
9473 /* Checksum the DIE and its children. */
9474 die_checksum_ordered (die, &ctx, &mark);
9475 unmark_all_dies (die);
9476 md5_finish_ctx (&ctx, checksum);
9478 /* Store the signature in the type node and link the type DIE and the
9479 type node together. */
9480 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9481 DWARF_TYPE_SIGNATURE_SIZE);
9482 die->die_id.die_type_node = type_node;
9483 type_node->type_die = die;
9485 /* If the DIE is a specification, link its declaration to the type node
9488 decl->die_id.die_type_node = type_node;
9491 /* Do the location expressions look same? */
9493 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9495 return loc1->dw_loc_opc == loc2->dw_loc_opc
9496 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9497 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9500 /* Do the values look the same? */
9502 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9504 dw_loc_descr_ref loc1, loc2;
9507 if (v1->val_class != v2->val_class)
9510 switch (v1->val_class)
9512 case dw_val_class_const:
9513 return v1->v.val_int == v2->v.val_int;
9514 case dw_val_class_unsigned_const:
9515 return v1->v.val_unsigned == v2->v.val_unsigned;
9516 case dw_val_class_const_double:
9517 return v1->v.val_double.high == v2->v.val_double.high
9518 && v1->v.val_double.low == v2->v.val_double.low;
9519 case dw_val_class_vec:
9520 if (v1->v.val_vec.length != v2->v.val_vec.length
9521 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9523 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9524 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9527 case dw_val_class_flag:
9528 return v1->v.val_flag == v2->v.val_flag;
9529 case dw_val_class_str:
9530 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9532 case dw_val_class_addr:
9533 r1 = v1->v.val_addr;
9534 r2 = v2->v.val_addr;
9535 if (GET_CODE (r1) != GET_CODE (r2))
9537 return !rtx_equal_p (r1, r2);
9539 case dw_val_class_offset:
9540 return v1->v.val_offset == v2->v.val_offset;
9542 case dw_val_class_loc:
9543 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9545 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9546 if (!same_loc_p (loc1, loc2, mark))
9548 return !loc1 && !loc2;
9550 case dw_val_class_die_ref:
9551 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9553 case dw_val_class_fde_ref:
9554 case dw_val_class_vms_delta:
9555 case dw_val_class_lbl_id:
9556 case dw_val_class_lineptr:
9557 case dw_val_class_macptr:
9560 case dw_val_class_file:
9561 return v1->v.val_file == v2->v.val_file;
9563 case dw_val_class_data8:
9564 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9571 /* Do the attributes look the same? */
9574 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9576 if (at1->dw_attr != at2->dw_attr)
9579 /* We don't care that this was compiled with a different compiler
9580 snapshot; if the output is the same, that's what matters. */
9581 if (at1->dw_attr == DW_AT_producer)
9584 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9587 /* Do the dies look the same? */
9590 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9596 /* To avoid infinite recursion. */
9598 return die1->die_mark == die2->die_mark;
9599 die1->die_mark = die2->die_mark = ++(*mark);
9601 if (die1->die_tag != die2->die_tag)
9604 if (VEC_length (dw_attr_node, die1->die_attr)
9605 != VEC_length (dw_attr_node, die2->die_attr))
9608 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9609 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9612 c1 = die1->die_child;
9613 c2 = die2->die_child;
9622 if (!same_die_p (c1, c2, mark))
9626 if (c1 == die1->die_child)
9628 if (c2 == die2->die_child)
9638 /* Do the dies look the same? Wrapper around same_die_p. */
9641 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9644 int ret = same_die_p (die1, die2, &mark);
9646 unmark_all_dies (die1);
9647 unmark_all_dies (die2);
9652 /* The prefix to attach to symbols on DIEs in the current comdat debug
9654 static char *comdat_symbol_id;
9656 /* The index of the current symbol within the current comdat CU. */
9657 static unsigned int comdat_symbol_number;
9659 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9660 children, and set comdat_symbol_id accordingly. */
9663 compute_section_prefix (dw_die_ref unit_die)
9665 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9666 const char *base = die_name ? lbasename (die_name) : "anonymous";
9667 char *name = XALLOCAVEC (char, strlen (base) + 64);
9670 unsigned char checksum[16];
9673 /* Compute the checksum of the DIE, then append part of it as hex digits to
9674 the name filename of the unit. */
9676 md5_init_ctx (&ctx);
9678 die_checksum (unit_die, &ctx, &mark);
9679 unmark_all_dies (unit_die);
9680 md5_finish_ctx (&ctx, checksum);
9682 sprintf (name, "%s.", base);
9683 clean_symbol_name (name);
9685 p = name + strlen (name);
9686 for (i = 0; i < 4; i++)
9688 sprintf (p, "%.2x", checksum[i]);
9692 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9693 comdat_symbol_number = 0;
9696 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9699 is_type_die (dw_die_ref die)
9701 switch (die->die_tag)
9703 case DW_TAG_array_type:
9704 case DW_TAG_class_type:
9705 case DW_TAG_interface_type:
9706 case DW_TAG_enumeration_type:
9707 case DW_TAG_pointer_type:
9708 case DW_TAG_reference_type:
9709 case DW_TAG_rvalue_reference_type:
9710 case DW_TAG_string_type:
9711 case DW_TAG_structure_type:
9712 case DW_TAG_subroutine_type:
9713 case DW_TAG_union_type:
9714 case DW_TAG_ptr_to_member_type:
9715 case DW_TAG_set_type:
9716 case DW_TAG_subrange_type:
9717 case DW_TAG_base_type:
9718 case DW_TAG_const_type:
9719 case DW_TAG_file_type:
9720 case DW_TAG_packed_type:
9721 case DW_TAG_volatile_type:
9722 case DW_TAG_typedef:
9729 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9730 Basically, we want to choose the bits that are likely to be shared between
9731 compilations (types) and leave out the bits that are specific to individual
9732 compilations (functions). */
9735 is_comdat_die (dw_die_ref c)
9737 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9738 we do for stabs. The advantage is a greater likelihood of sharing between
9739 objects that don't include headers in the same order (and therefore would
9740 put the base types in a different comdat). jason 8/28/00 */
9742 if (c->die_tag == DW_TAG_base_type)
9745 if (c->die_tag == DW_TAG_pointer_type
9746 || c->die_tag == DW_TAG_reference_type
9747 || c->die_tag == DW_TAG_rvalue_reference_type
9748 || c->die_tag == DW_TAG_const_type
9749 || c->die_tag == DW_TAG_volatile_type)
9751 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9753 return t ? is_comdat_die (t) : 0;
9756 return is_type_die (c);
9759 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9760 compilation unit. */
9763 is_symbol_die (dw_die_ref c)
9765 return (is_type_die (c)
9766 || is_declaration_die (c)
9767 || c->die_tag == DW_TAG_namespace
9768 || c->die_tag == DW_TAG_module);
9771 /* Returns true iff C is a compile-unit DIE. */
9774 is_cu_die (dw_die_ref c)
9776 return c && c->die_tag == DW_TAG_compile_unit;
9780 gen_internal_sym (const char *prefix)
9784 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9785 return xstrdup (buf);
9788 /* Assign symbols to all worthy DIEs under DIE. */
9791 assign_symbol_names (dw_die_ref die)
9795 if (is_symbol_die (die))
9797 if (comdat_symbol_id)
9799 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9801 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9802 comdat_symbol_id, comdat_symbol_number++);
9803 die->die_id.die_symbol = xstrdup (p);
9806 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9809 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9812 struct cu_hash_table_entry
9815 unsigned min_comdat_num, max_comdat_num;
9816 struct cu_hash_table_entry *next;
9819 /* Routines to manipulate hash table of CUs. */
9821 htab_cu_hash (const void *of)
9823 const struct cu_hash_table_entry *const entry =
9824 (const struct cu_hash_table_entry *) of;
9826 return htab_hash_string (entry->cu->die_id.die_symbol);
9830 htab_cu_eq (const void *of1, const void *of2)
9832 const struct cu_hash_table_entry *const entry1 =
9833 (const struct cu_hash_table_entry *) of1;
9834 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9836 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9840 htab_cu_del (void *what)
9842 struct cu_hash_table_entry *next,
9843 *entry = (struct cu_hash_table_entry *) what;
9853 /* Check whether we have already seen this CU and set up SYM_NUM
9856 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9858 struct cu_hash_table_entry dummy;
9859 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9861 dummy.max_comdat_num = 0;
9863 slot = (struct cu_hash_table_entry **)
9864 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9868 for (; entry; last = entry, entry = entry->next)
9870 if (same_die_p_wrap (cu, entry->cu))
9876 *sym_num = entry->min_comdat_num;
9880 entry = XCNEW (struct cu_hash_table_entry);
9882 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9883 entry->next = *slot;
9889 /* Record SYM_NUM to record of CU in HTABLE. */
9891 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9893 struct cu_hash_table_entry **slot, *entry;
9895 slot = (struct cu_hash_table_entry **)
9896 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9900 entry->max_comdat_num = sym_num;
9903 /* Traverse the DIE (which is always comp_unit_die), and set up
9904 additional compilation units for each of the include files we see
9905 bracketed by BINCL/EINCL. */
9908 break_out_includes (dw_die_ref die)
9911 dw_die_ref unit = NULL;
9912 limbo_die_node *node, **pnode;
9913 htab_t cu_hash_table;
9917 dw_die_ref prev = c;
9919 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9920 || (unit && is_comdat_die (c)))
9922 dw_die_ref next = c->die_sib;
9924 /* This DIE is for a secondary CU; remove it from the main one. */
9925 remove_child_with_prev (c, prev);
9927 if (c->die_tag == DW_TAG_GNU_BINCL)
9928 unit = push_new_compile_unit (unit, c);
9929 else if (c->die_tag == DW_TAG_GNU_EINCL)
9930 unit = pop_compile_unit (unit);
9932 add_child_die (unit, c);
9934 if (c == die->die_child)
9937 } while (c != die->die_child);
9940 /* We can only use this in debugging, since the frontend doesn't check
9941 to make sure that we leave every include file we enter. */
9945 assign_symbol_names (die);
9946 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9947 for (node = limbo_die_list, pnode = &limbo_die_list;
9953 compute_section_prefix (node->die);
9954 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9955 &comdat_symbol_number);
9956 assign_symbol_names (node->die);
9958 *pnode = node->next;
9961 pnode = &node->next;
9962 record_comdat_symbol_number (node->die, cu_hash_table,
9963 comdat_symbol_number);
9966 htab_delete (cu_hash_table);
9969 /* Return non-zero if this DIE is a declaration. */
9972 is_declaration_die (dw_die_ref die)
9977 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9978 if (a->dw_attr == DW_AT_declaration)
9984 /* Return non-zero if this DIE is nested inside a subprogram. */
9987 is_nested_in_subprogram (dw_die_ref die)
9989 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
9993 return local_scope_p (decl);
9996 /* Return non-zero if this is a type DIE that should be moved to a
9997 COMDAT .debug_types section. */
10000 should_move_die_to_comdat (dw_die_ref die)
10002 switch (die->die_tag)
10004 case DW_TAG_class_type:
10005 case DW_TAG_structure_type:
10006 case DW_TAG_enumeration_type:
10007 case DW_TAG_union_type:
10008 /* Don't move declarations, inlined instances, or types nested in a
10010 if (is_declaration_die (die)
10011 || get_AT (die, DW_AT_abstract_origin)
10012 || is_nested_in_subprogram (die))
10015 case DW_TAG_array_type:
10016 case DW_TAG_interface_type:
10017 case DW_TAG_pointer_type:
10018 case DW_TAG_reference_type:
10019 case DW_TAG_rvalue_reference_type:
10020 case DW_TAG_string_type:
10021 case DW_TAG_subroutine_type:
10022 case DW_TAG_ptr_to_member_type:
10023 case DW_TAG_set_type:
10024 case DW_TAG_subrange_type:
10025 case DW_TAG_base_type:
10026 case DW_TAG_const_type:
10027 case DW_TAG_file_type:
10028 case DW_TAG_packed_type:
10029 case DW_TAG_volatile_type:
10030 case DW_TAG_typedef:
10036 /* Make a clone of DIE. */
10039 clone_die (dw_die_ref die)
10045 clone = ggc_alloc_cleared_die_node ();
10046 clone->die_tag = die->die_tag;
10048 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10049 add_dwarf_attr (clone, a);
10054 /* Make a clone of the tree rooted at DIE. */
10057 clone_tree (dw_die_ref die)
10060 dw_die_ref clone = clone_die (die);
10062 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10067 /* Make a clone of DIE as a declaration. */
10070 clone_as_declaration (dw_die_ref die)
10077 /* If the DIE is already a declaration, just clone it. */
10078 if (is_declaration_die (die))
10079 return clone_die (die);
10081 /* If the DIE is a specification, just clone its declaration DIE. */
10082 decl = get_AT_ref (die, DW_AT_specification);
10084 return clone_die (decl);
10086 clone = ggc_alloc_cleared_die_node ();
10087 clone->die_tag = die->die_tag;
10089 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10091 /* We don't want to copy over all attributes.
10092 For example we don't want DW_AT_byte_size because otherwise we will no
10093 longer have a declaration and GDB will treat it as a definition. */
10095 switch (a->dw_attr)
10097 case DW_AT_artificial:
10098 case DW_AT_containing_type:
10099 case DW_AT_external:
10102 case DW_AT_virtuality:
10103 case DW_AT_linkage_name:
10104 case DW_AT_MIPS_linkage_name:
10105 add_dwarf_attr (clone, a);
10107 case DW_AT_byte_size:
10113 if (die->die_id.die_type_node)
10114 add_AT_die_ref (clone, DW_AT_signature, die);
10116 add_AT_flag (clone, DW_AT_declaration, 1);
10120 /* Copy the declaration context to the new compile unit DIE. This includes
10121 any surrounding namespace or type declarations. If the DIE has an
10122 AT_specification attribute, it also includes attributes and children
10123 attached to the specification. */
10126 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10129 dw_die_ref new_decl;
10131 decl = get_AT_ref (die, DW_AT_specification);
10140 /* Copy the type node pointer from the new DIE to the original
10141 declaration DIE so we can forward references later. */
10142 decl->die_id.die_type_node = die->die_id.die_type_node;
10144 remove_AT (die, DW_AT_specification);
10146 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10148 if (a->dw_attr != DW_AT_name
10149 && a->dw_attr != DW_AT_declaration
10150 && a->dw_attr != DW_AT_external)
10151 add_dwarf_attr (die, a);
10154 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10157 if (decl->die_parent != NULL
10158 && decl->die_parent->die_tag != DW_TAG_compile_unit
10159 && decl->die_parent->die_tag != DW_TAG_type_unit)
10161 new_decl = copy_ancestor_tree (unit, decl, NULL);
10162 if (new_decl != NULL)
10164 remove_AT (new_decl, DW_AT_signature);
10165 add_AT_specification (die, new_decl);
10170 /* Generate the skeleton ancestor tree for the given NODE, then clone
10171 the DIE and add the clone into the tree. */
10174 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10176 if (node->new_die != NULL)
10179 node->new_die = clone_as_declaration (node->old_die);
10181 if (node->parent != NULL)
10183 generate_skeleton_ancestor_tree (node->parent);
10184 add_child_die (node->parent->new_die, node->new_die);
10188 /* Generate a skeleton tree of DIEs containing any declarations that are
10189 found in the original tree. We traverse the tree looking for declaration
10190 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10193 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10195 skeleton_chain_node node;
10198 dw_die_ref prev = NULL;
10199 dw_die_ref next = NULL;
10201 node.parent = parent;
10203 first = c = parent->old_die->die_child;
10207 if (prev == NULL || prev->die_sib == c)
10210 next = (c == first ? NULL : c->die_sib);
10212 node.new_die = NULL;
10213 if (is_declaration_die (c))
10215 /* Clone the existing DIE, move the original to the skeleton
10216 tree (which is in the main CU), and put the clone, with
10217 all the original's children, where the original came from. */
10218 dw_die_ref clone = clone_die (c);
10219 move_all_children (c, clone);
10221 replace_child (c, clone, prev);
10222 generate_skeleton_ancestor_tree (parent);
10223 add_child_die (parent->new_die, c);
10227 generate_skeleton_bottom_up (&node);
10228 } while (next != NULL);
10231 /* Wrapper function for generate_skeleton_bottom_up. */
10234 generate_skeleton (dw_die_ref die)
10236 skeleton_chain_node node;
10238 node.old_die = die;
10239 node.new_die = NULL;
10240 node.parent = NULL;
10242 /* If this type definition is nested inside another type,
10243 always leave at least a declaration in its place. */
10244 if (die->die_parent != NULL && is_type_die (die->die_parent))
10245 node.new_die = clone_as_declaration (die);
10247 generate_skeleton_bottom_up (&node);
10248 return node.new_die;
10251 /* Remove the DIE from its parent, possibly replacing it with a cloned
10252 declaration. The original DIE will be moved to a new compile unit
10253 so that existing references to it follow it to the new location. If
10254 any of the original DIE's descendants is a declaration, we need to
10255 replace the original DIE with a skeleton tree and move the
10256 declarations back into the skeleton tree. */
10259 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10261 dw_die_ref skeleton;
10263 skeleton = generate_skeleton (child);
10264 if (skeleton == NULL)
10265 remove_child_with_prev (child, prev);
10268 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10269 replace_child (child, skeleton, prev);
10275 /* Traverse the DIE and set up additional .debug_types sections for each
10276 type worthy of being placed in a COMDAT section. */
10279 break_out_comdat_types (dw_die_ref die)
10283 dw_die_ref prev = NULL;
10284 dw_die_ref next = NULL;
10285 dw_die_ref unit = NULL;
10287 first = c = die->die_child;
10291 if (prev == NULL || prev->die_sib == c)
10294 next = (c == first ? NULL : c->die_sib);
10295 if (should_move_die_to_comdat (c))
10297 dw_die_ref replacement;
10298 comdat_type_node_ref type_node;
10300 /* Create a new type unit DIE as the root for the new tree, and
10301 add it to the list of comdat types. */
10302 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10303 add_AT_unsigned (unit, DW_AT_language,
10304 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10305 type_node = ggc_alloc_cleared_comdat_type_node ();
10306 type_node->root_die = unit;
10307 type_node->next = comdat_type_list;
10308 comdat_type_list = type_node;
10310 /* Generate the type signature. */
10311 generate_type_signature (c, type_node);
10313 /* Copy the declaration context, attributes, and children of the
10314 declaration into the new compile unit DIE. */
10315 copy_declaration_context (unit, c);
10317 /* Remove this DIE from the main CU. */
10318 replacement = remove_child_or_replace_with_skeleton (c, prev);
10320 /* Break out nested types into their own type units. */
10321 break_out_comdat_types (c);
10323 /* Add the DIE to the new compunit. */
10324 add_child_die (unit, c);
10326 if (replacement != NULL)
10329 else if (c->die_tag == DW_TAG_namespace
10330 || c->die_tag == DW_TAG_class_type
10331 || c->die_tag == DW_TAG_structure_type
10332 || c->die_tag == DW_TAG_union_type)
10334 /* Look for nested types that can be broken out. */
10335 break_out_comdat_types (c);
10337 } while (next != NULL);
10340 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10342 struct decl_table_entry
10348 /* Routines to manipulate hash table of copied declarations. */
10351 htab_decl_hash (const void *of)
10353 const struct decl_table_entry *const entry =
10354 (const struct decl_table_entry *) of;
10356 return htab_hash_pointer (entry->orig);
10360 htab_decl_eq (const void *of1, const void *of2)
10362 const struct decl_table_entry *const entry1 =
10363 (const struct decl_table_entry *) of1;
10364 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10366 return entry1->orig == entry2;
10370 htab_decl_del (void *what)
10372 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10377 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10378 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10379 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10380 to check if the ancestor has already been copied into UNIT. */
10383 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10385 dw_die_ref parent = die->die_parent;
10386 dw_die_ref new_parent = unit;
10388 void **slot = NULL;
10389 struct decl_table_entry *entry = NULL;
10393 /* Check if the entry has already been copied to UNIT. */
10394 slot = htab_find_slot_with_hash (decl_table, die,
10395 htab_hash_pointer (die), INSERT);
10396 if (*slot != HTAB_EMPTY_ENTRY)
10398 entry = (struct decl_table_entry *) *slot;
10399 return entry->copy;
10402 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10403 entry = XCNEW (struct decl_table_entry);
10405 entry->copy = NULL;
10409 if (parent != NULL)
10411 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10414 if (parent->die_tag != DW_TAG_compile_unit
10415 && parent->die_tag != DW_TAG_type_unit)
10416 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10419 copy = clone_as_declaration (die);
10420 add_child_die (new_parent, copy);
10422 if (decl_table != NULL)
10424 /* Record the pointer to the copy. */
10425 entry->copy = copy;
10431 /* Walk the DIE and its children, looking for references to incomplete
10432 or trivial types that are unmarked (i.e., that are not in the current
10436 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10442 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10444 if (AT_class (a) == dw_val_class_die_ref)
10446 dw_die_ref targ = AT_ref (a);
10447 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10449 struct decl_table_entry *entry;
10451 if (targ->die_mark != 0 || type_node != NULL)
10454 slot = htab_find_slot_with_hash (decl_table, targ,
10455 htab_hash_pointer (targ), INSERT);
10457 if (*slot != HTAB_EMPTY_ENTRY)
10459 /* TARG has already been copied, so we just need to
10460 modify the reference to point to the copy. */
10461 entry = (struct decl_table_entry *) *slot;
10462 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10466 dw_die_ref parent = unit;
10467 dw_die_ref copy = clone_tree (targ);
10469 /* Make sure the cloned tree is marked as part of the
10473 /* Record in DECL_TABLE that TARG has been copied.
10474 Need to do this now, before the recursive call,
10475 because DECL_TABLE may be expanded and SLOT
10476 would no longer be a valid pointer. */
10477 entry = XCNEW (struct decl_table_entry);
10478 entry->orig = targ;
10479 entry->copy = copy;
10482 /* If TARG has surrounding context, copy its ancestor tree
10483 into the new type unit. */
10484 if (targ->die_parent != NULL
10485 && targ->die_parent->die_tag != DW_TAG_compile_unit
10486 && targ->die_parent->die_tag != DW_TAG_type_unit)
10487 parent = copy_ancestor_tree (unit, targ->die_parent,
10490 add_child_die (parent, copy);
10491 a->dw_attr_val.v.val_die_ref.die = copy;
10493 /* Make sure the newly-copied DIE is walked. If it was
10494 installed in a previously-added context, it won't
10495 get visited otherwise. */
10496 if (parent != unit)
10498 /* Find the highest point of the newly-added tree,
10499 mark each node along the way, and walk from there. */
10500 parent->die_mark = 1;
10501 while (parent->die_parent
10502 && parent->die_parent->die_mark == 0)
10504 parent = parent->die_parent;
10505 parent->die_mark = 1;
10507 copy_decls_walk (unit, parent, decl_table);
10513 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10516 /* Copy declarations for "unworthy" types into the new comdat section.
10517 Incomplete types, modified types, and certain other types aren't broken
10518 out into comdat sections of their own, so they don't have a signature,
10519 and we need to copy the declaration into the same section so that we
10520 don't have an external reference. */
10523 copy_decls_for_unworthy_types (dw_die_ref unit)
10528 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10529 copy_decls_walk (unit, unit, decl_table);
10530 htab_delete (decl_table);
10531 unmark_dies (unit);
10534 /* Traverse the DIE and add a sibling attribute if it may have the
10535 effect of speeding up access to siblings. To save some space,
10536 avoid generating sibling attributes for DIE's without children. */
10539 add_sibling_attributes (dw_die_ref die)
10543 if (! die->die_child)
10546 if (die->die_parent && die != die->die_parent->die_child)
10547 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10549 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10552 /* Output all location lists for the DIE and its children. */
10555 output_location_lists (dw_die_ref die)
10561 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10562 if (AT_class (a) == dw_val_class_loc_list)
10563 output_loc_list (AT_loc_list (a));
10565 FOR_EACH_CHILD (die, c, output_location_lists (c));
10568 /* The format of each DIE (and its attribute value pairs) is encoded in an
10569 abbreviation table. This routine builds the abbreviation table and assigns
10570 a unique abbreviation id for each abbreviation entry. The children of each
10571 die are visited recursively. */
10574 build_abbrev_table (dw_die_ref die)
10576 unsigned long abbrev_id;
10577 unsigned int n_alloc;
10582 /* Scan the DIE references, and mark as external any that refer to
10583 DIEs from other CUs (i.e. those which are not marked). */
10584 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10585 if (AT_class (a) == dw_val_class_die_ref
10586 && AT_ref (a)->die_mark == 0)
10588 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10589 set_AT_ref_external (a, 1);
10592 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10594 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10595 dw_attr_ref die_a, abbrev_a;
10599 if (abbrev->die_tag != die->die_tag)
10601 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10604 if (VEC_length (dw_attr_node, abbrev->die_attr)
10605 != VEC_length (dw_attr_node, die->die_attr))
10608 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10610 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10611 if ((abbrev_a->dw_attr != die_a->dw_attr)
10612 || (value_format (abbrev_a) != value_format (die_a)))
10622 if (abbrev_id >= abbrev_die_table_in_use)
10624 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10626 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10627 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10630 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10631 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10632 abbrev_die_table_allocated = n_alloc;
10635 ++abbrev_die_table_in_use;
10636 abbrev_die_table[abbrev_id] = die;
10639 die->die_abbrev = abbrev_id;
10640 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10643 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10646 constant_size (unsigned HOST_WIDE_INT value)
10653 log = floor_log2 (value);
10656 log = 1 << (floor_log2 (log) + 1);
10661 /* Return the size of a DIE as it is represented in the
10662 .debug_info section. */
10664 static unsigned long
10665 size_of_die (dw_die_ref die)
10667 unsigned long size = 0;
10671 size += size_of_uleb128 (die->die_abbrev);
10672 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10674 switch (AT_class (a))
10676 case dw_val_class_addr:
10677 size += DWARF2_ADDR_SIZE;
10679 case dw_val_class_offset:
10680 size += DWARF_OFFSET_SIZE;
10682 case dw_val_class_loc:
10684 unsigned long lsize = size_of_locs (AT_loc (a));
10686 /* Block length. */
10687 if (dwarf_version >= 4)
10688 size += size_of_uleb128 (lsize);
10690 size += constant_size (lsize);
10694 case dw_val_class_loc_list:
10695 size += DWARF_OFFSET_SIZE;
10697 case dw_val_class_range_list:
10698 size += DWARF_OFFSET_SIZE;
10700 case dw_val_class_const:
10701 size += size_of_sleb128 (AT_int (a));
10703 case dw_val_class_unsigned_const:
10704 size += constant_size (AT_unsigned (a));
10706 case dw_val_class_const_double:
10707 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10708 if (HOST_BITS_PER_WIDE_INT >= 64)
10709 size++; /* block */
10711 case dw_val_class_vec:
10712 size += constant_size (a->dw_attr_val.v.val_vec.length
10713 * a->dw_attr_val.v.val_vec.elt_size)
10714 + a->dw_attr_val.v.val_vec.length
10715 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10717 case dw_val_class_flag:
10718 if (dwarf_version >= 4)
10719 /* Currently all add_AT_flag calls pass in 1 as last argument,
10720 so DW_FORM_flag_present can be used. If that ever changes,
10721 we'll need to use DW_FORM_flag and have some optimization
10722 in build_abbrev_table that will change those to
10723 DW_FORM_flag_present if it is set to 1 in all DIEs using
10724 the same abbrev entry. */
10725 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10729 case dw_val_class_die_ref:
10730 if (AT_ref_external (a))
10732 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10733 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10734 is sized by target address length, whereas in DWARF3
10735 it's always sized as an offset. */
10736 if (dwarf_version >= 4)
10737 size += DWARF_TYPE_SIGNATURE_SIZE;
10738 else if (dwarf_version == 2)
10739 size += DWARF2_ADDR_SIZE;
10741 size += DWARF_OFFSET_SIZE;
10744 size += DWARF_OFFSET_SIZE;
10746 case dw_val_class_fde_ref:
10747 size += DWARF_OFFSET_SIZE;
10749 case dw_val_class_lbl_id:
10750 size += DWARF2_ADDR_SIZE;
10752 case dw_val_class_lineptr:
10753 case dw_val_class_macptr:
10754 size += DWARF_OFFSET_SIZE;
10756 case dw_val_class_str:
10757 if (AT_string_form (a) == DW_FORM_strp)
10758 size += DWARF_OFFSET_SIZE;
10760 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10762 case dw_val_class_file:
10763 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10765 case dw_val_class_data8:
10768 case dw_val_class_vms_delta:
10769 size += DWARF_OFFSET_SIZE;
10772 gcc_unreachable ();
10779 /* Size the debugging information associated with a given DIE. Visits the
10780 DIE's children recursively. Updates the global variable next_die_offset, on
10781 each time through. Uses the current value of next_die_offset to update the
10782 die_offset field in each DIE. */
10785 calc_die_sizes (dw_die_ref die)
10789 die->die_offset = next_die_offset;
10790 next_die_offset += size_of_die (die);
10792 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10794 if (die->die_child != NULL)
10795 /* Count the null byte used to terminate sibling lists. */
10796 next_die_offset += 1;
10799 /* Set the marks for a die and its children. We do this so
10800 that we know whether or not a reference needs to use FORM_ref_addr; only
10801 DIEs in the same CU will be marked. We used to clear out the offset
10802 and use that as the flag, but ran into ordering problems. */
10805 mark_dies (dw_die_ref die)
10809 gcc_assert (!die->die_mark);
10812 FOR_EACH_CHILD (die, c, mark_dies (c));
10815 /* Clear the marks for a die and its children. */
10818 unmark_dies (dw_die_ref die)
10822 if (dwarf_version < 4)
10823 gcc_assert (die->die_mark);
10826 FOR_EACH_CHILD (die, c, unmark_dies (c));
10829 /* Clear the marks for a die, its children and referred dies. */
10832 unmark_all_dies (dw_die_ref die)
10838 if (!die->die_mark)
10842 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10844 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10845 if (AT_class (a) == dw_val_class_die_ref)
10846 unmark_all_dies (AT_ref (a));
10849 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10850 generated for the compilation unit. */
10852 static unsigned long
10853 size_of_pubnames (VEC (pubname_entry, gc) * names)
10855 unsigned long size;
10859 size = DWARF_PUBNAMES_HEADER_SIZE;
10860 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10861 if (names != pubtype_table
10862 || p->die->die_offset != 0
10863 || !flag_eliminate_unused_debug_types)
10864 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10866 size += DWARF_OFFSET_SIZE;
10870 /* Return the size of the information in the .debug_aranges section. */
10872 static unsigned long
10873 size_of_aranges (void)
10875 unsigned long size;
10877 size = DWARF_ARANGES_HEADER_SIZE;
10879 /* Count the address/length pair for this compilation unit. */
10880 if (text_section_used)
10881 size += 2 * DWARF2_ADDR_SIZE;
10882 if (cold_text_section_used)
10883 size += 2 * DWARF2_ADDR_SIZE;
10884 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
10886 /* Count the two zero words used to terminated the address range table. */
10887 size += 2 * DWARF2_ADDR_SIZE;
10891 /* Select the encoding of an attribute value. */
10893 static enum dwarf_form
10894 value_format (dw_attr_ref a)
10896 switch (a->dw_attr_val.val_class)
10898 case dw_val_class_addr:
10899 /* Only very few attributes allow DW_FORM_addr. */
10900 switch (a->dw_attr)
10903 case DW_AT_high_pc:
10904 case DW_AT_entry_pc:
10905 case DW_AT_trampoline:
10906 return DW_FORM_addr;
10910 switch (DWARF2_ADDR_SIZE)
10913 return DW_FORM_data1;
10915 return DW_FORM_data2;
10917 return DW_FORM_data4;
10919 return DW_FORM_data8;
10921 gcc_unreachable ();
10923 case dw_val_class_range_list:
10924 case dw_val_class_loc_list:
10925 if (dwarf_version >= 4)
10926 return DW_FORM_sec_offset;
10928 case dw_val_class_vms_delta:
10929 case dw_val_class_offset:
10930 switch (DWARF_OFFSET_SIZE)
10933 return DW_FORM_data4;
10935 return DW_FORM_data8;
10937 gcc_unreachable ();
10939 case dw_val_class_loc:
10940 if (dwarf_version >= 4)
10941 return DW_FORM_exprloc;
10942 switch (constant_size (size_of_locs (AT_loc (a))))
10945 return DW_FORM_block1;
10947 return DW_FORM_block2;
10949 gcc_unreachable ();
10951 case dw_val_class_const:
10952 return DW_FORM_sdata;
10953 case dw_val_class_unsigned_const:
10954 switch (constant_size (AT_unsigned (a)))
10957 return DW_FORM_data1;
10959 return DW_FORM_data2;
10961 return DW_FORM_data4;
10963 return DW_FORM_data8;
10965 gcc_unreachable ();
10967 case dw_val_class_const_double:
10968 switch (HOST_BITS_PER_WIDE_INT)
10971 return DW_FORM_data2;
10973 return DW_FORM_data4;
10975 return DW_FORM_data8;
10978 return DW_FORM_block1;
10980 case dw_val_class_vec:
10981 switch (constant_size (a->dw_attr_val.v.val_vec.length
10982 * a->dw_attr_val.v.val_vec.elt_size))
10985 return DW_FORM_block1;
10987 return DW_FORM_block2;
10989 return DW_FORM_block4;
10991 gcc_unreachable ();
10993 case dw_val_class_flag:
10994 if (dwarf_version >= 4)
10996 /* Currently all add_AT_flag calls pass in 1 as last argument,
10997 so DW_FORM_flag_present can be used. If that ever changes,
10998 we'll need to use DW_FORM_flag and have some optimization
10999 in build_abbrev_table that will change those to
11000 DW_FORM_flag_present if it is set to 1 in all DIEs using
11001 the same abbrev entry. */
11002 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11003 return DW_FORM_flag_present;
11005 return DW_FORM_flag;
11006 case dw_val_class_die_ref:
11007 if (AT_ref_external (a))
11008 return dwarf_version >= 4 ? DW_FORM_sig8 : DW_FORM_ref_addr;
11010 return DW_FORM_ref;
11011 case dw_val_class_fde_ref:
11012 return DW_FORM_data;
11013 case dw_val_class_lbl_id:
11014 return DW_FORM_addr;
11015 case dw_val_class_lineptr:
11016 case dw_val_class_macptr:
11017 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11018 case dw_val_class_str:
11019 return AT_string_form (a);
11020 case dw_val_class_file:
11021 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11024 return DW_FORM_data1;
11026 return DW_FORM_data2;
11028 return DW_FORM_data4;
11030 gcc_unreachable ();
11033 case dw_val_class_data8:
11034 return DW_FORM_data8;
11037 gcc_unreachable ();
11041 /* Output the encoding of an attribute value. */
11044 output_value_format (dw_attr_ref a)
11046 enum dwarf_form form = value_format (a);
11048 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11051 /* Output the .debug_abbrev section which defines the DIE abbreviation
11055 output_abbrev_section (void)
11057 unsigned long abbrev_id;
11059 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11061 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11063 dw_attr_ref a_attr;
11065 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11066 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11067 dwarf_tag_name (abbrev->die_tag));
11069 if (abbrev->die_child != NULL)
11070 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11072 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11074 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11077 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11078 dwarf_attr_name (a_attr->dw_attr));
11079 output_value_format (a_attr);
11082 dw2_asm_output_data (1, 0, NULL);
11083 dw2_asm_output_data (1, 0, NULL);
11086 /* Terminate the table. */
11087 dw2_asm_output_data (1, 0, NULL);
11090 /* Output a symbol we can use to refer to this DIE from another CU. */
11093 output_die_symbol (dw_die_ref die)
11095 char *sym = die->die_id.die_symbol;
11100 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11101 /* We make these global, not weak; if the target doesn't support
11102 .linkonce, it doesn't support combining the sections, so debugging
11104 targetm.asm_out.globalize_label (asm_out_file, sym);
11106 ASM_OUTPUT_LABEL (asm_out_file, sym);
11109 /* Return a new location list, given the begin and end range, and the
11112 static inline dw_loc_list_ref
11113 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11114 const char *section)
11116 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11118 retlist->begin = begin;
11119 retlist->end = end;
11120 retlist->expr = expr;
11121 retlist->section = section;
11126 /* Generate a new internal symbol for this location list node, if it
11127 hasn't got one yet. */
11130 gen_llsym (dw_loc_list_ref list)
11132 gcc_assert (!list->ll_symbol);
11133 list->ll_symbol = gen_internal_sym ("LLST");
11136 /* Output the location list given to us. */
11139 output_loc_list (dw_loc_list_ref list_head)
11141 dw_loc_list_ref curr = list_head;
11143 if (list_head->emitted)
11145 list_head->emitted = true;
11147 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11149 /* Walk the location list, and output each range + expression. */
11150 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11152 unsigned long size;
11153 /* Don't output an entry that starts and ends at the same address. */
11154 if (strcmp (curr->begin, curr->end) == 0)
11156 if (!have_multiple_function_sections)
11158 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11159 "Location list begin address (%s)",
11160 list_head->ll_symbol);
11161 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11162 "Location list end address (%s)",
11163 list_head->ll_symbol);
11167 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11168 "Location list begin address (%s)",
11169 list_head->ll_symbol);
11170 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11171 "Location list end address (%s)",
11172 list_head->ll_symbol);
11174 size = size_of_locs (curr->expr);
11176 /* Output the block length for this list of location operations. */
11177 gcc_assert (size <= 0xffff);
11178 dw2_asm_output_data (2, size, "%s", "Location expression size");
11180 output_loc_sequence (curr->expr, -1);
11183 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11184 "Location list terminator begin (%s)",
11185 list_head->ll_symbol);
11186 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11187 "Location list terminator end (%s)",
11188 list_head->ll_symbol);
11191 /* Output a type signature. */
11194 output_signature (const char *sig, const char *name)
11198 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11199 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11202 /* Output the DIE and its attributes. Called recursively to generate
11203 the definitions of each child DIE. */
11206 output_die (dw_die_ref die)
11210 unsigned long size;
11213 /* If someone in another CU might refer to us, set up a symbol for
11214 them to point to. */
11215 if (dwarf_version < 4 && die->die_id.die_symbol)
11216 output_die_symbol (die);
11218 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11219 (unsigned long)die->die_offset,
11220 dwarf_tag_name (die->die_tag));
11222 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11224 const char *name = dwarf_attr_name (a->dw_attr);
11226 switch (AT_class (a))
11228 case dw_val_class_addr:
11229 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11232 case dw_val_class_offset:
11233 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11237 case dw_val_class_range_list:
11239 char *p = strchr (ranges_section_label, '\0');
11241 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11242 a->dw_attr_val.v.val_offset);
11243 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11244 debug_ranges_section, "%s", name);
11249 case dw_val_class_loc:
11250 size = size_of_locs (AT_loc (a));
11252 /* Output the block length for this list of location operations. */
11253 if (dwarf_version >= 4)
11254 dw2_asm_output_data_uleb128 (size, "%s", name);
11256 dw2_asm_output_data (constant_size (size), size, "%s", name);
11258 output_loc_sequence (AT_loc (a), -1);
11261 case dw_val_class_const:
11262 /* ??? It would be slightly more efficient to use a scheme like is
11263 used for unsigned constants below, but gdb 4.x does not sign
11264 extend. Gdb 5.x does sign extend. */
11265 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11268 case dw_val_class_unsigned_const:
11269 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11270 AT_unsigned (a), "%s", name);
11273 case dw_val_class_const_double:
11275 unsigned HOST_WIDE_INT first, second;
11277 if (HOST_BITS_PER_WIDE_INT >= 64)
11278 dw2_asm_output_data (1,
11279 2 * HOST_BITS_PER_WIDE_INT
11280 / HOST_BITS_PER_CHAR,
11283 if (WORDS_BIG_ENDIAN)
11285 first = a->dw_attr_val.v.val_double.high;
11286 second = a->dw_attr_val.v.val_double.low;
11290 first = a->dw_attr_val.v.val_double.low;
11291 second = a->dw_attr_val.v.val_double.high;
11294 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11296 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11301 case dw_val_class_vec:
11303 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11304 unsigned int len = a->dw_attr_val.v.val_vec.length;
11308 dw2_asm_output_data (constant_size (len * elt_size),
11309 len * elt_size, "%s", name);
11310 if (elt_size > sizeof (HOST_WIDE_INT))
11315 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11317 i++, p += elt_size)
11318 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11319 "fp or vector constant word %u", i);
11323 case dw_val_class_flag:
11324 if (dwarf_version >= 4)
11326 /* Currently all add_AT_flag calls pass in 1 as last argument,
11327 so DW_FORM_flag_present can be used. If that ever changes,
11328 we'll need to use DW_FORM_flag and have some optimization
11329 in build_abbrev_table that will change those to
11330 DW_FORM_flag_present if it is set to 1 in all DIEs using
11331 the same abbrev entry. */
11332 gcc_assert (AT_flag (a) == 1);
11333 if (flag_debug_asm)
11334 fprintf (asm_out_file, "\t\t\t%s %s\n",
11335 ASM_COMMENT_START, name);
11338 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11341 case dw_val_class_loc_list:
11343 char *sym = AT_loc_list (a)->ll_symbol;
11346 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11351 case dw_val_class_die_ref:
11352 if (AT_ref_external (a))
11354 if (dwarf_version >= 4)
11356 comdat_type_node_ref type_node =
11357 AT_ref (a)->die_id.die_type_node;
11359 gcc_assert (type_node);
11360 output_signature (type_node->signature, name);
11364 char *sym = AT_ref (a)->die_id.die_symbol;
11368 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11369 length, whereas in DWARF3 it's always sized as an
11371 if (dwarf_version == 2)
11372 size = DWARF2_ADDR_SIZE;
11374 size = DWARF_OFFSET_SIZE;
11375 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11381 gcc_assert (AT_ref (a)->die_offset);
11382 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11387 case dw_val_class_fde_ref:
11391 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11392 a->dw_attr_val.v.val_fde_index * 2);
11393 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11398 case dw_val_class_vms_delta:
11399 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11400 AT_vms_delta2 (a), AT_vms_delta1 (a),
11404 case dw_val_class_lbl_id:
11405 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11408 case dw_val_class_lineptr:
11409 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11410 debug_line_section, "%s", name);
11413 case dw_val_class_macptr:
11414 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11415 debug_macinfo_section, "%s", name);
11418 case dw_val_class_str:
11419 if (AT_string_form (a) == DW_FORM_strp)
11420 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11421 a->dw_attr_val.v.val_str->label,
11423 "%s: \"%s\"", name, AT_string (a));
11425 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11428 case dw_val_class_file:
11430 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11432 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11433 a->dw_attr_val.v.val_file->filename);
11437 case dw_val_class_data8:
11441 for (i = 0; i < 8; i++)
11442 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11443 i == 0 ? "%s" : NULL, name);
11448 gcc_unreachable ();
11452 FOR_EACH_CHILD (die, c, output_die (c));
11454 /* Add null byte to terminate sibling list. */
11455 if (die->die_child != NULL)
11456 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11457 (unsigned long) die->die_offset);
11460 /* Output the compilation unit that appears at the beginning of the
11461 .debug_info section, and precedes the DIE descriptions. */
11464 output_compilation_unit_header (void)
11466 int ver = dwarf_version;
11468 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11469 dw2_asm_output_data (4, 0xffffffff,
11470 "Initial length escape value indicating 64-bit DWARF extension");
11471 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11472 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11473 "Length of Compilation Unit Info");
11474 dw2_asm_output_data (2, ver, "DWARF version number");
11475 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11476 debug_abbrev_section,
11477 "Offset Into Abbrev. Section");
11478 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11481 /* Output the compilation unit DIE and its children. */
11484 output_comp_unit (dw_die_ref die, int output_if_empty)
11486 const char *secname;
11487 char *oldsym, *tmp;
11489 /* Unless we are outputting main CU, we may throw away empty ones. */
11490 if (!output_if_empty && die->die_child == NULL)
11493 /* Even if there are no children of this DIE, we must output the information
11494 about the compilation unit. Otherwise, on an empty translation unit, we
11495 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11496 will then complain when examining the file. First mark all the DIEs in
11497 this CU so we know which get local refs. */
11500 build_abbrev_table (die);
11502 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11503 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11504 calc_die_sizes (die);
11506 oldsym = die->die_id.die_symbol;
11509 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11511 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11513 die->die_id.die_symbol = NULL;
11514 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11518 switch_to_section (debug_info_section);
11519 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11520 info_section_emitted = true;
11523 /* Output debugging information. */
11524 output_compilation_unit_header ();
11527 /* Leave the marks on the main CU, so we can check them in
11528 output_pubnames. */
11532 die->die_id.die_symbol = oldsym;
11536 /* Output a comdat type unit DIE and its children. */
11539 output_comdat_type_unit (comdat_type_node *node)
11541 const char *secname;
11544 #if defined (OBJECT_FORMAT_ELF)
11548 /* First mark all the DIEs in this CU so we know which get local refs. */
11549 mark_dies (node->root_die);
11551 build_abbrev_table (node->root_die);
11553 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11554 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11555 calc_die_sizes (node->root_die);
11557 #if defined (OBJECT_FORMAT_ELF)
11558 secname = ".debug_types";
11559 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11560 sprintf (tmp, "wt.");
11561 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11562 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11563 comdat_key = get_identifier (tmp);
11564 targetm.asm_out.named_section (secname,
11565 SECTION_DEBUG | SECTION_LINKONCE,
11568 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11569 sprintf (tmp, ".gnu.linkonce.wt.");
11570 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11571 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11573 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11576 /* Output debugging information. */
11577 output_compilation_unit_header ();
11578 output_signature (node->signature, "Type Signature");
11579 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11580 "Offset to Type DIE");
11581 output_die (node->root_die);
11583 unmark_dies (node->root_die);
11586 /* Return the DWARF2/3 pubname associated with a decl. */
11588 static const char *
11589 dwarf2_name (tree decl, int scope)
11591 if (DECL_NAMELESS (decl))
11593 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11596 /* Add a new entry to .debug_pubnames if appropriate. */
11599 add_pubname_string (const char *str, dw_die_ref die)
11601 if (targetm.want_debug_pub_sections)
11606 e.name = xstrdup (str);
11607 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11612 add_pubname (tree decl, dw_die_ref die)
11614 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11616 const char *name = dwarf2_name (decl, 1);
11618 add_pubname_string (name, die);
11622 /* Add a new entry to .debug_pubtypes if appropriate. */
11625 add_pubtype (tree decl, dw_die_ref die)
11629 if (!targetm.want_debug_pub_sections)
11633 if ((TREE_PUBLIC (decl)
11634 || is_cu_die (die->die_parent))
11635 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11640 if (TYPE_NAME (decl))
11642 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11643 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11644 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11645 && DECL_NAME (TYPE_NAME (decl)))
11646 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11648 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11653 e.name = dwarf2_name (decl, 1);
11655 e.name = xstrdup (e.name);
11658 /* If we don't have a name for the type, there's no point in adding
11659 it to the table. */
11660 if (e.name && e.name[0] != '\0')
11661 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11665 /* Output the public names table used to speed up access to externally
11666 visible names; or the public types table used to find type definitions. */
11669 output_pubnames (VEC (pubname_entry, gc) * names)
11672 unsigned long pubnames_length = size_of_pubnames (names);
11675 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11676 dw2_asm_output_data (4, 0xffffffff,
11677 "Initial length escape value indicating 64-bit DWARF extension");
11678 if (names == pubname_table)
11679 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11680 "Length of Public Names Info");
11682 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11683 "Length of Public Type Names Info");
11684 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11685 dw2_asm_output_data (2, 2, "DWARF Version");
11686 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11687 debug_info_section,
11688 "Offset of Compilation Unit Info");
11689 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11690 "Compilation Unit Length");
11692 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11694 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11695 if (names == pubname_table)
11696 gcc_assert (pub->die->die_mark);
11698 if (names != pubtype_table
11699 || pub->die->die_offset != 0
11700 || !flag_eliminate_unused_debug_types)
11702 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11705 dw2_asm_output_nstring (pub->name, -1, "external name");
11709 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11712 /* Add a new entry to .debug_aranges if appropriate. */
11715 add_arange (tree decl, dw_die_ref die)
11717 if (! DECL_SECTION_NAME (decl))
11720 if (arange_table_in_use == arange_table_allocated)
11722 arange_table_allocated += ARANGE_TABLE_INCREMENT;
11723 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
11724 arange_table_allocated);
11725 memset (arange_table + arange_table_in_use, 0,
11726 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
11729 arange_table[arange_table_in_use++] = die;
11732 /* Output the information that goes into the .debug_aranges table.
11733 Namely, define the beginning and ending address range of the
11734 text section generated for this compilation unit. */
11737 output_aranges (void)
11740 unsigned long aranges_length = size_of_aranges ();
11742 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11743 dw2_asm_output_data (4, 0xffffffff,
11744 "Initial length escape value indicating 64-bit DWARF extension");
11745 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11746 "Length of Address Ranges Info");
11747 /* Version number for aranges is still 2, even in DWARF3. */
11748 dw2_asm_output_data (2, 2, "DWARF Version");
11749 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11750 debug_info_section,
11751 "Offset of Compilation Unit Info");
11752 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11753 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11755 /* We need to align to twice the pointer size here. */
11756 if (DWARF_ARANGES_PAD_SIZE)
11758 /* Pad using a 2 byte words so that padding is correct for any
11760 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11761 2 * DWARF2_ADDR_SIZE);
11762 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11763 dw2_asm_output_data (2, 0, NULL);
11766 /* It is necessary not to output these entries if the sections were
11767 not used; if the sections were not used, the length will be 0 and
11768 the address may end up as 0 if the section is discarded by ld
11769 --gc-sections, leaving an invalid (0, 0) entry that can be
11770 confused with the terminator. */
11771 if (text_section_used)
11773 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11774 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11775 text_section_label, "Length");
11777 if (cold_text_section_used)
11779 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11781 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11782 cold_text_section_label, "Length");
11785 for (i = 0; i < arange_table_in_use; i++)
11787 dw_die_ref die = arange_table[i];
11789 /* We shouldn't see aranges for DIEs outside of the main CU. */
11790 gcc_assert (die->die_mark);
11792 if (die->die_tag == DW_TAG_subprogram)
11794 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
11796 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
11797 get_AT_low_pc (die), "Length");
11801 /* A static variable; extract the symbol from DW_AT_location.
11802 Note that this code isn't currently hit, as we only emit
11803 aranges for functions (jason 9/23/99). */
11804 dw_attr_ref a = get_AT (die, DW_AT_location);
11805 dw_loc_descr_ref loc;
11807 gcc_assert (a && AT_class (a) == dw_val_class_loc);
11810 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
11812 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
11813 loc->dw_loc_oprnd1.v.val_addr, "Address");
11814 dw2_asm_output_data (DWARF2_ADDR_SIZE,
11815 get_AT_unsigned (die, DW_AT_byte_size),
11820 /* Output the terminator words. */
11821 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11822 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11825 /* Add a new entry to .debug_ranges. Return the offset at which it
11828 static unsigned int
11829 add_ranges_num (int num)
11831 unsigned int in_use = ranges_table_in_use;
11833 if (in_use == ranges_table_allocated)
11835 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11836 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11837 ranges_table_allocated);
11838 memset (ranges_table + ranges_table_in_use, 0,
11839 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11842 ranges_table[in_use].num = num;
11843 ranges_table_in_use = in_use + 1;
11845 return in_use * 2 * DWARF2_ADDR_SIZE;
11848 /* Add a new entry to .debug_ranges corresponding to a block, or a
11849 range terminator if BLOCK is NULL. */
11851 static unsigned int
11852 add_ranges (const_tree block)
11854 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11857 /* Add a new entry to .debug_ranges corresponding to a pair of
11861 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11864 unsigned int in_use = ranges_by_label_in_use;
11865 unsigned int offset;
11867 if (in_use == ranges_by_label_allocated)
11869 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11870 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11872 ranges_by_label_allocated);
11873 memset (ranges_by_label + ranges_by_label_in_use, 0,
11874 RANGES_TABLE_INCREMENT
11875 * sizeof (struct dw_ranges_by_label_struct));
11878 ranges_by_label[in_use].begin = begin;
11879 ranges_by_label[in_use].end = end;
11880 ranges_by_label_in_use = in_use + 1;
11882 offset = add_ranges_num (-(int)in_use - 1);
11885 add_AT_range_list (die, DW_AT_ranges, offset);
11891 output_ranges (void)
11894 static const char *const start_fmt = "Offset %#x";
11895 const char *fmt = start_fmt;
11897 for (i = 0; i < ranges_table_in_use; i++)
11899 int block_num = ranges_table[i].num;
11903 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11904 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11906 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11907 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11909 /* If all code is in the text section, then the compilation
11910 unit base address defaults to DW_AT_low_pc, which is the
11911 base of the text section. */
11912 if (!have_multiple_function_sections)
11914 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11915 text_section_label,
11916 fmt, i * 2 * DWARF2_ADDR_SIZE);
11917 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11918 text_section_label, NULL);
11921 /* Otherwise, the compilation unit base address is zero,
11922 which allows us to use absolute addresses, and not worry
11923 about whether the target supports cross-section
11927 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11928 fmt, i * 2 * DWARF2_ADDR_SIZE);
11929 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11935 /* Negative block_num stands for an index into ranges_by_label. */
11936 else if (block_num < 0)
11938 int lab_idx = - block_num - 1;
11940 if (!have_multiple_function_sections)
11942 gcc_unreachable ();
11944 /* If we ever use add_ranges_by_labels () for a single
11945 function section, all we have to do is to take out
11946 the #if 0 above. */
11947 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11948 ranges_by_label[lab_idx].begin,
11949 text_section_label,
11950 fmt, i * 2 * DWARF2_ADDR_SIZE);
11951 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11952 ranges_by_label[lab_idx].end,
11953 text_section_label, NULL);
11958 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11959 ranges_by_label[lab_idx].begin,
11960 fmt, i * 2 * DWARF2_ADDR_SIZE);
11961 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11962 ranges_by_label[lab_idx].end,
11968 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11969 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11975 /* Data structure containing information about input files. */
11978 const char *path; /* Complete file name. */
11979 const char *fname; /* File name part. */
11980 int length; /* Length of entire string. */
11981 struct dwarf_file_data * file_idx; /* Index in input file table. */
11982 int dir_idx; /* Index in directory table. */
11985 /* Data structure containing information about directories with source
11989 const char *path; /* Path including directory name. */
11990 int length; /* Path length. */
11991 int prefix; /* Index of directory entry which is a prefix. */
11992 int count; /* Number of files in this directory. */
11993 int dir_idx; /* Index of directory used as base. */
11996 /* Callback function for file_info comparison. We sort by looking at
11997 the directories in the path. */
12000 file_info_cmp (const void *p1, const void *p2)
12002 const struct file_info *const s1 = (const struct file_info *) p1;
12003 const struct file_info *const s2 = (const struct file_info *) p2;
12004 const unsigned char *cp1;
12005 const unsigned char *cp2;
12007 /* Take care of file names without directories. We need to make sure that
12008 we return consistent values to qsort since some will get confused if
12009 we return the same value when identical operands are passed in opposite
12010 orders. So if neither has a directory, return 0 and otherwise return
12011 1 or -1 depending on which one has the directory. */
12012 if ((s1->path == s1->fname || s2->path == s2->fname))
12013 return (s2->path == s2->fname) - (s1->path == s1->fname);
12015 cp1 = (const unsigned char *) s1->path;
12016 cp2 = (const unsigned char *) s2->path;
12022 /* Reached the end of the first path? If so, handle like above. */
12023 if ((cp1 == (const unsigned char *) s1->fname)
12024 || (cp2 == (const unsigned char *) s2->fname))
12025 return ((cp2 == (const unsigned char *) s2->fname)
12026 - (cp1 == (const unsigned char *) s1->fname));
12028 /* Character of current path component the same? */
12029 else if (*cp1 != *cp2)
12030 return *cp1 - *cp2;
12034 struct file_name_acquire_data
12036 struct file_info *files;
12041 /* Traversal function for the hash table. */
12044 file_name_acquire (void ** slot, void *data)
12046 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12047 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12048 struct file_info *fi;
12051 gcc_assert (fnad->max_files >= d->emitted_number);
12053 if (! d->emitted_number)
12056 gcc_assert (fnad->max_files != fnad->used_files);
12058 fi = fnad->files + fnad->used_files++;
12060 /* Skip all leading "./". */
12062 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12065 /* Create a new array entry. */
12067 fi->length = strlen (f);
12070 /* Search for the file name part. */
12071 f = strrchr (f, DIR_SEPARATOR);
12072 #if defined (DIR_SEPARATOR_2)
12074 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12078 if (f == NULL || f < g)
12084 fi->fname = f == NULL ? fi->path : f + 1;
12088 /* Output the directory table and the file name table. We try to minimize
12089 the total amount of memory needed. A heuristic is used to avoid large
12090 slowdowns with many input files. */
12093 output_file_names (void)
12095 struct file_name_acquire_data fnad;
12097 struct file_info *files;
12098 struct dir_info *dirs;
12106 if (!last_emitted_file)
12108 dw2_asm_output_data (1, 0, "End directory table");
12109 dw2_asm_output_data (1, 0, "End file name table");
12113 numfiles = last_emitted_file->emitted_number;
12115 /* Allocate the various arrays we need. */
12116 files = XALLOCAVEC (struct file_info, numfiles);
12117 dirs = XALLOCAVEC (struct dir_info, numfiles);
12119 fnad.files = files;
12120 fnad.used_files = 0;
12121 fnad.max_files = numfiles;
12122 htab_traverse (file_table, file_name_acquire, &fnad);
12123 gcc_assert (fnad.used_files == fnad.max_files);
12125 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12127 /* Find all the different directories used. */
12128 dirs[0].path = files[0].path;
12129 dirs[0].length = files[0].fname - files[0].path;
12130 dirs[0].prefix = -1;
12132 dirs[0].dir_idx = 0;
12133 files[0].dir_idx = 0;
12136 for (i = 1; i < numfiles; i++)
12137 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12138 && memcmp (dirs[ndirs - 1].path, files[i].path,
12139 dirs[ndirs - 1].length) == 0)
12141 /* Same directory as last entry. */
12142 files[i].dir_idx = ndirs - 1;
12143 ++dirs[ndirs - 1].count;
12149 /* This is a new directory. */
12150 dirs[ndirs].path = files[i].path;
12151 dirs[ndirs].length = files[i].fname - files[i].path;
12152 dirs[ndirs].count = 1;
12153 dirs[ndirs].dir_idx = ndirs;
12154 files[i].dir_idx = ndirs;
12156 /* Search for a prefix. */
12157 dirs[ndirs].prefix = -1;
12158 for (j = 0; j < ndirs; j++)
12159 if (dirs[j].length < dirs[ndirs].length
12160 && dirs[j].length > 1
12161 && (dirs[ndirs].prefix == -1
12162 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12163 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12164 dirs[ndirs].prefix = j;
12169 /* Now to the actual work. We have to find a subset of the directories which
12170 allow expressing the file name using references to the directory table
12171 with the least amount of characters. We do not do an exhaustive search
12172 where we would have to check out every combination of every single
12173 possible prefix. Instead we use a heuristic which provides nearly optimal
12174 results in most cases and never is much off. */
12175 saved = XALLOCAVEC (int, ndirs);
12176 savehere = XALLOCAVEC (int, ndirs);
12178 memset (saved, '\0', ndirs * sizeof (saved[0]));
12179 for (i = 0; i < ndirs; i++)
12184 /* We can always save some space for the current directory. But this
12185 does not mean it will be enough to justify adding the directory. */
12186 savehere[i] = dirs[i].length;
12187 total = (savehere[i] - saved[i]) * dirs[i].count;
12189 for (j = i + 1; j < ndirs; j++)
12192 if (saved[j] < dirs[i].length)
12194 /* Determine whether the dirs[i] path is a prefix of the
12198 k = dirs[j].prefix;
12199 while (k != -1 && k != (int) i)
12200 k = dirs[k].prefix;
12204 /* Yes it is. We can possibly save some memory by
12205 writing the filenames in dirs[j] relative to
12207 savehere[j] = dirs[i].length;
12208 total += (savehere[j] - saved[j]) * dirs[j].count;
12213 /* Check whether we can save enough to justify adding the dirs[i]
12215 if (total > dirs[i].length + 1)
12217 /* It's worthwhile adding. */
12218 for (j = i; j < ndirs; j++)
12219 if (savehere[j] > 0)
12221 /* Remember how much we saved for this directory so far. */
12222 saved[j] = savehere[j];
12224 /* Remember the prefix directory. */
12225 dirs[j].dir_idx = i;
12230 /* Emit the directory name table. */
12231 idx_offset = dirs[0].length > 0 ? 1 : 0;
12232 for (i = 1 - idx_offset; i < ndirs; i++)
12233 dw2_asm_output_nstring (dirs[i].path,
12235 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12236 "Directory Entry: %#x", i + idx_offset);
12238 dw2_asm_output_data (1, 0, "End directory table");
12240 /* We have to emit them in the order of emitted_number since that's
12241 used in the debug info generation. To do this efficiently we
12242 generate a back-mapping of the indices first. */
12243 backmap = XALLOCAVEC (int, numfiles);
12244 for (i = 0; i < numfiles; i++)
12245 backmap[files[i].file_idx->emitted_number - 1] = i;
12247 /* Now write all the file names. */
12248 for (i = 0; i < numfiles; i++)
12250 int file_idx = backmap[i];
12251 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12253 #ifdef VMS_DEBUGGING_INFO
12254 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12256 /* Setting these fields can lead to debugger miscomparisons,
12257 but VMS Debug requires them to be set correctly. */
12262 int maxfilelen = strlen (files[file_idx].path)
12263 + dirs[dir_idx].length
12264 + MAX_VMS_VERSION_LEN + 1;
12265 char *filebuf = XALLOCAVEC (char, maxfilelen);
12267 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12268 snprintf (filebuf, maxfilelen, "%s;%d",
12269 files[file_idx].path + dirs[dir_idx].length, ver);
12271 dw2_asm_output_nstring
12272 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12274 /* Include directory index. */
12275 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12277 /* Modification time. */
12278 dw2_asm_output_data_uleb128
12279 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12283 /* File length in bytes. */
12284 dw2_asm_output_data_uleb128
12285 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12289 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12290 "File Entry: %#x", (unsigned) i + 1);
12292 /* Include directory index. */
12293 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12295 /* Modification time. */
12296 dw2_asm_output_data_uleb128 (0, NULL);
12298 /* File length in bytes. */
12299 dw2_asm_output_data_uleb128 (0, NULL);
12300 #endif /* VMS_DEBUGGING_INFO */
12303 dw2_asm_output_data (1, 0, "End file name table");
12307 /* Output the source line number correspondence information. This
12308 information goes into the .debug_line section. */
12311 output_line_info (void)
12313 char l1[20], l2[20], p1[20], p2[20];
12314 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12315 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12317 unsigned n_op_args;
12318 unsigned long lt_index;
12319 unsigned long current_line;
12322 unsigned long current_file;
12323 unsigned long function;
12324 int ver = dwarf_version;
12326 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12327 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12328 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12329 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12331 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12332 dw2_asm_output_data (4, 0xffffffff,
12333 "Initial length escape value indicating 64-bit DWARF extension");
12334 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12335 "Length of Source Line Info");
12336 ASM_OUTPUT_LABEL (asm_out_file, l1);
12338 dw2_asm_output_data (2, ver, "DWARF Version");
12339 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12340 ASM_OUTPUT_LABEL (asm_out_file, p1);
12342 /* Define the architecture-dependent minimum instruction length (in
12343 bytes). In this implementation of DWARF, this field is used for
12344 information purposes only. Since GCC generates assembly language,
12345 we have no a priori knowledge of how many instruction bytes are
12346 generated for each source line, and therefore can use only the
12347 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12348 commands. Accordingly, we fix this as `1', which is "correct
12349 enough" for all architectures, and don't let the target override. */
12350 dw2_asm_output_data (1, 1,
12351 "Minimum Instruction Length");
12354 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12355 "Maximum Operations Per Instruction");
12356 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12357 "Default is_stmt_start flag");
12358 dw2_asm_output_data (1, DWARF_LINE_BASE,
12359 "Line Base Value (Special Opcodes)");
12360 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12361 "Line Range Value (Special Opcodes)");
12362 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12363 "Special Opcode Base");
12365 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12369 case DW_LNS_advance_pc:
12370 case DW_LNS_advance_line:
12371 case DW_LNS_set_file:
12372 case DW_LNS_set_column:
12373 case DW_LNS_fixed_advance_pc:
12381 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12385 /* Write out the information about the files we use. */
12386 output_file_names ();
12387 ASM_OUTPUT_LABEL (asm_out_file, p2);
12389 /* We used to set the address register to the first location in the text
12390 section here, but that didn't accomplish anything since we already
12391 have a line note for the opening brace of the first function. */
12393 /* Generate the line number to PC correspondence table, encoded as
12394 a series of state machine operations. */
12398 if (cfun && in_cold_section_p)
12399 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12401 strcpy (prev_line_label, text_section_label);
12402 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12404 dw_line_info_ref line_info = &line_info_table[lt_index];
12407 /* Disable this optimization for now; GDB wants to see two line notes
12408 at the beginning of a function so it can find the end of the
12411 /* Don't emit anything for redundant notes. Just updating the
12412 address doesn't accomplish anything, because we already assume
12413 that anything after the last address is this line. */
12414 if (line_info->dw_line_num == current_line
12415 && line_info->dw_file_num == current_file)
12419 /* Emit debug info for the address of the current line.
12421 Unfortunately, we have little choice here currently, and must always
12422 use the most general form. GCC does not know the address delta
12423 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12424 attributes which will give an upper bound on the address range. We
12425 could perhaps use length attributes to determine when it is safe to
12426 use DW_LNS_fixed_advance_pc. */
12428 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12431 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12432 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12433 "DW_LNS_fixed_advance_pc");
12434 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12438 /* This can handle any delta. This takes
12439 4+DWARF2_ADDR_SIZE bytes. */
12440 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12441 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12442 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12443 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12446 strcpy (prev_line_label, line_label);
12448 /* Emit debug info for the source file of the current line, if
12449 different from the previous line. */
12450 if (line_info->dw_file_num != current_file)
12452 current_file = line_info->dw_file_num;
12453 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12454 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12457 /* Emit debug info for the current line number, choosing the encoding
12458 that uses the least amount of space. */
12459 if (line_info->dw_line_num != current_line)
12461 line_offset = line_info->dw_line_num - current_line;
12462 line_delta = line_offset - DWARF_LINE_BASE;
12463 current_line = line_info->dw_line_num;
12464 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12465 /* This can handle deltas from -10 to 234, using the current
12466 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12468 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12469 "line %lu", current_line);
12472 /* This can handle any delta. This takes at least 4 bytes,
12473 depending on the value being encoded. */
12474 dw2_asm_output_data (1, DW_LNS_advance_line,
12475 "advance to line %lu", current_line);
12476 dw2_asm_output_data_sleb128 (line_offset, NULL);
12477 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12481 /* We still need to start a new row, so output a copy insn. */
12482 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12485 /* Emit debug info for the address of the end of the function. */
12488 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12489 "DW_LNS_fixed_advance_pc");
12490 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12494 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12495 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12496 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12497 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12500 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12501 dw2_asm_output_data_uleb128 (1, NULL);
12502 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12507 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12509 dw_separate_line_info_ref line_info
12510 = &separate_line_info_table[lt_index];
12513 /* Don't emit anything for redundant notes. */
12514 if (line_info->dw_line_num == current_line
12515 && line_info->dw_file_num == current_file
12516 && line_info->function == function)
12520 /* Emit debug info for the address of the current line. If this is
12521 a new function, or the first line of a function, then we need
12522 to handle it differently. */
12523 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12525 if (function != line_info->function)
12527 function = line_info->function;
12529 /* Set the address register to the first line in the function. */
12530 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12531 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12532 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12533 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12537 /* ??? See the DW_LNS_advance_pc comment above. */
12540 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12541 "DW_LNS_fixed_advance_pc");
12542 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12546 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12547 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12548 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12549 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12553 strcpy (prev_line_label, line_label);
12555 /* Emit debug info for the source file of the current line, if
12556 different from the previous line. */
12557 if (line_info->dw_file_num != current_file)
12559 current_file = line_info->dw_file_num;
12560 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12561 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12564 /* Emit debug info for the current line number, choosing the encoding
12565 that uses the least amount of space. */
12566 if (line_info->dw_line_num != current_line)
12568 line_offset = line_info->dw_line_num - current_line;
12569 line_delta = line_offset - DWARF_LINE_BASE;
12570 current_line = line_info->dw_line_num;
12571 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12572 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12573 "line %lu", current_line);
12576 dw2_asm_output_data (1, DW_LNS_advance_line,
12577 "advance to line %lu", current_line);
12578 dw2_asm_output_data_sleb128 (line_offset, NULL);
12579 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12583 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12591 /* If we're done with a function, end its sequence. */
12592 if (lt_index == separate_line_info_table_in_use
12593 || separate_line_info_table[lt_index].function != function)
12598 /* Emit debug info for the address of the end of the function. */
12599 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12602 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12603 "DW_LNS_fixed_advance_pc");
12604 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12608 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12609 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12610 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12611 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12614 /* Output the marker for the end of this sequence. */
12615 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12616 dw2_asm_output_data_uleb128 (1, NULL);
12617 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12621 /* Output the marker for the end of the line number info. */
12622 ASM_OUTPUT_LABEL (asm_out_file, l2);
12625 /* Given a pointer to a tree node for some base type, return a pointer to
12626 a DIE that describes the given type.
12628 This routine must only be called for GCC type nodes that correspond to
12629 Dwarf base (fundamental) types. */
12632 base_type_die (tree type)
12634 dw_die_ref base_type_result;
12635 enum dwarf_type encoding;
12637 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12640 /* If this is a subtype that should not be emitted as a subrange type,
12641 use the base type. See subrange_type_for_debug_p. */
12642 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12643 type = TREE_TYPE (type);
12645 switch (TREE_CODE (type))
12648 if ((dwarf_version >= 4 || !dwarf_strict)
12649 && TYPE_NAME (type)
12650 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12651 && DECL_IS_BUILTIN (TYPE_NAME (type))
12652 && DECL_NAME (TYPE_NAME (type)))
12654 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12655 if (strcmp (name, "char16_t") == 0
12656 || strcmp (name, "char32_t") == 0)
12658 encoding = DW_ATE_UTF;
12662 if (TYPE_STRING_FLAG (type))
12664 if (TYPE_UNSIGNED (type))
12665 encoding = DW_ATE_unsigned_char;
12667 encoding = DW_ATE_signed_char;
12669 else if (TYPE_UNSIGNED (type))
12670 encoding = DW_ATE_unsigned;
12672 encoding = DW_ATE_signed;
12676 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12678 if (dwarf_version >= 3 || !dwarf_strict)
12679 encoding = DW_ATE_decimal_float;
12681 encoding = DW_ATE_lo_user;
12684 encoding = DW_ATE_float;
12687 case FIXED_POINT_TYPE:
12688 if (!(dwarf_version >= 3 || !dwarf_strict))
12689 encoding = DW_ATE_lo_user;
12690 else if (TYPE_UNSIGNED (type))
12691 encoding = DW_ATE_unsigned_fixed;
12693 encoding = DW_ATE_signed_fixed;
12696 /* Dwarf2 doesn't know anything about complex ints, so use
12697 a user defined type for it. */
12699 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12700 encoding = DW_ATE_complex_float;
12702 encoding = DW_ATE_lo_user;
12706 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12707 encoding = DW_ATE_boolean;
12711 /* No other TREE_CODEs are Dwarf fundamental types. */
12712 gcc_unreachable ();
12715 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12717 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12718 int_size_in_bytes (type));
12719 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12721 return base_type_result;
12724 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12725 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12728 is_base_type (tree type)
12730 switch (TREE_CODE (type))
12736 case FIXED_POINT_TYPE:
12744 case QUAL_UNION_TYPE:
12745 case ENUMERAL_TYPE:
12746 case FUNCTION_TYPE:
12749 case REFERENCE_TYPE:
12757 gcc_unreachable ();
12763 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12764 node, return the size in bits for the type if it is a constant, or else
12765 return the alignment for the type if the type's size is not constant, or
12766 else return BITS_PER_WORD if the type actually turns out to be an
12767 ERROR_MARK node. */
12769 static inline unsigned HOST_WIDE_INT
12770 simple_type_size_in_bits (const_tree type)
12772 if (TREE_CODE (type) == ERROR_MARK)
12773 return BITS_PER_WORD;
12774 else if (TYPE_SIZE (type) == NULL_TREE)
12776 else if (host_integerp (TYPE_SIZE (type), 1))
12777 return tree_low_cst (TYPE_SIZE (type), 1);
12779 return TYPE_ALIGN (type);
12782 /* Similarly, but return a double_int instead of UHWI. */
12784 static inline double_int
12785 double_int_type_size_in_bits (const_tree type)
12787 if (TREE_CODE (type) == ERROR_MARK)
12788 return uhwi_to_double_int (BITS_PER_WORD);
12789 else if (TYPE_SIZE (type) == NULL_TREE)
12790 return double_int_zero;
12791 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12792 return tree_to_double_int (TYPE_SIZE (type));
12794 return uhwi_to_double_int (TYPE_ALIGN (type));
12797 /* Given a pointer to a tree node for a subrange type, return a pointer
12798 to a DIE that describes the given type. */
12801 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12803 dw_die_ref subrange_die;
12804 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12806 if (context_die == NULL)
12807 context_die = comp_unit_die ();
12809 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12811 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12813 /* The size of the subrange type and its base type do not match,
12814 so we need to generate a size attribute for the subrange type. */
12815 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12819 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12821 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12823 return subrange_die;
12826 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12827 entry that chains various modifiers in front of the given type. */
12830 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12831 dw_die_ref context_die)
12833 enum tree_code code = TREE_CODE (type);
12834 dw_die_ref mod_type_die;
12835 dw_die_ref sub_die = NULL;
12836 tree item_type = NULL;
12837 tree qualified_type;
12838 tree name, low, high;
12840 if (code == ERROR_MARK)
12843 /* See if we already have the appropriately qualified variant of
12846 = get_qualified_type (type,
12847 ((is_const_type ? TYPE_QUAL_CONST : 0)
12848 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12850 if (qualified_type == sizetype
12851 && TYPE_NAME (qualified_type)
12852 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12854 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
12856 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
12857 && TYPE_PRECISION (t)
12858 == TYPE_PRECISION (qualified_type)
12859 && TYPE_UNSIGNED (t)
12860 == TYPE_UNSIGNED (qualified_type));
12861 qualified_type = t;
12864 /* If we do, then we can just use its DIE, if it exists. */
12865 if (qualified_type)
12867 mod_type_die = lookup_type_die (qualified_type);
12869 return mod_type_die;
12872 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12874 /* Handle C typedef types. */
12875 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12876 && !DECL_ARTIFICIAL (name))
12878 tree dtype = TREE_TYPE (name);
12880 if (qualified_type == dtype)
12882 /* For a named type, use the typedef. */
12883 gen_type_die (qualified_type, context_die);
12884 return lookup_type_die (qualified_type);
12886 else if (is_const_type < TYPE_READONLY (dtype)
12887 || is_volatile_type < TYPE_VOLATILE (dtype)
12888 || (is_const_type <= TYPE_READONLY (dtype)
12889 && is_volatile_type <= TYPE_VOLATILE (dtype)
12890 && DECL_ORIGINAL_TYPE (name) != type))
12891 /* cv-unqualified version of named type. Just use the unnamed
12892 type to which it refers. */
12893 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12894 is_const_type, is_volatile_type,
12896 /* Else cv-qualified version of named type; fall through. */
12900 /* If both is_const_type and is_volatile_type, prefer the path
12901 which leads to a qualified type. */
12902 && (!is_volatile_type
12903 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
12904 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
12906 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
12907 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12909 else if (is_volatile_type)
12911 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
12912 sub_die = modified_type_die (type, is_const_type, 0, context_die);
12914 else if (code == POINTER_TYPE)
12916 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
12917 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12918 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12919 item_type = TREE_TYPE (type);
12920 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12921 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12922 TYPE_ADDR_SPACE (item_type));
12924 else if (code == REFERENCE_TYPE)
12926 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
12927 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
12930 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
12931 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12932 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12933 item_type = TREE_TYPE (type);
12934 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12935 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12936 TYPE_ADDR_SPACE (item_type));
12938 else if (code == INTEGER_TYPE
12939 && TREE_TYPE (type) != NULL_TREE
12940 && subrange_type_for_debug_p (type, &low, &high))
12942 mod_type_die = subrange_type_die (type, low, high, context_die);
12943 item_type = TREE_TYPE (type);
12945 else if (is_base_type (type))
12946 mod_type_die = base_type_die (type);
12949 gen_type_die (type, context_die);
12951 /* We have to get the type_main_variant here (and pass that to the
12952 `lookup_type_die' routine) because the ..._TYPE node we have
12953 might simply be a *copy* of some original type node (where the
12954 copy was created to help us keep track of typedef names) and
12955 that copy might have a different TYPE_UID from the original
12957 if (TREE_CODE (type) != VECTOR_TYPE)
12958 return lookup_type_die (type_main_variant (type));
12960 /* Vectors have the debugging information in the type,
12961 not the main variant. */
12962 return lookup_type_die (type);
12965 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12966 don't output a DW_TAG_typedef, since there isn't one in the
12967 user's program; just attach a DW_AT_name to the type.
12968 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12969 if the base type already has the same name. */
12971 && ((TREE_CODE (name) != TYPE_DECL
12972 && (qualified_type == TYPE_MAIN_VARIANT (type)
12973 || (!is_const_type && !is_volatile_type)))
12974 || (TREE_CODE (name) == TYPE_DECL
12975 && TREE_TYPE (name) == qualified_type
12976 && DECL_NAME (name))))
12978 if (TREE_CODE (name) == TYPE_DECL)
12979 /* Could just call add_name_and_src_coords_attributes here,
12980 but since this is a builtin type it doesn't have any
12981 useful source coordinates anyway. */
12982 name = DECL_NAME (name);
12983 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12985 /* This probably indicates a bug. */
12986 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12987 add_name_attribute (mod_type_die, "__unknown__");
12989 if (qualified_type)
12990 equate_type_number_to_die (qualified_type, mod_type_die);
12993 /* We must do this after the equate_type_number_to_die call, in case
12994 this is a recursive type. This ensures that the modified_type_die
12995 recursion will terminate even if the type is recursive. Recursive
12996 types are possible in Ada. */
12997 sub_die = modified_type_die (item_type,
12998 TYPE_READONLY (item_type),
12999 TYPE_VOLATILE (item_type),
13002 if (sub_die != NULL)
13003 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
13005 return mod_type_die;
13008 /* Generate DIEs for the generic parameters of T.
13009 T must be either a generic type or a generic function.
13010 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13013 gen_generic_params_dies (tree t)
13017 dw_die_ref die = NULL;
13019 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13023 die = lookup_type_die (t);
13024 else if (DECL_P (t))
13025 die = lookup_decl_die (t);
13029 parms = lang_hooks.get_innermost_generic_parms (t);
13031 /* T has no generic parameter. It means T is neither a generic type
13032 or function. End of story. */
13035 parms_num = TREE_VEC_LENGTH (parms);
13036 args = lang_hooks.get_innermost_generic_args (t);
13037 for (i = 0; i < parms_num; i++)
13039 tree parm, arg, arg_pack_elems;
13041 parm = TREE_VEC_ELT (parms, i);
13042 arg = TREE_VEC_ELT (args, i);
13043 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13044 gcc_assert (parm && TREE_VALUE (parm) && arg);
13046 if (parm && TREE_VALUE (parm) && arg)
13048 /* If PARM represents a template parameter pack,
13049 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13050 by DW_TAG_template_*_parameter DIEs for the argument
13051 pack elements of ARG. Note that ARG would then be
13052 an argument pack. */
13053 if (arg_pack_elems)
13054 template_parameter_pack_die (TREE_VALUE (parm),
13058 generic_parameter_die (TREE_VALUE (parm), arg,
13059 true /* Emit DW_AT_name */, die);
13064 /* Create and return a DIE for PARM which should be
13065 the representation of a generic type parameter.
13066 For instance, in the C++ front end, PARM would be a template parameter.
13067 ARG is the argument to PARM.
13068 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13070 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13071 as a child node. */
13074 generic_parameter_die (tree parm, tree arg,
13076 dw_die_ref parent_die)
13078 dw_die_ref tmpl_die = NULL;
13079 const char *name = NULL;
13081 if (!parm || !DECL_NAME (parm) || !arg)
13084 /* We support non-type generic parameters and arguments,
13085 type generic parameters and arguments, as well as
13086 generic generic parameters (a.k.a. template template parameters in C++)
13088 if (TREE_CODE (parm) == PARM_DECL)
13089 /* PARM is a nontype generic parameter */
13090 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13091 else if (TREE_CODE (parm) == TYPE_DECL)
13092 /* PARM is a type generic parameter. */
13093 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13094 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13095 /* PARM is a generic generic parameter.
13096 Its DIE is a GNU extension. It shall have a
13097 DW_AT_name attribute to represent the name of the template template
13098 parameter, and a DW_AT_GNU_template_name attribute to represent the
13099 name of the template template argument. */
13100 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13103 gcc_unreachable ();
13109 /* If PARM is a generic parameter pack, it means we are
13110 emitting debug info for a template argument pack element.
13111 In other terms, ARG is a template argument pack element.
13112 In that case, we don't emit any DW_AT_name attribute for
13116 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13118 add_AT_string (tmpl_die, DW_AT_name, name);
13121 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13123 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13124 TMPL_DIE should have a child DW_AT_type attribute that is set
13125 to the type of the argument to PARM, which is ARG.
13126 If PARM is a type generic parameter, TMPL_DIE should have a
13127 child DW_AT_type that is set to ARG. */
13128 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13129 add_type_attribute (tmpl_die, tmpl_type, 0,
13130 TREE_THIS_VOLATILE (tmpl_type),
13135 /* So TMPL_DIE is a DIE representing a
13136 a generic generic template parameter, a.k.a template template
13137 parameter in C++ and arg is a template. */
13139 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13140 to the name of the argument. */
13141 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13143 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13146 if (TREE_CODE (parm) == PARM_DECL)
13147 /* So PARM is a non-type generic parameter.
13148 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13149 attribute of TMPL_DIE which value represents the value
13151 We must be careful here:
13152 The value of ARG might reference some function decls.
13153 We might currently be emitting debug info for a generic
13154 type and types are emitted before function decls, we don't
13155 know if the function decls referenced by ARG will actually be
13156 emitted after cgraph computations.
13157 So must defer the generation of the DW_AT_const_value to
13158 after cgraph is ready. */
13159 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13165 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13166 PARM_PACK must be a template parameter pack. The returned DIE
13167 will be child DIE of PARENT_DIE. */
13170 template_parameter_pack_die (tree parm_pack,
13171 tree parm_pack_args,
13172 dw_die_ref parent_die)
13177 gcc_assert (parent_die && parm_pack);
13179 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13180 add_name_and_src_coords_attributes (die, parm_pack);
13181 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13182 generic_parameter_die (parm_pack,
13183 TREE_VEC_ELT (parm_pack_args, j),
13184 false /* Don't emit DW_AT_name */,
13189 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13190 an enumerated type. */
13193 type_is_enum (const_tree type)
13195 return TREE_CODE (type) == ENUMERAL_TYPE;
13198 /* Return the DBX register number described by a given RTL node. */
13200 static unsigned int
13201 dbx_reg_number (const_rtx rtl)
13203 unsigned regno = REGNO (rtl);
13205 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13207 #ifdef LEAF_REG_REMAP
13208 if (current_function_uses_only_leaf_regs)
13210 int leaf_reg = LEAF_REG_REMAP (regno);
13211 if (leaf_reg != -1)
13212 regno = (unsigned) leaf_reg;
13216 return DBX_REGISTER_NUMBER (regno);
13219 /* Optionally add a DW_OP_piece term to a location description expression.
13220 DW_OP_piece is only added if the location description expression already
13221 doesn't end with DW_OP_piece. */
13224 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13226 dw_loc_descr_ref loc;
13228 if (*list_head != NULL)
13230 /* Find the end of the chain. */
13231 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13234 if (loc->dw_loc_opc != DW_OP_piece)
13235 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13239 /* Return a location descriptor that designates a machine register or
13240 zero if there is none. */
13242 static dw_loc_descr_ref
13243 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13247 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13250 /* We only use "frame base" when we're sure we're talking about the
13251 post-prologue local stack frame. We do this by *not* running
13252 register elimination until this point, and recognizing the special
13253 argument pointer and soft frame pointer rtx's.
13254 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13255 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13256 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13258 dw_loc_descr_ref result = NULL;
13260 if (dwarf_version >= 4 || !dwarf_strict)
13262 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13264 add_loc_descr (&result,
13265 new_loc_descr (DW_OP_stack_value, 0, 0));
13270 regs = targetm.dwarf_register_span (rtl);
13272 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13273 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13275 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13278 /* Return a location descriptor that designates a machine register for
13279 a given hard register number. */
13281 static dw_loc_descr_ref
13282 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13284 dw_loc_descr_ref reg_loc_descr;
13288 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13290 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13292 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13293 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13295 return reg_loc_descr;
13298 /* Given an RTL of a register, return a location descriptor that
13299 designates a value that spans more than one register. */
13301 static dw_loc_descr_ref
13302 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13303 enum var_init_status initialized)
13305 int nregs, size, i;
13307 dw_loc_descr_ref loc_result = NULL;
13310 #ifdef LEAF_REG_REMAP
13311 if (current_function_uses_only_leaf_regs)
13313 int leaf_reg = LEAF_REG_REMAP (reg);
13314 if (leaf_reg != -1)
13315 reg = (unsigned) leaf_reg;
13318 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13319 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13321 /* Simple, contiguous registers. */
13322 if (regs == NULL_RTX)
13324 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13329 dw_loc_descr_ref t;
13331 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13332 VAR_INIT_STATUS_INITIALIZED);
13333 add_loc_descr (&loc_result, t);
13334 add_loc_descr_op_piece (&loc_result, size);
13340 /* Now onto stupid register sets in non contiguous locations. */
13342 gcc_assert (GET_CODE (regs) == PARALLEL);
13344 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13347 for (i = 0; i < XVECLEN (regs, 0); ++i)
13349 dw_loc_descr_ref t;
13351 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13352 VAR_INIT_STATUS_INITIALIZED);
13353 add_loc_descr (&loc_result, t);
13354 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13355 add_loc_descr_op_piece (&loc_result, size);
13358 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13359 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13363 /* Return a location descriptor that designates a constant. */
13365 static dw_loc_descr_ref
13366 int_loc_descriptor (HOST_WIDE_INT i)
13368 enum dwarf_location_atom op;
13370 /* Pick the smallest representation of a constant, rather than just
13371 defaulting to the LEB encoding. */
13375 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13376 else if (i <= 0xff)
13377 op = DW_OP_const1u;
13378 else if (i <= 0xffff)
13379 op = DW_OP_const2u;
13380 else if (HOST_BITS_PER_WIDE_INT == 32
13381 || i <= 0xffffffff)
13382 op = DW_OP_const4u;
13389 op = DW_OP_const1s;
13390 else if (i >= -0x8000)
13391 op = DW_OP_const2s;
13392 else if (HOST_BITS_PER_WIDE_INT == 32
13393 || i >= -0x80000000)
13394 op = DW_OP_const4s;
13399 return new_loc_descr (op, i, 0);
13402 /* Return loc description representing "address" of integer value.
13403 This can appear only as toplevel expression. */
13405 static dw_loc_descr_ref
13406 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13409 dw_loc_descr_ref loc_result = NULL;
13411 if (!(dwarf_version >= 4 || !dwarf_strict))
13418 else if (i <= 0xff)
13420 else if (i <= 0xffff)
13422 else if (HOST_BITS_PER_WIDE_INT == 32
13423 || i <= 0xffffffff)
13426 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13432 else if (i >= -0x8000)
13434 else if (HOST_BITS_PER_WIDE_INT == 32
13435 || i >= -0x80000000)
13438 litsize = 1 + size_of_sleb128 (i);
13440 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13441 is more compact. For DW_OP_stack_value we need:
13442 litsize + 1 (DW_OP_stack_value)
13443 and for DW_OP_implicit_value:
13444 1 (DW_OP_implicit_value) + 1 (length) + size. */
13445 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13447 loc_result = int_loc_descriptor (i);
13448 add_loc_descr (&loc_result,
13449 new_loc_descr (DW_OP_stack_value, 0, 0));
13453 loc_result = new_loc_descr (DW_OP_implicit_value,
13455 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13456 loc_result->dw_loc_oprnd2.v.val_int = i;
13460 /* Return a location descriptor that designates a base+offset location. */
13462 static dw_loc_descr_ref
13463 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13464 enum var_init_status initialized)
13466 unsigned int regno;
13467 dw_loc_descr_ref result;
13468 dw_fde_ref fde = current_fde ();
13470 /* We only use "frame base" when we're sure we're talking about the
13471 post-prologue local stack frame. We do this by *not* running
13472 register elimination until this point, and recognizing the special
13473 argument pointer and soft frame pointer rtx's. */
13474 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13476 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13480 if (GET_CODE (elim) == PLUS)
13482 offset += INTVAL (XEXP (elim, 1));
13483 elim = XEXP (elim, 0);
13485 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13486 && (elim == hard_frame_pointer_rtx
13487 || elim == stack_pointer_rtx))
13488 || elim == (frame_pointer_needed
13489 ? hard_frame_pointer_rtx
13490 : stack_pointer_rtx));
13492 /* If drap register is used to align stack, use frame
13493 pointer + offset to access stack variables. If stack
13494 is aligned without drap, use stack pointer + offset to
13495 access stack variables. */
13496 if (crtl->stack_realign_tried
13497 && reg == frame_pointer_rtx)
13500 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13501 ? HARD_FRAME_POINTER_REGNUM
13502 : STACK_POINTER_REGNUM);
13503 return new_reg_loc_descr (base_reg, offset);
13506 offset += frame_pointer_fb_offset;
13507 return new_loc_descr (DW_OP_fbreg, offset, 0);
13512 && (fde->drap_reg == REGNO (reg)
13513 || fde->vdrap_reg == REGNO (reg)))
13515 /* Use cfa+offset to represent the location of arguments passed
13516 on the stack when drap is used to align stack.
13517 Only do this when not optimizing, for optimized code var-tracking
13518 is supposed to track where the arguments live and the register
13519 used as vdrap or drap in some spot might be used for something
13520 else in other part of the routine. */
13521 return new_loc_descr (DW_OP_fbreg, offset, 0);
13524 regno = dbx_reg_number (reg);
13526 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13529 result = new_loc_descr (DW_OP_bregx, regno, offset);
13531 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13532 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13537 /* Return true if this RTL expression describes a base+offset calculation. */
13540 is_based_loc (const_rtx rtl)
13542 return (GET_CODE (rtl) == PLUS
13543 && ((REG_P (XEXP (rtl, 0))
13544 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13545 && CONST_INT_P (XEXP (rtl, 1)))));
13548 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13551 static dw_loc_descr_ref
13552 tls_mem_loc_descriptor (rtx mem)
13555 dw_loc_descr_ref loc_result;
13557 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13560 base = get_base_address (MEM_EXPR (mem));
13562 || TREE_CODE (base) != VAR_DECL
13563 || !DECL_THREAD_LOCAL_P (base))
13566 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13567 if (loc_result == NULL)
13570 if (INTVAL (MEM_OFFSET (mem)))
13571 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13576 /* Output debug info about reason why we failed to expand expression as dwarf
13580 expansion_failed (tree expr, rtx rtl, char const *reason)
13582 if (dump_file && (dump_flags & TDF_DETAILS))
13584 fprintf (dump_file, "Failed to expand as dwarf: ");
13586 print_generic_expr (dump_file, expr, dump_flags);
13589 fprintf (dump_file, "\n");
13590 print_rtl (dump_file, rtl);
13592 fprintf (dump_file, "\nReason: %s\n", reason);
13596 /* Helper function for const_ok_for_output, called either directly
13597 or via for_each_rtx. */
13600 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13604 if (GET_CODE (rtl) == UNSPEC)
13606 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13607 we can't express it in the debug info. */
13608 #ifdef ENABLE_CHECKING
13609 /* Don't complain about TLS UNSPECs, those are just too hard to
13611 if (XVECLEN (rtl, 0) != 1
13612 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13613 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13614 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13615 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13616 inform (current_function_decl
13617 ? DECL_SOURCE_LOCATION (current_function_decl)
13618 : UNKNOWN_LOCATION,
13619 "non-delegitimized UNSPEC %d found in variable location",
13622 expansion_failed (NULL_TREE, rtl,
13623 "UNSPEC hasn't been delegitimized.\n");
13627 if (GET_CODE (rtl) != SYMBOL_REF)
13630 if (CONSTANT_POOL_ADDRESS_P (rtl))
13633 get_pool_constant_mark (rtl, &marked);
13634 /* If all references to this pool constant were optimized away,
13635 it was not output and thus we can't represent it. */
13638 expansion_failed (NULL_TREE, rtl,
13639 "Constant was removed from constant pool.\n");
13644 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13647 /* Avoid references to external symbols in debug info, on several targets
13648 the linker might even refuse to link when linking a shared library,
13649 and in many other cases the relocations for .debug_info/.debug_loc are
13650 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13651 to be defined within the same shared library or executable are fine. */
13652 if (SYMBOL_REF_EXTERNAL_P (rtl))
13654 tree decl = SYMBOL_REF_DECL (rtl);
13656 if (decl == NULL || !targetm.binds_local_p (decl))
13658 expansion_failed (NULL_TREE, rtl,
13659 "Symbol not defined in current TU.\n");
13667 /* Return true if constant RTL can be emitted in DW_OP_addr or
13668 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13669 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13672 const_ok_for_output (rtx rtl)
13674 if (GET_CODE (rtl) == SYMBOL_REF)
13675 return const_ok_for_output_1 (&rtl, NULL) == 0;
13677 if (GET_CODE (rtl) == CONST)
13678 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13683 /* The following routine converts the RTL for a variable or parameter
13684 (resident in memory) into an equivalent Dwarf representation of a
13685 mechanism for getting the address of that same variable onto the top of a
13686 hypothetical "address evaluation" stack.
13688 When creating memory location descriptors, we are effectively transforming
13689 the RTL for a memory-resident object into its Dwarf postfix expression
13690 equivalent. This routine recursively descends an RTL tree, turning
13691 it into Dwarf postfix code as it goes.
13693 MODE is the mode of the memory reference, needed to handle some
13694 autoincrement addressing modes.
13696 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13697 location list for RTL.
13699 Return 0 if we can't represent the location. */
13701 static dw_loc_descr_ref
13702 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13703 enum var_init_status initialized)
13705 dw_loc_descr_ref mem_loc_result = NULL;
13706 enum dwarf_location_atom op;
13707 dw_loc_descr_ref op0, op1;
13709 /* Note that for a dynamically sized array, the location we will generate a
13710 description of here will be the lowest numbered location which is
13711 actually within the array. That's *not* necessarily the same as the
13712 zeroth element of the array. */
13714 rtl = targetm.delegitimize_address (rtl);
13716 switch (GET_CODE (rtl))
13721 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13724 /* The case of a subreg may arise when we have a local (register)
13725 variable or a formal (register) parameter which doesn't quite fill
13726 up an entire register. For now, just assume that it is
13727 legitimate to make the Dwarf info refer to the whole register which
13728 contains the given subreg. */
13729 if (!subreg_lowpart_p (rtl))
13731 rtl = SUBREG_REG (rtl);
13732 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13734 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13736 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13740 /* Whenever a register number forms a part of the description of the
13741 method for calculating the (dynamic) address of a memory resident
13742 object, DWARF rules require the register number be referred to as
13743 a "base register". This distinction is not based in any way upon
13744 what category of register the hardware believes the given register
13745 belongs to. This is strictly DWARF terminology we're dealing with
13746 here. Note that in cases where the location of a memory-resident
13747 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13748 OP_CONST (0)) the actual DWARF location descriptor that we generate
13749 may just be OP_BASEREG (basereg). This may look deceptively like
13750 the object in question was allocated to a register (rather than in
13751 memory) so DWARF consumers need to be aware of the subtle
13752 distinction between OP_REG and OP_BASEREG. */
13753 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13754 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13755 else if (stack_realign_drap
13757 && crtl->args.internal_arg_pointer == rtl
13758 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13760 /* If RTL is internal_arg_pointer, which has been optimized
13761 out, use DRAP instead. */
13762 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13763 VAR_INIT_STATUS_INITIALIZED);
13769 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13770 VAR_INIT_STATUS_INITIALIZED);
13775 int shift = DWARF2_ADDR_SIZE
13776 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13777 shift *= BITS_PER_UNIT;
13778 if (GET_CODE (rtl) == SIGN_EXTEND)
13782 mem_loc_result = op0;
13783 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13784 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13785 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13786 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13791 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13792 VAR_INIT_STATUS_INITIALIZED);
13793 if (mem_loc_result == NULL)
13794 mem_loc_result = tls_mem_loc_descriptor (rtl);
13795 if (mem_loc_result != 0)
13797 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13799 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13802 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13803 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13805 add_loc_descr (&mem_loc_result,
13806 new_loc_descr (DW_OP_deref_size,
13807 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13811 rtx new_rtl = avoid_constant_pool_reference (rtl);
13812 if (new_rtl != rtl)
13813 return mem_loc_descriptor (new_rtl, mode, initialized);
13818 rtl = XEXP (rtl, 1);
13820 /* ... fall through ... */
13823 /* Some ports can transform a symbol ref into a label ref, because
13824 the symbol ref is too far away and has to be dumped into a constant
13828 if (GET_CODE (rtl) == SYMBOL_REF
13829 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13831 dw_loc_descr_ref temp;
13833 /* If this is not defined, we have no way to emit the data. */
13834 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13837 /* We used to emit DW_OP_addr here, but that's wrong, since
13838 DW_OP_addr should be relocated by the debug info consumer,
13839 while DW_OP_GNU_push_tls_address operand should not. */
13840 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13841 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13842 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13843 temp->dw_loc_oprnd1.v.val_addr = rtl;
13844 temp->dtprel = true;
13846 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13847 add_loc_descr (&mem_loc_result, temp);
13852 if (!const_ok_for_output (rtl))
13856 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13857 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13858 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13859 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13865 case DEBUG_IMPLICIT_PTR:
13866 expansion_failed (NULL_TREE, rtl,
13867 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13873 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
13874 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
13875 if (REG_P (ENTRY_VALUE_EXP (rtl)))
13876 mem_loc_result->dw_loc_oprnd1.v.val_loc
13877 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
13878 VAR_INIT_STATUS_INITIALIZED);
13879 else if (MEM_P (ENTRY_VALUE_EXP (rtl)) && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
13881 dw_loc_descr_ref ref
13882 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), GET_MODE (rtl),
13883 VAR_INIT_STATUS_INITIALIZED);
13886 mem_loc_result->dw_loc_oprnd1.v.val_loc = ref;
13889 gcc_unreachable ();
13890 return mem_loc_result;
13893 /* Extract the PLUS expression nested inside and fall into
13894 PLUS code below. */
13895 rtl = XEXP (rtl, 1);
13900 /* Turn these into a PLUS expression and fall into the PLUS code
13902 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13903 GEN_INT (GET_CODE (rtl) == PRE_INC
13904 ? GET_MODE_UNIT_SIZE (mode)
13905 : -GET_MODE_UNIT_SIZE (mode)));
13907 /* ... fall through ... */
13911 if (is_based_loc (rtl))
13912 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13913 INTVAL (XEXP (rtl, 1)),
13914 VAR_INIT_STATUS_INITIALIZED);
13917 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13918 VAR_INIT_STATUS_INITIALIZED);
13919 if (mem_loc_result == 0)
13922 if (CONST_INT_P (XEXP (rtl, 1)))
13923 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13926 dw_loc_descr_ref mem_loc_result2
13927 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13928 VAR_INIT_STATUS_INITIALIZED);
13929 if (mem_loc_result2 == 0)
13931 add_loc_descr (&mem_loc_result, mem_loc_result2);
13932 add_loc_descr (&mem_loc_result,
13933 new_loc_descr (DW_OP_plus, 0, 0));
13938 /* If a pseudo-reg is optimized away, it is possible for it to
13939 be replaced with a MEM containing a multiply or shift. */
13981 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13982 VAR_INIT_STATUS_INITIALIZED);
13983 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13984 VAR_INIT_STATUS_INITIALIZED);
13986 if (op0 == 0 || op1 == 0)
13989 mem_loc_result = op0;
13990 add_loc_descr (&mem_loc_result, op1);
13991 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13995 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13996 VAR_INIT_STATUS_INITIALIZED);
13997 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13998 VAR_INIT_STATUS_INITIALIZED);
14000 if (op0 == 0 || op1 == 0)
14003 mem_loc_result = op0;
14004 add_loc_descr (&mem_loc_result, op1);
14005 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14006 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14007 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
14008 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14009 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
14025 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14026 VAR_INIT_STATUS_INITIALIZED);
14031 mem_loc_result = op0;
14032 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14036 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
14064 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14065 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14069 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14071 if (op_mode == VOIDmode)
14072 op_mode = GET_MODE (XEXP (rtl, 1));
14073 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14076 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14077 VAR_INIT_STATUS_INITIALIZED);
14078 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14079 VAR_INIT_STATUS_INITIALIZED);
14081 if (op0 == 0 || op1 == 0)
14084 if (op_mode != VOIDmode
14085 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14087 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
14088 shift *= BITS_PER_UNIT;
14089 /* For eq/ne, if the operands are known to be zero-extended,
14090 there is no need to do the fancy shifting up. */
14091 if (op == DW_OP_eq || op == DW_OP_ne)
14093 dw_loc_descr_ref last0, last1;
14095 last0->dw_loc_next != NULL;
14096 last0 = last0->dw_loc_next)
14099 last1->dw_loc_next != NULL;
14100 last1 = last1->dw_loc_next)
14102 /* deref_size zero extends, and for constants we can check
14103 whether they are zero extended or not. */
14104 if (((last0->dw_loc_opc == DW_OP_deref_size
14105 && last0->dw_loc_oprnd1.v.val_int
14106 <= GET_MODE_SIZE (op_mode))
14107 || (CONST_INT_P (XEXP (rtl, 0))
14108 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14109 == (INTVAL (XEXP (rtl, 0))
14110 & GET_MODE_MASK (op_mode))))
14111 && ((last1->dw_loc_opc == DW_OP_deref_size
14112 && last1->dw_loc_oprnd1.v.val_int
14113 <= GET_MODE_SIZE (op_mode))
14114 || (CONST_INT_P (XEXP (rtl, 1))
14115 && (unsigned HOST_WIDE_INT)
14116 INTVAL (XEXP (rtl, 1))
14117 == (INTVAL (XEXP (rtl, 1))
14118 & GET_MODE_MASK (op_mode)))))
14121 add_loc_descr (&op0, int_loc_descriptor (shift));
14122 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14123 if (CONST_INT_P (XEXP (rtl, 1)))
14124 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14127 add_loc_descr (&op1, int_loc_descriptor (shift));
14128 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14134 mem_loc_result = op0;
14135 add_loc_descr (&mem_loc_result, op1);
14136 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14137 if (STORE_FLAG_VALUE != 1)
14139 add_loc_descr (&mem_loc_result,
14140 int_loc_descriptor (STORE_FLAG_VALUE));
14141 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14162 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14163 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14167 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14169 if (op_mode == VOIDmode)
14170 op_mode = GET_MODE (XEXP (rtl, 1));
14171 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14174 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14175 VAR_INIT_STATUS_INITIALIZED);
14176 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14177 VAR_INIT_STATUS_INITIALIZED);
14179 if (op0 == 0 || op1 == 0)
14182 if (op_mode != VOIDmode
14183 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14185 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14186 dw_loc_descr_ref last0, last1;
14188 last0->dw_loc_next != NULL;
14189 last0 = last0->dw_loc_next)
14192 last1->dw_loc_next != NULL;
14193 last1 = last1->dw_loc_next)
14195 if (CONST_INT_P (XEXP (rtl, 0)))
14196 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14197 /* deref_size zero extends, so no need to mask it again. */
14198 else if (last0->dw_loc_opc != DW_OP_deref_size
14199 || last0->dw_loc_oprnd1.v.val_int
14200 > GET_MODE_SIZE (op_mode))
14202 add_loc_descr (&op0, int_loc_descriptor (mask));
14203 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14205 if (CONST_INT_P (XEXP (rtl, 1)))
14206 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14207 /* deref_size zero extends, so no need to mask it again. */
14208 else if (last1->dw_loc_opc != DW_OP_deref_size
14209 || last1->dw_loc_oprnd1.v.val_int
14210 > GET_MODE_SIZE (op_mode))
14212 add_loc_descr (&op1, int_loc_descriptor (mask));
14213 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14218 HOST_WIDE_INT bias = 1;
14219 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14220 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14221 if (CONST_INT_P (XEXP (rtl, 1)))
14222 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14223 + INTVAL (XEXP (rtl, 1)));
14225 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14235 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14236 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14237 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14240 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14241 VAR_INIT_STATUS_INITIALIZED);
14242 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14243 VAR_INIT_STATUS_INITIALIZED);
14245 if (op0 == 0 || op1 == 0)
14248 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14249 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14250 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14251 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14253 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14255 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14256 add_loc_descr (&op0, int_loc_descriptor (mask));
14257 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14258 add_loc_descr (&op1, int_loc_descriptor (mask));
14259 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14263 HOST_WIDE_INT bias = 1;
14264 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14265 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14266 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14269 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14271 int shift = DWARF2_ADDR_SIZE
14272 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14273 shift *= BITS_PER_UNIT;
14274 add_loc_descr (&op0, int_loc_descriptor (shift));
14275 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14276 add_loc_descr (&op1, int_loc_descriptor (shift));
14277 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14280 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14284 mem_loc_result = op0;
14285 add_loc_descr (&mem_loc_result, op1);
14286 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14288 dw_loc_descr_ref bra_node, drop_node;
14290 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14291 add_loc_descr (&mem_loc_result, bra_node);
14292 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14293 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14294 add_loc_descr (&mem_loc_result, drop_node);
14295 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14296 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14302 if (CONST_INT_P (XEXP (rtl, 1))
14303 && CONST_INT_P (XEXP (rtl, 2))
14304 && ((unsigned) INTVAL (XEXP (rtl, 1))
14305 + (unsigned) INTVAL (XEXP (rtl, 2))
14306 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14307 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14308 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14311 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14312 VAR_INIT_STATUS_INITIALIZED);
14315 if (GET_CODE (rtl) == SIGN_EXTRACT)
14319 mem_loc_result = op0;
14320 size = INTVAL (XEXP (rtl, 1));
14321 shift = INTVAL (XEXP (rtl, 2));
14322 if (BITS_BIG_ENDIAN)
14323 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14325 if (shift + size != (int) DWARF2_ADDR_SIZE)
14327 add_loc_descr (&mem_loc_result,
14328 int_loc_descriptor (DWARF2_ADDR_SIZE
14330 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14332 if (size != (int) DWARF2_ADDR_SIZE)
14334 add_loc_descr (&mem_loc_result,
14335 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14336 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14343 dw_loc_descr_ref op2, bra_node, drop_node;
14344 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14345 VAR_INIT_STATUS_INITIALIZED);
14346 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14347 VAR_INIT_STATUS_INITIALIZED);
14348 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
14349 VAR_INIT_STATUS_INITIALIZED);
14350 if (op0 == NULL || op1 == NULL || op2 == NULL)
14353 mem_loc_result = op1;
14354 add_loc_descr (&mem_loc_result, op2);
14355 add_loc_descr (&mem_loc_result, op0);
14356 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14357 add_loc_descr (&mem_loc_result, bra_node);
14358 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14359 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14360 add_loc_descr (&mem_loc_result, drop_node);
14361 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14362 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14370 /* In theory, we could implement the above. */
14371 /* DWARF cannot represent the unsigned compare operations
14398 case FLOAT_TRUNCATE:
14400 case UNSIGNED_FLOAT:
14403 case FRACT_CONVERT:
14404 case UNSIGNED_FRACT_CONVERT:
14406 case UNSIGNED_SAT_FRACT:
14418 case VEC_DUPLICATE:
14421 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14422 can't express it in the debug info. This can happen e.g. with some
14427 resolve_one_addr (&rtl, NULL);
14431 #ifdef ENABLE_CHECKING
14432 print_rtl (stderr, rtl);
14433 gcc_unreachable ();
14439 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14440 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14442 return mem_loc_result;
14445 /* Return a descriptor that describes the concatenation of two locations.
14446 This is typically a complex variable. */
14448 static dw_loc_descr_ref
14449 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14451 dw_loc_descr_ref cc_loc_result = NULL;
14452 dw_loc_descr_ref x0_ref
14453 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14454 dw_loc_descr_ref x1_ref
14455 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14457 if (x0_ref == 0 || x1_ref == 0)
14460 cc_loc_result = x0_ref;
14461 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14463 add_loc_descr (&cc_loc_result, x1_ref);
14464 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14466 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14467 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14469 return cc_loc_result;
14472 /* Return a descriptor that describes the concatenation of N
14475 static dw_loc_descr_ref
14476 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14479 dw_loc_descr_ref cc_loc_result = NULL;
14480 unsigned int n = XVECLEN (concatn, 0);
14482 for (i = 0; i < n; ++i)
14484 dw_loc_descr_ref ref;
14485 rtx x = XVECEXP (concatn, 0, i);
14487 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14491 add_loc_descr (&cc_loc_result, ref);
14492 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14495 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14496 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14498 return cc_loc_result;
14501 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14502 for DEBUG_IMPLICIT_PTR RTL. */
14504 static dw_loc_descr_ref
14505 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14507 dw_loc_descr_ref ret;
14512 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14513 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14514 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14515 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14516 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14517 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14520 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14521 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14522 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14526 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14527 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14532 /* Output a proper Dwarf location descriptor for a variable or parameter
14533 which is either allocated in a register or in a memory location. For a
14534 register, we just generate an OP_REG and the register number. For a
14535 memory location we provide a Dwarf postfix expression describing how to
14536 generate the (dynamic) address of the object onto the address stack.
14538 MODE is mode of the decl if this loc_descriptor is going to be used in
14539 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14540 allowed, VOIDmode otherwise.
14542 If we don't know how to describe it, return 0. */
14544 static dw_loc_descr_ref
14545 loc_descriptor (rtx rtl, enum machine_mode mode,
14546 enum var_init_status initialized)
14548 dw_loc_descr_ref loc_result = NULL;
14550 switch (GET_CODE (rtl))
14553 /* The case of a subreg may arise when we have a local (register)
14554 variable or a formal (register) parameter which doesn't quite fill
14555 up an entire register. For now, just assume that it is
14556 legitimate to make the Dwarf info refer to the whole register which
14557 contains the given subreg. */
14558 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14562 loc_result = reg_loc_descriptor (rtl, initialized);
14566 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14568 if (loc_result == NULL)
14569 loc_result = tls_mem_loc_descriptor (rtl);
14570 if (loc_result == NULL)
14572 rtx new_rtl = avoid_constant_pool_reference (rtl);
14573 if (new_rtl != rtl)
14574 loc_result = loc_descriptor (new_rtl, mode, initialized);
14579 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14584 loc_result = concatn_loc_descriptor (rtl, initialized);
14589 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14591 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14592 if (GET_CODE (loc) == EXPR_LIST)
14593 loc = XEXP (loc, 0);
14594 loc_result = loc_descriptor (loc, mode, initialized);
14598 rtl = XEXP (rtl, 1);
14603 rtvec par_elems = XVEC (rtl, 0);
14604 int num_elem = GET_NUM_ELEM (par_elems);
14605 enum machine_mode mode;
14608 /* Create the first one, so we have something to add to. */
14609 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14610 VOIDmode, initialized);
14611 if (loc_result == NULL)
14613 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14614 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14615 for (i = 1; i < num_elem; i++)
14617 dw_loc_descr_ref temp;
14619 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14620 VOIDmode, initialized);
14623 add_loc_descr (&loc_result, temp);
14624 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14625 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14631 if (mode != VOIDmode && mode != BLKmode)
14632 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14637 if (mode == VOIDmode)
14638 mode = GET_MODE (rtl);
14640 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14642 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14644 /* Note that a CONST_DOUBLE rtx could represent either an integer
14645 or a floating-point constant. A CONST_DOUBLE is used whenever
14646 the constant requires more than one word in order to be
14647 adequately represented. We output CONST_DOUBLEs as blocks. */
14648 loc_result = new_loc_descr (DW_OP_implicit_value,
14649 GET_MODE_SIZE (mode), 0);
14650 if (SCALAR_FLOAT_MODE_P (mode))
14652 unsigned int length = GET_MODE_SIZE (mode);
14653 unsigned char *array
14654 = (unsigned char*) ggc_alloc_atomic (length);
14656 insert_float (rtl, array);
14657 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14658 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14659 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14660 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14664 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14665 loc_result->dw_loc_oprnd2.v.val_double
14666 = rtx_to_double_int (rtl);
14672 if (mode == VOIDmode)
14673 mode = GET_MODE (rtl);
14675 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14677 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14678 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14679 unsigned char *array = (unsigned char *)
14680 ggc_alloc_atomic (length * elt_size);
14684 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14685 switch (GET_MODE_CLASS (mode))
14687 case MODE_VECTOR_INT:
14688 for (i = 0, p = array; i < length; i++, p += elt_size)
14690 rtx elt = CONST_VECTOR_ELT (rtl, i);
14691 double_int val = rtx_to_double_int (elt);
14693 if (elt_size <= sizeof (HOST_WIDE_INT))
14694 insert_int (double_int_to_shwi (val), elt_size, p);
14697 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14698 insert_double (val, p);
14703 case MODE_VECTOR_FLOAT:
14704 for (i = 0, p = array; i < length; i++, p += elt_size)
14706 rtx elt = CONST_VECTOR_ELT (rtl, i);
14707 insert_float (elt, p);
14712 gcc_unreachable ();
14715 loc_result = new_loc_descr (DW_OP_implicit_value,
14716 length * elt_size, 0);
14717 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14718 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14719 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14720 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14725 if (mode == VOIDmode
14726 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14727 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14728 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14730 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14735 if (!const_ok_for_output (rtl))
14738 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14739 && (dwarf_version >= 4 || !dwarf_strict))
14741 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14742 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14743 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14744 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14745 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14749 case DEBUG_IMPLICIT_PTR:
14750 loc_result = implicit_ptr_descriptor (rtl, 0);
14754 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14755 && CONST_INT_P (XEXP (rtl, 1)))
14758 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14763 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14764 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14765 && (dwarf_version >= 4 || !dwarf_strict))
14767 /* Value expression. */
14768 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14770 add_loc_descr (&loc_result,
14771 new_loc_descr (DW_OP_stack_value, 0, 0));
14779 /* We need to figure out what section we should use as the base for the
14780 address ranges where a given location is valid.
14781 1. If this particular DECL has a section associated with it, use that.
14782 2. If this function has a section associated with it, use that.
14783 3. Otherwise, use the text section.
14784 XXX: If you split a variable across multiple sections, we won't notice. */
14786 static const char *
14787 secname_for_decl (const_tree decl)
14789 const char *secname;
14791 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14793 tree sectree = DECL_SECTION_NAME (decl);
14794 secname = TREE_STRING_POINTER (sectree);
14796 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14798 tree sectree = DECL_SECTION_NAME (current_function_decl);
14799 secname = TREE_STRING_POINTER (sectree);
14801 else if (cfun && in_cold_section_p)
14802 secname = crtl->subsections.cold_section_label;
14804 secname = text_section_label;
14809 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14812 decl_by_reference_p (tree decl)
14814 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14815 || TREE_CODE (decl) == VAR_DECL)
14816 && DECL_BY_REFERENCE (decl));
14819 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14822 static dw_loc_descr_ref
14823 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14824 enum var_init_status initialized)
14826 int have_address = 0;
14827 dw_loc_descr_ref descr;
14828 enum machine_mode mode;
14830 if (want_address != 2)
14832 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14834 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14836 varloc = PAT_VAR_LOCATION_LOC (varloc);
14837 if (GET_CODE (varloc) == EXPR_LIST)
14838 varloc = XEXP (varloc, 0);
14839 mode = GET_MODE (varloc);
14840 if (MEM_P (varloc))
14842 rtx addr = XEXP (varloc, 0);
14843 descr = mem_loc_descriptor (addr, mode, initialized);
14848 rtx x = avoid_constant_pool_reference (varloc);
14850 descr = mem_loc_descriptor (x, mode, initialized);
14854 descr = mem_loc_descriptor (varloc, mode, initialized);
14861 if (GET_CODE (varloc) == VAR_LOCATION)
14862 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14864 mode = DECL_MODE (loc);
14865 descr = loc_descriptor (varloc, mode, initialized);
14872 if (want_address == 2 && !have_address
14873 && (dwarf_version >= 4 || !dwarf_strict))
14875 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14877 expansion_failed (loc, NULL_RTX,
14878 "DWARF address size mismatch");
14881 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14884 /* Show if we can't fill the request for an address. */
14885 if (want_address && !have_address)
14887 expansion_failed (loc, NULL_RTX,
14888 "Want address and only have value");
14892 /* If we've got an address and don't want one, dereference. */
14893 if (!want_address && have_address)
14895 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14896 enum dwarf_location_atom op;
14898 if (size > DWARF2_ADDR_SIZE || size == -1)
14900 expansion_failed (loc, NULL_RTX,
14901 "DWARF address size mismatch");
14904 else if (size == DWARF2_ADDR_SIZE)
14907 op = DW_OP_deref_size;
14909 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14915 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14916 if it is not possible. */
14918 static dw_loc_descr_ref
14919 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14921 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14922 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14923 else if (dwarf_version >= 3 || !dwarf_strict)
14924 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14929 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14930 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14932 static dw_loc_descr_ref
14933 dw_sra_loc_expr (tree decl, rtx loc)
14936 unsigned int padsize = 0;
14937 dw_loc_descr_ref descr, *descr_tail;
14938 unsigned HOST_WIDE_INT decl_size;
14940 enum var_init_status initialized;
14942 if (DECL_SIZE (decl) == NULL
14943 || !host_integerp (DECL_SIZE (decl), 1))
14946 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14948 descr_tail = &descr;
14950 for (p = loc; p; p = XEXP (p, 1))
14952 unsigned int bitsize = decl_piece_bitsize (p);
14953 rtx loc_note = *decl_piece_varloc_ptr (p);
14954 dw_loc_descr_ref cur_descr;
14955 dw_loc_descr_ref *tail, last = NULL;
14956 unsigned int opsize = 0;
14958 if (loc_note == NULL_RTX
14959 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14961 padsize += bitsize;
14964 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14965 varloc = NOTE_VAR_LOCATION (loc_note);
14966 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14967 if (cur_descr == NULL)
14969 padsize += bitsize;
14973 /* Check that cur_descr either doesn't use
14974 DW_OP_*piece operations, or their sum is equal
14975 to bitsize. Otherwise we can't embed it. */
14976 for (tail = &cur_descr; *tail != NULL;
14977 tail = &(*tail)->dw_loc_next)
14978 if ((*tail)->dw_loc_opc == DW_OP_piece)
14980 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14984 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14986 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14990 if (last != NULL && opsize != bitsize)
14992 padsize += bitsize;
14996 /* If there is a hole, add DW_OP_*piece after empty DWARF
14997 expression, which means that those bits are optimized out. */
15000 if (padsize > decl_size)
15002 decl_size -= padsize;
15003 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
15004 if (*descr_tail == NULL)
15006 descr_tail = &(*descr_tail)->dw_loc_next;
15009 *descr_tail = cur_descr;
15011 if (bitsize > decl_size)
15013 decl_size -= bitsize;
15016 HOST_WIDE_INT offset = 0;
15017 if (GET_CODE (varloc) == VAR_LOCATION
15018 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15020 varloc = PAT_VAR_LOCATION_LOC (varloc);
15021 if (GET_CODE (varloc) == EXPR_LIST)
15022 varloc = XEXP (varloc, 0);
15026 if (GET_CODE (varloc) == CONST
15027 || GET_CODE (varloc) == SIGN_EXTEND
15028 || GET_CODE (varloc) == ZERO_EXTEND)
15029 varloc = XEXP (varloc, 0);
15030 else if (GET_CODE (varloc) == SUBREG)
15031 varloc = SUBREG_REG (varloc);
15036 /* DW_OP_bit_size offset should be zero for register
15037 or implicit location descriptions and empty location
15038 descriptions, but for memory addresses needs big endian
15040 if (MEM_P (varloc))
15042 unsigned HOST_WIDE_INT memsize
15043 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
15044 if (memsize != bitsize)
15046 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
15047 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
15049 if (memsize < bitsize)
15051 if (BITS_BIG_ENDIAN)
15052 offset = memsize - bitsize;
15056 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
15057 if (*descr_tail == NULL)
15059 descr_tail = &(*descr_tail)->dw_loc_next;
15063 /* If there were any non-empty expressions, add padding till the end of
15065 if (descr != NULL && decl_size != 0)
15067 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
15068 if (*descr_tail == NULL)
15074 /* Return the dwarf representation of the location list LOC_LIST of
15075 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
15078 static dw_loc_list_ref
15079 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
15081 const char *endname, *secname;
15083 enum var_init_status initialized;
15084 struct var_loc_node *node;
15085 dw_loc_descr_ref descr;
15086 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15087 dw_loc_list_ref list = NULL;
15088 dw_loc_list_ref *listp = &list;
15090 /* Now that we know what section we are using for a base,
15091 actually construct the list of locations.
15092 The first location information is what is passed to the
15093 function that creates the location list, and the remaining
15094 locations just get added on to that list.
15095 Note that we only know the start address for a location
15096 (IE location changes), so to build the range, we use
15097 the range [current location start, next location start].
15098 This means we have to special case the last node, and generate
15099 a range of [last location start, end of function label]. */
15101 secname = secname_for_decl (decl);
15103 for (node = loc_list->first; node; node = node->next)
15104 if (GET_CODE (node->loc) == EXPR_LIST
15105 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
15107 if (GET_CODE (node->loc) == EXPR_LIST)
15109 /* This requires DW_OP_{,bit_}piece, which is not usable
15110 inside DWARF expressions. */
15111 if (want_address != 2)
15113 descr = dw_sra_loc_expr (decl, node->loc);
15119 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15120 varloc = NOTE_VAR_LOCATION (node->loc);
15121 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15125 /* The variable has a location between NODE->LABEL and
15126 NODE->NEXT->LABEL. */
15128 endname = node->next->label;
15129 /* If the variable has a location at the last label
15130 it keeps its location until the end of function. */
15131 else if (!current_function_decl)
15132 endname = text_end_label;
15135 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15136 current_function_funcdef_no);
15137 endname = ggc_strdup (label_id);
15140 *listp = new_loc_list (descr, node->label, endname, secname);
15141 listp = &(*listp)->dw_loc_next;
15145 /* Try to avoid the overhead of a location list emitting a location
15146 expression instead, but only if we didn't have more than one
15147 location entry in the first place. If some entries were not
15148 representable, we don't want to pretend a single entry that was
15149 applies to the entire scope in which the variable is
15151 if (list && loc_list->first->next)
15157 /* Return if the loc_list has only single element and thus can be represented
15158 as location description. */
15161 single_element_loc_list_p (dw_loc_list_ref list)
15163 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15164 return !list->ll_symbol;
15167 /* To each location in list LIST add loc descr REF. */
15170 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15172 dw_loc_descr_ref copy;
15173 add_loc_descr (&list->expr, ref);
15174 list = list->dw_loc_next;
15177 copy = ggc_alloc_dw_loc_descr_node ();
15178 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15179 add_loc_descr (&list->expr, copy);
15180 while (copy->dw_loc_next)
15182 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15183 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15184 copy->dw_loc_next = new_copy;
15187 list = list->dw_loc_next;
15191 /* Given two lists RET and LIST
15192 produce location list that is result of adding expression in LIST
15193 to expression in RET on each possition in program.
15194 Might be destructive on both RET and LIST.
15196 TODO: We handle only simple cases of RET or LIST having at most one
15197 element. General case would inolve sorting the lists in program order
15198 and merging them that will need some additional work.
15199 Adding that will improve quality of debug info especially for SRA-ed
15203 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15212 if (!list->dw_loc_next)
15214 add_loc_descr_to_each (*ret, list->expr);
15217 if (!(*ret)->dw_loc_next)
15219 add_loc_descr_to_each (list, (*ret)->expr);
15223 expansion_failed (NULL_TREE, NULL_RTX,
15224 "Don't know how to merge two non-trivial"
15225 " location lists.\n");
15230 /* LOC is constant expression. Try a luck, look it up in constant
15231 pool and return its loc_descr of its address. */
15233 static dw_loc_descr_ref
15234 cst_pool_loc_descr (tree loc)
15236 /* Get an RTL for this, if something has been emitted. */
15237 rtx rtl = lookup_constant_def (loc);
15238 enum machine_mode mode;
15240 if (!rtl || !MEM_P (rtl))
15245 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15247 /* TODO: We might get more coverage if we was actually delaying expansion
15248 of all expressions till end of compilation when constant pools are fully
15250 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15252 expansion_failed (loc, NULL_RTX,
15253 "CST value in contant pool but not marked.");
15256 mode = GET_MODE (rtl);
15257 rtl = XEXP (rtl, 0);
15258 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15261 /* Return dw_loc_list representing address of addr_expr LOC
15262 by looking for innder INDIRECT_REF expression and turing it
15263 into simple arithmetics. */
15265 static dw_loc_list_ref
15266 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15269 HOST_WIDE_INT bitsize, bitpos, bytepos;
15270 enum machine_mode mode;
15272 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15273 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15275 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15276 &bitsize, &bitpos, &offset, &mode,
15277 &unsignedp, &volatilep, false);
15279 if (bitpos % BITS_PER_UNIT)
15281 expansion_failed (loc, NULL_RTX, "bitfield access");
15284 if (!INDIRECT_REF_P (obj))
15286 expansion_failed (obj,
15287 NULL_RTX, "no indirect ref in inner refrence");
15290 if (!offset && !bitpos)
15291 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15293 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15294 && (dwarf_version >= 4 || !dwarf_strict))
15296 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15301 /* Variable offset. */
15302 list_ret1 = loc_list_from_tree (offset, 0);
15303 if (list_ret1 == 0)
15305 add_loc_list (&list_ret, list_ret1);
15308 add_loc_descr_to_each (list_ret,
15309 new_loc_descr (DW_OP_plus, 0, 0));
15311 bytepos = bitpos / BITS_PER_UNIT;
15313 add_loc_descr_to_each (list_ret,
15314 new_loc_descr (DW_OP_plus_uconst,
15316 else if (bytepos < 0)
15317 loc_list_plus_const (list_ret, bytepos);
15318 add_loc_descr_to_each (list_ret,
15319 new_loc_descr (DW_OP_stack_value, 0, 0));
15325 /* Generate Dwarf location list representing LOC.
15326 If WANT_ADDRESS is false, expression computing LOC will be computed
15327 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15328 if WANT_ADDRESS is 2, expression computing address useable in location
15329 will be returned (i.e. DW_OP_reg can be used
15330 to refer to register values). */
15332 static dw_loc_list_ref
15333 loc_list_from_tree (tree loc, int want_address)
15335 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15336 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15337 int have_address = 0;
15338 enum dwarf_location_atom op;
15340 /* ??? Most of the time we do not take proper care for sign/zero
15341 extending the values properly. Hopefully this won't be a real
15344 switch (TREE_CODE (loc))
15347 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15350 case PLACEHOLDER_EXPR:
15351 /* This case involves extracting fields from an object to determine the
15352 position of other fields. We don't try to encode this here. The
15353 only user of this is Ada, which encodes the needed information using
15354 the names of types. */
15355 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15359 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15360 /* There are no opcodes for these operations. */
15363 case PREINCREMENT_EXPR:
15364 case PREDECREMENT_EXPR:
15365 case POSTINCREMENT_EXPR:
15366 case POSTDECREMENT_EXPR:
15367 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15368 /* There are no opcodes for these operations. */
15372 /* If we already want an address, see if there is INDIRECT_REF inside
15373 e.g. for &this->field. */
15376 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15377 (loc, want_address == 2);
15380 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15381 && (ret = cst_pool_loc_descr (loc)))
15384 /* Otherwise, process the argument and look for the address. */
15385 if (!list_ret && !ret)
15386 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15390 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15396 if (DECL_THREAD_LOCAL_P (loc))
15399 enum dwarf_location_atom first_op;
15400 enum dwarf_location_atom second_op;
15401 bool dtprel = false;
15403 if (targetm.have_tls)
15405 /* If this is not defined, we have no way to emit the
15407 if (!targetm.asm_out.output_dwarf_dtprel)
15410 /* The way DW_OP_GNU_push_tls_address is specified, we
15411 can only look up addresses of objects in the current
15412 module. We used DW_OP_addr as first op, but that's
15413 wrong, because DW_OP_addr is relocated by the debug
15414 info consumer, while DW_OP_GNU_push_tls_address
15415 operand shouldn't be. */
15416 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15418 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15420 second_op = DW_OP_GNU_push_tls_address;
15424 if (!targetm.emutls.debug_form_tls_address
15425 || !(dwarf_version >= 3 || !dwarf_strict))
15427 /* We stuffed the control variable into the DECL_VALUE_EXPR
15428 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15429 no longer appear in gimple code. We used the control
15430 variable in specific so that we could pick it up here. */
15431 loc = DECL_VALUE_EXPR (loc);
15432 first_op = DW_OP_addr;
15433 second_op = DW_OP_form_tls_address;
15436 rtl = rtl_for_decl_location (loc);
15437 if (rtl == NULL_RTX)
15442 rtl = XEXP (rtl, 0);
15443 if (! CONSTANT_P (rtl))
15446 ret = new_loc_descr (first_op, 0, 0);
15447 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15448 ret->dw_loc_oprnd1.v.val_addr = rtl;
15449 ret->dtprel = dtprel;
15451 ret1 = new_loc_descr (second_op, 0, 0);
15452 add_loc_descr (&ret, ret1);
15461 if (DECL_HAS_VALUE_EXPR_P (loc))
15462 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15466 case FUNCTION_DECL:
15469 var_loc_list *loc_list = lookup_decl_loc (loc);
15471 if (loc_list && loc_list->first)
15473 list_ret = dw_loc_list (loc_list, loc, want_address);
15474 have_address = want_address != 0;
15477 rtl = rtl_for_decl_location (loc);
15478 if (rtl == NULL_RTX)
15480 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15483 else if (CONST_INT_P (rtl))
15485 HOST_WIDE_INT val = INTVAL (rtl);
15486 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15487 val &= GET_MODE_MASK (DECL_MODE (loc));
15488 ret = int_loc_descriptor (val);
15490 else if (GET_CODE (rtl) == CONST_STRING)
15492 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15495 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15497 ret = new_loc_descr (DW_OP_addr, 0, 0);
15498 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15499 ret->dw_loc_oprnd1.v.val_addr = rtl;
15503 enum machine_mode mode;
15505 /* Certain constructs can only be represented at top-level. */
15506 if (want_address == 2)
15508 ret = loc_descriptor (rtl, VOIDmode,
15509 VAR_INIT_STATUS_INITIALIZED);
15514 mode = GET_MODE (rtl);
15517 rtl = XEXP (rtl, 0);
15520 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15523 expansion_failed (loc, rtl,
15524 "failed to produce loc descriptor for rtl");
15531 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15535 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15539 case COMPOUND_EXPR:
15540 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15543 case VIEW_CONVERT_EXPR:
15546 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15548 case COMPONENT_REF:
15549 case BIT_FIELD_REF:
15551 case ARRAY_RANGE_REF:
15552 case REALPART_EXPR:
15553 case IMAGPART_EXPR:
15556 HOST_WIDE_INT bitsize, bitpos, bytepos;
15557 enum machine_mode mode;
15559 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15561 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15562 &unsignedp, &volatilep, false);
15564 gcc_assert (obj != loc);
15566 list_ret = loc_list_from_tree (obj,
15568 && !bitpos && !offset ? 2 : 1);
15569 /* TODO: We can extract value of the small expression via shifting even
15570 for nonzero bitpos. */
15573 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15575 expansion_failed (loc, NULL_RTX,
15576 "bitfield access");
15580 if (offset != NULL_TREE)
15582 /* Variable offset. */
15583 list_ret1 = loc_list_from_tree (offset, 0);
15584 if (list_ret1 == 0)
15586 add_loc_list (&list_ret, list_ret1);
15589 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15592 bytepos = bitpos / BITS_PER_UNIT;
15594 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15595 else if (bytepos < 0)
15596 loc_list_plus_const (list_ret, bytepos);
15603 if ((want_address || !host_integerp (loc, 0))
15604 && (ret = cst_pool_loc_descr (loc)))
15606 else if (want_address == 2
15607 && host_integerp (loc, 0)
15608 && (ret = address_of_int_loc_descriptor
15609 (int_size_in_bytes (TREE_TYPE (loc)),
15610 tree_low_cst (loc, 0))))
15612 else if (host_integerp (loc, 0))
15613 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15616 expansion_failed (loc, NULL_RTX,
15617 "Integer operand is not host integer");
15626 if ((ret = cst_pool_loc_descr (loc)))
15629 /* We can construct small constants here using int_loc_descriptor. */
15630 expansion_failed (loc, NULL_RTX,
15631 "constructor or constant not in constant pool");
15634 case TRUTH_AND_EXPR:
15635 case TRUTH_ANDIF_EXPR:
15640 case TRUTH_XOR_EXPR:
15645 case TRUTH_OR_EXPR:
15646 case TRUTH_ORIF_EXPR:
15651 case FLOOR_DIV_EXPR:
15652 case CEIL_DIV_EXPR:
15653 case ROUND_DIV_EXPR:
15654 case TRUNC_DIV_EXPR:
15655 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15664 case FLOOR_MOD_EXPR:
15665 case CEIL_MOD_EXPR:
15666 case ROUND_MOD_EXPR:
15667 case TRUNC_MOD_EXPR:
15668 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15673 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15674 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15675 if (list_ret == 0 || list_ret1 == 0)
15678 add_loc_list (&list_ret, list_ret1);
15681 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15682 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15683 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15684 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15685 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15697 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15700 case POINTER_PLUS_EXPR:
15702 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15704 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15708 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15716 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15723 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15730 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15737 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15752 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15753 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15754 if (list_ret == 0 || list_ret1 == 0)
15757 add_loc_list (&list_ret, list_ret1);
15760 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15763 case TRUTH_NOT_EXPR:
15777 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15781 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15787 const enum tree_code code =
15788 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15790 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15791 build2 (code, integer_type_node,
15792 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15793 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15796 /* ... fall through ... */
15800 dw_loc_descr_ref lhs
15801 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15802 dw_loc_list_ref rhs
15803 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15804 dw_loc_descr_ref bra_node, jump_node, tmp;
15806 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15807 if (list_ret == 0 || lhs == 0 || rhs == 0)
15810 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15811 add_loc_descr_to_each (list_ret, bra_node);
15813 add_loc_list (&list_ret, rhs);
15814 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15815 add_loc_descr_to_each (list_ret, jump_node);
15817 add_loc_descr_to_each (list_ret, lhs);
15818 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15819 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15821 /* ??? Need a node to point the skip at. Use a nop. */
15822 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15823 add_loc_descr_to_each (list_ret, tmp);
15824 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15825 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15829 case FIX_TRUNC_EXPR:
15833 /* Leave front-end specific codes as simply unknown. This comes
15834 up, for instance, with the C STMT_EXPR. */
15835 if ((unsigned int) TREE_CODE (loc)
15836 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15838 expansion_failed (loc, NULL_RTX,
15839 "language specific tree node");
15843 #ifdef ENABLE_CHECKING
15844 /* Otherwise this is a generic code; we should just lists all of
15845 these explicitly. We forgot one. */
15846 gcc_unreachable ();
15848 /* In a release build, we want to degrade gracefully: better to
15849 generate incomplete debugging information than to crash. */
15854 if (!ret && !list_ret)
15857 if (want_address == 2 && !have_address
15858 && (dwarf_version >= 4 || !dwarf_strict))
15860 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15862 expansion_failed (loc, NULL_RTX,
15863 "DWARF address size mismatch");
15867 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15869 add_loc_descr_to_each (list_ret,
15870 new_loc_descr (DW_OP_stack_value, 0, 0));
15873 /* Show if we can't fill the request for an address. */
15874 if (want_address && !have_address)
15876 expansion_failed (loc, NULL_RTX,
15877 "Want address and only have value");
15881 gcc_assert (!ret || !list_ret);
15883 /* If we've got an address and don't want one, dereference. */
15884 if (!want_address && have_address)
15886 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15888 if (size > DWARF2_ADDR_SIZE || size == -1)
15890 expansion_failed (loc, NULL_RTX,
15891 "DWARF address size mismatch");
15894 else if (size == DWARF2_ADDR_SIZE)
15897 op = DW_OP_deref_size;
15900 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15902 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15905 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15910 /* Same as above but return only single location expression. */
15911 static dw_loc_descr_ref
15912 loc_descriptor_from_tree (tree loc, int want_address)
15914 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15917 if (ret->dw_loc_next)
15919 expansion_failed (loc, NULL_RTX,
15920 "Location list where only loc descriptor needed");
15926 /* Given a value, round it up to the lowest multiple of `boundary'
15927 which is not less than the value itself. */
15929 static inline HOST_WIDE_INT
15930 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15932 return (((value + boundary - 1) / boundary) * boundary);
15935 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15936 pointer to the declared type for the relevant field variable, or return
15937 `integer_type_node' if the given node turns out to be an
15938 ERROR_MARK node. */
15941 field_type (const_tree decl)
15945 if (TREE_CODE (decl) == ERROR_MARK)
15946 return integer_type_node;
15948 type = DECL_BIT_FIELD_TYPE (decl);
15949 if (type == NULL_TREE)
15950 type = TREE_TYPE (decl);
15955 /* Given a pointer to a tree node, return the alignment in bits for
15956 it, or else return BITS_PER_WORD if the node actually turns out to
15957 be an ERROR_MARK node. */
15959 static inline unsigned
15960 simple_type_align_in_bits (const_tree type)
15962 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15965 static inline unsigned
15966 simple_decl_align_in_bits (const_tree decl)
15968 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15971 /* Return the result of rounding T up to ALIGN. */
15973 static inline double_int
15974 round_up_to_align (double_int t, unsigned int align)
15976 double_int alignd = uhwi_to_double_int (align);
15977 t = double_int_add (t, alignd);
15978 t = double_int_add (t, double_int_minus_one);
15979 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
15980 t = double_int_mul (t, alignd);
15984 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15985 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15986 or return 0 if we are unable to determine what that offset is, either
15987 because the argument turns out to be a pointer to an ERROR_MARK node, or
15988 because the offset is actually variable. (We can't handle the latter case
15991 static HOST_WIDE_INT
15992 field_byte_offset (const_tree decl)
15994 double_int object_offset_in_bits;
15995 double_int object_offset_in_bytes;
15996 double_int bitpos_int;
15998 if (TREE_CODE (decl) == ERROR_MARK)
16001 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
16003 /* We cannot yet cope with fields whose positions are variable, so
16004 for now, when we see such things, we simply return 0. Someday, we may
16005 be able to handle such cases, but it will be damn difficult. */
16006 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
16009 bitpos_int = tree_to_double_int (bit_position (decl));
16011 #ifdef PCC_BITFIELD_TYPE_MATTERS
16012 if (PCC_BITFIELD_TYPE_MATTERS)
16015 tree field_size_tree;
16016 double_int deepest_bitpos;
16017 double_int field_size_in_bits;
16018 unsigned int type_align_in_bits;
16019 unsigned int decl_align_in_bits;
16020 double_int type_size_in_bits;
16022 type = field_type (decl);
16023 type_size_in_bits = double_int_type_size_in_bits (type);
16024 type_align_in_bits = simple_type_align_in_bits (type);
16026 field_size_tree = DECL_SIZE (decl);
16028 /* The size could be unspecified if there was an error, or for
16029 a flexible array member. */
16030 if (!field_size_tree)
16031 field_size_tree = bitsize_zero_node;
16033 /* If the size of the field is not constant, use the type size. */
16034 if (TREE_CODE (field_size_tree) == INTEGER_CST)
16035 field_size_in_bits = tree_to_double_int (field_size_tree);
16037 field_size_in_bits = type_size_in_bits;
16039 decl_align_in_bits = simple_decl_align_in_bits (decl);
16041 /* The GCC front-end doesn't make any attempt to keep track of the
16042 starting bit offset (relative to the start of the containing
16043 structure type) of the hypothetical "containing object" for a
16044 bit-field. Thus, when computing the byte offset value for the
16045 start of the "containing object" of a bit-field, we must deduce
16046 this information on our own. This can be rather tricky to do in
16047 some cases. For example, handling the following structure type
16048 definition when compiling for an i386/i486 target (which only
16049 aligns long long's to 32-bit boundaries) can be very tricky:
16051 struct S { int field1; long long field2:31; };
16053 Fortunately, there is a simple rule-of-thumb which can be used
16054 in such cases. When compiling for an i386/i486, GCC will
16055 allocate 8 bytes for the structure shown above. It decides to
16056 do this based upon one simple rule for bit-field allocation.
16057 GCC allocates each "containing object" for each bit-field at
16058 the first (i.e. lowest addressed) legitimate alignment boundary
16059 (based upon the required minimum alignment for the declared
16060 type of the field) which it can possibly use, subject to the
16061 condition that there is still enough available space remaining
16062 in the containing object (when allocated at the selected point)
16063 to fully accommodate all of the bits of the bit-field itself.
16065 This simple rule makes it obvious why GCC allocates 8 bytes for
16066 each object of the structure type shown above. When looking
16067 for a place to allocate the "containing object" for `field2',
16068 the compiler simply tries to allocate a 64-bit "containing
16069 object" at each successive 32-bit boundary (starting at zero)
16070 until it finds a place to allocate that 64- bit field such that
16071 at least 31 contiguous (and previously unallocated) bits remain
16072 within that selected 64 bit field. (As it turns out, for the
16073 example above, the compiler finds it is OK to allocate the
16074 "containing object" 64-bit field at bit-offset zero within the
16077 Here we attempt to work backwards from the limited set of facts
16078 we're given, and we try to deduce from those facts, where GCC
16079 must have believed that the containing object started (within
16080 the structure type). The value we deduce is then used (by the
16081 callers of this routine) to generate DW_AT_location and
16082 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16083 the case of DW_AT_location, regular fields as well). */
16085 /* Figure out the bit-distance from the start of the structure to
16086 the "deepest" bit of the bit-field. */
16087 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16089 /* This is the tricky part. Use some fancy footwork to deduce
16090 where the lowest addressed bit of the containing object must
16092 object_offset_in_bits
16093 = double_int_sub (deepest_bitpos, type_size_in_bits);
16095 /* Round up to type_align by default. This works best for
16097 object_offset_in_bits
16098 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16100 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16102 object_offset_in_bits
16103 = double_int_sub (deepest_bitpos, type_size_in_bits);
16105 /* Round up to decl_align instead. */
16106 object_offset_in_bits
16107 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16111 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16112 object_offset_in_bits = bitpos_int;
16114 object_offset_in_bytes
16115 = double_int_div (object_offset_in_bits,
16116 uhwi_to_double_int (BITS_PER_UNIT), true,
16118 return double_int_to_shwi (object_offset_in_bytes);
16121 /* The following routines define various Dwarf attributes and any data
16122 associated with them. */
16124 /* Add a location description attribute value to a DIE.
16126 This emits location attributes suitable for whole variables and
16127 whole parameters. Note that the location attributes for struct fields are
16128 generated by the routine `data_member_location_attribute' below. */
16131 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16132 dw_loc_list_ref descr)
16136 if (single_element_loc_list_p (descr))
16137 add_AT_loc (die, attr_kind, descr->expr);
16139 add_AT_loc_list (die, attr_kind, descr);
16142 /* Add DW_AT_accessibility attribute to DIE if needed. */
16145 add_accessibility_attribute (dw_die_ref die, tree decl)
16147 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16148 children, otherwise the default is DW_ACCESS_public. In DWARF2
16149 the default has always been DW_ACCESS_public. */
16150 if (TREE_PROTECTED (decl))
16151 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16152 else if (TREE_PRIVATE (decl))
16154 if (dwarf_version == 2
16155 || die->die_parent == NULL
16156 || die->die_parent->die_tag != DW_TAG_class_type)
16157 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16159 else if (dwarf_version > 2
16161 && die->die_parent->die_tag == DW_TAG_class_type)
16162 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16165 /* Attach the specialized form of location attribute used for data members of
16166 struct and union types. In the special case of a FIELD_DECL node which
16167 represents a bit-field, the "offset" part of this special location
16168 descriptor must indicate the distance in bytes from the lowest-addressed
16169 byte of the containing struct or union type to the lowest-addressed byte of
16170 the "containing object" for the bit-field. (See the `field_byte_offset'
16173 For any given bit-field, the "containing object" is a hypothetical object
16174 (of some integral or enum type) within which the given bit-field lives. The
16175 type of this hypothetical "containing object" is always the same as the
16176 declared type of the individual bit-field itself (for GCC anyway... the
16177 DWARF spec doesn't actually mandate this). Note that it is the size (in
16178 bytes) of the hypothetical "containing object" which will be given in the
16179 DW_AT_byte_size attribute for this bit-field. (See the
16180 `byte_size_attribute' function below.) It is also used when calculating the
16181 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16182 function below.) */
16185 add_data_member_location_attribute (dw_die_ref die, tree decl)
16187 HOST_WIDE_INT offset;
16188 dw_loc_descr_ref loc_descr = 0;
16190 if (TREE_CODE (decl) == TREE_BINFO)
16192 /* We're working on the TAG_inheritance for a base class. */
16193 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16195 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16196 aren't at a fixed offset from all (sub)objects of the same
16197 type. We need to extract the appropriate offset from our
16198 vtable. The following dwarf expression means
16200 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16202 This is specific to the V3 ABI, of course. */
16204 dw_loc_descr_ref tmp;
16206 /* Make a copy of the object address. */
16207 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16208 add_loc_descr (&loc_descr, tmp);
16210 /* Extract the vtable address. */
16211 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16212 add_loc_descr (&loc_descr, tmp);
16214 /* Calculate the address of the offset. */
16215 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16216 gcc_assert (offset < 0);
16218 tmp = int_loc_descriptor (-offset);
16219 add_loc_descr (&loc_descr, tmp);
16220 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16221 add_loc_descr (&loc_descr, tmp);
16223 /* Extract the offset. */
16224 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16225 add_loc_descr (&loc_descr, tmp);
16227 /* Add it to the object address. */
16228 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16229 add_loc_descr (&loc_descr, tmp);
16232 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16235 offset = field_byte_offset (decl);
16239 if (dwarf_version > 2)
16241 /* Don't need to output a location expression, just the constant. */
16243 add_AT_int (die, DW_AT_data_member_location, offset);
16245 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16250 enum dwarf_location_atom op;
16252 /* The DWARF2 standard says that we should assume that the structure
16253 address is already on the stack, so we can specify a structure
16254 field address by using DW_OP_plus_uconst. */
16256 #ifdef MIPS_DEBUGGING_INFO
16257 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16258 operator correctly. It works only if we leave the offset on the
16262 op = DW_OP_plus_uconst;
16265 loc_descr = new_loc_descr (op, offset, 0);
16269 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16272 /* Writes integer values to dw_vec_const array. */
16275 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16279 *dest++ = val & 0xff;
16285 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16287 static HOST_WIDE_INT
16288 extract_int (const unsigned char *src, unsigned int size)
16290 HOST_WIDE_INT val = 0;
16296 val |= *--src & 0xff;
16302 /* Writes double_int values to dw_vec_const array. */
16305 insert_double (double_int val, unsigned char *dest)
16307 unsigned char *p0 = dest;
16308 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16310 if (WORDS_BIG_ENDIAN)
16316 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16317 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16320 /* Writes floating point values to dw_vec_const array. */
16323 insert_float (const_rtx rtl, unsigned char *array)
16325 REAL_VALUE_TYPE rv;
16329 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16330 real_to_target (val, &rv, GET_MODE (rtl));
16332 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16333 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16335 insert_int (val[i], 4, array);
16340 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16341 does not have a "location" either in memory or in a register. These
16342 things can arise in GNU C when a constant is passed as an actual parameter
16343 to an inlined function. They can also arise in C++ where declared
16344 constants do not necessarily get memory "homes". */
16347 add_const_value_attribute (dw_die_ref die, rtx rtl)
16349 switch (GET_CODE (rtl))
16353 HOST_WIDE_INT val = INTVAL (rtl);
16356 add_AT_int (die, DW_AT_const_value, val);
16358 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16363 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16364 floating-point constant. A CONST_DOUBLE is used whenever the
16365 constant requires more than one word in order to be adequately
16368 enum machine_mode mode = GET_MODE (rtl);
16370 if (SCALAR_FLOAT_MODE_P (mode))
16372 unsigned int length = GET_MODE_SIZE (mode);
16373 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16375 insert_float (rtl, array);
16376 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16379 add_AT_double (die, DW_AT_const_value,
16380 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16386 enum machine_mode mode = GET_MODE (rtl);
16387 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16388 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16389 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16390 (length * elt_size);
16394 switch (GET_MODE_CLASS (mode))
16396 case MODE_VECTOR_INT:
16397 for (i = 0, p = array; i < length; i++, p += elt_size)
16399 rtx elt = CONST_VECTOR_ELT (rtl, i);
16400 double_int val = rtx_to_double_int (elt);
16402 if (elt_size <= sizeof (HOST_WIDE_INT))
16403 insert_int (double_int_to_shwi (val), elt_size, p);
16406 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16407 insert_double (val, p);
16412 case MODE_VECTOR_FLOAT:
16413 for (i = 0, p = array; i < length; i++, p += elt_size)
16415 rtx elt = CONST_VECTOR_ELT (rtl, i);
16416 insert_float (elt, p);
16421 gcc_unreachable ();
16424 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16429 if (dwarf_version >= 4 || !dwarf_strict)
16431 dw_loc_descr_ref loc_result;
16432 resolve_one_addr (&rtl, NULL);
16434 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16435 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16436 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16437 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16438 add_AT_loc (die, DW_AT_location, loc_result);
16439 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16445 if (CONSTANT_P (XEXP (rtl, 0)))
16446 return add_const_value_attribute (die, XEXP (rtl, 0));
16449 if (!const_ok_for_output (rtl))
16452 if (dwarf_version >= 4 || !dwarf_strict)
16457 /* In cases where an inlined instance of an inline function is passed
16458 the address of an `auto' variable (which is local to the caller) we
16459 can get a situation where the DECL_RTL of the artificial local
16460 variable (for the inlining) which acts as a stand-in for the
16461 corresponding formal parameter (of the inline function) will look
16462 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16463 exactly a compile-time constant expression, but it isn't the address
16464 of the (artificial) local variable either. Rather, it represents the
16465 *value* which the artificial local variable always has during its
16466 lifetime. We currently have no way to represent such quasi-constant
16467 values in Dwarf, so for now we just punt and generate nothing. */
16475 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16476 && MEM_READONLY_P (rtl)
16477 && GET_MODE (rtl) == BLKmode)
16479 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16485 /* No other kinds of rtx should be possible here. */
16486 gcc_unreachable ();
16491 /* Determine whether the evaluation of EXPR references any variables
16492 or functions which aren't otherwise used (and therefore may not be
16495 reference_to_unused (tree * tp, int * walk_subtrees,
16496 void * data ATTRIBUTE_UNUSED)
16498 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16499 *walk_subtrees = 0;
16501 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16502 && ! TREE_ASM_WRITTEN (*tp))
16504 /* ??? The C++ FE emits debug information for using decls, so
16505 putting gcc_unreachable here falls over. See PR31899. For now
16506 be conservative. */
16507 else if (!cgraph_global_info_ready
16508 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16510 else if (TREE_CODE (*tp) == VAR_DECL)
16512 struct varpool_node *node = varpool_get_node (*tp);
16513 if (!node || !node->needed)
16516 else if (TREE_CODE (*tp) == FUNCTION_DECL
16517 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16519 /* The call graph machinery must have finished analyzing,
16520 optimizing and gimplifying the CU by now.
16521 So if *TP has no call graph node associated
16522 to it, it means *TP will not be emitted. */
16523 if (!cgraph_get_node (*tp))
16526 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16532 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16533 for use in a later add_const_value_attribute call. */
16536 rtl_for_decl_init (tree init, tree type)
16538 rtx rtl = NULL_RTX;
16542 /* If a variable is initialized with a string constant without embedded
16543 zeros, build CONST_STRING. */
16544 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16546 tree enttype = TREE_TYPE (type);
16547 tree domain = TYPE_DOMAIN (type);
16548 enum machine_mode mode = TYPE_MODE (enttype);
16550 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16552 && integer_zerop (TYPE_MIN_VALUE (domain))
16553 && compare_tree_int (TYPE_MAX_VALUE (domain),
16554 TREE_STRING_LENGTH (init) - 1) == 0
16555 && ((size_t) TREE_STRING_LENGTH (init)
16556 == strlen (TREE_STRING_POINTER (init)) + 1))
16558 rtl = gen_rtx_CONST_STRING (VOIDmode,
16559 ggc_strdup (TREE_STRING_POINTER (init)));
16560 rtl = gen_rtx_MEM (BLKmode, rtl);
16561 MEM_READONLY_P (rtl) = 1;
16564 /* Other aggregates, and complex values, could be represented using
16566 else if (AGGREGATE_TYPE_P (type)
16567 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
16568 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
16569 || TREE_CODE (type) == COMPLEX_TYPE)
16571 /* Vectors only work if their mode is supported by the target.
16572 FIXME: generic vectors ought to work too. */
16573 else if (TREE_CODE (type) == VECTOR_TYPE
16574 && !VECTOR_MODE_P (TYPE_MODE (type)))
16576 /* If the initializer is something that we know will expand into an
16577 immediate RTL constant, expand it now. We must be careful not to
16578 reference variables which won't be output. */
16579 else if (initializer_constant_valid_p (init, type)
16580 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16582 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16584 if (TREE_CODE (type) == VECTOR_TYPE)
16585 switch (TREE_CODE (init))
16590 if (TREE_CONSTANT (init))
16592 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16593 bool constant_p = true;
16595 unsigned HOST_WIDE_INT ix;
16597 /* Even when ctor is constant, it might contain non-*_CST
16598 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16599 belong into VECTOR_CST nodes. */
16600 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16601 if (!CONSTANT_CLASS_P (value))
16603 constant_p = false;
16609 init = build_vector_from_ctor (type, elts);
16619 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16621 /* If expand_expr returns a MEM, it wasn't immediate. */
16622 gcc_assert (!rtl || !MEM_P (rtl));
16628 /* Generate RTL for the variable DECL to represent its location. */
16631 rtl_for_decl_location (tree decl)
16635 /* Here we have to decide where we are going to say the parameter "lives"
16636 (as far as the debugger is concerned). We only have a couple of
16637 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16639 DECL_RTL normally indicates where the parameter lives during most of the
16640 activation of the function. If optimization is enabled however, this
16641 could be either NULL or else a pseudo-reg. Both of those cases indicate
16642 that the parameter doesn't really live anywhere (as far as the code
16643 generation parts of GCC are concerned) during most of the function's
16644 activation. That will happen (for example) if the parameter is never
16645 referenced within the function.
16647 We could just generate a location descriptor here for all non-NULL
16648 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16649 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16650 where DECL_RTL is NULL or is a pseudo-reg.
16652 Note however that we can only get away with using DECL_INCOMING_RTL as
16653 a backup substitute for DECL_RTL in certain limited cases. In cases
16654 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16655 we can be sure that the parameter was passed using the same type as it is
16656 declared to have within the function, and that its DECL_INCOMING_RTL
16657 points us to a place where a value of that type is passed.
16659 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16660 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16661 because in these cases DECL_INCOMING_RTL points us to a value of some
16662 type which is *different* from the type of the parameter itself. Thus,
16663 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16664 such cases, the debugger would end up (for example) trying to fetch a
16665 `float' from a place which actually contains the first part of a
16666 `double'. That would lead to really incorrect and confusing
16667 output at debug-time.
16669 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16670 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16671 are a couple of exceptions however. On little-endian machines we can
16672 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16673 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16674 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16675 when (on a little-endian machine) a non-prototyped function has a
16676 parameter declared to be of type `short' or `char'. In such cases,
16677 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16678 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16679 passed `int' value. If the debugger then uses that address to fetch
16680 a `short' or a `char' (on a little-endian machine) the result will be
16681 the correct data, so we allow for such exceptional cases below.
16683 Note that our goal here is to describe the place where the given formal
16684 parameter lives during most of the function's activation (i.e. between the
16685 end of the prologue and the start of the epilogue). We'll do that as best
16686 as we can. Note however that if the given formal parameter is modified
16687 sometime during the execution of the function, then a stack backtrace (at
16688 debug-time) will show the function as having been called with the *new*
16689 value rather than the value which was originally passed in. This happens
16690 rarely enough that it is not a major problem, but it *is* a problem, and
16691 I'd like to fix it.
16693 A future version of dwarf2out.c may generate two additional attributes for
16694 any given DW_TAG_formal_parameter DIE which will describe the "passed
16695 type" and the "passed location" for the given formal parameter in addition
16696 to the attributes we now generate to indicate the "declared type" and the
16697 "active location" for each parameter. This additional set of attributes
16698 could be used by debuggers for stack backtraces. Separately, note that
16699 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16700 This happens (for example) for inlined-instances of inline function formal
16701 parameters which are never referenced. This really shouldn't be
16702 happening. All PARM_DECL nodes should get valid non-NULL
16703 DECL_INCOMING_RTL values. FIXME. */
16705 /* Use DECL_RTL as the "location" unless we find something better. */
16706 rtl = DECL_RTL_IF_SET (decl);
16708 /* When generating abstract instances, ignore everything except
16709 constants, symbols living in memory, and symbols living in
16710 fixed registers. */
16711 if (! reload_completed)
16714 && (CONSTANT_P (rtl)
16716 && CONSTANT_P (XEXP (rtl, 0)))
16718 && TREE_CODE (decl) == VAR_DECL
16719 && TREE_STATIC (decl))))
16721 rtl = targetm.delegitimize_address (rtl);
16726 else if (TREE_CODE (decl) == PARM_DECL)
16728 if (rtl == NULL_RTX
16729 || is_pseudo_reg (rtl)
16731 && is_pseudo_reg (XEXP (rtl, 0))
16732 && DECL_INCOMING_RTL (decl)
16733 && MEM_P (DECL_INCOMING_RTL (decl))
16734 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
16736 tree declared_type = TREE_TYPE (decl);
16737 tree passed_type = DECL_ARG_TYPE (decl);
16738 enum machine_mode dmode = TYPE_MODE (declared_type);
16739 enum machine_mode pmode = TYPE_MODE (passed_type);
16741 /* This decl represents a formal parameter which was optimized out.
16742 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16743 all cases where (rtl == NULL_RTX) just below. */
16744 if (dmode == pmode)
16745 rtl = DECL_INCOMING_RTL (decl);
16746 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
16747 && SCALAR_INT_MODE_P (dmode)
16748 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16749 && DECL_INCOMING_RTL (decl))
16751 rtx inc = DECL_INCOMING_RTL (decl);
16754 else if (MEM_P (inc))
16756 if (BYTES_BIG_ENDIAN)
16757 rtl = adjust_address_nv (inc, dmode,
16758 GET_MODE_SIZE (pmode)
16759 - GET_MODE_SIZE (dmode));
16766 /* If the parm was passed in registers, but lives on the stack, then
16767 make a big endian correction if the mode of the type of the
16768 parameter is not the same as the mode of the rtl. */
16769 /* ??? This is the same series of checks that are made in dbxout.c before
16770 we reach the big endian correction code there. It isn't clear if all
16771 of these checks are necessary here, but keeping them all is the safe
16773 else if (MEM_P (rtl)
16774 && XEXP (rtl, 0) != const0_rtx
16775 && ! CONSTANT_P (XEXP (rtl, 0))
16776 /* Not passed in memory. */
16777 && !MEM_P (DECL_INCOMING_RTL (decl))
16778 /* Not passed by invisible reference. */
16779 && (!REG_P (XEXP (rtl, 0))
16780 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16781 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16782 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16783 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16786 /* Big endian correction check. */
16787 && BYTES_BIG_ENDIAN
16788 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16789 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16792 int offset = (UNITS_PER_WORD
16793 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16795 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16796 plus_constant (XEXP (rtl, 0), offset));
16799 else if (TREE_CODE (decl) == VAR_DECL
16802 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16803 && BYTES_BIG_ENDIAN)
16805 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16806 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16808 /* If a variable is declared "register" yet is smaller than
16809 a register, then if we store the variable to memory, it
16810 looks like we're storing a register-sized value, when in
16811 fact we are not. We need to adjust the offset of the
16812 storage location to reflect the actual value's bytes,
16813 else gdb will not be able to display it. */
16815 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16816 plus_constant (XEXP (rtl, 0), rsize-dsize));
16819 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16820 and will have been substituted directly into all expressions that use it.
16821 C does not have such a concept, but C++ and other languages do. */
16822 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16823 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16826 rtl = targetm.delegitimize_address (rtl);
16828 /* If we don't look past the constant pool, we risk emitting a
16829 reference to a constant pool entry that isn't referenced from
16830 code, and thus is not emitted. */
16832 rtl = avoid_constant_pool_reference (rtl);
16834 /* Try harder to get a rtl. If this symbol ends up not being emitted
16835 in the current CU, resolve_addr will remove the expression referencing
16837 if (rtl == NULL_RTX
16838 && TREE_CODE (decl) == VAR_DECL
16839 && !DECL_EXTERNAL (decl)
16840 && TREE_STATIC (decl)
16841 && DECL_NAME (decl)
16842 && !DECL_HARD_REGISTER (decl)
16843 && DECL_MODE (decl) != VOIDmode)
16845 rtl = make_decl_rtl_for_debug (decl);
16847 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16848 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16855 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16856 returned. If so, the decl for the COMMON block is returned, and the
16857 value is the offset into the common block for the symbol. */
16860 fortran_common (tree decl, HOST_WIDE_INT *value)
16862 tree val_expr, cvar;
16863 enum machine_mode mode;
16864 HOST_WIDE_INT bitsize, bitpos;
16866 int volatilep = 0, unsignedp = 0;
16868 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16869 it does not have a value (the offset into the common area), or if it
16870 is thread local (as opposed to global) then it isn't common, and shouldn't
16871 be handled as such. */
16872 if (TREE_CODE (decl) != VAR_DECL
16873 || !TREE_STATIC (decl)
16874 || !DECL_HAS_VALUE_EXPR_P (decl)
16878 val_expr = DECL_VALUE_EXPR (decl);
16879 if (TREE_CODE (val_expr) != COMPONENT_REF)
16882 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16883 &mode, &unsignedp, &volatilep, true);
16885 if (cvar == NULL_TREE
16886 || TREE_CODE (cvar) != VAR_DECL
16887 || DECL_ARTIFICIAL (cvar)
16888 || !TREE_PUBLIC (cvar))
16892 if (offset != NULL)
16894 if (!host_integerp (offset, 0))
16896 *value = tree_low_cst (offset, 0);
16899 *value += bitpos / BITS_PER_UNIT;
16904 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16905 data attribute for a variable or a parameter. We generate the
16906 DW_AT_const_value attribute only in those cases where the given variable
16907 or parameter does not have a true "location" either in memory or in a
16908 register. This can happen (for example) when a constant is passed as an
16909 actual argument in a call to an inline function. (It's possible that
16910 these things can crop up in other ways also.) Note that one type of
16911 constant value which can be passed into an inlined function is a constant
16912 pointer. This can happen for example if an actual argument in an inlined
16913 function call evaluates to a compile-time constant address. */
16916 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
16917 enum dwarf_attribute attr)
16920 dw_loc_list_ref list;
16921 var_loc_list *loc_list;
16923 if (TREE_CODE (decl) == ERROR_MARK)
16926 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16927 || TREE_CODE (decl) == RESULT_DECL);
16929 /* Try to get some constant RTL for this decl, and use that as the value of
16932 rtl = rtl_for_decl_location (decl);
16933 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16934 && add_const_value_attribute (die, rtl))
16937 /* See if we have single element location list that is equivalent to
16938 a constant value. That way we are better to use add_const_value_attribute
16939 rather than expanding constant value equivalent. */
16940 loc_list = lookup_decl_loc (decl);
16943 && loc_list->first->next == NULL
16944 && NOTE_P (loc_list->first->loc)
16945 && NOTE_VAR_LOCATION (loc_list->first->loc)
16946 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16948 struct var_loc_node *node;
16950 node = loc_list->first;
16951 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16952 if (GET_CODE (rtl) == EXPR_LIST)
16953 rtl = XEXP (rtl, 0);
16954 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16955 && add_const_value_attribute (die, rtl))
16958 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
16961 add_AT_location_description (die, attr, list);
16964 /* None of that worked, so it must not really have a location;
16965 try adding a constant value attribute from the DECL_INITIAL. */
16966 return tree_add_const_value_attribute_for_decl (die, decl);
16969 /* Add VARIABLE and DIE into deferred locations list. */
16972 defer_location (tree variable, dw_die_ref die)
16974 deferred_locations entry;
16975 entry.variable = variable;
16977 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
16980 /* Helper function for tree_add_const_value_attribute. Natively encode
16981 initializer INIT into an array. Return true if successful. */
16984 native_encode_initializer (tree init, unsigned char *array, int size)
16988 if (init == NULL_TREE)
16992 switch (TREE_CODE (init))
16995 type = TREE_TYPE (init);
16996 if (TREE_CODE (type) == ARRAY_TYPE)
16998 tree enttype = TREE_TYPE (type);
16999 enum machine_mode mode = TYPE_MODE (enttype);
17001 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
17003 if (int_size_in_bytes (type) != size)
17005 if (size > TREE_STRING_LENGTH (init))
17007 memcpy (array, TREE_STRING_POINTER (init),
17008 TREE_STRING_LENGTH (init));
17009 memset (array + TREE_STRING_LENGTH (init),
17010 '\0', size - TREE_STRING_LENGTH (init));
17013 memcpy (array, TREE_STRING_POINTER (init), size);
17018 type = TREE_TYPE (init);
17019 if (int_size_in_bytes (type) != size)
17021 if (TREE_CODE (type) == ARRAY_TYPE)
17023 HOST_WIDE_INT min_index;
17024 unsigned HOST_WIDE_INT cnt;
17025 int curpos = 0, fieldsize;
17026 constructor_elt *ce;
17028 if (TYPE_DOMAIN (type) == NULL_TREE
17029 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
17032 fieldsize = int_size_in_bytes (TREE_TYPE (type));
17033 if (fieldsize <= 0)
17036 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
17037 memset (array, '\0', size);
17038 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17040 tree val = ce->value;
17041 tree index = ce->index;
17043 if (index && TREE_CODE (index) == RANGE_EXPR)
17044 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
17047 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
17052 if (!native_encode_initializer (val, array + pos, fieldsize))
17055 curpos = pos + fieldsize;
17056 if (index && TREE_CODE (index) == RANGE_EXPR)
17058 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17059 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17063 memcpy (array + curpos, array + pos, fieldsize);
17064 curpos += fieldsize;
17067 gcc_assert (curpos <= size);
17071 else if (TREE_CODE (type) == RECORD_TYPE
17072 || TREE_CODE (type) == UNION_TYPE)
17074 tree field = NULL_TREE;
17075 unsigned HOST_WIDE_INT cnt;
17076 constructor_elt *ce;
17078 if (int_size_in_bytes (type) != size)
17081 if (TREE_CODE (type) == RECORD_TYPE)
17082 field = TYPE_FIELDS (type);
17084 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17086 tree val = ce->value;
17087 int pos, fieldsize;
17089 if (ce->index != 0)
17095 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17098 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17099 && TYPE_DOMAIN (TREE_TYPE (field))
17100 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17102 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17103 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17105 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17106 pos = int_byte_position (field);
17107 gcc_assert (pos + fieldsize <= size);
17109 && !native_encode_initializer (val, array + pos, fieldsize))
17115 case VIEW_CONVERT_EXPR:
17116 case NON_LVALUE_EXPR:
17117 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17119 return native_encode_expr (init, array, size) == size;
17123 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17124 attribute is the const value T. */
17127 tree_add_const_value_attribute (dw_die_ref die, tree t)
17130 tree type = TREE_TYPE (t);
17133 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17137 gcc_assert (!DECL_P (init));
17139 rtl = rtl_for_decl_init (init, type);
17141 return add_const_value_attribute (die, rtl);
17142 /* If the host and target are sane, try harder. */
17143 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17144 && initializer_constant_valid_p (init, type))
17146 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17147 if (size > 0 && (int) size == size)
17149 unsigned char *array = (unsigned char *)
17150 ggc_alloc_cleared_atomic (size);
17152 if (native_encode_initializer (init, array, size))
17154 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17162 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17163 attribute is the const value of T, where T is an integral constant
17164 variable with static storage duration
17165 (so it can't be a PARM_DECL or a RESULT_DECL). */
17168 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17172 || (TREE_CODE (decl) != VAR_DECL
17173 && TREE_CODE (decl) != CONST_DECL))
17176 if (TREE_READONLY (decl)
17177 && ! TREE_THIS_VOLATILE (decl)
17178 && DECL_INITIAL (decl))
17183 /* Don't add DW_AT_const_value if abstract origin already has one. */
17184 if (get_AT (var_die, DW_AT_const_value))
17187 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17190 /* Convert the CFI instructions for the current function into a
17191 location list. This is used for DW_AT_frame_base when we targeting
17192 a dwarf2 consumer that does not support the dwarf3
17193 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17196 static dw_loc_list_ref
17197 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17200 dw_loc_list_ref list, *list_tail;
17202 dw_cfa_location last_cfa, next_cfa;
17203 const char *start_label, *last_label, *section;
17204 dw_cfa_location remember;
17206 fde = current_fde ();
17207 gcc_assert (fde != NULL);
17209 section = secname_for_decl (current_function_decl);
17213 memset (&next_cfa, 0, sizeof (next_cfa));
17214 next_cfa.reg = INVALID_REGNUM;
17215 remember = next_cfa;
17217 start_label = fde->dw_fde_begin;
17219 /* ??? Bald assumption that the CIE opcode list does not contain
17220 advance opcodes. */
17221 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
17222 lookup_cfa_1 (cfi, &next_cfa, &remember);
17224 last_cfa = next_cfa;
17225 last_label = start_label;
17227 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17228 switch (cfi->dw_cfi_opc)
17230 case DW_CFA_set_loc:
17231 case DW_CFA_advance_loc1:
17232 case DW_CFA_advance_loc2:
17233 case DW_CFA_advance_loc4:
17234 if (!cfa_equal_p (&last_cfa, &next_cfa))
17236 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17237 start_label, last_label, section);
17239 list_tail = &(*list_tail)->dw_loc_next;
17240 last_cfa = next_cfa;
17241 start_label = last_label;
17243 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17246 case DW_CFA_advance_loc:
17247 /* The encoding is complex enough that we should never emit this. */
17248 gcc_unreachable ();
17251 lookup_cfa_1 (cfi, &next_cfa, &remember);
17255 if (!cfa_equal_p (&last_cfa, &next_cfa))
17257 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17258 start_label, last_label, section);
17259 list_tail = &(*list_tail)->dw_loc_next;
17260 start_label = last_label;
17263 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17264 start_label, fde->dw_fde_end, section);
17266 if (list && list->dw_loc_next)
17272 /* Compute a displacement from the "steady-state frame pointer" to the
17273 frame base (often the same as the CFA), and store it in
17274 frame_pointer_fb_offset. OFFSET is added to the displacement
17275 before the latter is negated. */
17278 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17282 #ifdef FRAME_POINTER_CFA_OFFSET
17283 reg = frame_pointer_rtx;
17284 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17286 reg = arg_pointer_rtx;
17287 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17290 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17291 if (GET_CODE (elim) == PLUS)
17293 offset += INTVAL (XEXP (elim, 1));
17294 elim = XEXP (elim, 0);
17297 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17298 && (elim == hard_frame_pointer_rtx
17299 || elim == stack_pointer_rtx))
17300 || elim == (frame_pointer_needed
17301 ? hard_frame_pointer_rtx
17302 : stack_pointer_rtx));
17304 frame_pointer_fb_offset = -offset;
17307 /* Generate a DW_AT_name attribute given some string value to be included as
17308 the value of the attribute. */
17311 add_name_attribute (dw_die_ref die, const char *name_string)
17313 if (name_string != NULL && *name_string != 0)
17315 if (demangle_name_func)
17316 name_string = (*demangle_name_func) (name_string);
17318 add_AT_string (die, DW_AT_name, name_string);
17322 /* Generate a DW_AT_comp_dir attribute for DIE. */
17325 add_comp_dir_attribute (dw_die_ref die)
17327 const char *wd = get_src_pwd ();
17333 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17337 wdlen = strlen (wd);
17338 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17340 wd1 [wdlen] = DIR_SEPARATOR;
17341 wd1 [wdlen + 1] = 0;
17345 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17348 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17352 lower_bound_default (void)
17354 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17359 case DW_LANG_C_plus_plus:
17361 case DW_LANG_ObjC_plus_plus:
17364 case DW_LANG_Fortran77:
17365 case DW_LANG_Fortran90:
17366 case DW_LANG_Fortran95:
17370 case DW_LANG_Python:
17371 return dwarf_version >= 4 ? 0 : -1;
17372 case DW_LANG_Ada95:
17373 case DW_LANG_Ada83:
17374 case DW_LANG_Cobol74:
17375 case DW_LANG_Cobol85:
17376 case DW_LANG_Pascal83:
17377 case DW_LANG_Modula2:
17379 return dwarf_version >= 4 ? 1 : -1;
17385 /* Given a tree node describing an array bound (either lower or upper) output
17386 a representation for that bound. */
17389 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17391 switch (TREE_CODE (bound))
17396 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17399 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17402 /* Use the default if possible. */
17403 if (bound_attr == DW_AT_lower_bound
17404 && host_integerp (bound, 0)
17405 && (dflt = lower_bound_default ()) != -1
17406 && tree_low_cst (bound, 0) == dflt)
17409 /* Otherwise represent the bound as an unsigned value with the
17410 precision of its type. The precision and signedness of the
17411 type will be necessary to re-interpret it unambiguously. */
17412 else if (prec < HOST_BITS_PER_WIDE_INT)
17414 unsigned HOST_WIDE_INT mask
17415 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17416 add_AT_unsigned (subrange_die, bound_attr,
17417 TREE_INT_CST_LOW (bound) & mask);
17419 else if (prec == HOST_BITS_PER_WIDE_INT
17420 || TREE_INT_CST_HIGH (bound) == 0)
17421 add_AT_unsigned (subrange_die, bound_attr,
17422 TREE_INT_CST_LOW (bound));
17424 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17425 TREE_INT_CST_LOW (bound));
17430 case VIEW_CONVERT_EXPR:
17431 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17441 dw_die_ref decl_die = lookup_decl_die (bound);
17443 /* ??? Can this happen, or should the variable have been bound
17444 first? Probably it can, since I imagine that we try to create
17445 the types of parameters in the order in which they exist in
17446 the list, and won't have created a forward reference to a
17447 later parameter. */
17448 if (decl_die != NULL)
17450 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17458 /* Otherwise try to create a stack operation procedure to
17459 evaluate the value of the array bound. */
17461 dw_die_ref ctx, decl_die;
17462 dw_loc_list_ref list;
17464 list = loc_list_from_tree (bound, 2);
17465 if (list == NULL || single_element_loc_list_p (list))
17467 /* If DW_AT_*bound is not a reference nor constant, it is
17468 a DWARF expression rather than location description.
17469 For that loc_list_from_tree (bound, 0) is needed.
17470 If that fails to give a single element list,
17471 fall back to outputting this as a reference anyway. */
17472 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17473 if (list2 && single_element_loc_list_p (list2))
17475 add_AT_loc (subrange_die, bound_attr, list2->expr);
17482 if (current_function_decl == 0)
17483 ctx = comp_unit_die ();
17485 ctx = lookup_decl_die (current_function_decl);
17487 decl_die = new_die (DW_TAG_variable, ctx, bound);
17488 add_AT_flag (decl_die, DW_AT_artificial, 1);
17489 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17490 add_AT_location_description (decl_die, DW_AT_location, list);
17491 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17497 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17498 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17499 Note that the block of subscript information for an array type also
17500 includes information about the element type of the given array type. */
17503 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17505 unsigned dimension_number;
17507 dw_die_ref subrange_die;
17509 for (dimension_number = 0;
17510 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17511 type = TREE_TYPE (type), dimension_number++)
17513 tree domain = TYPE_DOMAIN (type);
17515 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17518 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17519 and (in GNU C only) variable bounds. Handle all three forms
17521 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17524 /* We have an array type with specified bounds. */
17525 lower = TYPE_MIN_VALUE (domain);
17526 upper = TYPE_MAX_VALUE (domain);
17528 /* Define the index type. */
17529 if (TREE_TYPE (domain))
17531 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17532 TREE_TYPE field. We can't emit debug info for this
17533 because it is an unnamed integral type. */
17534 if (TREE_CODE (domain) == INTEGER_TYPE
17535 && TYPE_NAME (domain) == NULL_TREE
17536 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17537 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17540 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17544 /* ??? If upper is NULL, the array has unspecified length,
17545 but it does have a lower bound. This happens with Fortran
17547 Since the debugger is definitely going to need to know N
17548 to produce useful results, go ahead and output the lower
17549 bound solo, and hope the debugger can cope. */
17551 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17553 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17556 /* Otherwise we have an array type with an unspecified length. The
17557 DWARF-2 spec does not say how to handle this; let's just leave out the
17563 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17567 switch (TREE_CODE (tree_node))
17572 case ENUMERAL_TYPE:
17575 case QUAL_UNION_TYPE:
17576 size = int_size_in_bytes (tree_node);
17579 /* For a data member of a struct or union, the DW_AT_byte_size is
17580 generally given as the number of bytes normally allocated for an
17581 object of the *declared* type of the member itself. This is true
17582 even for bit-fields. */
17583 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17586 gcc_unreachable ();
17589 /* Note that `size' might be -1 when we get to this point. If it is, that
17590 indicates that the byte size of the entity in question is variable. We
17591 have no good way of expressing this fact in Dwarf at the present time,
17592 so just let the -1 pass on through. */
17593 add_AT_unsigned (die, DW_AT_byte_size, size);
17596 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17597 which specifies the distance in bits from the highest order bit of the
17598 "containing object" for the bit-field to the highest order bit of the
17601 For any given bit-field, the "containing object" is a hypothetical object
17602 (of some integral or enum type) within which the given bit-field lives. The
17603 type of this hypothetical "containing object" is always the same as the
17604 declared type of the individual bit-field itself. The determination of the
17605 exact location of the "containing object" for a bit-field is rather
17606 complicated. It's handled by the `field_byte_offset' function (above).
17608 Note that it is the size (in bytes) of the hypothetical "containing object"
17609 which will be given in the DW_AT_byte_size attribute for this bit-field.
17610 (See `byte_size_attribute' above). */
17613 add_bit_offset_attribute (dw_die_ref die, tree decl)
17615 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17616 tree type = DECL_BIT_FIELD_TYPE (decl);
17617 HOST_WIDE_INT bitpos_int;
17618 HOST_WIDE_INT highest_order_object_bit_offset;
17619 HOST_WIDE_INT highest_order_field_bit_offset;
17620 HOST_WIDE_INT bit_offset;
17622 /* Must be a field and a bit field. */
17623 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17625 /* We can't yet handle bit-fields whose offsets are variable, so if we
17626 encounter such things, just return without generating any attribute
17627 whatsoever. Likewise for variable or too large size. */
17628 if (! host_integerp (bit_position (decl), 0)
17629 || ! host_integerp (DECL_SIZE (decl), 1))
17632 bitpos_int = int_bit_position (decl);
17634 /* Note that the bit offset is always the distance (in bits) from the
17635 highest-order bit of the "containing object" to the highest-order bit of
17636 the bit-field itself. Since the "high-order end" of any object or field
17637 is different on big-endian and little-endian machines, the computation
17638 below must take account of these differences. */
17639 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17640 highest_order_field_bit_offset = bitpos_int;
17642 if (! BYTES_BIG_ENDIAN)
17644 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17645 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17649 = (! BYTES_BIG_ENDIAN
17650 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17651 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17653 if (bit_offset < 0)
17654 add_AT_int (die, DW_AT_bit_offset, bit_offset);
17656 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
17659 /* For a FIELD_DECL node which represents a bit field, output an attribute
17660 which specifies the length in bits of the given field. */
17663 add_bit_size_attribute (dw_die_ref die, tree decl)
17665 /* Must be a field and a bit field. */
17666 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17667 && DECL_BIT_FIELD_TYPE (decl));
17669 if (host_integerp (DECL_SIZE (decl), 1))
17670 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17673 /* If the compiled language is ANSI C, then add a 'prototyped'
17674 attribute, if arg types are given for the parameters of a function. */
17677 add_prototyped_attribute (dw_die_ref die, tree func_type)
17679 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
17680 && prototype_p (func_type))
17681 add_AT_flag (die, DW_AT_prototyped, 1);
17684 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17685 by looking in either the type declaration or object declaration
17688 static inline dw_die_ref
17689 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17691 dw_die_ref origin_die = NULL;
17693 if (TREE_CODE (origin) != FUNCTION_DECL)
17695 /* We may have gotten separated from the block for the inlined
17696 function, if we're in an exception handler or some such; make
17697 sure that the abstract function has been written out.
17699 Doing this for nested functions is wrong, however; functions are
17700 distinct units, and our context might not even be inline. */
17704 fn = TYPE_STUB_DECL (fn);
17706 fn = decl_function_context (fn);
17708 dwarf2out_abstract_function (fn);
17711 if (DECL_P (origin))
17712 origin_die = lookup_decl_die (origin);
17713 else if (TYPE_P (origin))
17714 origin_die = lookup_type_die (origin);
17716 /* XXX: Functions that are never lowered don't always have correct block
17717 trees (in the case of java, they simply have no block tree, in some other
17718 languages). For these functions, there is nothing we can really do to
17719 output correct debug info for inlined functions in all cases. Rather
17720 than die, we'll just produce deficient debug info now, in that we will
17721 have variables without a proper abstract origin. In the future, when all
17722 functions are lowered, we should re-add a gcc_assert (origin_die)
17726 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17730 /* We do not currently support the pure_virtual attribute. */
17733 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17735 if (DECL_VINDEX (func_decl))
17737 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17739 if (host_integerp (DECL_VINDEX (func_decl), 0))
17740 add_AT_loc (die, DW_AT_vtable_elem_location,
17741 new_loc_descr (DW_OP_constu,
17742 tree_low_cst (DECL_VINDEX (func_decl), 0),
17745 /* GNU extension: Record what type this method came from originally. */
17746 if (debug_info_level > DINFO_LEVEL_TERSE
17747 && DECL_CONTEXT (func_decl))
17748 add_AT_die_ref (die, DW_AT_containing_type,
17749 lookup_type_die (DECL_CONTEXT (func_decl)));
17753 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17754 given decl. This used to be a vendor extension until after DWARF 4
17755 standardized it. */
17758 add_linkage_attr (dw_die_ref die, tree decl)
17760 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17762 /* Mimic what assemble_name_raw does with a leading '*'. */
17763 if (name[0] == '*')
17766 if (dwarf_version >= 4)
17767 add_AT_string (die, DW_AT_linkage_name, name);
17769 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17772 /* Add source coordinate attributes for the given decl. */
17775 add_src_coords_attributes (dw_die_ref die, tree decl)
17777 expanded_location s;
17779 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
17781 s = expand_location (DECL_SOURCE_LOCATION (decl));
17782 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17783 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17786 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17789 add_linkage_name (dw_die_ref die, tree decl)
17791 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17792 && TREE_PUBLIC (decl)
17793 && !DECL_ABSTRACT (decl)
17794 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17795 && die->die_tag != DW_TAG_member)
17797 /* Defer until we have an assembler name set. */
17798 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17800 limbo_die_node *asm_name;
17802 asm_name = ggc_alloc_cleared_limbo_die_node ();
17803 asm_name->die = die;
17804 asm_name->created_for = decl;
17805 asm_name->next = deferred_asm_name;
17806 deferred_asm_name = asm_name;
17808 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17809 add_linkage_attr (die, decl);
17813 /* Add a DW_AT_name attribute and source coordinate attribute for the
17814 given decl, but only if it actually has a name. */
17817 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17821 decl_name = DECL_NAME (decl);
17822 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17824 const char *name = dwarf2_name (decl, 0);
17826 add_name_attribute (die, name);
17827 if (! DECL_ARTIFICIAL (decl))
17828 add_src_coords_attributes (die, decl);
17830 add_linkage_name (die, decl);
17833 #ifdef VMS_DEBUGGING_INFO
17834 /* Get the function's name, as described by its RTL. This may be different
17835 from the DECL_NAME name used in the source file. */
17836 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17838 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17839 XEXP (DECL_RTL (decl), 0));
17840 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17842 #endif /* VMS_DEBUGGING_INFO */
17845 #ifdef VMS_DEBUGGING_INFO
17846 /* Output the debug main pointer die for VMS */
17849 dwarf2out_vms_debug_main_pointer (void)
17851 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17854 /* Allocate the VMS debug main subprogram die. */
17855 die = ggc_alloc_cleared_die_node ();
17856 die->die_tag = DW_TAG_subprogram;
17857 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17858 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17859 current_function_funcdef_no);
17860 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17862 /* Make it the first child of comp_unit_die (). */
17863 die->die_parent = comp_unit_die ();
17864 if (comp_unit_die ()->die_child)
17866 die->die_sib = comp_unit_die ()->die_child->die_sib;
17867 comp_unit_die ()->die_child->die_sib = die;
17871 die->die_sib = die;
17872 comp_unit_die ()->die_child = die;
17875 #endif /* VMS_DEBUGGING_INFO */
17877 /* Push a new declaration scope. */
17880 push_decl_scope (tree scope)
17882 VEC_safe_push (tree, gc, decl_scope_table, scope);
17885 /* Pop a declaration scope. */
17888 pop_decl_scope (void)
17890 VEC_pop (tree, decl_scope_table);
17893 /* Return the DIE for the scope that immediately contains this type.
17894 Non-named types get global scope. Named types nested in other
17895 types get their containing scope if it's open, or global scope
17896 otherwise. All other types (i.e. function-local named types) get
17897 the current active scope. */
17900 scope_die_for (tree t, dw_die_ref context_die)
17902 dw_die_ref scope_die = NULL;
17903 tree containing_scope;
17906 /* Non-types always go in the current scope. */
17907 gcc_assert (TYPE_P (t));
17909 containing_scope = TYPE_CONTEXT (t);
17911 /* Use the containing namespace if it was passed in (for a declaration). */
17912 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17914 if (context_die == lookup_decl_die (containing_scope))
17917 containing_scope = NULL_TREE;
17920 /* Ignore function type "scopes" from the C frontend. They mean that
17921 a tagged type is local to a parmlist of a function declarator, but
17922 that isn't useful to DWARF. */
17923 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17924 containing_scope = NULL_TREE;
17926 if (SCOPE_FILE_SCOPE_P (containing_scope))
17927 scope_die = comp_unit_die ();
17928 else if (TYPE_P (containing_scope))
17930 /* For types, we can just look up the appropriate DIE. But
17931 first we check to see if we're in the middle of emitting it
17932 so we know where the new DIE should go. */
17933 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
17934 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
17939 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
17940 || TREE_ASM_WRITTEN (containing_scope));
17941 /*We are not in the middle of emitting the type
17942 CONTAINING_SCOPE. Let's see if it's emitted already. */
17943 scope_die = lookup_type_die (containing_scope);
17945 /* If none of the current dies are suitable, we get file scope. */
17946 if (scope_die == NULL)
17947 scope_die = comp_unit_die ();
17950 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
17953 scope_die = context_die;
17958 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17961 local_scope_p (dw_die_ref context_die)
17963 for (; context_die; context_die = context_die->die_parent)
17964 if (context_die->die_tag == DW_TAG_inlined_subroutine
17965 || context_die->die_tag == DW_TAG_subprogram)
17971 /* Returns nonzero if CONTEXT_DIE is a class. */
17974 class_scope_p (dw_die_ref context_die)
17976 return (context_die
17977 && (context_die->die_tag == DW_TAG_structure_type
17978 || context_die->die_tag == DW_TAG_class_type
17979 || context_die->die_tag == DW_TAG_interface_type
17980 || context_die->die_tag == DW_TAG_union_type));
17983 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17984 whether or not to treat a DIE in this context as a declaration. */
17987 class_or_namespace_scope_p (dw_die_ref context_die)
17989 return (class_scope_p (context_die)
17990 || (context_die && context_die->die_tag == DW_TAG_namespace));
17993 /* Many forms of DIEs require a "type description" attribute. This
17994 routine locates the proper "type descriptor" die for the type given
17995 by 'type', and adds a DW_AT_type attribute below the given die. */
17998 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
17999 int decl_volatile, dw_die_ref context_die)
18001 enum tree_code code = TREE_CODE (type);
18002 dw_die_ref type_die = NULL;
18004 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18005 or fixed-point type, use the inner type. This is because we have no
18006 support for unnamed types in base_type_die. This can happen if this is
18007 an Ada subrange type. Correct solution is emit a subrange type die. */
18008 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
18009 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
18010 type = TREE_TYPE (type), code = TREE_CODE (type);
18012 if (code == ERROR_MARK
18013 /* Handle a special case. For functions whose return type is void, we
18014 generate *no* type attribute. (Note that no object may have type
18015 `void', so this only applies to function return types). */
18016 || code == VOID_TYPE)
18019 type_die = modified_type_die (type,
18020 decl_const || TYPE_READONLY (type),
18021 decl_volatile || TYPE_VOLATILE (type),
18024 if (type_die != NULL)
18025 add_AT_die_ref (object_die, DW_AT_type, type_die);
18028 /* Given an object die, add the calling convention attribute for the
18029 function call type. */
18031 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
18033 enum dwarf_calling_convention value = DW_CC_normal;
18035 value = ((enum dwarf_calling_convention)
18036 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
18039 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
18041 /* DWARF 2 doesn't provide a way to identify a program's source-level
18042 entry point. DW_AT_calling_convention attributes are only meant
18043 to describe functions' calling conventions. However, lacking a
18044 better way to signal the Fortran main program, we used this for
18045 a long time, following existing custom. Now, DWARF 4 has
18046 DW_AT_main_subprogram, which we add below, but some tools still
18047 rely on the old way, which we thus keep. */
18048 value = DW_CC_program;
18050 if (dwarf_version >= 4 || !dwarf_strict)
18051 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
18054 /* Only add the attribute if the backend requests it, and
18055 is not DW_CC_normal. */
18056 if (value && (value != DW_CC_normal))
18057 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18060 /* Given a tree pointer to a struct, class, union, or enum type node, return
18061 a pointer to the (string) tag name for the given type, or zero if the type
18062 was declared without a tag. */
18064 static const char *
18065 type_tag (const_tree type)
18067 const char *name = 0;
18069 if (TYPE_NAME (type) != 0)
18073 /* Find the IDENTIFIER_NODE for the type name. */
18074 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18075 && !TYPE_NAMELESS (type))
18076 t = TYPE_NAME (type);
18078 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18079 a TYPE_DECL node, regardless of whether or not a `typedef' was
18081 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18082 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18084 /* We want to be extra verbose. Don't call dwarf_name if
18085 DECL_NAME isn't set. The default hook for decl_printable_name
18086 doesn't like that, and in this context it's correct to return
18087 0, instead of "<anonymous>" or the like. */
18088 if (DECL_NAME (TYPE_NAME (type))
18089 && !DECL_NAMELESS (TYPE_NAME (type)))
18090 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18093 /* Now get the name as a string, or invent one. */
18094 if (!name && t != 0)
18095 name = IDENTIFIER_POINTER (t);
18098 return (name == 0 || *name == '\0') ? 0 : name;
18101 /* Return the type associated with a data member, make a special check
18102 for bit field types. */
18105 member_declared_type (const_tree member)
18107 return (DECL_BIT_FIELD_TYPE (member)
18108 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18111 /* Get the decl's label, as described by its RTL. This may be different
18112 from the DECL_NAME name used in the source file. */
18115 static const char *
18116 decl_start_label (tree decl)
18119 const char *fnname;
18121 x = DECL_RTL (decl);
18122 gcc_assert (MEM_P (x));
18125 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18127 fnname = XSTR (x, 0);
18132 /* These routines generate the internal representation of the DIE's for
18133 the compilation unit. Debugging information is collected by walking
18134 the declaration trees passed in from dwarf2out_decl(). */
18137 gen_array_type_die (tree type, dw_die_ref context_die)
18139 dw_die_ref scope_die = scope_die_for (type, context_die);
18140 dw_die_ref array_die;
18142 /* GNU compilers represent multidimensional array types as sequences of one
18143 dimensional array types whose element types are themselves array types.
18144 We sometimes squish that down to a single array_type DIE with multiple
18145 subscripts in the Dwarf debugging info. The draft Dwarf specification
18146 say that we are allowed to do this kind of compression in C, because
18147 there is no difference between an array of arrays and a multidimensional
18148 array. We don't do this for Ada to remain as close as possible to the
18149 actual representation, which is especially important against the language
18150 flexibilty wrt arrays of variable size. */
18152 bool collapse_nested_arrays = !is_ada ();
18155 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18156 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18157 if (TYPE_STRING_FLAG (type)
18158 && TREE_CODE (type) == ARRAY_TYPE
18160 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18162 HOST_WIDE_INT size;
18164 array_die = new_die (DW_TAG_string_type, scope_die, type);
18165 add_name_attribute (array_die, type_tag (type));
18166 equate_type_number_to_die (type, array_die);
18167 size = int_size_in_bytes (type);
18169 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18170 else if (TYPE_DOMAIN (type) != NULL_TREE
18171 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18172 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18174 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18175 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18177 size = int_size_in_bytes (TREE_TYPE (szdecl));
18178 if (loc && size > 0)
18180 add_AT_location_description (array_die, DW_AT_string_length, loc);
18181 if (size != DWARF2_ADDR_SIZE)
18182 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18188 /* ??? The SGI dwarf reader fails for array of array of enum types
18189 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18190 array type comes before the outer array type. We thus call gen_type_die
18191 before we new_die and must prevent nested array types collapsing for this
18194 #ifdef MIPS_DEBUGGING_INFO
18195 gen_type_die (TREE_TYPE (type), context_die);
18196 collapse_nested_arrays = false;
18199 array_die = new_die (DW_TAG_array_type, scope_die, type);
18200 add_name_attribute (array_die, type_tag (type));
18201 equate_type_number_to_die (type, array_die);
18203 if (TREE_CODE (type) == VECTOR_TYPE)
18204 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18206 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18208 && TREE_CODE (type) == ARRAY_TYPE
18209 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18210 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18211 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18214 /* We default the array ordering. SDB will probably do
18215 the right things even if DW_AT_ordering is not present. It's not even
18216 an issue until we start to get into multidimensional arrays anyway. If
18217 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18218 then we'll have to put the DW_AT_ordering attribute back in. (But if
18219 and when we find out that we need to put these in, we will only do so
18220 for multidimensional arrays. */
18221 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18224 #ifdef MIPS_DEBUGGING_INFO
18225 /* The SGI compilers handle arrays of unknown bound by setting
18226 AT_declaration and not emitting any subrange DIEs. */
18227 if (TREE_CODE (type) == ARRAY_TYPE
18228 && ! TYPE_DOMAIN (type))
18229 add_AT_flag (array_die, DW_AT_declaration, 1);
18232 if (TREE_CODE (type) == VECTOR_TYPE)
18234 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18235 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18236 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18237 add_bound_info (subrange_die, DW_AT_upper_bound,
18238 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18241 add_subscript_info (array_die, type, collapse_nested_arrays);
18243 /* Add representation of the type of the elements of this array type and
18244 emit the corresponding DIE if we haven't done it already. */
18245 element_type = TREE_TYPE (type);
18246 if (collapse_nested_arrays)
18247 while (TREE_CODE (element_type) == ARRAY_TYPE)
18249 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18251 element_type = TREE_TYPE (element_type);
18254 #ifndef MIPS_DEBUGGING_INFO
18255 gen_type_die (element_type, context_die);
18258 add_type_attribute (array_die, element_type, 0, 0, context_die);
18260 if (get_AT (array_die, DW_AT_name))
18261 add_pubtype (type, array_die);
18264 static dw_loc_descr_ref
18265 descr_info_loc (tree val, tree base_decl)
18267 HOST_WIDE_INT size;
18268 dw_loc_descr_ref loc, loc2;
18269 enum dwarf_location_atom op;
18271 if (val == base_decl)
18272 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18274 switch (TREE_CODE (val))
18277 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18279 return loc_descriptor_from_tree (val, 0);
18281 if (host_integerp (val, 0))
18282 return int_loc_descriptor (tree_low_cst (val, 0));
18285 size = int_size_in_bytes (TREE_TYPE (val));
18288 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18291 if (size == DWARF2_ADDR_SIZE)
18292 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18294 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18296 case POINTER_PLUS_EXPR:
18298 if (host_integerp (TREE_OPERAND (val, 1), 1)
18299 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18302 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18305 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18311 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18314 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18317 add_loc_descr (&loc, loc2);
18318 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18340 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18341 tree val, tree base_decl)
18343 dw_loc_descr_ref loc;
18345 if (host_integerp (val, 0))
18347 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18351 loc = descr_info_loc (val, base_decl);
18355 add_AT_loc (die, attr, loc);
18358 /* This routine generates DIE for array with hidden descriptor, details
18359 are filled into *info by a langhook. */
18362 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18363 dw_die_ref context_die)
18365 dw_die_ref scope_die = scope_die_for (type, context_die);
18366 dw_die_ref array_die;
18369 array_die = new_die (DW_TAG_array_type, scope_die, type);
18370 add_name_attribute (array_die, type_tag (type));
18371 equate_type_number_to_die (type, array_die);
18373 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18375 && info->ndimensions >= 2)
18376 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18378 if (info->data_location)
18379 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18381 if (info->associated)
18382 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18384 if (info->allocated)
18385 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18388 for (dim = 0; dim < info->ndimensions; dim++)
18390 dw_die_ref subrange_die
18391 = new_die (DW_TAG_subrange_type, array_die, NULL);
18393 if (info->dimen[dim].lower_bound)
18395 /* If it is the default value, omit it. */
18398 if (host_integerp (info->dimen[dim].lower_bound, 0)
18399 && (dflt = lower_bound_default ()) != -1
18400 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18403 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18404 info->dimen[dim].lower_bound,
18407 if (info->dimen[dim].upper_bound)
18408 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18409 info->dimen[dim].upper_bound,
18411 if (info->dimen[dim].stride)
18412 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18413 info->dimen[dim].stride,
18417 gen_type_die (info->element_type, context_die);
18418 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18420 if (get_AT (array_die, DW_AT_name))
18421 add_pubtype (type, array_die);
18426 gen_entry_point_die (tree decl, dw_die_ref context_die)
18428 tree origin = decl_ultimate_origin (decl);
18429 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18431 if (origin != NULL)
18432 add_abstract_origin_attribute (decl_die, origin);
18435 add_name_and_src_coords_attributes (decl_die, decl);
18436 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18437 0, 0, context_die);
18440 if (DECL_ABSTRACT (decl))
18441 equate_decl_number_to_die (decl, decl_die);
18443 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18447 /* Walk through the list of incomplete types again, trying once more to
18448 emit full debugging info for them. */
18451 retry_incomplete_types (void)
18455 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18456 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18457 DINFO_USAGE_DIR_USE))
18458 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
18461 /* Determine what tag to use for a record type. */
18463 static enum dwarf_tag
18464 record_type_tag (tree type)
18466 if (! lang_hooks.types.classify_record)
18467 return DW_TAG_structure_type;
18469 switch (lang_hooks.types.classify_record (type))
18471 case RECORD_IS_STRUCT:
18472 return DW_TAG_structure_type;
18474 case RECORD_IS_CLASS:
18475 return DW_TAG_class_type;
18477 case RECORD_IS_INTERFACE:
18478 if (dwarf_version >= 3 || !dwarf_strict)
18479 return DW_TAG_interface_type;
18480 return DW_TAG_structure_type;
18483 gcc_unreachable ();
18487 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18488 include all of the information about the enumeration values also. Each
18489 enumerated type name/value is listed as a child of the enumerated type
18493 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18495 dw_die_ref type_die = lookup_type_die (type);
18497 if (type_die == NULL)
18499 type_die = new_die (DW_TAG_enumeration_type,
18500 scope_die_for (type, context_die), type);
18501 equate_type_number_to_die (type, type_die);
18502 add_name_attribute (type_die, type_tag (type));
18503 if (dwarf_version >= 4 || !dwarf_strict)
18505 if (ENUM_IS_SCOPED (type))
18506 add_AT_flag (type_die, DW_AT_enum_class, 1);
18507 if (ENUM_IS_OPAQUE (type))
18508 add_AT_flag (type_die, DW_AT_declaration, 1);
18511 else if (! TYPE_SIZE (type))
18514 remove_AT (type_die, DW_AT_declaration);
18516 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18517 given enum type is incomplete, do not generate the DW_AT_byte_size
18518 attribute or the DW_AT_element_list attribute. */
18519 if (TYPE_SIZE (type))
18523 TREE_ASM_WRITTEN (type) = 1;
18524 add_byte_size_attribute (type_die, type);
18525 if (TYPE_STUB_DECL (type) != NULL_TREE)
18527 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18528 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18531 /* If the first reference to this type was as the return type of an
18532 inline function, then it may not have a parent. Fix this now. */
18533 if (type_die->die_parent == NULL)
18534 add_child_die (scope_die_for (type, context_die), type_die);
18536 for (link = TYPE_VALUES (type);
18537 link != NULL; link = TREE_CHAIN (link))
18539 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18540 tree value = TREE_VALUE (link);
18542 add_name_attribute (enum_die,
18543 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18545 if (TREE_CODE (value) == CONST_DECL)
18546 value = DECL_INITIAL (value);
18548 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18549 /* DWARF2 does not provide a way of indicating whether or
18550 not enumeration constants are signed or unsigned. GDB
18551 always assumes the values are signed, so we output all
18552 values as if they were signed. That means that
18553 enumeration constants with very large unsigned values
18554 will appear to have negative values in the debugger. */
18555 add_AT_int (enum_die, DW_AT_const_value,
18556 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18560 add_AT_flag (type_die, DW_AT_declaration, 1);
18562 if (get_AT (type_die, DW_AT_name))
18563 add_pubtype (type, type_die);
18568 /* Generate a DIE to represent either a real live formal parameter decl or to
18569 represent just the type of some formal parameter position in some function
18572 Note that this routine is a bit unusual because its argument may be a
18573 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18574 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18575 node. If it's the former then this function is being called to output a
18576 DIE to represent a formal parameter object (or some inlining thereof). If
18577 it's the latter, then this function is only being called to output a
18578 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18579 argument type of some subprogram type.
18580 If EMIT_NAME_P is true, name and source coordinate attributes
18584 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18585 dw_die_ref context_die)
18587 tree node_or_origin = node ? node : origin;
18588 tree ultimate_origin;
18589 dw_die_ref parm_die
18590 = new_die (DW_TAG_formal_parameter, context_die, node);
18592 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18594 case tcc_declaration:
18595 ultimate_origin = decl_ultimate_origin (node_or_origin);
18596 if (node || ultimate_origin)
18597 origin = ultimate_origin;
18598 if (origin != NULL)
18599 add_abstract_origin_attribute (parm_die, origin);
18600 else if (emit_name_p)
18601 add_name_and_src_coords_attributes (parm_die, node);
18603 || (! DECL_ABSTRACT (node_or_origin)
18604 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18605 decl_function_context
18606 (node_or_origin))))
18608 tree type = TREE_TYPE (node_or_origin);
18609 if (decl_by_reference_p (node_or_origin))
18610 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18613 add_type_attribute (parm_die, type,
18614 TREE_READONLY (node_or_origin),
18615 TREE_THIS_VOLATILE (node_or_origin),
18618 if (origin == NULL && DECL_ARTIFICIAL (node))
18619 add_AT_flag (parm_die, DW_AT_artificial, 1);
18621 if (node && node != origin)
18622 equate_decl_number_to_die (node, parm_die);
18623 if (! DECL_ABSTRACT (node_or_origin))
18624 add_location_or_const_value_attribute (parm_die, node_or_origin,
18630 /* We were called with some kind of a ..._TYPE node. */
18631 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18635 gcc_unreachable ();
18641 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18642 children DW_TAG_formal_parameter DIEs representing the arguments of the
18645 PARM_PACK must be a function parameter pack.
18646 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18647 must point to the subsequent arguments of the function PACK_ARG belongs to.
18648 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18649 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18650 following the last one for which a DIE was generated. */
18653 gen_formal_parameter_pack_die (tree parm_pack,
18655 dw_die_ref subr_die,
18659 dw_die_ref parm_pack_die;
18661 gcc_assert (parm_pack
18662 && lang_hooks.function_parameter_pack_p (parm_pack)
18665 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18666 add_src_coords_attributes (parm_pack_die, parm_pack);
18668 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18670 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18673 gen_formal_parameter_die (arg, NULL,
18674 false /* Don't emit name attribute. */,
18679 return parm_pack_die;
18682 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18683 at the end of an (ANSI prototyped) formal parameters list. */
18686 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18688 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18691 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18692 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18693 parameters as specified in some function type specification (except for
18694 those which appear as part of a function *definition*). */
18697 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18700 tree formal_type = NULL;
18701 tree first_parm_type;
18704 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18706 arg = DECL_ARGUMENTS (function_or_method_type);
18707 function_or_method_type = TREE_TYPE (function_or_method_type);
18712 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18714 /* Make our first pass over the list of formal parameter types and output a
18715 DW_TAG_formal_parameter DIE for each one. */
18716 for (link = first_parm_type; link; )
18718 dw_die_ref parm_die;
18720 formal_type = TREE_VALUE (link);
18721 if (formal_type == void_type_node)
18724 /* Output a (nameless) DIE to represent the formal parameter itself. */
18725 parm_die = gen_formal_parameter_die (formal_type, NULL,
18726 true /* Emit name attribute. */,
18728 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18729 && link == first_parm_type)
18731 add_AT_flag (parm_die, DW_AT_artificial, 1);
18732 if (dwarf_version >= 3 || !dwarf_strict)
18733 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18735 else if (arg && DECL_ARTIFICIAL (arg))
18736 add_AT_flag (parm_die, DW_AT_artificial, 1);
18738 link = TREE_CHAIN (link);
18740 arg = DECL_CHAIN (arg);
18743 /* If this function type has an ellipsis, add a
18744 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18745 if (formal_type != void_type_node)
18746 gen_unspecified_parameters_die (function_or_method_type, context_die);
18748 /* Make our second (and final) pass over the list of formal parameter types
18749 and output DIEs to represent those types (as necessary). */
18750 for (link = TYPE_ARG_TYPES (function_or_method_type);
18751 link && TREE_VALUE (link);
18752 link = TREE_CHAIN (link))
18753 gen_type_die (TREE_VALUE (link), context_die);
18756 /* We want to generate the DIE for TYPE so that we can generate the
18757 die for MEMBER, which has been defined; we will need to refer back
18758 to the member declaration nested within TYPE. If we're trying to
18759 generate minimal debug info for TYPE, processing TYPE won't do the
18760 trick; we need to attach the member declaration by hand. */
18763 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18765 gen_type_die (type, context_die);
18767 /* If we're trying to avoid duplicate debug info, we may not have
18768 emitted the member decl for this function. Emit it now. */
18769 if (TYPE_STUB_DECL (type)
18770 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18771 && ! lookup_decl_die (member))
18773 dw_die_ref type_die;
18774 gcc_assert (!decl_ultimate_origin (member));
18776 push_decl_scope (type);
18777 type_die = lookup_type_die_strip_naming_typedef (type);
18778 if (TREE_CODE (member) == FUNCTION_DECL)
18779 gen_subprogram_die (member, type_die);
18780 else if (TREE_CODE (member) == FIELD_DECL)
18782 /* Ignore the nameless fields that are used to skip bits but handle
18783 C++ anonymous unions and structs. */
18784 if (DECL_NAME (member) != NULL_TREE
18785 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18786 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18788 gen_type_die (member_declared_type (member), type_die);
18789 gen_field_die (member, type_die);
18793 gen_variable_die (member, NULL_TREE, type_die);
18799 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18800 may later generate inlined and/or out-of-line instances of. */
18803 dwarf2out_abstract_function (tree decl)
18805 dw_die_ref old_die;
18809 htab_t old_decl_loc_table;
18810 int old_call_site_count, old_tail_call_site_count;
18811 struct call_arg_loc_node *old_call_arg_locations;
18813 /* Make sure we have the actual abstract inline, not a clone. */
18814 decl = DECL_ORIGIN (decl);
18816 old_die = lookup_decl_die (decl);
18817 if (old_die && get_AT (old_die, DW_AT_inline))
18818 /* We've already generated the abstract instance. */
18821 /* We can be called while recursively when seeing block defining inlined subroutine
18822 DIE. Be sure to not clobber the outer location table nor use it or we would
18823 get locations in abstract instantces. */
18824 old_decl_loc_table = decl_loc_table;
18825 decl_loc_table = NULL;
18826 old_call_arg_locations = call_arg_locations;
18827 call_arg_locations = NULL;
18828 old_call_site_count = call_site_count;
18829 call_site_count = -1;
18830 old_tail_call_site_count = tail_call_site_count;
18831 tail_call_site_count = -1;
18833 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18834 we don't get confused by DECL_ABSTRACT. */
18835 if (debug_info_level > DINFO_LEVEL_TERSE)
18837 context = decl_class_context (decl);
18839 gen_type_die_for_member
18840 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18843 /* Pretend we've just finished compiling this function. */
18844 save_fn = current_function_decl;
18845 current_function_decl = decl;
18846 push_cfun (DECL_STRUCT_FUNCTION (decl));
18848 was_abstract = DECL_ABSTRACT (decl);
18849 set_decl_abstract_flags (decl, 1);
18850 dwarf2out_decl (decl);
18851 if (! was_abstract)
18852 set_decl_abstract_flags (decl, 0);
18854 current_function_decl = save_fn;
18855 decl_loc_table = old_decl_loc_table;
18856 call_arg_locations = old_call_arg_locations;
18857 call_site_count = old_call_site_count;
18858 tail_call_site_count = old_tail_call_site_count;
18862 /* Helper function of premark_used_types() which gets called through
18865 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18866 marked as unused by prune_unused_types. */
18869 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
18874 type = (tree) *slot;
18875 die = lookup_type_die (type);
18877 die->die_perennial_p = 1;
18881 /* Helper function of premark_types_used_by_global_vars which gets called
18882 through htab_traverse.
18884 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18885 marked as unused by prune_unused_types. The DIE of the type is marked
18886 only if the global variable using the type will actually be emitted. */
18889 premark_types_used_by_global_vars_helper (void **slot,
18890 void *data ATTRIBUTE_UNUSED)
18892 struct types_used_by_vars_entry *entry;
18895 entry = (struct types_used_by_vars_entry *) *slot;
18896 gcc_assert (entry->type != NULL
18897 && entry->var_decl != NULL);
18898 die = lookup_type_die (entry->type);
18901 /* Ask cgraph if the global variable really is to be emitted.
18902 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18903 struct varpool_node *node = varpool_get_node (entry->var_decl);
18904 if (node && node->needed)
18906 die->die_perennial_p = 1;
18907 /* Keep the parent DIEs as well. */
18908 while ((die = die->die_parent) && die->die_perennial_p == 0)
18909 die->die_perennial_p = 1;
18915 /* Mark all members of used_types_hash as perennial. */
18918 premark_used_types (void)
18920 if (cfun && cfun->used_types_hash)
18921 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
18924 /* Mark all members of types_used_by_vars_entry as perennial. */
18927 premark_types_used_by_global_vars (void)
18929 if (types_used_by_vars_hash)
18930 htab_traverse (types_used_by_vars_hash,
18931 premark_types_used_by_global_vars_helper, NULL);
18934 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18935 for CA_LOC call arg loc node. */
18938 gen_call_site_die (tree decl, dw_die_ref subr_die,
18939 struct call_arg_loc_node *ca_loc)
18941 dw_die_ref stmt_die = NULL, die;
18942 tree block = ca_loc->block;
18945 && block != DECL_INITIAL (decl)
18946 && TREE_CODE (block) == BLOCK)
18948 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
18949 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
18952 block = BLOCK_SUPERCONTEXT (block);
18954 if (stmt_die == NULL)
18955 stmt_die = subr_die;
18956 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
18957 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
18958 if (ca_loc->tail_call_p)
18959 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
18960 if (ca_loc->symbol_ref)
18962 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
18964 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
18966 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
18971 /* Generate a DIE to represent a declared function (either file-scope or
18975 gen_subprogram_die (tree decl, dw_die_ref context_die)
18977 tree origin = decl_ultimate_origin (decl);
18978 dw_die_ref subr_die;
18980 dw_die_ref old_die = lookup_decl_die (decl);
18981 int declaration = (current_function_decl != decl
18982 || class_or_namespace_scope_p (context_die));
18984 premark_used_types ();
18986 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18987 started to generate the abstract instance of an inline, decided to output
18988 its containing class, and proceeded to emit the declaration of the inline
18989 from the member list for the class. If so, DECLARATION takes priority;
18990 we'll get back to the abstract instance when done with the class. */
18992 /* The class-scope declaration DIE must be the primary DIE. */
18993 if (origin && declaration && class_or_namespace_scope_p (context_die))
18996 gcc_assert (!old_die);
18999 /* Now that the C++ front end lazily declares artificial member fns, we
19000 might need to retrofit the declaration into its class. */
19001 if (!declaration && !origin && !old_die
19002 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
19003 && !class_or_namespace_scope_p (context_die)
19004 && debug_info_level > DINFO_LEVEL_TERSE)
19005 old_die = force_decl_die (decl);
19007 if (origin != NULL)
19009 gcc_assert (!declaration || local_scope_p (context_die));
19011 /* Fixup die_parent for the abstract instance of a nested
19012 inline function. */
19013 if (old_die && old_die->die_parent == NULL)
19014 add_child_die (context_die, old_die);
19016 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19017 add_abstract_origin_attribute (subr_die, origin);
19021 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19022 struct dwarf_file_data * file_index = lookup_filename (s.file);
19024 if (!get_AT_flag (old_die, DW_AT_declaration)
19025 /* We can have a normal definition following an inline one in the
19026 case of redefinition of GNU C extern inlines.
19027 It seems reasonable to use AT_specification in this case. */
19028 && !get_AT (old_die, DW_AT_inline))
19030 /* Detect and ignore this case, where we are trying to output
19031 something we have already output. */
19035 /* If the definition comes from the same place as the declaration,
19036 maybe use the old DIE. We always want the DIE for this function
19037 that has the *_pc attributes to be under comp_unit_die so the
19038 debugger can find it. We also need to do this for abstract
19039 instances of inlines, since the spec requires the out-of-line copy
19040 to have the same parent. For local class methods, this doesn't
19041 apply; we just use the old DIE. */
19042 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
19043 && (DECL_ARTIFICIAL (decl)
19044 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
19045 && (get_AT_unsigned (old_die, DW_AT_decl_line)
19046 == (unsigned) s.line))))
19048 subr_die = old_die;
19050 /* Clear out the declaration attribute and the formal parameters.
19051 Do not remove all children, because it is possible that this
19052 declaration die was forced using force_decl_die(). In such
19053 cases die that forced declaration die (e.g. TAG_imported_module)
19054 is one of the children that we do not want to remove. */
19055 remove_AT (subr_die, DW_AT_declaration);
19056 remove_AT (subr_die, DW_AT_object_pointer);
19057 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
19061 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19062 add_AT_specification (subr_die, old_die);
19063 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19064 add_AT_file (subr_die, DW_AT_decl_file, file_index);
19065 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19066 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
19071 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19073 if (TREE_PUBLIC (decl))
19074 add_AT_flag (subr_die, DW_AT_external, 1);
19076 add_name_and_src_coords_attributes (subr_die, decl);
19077 if (debug_info_level > DINFO_LEVEL_TERSE)
19079 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
19080 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
19081 0, 0, context_die);
19084 add_pure_or_virtual_attribute (subr_die, decl);
19085 if (DECL_ARTIFICIAL (decl))
19086 add_AT_flag (subr_die, DW_AT_artificial, 1);
19088 add_accessibility_attribute (subr_die, decl);
19093 if (!old_die || !get_AT (old_die, DW_AT_inline))
19095 add_AT_flag (subr_die, DW_AT_declaration, 1);
19097 /* If this is an explicit function declaration then generate
19098 a DW_AT_explicit attribute. */
19099 if (lang_hooks.decls.function_decl_explicit_p (decl)
19100 && (dwarf_version >= 3 || !dwarf_strict))
19101 add_AT_flag (subr_die, DW_AT_explicit, 1);
19103 /* The first time we see a member function, it is in the context of
19104 the class to which it belongs. We make sure of this by emitting
19105 the class first. The next time is the definition, which is
19106 handled above. The two may come from the same source text.
19108 Note that force_decl_die() forces function declaration die. It is
19109 later reused to represent definition. */
19110 equate_decl_number_to_die (decl, subr_die);
19113 else if (DECL_ABSTRACT (decl))
19115 if (DECL_DECLARED_INLINE_P (decl))
19117 if (cgraph_function_possibly_inlined_p (decl))
19118 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19120 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19124 if (cgraph_function_possibly_inlined_p (decl))
19125 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19127 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19130 if (DECL_DECLARED_INLINE_P (decl)
19131 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19132 add_AT_flag (subr_die, DW_AT_artificial, 1);
19134 equate_decl_number_to_die (decl, subr_die);
19136 else if (!DECL_EXTERNAL (decl))
19138 HOST_WIDE_INT cfa_fb_offset;
19140 if (!old_die || !get_AT (old_die, DW_AT_inline))
19141 equate_decl_number_to_die (decl, subr_die);
19143 if (!flag_reorder_blocks_and_partition)
19145 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19146 if (fde->dw_fde_begin)
19148 /* We have already generated the labels. */
19149 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19150 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19154 /* Create start/end labels and add the range. */
19155 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
19156 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19157 current_function_funcdef_no);
19158 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19159 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19160 current_function_funcdef_no);
19161 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19164 #if VMS_DEBUGGING_INFO
19165 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19166 Section 2.3 Prologue and Epilogue Attributes:
19167 When a breakpoint is set on entry to a function, it is generally
19168 desirable for execution to be suspended, not on the very first
19169 instruction of the function, but rather at a point after the
19170 function's frame has been set up, after any language defined local
19171 declaration processing has been completed, and before execution of
19172 the first statement of the function begins. Debuggers generally
19173 cannot properly determine where this point is. Similarly for a
19174 breakpoint set on exit from a function. The prologue and epilogue
19175 attributes allow a compiler to communicate the location(s) to use. */
19178 if (fde->dw_fde_vms_end_prologue)
19179 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19180 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19182 if (fde->dw_fde_vms_begin_epilogue)
19183 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19184 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19188 add_pubname (decl, subr_die);
19189 add_arange (decl, subr_die);
19192 { /* Generate pubnames entries for the split function code
19194 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19196 if (fde->dw_fde_switched_sections)
19198 if (dwarf_version >= 3 || !dwarf_strict)
19200 /* We should use ranges for non-contiguous code section
19201 addresses. Use the actual code range for the initial
19202 section, since the HOT/COLD labels might precede an
19203 alignment offset. */
19204 bool range_list_added = false;
19205 if (fde->in_std_section)
19207 add_ranges_by_labels (subr_die,
19210 &range_list_added);
19211 add_ranges_by_labels (subr_die,
19212 fde->dw_fde_unlikely_section_label,
19213 fde->dw_fde_unlikely_section_end_label,
19214 &range_list_added);
19218 add_ranges_by_labels (subr_die,
19221 &range_list_added);
19222 add_ranges_by_labels (subr_die,
19223 fde->dw_fde_hot_section_label,
19224 fde->dw_fde_hot_section_end_label,
19225 &range_list_added);
19227 add_pubname (decl, subr_die);
19228 if (range_list_added)
19233 /* There is no real support in DW2 for this .. so we make
19234 a work-around. First, emit the pub name for the segment
19235 containing the function label. Then make and emit a
19236 simplified subprogram DIE for the second segment with the
19237 name pre-fixed by __hot/cold_sect_of_. We use the same
19238 linkage name for the second die so that gdb will find both
19239 sections when given "b foo". */
19240 const char *name = NULL;
19241 tree decl_name = DECL_NAME (decl);
19242 dw_die_ref seg_die;
19244 /* Do the 'primary' section. */
19245 add_AT_lbl_id (subr_die, DW_AT_low_pc,
19246 fde->dw_fde_begin);
19247 add_AT_lbl_id (subr_die, DW_AT_high_pc,
19250 add_pubname (decl, subr_die);
19251 add_arange (decl, subr_die);
19253 /* Build a minimal DIE for the secondary section. */
19254 seg_die = new_die (DW_TAG_subprogram,
19255 subr_die->die_parent, decl);
19257 if (TREE_PUBLIC (decl))
19258 add_AT_flag (seg_die, DW_AT_external, 1);
19260 if (decl_name != NULL
19261 && IDENTIFIER_POINTER (decl_name) != NULL)
19263 name = dwarf2_name (decl, 1);
19264 if (! DECL_ARTIFICIAL (decl))
19265 add_src_coords_attributes (seg_die, decl);
19267 add_linkage_name (seg_die, decl);
19269 gcc_assert (name!=NULL);
19270 add_pure_or_virtual_attribute (seg_die, decl);
19271 if (DECL_ARTIFICIAL (decl))
19272 add_AT_flag (seg_die, DW_AT_artificial, 1);
19274 if (fde->in_std_section)
19276 name = concat ("__cold_sect_of_", name, NULL);
19277 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19278 fde->dw_fde_unlikely_section_label);
19279 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19280 fde->dw_fde_unlikely_section_end_label);
19284 name = concat ("__hot_sect_of_", name, NULL);
19285 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19286 fde->dw_fde_hot_section_label);
19287 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19288 fde->dw_fde_hot_section_end_label);
19290 add_name_attribute (seg_die, name);
19291 add_pubname_string (name, seg_die);
19292 add_arange (decl, seg_die);
19297 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19298 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19299 add_pubname (decl, subr_die);
19300 add_arange (decl, subr_die);
19304 #ifdef MIPS_DEBUGGING_INFO
19305 /* Add a reference to the FDE for this routine. */
19306 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19309 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19311 /* We define the "frame base" as the function's CFA. This is more
19312 convenient for several reasons: (1) It's stable across the prologue
19313 and epilogue, which makes it better than just a frame pointer,
19314 (2) With dwarf3, there exists a one-byte encoding that allows us
19315 to reference the .debug_frame data by proxy, but failing that,
19316 (3) We can at least reuse the code inspection and interpretation
19317 code that determines the CFA position at various points in the
19319 if (dwarf_version >= 3)
19321 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19322 add_AT_loc (subr_die, DW_AT_frame_base, op);
19326 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19327 if (list->dw_loc_next)
19328 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19330 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19333 /* Compute a displacement from the "steady-state frame pointer" to
19334 the CFA. The former is what all stack slots and argument slots
19335 will reference in the rtl; the later is what we've told the
19336 debugger about. We'll need to adjust all frame_base references
19337 by this displacement. */
19338 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19340 if (cfun->static_chain_decl)
19341 add_AT_location_description (subr_die, DW_AT_static_link,
19342 loc_list_from_tree (cfun->static_chain_decl, 2));
19345 /* Generate child dies for template paramaters. */
19346 if (debug_info_level > DINFO_LEVEL_TERSE)
19347 gen_generic_params_dies (decl);
19349 /* Now output descriptions of the arguments for this function. This gets
19350 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19351 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19352 `...' at the end of the formal parameter list. In order to find out if
19353 there was a trailing ellipsis or not, we must instead look at the type
19354 associated with the FUNCTION_DECL. This will be a node of type
19355 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19356 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19357 an ellipsis at the end. */
19359 /* In the case where we are describing a mere function declaration, all we
19360 need to do here (and all we *can* do here) is to describe the *types* of
19361 its formal parameters. */
19362 if (debug_info_level <= DINFO_LEVEL_TERSE)
19364 else if (declaration)
19365 gen_formal_types_die (decl, subr_die);
19368 /* Generate DIEs to represent all known formal parameters. */
19369 tree parm = DECL_ARGUMENTS (decl);
19370 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19371 tree generic_decl_parm = generic_decl
19372 ? DECL_ARGUMENTS (generic_decl)
19375 /* Now we want to walk the list of parameters of the function and
19376 emit their relevant DIEs.
19378 We consider the case of DECL being an instance of a generic function
19379 as well as it being a normal function.
19381 If DECL is an instance of a generic function we walk the
19382 parameters of the generic function declaration _and_ the parameters of
19383 DECL itself. This is useful because we want to emit specific DIEs for
19384 function parameter packs and those are declared as part of the
19385 generic function declaration. In that particular case,
19386 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19387 That DIE has children DIEs representing the set of arguments
19388 of the pack. Note that the set of pack arguments can be empty.
19389 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19392 Otherwise, we just consider the parameters of DECL. */
19393 while (generic_decl_parm || parm)
19395 if (generic_decl_parm
19396 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19397 gen_formal_parameter_pack_die (generic_decl_parm,
19402 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19404 if (parm == DECL_ARGUMENTS (decl)
19405 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19407 && (dwarf_version >= 3 || !dwarf_strict))
19408 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19410 parm = DECL_CHAIN (parm);
19413 if (generic_decl_parm)
19414 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19417 /* Decide whether we need an unspecified_parameters DIE at the end.
19418 There are 2 more cases to do this for: 1) the ansi ... declaration -
19419 this is detectable when the end of the arg list is not a
19420 void_type_node 2) an unprototyped function declaration (not a
19421 definition). This just means that we have no info about the
19422 parameters at all. */
19423 if (prototype_p (TREE_TYPE (decl)))
19425 /* This is the prototyped case, check for.... */
19426 if (stdarg_p (TREE_TYPE (decl)))
19427 gen_unspecified_parameters_die (decl, subr_die);
19429 else if (DECL_INITIAL (decl) == NULL_TREE)
19430 gen_unspecified_parameters_die (decl, subr_die);
19433 /* Output Dwarf info for all of the stuff within the body of the function
19434 (if it has one - it may be just a declaration). */
19435 outer_scope = DECL_INITIAL (decl);
19437 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19438 a function. This BLOCK actually represents the outermost binding contour
19439 for the function, i.e. the contour in which the function's formal
19440 parameters and labels get declared. Curiously, it appears that the front
19441 end doesn't actually put the PARM_DECL nodes for the current function onto
19442 the BLOCK_VARS list for this outer scope, but are strung off of the
19443 DECL_ARGUMENTS list for the function instead.
19445 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19446 the LABEL_DECL nodes for the function however, and we output DWARF info
19447 for those in decls_for_scope. Just within the `outer_scope' there will be
19448 a BLOCK node representing the function's outermost pair of curly braces,
19449 and any blocks used for the base and member initializers of a C++
19450 constructor function. */
19451 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19453 int call_site_note_count = 0;
19454 int tail_call_site_note_count = 0;
19456 /* Emit a DW_TAG_variable DIE for a named return value. */
19457 if (DECL_NAME (DECL_RESULT (decl)))
19458 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19460 current_function_has_inlines = 0;
19461 decls_for_scope (outer_scope, subr_die, 0);
19463 if (call_arg_locations && !dwarf_strict)
19465 struct call_arg_loc_node *ca_loc;
19466 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
19468 dw_die_ref die = NULL;
19469 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
19472 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
19473 arg; arg = next_arg)
19475 dw_loc_descr_ref reg, val;
19476 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
19479 next_arg = XEXP (arg, 1);
19480 if (REG_P (XEXP (XEXP (arg, 0), 0))
19482 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
19483 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
19484 && REGNO (XEXP (XEXP (arg, 0), 0))
19485 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
19486 next_arg = XEXP (next_arg, 1);
19487 if (mode == VOIDmode)
19489 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
19490 if (mode == VOIDmode)
19491 mode = GET_MODE (XEXP (arg, 0));
19493 if (GET_MODE_CLASS (mode) != MODE_INT
19494 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
19496 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
19498 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19499 tloc = XEXP (XEXP (arg, 0), 1);
19502 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
19503 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
19505 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19506 tlocc = XEXP (XEXP (arg, 0), 1);
19509 if (REG_P (XEXP (XEXP (arg, 0), 0)))
19510 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
19511 VAR_INIT_STATUS_INITIALIZED);
19512 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
19513 reg = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 0),
19515 VAR_INIT_STATUS_INITIALIZED);
19520 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), VOIDmode,
19521 VAR_INIT_STATUS_INITIALIZED);
19525 die = gen_call_site_die (decl, subr_die, ca_loc);
19526 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
19528 add_AT_loc (cdie, DW_AT_location, reg);
19529 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
19530 if (next_arg != XEXP (arg, 1))
19532 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
19534 VAR_INIT_STATUS_INITIALIZED);
19536 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
19540 && (ca_loc->symbol_ref || tloc))
19541 die = gen_call_site_die (decl, subr_die, ca_loc);
19542 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
19544 dw_loc_descr_ref tval = NULL;
19546 if (tloc != NULL_RTX)
19547 tval = mem_loc_descriptor (tloc, VOIDmode,
19548 VAR_INIT_STATUS_INITIALIZED);
19550 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
19551 else if (tlocc != NULL_RTX)
19553 tval = mem_loc_descriptor (tlocc, VOIDmode,
19554 VAR_INIT_STATUS_INITIALIZED);
19556 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
19562 call_site_note_count++;
19563 if (ca_loc->tail_call_p)
19564 tail_call_site_note_count++;
19568 call_arg_locations = NULL;
19569 call_arg_loc_last = NULL;
19570 if (tail_call_site_count >= 0
19571 && tail_call_site_count == tail_call_site_note_count
19574 if (call_site_count >= 0
19575 && call_site_count == call_site_note_count)
19576 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
19578 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
19580 call_site_count = -1;
19581 tail_call_site_count = -1;
19583 /* Add the calling convention attribute if requested. */
19584 add_calling_convention_attribute (subr_die, decl);
19588 /* Returns a hash value for X (which really is a die_struct). */
19591 common_block_die_table_hash (const void *x)
19593 const_dw_die_ref d = (const_dw_die_ref) x;
19594 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19597 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19598 as decl_id and die_parent of die_struct Y. */
19601 common_block_die_table_eq (const void *x, const void *y)
19603 const_dw_die_ref d = (const_dw_die_ref) x;
19604 const_dw_die_ref e = (const_dw_die_ref) y;
19605 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19608 /* Generate a DIE to represent a declared data object.
19609 Either DECL or ORIGIN must be non-null. */
19612 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19616 tree decl_or_origin = decl ? decl : origin;
19617 tree ultimate_origin;
19618 dw_die_ref var_die;
19619 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19620 dw_die_ref origin_die;
19621 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19622 || class_or_namespace_scope_p (context_die));
19623 bool specialization_p = false;
19625 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19626 if (decl || ultimate_origin)
19627 origin = ultimate_origin;
19628 com_decl = fortran_common (decl_or_origin, &off);
19630 /* Symbol in common gets emitted as a child of the common block, in the form
19631 of a data member. */
19634 dw_die_ref com_die;
19635 dw_loc_list_ref loc;
19636 die_node com_die_arg;
19638 var_die = lookup_decl_die (decl_or_origin);
19641 if (get_AT (var_die, DW_AT_location) == NULL)
19643 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19648 /* Optimize the common case. */
19649 if (single_element_loc_list_p (loc)
19650 && loc->expr->dw_loc_opc == DW_OP_addr
19651 && loc->expr->dw_loc_next == NULL
19652 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19654 loc->expr->dw_loc_oprnd1.v.val_addr
19655 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19657 loc_list_plus_const (loc, off);
19659 add_AT_location_description (var_die, DW_AT_location, loc);
19660 remove_AT (var_die, DW_AT_declaration);
19666 if (common_block_die_table == NULL)
19667 common_block_die_table
19668 = htab_create_ggc (10, common_block_die_table_hash,
19669 common_block_die_table_eq, NULL);
19671 com_die_arg.decl_id = DECL_UID (com_decl);
19672 com_die_arg.die_parent = context_die;
19673 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19674 loc = loc_list_from_tree (com_decl, 2);
19675 if (com_die == NULL)
19678 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19681 com_die = new_die (DW_TAG_common_block, context_die, decl);
19682 add_name_and_src_coords_attributes (com_die, com_decl);
19685 add_AT_location_description (com_die, DW_AT_location, loc);
19686 /* Avoid sharing the same loc descriptor between
19687 DW_TAG_common_block and DW_TAG_variable. */
19688 loc = loc_list_from_tree (com_decl, 2);
19690 else if (DECL_EXTERNAL (decl))
19691 add_AT_flag (com_die, DW_AT_declaration, 1);
19692 add_pubname_string (cnam, com_die); /* ??? needed? */
19693 com_die->decl_id = DECL_UID (com_decl);
19694 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19695 *slot = (void *) com_die;
19697 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19699 add_AT_location_description (com_die, DW_AT_location, loc);
19700 loc = loc_list_from_tree (com_decl, 2);
19701 remove_AT (com_die, DW_AT_declaration);
19703 var_die = new_die (DW_TAG_variable, com_die, decl);
19704 add_name_and_src_coords_attributes (var_die, decl);
19705 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19706 TREE_THIS_VOLATILE (decl), context_die);
19707 add_AT_flag (var_die, DW_AT_external, 1);
19712 /* Optimize the common case. */
19713 if (single_element_loc_list_p (loc)
19714 && loc->expr->dw_loc_opc == DW_OP_addr
19715 && loc->expr->dw_loc_next == NULL
19716 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19717 loc->expr->dw_loc_oprnd1.v.val_addr
19718 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19720 loc_list_plus_const (loc, off);
19722 add_AT_location_description (var_die, DW_AT_location, loc);
19724 else if (DECL_EXTERNAL (decl))
19725 add_AT_flag (var_die, DW_AT_declaration, 1);
19726 equate_decl_number_to_die (decl, var_die);
19730 /* If the compiler emitted a definition for the DECL declaration
19731 and if we already emitted a DIE for it, don't emit a second
19732 DIE for it again. Allow re-declarations of DECLs that are
19733 inside functions, though. */
19734 if (old_die && declaration && !local_scope_p (context_die))
19737 /* For static data members, the declaration in the class is supposed
19738 to have DW_TAG_member tag; the specification should still be
19739 DW_TAG_variable referencing the DW_TAG_member DIE. */
19740 if (declaration && class_scope_p (context_die))
19741 var_die = new_die (DW_TAG_member, context_die, decl);
19743 var_die = new_die (DW_TAG_variable, context_die, decl);
19746 if (origin != NULL)
19747 origin_die = add_abstract_origin_attribute (var_die, origin);
19749 /* Loop unrolling can create multiple blocks that refer to the same
19750 static variable, so we must test for the DW_AT_declaration flag.
19752 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19753 copy decls and set the DECL_ABSTRACT flag on them instead of
19756 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19758 ??? The declare_in_namespace support causes us to get two DIEs for one
19759 variable, both of which are declarations. We want to avoid considering
19760 one to be a specification, so we must test that this DIE is not a
19762 else if (old_die && TREE_STATIC (decl) && ! declaration
19763 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19765 /* This is a definition of a C++ class level static. */
19766 add_AT_specification (var_die, old_die);
19767 specialization_p = true;
19768 if (DECL_NAME (decl))
19770 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19771 struct dwarf_file_data * file_index = lookup_filename (s.file);
19773 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19774 add_AT_file (var_die, DW_AT_decl_file, file_index);
19776 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19777 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19779 if (old_die->die_tag == DW_TAG_member)
19780 add_linkage_name (var_die, decl);
19784 add_name_and_src_coords_attributes (var_die, decl);
19786 if ((origin == NULL && !specialization_p)
19788 && !DECL_ABSTRACT (decl_or_origin)
19789 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19790 decl_function_context
19791 (decl_or_origin))))
19793 tree type = TREE_TYPE (decl_or_origin);
19795 if (decl_by_reference_p (decl_or_origin))
19796 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19798 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19799 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19802 if (origin == NULL && !specialization_p)
19804 if (TREE_PUBLIC (decl))
19805 add_AT_flag (var_die, DW_AT_external, 1);
19807 if (DECL_ARTIFICIAL (decl))
19808 add_AT_flag (var_die, DW_AT_artificial, 1);
19810 add_accessibility_attribute (var_die, decl);
19814 add_AT_flag (var_die, DW_AT_declaration, 1);
19816 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19817 equate_decl_number_to_die (decl, var_die);
19820 && (! DECL_ABSTRACT (decl_or_origin)
19821 /* Local static vars are shared between all clones/inlines,
19822 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19824 || (TREE_CODE (decl_or_origin) == VAR_DECL
19825 && TREE_STATIC (decl_or_origin)
19826 && DECL_RTL_SET_P (decl_or_origin)))
19827 /* When abstract origin already has DW_AT_location attribute, no need
19828 to add it again. */
19829 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19831 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19832 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19833 defer_location (decl_or_origin, var_die);
19835 add_location_or_const_value_attribute (var_die,
19838 add_pubname (decl_or_origin, var_die);
19841 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19844 /* Generate a DIE to represent a named constant. */
19847 gen_const_die (tree decl, dw_die_ref context_die)
19849 dw_die_ref const_die;
19850 tree type = TREE_TYPE (decl);
19852 const_die = new_die (DW_TAG_constant, context_die, decl);
19853 add_name_and_src_coords_attributes (const_die, decl);
19854 add_type_attribute (const_die, type, 1, 0, context_die);
19855 if (TREE_PUBLIC (decl))
19856 add_AT_flag (const_die, DW_AT_external, 1);
19857 if (DECL_ARTIFICIAL (decl))
19858 add_AT_flag (const_die, DW_AT_artificial, 1);
19859 tree_add_const_value_attribute_for_decl (const_die, decl);
19862 /* Generate a DIE to represent a label identifier. */
19865 gen_label_die (tree decl, dw_die_ref context_die)
19867 tree origin = decl_ultimate_origin (decl);
19868 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19870 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19872 if (origin != NULL)
19873 add_abstract_origin_attribute (lbl_die, origin);
19875 add_name_and_src_coords_attributes (lbl_die, decl);
19877 if (DECL_ABSTRACT (decl))
19878 equate_decl_number_to_die (decl, lbl_die);
19881 insn = DECL_RTL_IF_SET (decl);
19883 /* Deleted labels are programmer specified labels which have been
19884 eliminated because of various optimizations. We still emit them
19885 here so that it is possible to put breakpoints on them. */
19889 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19891 /* When optimization is enabled (via -O) some parts of the compiler
19892 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19893 represent source-level labels which were explicitly declared by
19894 the user. This really shouldn't be happening though, so catch
19895 it if it ever does happen. */
19896 gcc_assert (!INSN_DELETED_P (insn));
19898 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19899 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19904 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19905 attributes to the DIE for a block STMT, to describe where the inlined
19906 function was called from. This is similar to add_src_coords_attributes. */
19909 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19911 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19913 if (dwarf_version >= 3 || !dwarf_strict)
19915 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19916 add_AT_unsigned (die, DW_AT_call_line, s.line);
19921 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19922 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19925 add_high_low_attributes (tree stmt, dw_die_ref die)
19927 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19929 if (BLOCK_FRAGMENT_CHAIN (stmt)
19930 && (dwarf_version >= 3 || !dwarf_strict))
19934 if (inlined_function_outer_scope_p (stmt))
19936 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19937 BLOCK_NUMBER (stmt));
19938 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19941 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19943 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19946 add_ranges (chain);
19947 chain = BLOCK_FRAGMENT_CHAIN (chain);
19954 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19955 BLOCK_NUMBER (stmt));
19956 add_AT_lbl_id (die, DW_AT_low_pc, label);
19957 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
19958 BLOCK_NUMBER (stmt));
19959 add_AT_lbl_id (die, DW_AT_high_pc, label);
19963 /* Generate a DIE for a lexical block. */
19966 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
19968 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19970 if (call_arg_locations)
19972 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
19973 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
19974 BLOCK_NUMBER (stmt) + 1);
19975 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
19978 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19979 add_high_low_attributes (stmt, stmt_die);
19981 decls_for_scope (stmt, stmt_die, depth);
19984 /* Generate a DIE for an inlined subprogram. */
19987 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
19991 /* The instance of function that is effectively being inlined shall not
19993 gcc_assert (! BLOCK_ABSTRACT (stmt));
19995 decl = block_ultimate_origin (stmt);
19997 /* Emit info for the abstract instance first, if we haven't yet. We
19998 must emit this even if the block is abstract, otherwise when we
19999 emit the block below (or elsewhere), we may end up trying to emit
20000 a die whose origin die hasn't been emitted, and crashing. */
20001 dwarf2out_abstract_function (decl);
20003 if (! BLOCK_ABSTRACT (stmt))
20005 dw_die_ref subr_die
20006 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
20008 if (call_arg_locations)
20010 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
20011 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
20012 BLOCK_NUMBER (stmt) + 1);
20013 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
20015 add_abstract_origin_attribute (subr_die, decl);
20016 if (TREE_ASM_WRITTEN (stmt))
20017 add_high_low_attributes (stmt, subr_die);
20018 add_call_src_coords_attributes (stmt, subr_die);
20020 decls_for_scope (stmt, subr_die, depth);
20021 current_function_has_inlines = 1;
20025 /* Generate a DIE for a field in a record, or structure. */
20028 gen_field_die (tree decl, dw_die_ref context_die)
20030 dw_die_ref decl_die;
20032 if (TREE_TYPE (decl) == error_mark_node)
20035 decl_die = new_die (DW_TAG_member, context_die, decl);
20036 add_name_and_src_coords_attributes (decl_die, decl);
20037 add_type_attribute (decl_die, member_declared_type (decl),
20038 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
20041 if (DECL_BIT_FIELD_TYPE (decl))
20043 add_byte_size_attribute (decl_die, decl);
20044 add_bit_size_attribute (decl_die, decl);
20045 add_bit_offset_attribute (decl_die, decl);
20048 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
20049 add_data_member_location_attribute (decl_die, decl);
20051 if (DECL_ARTIFICIAL (decl))
20052 add_AT_flag (decl_die, DW_AT_artificial, 1);
20054 add_accessibility_attribute (decl_die, decl);
20056 /* Equate decl number to die, so that we can look up this decl later on. */
20057 equate_decl_number_to_die (decl, decl_die);
20061 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20062 Use modified_type_die instead.
20063 We keep this code here just in case these types of DIEs may be needed to
20064 represent certain things in other languages (e.g. Pascal) someday. */
20067 gen_pointer_type_die (tree type, dw_die_ref context_die)
20070 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20072 equate_type_number_to_die (type, ptr_die);
20073 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20074 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20077 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20078 Use modified_type_die instead.
20079 We keep this code here just in case these types of DIEs may be needed to
20080 represent certain things in other languages (e.g. Pascal) someday. */
20083 gen_reference_type_die (tree type, dw_die_ref context_die)
20085 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20087 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
20088 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20090 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20092 equate_type_number_to_die (type, ref_die);
20093 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
20094 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20098 /* Generate a DIE for a pointer to a member type. */
20101 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20104 = new_die (DW_TAG_ptr_to_member_type,
20105 scope_die_for (type, context_die), type);
20107 equate_type_number_to_die (type, ptr_die);
20108 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20109 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20110 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20113 /* Generate the DIE for the compilation unit. */
20116 gen_compile_unit_die (const char *filename)
20119 char producer[250];
20120 const char *language_string = lang_hooks.name;
20123 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20127 add_name_attribute (die, filename);
20128 /* Don't add cwd for <built-in>. */
20129 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20130 add_comp_dir_attribute (die);
20133 sprintf (producer, "%s %s", language_string, version_string);
20135 #ifdef MIPS_DEBUGGING_INFO
20136 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20137 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20138 not appear in the producer string, the debugger reaches the conclusion
20139 that the object file is stripped and has no debugging information.
20140 To get the MIPS/SGI debugger to believe that there is debugging
20141 information in the object file, we add a -g to the producer string. */
20142 if (debug_info_level > DINFO_LEVEL_TERSE)
20143 strcat (producer, " -g");
20146 add_AT_string (die, DW_AT_producer, producer);
20148 /* If our producer is LTO try to figure out a common language to use
20149 from the global list of translation units. */
20150 if (strcmp (language_string, "GNU GIMPLE") == 0)
20154 const char *common_lang = NULL;
20156 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
20158 if (!TRANSLATION_UNIT_LANGUAGE (t))
20161 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20162 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20164 else if (strncmp (common_lang, "GNU C", 5) == 0
20165 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20166 /* Mixing C and C++ is ok, use C++ in that case. */
20167 common_lang = "GNU C++";
20170 /* Fall back to C. */
20171 common_lang = NULL;
20177 language_string = common_lang;
20180 language = DW_LANG_C89;
20181 if (strcmp (language_string, "GNU C++") == 0)
20182 language = DW_LANG_C_plus_plus;
20183 else if (strcmp (language_string, "GNU F77") == 0)
20184 language = DW_LANG_Fortran77;
20185 else if (strcmp (language_string, "GNU Pascal") == 0)
20186 language = DW_LANG_Pascal83;
20187 else if (dwarf_version >= 3 || !dwarf_strict)
20189 if (strcmp (language_string, "GNU Ada") == 0)
20190 language = DW_LANG_Ada95;
20191 else if (strcmp (language_string, "GNU Fortran") == 0)
20192 language = DW_LANG_Fortran95;
20193 else if (strcmp (language_string, "GNU Java") == 0)
20194 language = DW_LANG_Java;
20195 else if (strcmp (language_string, "GNU Objective-C") == 0)
20196 language = DW_LANG_ObjC;
20197 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20198 language = DW_LANG_ObjC_plus_plus;
20201 add_AT_unsigned (die, DW_AT_language, language);
20205 case DW_LANG_Fortran77:
20206 case DW_LANG_Fortran90:
20207 case DW_LANG_Fortran95:
20208 /* Fortran has case insensitive identifiers and the front-end
20209 lowercases everything. */
20210 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20213 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20219 /* Generate the DIE for a base class. */
20222 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20224 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20226 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
20227 add_data_member_location_attribute (die, binfo);
20229 if (BINFO_VIRTUAL_P (binfo))
20230 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20232 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20233 children, otherwise the default is DW_ACCESS_public. In DWARF2
20234 the default has always been DW_ACCESS_private. */
20235 if (access == access_public_node)
20237 if (dwarf_version == 2
20238 || context_die->die_tag == DW_TAG_class_type)
20239 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20241 else if (access == access_protected_node)
20242 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20243 else if (dwarf_version > 2
20244 && context_die->die_tag != DW_TAG_class_type)
20245 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20248 /* Generate a DIE for a class member. */
20251 gen_member_die (tree type, dw_die_ref context_die)
20254 tree binfo = TYPE_BINFO (type);
20257 /* If this is not an incomplete type, output descriptions of each of its
20258 members. Note that as we output the DIEs necessary to represent the
20259 members of this record or union type, we will also be trying to output
20260 DIEs to represent the *types* of those members. However the `type'
20261 function (above) will specifically avoid generating type DIEs for member
20262 types *within* the list of member DIEs for this (containing) type except
20263 for those types (of members) which are explicitly marked as also being
20264 members of this (containing) type themselves. The g++ front- end can
20265 force any given type to be treated as a member of some other (containing)
20266 type by setting the TYPE_CONTEXT of the given (member) type to point to
20267 the TREE node representing the appropriate (containing) type. */
20269 /* First output info about the base classes. */
20272 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
20276 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20277 gen_inheritance_die (base,
20278 (accesses ? VEC_index (tree, accesses, i)
20279 : access_public_node), context_die);
20282 /* Now output info about the data members and type members. */
20283 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20285 /* If we thought we were generating minimal debug info for TYPE
20286 and then changed our minds, some of the member declarations
20287 may have already been defined. Don't define them again, but
20288 do put them in the right order. */
20290 child = lookup_decl_die (member);
20292 splice_child_die (context_die, child);
20294 gen_decl_die (member, NULL, context_die);
20297 /* Now output info about the function members (if any). */
20298 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20300 /* Don't include clones in the member list. */
20301 if (DECL_ABSTRACT_ORIGIN (member))
20304 child = lookup_decl_die (member);
20306 splice_child_die (context_die, child);
20308 gen_decl_die (member, NULL, context_die);
20312 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20313 is set, we pretend that the type was never defined, so we only get the
20314 member DIEs needed by later specification DIEs. */
20317 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20318 enum debug_info_usage usage)
20320 dw_die_ref type_die = lookup_type_die (type);
20321 dw_die_ref scope_die = 0;
20323 int complete = (TYPE_SIZE (type)
20324 && (! TYPE_STUB_DECL (type)
20325 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20326 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20327 complete = complete && should_emit_struct_debug (type, usage);
20329 if (type_die && ! complete)
20332 if (TYPE_CONTEXT (type) != NULL_TREE
20333 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20334 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20337 scope_die = scope_die_for (type, context_die);
20339 if (! type_die || (nested && is_cu_die (scope_die)))
20340 /* First occurrence of type or toplevel definition of nested class. */
20342 dw_die_ref old_die = type_die;
20344 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20345 ? record_type_tag (type) : DW_TAG_union_type,
20347 equate_type_number_to_die (type, type_die);
20349 add_AT_specification (type_die, old_die);
20351 add_name_attribute (type_die, type_tag (type));
20354 remove_AT (type_die, DW_AT_declaration);
20356 /* Generate child dies for template paramaters. */
20357 if (debug_info_level > DINFO_LEVEL_TERSE
20358 && COMPLETE_TYPE_P (type))
20359 schedule_generic_params_dies_gen (type);
20361 /* If this type has been completed, then give it a byte_size attribute and
20362 then give a list of members. */
20363 if (complete && !ns_decl)
20365 /* Prevent infinite recursion in cases where the type of some member of
20366 this type is expressed in terms of this type itself. */
20367 TREE_ASM_WRITTEN (type) = 1;
20368 add_byte_size_attribute (type_die, type);
20369 if (TYPE_STUB_DECL (type) != NULL_TREE)
20371 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20372 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20375 /* If the first reference to this type was as the return type of an
20376 inline function, then it may not have a parent. Fix this now. */
20377 if (type_die->die_parent == NULL)
20378 add_child_die (scope_die, type_die);
20380 push_decl_scope (type);
20381 gen_member_die (type, type_die);
20384 /* GNU extension: Record what type our vtable lives in. */
20385 if (TYPE_VFIELD (type))
20387 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20389 gen_type_die (vtype, context_die);
20390 add_AT_die_ref (type_die, DW_AT_containing_type,
20391 lookup_type_die (vtype));
20396 add_AT_flag (type_die, DW_AT_declaration, 1);
20398 /* We don't need to do this for function-local types. */
20399 if (TYPE_STUB_DECL (type)
20400 && ! decl_function_context (TYPE_STUB_DECL (type)))
20401 VEC_safe_push (tree, gc, incomplete_types, type);
20404 if (get_AT (type_die, DW_AT_name))
20405 add_pubtype (type, type_die);
20408 /* Generate a DIE for a subroutine _type_. */
20411 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20413 tree return_type = TREE_TYPE (type);
20414 dw_die_ref subr_die
20415 = new_die (DW_TAG_subroutine_type,
20416 scope_die_for (type, context_die), type);
20418 equate_type_number_to_die (type, subr_die);
20419 add_prototyped_attribute (subr_die, type);
20420 add_type_attribute (subr_die, return_type, 0, 0, context_die);
20421 gen_formal_types_die (type, subr_die);
20423 if (get_AT (subr_die, DW_AT_name))
20424 add_pubtype (type, subr_die);
20427 /* Generate a DIE for a type definition. */
20430 gen_typedef_die (tree decl, dw_die_ref context_die)
20432 dw_die_ref type_die;
20435 if (TREE_ASM_WRITTEN (decl))
20438 TREE_ASM_WRITTEN (decl) = 1;
20439 type_die = new_die (DW_TAG_typedef, context_die, decl);
20440 origin = decl_ultimate_origin (decl);
20441 if (origin != NULL)
20442 add_abstract_origin_attribute (type_die, origin);
20447 add_name_and_src_coords_attributes (type_die, decl);
20448 if (DECL_ORIGINAL_TYPE (decl))
20450 type = DECL_ORIGINAL_TYPE (decl);
20452 gcc_assert (type != TREE_TYPE (decl));
20453 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20457 type = TREE_TYPE (decl);
20459 if (is_naming_typedef_decl (TYPE_NAME (type)))
20461 /* Here, we are in the case of decl being a typedef naming
20462 an anonymous type, e.g:
20463 typedef struct {...} foo;
20464 In that case TREE_TYPE (decl) is not a typedef variant
20465 type and TYPE_NAME of the anonymous type is set to the
20466 TYPE_DECL of the typedef. This construct is emitted by
20469 TYPE is the anonymous struct named by the typedef
20470 DECL. As we need the DW_AT_type attribute of the
20471 DW_TAG_typedef to point to the DIE of TYPE, let's
20472 generate that DIE right away. add_type_attribute
20473 called below will then pick (via lookup_type_die) that
20474 anonymous struct DIE. */
20475 if (!TREE_ASM_WRITTEN (type))
20476 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20478 /* This is a GNU Extension. We are adding a
20479 DW_AT_linkage_name attribute to the DIE of the
20480 anonymous struct TYPE. The value of that attribute
20481 is the name of the typedef decl naming the anonymous
20482 struct. This greatly eases the work of consumers of
20483 this debug info. */
20484 add_linkage_attr (lookup_type_die (type), decl);
20488 add_type_attribute (type_die, type, TREE_READONLY (decl),
20489 TREE_THIS_VOLATILE (decl), context_die);
20491 if (is_naming_typedef_decl (decl))
20492 /* We want that all subsequent calls to lookup_type_die with
20493 TYPE in argument yield the DW_TAG_typedef we have just
20495 equate_type_number_to_die (type, type_die);
20497 add_accessibility_attribute (type_die, decl);
20500 if (DECL_ABSTRACT (decl))
20501 equate_decl_number_to_die (decl, type_die);
20503 if (get_AT (type_die, DW_AT_name))
20504 add_pubtype (decl, type_die);
20507 /* Generate a DIE for a struct, class, enum or union type. */
20510 gen_tagged_type_die (tree type,
20511 dw_die_ref context_die,
20512 enum debug_info_usage usage)
20516 if (type == NULL_TREE
20517 || !is_tagged_type (type))
20520 /* If this is a nested type whose containing class hasn't been written
20521 out yet, writing it out will cover this one, too. This does not apply
20522 to instantiations of member class templates; they need to be added to
20523 the containing class as they are generated. FIXME: This hurts the
20524 idea of combining type decls from multiple TUs, since we can't predict
20525 what set of template instantiations we'll get. */
20526 if (TYPE_CONTEXT (type)
20527 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20528 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20530 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20532 if (TREE_ASM_WRITTEN (type))
20535 /* If that failed, attach ourselves to the stub. */
20536 push_decl_scope (TYPE_CONTEXT (type));
20537 context_die = lookup_type_die (TYPE_CONTEXT (type));
20540 else if (TYPE_CONTEXT (type) != NULL_TREE
20541 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20543 /* If this type is local to a function that hasn't been written
20544 out yet, use a NULL context for now; it will be fixed up in
20545 decls_for_scope. */
20546 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20547 /* A declaration DIE doesn't count; nested types need to go in the
20549 if (context_die && is_declaration_die (context_die))
20550 context_die = NULL;
20555 context_die = declare_in_namespace (type, context_die);
20559 if (TREE_CODE (type) == ENUMERAL_TYPE)
20561 /* This might have been written out by the call to
20562 declare_in_namespace. */
20563 if (!TREE_ASM_WRITTEN (type))
20564 gen_enumeration_type_die (type, context_die);
20567 gen_struct_or_union_type_die (type, context_die, usage);
20572 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20573 it up if it is ever completed. gen_*_type_die will set it for us
20574 when appropriate. */
20577 /* Generate a type description DIE. */
20580 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20581 enum debug_info_usage usage)
20583 struct array_descr_info info;
20585 if (type == NULL_TREE || type == error_mark_node)
20588 if (TYPE_NAME (type) != NULL_TREE
20589 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
20590 && is_redundant_typedef (TYPE_NAME (type))
20591 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
20592 /* The DECL of this type is a typedef we don't want to emit debug
20593 info for but we want debug info for its underlying typedef.
20594 This can happen for e.g, the injected-class-name of a C++
20596 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
20598 /* If TYPE is a typedef type variant, let's generate debug info
20599 for the parent typedef which TYPE is a type of. */
20600 if (typedef_variant_p (type))
20602 if (TREE_ASM_WRITTEN (type))
20605 /* Prevent broken recursion; we can't hand off to the same type. */
20606 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20608 /* Use the DIE of the containing namespace as the parent DIE of
20609 the type description DIE we want to generate. */
20610 if (DECL_CONTEXT (TYPE_NAME (type))
20611 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20612 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20614 TREE_ASM_WRITTEN (type) = 1;
20616 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20620 /* If type is an anonymous tagged type named by a typedef, let's
20621 generate debug info for the typedef. */
20622 if (is_naming_typedef_decl (TYPE_NAME (type)))
20624 /* Use the DIE of the containing namespace as the parent DIE of
20625 the type description DIE we want to generate. */
20626 if (DECL_CONTEXT (TYPE_NAME (type))
20627 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20628 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20630 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20634 /* If this is an array type with hidden descriptor, handle it first. */
20635 if (!TREE_ASM_WRITTEN (type)
20636 && lang_hooks.types.get_array_descr_info
20637 && lang_hooks.types.get_array_descr_info (type, &info)
20638 && (dwarf_version >= 3 || !dwarf_strict))
20640 gen_descr_array_type_die (type, &info, context_die);
20641 TREE_ASM_WRITTEN (type) = 1;
20645 /* We are going to output a DIE to represent the unqualified version
20646 of this type (i.e. without any const or volatile qualifiers) so
20647 get the main variant (i.e. the unqualified version) of this type
20648 now. (Vectors are special because the debugging info is in the
20649 cloned type itself). */
20650 if (TREE_CODE (type) != VECTOR_TYPE)
20651 type = type_main_variant (type);
20653 if (TREE_ASM_WRITTEN (type))
20656 switch (TREE_CODE (type))
20662 case REFERENCE_TYPE:
20663 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20664 ensures that the gen_type_die recursion will terminate even if the
20665 type is recursive. Recursive types are possible in Ada. */
20666 /* ??? We could perhaps do this for all types before the switch
20668 TREE_ASM_WRITTEN (type) = 1;
20670 /* For these types, all that is required is that we output a DIE (or a
20671 set of DIEs) to represent the "basis" type. */
20672 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20673 DINFO_USAGE_IND_USE);
20677 /* This code is used for C++ pointer-to-data-member types.
20678 Output a description of the relevant class type. */
20679 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20680 DINFO_USAGE_IND_USE);
20682 /* Output a description of the type of the object pointed to. */
20683 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20684 DINFO_USAGE_IND_USE);
20686 /* Now output a DIE to represent this pointer-to-data-member type
20688 gen_ptr_to_mbr_type_die (type, context_die);
20691 case FUNCTION_TYPE:
20692 /* Force out return type (in case it wasn't forced out already). */
20693 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20694 DINFO_USAGE_DIR_USE);
20695 gen_subroutine_type_die (type, context_die);
20699 /* Force out return type (in case it wasn't forced out already). */
20700 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20701 DINFO_USAGE_DIR_USE);
20702 gen_subroutine_type_die (type, context_die);
20706 gen_array_type_die (type, context_die);
20710 gen_array_type_die (type, context_die);
20713 case ENUMERAL_TYPE:
20716 case QUAL_UNION_TYPE:
20717 gen_tagged_type_die (type, context_die, usage);
20723 case FIXED_POINT_TYPE:
20726 /* No DIEs needed for fundamental types. */
20731 /* Just use DW_TAG_unspecified_type. */
20733 dw_die_ref type_die = lookup_type_die (type);
20734 if (type_die == NULL)
20736 tree name = TYPE_NAME (type);
20737 if (TREE_CODE (name) == TYPE_DECL)
20738 name = DECL_NAME (name);
20739 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
20740 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20741 equate_type_number_to_die (type, type_die);
20747 gcc_unreachable ();
20750 TREE_ASM_WRITTEN (type) = 1;
20754 gen_type_die (tree type, dw_die_ref context_die)
20756 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20759 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20760 things which are local to the given block. */
20763 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20765 int must_output_die = 0;
20768 /* Ignore blocks that are NULL. */
20769 if (stmt == NULL_TREE)
20772 inlined_func = inlined_function_outer_scope_p (stmt);
20774 /* If the block is one fragment of a non-contiguous block, do not
20775 process the variables, since they will have been done by the
20776 origin block. Do process subblocks. */
20777 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20781 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20782 gen_block_die (sub, context_die, depth + 1);
20787 /* Determine if we need to output any Dwarf DIEs at all to represent this
20790 /* The outer scopes for inlinings *must* always be represented. We
20791 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20792 must_output_die = 1;
20795 /* Determine if this block directly contains any "significant"
20796 local declarations which we will need to output DIEs for. */
20797 if (debug_info_level > DINFO_LEVEL_TERSE)
20798 /* We are not in terse mode so *any* local declaration counts
20799 as being a "significant" one. */
20800 must_output_die = ((BLOCK_VARS (stmt) != NULL
20801 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20802 && (TREE_USED (stmt)
20803 || TREE_ASM_WRITTEN (stmt)
20804 || BLOCK_ABSTRACT (stmt)));
20805 else if ((TREE_USED (stmt)
20806 || TREE_ASM_WRITTEN (stmt)
20807 || BLOCK_ABSTRACT (stmt))
20808 && !dwarf2out_ignore_block (stmt))
20809 must_output_die = 1;
20812 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20813 DIE for any block which contains no significant local declarations at
20814 all. Rather, in such cases we just call `decls_for_scope' so that any
20815 needed Dwarf info for any sub-blocks will get properly generated. Note
20816 that in terse mode, our definition of what constitutes a "significant"
20817 local declaration gets restricted to include only inlined function
20818 instances and local (nested) function definitions. */
20819 if (must_output_die)
20823 /* If STMT block is abstract, that means we have been called
20824 indirectly from dwarf2out_abstract_function.
20825 That function rightfully marks the descendent blocks (of
20826 the abstract function it is dealing with) as being abstract,
20827 precisely to prevent us from emitting any
20828 DW_TAG_inlined_subroutine DIE as a descendent
20829 of an abstract function instance. So in that case, we should
20830 not call gen_inlined_subroutine_die.
20832 Later though, when cgraph asks dwarf2out to emit info
20833 for the concrete instance of the function decl into which
20834 the concrete instance of STMT got inlined, the later will lead
20835 to the generation of a DW_TAG_inlined_subroutine DIE. */
20836 if (! BLOCK_ABSTRACT (stmt))
20837 gen_inlined_subroutine_die (stmt, context_die, depth);
20840 gen_lexical_block_die (stmt, context_die, depth);
20843 decls_for_scope (stmt, context_die, depth);
20846 /* Process variable DECL (or variable with origin ORIGIN) within
20847 block STMT and add it to CONTEXT_DIE. */
20849 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20852 tree decl_or_origin = decl ? decl : origin;
20854 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20855 die = lookup_decl_die (decl_or_origin);
20856 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20857 && TYPE_DECL_IS_STUB (decl_or_origin))
20858 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20862 if (die != NULL && die->die_parent == NULL)
20863 add_child_die (context_die, die);
20864 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20865 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20866 stmt, context_die);
20868 gen_decl_die (decl, origin, context_die);
20871 /* Generate all of the decls declared within a given scope and (recursively)
20872 all of its sub-blocks. */
20875 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20881 /* Ignore NULL blocks. */
20882 if (stmt == NULL_TREE)
20885 /* Output the DIEs to represent all of the data objects and typedefs
20886 declared directly within this block but not within any nested
20887 sub-blocks. Also, nested function and tag DIEs have been
20888 generated with a parent of NULL; fix that up now. */
20889 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20890 process_scope_var (stmt, decl, NULL_TREE, context_die);
20891 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20892 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20895 /* If we're at -g1, we're not interested in subblocks. */
20896 if (debug_info_level <= DINFO_LEVEL_TERSE)
20899 /* Output the DIEs to represent all sub-blocks (and the items declared
20900 therein) of this block. */
20901 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20903 subblocks = BLOCK_CHAIN (subblocks))
20904 gen_block_die (subblocks, context_die, depth + 1);
20907 /* Is this a typedef we can avoid emitting? */
20910 is_redundant_typedef (const_tree decl)
20912 if (TYPE_DECL_IS_STUB (decl))
20915 if (DECL_ARTIFICIAL (decl)
20916 && DECL_CONTEXT (decl)
20917 && is_tagged_type (DECL_CONTEXT (decl))
20918 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20919 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20920 /* Also ignore the artificial member typedef for the class name. */
20926 /* Return TRUE if TYPE is a typedef that names a type for linkage
20927 purposes. This kind of typedefs is produced by the C++ FE for
20930 typedef struct {...} foo;
20932 In that case, there is no typedef variant type produced for foo.
20933 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20937 is_naming_typedef_decl (const_tree decl)
20939 if (decl == NULL_TREE
20940 || TREE_CODE (decl) != TYPE_DECL
20941 || !is_tagged_type (TREE_TYPE (decl))
20942 || DECL_IS_BUILTIN (decl)
20943 || is_redundant_typedef (decl)
20944 /* It looks like Ada produces TYPE_DECLs that are very similar
20945 to C++ naming typedefs but that have different
20946 semantics. Let's be specific to c++ for now. */
20950 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
20951 && TYPE_NAME (TREE_TYPE (decl)) == decl
20952 && (TYPE_STUB_DECL (TREE_TYPE (decl))
20953 != TYPE_NAME (TREE_TYPE (decl))));
20956 /* Returns the DIE for a context. */
20958 static inline dw_die_ref
20959 get_context_die (tree context)
20963 /* Find die that represents this context. */
20964 if (TYPE_P (context))
20966 context = TYPE_MAIN_VARIANT (context);
20967 return strip_naming_typedef (context, force_type_die (context));
20970 return force_decl_die (context);
20972 return comp_unit_die ();
20975 /* Returns the DIE for decl. A DIE will always be returned. */
20978 force_decl_die (tree decl)
20980 dw_die_ref decl_die;
20981 unsigned saved_external_flag;
20982 tree save_fn = NULL_TREE;
20983 decl_die = lookup_decl_die (decl);
20986 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
20988 decl_die = lookup_decl_die (decl);
20992 switch (TREE_CODE (decl))
20994 case FUNCTION_DECL:
20995 /* Clear current_function_decl, so that gen_subprogram_die thinks
20996 that this is a declaration. At this point, we just want to force
20997 declaration die. */
20998 save_fn = current_function_decl;
20999 current_function_decl = NULL_TREE;
21000 gen_subprogram_die (decl, context_die);
21001 current_function_decl = save_fn;
21005 /* Set external flag to force declaration die. Restore it after
21006 gen_decl_die() call. */
21007 saved_external_flag = DECL_EXTERNAL (decl);
21008 DECL_EXTERNAL (decl) = 1;
21009 gen_decl_die (decl, NULL, context_die);
21010 DECL_EXTERNAL (decl) = saved_external_flag;
21013 case NAMESPACE_DECL:
21014 if (dwarf_version >= 3 || !dwarf_strict)
21015 dwarf2out_decl (decl);
21017 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21018 decl_die = comp_unit_die ();
21021 case TRANSLATION_UNIT_DECL:
21022 decl_die = comp_unit_die ();
21026 gcc_unreachable ();
21029 /* We should be able to find the DIE now. */
21031 decl_die = lookup_decl_die (decl);
21032 gcc_assert (decl_die);
21038 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21039 always returned. */
21042 force_type_die (tree type)
21044 dw_die_ref type_die;
21046 type_die = lookup_type_die (type);
21049 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21051 type_die = modified_type_die (type, TYPE_READONLY (type),
21052 TYPE_VOLATILE (type), context_die);
21053 gcc_assert (type_die);
21058 /* Force out any required namespaces to be able to output DECL,
21059 and return the new context_die for it, if it's changed. */
21062 setup_namespace_context (tree thing, dw_die_ref context_die)
21064 tree context = (DECL_P (thing)
21065 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21066 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21067 /* Force out the namespace. */
21068 context_die = force_decl_die (context);
21070 return context_die;
21073 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21074 type) within its namespace, if appropriate.
21076 For compatibility with older debuggers, namespace DIEs only contain
21077 declarations; all definitions are emitted at CU scope. */
21080 declare_in_namespace (tree thing, dw_die_ref context_die)
21082 dw_die_ref ns_context;
21084 if (debug_info_level <= DINFO_LEVEL_TERSE)
21085 return context_die;
21087 /* If this decl is from an inlined function, then don't try to emit it in its
21088 namespace, as we will get confused. It would have already been emitted
21089 when the abstract instance of the inline function was emitted anyways. */
21090 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21091 return context_die;
21093 ns_context = setup_namespace_context (thing, context_die);
21095 if (ns_context != context_die)
21099 if (DECL_P (thing))
21100 gen_decl_die (thing, NULL, ns_context);
21102 gen_type_die (thing, ns_context);
21104 return context_die;
21107 /* Generate a DIE for a namespace or namespace alias. */
21110 gen_namespace_die (tree decl, dw_die_ref context_die)
21112 dw_die_ref namespace_die;
21114 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21115 they are an alias of. */
21116 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21118 /* Output a real namespace or module. */
21119 context_die = setup_namespace_context (decl, comp_unit_die ());
21120 namespace_die = new_die (is_fortran ()
21121 ? DW_TAG_module : DW_TAG_namespace,
21122 context_die, decl);
21123 /* For Fortran modules defined in different CU don't add src coords. */
21124 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21126 const char *name = dwarf2_name (decl, 0);
21128 add_name_attribute (namespace_die, name);
21131 add_name_and_src_coords_attributes (namespace_die, decl);
21132 if (DECL_EXTERNAL (decl))
21133 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21134 equate_decl_number_to_die (decl, namespace_die);
21138 /* Output a namespace alias. */
21140 /* Force out the namespace we are an alias of, if necessary. */
21141 dw_die_ref origin_die
21142 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21144 if (DECL_FILE_SCOPE_P (decl)
21145 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21146 context_die = setup_namespace_context (decl, comp_unit_die ());
21147 /* Now create the namespace alias DIE. */
21148 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21149 add_name_and_src_coords_attributes (namespace_die, decl);
21150 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21151 equate_decl_number_to_die (decl, namespace_die);
21155 /* Generate Dwarf debug information for a decl described by DECL.
21156 The return value is currently only meaningful for PARM_DECLs,
21157 for all other decls it returns NULL. */
21160 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21162 tree decl_or_origin = decl ? decl : origin;
21163 tree class_origin = NULL, ultimate_origin;
21165 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21168 switch (TREE_CODE (decl_or_origin))
21174 if (!is_fortran () && !is_ada ())
21176 /* The individual enumerators of an enum type get output when we output
21177 the Dwarf representation of the relevant enum type itself. */
21181 /* Emit its type. */
21182 gen_type_die (TREE_TYPE (decl), context_die);
21184 /* And its containing namespace. */
21185 context_die = declare_in_namespace (decl, context_die);
21187 gen_const_die (decl, context_die);
21190 case FUNCTION_DECL:
21191 /* Don't output any DIEs to represent mere function declarations,
21192 unless they are class members or explicit block externs. */
21193 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21194 && DECL_FILE_SCOPE_P (decl_or_origin)
21195 && (current_function_decl == NULL_TREE
21196 || DECL_ARTIFICIAL (decl_or_origin)))
21201 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21202 on local redeclarations of global functions. That seems broken. */
21203 if (current_function_decl != decl)
21204 /* This is only a declaration. */;
21207 /* If we're emitting a clone, emit info for the abstract instance. */
21208 if (origin || DECL_ORIGIN (decl) != decl)
21209 dwarf2out_abstract_function (origin
21210 ? DECL_ORIGIN (origin)
21211 : DECL_ABSTRACT_ORIGIN (decl));
21213 /* If we're emitting an out-of-line copy of an inline function,
21214 emit info for the abstract instance and set up to refer to it. */
21215 else if (cgraph_function_possibly_inlined_p (decl)
21216 && ! DECL_ABSTRACT (decl)
21217 && ! class_or_namespace_scope_p (context_die)
21218 /* dwarf2out_abstract_function won't emit a die if this is just
21219 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21220 that case, because that works only if we have a die. */
21221 && DECL_INITIAL (decl) != NULL_TREE)
21223 dwarf2out_abstract_function (decl);
21224 set_decl_origin_self (decl);
21227 /* Otherwise we're emitting the primary DIE for this decl. */
21228 else if (debug_info_level > DINFO_LEVEL_TERSE)
21230 /* Before we describe the FUNCTION_DECL itself, make sure that we
21231 have its containing type. */
21233 origin = decl_class_context (decl);
21234 if (origin != NULL_TREE)
21235 gen_type_die (origin, context_die);
21237 /* And its return type. */
21238 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21240 /* And its virtual context. */
21241 if (DECL_VINDEX (decl) != NULL_TREE)
21242 gen_type_die (DECL_CONTEXT (decl), context_die);
21244 /* Make sure we have a member DIE for decl. */
21245 if (origin != NULL_TREE)
21246 gen_type_die_for_member (origin, decl, context_die);
21248 /* And its containing namespace. */
21249 context_die = declare_in_namespace (decl, context_die);
21252 /* Now output a DIE to represent the function itself. */
21254 gen_subprogram_die (decl, context_die);
21258 /* If we are in terse mode, don't generate any DIEs to represent any
21259 actual typedefs. */
21260 if (debug_info_level <= DINFO_LEVEL_TERSE)
21263 /* In the special case of a TYPE_DECL node representing the declaration
21264 of some type tag, if the given TYPE_DECL is marked as having been
21265 instantiated from some other (original) TYPE_DECL node (e.g. one which
21266 was generated within the original definition of an inline function) we
21267 used to generate a special (abbreviated) DW_TAG_structure_type,
21268 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21269 should be actually referencing those DIEs, as variable DIEs with that
21270 type would be emitted already in the abstract origin, so it was always
21271 removed during unused type prunning. Don't add anything in this
21273 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21276 if (is_redundant_typedef (decl))
21277 gen_type_die (TREE_TYPE (decl), context_die);
21279 /* Output a DIE to represent the typedef itself. */
21280 gen_typedef_die (decl, context_die);
21284 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21285 gen_label_die (decl, context_die);
21290 /* If we are in terse mode, don't generate any DIEs to represent any
21291 variable declarations or definitions. */
21292 if (debug_info_level <= DINFO_LEVEL_TERSE)
21295 /* Output any DIEs that are needed to specify the type of this data
21297 if (decl_by_reference_p (decl_or_origin))
21298 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21300 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21302 /* And its containing type. */
21303 class_origin = decl_class_context (decl_or_origin);
21304 if (class_origin != NULL_TREE)
21305 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21307 /* And its containing namespace. */
21308 context_die = declare_in_namespace (decl_or_origin, context_die);
21310 /* Now output the DIE to represent the data object itself. This gets
21311 complicated because of the possibility that the VAR_DECL really
21312 represents an inlined instance of a formal parameter for an inline
21314 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21315 if (ultimate_origin != NULL_TREE
21316 && TREE_CODE (ultimate_origin) == PARM_DECL)
21317 gen_formal_parameter_die (decl, origin,
21318 true /* Emit name attribute. */,
21321 gen_variable_die (decl, origin, context_die);
21325 /* Ignore the nameless fields that are used to skip bits but handle C++
21326 anonymous unions and structs. */
21327 if (DECL_NAME (decl) != NULL_TREE
21328 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21329 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21331 gen_type_die (member_declared_type (decl), context_die);
21332 gen_field_die (decl, context_die);
21337 if (DECL_BY_REFERENCE (decl_or_origin))
21338 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21340 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21341 return gen_formal_parameter_die (decl, origin,
21342 true /* Emit name attribute. */,
21345 case NAMESPACE_DECL:
21346 case IMPORTED_DECL:
21347 if (dwarf_version >= 3 || !dwarf_strict)
21348 gen_namespace_die (decl, context_die);
21352 /* Probably some frontend-internal decl. Assume we don't care. */
21353 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21360 /* Output debug information for global decl DECL. Called from toplev.c after
21361 compilation proper has finished. */
21364 dwarf2out_global_decl (tree decl)
21366 /* Output DWARF2 information for file-scope tentative data object
21367 declarations, file-scope (extern) function declarations (which
21368 had no corresponding body) and file-scope tagged type declarations
21369 and definitions which have not yet been forced out. */
21370 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
21371 dwarf2out_decl (decl);
21374 /* Output debug information for type decl DECL. Called from toplev.c
21375 and from language front ends (to record built-in types). */
21377 dwarf2out_type_decl (tree decl, int local)
21380 dwarf2out_decl (decl);
21383 /* Output debug information for imported module or decl DECL.
21384 NAME is non-NULL name in the lexical block if the decl has been renamed.
21385 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21386 that DECL belongs to.
21387 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21389 dwarf2out_imported_module_or_decl_1 (tree decl,
21391 tree lexical_block,
21392 dw_die_ref lexical_block_die)
21394 expanded_location xloc;
21395 dw_die_ref imported_die = NULL;
21396 dw_die_ref at_import_die;
21398 if (TREE_CODE (decl) == IMPORTED_DECL)
21400 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21401 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21405 xloc = expand_location (input_location);
21407 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21409 at_import_die = force_type_die (TREE_TYPE (decl));
21410 /* For namespace N { typedef void T; } using N::T; base_type_die
21411 returns NULL, but DW_TAG_imported_declaration requires
21412 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21413 if (!at_import_die)
21415 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21416 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21417 at_import_die = lookup_type_die (TREE_TYPE (decl));
21418 gcc_assert (at_import_die);
21423 at_import_die = lookup_decl_die (decl);
21424 if (!at_import_die)
21426 /* If we're trying to avoid duplicate debug info, we may not have
21427 emitted the member decl for this field. Emit it now. */
21428 if (TREE_CODE (decl) == FIELD_DECL)
21430 tree type = DECL_CONTEXT (decl);
21432 if (TYPE_CONTEXT (type)
21433 && TYPE_P (TYPE_CONTEXT (type))
21434 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21435 DINFO_USAGE_DIR_USE))
21437 gen_type_die_for_member (type, decl,
21438 get_context_die (TYPE_CONTEXT (type)));
21440 at_import_die = force_decl_die (decl);
21444 if (TREE_CODE (decl) == NAMESPACE_DECL)
21446 if (dwarf_version >= 3 || !dwarf_strict)
21447 imported_die = new_die (DW_TAG_imported_module,
21454 imported_die = new_die (DW_TAG_imported_declaration,
21458 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21459 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21461 add_AT_string (imported_die, DW_AT_name,
21462 IDENTIFIER_POINTER (name));
21463 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21466 /* Output debug information for imported module or decl DECL.
21467 NAME is non-NULL name in context if the decl has been renamed.
21468 CHILD is true if decl is one of the renamed decls as part of
21469 importing whole module. */
21472 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21475 /* dw_die_ref at_import_die; */
21476 dw_die_ref scope_die;
21478 if (debug_info_level <= DINFO_LEVEL_TERSE)
21483 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21484 We need decl DIE for reference and scope die. First, get DIE for the decl
21487 /* Get the scope die for decl context. Use comp_unit_die for global module
21488 or decl. If die is not found for non globals, force new die. */
21490 && TYPE_P (context)
21491 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21494 if (!(dwarf_version >= 3 || !dwarf_strict))
21497 scope_die = get_context_die (context);
21501 gcc_assert (scope_die->die_child);
21502 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21503 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21504 scope_die = scope_die->die_child;
21507 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21508 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21512 /* Write the debugging output for DECL. */
21515 dwarf2out_decl (tree decl)
21517 dw_die_ref context_die = comp_unit_die ();
21519 switch (TREE_CODE (decl))
21524 case FUNCTION_DECL:
21525 /* What we would really like to do here is to filter out all mere
21526 file-scope declarations of file-scope functions which are never
21527 referenced later within this translation unit (and keep all of ones
21528 that *are* referenced later on) but we aren't clairvoyant, so we have
21529 no idea which functions will be referenced in the future (i.e. later
21530 on within the current translation unit). So here we just ignore all
21531 file-scope function declarations which are not also definitions. If
21532 and when the debugger needs to know something about these functions,
21533 it will have to hunt around and find the DWARF information associated
21534 with the definition of the function.
21536 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21537 nodes represent definitions and which ones represent mere
21538 declarations. We have to check DECL_INITIAL instead. That's because
21539 the C front-end supports some weird semantics for "extern inline"
21540 function definitions. These can get inlined within the current
21541 translation unit (and thus, we need to generate Dwarf info for their
21542 abstract instances so that the Dwarf info for the concrete inlined
21543 instances can have something to refer to) but the compiler never
21544 generates any out-of-lines instances of such things (despite the fact
21545 that they *are* definitions).
21547 The important point is that the C front-end marks these "extern
21548 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21549 them anyway. Note that the C++ front-end also plays some similar games
21550 for inline function definitions appearing within include files which
21551 also contain `#pragma interface' pragmas. */
21552 if (DECL_INITIAL (decl) == NULL_TREE)
21555 /* If we're a nested function, initially use a parent of NULL; if we're
21556 a plain function, this will be fixed up in decls_for_scope. If
21557 we're a method, it will be ignored, since we already have a DIE. */
21558 if (decl_function_context (decl)
21559 /* But if we're in terse mode, we don't care about scope. */
21560 && debug_info_level > DINFO_LEVEL_TERSE)
21561 context_die = NULL;
21565 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21566 declaration and if the declaration was never even referenced from
21567 within this entire compilation unit. We suppress these DIEs in
21568 order to save space in the .debug section (by eliminating entries
21569 which are probably useless). Note that we must not suppress
21570 block-local extern declarations (whether used or not) because that
21571 would screw-up the debugger's name lookup mechanism and cause it to
21572 miss things which really ought to be in scope at a given point. */
21573 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
21576 /* For local statics lookup proper context die. */
21577 if (TREE_STATIC (decl) && decl_function_context (decl))
21578 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21580 /* If we are in terse mode, don't generate any DIEs to represent any
21581 variable declarations or definitions. */
21582 if (debug_info_level <= DINFO_LEVEL_TERSE)
21587 if (debug_info_level <= DINFO_LEVEL_TERSE)
21589 if (!is_fortran () && !is_ada ())
21591 if (TREE_STATIC (decl) && decl_function_context (decl))
21592 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21595 case NAMESPACE_DECL:
21596 case IMPORTED_DECL:
21597 if (debug_info_level <= DINFO_LEVEL_TERSE)
21599 if (lookup_decl_die (decl) != NULL)
21604 /* Don't emit stubs for types unless they are needed by other DIEs. */
21605 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21608 /* Don't bother trying to generate any DIEs to represent any of the
21609 normal built-in types for the language we are compiling. */
21610 if (DECL_IS_BUILTIN (decl))
21613 /* If we are in terse mode, don't generate any DIEs for types. */
21614 if (debug_info_level <= DINFO_LEVEL_TERSE)
21617 /* If we're a function-scope tag, initially use a parent of NULL;
21618 this will be fixed up in decls_for_scope. */
21619 if (decl_function_context (decl))
21620 context_die = NULL;
21628 gen_decl_die (decl, NULL, context_die);
21631 /* Write the debugging output for DECL. */
21634 dwarf2out_function_decl (tree decl)
21636 dwarf2out_decl (decl);
21637 call_arg_locations = NULL;
21638 call_arg_loc_last = NULL;
21639 call_site_count = -1;
21640 tail_call_site_count = -1;
21641 VEC_free (dw_die_ref, heap, block_map);
21642 htab_empty (decl_loc_table);
21645 /* Output a marker (i.e. a label) for the beginning of the generated code for
21646 a lexical block. */
21649 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21650 unsigned int blocknum)
21652 switch_to_section (current_function_section ());
21653 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21656 /* Output a marker (i.e. a label) for the end of the generated code for a
21660 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21662 switch_to_section (current_function_section ());
21663 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21666 /* Returns nonzero if it is appropriate not to emit any debugging
21667 information for BLOCK, because it doesn't contain any instructions.
21669 Don't allow this for blocks with nested functions or local classes
21670 as we would end up with orphans, and in the presence of scheduling
21671 we may end up calling them anyway. */
21674 dwarf2out_ignore_block (const_tree block)
21679 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21680 if (TREE_CODE (decl) == FUNCTION_DECL
21681 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21683 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21685 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21686 if (TREE_CODE (decl) == FUNCTION_DECL
21687 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21694 /* Hash table routines for file_hash. */
21697 file_table_eq (const void *p1_p, const void *p2_p)
21699 const struct dwarf_file_data *const p1 =
21700 (const struct dwarf_file_data *) p1_p;
21701 const char *const p2 = (const char *) p2_p;
21702 return filename_cmp (p1->filename, p2) == 0;
21706 file_table_hash (const void *p_p)
21708 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21709 return htab_hash_string (p->filename);
21712 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21713 dwarf2out.c) and return its "index". The index of each (known) filename is
21714 just a unique number which is associated with only that one filename. We
21715 need such numbers for the sake of generating labels (in the .debug_sfnames
21716 section) and references to those files numbers (in the .debug_srcinfo
21717 and.debug_macinfo sections). If the filename given as an argument is not
21718 found in our current list, add it to the list and assign it the next
21719 available unique index number. In order to speed up searches, we remember
21720 the index of the filename was looked up last. This handles the majority of
21723 static struct dwarf_file_data *
21724 lookup_filename (const char *file_name)
21727 struct dwarf_file_data * created;
21729 /* Check to see if the file name that was searched on the previous
21730 call matches this file name. If so, return the index. */
21731 if (file_table_last_lookup
21732 && (file_name == file_table_last_lookup->filename
21733 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
21734 return file_table_last_lookup;
21736 /* Didn't match the previous lookup, search the table. */
21737 slot = htab_find_slot_with_hash (file_table, file_name,
21738 htab_hash_string (file_name), INSERT);
21740 return (struct dwarf_file_data *) *slot;
21742 created = ggc_alloc_dwarf_file_data ();
21743 created->filename = file_name;
21744 created->emitted_number = 0;
21749 /* If the assembler will construct the file table, then translate the compiler
21750 internal file table number into the assembler file table number, and emit
21751 a .file directive if we haven't already emitted one yet. The file table
21752 numbers are different because we prune debug info for unused variables and
21753 types, which may include filenames. */
21756 maybe_emit_file (struct dwarf_file_data * fd)
21758 if (! fd->emitted_number)
21760 if (last_emitted_file)
21761 fd->emitted_number = last_emitted_file->emitted_number + 1;
21763 fd->emitted_number = 1;
21764 last_emitted_file = fd;
21766 if (DWARF2_ASM_LINE_DEBUG_INFO)
21768 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21769 output_quoted_string (asm_out_file,
21770 remap_debug_filename (fd->filename));
21771 fputc ('\n', asm_out_file);
21775 return fd->emitted_number;
21778 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21779 That generation should happen after function debug info has been
21780 generated. The value of the attribute is the constant value of ARG. */
21783 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21785 die_arg_entry entry;
21790 if (!tmpl_value_parm_die_table)
21791 tmpl_value_parm_die_table
21792 = VEC_alloc (die_arg_entry, gc, 32);
21796 VEC_safe_push (die_arg_entry, gc,
21797 tmpl_value_parm_die_table,
21801 /* Return TRUE if T is an instance of generic type, FALSE
21805 generic_type_p (tree t)
21807 if (t == NULL_TREE || !TYPE_P (t))
21809 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
21812 /* Schedule the generation of the generic parameter dies for the
21813 instance of generic type T. The proper generation itself is later
21814 done by gen_scheduled_generic_parms_dies. */
21817 schedule_generic_params_dies_gen (tree t)
21819 if (!generic_type_p (t))
21822 if (generic_type_instances == NULL)
21823 generic_type_instances = VEC_alloc (tree, gc, 256);
21825 VEC_safe_push (tree, gc, generic_type_instances, t);
21828 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21829 by append_entry_to_tmpl_value_parm_die_table. This function must
21830 be called after function DIEs have been generated. */
21833 gen_remaining_tmpl_value_param_die_attribute (void)
21835 if (tmpl_value_parm_die_table)
21840 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21841 tree_add_const_value_attribute (e->die, e->arg);
21845 /* Generate generic parameters DIEs for instances of generic types
21846 that have been previously scheduled by
21847 schedule_generic_params_dies_gen. This function must be called
21848 after all the types of the CU have been laid out. */
21851 gen_scheduled_generic_parms_dies (void)
21856 if (generic_type_instances == NULL)
21859 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
21860 gen_generic_params_dies (t);
21864 /* Replace DW_AT_name for the decl with name. */
21867 dwarf2out_set_name (tree decl, tree name)
21873 die = TYPE_SYMTAB_DIE (decl);
21877 dname = dwarf2_name (name, 0);
21881 attr = get_AT (die, DW_AT_name);
21884 struct indirect_string_node *node;
21886 node = find_AT_string (dname);
21887 /* replace the string. */
21888 attr->dw_attr_val.v.val_str = node;
21892 add_name_attribute (die, dname);
21895 /* Called by the final INSN scan whenever we see a var location. We
21896 use it to drop labels in the right places, and throw the location in
21897 our lookup table. */
21900 dwarf2out_var_location (rtx loc_note)
21902 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21903 struct var_loc_node *newloc;
21905 static const char *last_label;
21906 static const char *last_postcall_label;
21907 static bool last_in_cold_section_p;
21911 if (!NOTE_P (loc_note))
21913 if (CALL_P (loc_note))
21916 if (SIBLING_CALL_P (loc_note))
21917 tail_call_site_count++;
21922 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
21923 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21926 next_real = next_real_insn (loc_note);
21928 /* If there are no instructions which would be affected by this note,
21929 don't do anything. */
21931 && next_real == NULL_RTX
21932 && !NOTE_DURING_CALL_P (loc_note))
21935 if (next_real == NULL_RTX)
21936 next_real = get_last_insn ();
21938 /* If there were any real insns between note we processed last time
21939 and this note (or if it is the first note), clear
21940 last_{,postcall_}label so that they are not reused this time. */
21941 if (last_var_location_insn == NULL_RTX
21942 || last_var_location_insn != next_real
21943 || last_in_cold_section_p != in_cold_section_p)
21946 last_postcall_label = NULL;
21951 decl = NOTE_VAR_LOCATION_DECL (loc_note);
21952 newloc = add_var_loc_to_decl (decl, loc_note,
21953 NOTE_DURING_CALL_P (loc_note)
21954 ? last_postcall_label : last_label);
21955 if (newloc == NULL)
21964 /* If there were no real insns between note we processed last time
21965 and this note, use the label we emitted last time. Otherwise
21966 create a new label and emit it. */
21967 if (last_label == NULL)
21969 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
21970 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
21972 last_label = ggc_strdup (loclabel);
21977 struct call_arg_loc_node *ca_loc
21978 = ggc_alloc_cleared_call_arg_loc_node ();
21979 rtx prev = prev_real_insn (loc_note), x;
21980 ca_loc->call_arg_loc_note = loc_note;
21981 ca_loc->next = NULL;
21982 ca_loc->label = last_label;
21985 || (NONJUMP_INSN_P (prev)
21986 && GET_CODE (PATTERN (prev)) == SEQUENCE
21987 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
21988 if (!CALL_P (prev))
21989 prev = XVECEXP (PATTERN (prev), 0, 0);
21990 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
21991 x = PATTERN (prev);
21992 if (GET_CODE (x) == PARALLEL)
21993 x = XVECEXP (x, 0, 0);
21994 if (GET_CODE (x) == SET)
21996 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
21998 x = XEXP (XEXP (x, 0), 0);
21999 if (GET_CODE (x) == SYMBOL_REF
22000 && SYMBOL_REF_DECL (x)
22001 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
22002 ca_loc->symbol_ref = x;
22004 ca_loc->block = insn_scope (prev);
22005 if (call_arg_locations)
22006 call_arg_loc_last->next = ca_loc;
22008 call_arg_locations = ca_loc;
22009 call_arg_loc_last = ca_loc;
22011 else if (!NOTE_DURING_CALL_P (loc_note))
22012 newloc->label = last_label;
22015 if (!last_postcall_label)
22017 sprintf (loclabel, "%s-1", last_label);
22018 last_postcall_label = ggc_strdup (loclabel);
22020 newloc->label = last_postcall_label;
22023 last_var_location_insn = next_real;
22024 last_in_cold_section_p = in_cold_section_p;
22027 /* We need to reset the locations at the beginning of each
22028 function. We can't do this in the end_function hook, because the
22029 declarations that use the locations won't have been output when
22030 that hook is called. Also compute have_multiple_function_sections here. */
22033 dwarf2out_begin_function (tree fun)
22035 if (function_section (fun) != text_section)
22036 have_multiple_function_sections = true;
22037 else if (flag_reorder_blocks_and_partition && !cold_text_section)
22039 gcc_assert (current_function_decl == fun);
22040 cold_text_section = unlikely_text_section ();
22041 switch_to_section (cold_text_section);
22042 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22043 switch_to_section (current_function_section ());
22046 dwarf2out_note_section_used ();
22047 call_site_count = 0;
22048 tail_call_site_count = 0;
22051 /* Output a label to mark the beginning of a source code line entry
22052 and record information relating to this source line, in
22053 'line_info_table' for later output of the .debug_line section. */
22056 dwarf2out_source_line (unsigned int line, const char *filename,
22057 int discriminator, bool is_stmt)
22059 static bool last_is_stmt = true;
22061 if (debug_info_level >= DINFO_LEVEL_NORMAL
22064 int file_num = maybe_emit_file (lookup_filename (filename));
22066 switch_to_section (current_function_section ());
22068 /* If requested, emit something human-readable. */
22069 if (flag_debug_asm)
22070 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
22073 if (DWARF2_ASM_LINE_DEBUG_INFO)
22075 /* Emit the .loc directive understood by GNU as. */
22076 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
22077 if (is_stmt != last_is_stmt)
22079 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
22080 last_is_stmt = is_stmt;
22082 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
22083 fprintf (asm_out_file, " discriminator %d", discriminator);
22084 fputc ('\n', asm_out_file);
22086 /* Indicate that line number info exists. */
22087 line_info_table_in_use++;
22089 else if (function_section (current_function_decl) != text_section)
22091 dw_separate_line_info_ref line_info;
22092 targetm.asm_out.internal_label (asm_out_file,
22093 SEPARATE_LINE_CODE_LABEL,
22094 separate_line_info_table_in_use);
22096 /* Expand the line info table if necessary. */
22097 if (separate_line_info_table_in_use
22098 == separate_line_info_table_allocated)
22100 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22101 separate_line_info_table
22102 = GGC_RESIZEVEC (dw_separate_line_info_entry,
22103 separate_line_info_table,
22104 separate_line_info_table_allocated);
22105 memset (separate_line_info_table
22106 + separate_line_info_table_in_use,
22108 (LINE_INFO_TABLE_INCREMENT
22109 * sizeof (dw_separate_line_info_entry)));
22112 /* Add the new entry at the end of the line_info_table. */
22114 = &separate_line_info_table[separate_line_info_table_in_use++];
22115 line_info->dw_file_num = file_num;
22116 line_info->dw_line_num = line;
22117 line_info->function = current_function_funcdef_no;
22121 dw_line_info_ref line_info;
22123 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
22124 line_info_table_in_use);
22126 /* Expand the line info table if necessary. */
22127 if (line_info_table_in_use == line_info_table_allocated)
22129 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22131 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
22132 line_info_table_allocated);
22133 memset (line_info_table + line_info_table_in_use, 0,
22134 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
22137 /* Add the new entry at the end of the line_info_table. */
22138 line_info = &line_info_table[line_info_table_in_use++];
22139 line_info->dw_file_num = file_num;
22140 line_info->dw_line_num = line;
22145 /* Record the beginning of a new source file. */
22148 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22150 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22152 /* Record the beginning of the file for break_out_includes. */
22153 dw_die_ref bincl_die;
22155 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22156 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22159 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22162 e.code = DW_MACINFO_start_file;
22164 e.info = xstrdup (filename);
22165 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22169 /* Record the end of a source file. */
22172 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22174 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22175 /* Record the end of the file for break_out_includes. */
22176 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22178 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22181 e.code = DW_MACINFO_end_file;
22184 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22188 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22189 the tail part of the directive line, i.e. the part which is past the
22190 initial whitespace, #, whitespace, directive-name, whitespace part. */
22193 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22194 const char *buffer ATTRIBUTE_UNUSED)
22196 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22199 e.code = DW_MACINFO_define;
22201 e.info = xstrdup (buffer);;
22202 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22206 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22207 the tail part of the directive line, i.e. the part which is past the
22208 initial whitespace, #, whitespace, directive-name, whitespace part. */
22211 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22212 const char *buffer ATTRIBUTE_UNUSED)
22214 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22217 e.code = DW_MACINFO_undef;
22219 e.info = xstrdup (buffer);;
22220 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22225 output_macinfo (void)
22228 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
22229 macinfo_entry *ref;
22234 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
22238 case DW_MACINFO_start_file:
22240 int file_num = maybe_emit_file (lookup_filename (ref->info));
22241 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22242 dw2_asm_output_data_uleb128
22243 (ref->lineno, "Included from line number %lu",
22244 (unsigned long)ref->lineno);
22245 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22248 case DW_MACINFO_end_file:
22249 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22251 case DW_MACINFO_define:
22252 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
22253 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22254 (unsigned long)ref->lineno);
22255 dw2_asm_output_nstring (ref->info, -1, "The macro");
22257 case DW_MACINFO_undef:
22258 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
22259 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22260 (unsigned long)ref->lineno);
22261 dw2_asm_output_nstring (ref->info, -1, "The macro");
22264 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22265 ASM_COMMENT_START, (unsigned long)ref->code);
22271 /* Set up for Dwarf output at the start of compilation. */
22274 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
22276 /* Allocate the file_table. */
22277 file_table = htab_create_ggc (50, file_table_hash,
22278 file_table_eq, NULL);
22280 /* Allocate the decl_die_table. */
22281 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
22282 decl_die_table_eq, NULL);
22284 /* Allocate the decl_loc_table. */
22285 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
22286 decl_loc_table_eq, NULL);
22288 /* Allocate the initial hunk of the decl_scope_table. */
22289 decl_scope_table = VEC_alloc (tree, gc, 256);
22291 /* Allocate the initial hunk of the abbrev_die_table. */
22292 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
22293 (ABBREV_DIE_TABLE_INCREMENT);
22294 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
22295 /* Zero-th entry is allocated, but unused. */
22296 abbrev_die_table_in_use = 1;
22298 /* Allocate the initial hunk of the line_info_table. */
22299 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
22300 (LINE_INFO_TABLE_INCREMENT);
22301 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
22303 /* Zero-th entry is allocated, but unused. */
22304 line_info_table_in_use = 1;
22306 /* Allocate the pubtypes and pubnames vectors. */
22307 pubname_table = VEC_alloc (pubname_entry, gc, 32);
22308 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
22310 incomplete_types = VEC_alloc (tree, gc, 64);
22312 used_rtx_array = VEC_alloc (rtx, gc, 32);
22314 debug_info_section = get_section (DEBUG_INFO_SECTION,
22315 SECTION_DEBUG, NULL);
22316 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
22317 SECTION_DEBUG, NULL);
22318 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
22319 SECTION_DEBUG, NULL);
22320 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
22321 SECTION_DEBUG, NULL);
22322 debug_line_section = get_section (DEBUG_LINE_SECTION,
22323 SECTION_DEBUG, NULL);
22324 debug_loc_section = get_section (DEBUG_LOC_SECTION,
22325 SECTION_DEBUG, NULL);
22326 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
22327 SECTION_DEBUG, NULL);
22328 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
22329 SECTION_DEBUG, NULL);
22330 debug_str_section = get_section (DEBUG_STR_SECTION,
22331 DEBUG_STR_SECTION_FLAGS, NULL);
22332 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
22333 SECTION_DEBUG, NULL);
22334 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
22335 SECTION_DEBUG, NULL);
22337 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
22338 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
22339 DEBUG_ABBREV_SECTION_LABEL, 0);
22340 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
22341 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
22342 COLD_TEXT_SECTION_LABEL, 0);
22343 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
22345 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
22346 DEBUG_INFO_SECTION_LABEL, 0);
22347 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
22348 DEBUG_LINE_SECTION_LABEL, 0);
22349 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
22350 DEBUG_RANGES_SECTION_LABEL, 0);
22351 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
22352 DEBUG_MACINFO_SECTION_LABEL, 0);
22354 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22355 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
22357 switch_to_section (text_section);
22358 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
22361 /* Called before cgraph_optimize starts outputtting functions, variables
22362 and toplevel asms into assembly. */
22365 dwarf2out_assembly_start (void)
22367 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22368 && dwarf2out_do_cfi_asm ()
22369 && (!(flag_unwind_tables || flag_exceptions)
22370 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
22371 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
22374 /* A helper function for dwarf2out_finish called through
22375 htab_traverse. Emit one queued .debug_str string. */
22378 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22380 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22382 if (node->label && node->refcount)
22384 switch_to_section (debug_str_section);
22385 ASM_OUTPUT_LABEL (asm_out_file, node->label);
22386 assemble_string (node->str, strlen (node->str) + 1);
22392 #if ENABLE_ASSERT_CHECKING
22393 /* Verify that all marks are clear. */
22396 verify_marks_clear (dw_die_ref die)
22400 gcc_assert (! die->die_mark);
22401 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
22403 #endif /* ENABLE_ASSERT_CHECKING */
22405 /* Clear the marks for a die and its children.
22406 Be cool if the mark isn't set. */
22409 prune_unmark_dies (dw_die_ref die)
22415 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
22418 /* Given DIE that we're marking as used, find any other dies
22419 it references as attributes and mark them as used. */
22422 prune_unused_types_walk_attribs (dw_die_ref die)
22427 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22429 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
22431 /* A reference to another DIE.
22432 Make sure that it will get emitted.
22433 If it was broken out into a comdat group, don't follow it. */
22434 if (dwarf_version < 4
22435 || a->dw_attr == DW_AT_specification
22436 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
22437 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
22439 /* Set the string's refcount to 0 so that prune_unused_types_mark
22440 accounts properly for it. */
22441 if (AT_class (a) == dw_val_class_str)
22442 a->dw_attr_val.v.val_str->refcount = 0;
22446 /* Mark the generic parameters and arguments children DIEs of DIE. */
22449 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
22453 if (die == NULL || die->die_child == NULL)
22455 c = die->die_child;
22458 switch (c->die_tag)
22460 case DW_TAG_template_type_param:
22461 case DW_TAG_template_value_param:
22462 case DW_TAG_GNU_template_template_param:
22463 case DW_TAG_GNU_template_parameter_pack:
22464 prune_unused_types_mark (c, 1);
22470 } while (c && c != die->die_child);
22473 /* Mark DIE as being used. If DOKIDS is true, then walk down
22474 to DIE's children. */
22477 prune_unused_types_mark (dw_die_ref die, int dokids)
22481 if (die->die_mark == 0)
22483 /* We haven't done this node yet. Mark it as used. */
22485 /* If this is the DIE of a generic type instantiation,
22486 mark the children DIEs that describe its generic parms and
22488 prune_unused_types_mark_generic_parms_dies (die);
22490 /* We also have to mark its parents as used.
22491 (But we don't want to mark our parents' kids due to this.) */
22492 if (die->die_parent)
22493 prune_unused_types_mark (die->die_parent, 0);
22495 /* Mark any referenced nodes. */
22496 prune_unused_types_walk_attribs (die);
22498 /* If this node is a specification,
22499 also mark the definition, if it exists. */
22500 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
22501 prune_unused_types_mark (die->die_definition, 1);
22504 if (dokids && die->die_mark != 2)
22506 /* We need to walk the children, but haven't done so yet.
22507 Remember that we've walked the kids. */
22510 /* If this is an array type, we need to make sure our
22511 kids get marked, even if they're types. If we're
22512 breaking out types into comdat sections, do this
22513 for all type definitions. */
22514 if (die->die_tag == DW_TAG_array_type
22515 || (dwarf_version >= 4
22516 && is_type_die (die) && ! is_declaration_die (die)))
22517 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
22519 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22523 /* For local classes, look if any static member functions were emitted
22524 and if so, mark them. */
22527 prune_unused_types_walk_local_classes (dw_die_ref die)
22531 if (die->die_mark == 2)
22534 switch (die->die_tag)
22536 case DW_TAG_structure_type:
22537 case DW_TAG_union_type:
22538 case DW_TAG_class_type:
22541 case DW_TAG_subprogram:
22542 if (!get_AT_flag (die, DW_AT_declaration)
22543 || die->die_definition != NULL)
22544 prune_unused_types_mark (die, 1);
22551 /* Mark children. */
22552 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
22555 /* Walk the tree DIE and mark types that we actually use. */
22558 prune_unused_types_walk (dw_die_ref die)
22562 /* Don't do anything if this node is already marked and
22563 children have been marked as well. */
22564 if (die->die_mark == 2)
22567 switch (die->die_tag)
22569 case DW_TAG_structure_type:
22570 case DW_TAG_union_type:
22571 case DW_TAG_class_type:
22572 if (die->die_perennial_p)
22575 for (c = die->die_parent; c; c = c->die_parent)
22576 if (c->die_tag == DW_TAG_subprogram)
22579 /* Finding used static member functions inside of classes
22580 is needed just for local classes, because for other classes
22581 static member function DIEs with DW_AT_specification
22582 are emitted outside of the DW_TAG_*_type. If we ever change
22583 it, we'd need to call this even for non-local classes. */
22585 prune_unused_types_walk_local_classes (die);
22587 /* It's a type node --- don't mark it. */
22590 case DW_TAG_const_type:
22591 case DW_TAG_packed_type:
22592 case DW_TAG_pointer_type:
22593 case DW_TAG_reference_type:
22594 case DW_TAG_rvalue_reference_type:
22595 case DW_TAG_volatile_type:
22596 case DW_TAG_typedef:
22597 case DW_TAG_array_type:
22598 case DW_TAG_interface_type:
22599 case DW_TAG_friend:
22600 case DW_TAG_variant_part:
22601 case DW_TAG_enumeration_type:
22602 case DW_TAG_subroutine_type:
22603 case DW_TAG_string_type:
22604 case DW_TAG_set_type:
22605 case DW_TAG_subrange_type:
22606 case DW_TAG_ptr_to_member_type:
22607 case DW_TAG_file_type:
22608 if (die->die_perennial_p)
22611 /* It's a type node --- don't mark it. */
22615 /* Mark everything else. */
22619 if (die->die_mark == 0)
22623 /* Now, mark any dies referenced from here. */
22624 prune_unused_types_walk_attribs (die);
22629 /* Mark children. */
22630 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22633 /* Increment the string counts on strings referred to from DIE's
22637 prune_unused_types_update_strings (dw_die_ref die)
22642 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22643 if (AT_class (a) == dw_val_class_str)
22645 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22647 /* Avoid unnecessarily putting strings that are used less than
22648 twice in the hash table. */
22650 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22653 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22654 htab_hash_string (s->str),
22656 gcc_assert (*slot == NULL);
22662 /* Remove from the tree DIE any dies that aren't marked. */
22665 prune_unused_types_prune (dw_die_ref die)
22669 gcc_assert (die->die_mark);
22670 prune_unused_types_update_strings (die);
22672 if (! die->die_child)
22675 c = die->die_child;
22677 dw_die_ref prev = c;
22678 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22679 if (c == die->die_child)
22681 /* No marked children between 'prev' and the end of the list. */
22683 /* No marked children at all. */
22684 die->die_child = NULL;
22687 prev->die_sib = c->die_sib;
22688 die->die_child = prev;
22693 if (c != prev->die_sib)
22695 prune_unused_types_prune (c);
22696 } while (c != die->die_child);
22699 /* A helper function for dwarf2out_finish called through
22700 htab_traverse. Clear .debug_str strings that we haven't already
22701 decided to emit. */
22704 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22706 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22708 if (!node->label || !node->refcount)
22709 htab_clear_slot (debug_str_hash, h);
22714 /* Remove dies representing declarations that we never use. */
22717 prune_unused_types (void)
22720 limbo_die_node *node;
22721 comdat_type_node *ctnode;
22724 #if ENABLE_ASSERT_CHECKING
22725 /* All the marks should already be clear. */
22726 verify_marks_clear (comp_unit_die ());
22727 for (node = limbo_die_list; node; node = node->next)
22728 verify_marks_clear (node->die);
22729 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22730 verify_marks_clear (ctnode->root_die);
22731 #endif /* ENABLE_ASSERT_CHECKING */
22733 /* Mark types that are used in global variables. */
22734 premark_types_used_by_global_vars ();
22736 /* Set the mark on nodes that are actually used. */
22737 prune_unused_types_walk (comp_unit_die ());
22738 for (node = limbo_die_list; node; node = node->next)
22739 prune_unused_types_walk (node->die);
22740 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22742 prune_unused_types_walk (ctnode->root_die);
22743 prune_unused_types_mark (ctnode->type_die, 1);
22746 /* Also set the mark on nodes referenced from the
22747 pubname_table or arange_table. */
22748 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22749 prune_unused_types_mark (pub->die, 1);
22750 for (i = 0; i < arange_table_in_use; i++)
22751 prune_unused_types_mark (arange_table[i], 1);
22753 /* Get rid of nodes that aren't marked; and update the string counts. */
22754 if (debug_str_hash && debug_str_hash_forced)
22755 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22756 else if (debug_str_hash)
22757 htab_empty (debug_str_hash);
22758 prune_unused_types_prune (comp_unit_die ());
22759 for (node = limbo_die_list; node; node = node->next)
22760 prune_unused_types_prune (node->die);
22761 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22762 prune_unused_types_prune (ctnode->root_die);
22764 /* Leave the marks clear. */
22765 prune_unmark_dies (comp_unit_die ());
22766 for (node = limbo_die_list; node; node = node->next)
22767 prune_unmark_dies (node->die);
22768 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22769 prune_unmark_dies (ctnode->root_die);
22772 /* Set the parameter to true if there are any relative pathnames in
22775 file_table_relative_p (void ** slot, void *param)
22777 bool *p = (bool *) param;
22778 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22779 if (!IS_ABSOLUTE_PATH (d->filename))
22787 /* Routines to manipulate hash table of comdat type units. */
22790 htab_ct_hash (const void *of)
22793 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22795 memcpy (&h, type_node->signature, sizeof (h));
22800 htab_ct_eq (const void *of1, const void *of2)
22802 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22803 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22805 return (! memcmp (type_node_1->signature, type_node_2->signature,
22806 DWARF_TYPE_SIGNATURE_SIZE));
22809 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22810 to the location it would have been added, should we know its
22811 DECL_ASSEMBLER_NAME when we added other attributes. This will
22812 probably improve compactness of debug info, removing equivalent
22813 abbrevs, and hide any differences caused by deferring the
22814 computation of the assembler name, triggered by e.g. PCH. */
22817 move_linkage_attr (dw_die_ref die)
22819 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22820 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22822 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22823 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22827 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22829 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22833 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22835 VEC_pop (dw_attr_node, die->die_attr);
22836 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22840 /* Helper function for resolve_addr, attempt to resolve
22841 one CONST_STRING, return non-zero if not successful. Similarly verify that
22842 SYMBOL_REFs refer to variables emitted in the current CU. */
22845 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22849 if (GET_CODE (rtl) == CONST_STRING)
22851 size_t len = strlen (XSTR (rtl, 0)) + 1;
22852 tree t = build_string (len, XSTR (rtl, 0));
22853 tree tlen = build_int_cst (NULL_TREE, len - 1);
22855 = build_array_type (char_type_node, build_index_type (tlen));
22856 rtl = lookup_constant_def (t);
22857 if (!rtl || !MEM_P (rtl))
22859 rtl = XEXP (rtl, 0);
22860 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22865 if (GET_CODE (rtl) == SYMBOL_REF
22866 && SYMBOL_REF_DECL (rtl))
22868 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
22870 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
22873 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22877 if (GET_CODE (rtl) == CONST
22878 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22884 /* Helper function for resolve_addr, handle one location
22885 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22886 the location list couldn't be resolved. */
22889 resolve_addr_in_expr (dw_loc_descr_ref loc)
22891 for (; loc; loc = loc->dw_loc_next)
22892 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22893 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22894 || (loc->dw_loc_opc == DW_OP_implicit_value
22895 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22896 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22898 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
22899 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
22902 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
22905 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
22906 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
22907 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
22912 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22913 an address in .rodata section if the string literal is emitted there,
22914 or remove the containing location list or replace DW_AT_const_value
22915 with DW_AT_location and empty location expression, if it isn't found
22916 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22917 to something that has been emitted in the current CU. */
22920 resolve_addr (dw_die_ref die)
22924 dw_loc_list_ref *curr;
22927 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22928 switch (AT_class (a))
22930 case dw_val_class_loc_list:
22931 curr = AT_loc_list_ptr (a);
22934 if (!resolve_addr_in_expr ((*curr)->expr))
22936 dw_loc_list_ref next = (*curr)->dw_loc_next;
22937 if (next && (*curr)->ll_symbol)
22939 gcc_assert (!next->ll_symbol);
22940 next->ll_symbol = (*curr)->ll_symbol;
22945 curr = &(*curr)->dw_loc_next;
22947 if (!AT_loc_list (a))
22949 remove_AT (die, a->dw_attr);
22953 case dw_val_class_loc:
22954 if (!resolve_addr_in_expr (AT_loc (a)))
22956 remove_AT (die, a->dw_attr);
22960 case dw_val_class_addr:
22961 if (a->dw_attr == DW_AT_const_value
22962 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
22964 remove_AT (die, a->dw_attr);
22967 if (die->die_tag == DW_TAG_GNU_call_site
22968 && a->dw_attr == DW_AT_abstract_origin)
22970 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
22971 dw_die_ref tdie = lookup_decl_die (tdecl);
22972 if (tdie == NULL && DECL_EXTERNAL (tdecl))
22974 force_decl_die (tdecl);
22975 tdie = lookup_decl_die (tdecl);
22979 a->dw_attr_val.val_class = dw_val_class_die_ref;
22980 a->dw_attr_val.v.val_die_ref.die = tdie;
22981 a->dw_attr_val.v.val_die_ref.external = 0;
22985 remove_AT (die, a->dw_attr);
22994 FOR_EACH_CHILD (die, c, resolve_addr (c));
22997 /* Helper routines for optimize_location_lists.
22998 This pass tries to share identical local lists in .debug_loc
23001 /* Iteratively hash operands of LOC opcode. */
23003 static inline hashval_t
23004 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
23006 dw_val_ref val1 = &loc->dw_loc_oprnd1;
23007 dw_val_ref val2 = &loc->dw_loc_oprnd2;
23009 switch (loc->dw_loc_opc)
23011 case DW_OP_const4u:
23012 case DW_OP_const8u:
23016 case DW_OP_const1u:
23017 case DW_OP_const1s:
23018 case DW_OP_const2u:
23019 case DW_OP_const2s:
23020 case DW_OP_const4s:
23021 case DW_OP_const8s:
23025 case DW_OP_plus_uconst:
23061 case DW_OP_deref_size:
23062 case DW_OP_xderef_size:
23063 hash = iterative_hash_object (val1->v.val_int, hash);
23070 gcc_assert (val1->val_class == dw_val_class_loc);
23071 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
23072 hash = iterative_hash_object (offset, hash);
23075 case DW_OP_implicit_value:
23076 hash = iterative_hash_object (val1->v.val_unsigned, hash);
23077 switch (val2->val_class)
23079 case dw_val_class_const:
23080 hash = iterative_hash_object (val2->v.val_int, hash);
23082 case dw_val_class_vec:
23084 unsigned int elt_size = val2->v.val_vec.elt_size;
23085 unsigned int len = val2->v.val_vec.length;
23087 hash = iterative_hash_object (elt_size, hash);
23088 hash = iterative_hash_object (len, hash);
23089 hash = iterative_hash (val2->v.val_vec.array,
23090 len * elt_size, hash);
23093 case dw_val_class_const_double:
23094 hash = iterative_hash_object (val2->v.val_double.low, hash);
23095 hash = iterative_hash_object (val2->v.val_double.high, hash);
23097 case dw_val_class_addr:
23098 hash = iterative_hash_rtx (val2->v.val_addr, hash);
23101 gcc_unreachable ();
23105 case DW_OP_bit_piece:
23106 hash = iterative_hash_object (val1->v.val_int, hash);
23107 hash = iterative_hash_object (val2->v.val_int, hash);
23113 unsigned char dtprel = 0xd1;
23114 hash = iterative_hash_object (dtprel, hash);
23116 hash = iterative_hash_rtx (val1->v.val_addr, hash);
23118 case DW_OP_GNU_implicit_pointer:
23119 hash = iterative_hash_object (val2->v.val_int, hash);
23123 /* Other codes have no operands. */
23129 /* Iteratively hash the whole DWARF location expression LOC. */
23131 static inline hashval_t
23132 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
23134 dw_loc_descr_ref l;
23135 bool sizes_computed = false;
23136 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23137 size_of_locs (loc);
23139 for (l = loc; l != NULL; l = l->dw_loc_next)
23141 enum dwarf_location_atom opc = l->dw_loc_opc;
23142 hash = iterative_hash_object (opc, hash);
23143 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
23145 size_of_locs (loc);
23146 sizes_computed = true;
23148 hash = hash_loc_operands (l, hash);
23153 /* Compute hash of the whole location list LIST_HEAD. */
23156 hash_loc_list (dw_loc_list_ref list_head)
23158 dw_loc_list_ref curr = list_head;
23159 hashval_t hash = 0;
23161 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
23163 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
23164 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
23166 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
23168 hash = hash_locs (curr->expr, hash);
23170 list_head->hash = hash;
23173 /* Return true if X and Y opcodes have the same operands. */
23176 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
23178 dw_val_ref valx1 = &x->dw_loc_oprnd1;
23179 dw_val_ref valx2 = &x->dw_loc_oprnd2;
23180 dw_val_ref valy1 = &y->dw_loc_oprnd1;
23181 dw_val_ref valy2 = &y->dw_loc_oprnd2;
23183 switch (x->dw_loc_opc)
23185 case DW_OP_const4u:
23186 case DW_OP_const8u:
23190 case DW_OP_const1u:
23191 case DW_OP_const1s:
23192 case DW_OP_const2u:
23193 case DW_OP_const2s:
23194 case DW_OP_const4s:
23195 case DW_OP_const8s:
23199 case DW_OP_plus_uconst:
23235 case DW_OP_deref_size:
23236 case DW_OP_xderef_size:
23237 return valx1->v.val_int == valy1->v.val_int;
23240 gcc_assert (valx1->val_class == dw_val_class_loc
23241 && valy1->val_class == dw_val_class_loc
23242 && x->dw_loc_addr == y->dw_loc_addr);
23243 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
23244 case DW_OP_implicit_value:
23245 if (valx1->v.val_unsigned != valy1->v.val_unsigned
23246 || valx2->val_class != valy2->val_class)
23248 switch (valx2->val_class)
23250 case dw_val_class_const:
23251 return valx2->v.val_int == valy2->v.val_int;
23252 case dw_val_class_vec:
23253 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
23254 && valx2->v.val_vec.length == valy2->v.val_vec.length
23255 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
23256 valx2->v.val_vec.elt_size
23257 * valx2->v.val_vec.length) == 0;
23258 case dw_val_class_const_double:
23259 return valx2->v.val_double.low == valy2->v.val_double.low
23260 && valx2->v.val_double.high == valy2->v.val_double.high;
23261 case dw_val_class_addr:
23262 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
23264 gcc_unreachable ();
23267 case DW_OP_bit_piece:
23268 return valx1->v.val_int == valy1->v.val_int
23269 && valx2->v.val_int == valy2->v.val_int;
23272 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
23273 case DW_OP_GNU_implicit_pointer:
23274 return valx1->val_class == dw_val_class_die_ref
23275 && valx1->val_class == valy1->val_class
23276 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
23277 && valx2->v.val_int == valy2->v.val_int;
23279 /* Other codes have no operands. */
23284 /* Return true if DWARF location expressions X and Y are the same. */
23287 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
23289 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
23290 if (x->dw_loc_opc != y->dw_loc_opc
23291 || x->dtprel != y->dtprel
23292 || !compare_loc_operands (x, y))
23294 return x == NULL && y == NULL;
23297 /* Return precomputed hash of location list X. */
23300 loc_list_hash (const void *x)
23302 return ((const struct dw_loc_list_struct *) x)->hash;
23305 /* Return 1 if location lists X and Y are the same. */
23308 loc_list_eq (const void *x, const void *y)
23310 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
23311 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
23314 if (a->hash != b->hash)
23316 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
23317 if (strcmp (a->begin, b->begin) != 0
23318 || strcmp (a->end, b->end) != 0
23319 || (a->section == NULL) != (b->section == NULL)
23320 || (a->section && strcmp (a->section, b->section) != 0)
23321 || !compare_locs (a->expr, b->expr))
23323 return a == NULL && b == NULL;
23326 /* Recursively optimize location lists referenced from DIE
23327 children and share them whenever possible. */
23330 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
23337 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23338 if (AT_class (a) == dw_val_class_loc_list)
23340 dw_loc_list_ref list = AT_loc_list (a);
23341 /* TODO: perform some optimizations here, before hashing
23342 it and storing into the hash table. */
23343 hash_loc_list (list);
23344 slot = htab_find_slot_with_hash (htab, list, list->hash,
23347 *slot = (void *) list;
23349 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
23352 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
23355 /* Optimize location lists referenced from DIE
23356 children and share them whenever possible. */
23359 optimize_location_lists (dw_die_ref die)
23361 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
23362 optimize_location_lists_1 (die, htab);
23363 htab_delete (htab);
23366 /* Output stuff that dwarf requires at the end of every file,
23367 and generate the DWARF-2 debugging info. */
23370 dwarf2out_finish (const char *filename)
23372 limbo_die_node *node, *next_node;
23373 comdat_type_node *ctnode;
23374 htab_t comdat_type_table;
23377 gen_scheduled_generic_parms_dies ();
23378 gen_remaining_tmpl_value_param_die_attribute ();
23380 /* Add the name for the main input file now. We delayed this from
23381 dwarf2out_init to avoid complications with PCH. */
23382 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
23383 if (!IS_ABSOLUTE_PATH (filename))
23384 add_comp_dir_attribute (comp_unit_die ());
23385 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
23388 htab_traverse (file_table, file_table_relative_p, &p);
23390 add_comp_dir_attribute (comp_unit_die ());
23393 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
23395 add_location_or_const_value_attribute (
23396 VEC_index (deferred_locations, deferred_locations_list, i)->die,
23397 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
23401 /* Traverse the limbo die list, and add parent/child links. The only
23402 dies without parents that should be here are concrete instances of
23403 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23404 For concrete instances, we can get the parent die from the abstract
23406 for (node = limbo_die_list; node; node = next_node)
23408 dw_die_ref die = node->die;
23409 next_node = node->next;
23411 if (die->die_parent == NULL)
23413 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
23416 add_child_die (origin->die_parent, die);
23417 else if (is_cu_die (die))
23419 else if (seen_error ())
23420 /* It's OK to be confused by errors in the input. */
23421 add_child_die (comp_unit_die (), die);
23424 /* In certain situations, the lexical block containing a
23425 nested function can be optimized away, which results
23426 in the nested function die being orphaned. Likewise
23427 with the return type of that nested function. Force
23428 this to be a child of the containing function.
23430 It may happen that even the containing function got fully
23431 inlined and optimized out. In that case we are lost and
23432 assign the empty child. This should not be big issue as
23433 the function is likely unreachable too. */
23434 tree context = NULL_TREE;
23436 gcc_assert (node->created_for);
23438 if (DECL_P (node->created_for))
23439 context = DECL_CONTEXT (node->created_for);
23440 else if (TYPE_P (node->created_for))
23441 context = TYPE_CONTEXT (node->created_for);
23443 gcc_assert (context
23444 && (TREE_CODE (context) == FUNCTION_DECL
23445 || TREE_CODE (context) == NAMESPACE_DECL));
23447 origin = lookup_decl_die (context);
23449 add_child_die (origin, die);
23451 add_child_die (comp_unit_die (), die);
23456 limbo_die_list = NULL;
23458 resolve_addr (comp_unit_die ());
23460 for (node = deferred_asm_name; node; node = node->next)
23462 tree decl = node->created_for;
23463 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
23465 add_linkage_attr (node->die, decl);
23466 move_linkage_attr (node->die);
23470 deferred_asm_name = NULL;
23472 /* Walk through the list of incomplete types again, trying once more to
23473 emit full debugging info for them. */
23474 retry_incomplete_types ();
23476 if (flag_eliminate_unused_debug_types)
23477 prune_unused_types ();
23479 /* Generate separate CUs for each of the include files we've seen.
23480 They will go into limbo_die_list. */
23481 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
23482 break_out_includes (comp_unit_die ());
23484 /* Generate separate COMDAT sections for type DIEs. */
23485 if (dwarf_version >= 4)
23487 break_out_comdat_types (comp_unit_die ());
23489 /* Each new type_unit DIE was added to the limbo die list when created.
23490 Since these have all been added to comdat_type_list, clear the
23492 limbo_die_list = NULL;
23494 /* For each new comdat type unit, copy declarations for incomplete
23495 types to make the new unit self-contained (i.e., no direct
23496 references to the main compile unit). */
23497 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23498 copy_decls_for_unworthy_types (ctnode->root_die);
23499 copy_decls_for_unworthy_types (comp_unit_die ());
23501 /* In the process of copying declarations from one unit to another,
23502 we may have left some declarations behind that are no longer
23503 referenced. Prune them. */
23504 prune_unused_types ();
23507 /* Traverse the DIE's and add add sibling attributes to those DIE's
23508 that have children. */
23509 add_sibling_attributes (comp_unit_die ());
23510 for (node = limbo_die_list; node; node = node->next)
23511 add_sibling_attributes (node->die);
23512 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23513 add_sibling_attributes (ctnode->root_die);
23515 /* Output a terminator label for the .text section. */
23516 switch_to_section (text_section);
23517 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
23518 if (cold_text_section)
23520 switch_to_section (cold_text_section);
23521 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
23524 /* We can only use the low/high_pc attributes if all of the code was
23526 if (!have_multiple_function_sections
23527 || (dwarf_version < 3 && dwarf_strict))
23529 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
23530 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
23535 unsigned fde_idx = 0;
23536 bool range_list_added = false;
23538 /* We need to give .debug_loc and .debug_ranges an appropriate
23539 "base address". Use zero so that these addresses become
23540 absolute. Historically, we've emitted the unexpected
23541 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23542 Emit both to give time for other tools to adapt. */
23543 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
23544 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
23546 if (text_section_used)
23547 add_ranges_by_labels (comp_unit_die (), text_section_label,
23548 text_end_label, &range_list_added);
23549 if (flag_reorder_blocks_and_partition && cold_text_section_used)
23550 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
23551 cold_end_label, &range_list_added);
23553 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
23555 dw_fde_ref fde = &fde_table[fde_idx];
23557 if (fde->dw_fde_switched_sections)
23559 if (!fde->in_std_section)
23560 add_ranges_by_labels (comp_unit_die (),
23561 fde->dw_fde_hot_section_label,
23562 fde->dw_fde_hot_section_end_label,
23563 &range_list_added);
23564 if (!fde->cold_in_std_section)
23565 add_ranges_by_labels (comp_unit_die (),
23566 fde->dw_fde_unlikely_section_label,
23567 fde->dw_fde_unlikely_section_end_label,
23568 &range_list_added);
23570 else if (!fde->in_std_section)
23571 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
23572 fde->dw_fde_end, &range_list_added);
23575 if (range_list_added)
23579 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23580 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
23581 debug_line_section_label);
23583 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23584 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
23586 if (have_location_lists)
23587 optimize_location_lists (comp_unit_die ());
23589 /* Output all of the compilation units. We put the main one last so that
23590 the offsets are available to output_pubnames. */
23591 for (node = limbo_die_list; node; node = node->next)
23592 output_comp_unit (node->die, 0);
23594 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
23595 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23597 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
23599 /* Don't output duplicate types. */
23600 if (*slot != HTAB_EMPTY_ENTRY)
23603 /* Add a pointer to the line table for the main compilation unit
23604 so that the debugger can make sense of DW_AT_decl_file
23606 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23607 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
23608 debug_line_section_label);
23610 output_comdat_type_unit (ctnode);
23613 htab_delete (comdat_type_table);
23615 /* Output the main compilation unit if non-empty or if .debug_macinfo
23616 will be emitted. */
23617 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
23619 /* Output the abbreviation table. */
23620 switch_to_section (debug_abbrev_section);
23621 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
23622 output_abbrev_section ();
23624 /* Output location list section if necessary. */
23625 if (have_location_lists)
23627 /* Output the location lists info. */
23628 switch_to_section (debug_loc_section);
23629 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
23630 DEBUG_LOC_SECTION_LABEL, 0);
23631 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
23632 output_location_lists (comp_unit_die ());
23635 /* Output public names table if necessary. */
23636 if (!VEC_empty (pubname_entry, pubname_table))
23638 gcc_assert (info_section_emitted);
23639 switch_to_section (debug_pubnames_section);
23640 output_pubnames (pubname_table);
23643 /* Output public types table if necessary. */
23644 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23645 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23646 simply won't look for the section. */
23647 if (!VEC_empty (pubname_entry, pubtype_table))
23649 bool empty = false;
23651 if (flag_eliminate_unused_debug_types)
23653 /* The pubtypes table might be emptied by pruning unused items. */
23657 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
23658 if (p->die->die_offset != 0)
23666 gcc_assert (info_section_emitted);
23667 switch_to_section (debug_pubtypes_section);
23668 output_pubnames (pubtype_table);
23672 /* Output the address range information. We only put functions in the arange
23673 table, so don't write it out if we don't have any. */
23674 if ((text_section_used || cold_text_section_used || arange_table_in_use)
23675 && info_section_emitted)
23677 switch_to_section (debug_aranges_section);
23681 /* Output ranges section if necessary. */
23682 if (ranges_table_in_use)
23684 switch_to_section (debug_ranges_section);
23685 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
23689 /* Output the source line correspondence table. We must do this
23690 even if there is no line information. Otherwise, on an empty
23691 translation unit, we will generate a present, but empty,
23692 .debug_info section. IRIX 6.5 `nm' will then complain when
23693 examining the file. This is done late so that any filenames
23694 used by the debug_info section are marked as 'used'. */
23695 switch_to_section (debug_line_section);
23696 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
23697 if (! DWARF2_ASM_LINE_DEBUG_INFO)
23698 output_line_info ();
23700 /* Have to end the macro section. */
23701 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23703 switch_to_section (debug_macinfo_section);
23704 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
23705 if (!VEC_empty (macinfo_entry, macinfo_table))
23707 dw2_asm_output_data (1, 0, "End compilation unit");
23710 /* If we emitted any DW_FORM_strp form attribute, output the string
23712 if (debug_str_hash)
23713 htab_traverse (debug_str_hash, output_indirect_string, NULL);
23716 #include "gt-dwarf2out.h"