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} 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 (postinc <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;
2594 offset = GET_MODE_SIZE (GET_MODE (dest));
2595 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2598 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2599 == STACK_POINTER_REGNUM)
2600 && cfa_store.reg == STACK_POINTER_REGNUM);
2602 cfa_store.offset += offset;
2604 /* Rule 18: If stack is aligned, we will use FP as a
2605 reference to represent the address of the stored
2608 && fde->stack_realign
2609 && src == hard_frame_pointer_rtx)
2611 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2612 cfa_store.offset = 0;
2615 if (cfa.reg == STACK_POINTER_REGNUM)
2616 cfa.offset = cfa_store.offset;
2618 offset = -cfa_store.offset;
2622 /* With an offset. */
2629 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2630 && REG_P (XEXP (XEXP (dest, 0), 0)));
2631 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2632 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2635 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2637 if (cfa.reg == (unsigned) regno)
2638 offset -= cfa.offset;
2639 else if (cfa_store.reg == (unsigned) regno)
2640 offset -= cfa_store.offset;
2643 gcc_assert (cfa_temp.reg == (unsigned) regno);
2644 offset -= cfa_temp.offset;
2650 /* Without an offset. */
2653 int regno = REGNO (XEXP (dest, 0));
2655 if (cfa.reg == (unsigned) regno)
2656 offset = -cfa.offset;
2657 else if (cfa_store.reg == (unsigned) regno)
2658 offset = -cfa_store.offset;
2661 gcc_assert (cfa_temp.reg == (unsigned) regno);
2662 offset = -cfa_temp.offset;
2669 gcc_assert (cfa_temp.reg
2670 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2671 offset = -cfa_temp.offset;
2672 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2680 /* If the source operand of this MEM operation is not a
2681 register, basically the source is return address. Here
2682 we only care how much stack grew and we don't save it. */
2686 if (REGNO (src) != STACK_POINTER_REGNUM
2687 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2688 && (unsigned) REGNO (src) == cfa.reg)
2690 /* We're storing the current CFA reg into the stack. */
2692 if (cfa.offset == 0)
2695 /* If stack is aligned, putting CFA reg into stack means
2696 we can no longer use reg + offset to represent CFA.
2697 Here we use DW_CFA_def_cfa_expression instead. The
2698 result of this expression equals to the original CFA
2701 && fde->stack_realign
2702 && cfa.indirect == 0
2703 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2705 dw_cfa_location cfa_exp;
2707 gcc_assert (fde->drap_reg == cfa.reg);
2709 cfa_exp.indirect = 1;
2710 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2711 cfa_exp.base_offset = offset;
2714 fde->drap_reg_saved = 1;
2716 def_cfa_1 (label, &cfa_exp);
2720 /* If the source register is exactly the CFA, assume
2721 we're saving SP like any other register; this happens
2723 def_cfa_1 (label, &cfa);
2724 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2729 /* Otherwise, we'll need to look in the stack to
2730 calculate the CFA. */
2731 rtx x = XEXP (dest, 0);
2735 gcc_assert (REG_P (x));
2737 cfa.reg = REGNO (x);
2738 cfa.base_offset = offset;
2740 def_cfa_1 (label, &cfa);
2745 def_cfa_1 (label, &cfa);
2747 span = targetm.dwarf_register_span (src);
2750 queue_reg_save (label, src, NULL_RTX, offset);
2753 /* We have a PARALLEL describing where the contents of SRC
2754 live. Queue register saves for each piece of the
2758 HOST_WIDE_INT span_offset = offset;
2760 gcc_assert (GET_CODE (span) == PARALLEL);
2762 limit = XVECLEN (span, 0);
2763 for (par_index = 0; par_index < limit; par_index++)
2765 rtx elem = XVECEXP (span, 0, par_index);
2767 queue_reg_save (label, elem, NULL_RTX, span_offset);
2768 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2779 /* Record call frame debugging information for INSN, which either
2780 sets SP or FP (adjusting how we calculate the frame address) or saves a
2781 register to the stack. If INSN is NULL_RTX, initialize our state.
2783 If AFTER_P is false, we're being called before the insn is emitted,
2784 otherwise after. Call instructions get invoked twice. */
2787 dwarf2out_frame_debug (rtx insn, bool after_p)
2791 bool handled_one = false;
2793 if (insn == NULL_RTX)
2797 /* Flush any queued register saves. */
2798 dwarf2out_flush_queued_reg_saves ();
2800 /* Set up state for generating call frame debug info. */
2803 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2805 cfa.reg = STACK_POINTER_REGNUM;
2808 cfa_temp.offset = 0;
2810 for (i = 0; i < num_regs_saved_in_regs; i++)
2812 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2813 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2815 num_regs_saved_in_regs = 0;
2817 if (barrier_args_size)
2819 XDELETEVEC (barrier_args_size);
2820 barrier_args_size = NULL;
2825 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2826 dwarf2out_flush_queued_reg_saves ();
2828 if (!RTX_FRAME_RELATED_P (insn))
2830 /* ??? This should be done unconditionally since stack adjustments
2831 matter if the stack pointer is not the CFA register anymore but
2832 is still used to save registers. */
2833 if (!ACCUMULATE_OUTGOING_ARGS)
2834 dwarf2out_notice_stack_adjust (insn, after_p);
2838 label = dwarf2out_cfi_label (false);
2839 any_cfis_emitted = false;
2841 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2842 switch (REG_NOTE_KIND (note))
2844 case REG_FRAME_RELATED_EXPR:
2845 insn = XEXP (note, 0);
2848 case REG_CFA_DEF_CFA:
2849 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2853 case REG_CFA_ADJUST_CFA:
2858 if (GET_CODE (n) == PARALLEL)
2859 n = XVECEXP (n, 0, 0);
2861 dwarf2out_frame_debug_adjust_cfa (n, label);
2865 case REG_CFA_OFFSET:
2868 n = single_set (insn);
2869 dwarf2out_frame_debug_cfa_offset (n, label);
2873 case REG_CFA_REGISTER:
2878 if (GET_CODE (n) == PARALLEL)
2879 n = XVECEXP (n, 0, 0);
2881 dwarf2out_frame_debug_cfa_register (n, label);
2885 case REG_CFA_EXPRESSION:
2888 n = single_set (insn);
2889 dwarf2out_frame_debug_cfa_expression (n, label);
2893 case REG_CFA_RESTORE:
2898 if (GET_CODE (n) == PARALLEL)
2899 n = XVECEXP (n, 0, 0);
2902 dwarf2out_frame_debug_cfa_restore (n, label);
2906 case REG_CFA_SET_VDRAP:
2910 dw_fde_ref fde = current_fde ();
2913 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2915 fde->vdrap_reg = REGNO (n);
2926 if (any_cfis_emitted)
2927 dwarf2out_flush_queued_reg_saves ();
2931 insn = PATTERN (insn);
2933 dwarf2out_frame_debug_expr (insn, label);
2935 /* Check again. A parallel can save and update the same register.
2936 We could probably check just once, here, but this is safer than
2937 removing the check above. */
2938 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2939 dwarf2out_flush_queued_reg_saves ();
2942 /* Determine if we need to save and restore CFI information around this
2943 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2944 we do need to save/restore, then emit the save now, and insert a
2945 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2948 dwarf2out_cfi_begin_epilogue (rtx insn)
2950 bool saw_frp = false;
2953 /* Scan forward to the return insn, noticing if there are possible
2954 frame related insns. */
2955 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2960 /* Look for both regular and sibcalls to end the block. */
2961 if (returnjump_p (i))
2963 if (CALL_P (i) && SIBLING_CALL_P (i))
2966 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2969 rtx seq = PATTERN (i);
2971 if (returnjump_p (XVECEXP (seq, 0, 0)))
2973 if (CALL_P (XVECEXP (seq, 0, 0))
2974 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2977 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2978 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2982 if (RTX_FRAME_RELATED_P (i))
2986 /* If the port doesn't emit epilogue unwind info, we don't need a
2987 save/restore pair. */
2991 /* Otherwise, search forward to see if the return insn was the last
2992 basic block of the function. If so, we don't need save/restore. */
2993 gcc_assert (i != NULL);
2994 i = next_real_insn (i);
2998 /* Insert the restore before that next real insn in the stream, and before
2999 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3000 properly nested. This should be after any label or alignment. This
3001 will be pushed into the CFI stream by the function below. */
3004 rtx p = PREV_INSN (i);
3007 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3011 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3013 emit_cfa_remember = true;
3015 /* And emulate the state save. */
3016 gcc_assert (!cfa_remember.in_use);
3018 cfa_remember.in_use = 1;
3021 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3025 dwarf2out_frame_debug_restore_state (void)
3027 dw_cfi_ref cfi = new_cfi ();
3028 const char *label = dwarf2out_cfi_label (false);
3030 cfi->dw_cfi_opc = DW_CFA_restore_state;
3031 add_fde_cfi (label, cfi);
3033 gcc_assert (cfa_remember.in_use);
3035 cfa_remember.in_use = 0;
3038 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3039 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3040 (enum dwarf_call_frame_info cfi);
3042 static enum dw_cfi_oprnd_type
3043 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3048 case DW_CFA_GNU_window_save:
3049 case DW_CFA_remember_state:
3050 case DW_CFA_restore_state:
3051 return dw_cfi_oprnd_unused;
3053 case DW_CFA_set_loc:
3054 case DW_CFA_advance_loc1:
3055 case DW_CFA_advance_loc2:
3056 case DW_CFA_advance_loc4:
3057 case DW_CFA_MIPS_advance_loc8:
3058 return dw_cfi_oprnd_addr;
3061 case DW_CFA_offset_extended:
3062 case DW_CFA_def_cfa:
3063 case DW_CFA_offset_extended_sf:
3064 case DW_CFA_def_cfa_sf:
3065 case DW_CFA_restore:
3066 case DW_CFA_restore_extended:
3067 case DW_CFA_undefined:
3068 case DW_CFA_same_value:
3069 case DW_CFA_def_cfa_register:
3070 case DW_CFA_register:
3071 case DW_CFA_expression:
3072 return dw_cfi_oprnd_reg_num;
3074 case DW_CFA_def_cfa_offset:
3075 case DW_CFA_GNU_args_size:
3076 case DW_CFA_def_cfa_offset_sf:
3077 return dw_cfi_oprnd_offset;
3079 case DW_CFA_def_cfa_expression:
3080 return dw_cfi_oprnd_loc;
3087 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3088 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3089 (enum dwarf_call_frame_info cfi);
3091 static enum dw_cfi_oprnd_type
3092 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3096 case DW_CFA_def_cfa:
3097 case DW_CFA_def_cfa_sf:
3099 case DW_CFA_offset_extended_sf:
3100 case DW_CFA_offset_extended:
3101 return dw_cfi_oprnd_offset;
3103 case DW_CFA_register:
3104 return dw_cfi_oprnd_reg_num;
3106 case DW_CFA_expression:
3107 return dw_cfi_oprnd_loc;
3110 return dw_cfi_oprnd_unused;
3114 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3115 switch to the data section instead, and write out a synthetic start label
3116 for collect2 the first time around. */
3119 switch_to_eh_frame_section (bool back)
3123 #ifdef EH_FRAME_SECTION_NAME
3124 if (eh_frame_section == 0)
3128 if (EH_TABLES_CAN_BE_READ_ONLY)
3134 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3136 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3138 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3140 flags = ((! flag_pic
3141 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3142 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3143 && (per_encoding & 0x70) != DW_EH_PE_absptr
3144 && (per_encoding & 0x70) != DW_EH_PE_aligned
3145 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3146 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3147 ? 0 : SECTION_WRITE);
3150 flags = SECTION_WRITE;
3151 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3153 #endif /* EH_FRAME_SECTION_NAME */
3155 if (eh_frame_section)
3156 switch_to_section (eh_frame_section);
3159 /* We have no special eh_frame section. Put the information in
3160 the data section and emit special labels to guide collect2. */
3161 switch_to_section (data_section);
3165 label = get_file_function_name ("F");
3166 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3167 targetm.asm_out.globalize_label (asm_out_file,
3168 IDENTIFIER_POINTER (label));
3169 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3174 /* Switch [BACK] to the eh or debug frame table section, depending on
3178 switch_to_frame_table_section (int for_eh, bool back)
3181 switch_to_eh_frame_section (back);
3184 if (!debug_frame_section)
3185 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3186 SECTION_DEBUG, NULL);
3187 switch_to_section (debug_frame_section);
3191 /* Output a Call Frame Information opcode and its operand(s). */
3194 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3199 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3200 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3201 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3202 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3203 ((unsigned HOST_WIDE_INT)
3204 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3205 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3207 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3208 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3209 "DW_CFA_offset, column %#lx", r);
3210 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3211 dw2_asm_output_data_uleb128 (off, NULL);
3213 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3215 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3216 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3217 "DW_CFA_restore, column %#lx", r);
3221 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3222 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3224 switch (cfi->dw_cfi_opc)
3226 case DW_CFA_set_loc:
3228 dw2_asm_output_encoded_addr_rtx (
3229 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3230 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3233 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3234 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3235 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3238 case DW_CFA_advance_loc1:
3239 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3240 fde->dw_fde_current_label, NULL);
3241 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3244 case DW_CFA_advance_loc2:
3245 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3246 fde->dw_fde_current_label, NULL);
3247 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3250 case DW_CFA_advance_loc4:
3251 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3252 fde->dw_fde_current_label, NULL);
3253 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3256 case DW_CFA_MIPS_advance_loc8:
3257 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3258 fde->dw_fde_current_label, NULL);
3259 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3262 case DW_CFA_offset_extended:
3263 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3264 dw2_asm_output_data_uleb128 (r, NULL);
3265 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3266 dw2_asm_output_data_uleb128 (off, NULL);
3269 case DW_CFA_def_cfa:
3270 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3271 dw2_asm_output_data_uleb128 (r, NULL);
3272 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3275 case DW_CFA_offset_extended_sf:
3276 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3277 dw2_asm_output_data_uleb128 (r, NULL);
3278 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3279 dw2_asm_output_data_sleb128 (off, NULL);
3282 case DW_CFA_def_cfa_sf:
3283 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3284 dw2_asm_output_data_uleb128 (r, NULL);
3285 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3286 dw2_asm_output_data_sleb128 (off, NULL);
3289 case DW_CFA_restore_extended:
3290 case DW_CFA_undefined:
3291 case DW_CFA_same_value:
3292 case DW_CFA_def_cfa_register:
3293 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3294 dw2_asm_output_data_uleb128 (r, NULL);
3297 case DW_CFA_register:
3298 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3299 dw2_asm_output_data_uleb128 (r, NULL);
3300 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3301 dw2_asm_output_data_uleb128 (r, NULL);
3304 case DW_CFA_def_cfa_offset:
3305 case DW_CFA_GNU_args_size:
3306 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3309 case DW_CFA_def_cfa_offset_sf:
3310 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3311 dw2_asm_output_data_sleb128 (off, NULL);
3314 case DW_CFA_GNU_window_save:
3317 case DW_CFA_def_cfa_expression:
3318 case DW_CFA_expression:
3319 output_cfa_loc (cfi, for_eh);
3322 case DW_CFA_GNU_negative_offset_extended:
3323 /* Obsoleted by DW_CFA_offset_extended_sf. */
3332 /* Similar, but do it via assembler directives instead. */
3335 output_cfi_directive (dw_cfi_ref cfi)
3337 unsigned long r, r2;
3339 switch (cfi->dw_cfi_opc)
3341 case DW_CFA_advance_loc:
3342 case DW_CFA_advance_loc1:
3343 case DW_CFA_advance_loc2:
3344 case DW_CFA_advance_loc4:
3345 case DW_CFA_MIPS_advance_loc8:
3346 case DW_CFA_set_loc:
3347 /* Should only be created by add_fde_cfi in a code path not
3348 followed when emitting via directives. The assembler is
3349 going to take care of this for us. */
3353 case DW_CFA_offset_extended:
3354 case DW_CFA_offset_extended_sf:
3355 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3356 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3357 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3360 case DW_CFA_restore:
3361 case DW_CFA_restore_extended:
3362 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3363 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3366 case DW_CFA_undefined:
3367 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3368 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3371 case DW_CFA_same_value:
3372 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3373 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3376 case DW_CFA_def_cfa:
3377 case DW_CFA_def_cfa_sf:
3378 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3379 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3380 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3383 case DW_CFA_def_cfa_register:
3384 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3385 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3388 case DW_CFA_register:
3389 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3390 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3391 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3394 case DW_CFA_def_cfa_offset:
3395 case DW_CFA_def_cfa_offset_sf:
3396 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3397 HOST_WIDE_INT_PRINT_DEC"\n",
3398 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3401 case DW_CFA_remember_state:
3402 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3404 case DW_CFA_restore_state:
3405 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3408 case DW_CFA_GNU_args_size:
3409 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3410 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3412 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3413 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3414 fputc ('\n', asm_out_file);
3417 case DW_CFA_GNU_window_save:
3418 fprintf (asm_out_file, "\t.cfi_window_save\n");
3421 case DW_CFA_def_cfa_expression:
3422 case DW_CFA_expression:
3423 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3424 output_cfa_loc_raw (cfi);
3425 fputc ('\n', asm_out_file);
3433 DEF_VEC_P (dw_cfi_ref);
3434 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3436 /* Output CFIs to bring current FDE to the same state as after executing
3437 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3438 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3439 other arguments to pass to output_cfi. */
3442 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3444 struct dw_cfi_struct cfi_buf;
3446 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3447 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3448 unsigned int len, idx;
3450 for (;; cfi = cfi->dw_cfi_next)
3451 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3453 case DW_CFA_advance_loc:
3454 case DW_CFA_advance_loc1:
3455 case DW_CFA_advance_loc2:
3456 case DW_CFA_advance_loc4:
3457 case DW_CFA_MIPS_advance_loc8:
3458 case DW_CFA_set_loc:
3459 /* All advances should be ignored. */
3461 case DW_CFA_remember_state:
3463 dw_cfi_ref args_size = cfi_args_size;
3465 /* Skip everything between .cfi_remember_state and
3466 .cfi_restore_state. */
3467 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3468 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3470 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3473 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3480 cfi_args_size = args_size;
3484 case DW_CFA_GNU_args_size:
3485 cfi_args_size = cfi;
3487 case DW_CFA_GNU_window_save:
3490 case DW_CFA_offset_extended:
3491 case DW_CFA_offset_extended_sf:
3492 case DW_CFA_restore:
3493 case DW_CFA_restore_extended:
3494 case DW_CFA_undefined:
3495 case DW_CFA_same_value:
3496 case DW_CFA_register:
3497 case DW_CFA_val_offset:
3498 case DW_CFA_val_offset_sf:
3499 case DW_CFA_expression:
3500 case DW_CFA_val_expression:
3501 case DW_CFA_GNU_negative_offset_extended:
3502 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3503 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3504 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3505 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3507 case DW_CFA_def_cfa:
3508 case DW_CFA_def_cfa_sf:
3509 case DW_CFA_def_cfa_expression:
3511 cfi_cfa_offset = cfi;
3513 case DW_CFA_def_cfa_register:
3516 case DW_CFA_def_cfa_offset:
3517 case DW_CFA_def_cfa_offset_sf:
3518 cfi_cfa_offset = cfi;
3521 gcc_assert (cfi == NULL);
3523 len = VEC_length (dw_cfi_ref, regs);
3524 for (idx = 0; idx < len; idx++)
3526 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3528 && cfi2->dw_cfi_opc != DW_CFA_restore
3529 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3532 output_cfi_directive (cfi2);
3534 output_cfi (cfi2, fde, for_eh);
3537 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3539 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3541 switch (cfi_cfa_offset->dw_cfi_opc)
3543 case DW_CFA_def_cfa_offset:
3544 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3545 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3547 case DW_CFA_def_cfa_offset_sf:
3548 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3549 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3551 case DW_CFA_def_cfa:
3552 case DW_CFA_def_cfa_sf:
3553 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3554 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3561 else if (cfi_cfa_offset)
3562 cfi_cfa = cfi_cfa_offset;
3566 output_cfi_directive (cfi_cfa);
3568 output_cfi (cfi_cfa, fde, for_eh);
3571 cfi_cfa_offset = NULL;
3573 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3576 output_cfi_directive (cfi_args_size);
3578 output_cfi (cfi_args_size, fde, for_eh);
3580 cfi_args_size = NULL;
3583 VEC_free (dw_cfi_ref, heap, regs);
3586 else if (do_cfi_asm)
3587 output_cfi_directive (cfi);
3589 output_cfi (cfi, fde, for_eh);
3596 /* Output one FDE. */
3599 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3600 char *section_start_label, int fde_encoding, char *augmentation,
3601 bool any_lsda_needed, int lsda_encoding)
3603 const char *begin, *end;
3604 static unsigned int j;
3605 char l1[20], l2[20];
3608 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3610 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3612 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3613 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3614 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3615 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3616 " indicating 64-bit DWARF extension");
3617 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3619 ASM_OUTPUT_LABEL (asm_out_file, l1);
3622 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3624 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3625 debug_frame_section, "FDE CIE offset");
3627 if (!fde->dw_fde_switched_sections)
3629 begin = fde->dw_fde_begin;
3630 end = fde->dw_fde_end;
3634 /* For the first section, prefer dw_fde_begin over
3635 dw_fde_{hot,cold}_section_label, as the latter
3636 might be separated from the real start of the
3637 function by alignment padding. */
3639 begin = fde->dw_fde_begin;
3640 else if (fde->dw_fde_switched_cold_to_hot)
3641 begin = fde->dw_fde_hot_section_label;
3643 begin = fde->dw_fde_unlikely_section_label;
3644 if (second ^ fde->dw_fde_switched_cold_to_hot)
3645 end = fde->dw_fde_unlikely_section_end_label;
3647 end = fde->dw_fde_hot_section_end_label;
3652 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3653 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3654 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3655 "FDE initial location");
3656 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3657 end, begin, "FDE address range");
3661 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3662 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3665 if (augmentation[0])
3667 if (any_lsda_needed)
3669 int size = size_of_encoded_value (lsda_encoding);
3671 if (lsda_encoding == DW_EH_PE_aligned)
3673 int offset = ( 4 /* Length */
3674 + 4 /* CIE offset */
3675 + 2 * size_of_encoded_value (fde_encoding)
3676 + 1 /* Augmentation size */ );
3677 int pad = -offset & (PTR_SIZE - 1);
3680 gcc_assert (size_of_uleb128 (size) == 1);
3683 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3685 if (fde->uses_eh_lsda)
3687 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3688 fde->funcdef_number);
3689 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3690 gen_rtx_SYMBOL_REF (Pmode, l1),
3692 "Language Specific Data Area");
3696 if (lsda_encoding == DW_EH_PE_aligned)
3697 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3698 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3699 "Language Specific Data Area (none)");
3703 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3706 /* Loop through the Call Frame Instructions associated with
3708 fde->dw_fde_current_label = begin;
3709 if (!fde->dw_fde_switched_sections)
3710 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3711 output_cfi (cfi, fde, for_eh);
3714 if (fde->dw_fde_switch_cfi)
3715 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3717 output_cfi (cfi, fde, for_eh);
3718 if (cfi == fde->dw_fde_switch_cfi)
3724 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3726 if (fde->dw_fde_switch_cfi)
3728 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3729 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3730 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3731 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3733 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3734 output_cfi (cfi, fde, for_eh);
3737 /* If we are to emit a ref/link from function bodies to their frame tables,
3738 do it now. This is typically performed to make sure that tables
3739 associated with functions are dragged with them and not discarded in
3740 garbage collecting links. We need to do this on a per function basis to
3741 cope with -ffunction-sections. */
3743 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3744 /* Switch to the function section, emit the ref to the tables, and
3745 switch *back* into the table section. */
3746 switch_to_section (function_section (fde->decl));
3747 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3748 switch_to_frame_table_section (for_eh, true);
3751 /* Pad the FDE out to an address sized boundary. */
3752 ASM_OUTPUT_ALIGN (asm_out_file,
3753 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3754 ASM_OUTPUT_LABEL (asm_out_file, l2);
3759 /* Return true if frame description entry FDE is needed for EH. */
3762 fde_needed_for_eh_p (dw_fde_ref fde)
3764 if (flag_asynchronous_unwind_tables)
3767 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3770 if (fde->uses_eh_lsda)
3773 /* If exceptions are enabled, we have collected nothrow info. */
3774 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3780 /* Output the call frame information used to record information
3781 that relates to calculating the frame pointer, and records the
3782 location of saved registers. */
3785 output_call_frame_info (int for_eh)
3790 char l1[20], l2[20], section_start_label[20];
3791 bool any_lsda_needed = false;
3792 char augmentation[6];
3793 int augmentation_size;
3794 int fde_encoding = DW_EH_PE_absptr;
3795 int per_encoding = DW_EH_PE_absptr;
3796 int lsda_encoding = DW_EH_PE_absptr;
3798 rtx personality = NULL;
3801 /* Don't emit a CIE if there won't be any FDEs. */
3802 if (fde_table_in_use == 0)
3805 /* Nothing to do if the assembler's doing it all. */
3806 if (dwarf2out_do_cfi_asm ())
3809 /* If we don't have any functions we'll want to unwind out of, don't emit
3810 any EH unwind information. If we make FDEs linkonce, we may have to
3811 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3812 want to avoid having an FDE kept around when the function it refers to
3813 is discarded. Example where this matters: a primary function template
3814 in C++ requires EH information, an explicit specialization doesn't. */
3817 bool any_eh_needed = false;
3819 for (i = 0; i < fde_table_in_use; i++)
3820 if (fde_table[i].uses_eh_lsda)
3821 any_eh_needed = any_lsda_needed = true;
3822 else if (fde_needed_for_eh_p (&fde_table[i]))
3823 any_eh_needed = true;
3824 else if (TARGET_USES_WEAK_UNWIND_INFO)
3825 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3832 /* We're going to be generating comments, so turn on app. */
3836 /* Switch to the proper frame section, first time. */
3837 switch_to_frame_table_section (for_eh, false);
3839 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3840 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3842 /* Output the CIE. */
3843 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3844 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3845 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3846 dw2_asm_output_data (4, 0xffffffff,
3847 "Initial length escape value indicating 64-bit DWARF extension");
3848 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3849 "Length of Common Information Entry");
3850 ASM_OUTPUT_LABEL (asm_out_file, l1);
3852 /* Now that the CIE pointer is PC-relative for EH,
3853 use 0 to identify the CIE. */
3854 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3855 (for_eh ? 0 : DWARF_CIE_ID),
3856 "CIE Identifier Tag");
3858 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3859 use CIE version 1, unless that would produce incorrect results
3860 due to overflowing the return register column. */
3861 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3863 if (return_reg >= 256 || dwarf_version > 2)
3865 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3867 augmentation[0] = 0;
3868 augmentation_size = 0;
3870 personality = current_unit_personality;
3876 z Indicates that a uleb128 is present to size the
3877 augmentation section.
3878 L Indicates the encoding (and thus presence) of
3879 an LSDA pointer in the FDE augmentation.
3880 R Indicates a non-default pointer encoding for
3882 P Indicates the presence of an encoding + language
3883 personality routine in the CIE augmentation. */
3885 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3886 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3887 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3889 p = augmentation + 1;
3893 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3894 assemble_external_libcall (personality);
3896 if (any_lsda_needed)
3899 augmentation_size += 1;
3901 if (fde_encoding != DW_EH_PE_absptr)
3904 augmentation_size += 1;
3906 if (p > augmentation + 1)
3908 augmentation[0] = 'z';
3912 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3913 if (personality && per_encoding == DW_EH_PE_aligned)
3915 int offset = ( 4 /* Length */
3917 + 1 /* CIE version */
3918 + strlen (augmentation) + 1 /* Augmentation */
3919 + size_of_uleb128 (1) /* Code alignment */
3920 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3922 + 1 /* Augmentation size */
3923 + 1 /* Personality encoding */ );
3924 int pad = -offset & (PTR_SIZE - 1);
3926 augmentation_size += pad;
3928 /* Augmentations should be small, so there's scarce need to
3929 iterate for a solution. Die if we exceed one uleb128 byte. */
3930 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3934 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3935 if (dw_cie_version >= 4)
3937 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3938 dw2_asm_output_data (1, 0, "CIE Segment Size");
3940 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3941 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3942 "CIE Data Alignment Factor");
3944 if (dw_cie_version == 1)
3945 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3947 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3949 if (augmentation[0])
3951 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3954 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3955 eh_data_format_name (per_encoding));
3956 dw2_asm_output_encoded_addr_rtx (per_encoding,
3961 if (any_lsda_needed)
3962 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3963 eh_data_format_name (lsda_encoding));
3965 if (fde_encoding != DW_EH_PE_absptr)
3966 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3967 eh_data_format_name (fde_encoding));
3970 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3971 output_cfi (cfi, NULL, for_eh);
3973 /* Pad the CIE out to an address sized boundary. */
3974 ASM_OUTPUT_ALIGN (asm_out_file,
3975 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3976 ASM_OUTPUT_LABEL (asm_out_file, l2);
3978 /* Loop through all of the FDE's. */
3979 for (i = 0; i < fde_table_in_use; i++)
3982 fde = &fde_table[i];
3984 /* Don't emit EH unwind info for leaf functions that don't need it. */
3985 if (for_eh && !fde_needed_for_eh_p (fde))
3988 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3989 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3990 augmentation, any_lsda_needed, lsda_encoding);
3993 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3994 dw2_asm_output_data (4, 0, "End of Table");
3995 #ifdef MIPS_DEBUGGING_INFO
3996 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3997 get a value of 0. Putting .align 0 after the label fixes it. */
3998 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4001 /* Turn off app to make assembly quicker. */
4006 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4009 dwarf2out_do_cfi_startproc (bool second)
4013 rtx personality = get_personality_function (current_function_decl);
4015 fprintf (asm_out_file, "\t.cfi_startproc\n");
4019 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4022 /* ??? The GAS support isn't entirely consistent. We have to
4023 handle indirect support ourselves, but PC-relative is done
4024 in the assembler. Further, the assembler can't handle any
4025 of the weirder relocation types. */
4026 if (enc & DW_EH_PE_indirect)
4027 ref = dw2_force_const_mem (ref, true);
4029 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4030 output_addr_const (asm_out_file, ref);
4031 fputc ('\n', asm_out_file);
4034 if (crtl->uses_eh_lsda)
4038 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4039 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4040 current_function_funcdef_no);
4041 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4042 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4044 if (enc & DW_EH_PE_indirect)
4045 ref = dw2_force_const_mem (ref, true);
4047 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4048 output_addr_const (asm_out_file, ref);
4049 fputc ('\n', asm_out_file);
4053 /* Output a marker (i.e. a label) for the beginning of a function, before
4057 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4058 const char *file ATTRIBUTE_UNUSED)
4060 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4066 current_function_func_begin_label = NULL;
4068 do_frame = dwarf2out_do_frame ();
4070 /* ??? current_function_func_begin_label is also used by except.c for
4071 call-site information. We must emit this label if it might be used. */
4073 && (!flag_exceptions
4074 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4077 fnsec = function_section (current_function_decl);
4078 switch_to_section (fnsec);
4079 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4080 current_function_funcdef_no);
4081 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4082 current_function_funcdef_no);
4083 dup_label = xstrdup (label);
4084 current_function_func_begin_label = dup_label;
4086 /* We can elide the fde allocation if we're not emitting debug info. */
4090 /* Expand the fde table if necessary. */
4091 if (fde_table_in_use == fde_table_allocated)
4093 fde_table_allocated += FDE_TABLE_INCREMENT;
4094 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4095 memset (fde_table + fde_table_in_use, 0,
4096 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4099 /* Record the FDE associated with this function. */
4100 current_funcdef_fde = fde_table_in_use;
4102 /* Add the new FDE at the end of the fde_table. */
4103 fde = &fde_table[fde_table_in_use++];
4104 fde->decl = current_function_decl;
4105 fde->dw_fde_begin = dup_label;
4106 fde->dw_fde_current_label = dup_label;
4107 fde->dw_fde_hot_section_label = NULL;
4108 fde->dw_fde_hot_section_end_label = NULL;
4109 fde->dw_fde_unlikely_section_label = NULL;
4110 fde->dw_fde_unlikely_section_end_label = NULL;
4111 fde->dw_fde_switched_sections = 0;
4112 fde->dw_fde_switched_cold_to_hot = 0;
4113 fde->dw_fde_end = NULL;
4114 fde->dw_fde_vms_end_prologue = NULL;
4115 fde->dw_fde_vms_begin_epilogue = NULL;
4116 fde->dw_fde_cfi = NULL;
4117 fde->dw_fde_switch_cfi = NULL;
4118 fde->funcdef_number = current_function_funcdef_no;
4119 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4120 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4121 fde->nothrow = crtl->nothrow;
4122 fde->drap_reg = INVALID_REGNUM;
4123 fde->vdrap_reg = INVALID_REGNUM;
4124 if (flag_reorder_blocks_and_partition)
4126 section *unlikelysec;
4127 if (first_function_block_is_cold)
4128 fde->in_std_section = 1;
4131 = (fnsec == text_section
4132 || (cold_text_section && fnsec == cold_text_section));
4133 unlikelysec = unlikely_text_section ();
4134 fde->cold_in_std_section
4135 = (unlikelysec == text_section
4136 || (cold_text_section && unlikelysec == cold_text_section));
4141 = (fnsec == text_section
4142 || (cold_text_section && fnsec == cold_text_section));
4143 fde->cold_in_std_section = 0;
4146 args_size = old_args_size = 0;
4148 /* We only want to output line number information for the genuine dwarf2
4149 prologue case, not the eh frame case. */
4150 #ifdef DWARF2_DEBUGGING_INFO
4152 dwarf2out_source_line (line, file, 0, true);
4155 if (dwarf2out_do_cfi_asm ())
4156 dwarf2out_do_cfi_startproc (false);
4159 rtx personality = get_personality_function (current_function_decl);
4160 if (!current_unit_personality)
4161 current_unit_personality = personality;
4163 /* We cannot keep a current personality per function as without CFI
4164 asm, at the point where we emit the CFI data, there is no current
4165 function anymore. */
4166 if (personality && current_unit_personality != personality)
4167 sorry ("multiple EH personalities are supported only with assemblers "
4168 "supporting .cfi_personality directive");
4172 /* Output a marker (i.e. a label) for the end of the generated code
4173 for a function prologue. This gets called *after* the prologue code has
4177 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4178 const char *file ATTRIBUTE_UNUSED)
4181 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4183 /* Output a label to mark the endpoint of the code generated for this
4185 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4186 current_function_funcdef_no);
4187 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4188 current_function_funcdef_no);
4189 fde = &fde_table[fde_table_in_use - 1];
4190 fde->dw_fde_vms_end_prologue = xstrdup (label);
4193 /* Output a marker (i.e. a label) for the beginning of the generated code
4194 for a function epilogue. This gets called *before* the prologue code has
4198 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4199 const char *file ATTRIBUTE_UNUSED)
4202 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4204 fde = &fde_table[fde_table_in_use - 1];
4205 if (fde->dw_fde_vms_begin_epilogue)
4208 /* Output a label to mark the endpoint of the code generated for this
4210 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4211 current_function_funcdef_no);
4212 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4213 current_function_funcdef_no);
4214 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4217 /* Output a marker (i.e. a label) for the absolute end of the generated code
4218 for a function definition. This gets called *after* the epilogue code has
4222 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4223 const char *file ATTRIBUTE_UNUSED)
4226 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4228 last_var_location_insn = NULL_RTX;
4230 if (dwarf2out_do_cfi_asm ())
4231 fprintf (asm_out_file, "\t.cfi_endproc\n");
4233 /* Output a label to mark the endpoint of the code generated for this
4235 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4236 current_function_funcdef_no);
4237 ASM_OUTPUT_LABEL (asm_out_file, label);
4238 fde = current_fde ();
4239 gcc_assert (fde != NULL);
4240 fde->dw_fde_end = xstrdup (label);
4244 dwarf2out_frame_init (void)
4246 /* Allocate the initial hunk of the fde_table. */
4247 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4248 fde_table_allocated = FDE_TABLE_INCREMENT;
4249 fde_table_in_use = 0;
4251 /* Generate the CFA instructions common to all FDE's. Do it now for the
4252 sake of lookup_cfa. */
4254 /* On entry, the Canonical Frame Address is at SP. */
4255 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4257 if (targetm.debug_unwind_info () == UI_DWARF2
4258 || targetm.except_unwind_info (&global_options) == UI_DWARF2)
4259 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4263 dwarf2out_frame_finish (void)
4265 /* Output call frame information. */
4266 if (targetm.debug_unwind_info () == UI_DWARF2)
4267 output_call_frame_info (0);
4269 /* Output another copy for the unwinder. */
4270 if ((flag_unwind_tables || flag_exceptions)
4271 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
4272 output_call_frame_info (1);
4275 /* Note that the current function section is being used for code. */
4278 dwarf2out_note_section_used (void)
4280 section *sec = current_function_section ();
4281 if (sec == text_section)
4282 text_section_used = true;
4283 else if (sec == cold_text_section)
4284 cold_text_section_used = true;
4288 dwarf2out_switch_text_section (void)
4290 dw_fde_ref fde = current_fde ();
4292 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4294 fde->dw_fde_switched_sections = 1;
4295 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4297 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4298 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4299 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4300 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4301 have_multiple_function_sections = true;
4303 /* Reset the current label on switching text sections, so that we
4304 don't attempt to advance_loc4 between labels in different sections. */
4305 fde->dw_fde_current_label = NULL;
4307 /* There is no need to mark used sections when not debugging. */
4308 if (cold_text_section != NULL)
4309 dwarf2out_note_section_used ();
4311 if (dwarf2out_do_cfi_asm ())
4312 fprintf (asm_out_file, "\t.cfi_endproc\n");
4314 /* Now do the real section switch. */
4315 switch_to_section (current_function_section ());
4317 if (dwarf2out_do_cfi_asm ())
4319 dwarf2out_do_cfi_startproc (true);
4320 /* As this is a different FDE, insert all current CFI instructions
4322 output_cfis (fde->dw_fde_cfi, true, fde, true);
4326 dw_cfi_ref cfi = fde->dw_fde_cfi;
4328 cfi = fde->dw_fde_cfi;
4330 while (cfi->dw_cfi_next != NULL)
4331 cfi = cfi->dw_cfi_next;
4332 fde->dw_fde_switch_cfi = cfi;
4336 /* And now, the subset of the debugging information support code necessary
4337 for emitting location expressions. */
4339 /* Data about a single source file. */
4340 struct GTY(()) dwarf_file_data {
4341 const char * filename;
4345 typedef struct dw_val_struct *dw_val_ref;
4346 typedef struct die_struct *dw_die_ref;
4347 typedef const struct die_struct *const_dw_die_ref;
4348 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4349 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4351 typedef struct GTY(()) deferred_locations_struct
4355 } deferred_locations;
4357 DEF_VEC_O(deferred_locations);
4358 DEF_VEC_ALLOC_O(deferred_locations,gc);
4360 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4362 DEF_VEC_P(dw_die_ref);
4363 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4365 /* Each DIE may have a series of attribute/value pairs. Values
4366 can take on several forms. The forms that are used in this
4367 implementation are listed below. */
4372 dw_val_class_offset,
4374 dw_val_class_loc_list,
4375 dw_val_class_range_list,
4377 dw_val_class_unsigned_const,
4378 dw_val_class_const_double,
4381 dw_val_class_die_ref,
4382 dw_val_class_fde_ref,
4383 dw_val_class_lbl_id,
4384 dw_val_class_lineptr,
4386 dw_val_class_macptr,
4389 dw_val_class_decl_ref,
4390 dw_val_class_vms_delta
4393 /* Describe a floating point constant value, or a vector constant value. */
4395 typedef struct GTY(()) dw_vec_struct {
4396 unsigned char * GTY((length ("%h.length"))) array;
4402 /* The dw_val_node describes an attribute's value, as it is
4403 represented internally. */
4405 typedef struct GTY(()) dw_val_struct {
4406 enum dw_val_class val_class;
4407 union dw_val_struct_union
4409 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4410 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4411 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4412 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4413 HOST_WIDE_INT GTY ((default)) val_int;
4414 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4415 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4416 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4417 struct dw_val_die_union
4421 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4422 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4423 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4424 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4425 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4426 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4427 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4428 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4429 struct dw_val_vms_delta_union
4433 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4435 GTY ((desc ("%1.val_class"))) v;
4439 /* Locations in memory are described using a sequence of stack machine
4442 typedef struct GTY(()) dw_loc_descr_struct {
4443 dw_loc_descr_ref dw_loc_next;
4444 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4445 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4446 from DW_OP_addr with a dtp-relative symbol relocation. */
4447 unsigned int dtprel : 1;
4449 dw_val_node dw_loc_oprnd1;
4450 dw_val_node dw_loc_oprnd2;
4454 /* Location lists are ranges + location descriptions for that range,
4455 so you can track variables that are in different places over
4456 their entire life. */
4457 typedef struct GTY(()) dw_loc_list_struct {
4458 dw_loc_list_ref dw_loc_next;
4459 const char *begin; /* Label for begin address of range */
4460 const char *end; /* Label for end address of range */
4461 char *ll_symbol; /* Label for beginning of location list.
4462 Only on head of list */
4463 const char *section; /* Section this loclist is relative to */
4464 dw_loc_descr_ref expr;
4469 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4471 /* Convert a DWARF stack opcode into its string name. */
4474 dwarf_stack_op_name (unsigned int op)
4479 return "DW_OP_addr";
4481 return "DW_OP_deref";
4483 return "DW_OP_const1u";
4485 return "DW_OP_const1s";
4487 return "DW_OP_const2u";
4489 return "DW_OP_const2s";
4491 return "DW_OP_const4u";
4493 return "DW_OP_const4s";
4495 return "DW_OP_const8u";
4497 return "DW_OP_const8s";
4499 return "DW_OP_constu";
4501 return "DW_OP_consts";
4505 return "DW_OP_drop";
4507 return "DW_OP_over";
4509 return "DW_OP_pick";
4511 return "DW_OP_swap";
4515 return "DW_OP_xderef";
4523 return "DW_OP_minus";
4535 return "DW_OP_plus";
4536 case DW_OP_plus_uconst:
4537 return "DW_OP_plus_uconst";
4543 return "DW_OP_shra";
4561 return "DW_OP_skip";
4563 return "DW_OP_lit0";
4565 return "DW_OP_lit1";
4567 return "DW_OP_lit2";
4569 return "DW_OP_lit3";
4571 return "DW_OP_lit4";
4573 return "DW_OP_lit5";
4575 return "DW_OP_lit6";
4577 return "DW_OP_lit7";
4579 return "DW_OP_lit8";
4581 return "DW_OP_lit9";
4583 return "DW_OP_lit10";
4585 return "DW_OP_lit11";
4587 return "DW_OP_lit12";
4589 return "DW_OP_lit13";
4591 return "DW_OP_lit14";
4593 return "DW_OP_lit15";
4595 return "DW_OP_lit16";
4597 return "DW_OP_lit17";
4599 return "DW_OP_lit18";
4601 return "DW_OP_lit19";
4603 return "DW_OP_lit20";
4605 return "DW_OP_lit21";
4607 return "DW_OP_lit22";
4609 return "DW_OP_lit23";
4611 return "DW_OP_lit24";
4613 return "DW_OP_lit25";
4615 return "DW_OP_lit26";
4617 return "DW_OP_lit27";
4619 return "DW_OP_lit28";
4621 return "DW_OP_lit29";
4623 return "DW_OP_lit30";
4625 return "DW_OP_lit31";
4627 return "DW_OP_reg0";
4629 return "DW_OP_reg1";
4631 return "DW_OP_reg2";
4633 return "DW_OP_reg3";
4635 return "DW_OP_reg4";
4637 return "DW_OP_reg5";
4639 return "DW_OP_reg6";
4641 return "DW_OP_reg7";
4643 return "DW_OP_reg8";
4645 return "DW_OP_reg9";
4647 return "DW_OP_reg10";
4649 return "DW_OP_reg11";
4651 return "DW_OP_reg12";
4653 return "DW_OP_reg13";
4655 return "DW_OP_reg14";
4657 return "DW_OP_reg15";
4659 return "DW_OP_reg16";
4661 return "DW_OP_reg17";
4663 return "DW_OP_reg18";
4665 return "DW_OP_reg19";
4667 return "DW_OP_reg20";
4669 return "DW_OP_reg21";
4671 return "DW_OP_reg22";
4673 return "DW_OP_reg23";
4675 return "DW_OP_reg24";
4677 return "DW_OP_reg25";
4679 return "DW_OP_reg26";
4681 return "DW_OP_reg27";
4683 return "DW_OP_reg28";
4685 return "DW_OP_reg29";
4687 return "DW_OP_reg30";
4689 return "DW_OP_reg31";
4691 return "DW_OP_breg0";
4693 return "DW_OP_breg1";
4695 return "DW_OP_breg2";
4697 return "DW_OP_breg3";
4699 return "DW_OP_breg4";
4701 return "DW_OP_breg5";
4703 return "DW_OP_breg6";
4705 return "DW_OP_breg7";
4707 return "DW_OP_breg8";
4709 return "DW_OP_breg9";
4711 return "DW_OP_breg10";
4713 return "DW_OP_breg11";
4715 return "DW_OP_breg12";
4717 return "DW_OP_breg13";
4719 return "DW_OP_breg14";
4721 return "DW_OP_breg15";
4723 return "DW_OP_breg16";
4725 return "DW_OP_breg17";
4727 return "DW_OP_breg18";
4729 return "DW_OP_breg19";
4731 return "DW_OP_breg20";
4733 return "DW_OP_breg21";
4735 return "DW_OP_breg22";
4737 return "DW_OP_breg23";
4739 return "DW_OP_breg24";
4741 return "DW_OP_breg25";
4743 return "DW_OP_breg26";
4745 return "DW_OP_breg27";
4747 return "DW_OP_breg28";
4749 return "DW_OP_breg29";
4751 return "DW_OP_breg30";
4753 return "DW_OP_breg31";
4755 return "DW_OP_regx";
4757 return "DW_OP_fbreg";
4759 return "DW_OP_bregx";
4761 return "DW_OP_piece";
4762 case DW_OP_deref_size:
4763 return "DW_OP_deref_size";
4764 case DW_OP_xderef_size:
4765 return "DW_OP_xderef_size";
4769 case DW_OP_push_object_address:
4770 return "DW_OP_push_object_address";
4772 return "DW_OP_call2";
4774 return "DW_OP_call4";
4775 case DW_OP_call_ref:
4776 return "DW_OP_call_ref";
4777 case DW_OP_implicit_value:
4778 return "DW_OP_implicit_value";
4779 case DW_OP_stack_value:
4780 return "DW_OP_stack_value";
4781 case DW_OP_form_tls_address:
4782 return "DW_OP_form_tls_address";
4783 case DW_OP_call_frame_cfa:
4784 return "DW_OP_call_frame_cfa";
4785 case DW_OP_bit_piece:
4786 return "DW_OP_bit_piece";
4788 case DW_OP_GNU_push_tls_address:
4789 return "DW_OP_GNU_push_tls_address";
4790 case DW_OP_GNU_uninit:
4791 return "DW_OP_GNU_uninit";
4792 case DW_OP_GNU_encoded_addr:
4793 return "DW_OP_GNU_encoded_addr";
4794 case DW_OP_GNU_implicit_pointer:
4795 return "DW_OP_GNU_implicit_pointer";
4796 case DW_OP_GNU_entry_value:
4797 return "DW_OP_GNU_entry_value";
4800 return "OP_<unknown>";
4804 /* Return a pointer to a newly allocated location description. Location
4805 descriptions are simple expression terms that can be strung
4806 together to form more complicated location (address) descriptions. */
4808 static inline dw_loc_descr_ref
4809 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4810 unsigned HOST_WIDE_INT oprnd2)
4812 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4814 descr->dw_loc_opc = op;
4815 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4816 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4817 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4818 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4823 /* Return a pointer to a newly allocated location description for
4826 static inline dw_loc_descr_ref
4827 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4830 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4833 return new_loc_descr (DW_OP_bregx, reg, offset);
4836 /* Add a location description term to a location description expression. */
4839 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4841 dw_loc_descr_ref *d;
4843 /* Find the end of the chain. */
4844 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4850 /* Add a constant OFFSET to a location expression. */
4853 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4855 dw_loc_descr_ref loc;
4858 gcc_assert (*list_head != NULL);
4863 /* Find the end of the chain. */
4864 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4868 if (loc->dw_loc_opc == DW_OP_fbreg
4869 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4870 p = &loc->dw_loc_oprnd1.v.val_int;
4871 else if (loc->dw_loc_opc == DW_OP_bregx)
4872 p = &loc->dw_loc_oprnd2.v.val_int;
4874 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4875 offset. Don't optimize if an signed integer overflow would happen. */
4877 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4878 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4881 else if (offset > 0)
4882 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4886 loc->dw_loc_next = int_loc_descriptor (-offset);
4887 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4891 /* Add a constant OFFSET to a location list. */
4894 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4897 for (d = list_head; d != NULL; d = d->dw_loc_next)
4898 loc_descr_plus_const (&d->expr, offset);
4901 #define DWARF_REF_SIZE \
4902 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4904 static unsigned long size_of_locs (dw_loc_descr_ref);
4906 /* Return the size of a location descriptor. */
4908 static unsigned long
4909 size_of_loc_descr (dw_loc_descr_ref loc)
4911 unsigned long size = 1;
4913 switch (loc->dw_loc_opc)
4916 size += DWARF2_ADDR_SIZE;
4935 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4938 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4943 case DW_OP_plus_uconst:
4944 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4982 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4985 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4988 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4991 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4992 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4995 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4997 case DW_OP_bit_piece:
4998 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4999 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
5001 case DW_OP_deref_size:
5002 case DW_OP_xderef_size:
5011 case DW_OP_call_ref:
5012 size += DWARF_REF_SIZE;
5014 case DW_OP_implicit_value:
5015 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5016 + loc->dw_loc_oprnd1.v.val_unsigned;
5018 case DW_OP_GNU_implicit_pointer:
5019 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5021 case DW_OP_GNU_entry_value:
5023 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
5024 size += size_of_uleb128 (op_size) + op_size;
5034 /* Return the size of a series of location descriptors. */
5036 static unsigned long
5037 size_of_locs (dw_loc_descr_ref loc)
5042 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5043 field, to avoid writing to a PCH file. */
5044 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5046 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5048 size += size_of_loc_descr (l);
5053 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5055 l->dw_loc_addr = size;
5056 size += size_of_loc_descr (l);
5062 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5063 static void get_ref_die_offset_label (char *, dw_die_ref);
5064 static void output_loc_sequence (dw_loc_descr_ref, int);
5066 /* Output location description stack opcode's operands (if any).
5067 The for_eh_or_skip parameter controls whether register numbers are
5068 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5069 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5070 info). This should be suppressed for the cases that have not been converted
5071 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5074 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5076 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5077 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5079 switch (loc->dw_loc_opc)
5081 #ifdef DWARF2_DEBUGGING_INFO
5084 dw2_asm_output_data (2, val1->v.val_int, NULL);
5089 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5090 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5092 fputc ('\n', asm_out_file);
5097 dw2_asm_output_data (4, val1->v.val_int, NULL);
5102 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5103 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5105 fputc ('\n', asm_out_file);
5110 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5111 dw2_asm_output_data (8, val1->v.val_int, NULL);
5118 gcc_assert (val1->val_class == dw_val_class_loc);
5119 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5121 dw2_asm_output_data (2, offset, NULL);
5124 case DW_OP_implicit_value:
5125 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5126 switch (val2->val_class)
5128 case dw_val_class_const:
5129 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5131 case dw_val_class_vec:
5133 unsigned int elt_size = val2->v.val_vec.elt_size;
5134 unsigned int len = val2->v.val_vec.length;
5138 if (elt_size > sizeof (HOST_WIDE_INT))
5143 for (i = 0, p = val2->v.val_vec.array;
5146 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5147 "fp or vector constant word %u", i);
5150 case dw_val_class_const_double:
5152 unsigned HOST_WIDE_INT first, second;
5154 if (WORDS_BIG_ENDIAN)
5156 first = val2->v.val_double.high;
5157 second = val2->v.val_double.low;
5161 first = val2->v.val_double.low;
5162 second = val2->v.val_double.high;
5164 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5166 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5170 case dw_val_class_addr:
5171 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5172 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5187 case DW_OP_implicit_value:
5188 /* We currently don't make any attempt to make sure these are
5189 aligned properly like we do for the main unwind info, so
5190 don't support emitting things larger than a byte if we're
5191 only doing unwinding. */
5196 dw2_asm_output_data (1, val1->v.val_int, NULL);
5199 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5202 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5205 dw2_asm_output_data (1, val1->v.val_int, NULL);
5207 case DW_OP_plus_uconst:
5208 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5242 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5246 unsigned r = val1->v.val_unsigned;
5247 if (for_eh_or_skip >= 0)
5248 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5249 gcc_assert (size_of_uleb128 (r)
5250 == size_of_uleb128 (val1->v.val_unsigned));
5251 dw2_asm_output_data_uleb128 (r, NULL);
5255 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5259 unsigned r = val1->v.val_unsigned;
5260 if (for_eh_or_skip >= 0)
5261 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5262 gcc_assert (size_of_uleb128 (r)
5263 == size_of_uleb128 (val1->v.val_unsigned));
5264 dw2_asm_output_data_uleb128 (r, NULL);
5265 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5269 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5271 case DW_OP_bit_piece:
5272 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5273 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5275 case DW_OP_deref_size:
5276 case DW_OP_xderef_size:
5277 dw2_asm_output_data (1, val1->v.val_int, NULL);
5283 if (targetm.asm_out.output_dwarf_dtprel)
5285 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5288 fputc ('\n', asm_out_file);
5295 #ifdef DWARF2_DEBUGGING_INFO
5296 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5303 case DW_OP_GNU_implicit_pointer:
5305 char label[MAX_ARTIFICIAL_LABEL_BYTES
5306 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5307 gcc_assert (val1->val_class == dw_val_class_die_ref);
5308 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5309 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5310 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5314 case DW_OP_GNU_entry_value:
5315 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5316 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5320 /* Other codes have no operands. */
5325 /* Output a sequence of location operations.
5326 The for_eh_or_skip parameter controls whether register numbers are
5327 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5328 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5329 info). This should be suppressed for the cases that have not been converted
5330 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5333 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5335 for (; loc != NULL; loc = loc->dw_loc_next)
5337 enum dwarf_location_atom opc = loc->dw_loc_opc;
5338 /* Output the opcode. */
5339 if (for_eh_or_skip >= 0
5340 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5342 unsigned r = (opc - DW_OP_breg0);
5343 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5344 gcc_assert (r <= 31);
5345 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5347 else if (for_eh_or_skip >= 0
5348 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5350 unsigned r = (opc - DW_OP_reg0);
5351 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5352 gcc_assert (r <= 31);
5353 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5356 dw2_asm_output_data (1, opc,
5357 "%s", dwarf_stack_op_name (opc));
5359 /* Output the operand(s) (if any). */
5360 output_loc_operands (loc, for_eh_or_skip);
5364 /* Output location description stack opcode's operands (if any).
5365 The output is single bytes on a line, suitable for .cfi_escape. */
5368 output_loc_operands_raw (dw_loc_descr_ref loc)
5370 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5371 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5373 switch (loc->dw_loc_opc)
5376 case DW_OP_implicit_value:
5377 /* We cannot output addresses in .cfi_escape, only bytes. */
5383 case DW_OP_deref_size:
5384 case DW_OP_xderef_size:
5385 fputc (',', asm_out_file);
5386 dw2_asm_output_data_raw (1, val1->v.val_int);
5391 fputc (',', asm_out_file);
5392 dw2_asm_output_data_raw (2, val1->v.val_int);
5397 fputc (',', asm_out_file);
5398 dw2_asm_output_data_raw (4, val1->v.val_int);
5403 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5404 fputc (',', asm_out_file);
5405 dw2_asm_output_data_raw (8, val1->v.val_int);
5413 gcc_assert (val1->val_class == dw_val_class_loc);
5414 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5416 fputc (',', asm_out_file);
5417 dw2_asm_output_data_raw (2, offset);
5423 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5424 gcc_assert (size_of_uleb128 (r)
5425 == size_of_uleb128 (val1->v.val_unsigned));
5426 fputc (',', asm_out_file);
5427 dw2_asm_output_data_uleb128_raw (r);
5432 case DW_OP_plus_uconst:
5434 fputc (',', asm_out_file);
5435 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5438 case DW_OP_bit_piece:
5439 fputc (',', asm_out_file);
5440 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5441 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5478 fputc (',', asm_out_file);
5479 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5484 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5485 gcc_assert (size_of_uleb128 (r)
5486 == size_of_uleb128 (val1->v.val_unsigned));
5487 fputc (',', asm_out_file);
5488 dw2_asm_output_data_uleb128_raw (r);
5489 fputc (',', asm_out_file);
5490 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5494 case DW_OP_GNU_implicit_pointer:
5495 case DW_OP_GNU_entry_value:
5500 /* Other codes have no operands. */
5506 output_loc_sequence_raw (dw_loc_descr_ref loc)
5510 enum dwarf_location_atom opc = loc->dw_loc_opc;
5511 /* Output the opcode. */
5512 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5514 unsigned r = (opc - DW_OP_breg0);
5515 r = DWARF2_FRAME_REG_OUT (r, 1);
5516 gcc_assert (r <= 31);
5517 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5519 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5521 unsigned r = (opc - DW_OP_reg0);
5522 r = DWARF2_FRAME_REG_OUT (r, 1);
5523 gcc_assert (r <= 31);
5524 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5526 /* Output the opcode. */
5527 fprintf (asm_out_file, "%#x", opc);
5528 output_loc_operands_raw (loc);
5530 if (!loc->dw_loc_next)
5532 loc = loc->dw_loc_next;
5534 fputc (',', asm_out_file);
5538 /* This routine will generate the correct assembly data for a location
5539 description based on a cfi entry with a complex address. */
5542 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5544 dw_loc_descr_ref loc;
5547 if (cfi->dw_cfi_opc == DW_CFA_expression)
5550 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5551 dw2_asm_output_data (1, r, NULL);
5552 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5555 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5557 /* Output the size of the block. */
5558 size = size_of_locs (loc);
5559 dw2_asm_output_data_uleb128 (size, NULL);
5561 /* Now output the operations themselves. */
5562 output_loc_sequence (loc, for_eh);
5565 /* Similar, but used for .cfi_escape. */
5568 output_cfa_loc_raw (dw_cfi_ref cfi)
5570 dw_loc_descr_ref loc;
5573 if (cfi->dw_cfi_opc == DW_CFA_expression)
5576 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5577 fprintf (asm_out_file, "%#x,", r);
5578 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5581 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5583 /* Output the size of the block. */
5584 size = size_of_locs (loc);
5585 dw2_asm_output_data_uleb128_raw (size);
5586 fputc (',', asm_out_file);
5588 /* Now output the operations themselves. */
5589 output_loc_sequence_raw (loc);
5592 /* This function builds a dwarf location descriptor sequence from a
5593 dw_cfa_location, adding the given OFFSET to the result of the
5596 static struct dw_loc_descr_struct *
5597 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5599 struct dw_loc_descr_struct *head, *tmp;
5601 offset += cfa->offset;
5605 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5606 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5607 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5608 add_loc_descr (&head, tmp);
5611 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5612 add_loc_descr (&head, tmp);
5616 head = new_reg_loc_descr (cfa->reg, offset);
5621 /* This function builds a dwarf location descriptor sequence for
5622 the address at OFFSET from the CFA when stack is aligned to
5625 static struct dw_loc_descr_struct *
5626 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5628 struct dw_loc_descr_struct *head;
5629 unsigned int dwarf_fp
5630 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5632 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5633 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5635 head = new_reg_loc_descr (dwarf_fp, 0);
5636 add_loc_descr (&head, int_loc_descriptor (alignment));
5637 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5638 loc_descr_plus_const (&head, offset);
5641 head = new_reg_loc_descr (dwarf_fp, offset);
5645 /* This function fills in aa dw_cfa_location structure from a dwarf location
5646 descriptor sequence. */
5649 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5651 struct dw_loc_descr_struct *ptr;
5653 cfa->base_offset = 0;
5657 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5659 enum dwarf_location_atom op = ptr->dw_loc_opc;
5695 cfa->reg = op - DW_OP_reg0;
5698 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5732 cfa->reg = op - DW_OP_breg0;
5733 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5736 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5737 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5742 case DW_OP_plus_uconst:
5743 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5746 internal_error ("DW_LOC_OP %s not implemented",
5747 dwarf_stack_op_name (ptr->dw_loc_opc));
5752 /* And now, the support for symbolic debugging information. */
5754 /* .debug_str support. */
5755 static int output_indirect_string (void **, void *);
5757 static void dwarf2out_init (const char *);
5758 static void dwarf2out_finish (const char *);
5759 static void dwarf2out_assembly_start (void);
5760 static void dwarf2out_define (unsigned int, const char *);
5761 static void dwarf2out_undef (unsigned int, const char *);
5762 static void dwarf2out_start_source_file (unsigned, const char *);
5763 static void dwarf2out_end_source_file (unsigned);
5764 static void dwarf2out_function_decl (tree);
5765 static void dwarf2out_begin_block (unsigned, unsigned);
5766 static void dwarf2out_end_block (unsigned, unsigned);
5767 static bool dwarf2out_ignore_block (const_tree);
5768 static void dwarf2out_global_decl (tree);
5769 static void dwarf2out_type_decl (tree, int);
5770 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5771 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5773 static void dwarf2out_abstract_function (tree);
5774 static void dwarf2out_var_location (rtx);
5775 static void dwarf2out_begin_function (tree);
5776 static void dwarf2out_set_name (tree, tree);
5778 /* The debug hooks structure. */
5780 const struct gcc_debug_hooks dwarf2_debug_hooks =
5784 dwarf2out_assembly_start,
5787 dwarf2out_start_source_file,
5788 dwarf2out_end_source_file,
5789 dwarf2out_begin_block,
5790 dwarf2out_end_block,
5791 dwarf2out_ignore_block,
5792 dwarf2out_source_line,
5793 dwarf2out_begin_prologue,
5794 #if VMS_DEBUGGING_INFO
5795 dwarf2out_vms_end_prologue,
5796 dwarf2out_vms_begin_epilogue,
5798 debug_nothing_int_charstar,
5799 debug_nothing_int_charstar,
5801 dwarf2out_end_epilogue,
5802 dwarf2out_begin_function,
5803 debug_nothing_int, /* end_function */
5804 dwarf2out_function_decl, /* function_decl */
5805 dwarf2out_global_decl,
5806 dwarf2out_type_decl, /* type_decl */
5807 dwarf2out_imported_module_or_decl,
5808 debug_nothing_tree, /* deferred_inline_function */
5809 /* The DWARF 2 backend tries to reduce debugging bloat by not
5810 emitting the abstract description of inline functions until
5811 something tries to reference them. */
5812 dwarf2out_abstract_function, /* outlining_inline_function */
5813 debug_nothing_rtx, /* label */
5814 debug_nothing_int, /* handle_pch */
5815 dwarf2out_var_location,
5816 dwarf2out_switch_text_section,
5818 1, /* start_end_main_source_file */
5819 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5822 /* NOTE: In the comments in this file, many references are made to
5823 "Debugging Information Entries". This term is abbreviated as `DIE'
5824 throughout the remainder of this file. */
5826 /* An internal representation of the DWARF output is built, and then
5827 walked to generate the DWARF debugging info. The walk of the internal
5828 representation is done after the entire program has been compiled.
5829 The types below are used to describe the internal representation. */
5831 /* Various DIE's use offsets relative to the beginning of the
5832 .debug_info section to refer to each other. */
5834 typedef long int dw_offset;
5836 /* Define typedefs here to avoid circular dependencies. */
5838 typedef struct dw_attr_struct *dw_attr_ref;
5839 typedef struct dw_line_info_struct *dw_line_info_ref;
5840 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5841 typedef struct pubname_struct *pubname_ref;
5842 typedef struct dw_ranges_struct *dw_ranges_ref;
5843 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5844 typedef struct comdat_type_struct *comdat_type_node_ref;
5846 /* Each entry in the line_info_table maintains the file and
5847 line number associated with the label generated for that
5848 entry. The label gives the PC value associated with
5849 the line number entry. */
5851 typedef struct GTY(()) dw_line_info_struct {
5852 unsigned long dw_file_num;
5853 unsigned long dw_line_num;
5857 /* Line information for functions in separate sections; each one gets its
5859 typedef struct GTY(()) dw_separate_line_info_struct {
5860 unsigned long dw_file_num;
5861 unsigned long dw_line_num;
5862 unsigned long function;
5864 dw_separate_line_info_entry;
5866 /* Each DIE attribute has a field specifying the attribute kind,
5867 a link to the next attribute in the chain, and an attribute value.
5868 Attributes are typically linked below the DIE they modify. */
5870 typedef struct GTY(()) dw_attr_struct {
5871 enum dwarf_attribute dw_attr;
5872 dw_val_node dw_attr_val;
5876 DEF_VEC_O(dw_attr_node);
5877 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5879 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5880 The children of each node form a circular list linked by
5881 die_sib. die_child points to the node *before* the "first" child node. */
5883 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5884 union die_symbol_or_type_node
5886 char * GTY ((tag ("0"))) die_symbol;
5887 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5889 GTY ((desc ("dwarf_version >= 4"))) die_id;
5890 VEC(dw_attr_node,gc) * die_attr;
5891 dw_die_ref die_parent;
5892 dw_die_ref die_child;
5894 dw_die_ref die_definition; /* ref from a specification to its definition */
5895 dw_offset die_offset;
5896 unsigned long die_abbrev;
5898 /* Die is used and must not be pruned as unused. */
5899 int die_perennial_p;
5900 unsigned int decl_id;
5901 enum dwarf_tag die_tag;
5905 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5906 #define FOR_EACH_CHILD(die, c, expr) do { \
5907 c = die->die_child; \
5911 } while (c != die->die_child); \
5914 /* The pubname structure */
5916 typedef struct GTY(()) pubname_struct {
5922 DEF_VEC_O(pubname_entry);
5923 DEF_VEC_ALLOC_O(pubname_entry, gc);
5925 struct GTY(()) dw_ranges_struct {
5926 /* If this is positive, it's a block number, otherwise it's a
5927 bitwise-negated index into dw_ranges_by_label. */
5931 /* A structure to hold a macinfo entry. */
5933 typedef struct GTY(()) macinfo_struct {
5934 unsigned HOST_WIDE_INT code;
5935 unsigned HOST_WIDE_INT lineno;
5940 DEF_VEC_O(macinfo_entry);
5941 DEF_VEC_ALLOC_O(macinfo_entry, gc);
5943 struct GTY(()) dw_ranges_by_label_struct {
5948 /* The comdat type node structure. */
5949 typedef struct GTY(()) comdat_type_struct
5951 dw_die_ref root_die;
5952 dw_die_ref type_die;
5953 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5954 struct comdat_type_struct *next;
5958 /* The limbo die list structure. */
5959 typedef struct GTY(()) limbo_die_struct {
5962 struct limbo_die_struct *next;
5966 typedef struct skeleton_chain_struct
5970 struct skeleton_chain_struct *parent;
5972 skeleton_chain_node;
5974 /* How to start an assembler comment. */
5975 #ifndef ASM_COMMENT_START
5976 #define ASM_COMMENT_START ";#"
5979 /* Define a macro which returns nonzero for a TYPE_DECL which was
5980 implicitly generated for a tagged type.
5982 Note that unlike the gcc front end (which generates a NULL named
5983 TYPE_DECL node for each complete tagged type, each array type, and
5984 each function type node created) the g++ front end generates a
5985 _named_ TYPE_DECL node for each tagged type node created.
5986 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5987 generate a DW_TAG_typedef DIE for them. */
5989 #define TYPE_DECL_IS_STUB(decl) \
5990 (DECL_NAME (decl) == NULL_TREE \
5991 || (DECL_ARTIFICIAL (decl) \
5992 && is_tagged_type (TREE_TYPE (decl)) \
5993 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5994 /* This is necessary for stub decls that \
5995 appear in nested inline functions. */ \
5996 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5997 && (decl_ultimate_origin (decl) \
5998 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6000 /* Information concerning the compilation unit's programming
6001 language, and compiler version. */
6003 /* Fixed size portion of the DWARF compilation unit header. */
6004 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6005 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6007 /* Fixed size portion of the DWARF comdat type unit header. */
6008 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6009 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6010 + DWARF_OFFSET_SIZE)
6012 /* Fixed size portion of public names info. */
6013 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6015 /* Fixed size portion of the address range info. */
6016 #define DWARF_ARANGES_HEADER_SIZE \
6017 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6018 DWARF2_ADDR_SIZE * 2) \
6019 - DWARF_INITIAL_LENGTH_SIZE)
6021 /* Size of padding portion in the address range info. It must be
6022 aligned to twice the pointer size. */
6023 #define DWARF_ARANGES_PAD_SIZE \
6024 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6025 DWARF2_ADDR_SIZE * 2) \
6026 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6028 /* Use assembler line directives if available. */
6029 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6030 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6031 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6033 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6037 /* Minimum line offset in a special line info. opcode.
6038 This value was chosen to give a reasonable range of values. */
6039 #define DWARF_LINE_BASE -10
6041 /* First special line opcode - leave room for the standard opcodes. */
6042 #define DWARF_LINE_OPCODE_BASE 10
6044 /* Range of line offsets in a special line info. opcode. */
6045 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6047 /* Flag that indicates the initial value of the is_stmt_start flag.
6048 In the present implementation, we do not mark any lines as
6049 the beginning of a source statement, because that information
6050 is not made available by the GCC front-end. */
6051 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6053 /* Maximum number of operations per instruction bundle. */
6054 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6055 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6058 /* This location is used by calc_die_sizes() to keep track
6059 the offset of each DIE within the .debug_info section. */
6060 static unsigned long next_die_offset;
6062 /* Record the root of the DIE's built for the current compilation unit. */
6063 static GTY(()) dw_die_ref single_comp_unit_die;
6065 /* A list of type DIEs that have been separated into comdat sections. */
6066 static GTY(()) comdat_type_node *comdat_type_list;
6068 /* A list of DIEs with a NULL parent waiting to be relocated. */
6069 static GTY(()) limbo_die_node *limbo_die_list;
6071 /* A list of DIEs for which we may have to generate
6072 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6073 static GTY(()) limbo_die_node *deferred_asm_name;
6075 /* Filenames referenced by this compilation unit. */
6076 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6078 /* A hash table of references to DIE's that describe declarations.
6079 The key is a DECL_UID() which is a unique number identifying each decl. */
6080 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6082 /* A hash table of references to DIE's that describe COMMON blocks.
6083 The key is DECL_UID() ^ die_parent. */
6084 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6086 typedef struct GTY(()) die_arg_entry_struct {
6091 DEF_VEC_O(die_arg_entry);
6092 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6094 /* Node of the variable location list. */
6095 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6096 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6097 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6098 in mode of the EXPR_LIST node and first EXPR_LIST operand
6099 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6100 location or NULL for padding. For larger bitsizes,
6101 mode is 0 and first operand is a CONCAT with bitsize
6102 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6103 NULL as second operand. */
6105 const char * GTY (()) label;
6106 struct var_loc_node * GTY (()) next;
6109 /* Variable location list. */
6110 struct GTY (()) var_loc_list_def {
6111 struct var_loc_node * GTY (()) first;
6113 /* Pointer to the last but one or last element of the
6114 chained list. If the list is empty, both first and
6115 last are NULL, if the list contains just one node
6116 or the last node certainly is not redundant, it points
6117 to the last node, otherwise points to the last but one.
6118 Do not mark it for GC because it is marked through the chain. */
6119 struct var_loc_node * GTY ((skip ("%h"))) last;
6121 /* DECL_UID of the variable decl. */
6122 unsigned int decl_id;
6124 typedef struct var_loc_list_def var_loc_list;
6126 /* Call argument location list. */
6127 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6128 rtx GTY (()) call_arg_loc_note;
6129 const char * GTY (()) label;
6130 tree GTY (()) block;
6132 rtx GTY (()) symbol_ref;
6133 struct call_arg_loc_node * GTY (()) next;
6137 /* Table of decl location linked lists. */
6138 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6140 /* Head and tail of call_arg_loc chain. */
6141 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6142 static struct call_arg_loc_node *call_arg_loc_last;
6144 /* Number of call sites in the current function. */
6145 static int call_site_count = -1;
6146 /* Number of tail call sites in the current function. */
6147 static int tail_call_site_count = -1;
6149 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6151 static VEC (dw_die_ref, heap) *block_map;
6153 /* A pointer to the base of a list of references to DIE's that
6154 are uniquely identified by their tag, presence/absence of
6155 children DIE's, and list of attribute/value pairs. */
6156 static GTY((length ("abbrev_die_table_allocated")))
6157 dw_die_ref *abbrev_die_table;
6159 /* Number of elements currently allocated for abbrev_die_table. */
6160 static GTY(()) unsigned abbrev_die_table_allocated;
6162 /* Number of elements in type_die_table currently in use. */
6163 static GTY(()) unsigned abbrev_die_table_in_use;
6165 /* Size (in elements) of increments by which we may expand the
6166 abbrev_die_table. */
6167 #define ABBREV_DIE_TABLE_INCREMENT 256
6169 /* A pointer to the base of a table that contains line information
6170 for each source code line in .text in the compilation unit. */
6171 static GTY((length ("line_info_table_allocated")))
6172 dw_line_info_ref line_info_table;
6174 /* Number of elements currently allocated for line_info_table. */
6175 static GTY(()) unsigned line_info_table_allocated;
6177 /* Number of elements in line_info_table currently in use. */
6178 static GTY(()) unsigned line_info_table_in_use;
6180 /* A pointer to the base of a table that contains line information
6181 for each source code line outside of .text in the compilation unit. */
6182 static GTY ((length ("separate_line_info_table_allocated")))
6183 dw_separate_line_info_ref separate_line_info_table;
6185 /* Number of elements currently allocated for separate_line_info_table. */
6186 static GTY(()) unsigned separate_line_info_table_allocated;
6188 /* Number of elements in separate_line_info_table currently in use. */
6189 static GTY(()) unsigned separate_line_info_table_in_use;
6191 /* Size (in elements) of increments by which we may expand the
6193 #define LINE_INFO_TABLE_INCREMENT 1024
6195 /* A flag to tell pubnames/types export if there is an info section to
6197 static bool info_section_emitted;
6199 /* A pointer to the base of a table that contains a list of publicly
6200 accessible names. */
6201 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6203 /* A pointer to the base of a table that contains a list of publicly
6204 accessible types. */
6205 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6207 /* A pointer to the base of a table that contains a list of macro
6208 defines/undefines (and file start/end markers). */
6209 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6211 /* Array of dies for which we should generate .debug_arange info. */
6212 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
6214 /* Number of elements currently allocated for arange_table. */
6215 static GTY(()) unsigned arange_table_allocated;
6217 /* Number of elements in arange_table currently in use. */
6218 static GTY(()) unsigned arange_table_in_use;
6220 /* Size (in elements) of increments by which we may expand the
6222 #define ARANGE_TABLE_INCREMENT 64
6224 /* Array of dies for which we should generate .debug_ranges info. */
6225 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6227 /* Number of elements currently allocated for ranges_table. */
6228 static GTY(()) unsigned ranges_table_allocated;
6230 /* Number of elements in ranges_table currently in use. */
6231 static GTY(()) unsigned ranges_table_in_use;
6233 /* Array of pairs of labels referenced in ranges_table. */
6234 static GTY ((length ("ranges_by_label_allocated")))
6235 dw_ranges_by_label_ref ranges_by_label;
6237 /* Number of elements currently allocated for ranges_by_label. */
6238 static GTY(()) unsigned ranges_by_label_allocated;
6240 /* Number of elements in ranges_by_label currently in use. */
6241 static GTY(()) unsigned ranges_by_label_in_use;
6243 /* Size (in elements) of increments by which we may expand the
6245 #define RANGES_TABLE_INCREMENT 64
6247 /* Whether we have location lists that need outputting */
6248 static GTY(()) bool have_location_lists;
6250 /* Unique label counter. */
6251 static GTY(()) unsigned int loclabel_num;
6253 /* Unique label counter for point-of-call tables. */
6254 static GTY(()) unsigned int poc_label_num;
6256 /* Record whether the function being analyzed contains inlined functions. */
6257 static int current_function_has_inlines;
6259 /* The last file entry emitted by maybe_emit_file(). */
6260 static GTY(()) struct dwarf_file_data * last_emitted_file;
6262 /* Number of internal labels generated by gen_internal_sym(). */
6263 static GTY(()) int label_num;
6265 /* Cached result of previous call to lookup_filename. */
6266 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6268 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6270 /* Instances of generic types for which we need to generate debug
6271 info that describe their generic parameters and arguments. That
6272 generation needs to happen once all types are properly laid out so
6273 we do it at the end of compilation. */
6274 static GTY(()) VEC(tree,gc) *generic_type_instances;
6276 /* Offset from the "steady-state frame pointer" to the frame base,
6277 within the current function. */
6278 static HOST_WIDE_INT frame_pointer_fb_offset;
6280 /* Forward declarations for functions defined in this file. */
6282 static int is_pseudo_reg (const_rtx);
6283 static tree type_main_variant (tree);
6284 static int is_tagged_type (const_tree);
6285 static const char *dwarf_tag_name (unsigned);
6286 static const char *dwarf_attr_name (unsigned);
6287 static const char *dwarf_form_name (unsigned);
6288 static tree decl_ultimate_origin (const_tree);
6289 static tree decl_class_context (tree);
6290 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6291 static inline enum dw_val_class AT_class (dw_attr_ref);
6292 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6293 static inline unsigned AT_flag (dw_attr_ref);
6294 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6295 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6296 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6297 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6298 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6299 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6300 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6301 unsigned int, unsigned char *);
6302 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6303 static hashval_t debug_str_do_hash (const void *);
6304 static int debug_str_eq (const void *, const void *);
6305 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6306 static inline const char *AT_string (dw_attr_ref);
6307 static enum dwarf_form AT_string_form (dw_attr_ref);
6308 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6309 static void add_AT_specification (dw_die_ref, dw_die_ref);
6310 static inline dw_die_ref AT_ref (dw_attr_ref);
6311 static inline int AT_ref_external (dw_attr_ref);
6312 static inline void set_AT_ref_external (dw_attr_ref, int);
6313 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6314 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6315 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6316 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6318 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6319 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6320 static inline rtx AT_addr (dw_attr_ref);
6321 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6322 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6323 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6324 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6325 unsigned HOST_WIDE_INT);
6326 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6328 static inline const char *AT_lbl (dw_attr_ref);
6329 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6330 static const char *get_AT_low_pc (dw_die_ref);
6331 static const char *get_AT_hi_pc (dw_die_ref);
6332 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6333 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6334 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6335 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6336 static bool is_cxx (void);
6337 static bool is_fortran (void);
6338 static bool is_ada (void);
6339 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6340 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6341 static void add_child_die (dw_die_ref, dw_die_ref);
6342 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6343 static dw_die_ref lookup_type_die (tree);
6344 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6345 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6346 static void equate_type_number_to_die (tree, dw_die_ref);
6347 static hashval_t decl_die_table_hash (const void *);
6348 static int decl_die_table_eq (const void *, const void *);
6349 static dw_die_ref lookup_decl_die (tree);
6350 static hashval_t common_block_die_table_hash (const void *);
6351 static int common_block_die_table_eq (const void *, const void *);
6352 static hashval_t decl_loc_table_hash (const void *);
6353 static int decl_loc_table_eq (const void *, const void *);
6354 static var_loc_list *lookup_decl_loc (const_tree);
6355 static void equate_decl_number_to_die (tree, dw_die_ref);
6356 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6357 static void print_spaces (FILE *);
6358 static void print_die (dw_die_ref, FILE *);
6359 static void print_dwarf_line_table (FILE *);
6360 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6361 static dw_die_ref pop_compile_unit (dw_die_ref);
6362 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6363 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6364 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6365 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6366 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6367 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6368 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6369 struct md5_ctx *, int *);
6370 struct checksum_attributes;
6371 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6372 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6373 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6374 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6375 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6376 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6377 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6378 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6379 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6380 static void compute_section_prefix (dw_die_ref);
6381 static int is_type_die (dw_die_ref);
6382 static int is_comdat_die (dw_die_ref);
6383 static int is_symbol_die (dw_die_ref);
6384 static void assign_symbol_names (dw_die_ref);
6385 static void break_out_includes (dw_die_ref);
6386 static int is_declaration_die (dw_die_ref);
6387 static int should_move_die_to_comdat (dw_die_ref);
6388 static dw_die_ref clone_as_declaration (dw_die_ref);
6389 static dw_die_ref clone_die (dw_die_ref);
6390 static dw_die_ref clone_tree (dw_die_ref);
6391 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6392 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6393 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6394 static dw_die_ref generate_skeleton (dw_die_ref);
6395 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6397 static void break_out_comdat_types (dw_die_ref);
6398 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6399 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6400 static void copy_decls_for_unworthy_types (dw_die_ref);
6402 static hashval_t htab_cu_hash (const void *);
6403 static int htab_cu_eq (const void *, const void *);
6404 static void htab_cu_del (void *);
6405 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6406 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6407 static void add_sibling_attributes (dw_die_ref);
6408 static void build_abbrev_table (dw_die_ref);
6409 static void output_location_lists (dw_die_ref);
6410 static int constant_size (unsigned HOST_WIDE_INT);
6411 static unsigned long size_of_die (dw_die_ref);
6412 static void calc_die_sizes (dw_die_ref);
6413 static void mark_dies (dw_die_ref);
6414 static void unmark_dies (dw_die_ref);
6415 static void unmark_all_dies (dw_die_ref);
6416 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6417 static unsigned long size_of_aranges (void);
6418 static enum dwarf_form value_format (dw_attr_ref);
6419 static void output_value_format (dw_attr_ref);
6420 static void output_abbrev_section (void);
6421 static void output_die_symbol (dw_die_ref);
6422 static void output_die (dw_die_ref);
6423 static void output_compilation_unit_header (void);
6424 static void output_comp_unit (dw_die_ref, int);
6425 static void output_comdat_type_unit (comdat_type_node *);
6426 static const char *dwarf2_name (tree, int);
6427 static void add_pubname (tree, dw_die_ref);
6428 static void add_pubname_string (const char *, dw_die_ref);
6429 static void add_pubtype (tree, dw_die_ref);
6430 static void output_pubnames (VEC (pubname_entry,gc) *);
6431 static void add_arange (tree, dw_die_ref);
6432 static void output_aranges (void);
6433 static unsigned int add_ranges_num (int);
6434 static unsigned int add_ranges (const_tree);
6435 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6437 static void output_ranges (void);
6438 static void output_line_info (void);
6439 static void output_file_names (void);
6440 static dw_die_ref base_type_die (tree);
6441 static int is_base_type (tree);
6442 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6443 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6444 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6445 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6446 static int type_is_enum (const_tree);
6447 static unsigned int dbx_reg_number (const_rtx);
6448 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6449 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6450 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6451 enum var_init_status);
6452 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6453 enum var_init_status);
6454 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6455 enum var_init_status);
6456 static int is_based_loc (const_rtx);
6457 static int resolve_one_addr (rtx *, void *);
6458 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6459 enum var_init_status);
6460 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6461 enum var_init_status);
6462 static dw_loc_list_ref loc_list_from_tree (tree, int);
6463 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6464 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6465 static tree field_type (const_tree);
6466 static unsigned int simple_type_align_in_bits (const_tree);
6467 static unsigned int simple_decl_align_in_bits (const_tree);
6468 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6469 static HOST_WIDE_INT field_byte_offset (const_tree);
6470 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6472 static void add_data_member_location_attribute (dw_die_ref, tree);
6473 static bool add_const_value_attribute (dw_die_ref, rtx);
6474 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6475 static void insert_double (double_int, unsigned char *);
6476 static void insert_float (const_rtx, unsigned char *);
6477 static rtx rtl_for_decl_location (tree);
6478 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
6479 enum dwarf_attribute);
6480 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6481 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6482 static void add_name_attribute (dw_die_ref, const char *);
6483 static void add_comp_dir_attribute (dw_die_ref);
6484 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6485 static void add_subscript_info (dw_die_ref, tree, bool);
6486 static void add_byte_size_attribute (dw_die_ref, tree);
6487 static void add_bit_offset_attribute (dw_die_ref, tree);
6488 static void add_bit_size_attribute (dw_die_ref, tree);
6489 static void add_prototyped_attribute (dw_die_ref, tree);
6490 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6491 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6492 static void add_src_coords_attributes (dw_die_ref, tree);
6493 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6494 static void push_decl_scope (tree);
6495 static void pop_decl_scope (void);
6496 static dw_die_ref scope_die_for (tree, dw_die_ref);
6497 static inline int local_scope_p (dw_die_ref);
6498 static inline int class_scope_p (dw_die_ref);
6499 static inline int class_or_namespace_scope_p (dw_die_ref);
6500 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6501 static void add_calling_convention_attribute (dw_die_ref, tree);
6502 static const char *type_tag (const_tree);
6503 static tree member_declared_type (const_tree);
6505 static const char *decl_start_label (tree);
6507 static void gen_array_type_die (tree, dw_die_ref);
6508 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6510 static void gen_entry_point_die (tree, dw_die_ref);
6512 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6513 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6514 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6515 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6516 static void gen_formal_types_die (tree, dw_die_ref);
6517 static void gen_subprogram_die (tree, dw_die_ref);
6518 static void gen_variable_die (tree, tree, dw_die_ref);
6519 static void gen_const_die (tree, dw_die_ref);
6520 static void gen_label_die (tree, dw_die_ref);
6521 static void gen_lexical_block_die (tree, dw_die_ref, int);
6522 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6523 static void gen_field_die (tree, dw_die_ref);
6524 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6525 static dw_die_ref gen_compile_unit_die (const char *);
6526 static void gen_inheritance_die (tree, tree, dw_die_ref);
6527 static void gen_member_die (tree, dw_die_ref);
6528 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6529 enum debug_info_usage);
6530 static void gen_subroutine_type_die (tree, dw_die_ref);
6531 static void gen_typedef_die (tree, dw_die_ref);
6532 static void gen_type_die (tree, dw_die_ref);
6533 static void gen_block_die (tree, dw_die_ref, int);
6534 static void decls_for_scope (tree, dw_die_ref, int);
6535 static int is_redundant_typedef (const_tree);
6536 static bool is_naming_typedef_decl (const_tree);
6537 static inline dw_die_ref get_context_die (tree);
6538 static void gen_namespace_die (tree, dw_die_ref);
6539 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6540 static dw_die_ref force_decl_die (tree);
6541 static dw_die_ref force_type_die (tree);
6542 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6543 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6544 static struct dwarf_file_data * lookup_filename (const char *);
6545 static void retry_incomplete_types (void);
6546 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6547 static void gen_generic_params_dies (tree);
6548 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6549 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6550 static void splice_child_die (dw_die_ref, dw_die_ref);
6551 static int file_info_cmp (const void *, const void *);
6552 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6553 const char *, const char *);
6554 static void output_loc_list (dw_loc_list_ref);
6555 static char *gen_internal_sym (const char *);
6557 static void prune_unmark_dies (dw_die_ref);
6558 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6559 static void prune_unused_types_mark (dw_die_ref, int);
6560 static void prune_unused_types_walk (dw_die_ref);
6561 static void prune_unused_types_walk_attribs (dw_die_ref);
6562 static void prune_unused_types_prune (dw_die_ref);
6563 static void prune_unused_types (void);
6564 static int maybe_emit_file (struct dwarf_file_data *fd);
6565 static inline const char *AT_vms_delta1 (dw_attr_ref);
6566 static inline const char *AT_vms_delta2 (dw_attr_ref);
6567 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6568 const char *, const char *);
6569 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6570 static void gen_remaining_tmpl_value_param_die_attribute (void);
6571 static bool generic_type_p (tree);
6572 static void schedule_generic_params_dies_gen (tree t);
6573 static void gen_scheduled_generic_parms_dies (void);
6575 /* Section names used to hold DWARF debugging information. */
6576 #ifndef DEBUG_INFO_SECTION
6577 #define DEBUG_INFO_SECTION ".debug_info"
6579 #ifndef DEBUG_ABBREV_SECTION
6580 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6582 #ifndef DEBUG_ARANGES_SECTION
6583 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6585 #ifndef DEBUG_MACINFO_SECTION
6586 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6588 #ifndef DEBUG_LINE_SECTION
6589 #define DEBUG_LINE_SECTION ".debug_line"
6591 #ifndef DEBUG_LOC_SECTION
6592 #define DEBUG_LOC_SECTION ".debug_loc"
6594 #ifndef DEBUG_PUBNAMES_SECTION
6595 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6597 #ifndef DEBUG_PUBTYPES_SECTION
6598 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6600 #ifndef DEBUG_STR_SECTION
6601 #define DEBUG_STR_SECTION ".debug_str"
6603 #ifndef DEBUG_RANGES_SECTION
6604 #define DEBUG_RANGES_SECTION ".debug_ranges"
6607 /* Standard ELF section names for compiled code and data. */
6608 #ifndef TEXT_SECTION_NAME
6609 #define TEXT_SECTION_NAME ".text"
6612 /* Section flags for .debug_str section. */
6613 #define DEBUG_STR_SECTION_FLAGS \
6614 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6615 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6618 /* Labels we insert at beginning sections we can reference instead of
6619 the section names themselves. */
6621 #ifndef TEXT_SECTION_LABEL
6622 #define TEXT_SECTION_LABEL "Ltext"
6624 #ifndef COLD_TEXT_SECTION_LABEL
6625 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6627 #ifndef DEBUG_LINE_SECTION_LABEL
6628 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6630 #ifndef DEBUG_INFO_SECTION_LABEL
6631 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6633 #ifndef DEBUG_ABBREV_SECTION_LABEL
6634 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6636 #ifndef DEBUG_LOC_SECTION_LABEL
6637 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6639 #ifndef DEBUG_RANGES_SECTION_LABEL
6640 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6642 #ifndef DEBUG_MACINFO_SECTION_LABEL
6643 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6647 /* Definitions of defaults for formats and names of various special
6648 (artificial) labels which may be generated within this file (when the -g
6649 options is used and DWARF2_DEBUGGING_INFO is in effect.
6650 If necessary, these may be overridden from within the tm.h file, but
6651 typically, overriding these defaults is unnecessary. */
6653 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6654 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6655 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6656 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6657 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6658 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6659 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6660 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6661 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6662 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6664 #ifndef TEXT_END_LABEL
6665 #define TEXT_END_LABEL "Letext"
6667 #ifndef COLD_END_LABEL
6668 #define COLD_END_LABEL "Letext_cold"
6670 #ifndef BLOCK_BEGIN_LABEL
6671 #define BLOCK_BEGIN_LABEL "LBB"
6673 #ifndef BLOCK_END_LABEL
6674 #define BLOCK_END_LABEL "LBE"
6676 #ifndef LINE_CODE_LABEL
6677 #define LINE_CODE_LABEL "LM"
6679 #ifndef SEPARATE_LINE_CODE_LABEL
6680 #define SEPARATE_LINE_CODE_LABEL "LSM"
6684 /* Return the root of the DIE's built for the current compilation unit. */
6686 comp_unit_die (void)
6688 if (!single_comp_unit_die)
6689 single_comp_unit_die = gen_compile_unit_die (NULL);
6690 return single_comp_unit_die;
6693 /* We allow a language front-end to designate a function that is to be
6694 called to "demangle" any name before it is put into a DIE. */
6696 static const char *(*demangle_name_func) (const char *);
6699 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6701 demangle_name_func = func;
6704 /* Test if rtl node points to a pseudo register. */
6707 is_pseudo_reg (const_rtx rtl)
6709 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6710 || (GET_CODE (rtl) == SUBREG
6711 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6714 /* Return a reference to a type, with its const and volatile qualifiers
6718 type_main_variant (tree type)
6720 type = TYPE_MAIN_VARIANT (type);
6722 /* ??? There really should be only one main variant among any group of
6723 variants of a given type (and all of the MAIN_VARIANT values for all
6724 members of the group should point to that one type) but sometimes the C
6725 front-end messes this up for array types, so we work around that bug
6727 if (TREE_CODE (type) == ARRAY_TYPE)
6728 while (type != TYPE_MAIN_VARIANT (type))
6729 type = TYPE_MAIN_VARIANT (type);
6734 /* Return nonzero if the given type node represents a tagged type. */
6737 is_tagged_type (const_tree type)
6739 enum tree_code code = TREE_CODE (type);
6741 return (code == RECORD_TYPE || code == UNION_TYPE
6742 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6745 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6748 get_ref_die_offset_label (char *label, dw_die_ref ref)
6750 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6753 /* Convert a DIE tag into its string name. */
6756 dwarf_tag_name (unsigned int tag)
6760 case DW_TAG_padding:
6761 return "DW_TAG_padding";
6762 case DW_TAG_array_type:
6763 return "DW_TAG_array_type";
6764 case DW_TAG_class_type:
6765 return "DW_TAG_class_type";
6766 case DW_TAG_entry_point:
6767 return "DW_TAG_entry_point";
6768 case DW_TAG_enumeration_type:
6769 return "DW_TAG_enumeration_type";
6770 case DW_TAG_formal_parameter:
6771 return "DW_TAG_formal_parameter";
6772 case DW_TAG_imported_declaration:
6773 return "DW_TAG_imported_declaration";
6775 return "DW_TAG_label";
6776 case DW_TAG_lexical_block:
6777 return "DW_TAG_lexical_block";
6779 return "DW_TAG_member";
6780 case DW_TAG_pointer_type:
6781 return "DW_TAG_pointer_type";
6782 case DW_TAG_reference_type:
6783 return "DW_TAG_reference_type";
6784 case DW_TAG_compile_unit:
6785 return "DW_TAG_compile_unit";
6786 case DW_TAG_string_type:
6787 return "DW_TAG_string_type";
6788 case DW_TAG_structure_type:
6789 return "DW_TAG_structure_type";
6790 case DW_TAG_subroutine_type:
6791 return "DW_TAG_subroutine_type";
6792 case DW_TAG_typedef:
6793 return "DW_TAG_typedef";
6794 case DW_TAG_union_type:
6795 return "DW_TAG_union_type";
6796 case DW_TAG_unspecified_parameters:
6797 return "DW_TAG_unspecified_parameters";
6798 case DW_TAG_variant:
6799 return "DW_TAG_variant";
6800 case DW_TAG_common_block:
6801 return "DW_TAG_common_block";
6802 case DW_TAG_common_inclusion:
6803 return "DW_TAG_common_inclusion";
6804 case DW_TAG_inheritance:
6805 return "DW_TAG_inheritance";
6806 case DW_TAG_inlined_subroutine:
6807 return "DW_TAG_inlined_subroutine";
6809 return "DW_TAG_module";
6810 case DW_TAG_ptr_to_member_type:
6811 return "DW_TAG_ptr_to_member_type";
6812 case DW_TAG_set_type:
6813 return "DW_TAG_set_type";
6814 case DW_TAG_subrange_type:
6815 return "DW_TAG_subrange_type";
6816 case DW_TAG_with_stmt:
6817 return "DW_TAG_with_stmt";
6818 case DW_TAG_access_declaration:
6819 return "DW_TAG_access_declaration";
6820 case DW_TAG_base_type:
6821 return "DW_TAG_base_type";
6822 case DW_TAG_catch_block:
6823 return "DW_TAG_catch_block";
6824 case DW_TAG_const_type:
6825 return "DW_TAG_const_type";
6826 case DW_TAG_constant:
6827 return "DW_TAG_constant";
6828 case DW_TAG_enumerator:
6829 return "DW_TAG_enumerator";
6830 case DW_TAG_file_type:
6831 return "DW_TAG_file_type";
6833 return "DW_TAG_friend";
6834 case DW_TAG_namelist:
6835 return "DW_TAG_namelist";
6836 case DW_TAG_namelist_item:
6837 return "DW_TAG_namelist_item";
6838 case DW_TAG_packed_type:
6839 return "DW_TAG_packed_type";
6840 case DW_TAG_subprogram:
6841 return "DW_TAG_subprogram";
6842 case DW_TAG_template_type_param:
6843 return "DW_TAG_template_type_param";
6844 case DW_TAG_template_value_param:
6845 return "DW_TAG_template_value_param";
6846 case DW_TAG_thrown_type:
6847 return "DW_TAG_thrown_type";
6848 case DW_TAG_try_block:
6849 return "DW_TAG_try_block";
6850 case DW_TAG_variant_part:
6851 return "DW_TAG_variant_part";
6852 case DW_TAG_variable:
6853 return "DW_TAG_variable";
6854 case DW_TAG_volatile_type:
6855 return "DW_TAG_volatile_type";
6856 case DW_TAG_dwarf_procedure:
6857 return "DW_TAG_dwarf_procedure";
6858 case DW_TAG_restrict_type:
6859 return "DW_TAG_restrict_type";
6860 case DW_TAG_interface_type:
6861 return "DW_TAG_interface_type";
6862 case DW_TAG_namespace:
6863 return "DW_TAG_namespace";
6864 case DW_TAG_imported_module:
6865 return "DW_TAG_imported_module";
6866 case DW_TAG_unspecified_type:
6867 return "DW_TAG_unspecified_type";
6868 case DW_TAG_partial_unit:
6869 return "DW_TAG_partial_unit";
6870 case DW_TAG_imported_unit:
6871 return "DW_TAG_imported_unit";
6872 case DW_TAG_condition:
6873 return "DW_TAG_condition";
6874 case DW_TAG_shared_type:
6875 return "DW_TAG_shared_type";
6876 case DW_TAG_type_unit:
6877 return "DW_TAG_type_unit";
6878 case DW_TAG_rvalue_reference_type:
6879 return "DW_TAG_rvalue_reference_type";
6880 case DW_TAG_template_alias:
6881 return "DW_TAG_template_alias";
6882 case DW_TAG_GNU_template_parameter_pack:
6883 return "DW_TAG_GNU_template_parameter_pack";
6884 case DW_TAG_GNU_formal_parameter_pack:
6885 return "DW_TAG_GNU_formal_parameter_pack";
6886 case DW_TAG_MIPS_loop:
6887 return "DW_TAG_MIPS_loop";
6888 case DW_TAG_format_label:
6889 return "DW_TAG_format_label";
6890 case DW_TAG_function_template:
6891 return "DW_TAG_function_template";
6892 case DW_TAG_class_template:
6893 return "DW_TAG_class_template";
6894 case DW_TAG_GNU_BINCL:
6895 return "DW_TAG_GNU_BINCL";
6896 case DW_TAG_GNU_EINCL:
6897 return "DW_TAG_GNU_EINCL";
6898 case DW_TAG_GNU_template_template_param:
6899 return "DW_TAG_GNU_template_template_param";
6900 case DW_TAG_GNU_call_site:
6901 return "DW_TAG_GNU_call_site";
6902 case DW_TAG_GNU_call_site_parameter:
6903 return "DW_TAG_GNU_call_site_parameter";
6905 return "DW_TAG_<unknown>";
6909 /* Convert a DWARF attribute code into its string name. */
6912 dwarf_attr_name (unsigned int attr)
6917 return "DW_AT_sibling";
6918 case DW_AT_location:
6919 return "DW_AT_location";
6921 return "DW_AT_name";
6922 case DW_AT_ordering:
6923 return "DW_AT_ordering";
6924 case DW_AT_subscr_data:
6925 return "DW_AT_subscr_data";
6926 case DW_AT_byte_size:
6927 return "DW_AT_byte_size";
6928 case DW_AT_bit_offset:
6929 return "DW_AT_bit_offset";
6930 case DW_AT_bit_size:
6931 return "DW_AT_bit_size";
6932 case DW_AT_element_list:
6933 return "DW_AT_element_list";
6934 case DW_AT_stmt_list:
6935 return "DW_AT_stmt_list";
6937 return "DW_AT_low_pc";
6939 return "DW_AT_high_pc";
6940 case DW_AT_language:
6941 return "DW_AT_language";
6943 return "DW_AT_member";
6945 return "DW_AT_discr";
6946 case DW_AT_discr_value:
6947 return "DW_AT_discr_value";
6948 case DW_AT_visibility:
6949 return "DW_AT_visibility";
6951 return "DW_AT_import";
6952 case DW_AT_string_length:
6953 return "DW_AT_string_length";
6954 case DW_AT_common_reference:
6955 return "DW_AT_common_reference";
6956 case DW_AT_comp_dir:
6957 return "DW_AT_comp_dir";
6958 case DW_AT_const_value:
6959 return "DW_AT_const_value";
6960 case DW_AT_containing_type:
6961 return "DW_AT_containing_type";
6962 case DW_AT_default_value:
6963 return "DW_AT_default_value";
6965 return "DW_AT_inline";
6966 case DW_AT_is_optional:
6967 return "DW_AT_is_optional";
6968 case DW_AT_lower_bound:
6969 return "DW_AT_lower_bound";
6970 case DW_AT_producer:
6971 return "DW_AT_producer";
6972 case DW_AT_prototyped:
6973 return "DW_AT_prototyped";
6974 case DW_AT_return_addr:
6975 return "DW_AT_return_addr";
6976 case DW_AT_start_scope:
6977 return "DW_AT_start_scope";
6978 case DW_AT_bit_stride:
6979 return "DW_AT_bit_stride";
6980 case DW_AT_upper_bound:
6981 return "DW_AT_upper_bound";
6982 case DW_AT_abstract_origin:
6983 return "DW_AT_abstract_origin";
6984 case DW_AT_accessibility:
6985 return "DW_AT_accessibility";
6986 case DW_AT_address_class:
6987 return "DW_AT_address_class";
6988 case DW_AT_artificial:
6989 return "DW_AT_artificial";
6990 case DW_AT_base_types:
6991 return "DW_AT_base_types";
6992 case DW_AT_calling_convention:
6993 return "DW_AT_calling_convention";
6995 return "DW_AT_count";
6996 case DW_AT_data_member_location:
6997 return "DW_AT_data_member_location";
6998 case DW_AT_decl_column:
6999 return "DW_AT_decl_column";
7000 case DW_AT_decl_file:
7001 return "DW_AT_decl_file";
7002 case DW_AT_decl_line:
7003 return "DW_AT_decl_line";
7004 case DW_AT_declaration:
7005 return "DW_AT_declaration";
7006 case DW_AT_discr_list:
7007 return "DW_AT_discr_list";
7008 case DW_AT_encoding:
7009 return "DW_AT_encoding";
7010 case DW_AT_external:
7011 return "DW_AT_external";
7012 case DW_AT_explicit:
7013 return "DW_AT_explicit";
7014 case DW_AT_frame_base:
7015 return "DW_AT_frame_base";
7017 return "DW_AT_friend";
7018 case DW_AT_identifier_case:
7019 return "DW_AT_identifier_case";
7020 case DW_AT_macro_info:
7021 return "DW_AT_macro_info";
7022 case DW_AT_namelist_items:
7023 return "DW_AT_namelist_items";
7024 case DW_AT_priority:
7025 return "DW_AT_priority";
7027 return "DW_AT_segment";
7028 case DW_AT_specification:
7029 return "DW_AT_specification";
7030 case DW_AT_static_link:
7031 return "DW_AT_static_link";
7033 return "DW_AT_type";
7034 case DW_AT_use_location:
7035 return "DW_AT_use_location";
7036 case DW_AT_variable_parameter:
7037 return "DW_AT_variable_parameter";
7038 case DW_AT_virtuality:
7039 return "DW_AT_virtuality";
7040 case DW_AT_vtable_elem_location:
7041 return "DW_AT_vtable_elem_location";
7043 case DW_AT_allocated:
7044 return "DW_AT_allocated";
7045 case DW_AT_associated:
7046 return "DW_AT_associated";
7047 case DW_AT_data_location:
7048 return "DW_AT_data_location";
7049 case DW_AT_byte_stride:
7050 return "DW_AT_byte_stride";
7051 case DW_AT_entry_pc:
7052 return "DW_AT_entry_pc";
7053 case DW_AT_use_UTF8:
7054 return "DW_AT_use_UTF8";
7055 case DW_AT_extension:
7056 return "DW_AT_extension";
7058 return "DW_AT_ranges";
7059 case DW_AT_trampoline:
7060 return "DW_AT_trampoline";
7061 case DW_AT_call_column:
7062 return "DW_AT_call_column";
7063 case DW_AT_call_file:
7064 return "DW_AT_call_file";
7065 case DW_AT_call_line:
7066 return "DW_AT_call_line";
7067 case DW_AT_object_pointer:
7068 return "DW_AT_object_pointer";
7070 case DW_AT_signature:
7071 return "DW_AT_signature";
7072 case DW_AT_main_subprogram:
7073 return "DW_AT_main_subprogram";
7074 case DW_AT_data_bit_offset:
7075 return "DW_AT_data_bit_offset";
7076 case DW_AT_const_expr:
7077 return "DW_AT_const_expr";
7078 case DW_AT_enum_class:
7079 return "DW_AT_enum_class";
7080 case DW_AT_linkage_name:
7081 return "DW_AT_linkage_name";
7083 case DW_AT_MIPS_fde:
7084 return "DW_AT_MIPS_fde";
7085 case DW_AT_MIPS_loop_begin:
7086 return "DW_AT_MIPS_loop_begin";
7087 case DW_AT_MIPS_tail_loop_begin:
7088 return "DW_AT_MIPS_tail_loop_begin";
7089 case DW_AT_MIPS_epilog_begin:
7090 return "DW_AT_MIPS_epilog_begin";
7091 #if VMS_DEBUGGING_INFO
7092 case DW_AT_HP_prologue:
7093 return "DW_AT_HP_prologue";
7095 case DW_AT_MIPS_loop_unroll_factor:
7096 return "DW_AT_MIPS_loop_unroll_factor";
7098 case DW_AT_MIPS_software_pipeline_depth:
7099 return "DW_AT_MIPS_software_pipeline_depth";
7100 case DW_AT_MIPS_linkage_name:
7101 return "DW_AT_MIPS_linkage_name";
7102 #if VMS_DEBUGGING_INFO
7103 case DW_AT_HP_epilogue:
7104 return "DW_AT_HP_epilogue";
7106 case DW_AT_MIPS_stride:
7107 return "DW_AT_MIPS_stride";
7109 case DW_AT_MIPS_abstract_name:
7110 return "DW_AT_MIPS_abstract_name";
7111 case DW_AT_MIPS_clone_origin:
7112 return "DW_AT_MIPS_clone_origin";
7113 case DW_AT_MIPS_has_inlines:
7114 return "DW_AT_MIPS_has_inlines";
7116 case DW_AT_sf_names:
7117 return "DW_AT_sf_names";
7118 case DW_AT_src_info:
7119 return "DW_AT_src_info";
7120 case DW_AT_mac_info:
7121 return "DW_AT_mac_info";
7122 case DW_AT_src_coords:
7123 return "DW_AT_src_coords";
7124 case DW_AT_body_begin:
7125 return "DW_AT_body_begin";
7126 case DW_AT_body_end:
7127 return "DW_AT_body_end";
7128 case DW_AT_GNU_vector:
7129 return "DW_AT_GNU_vector";
7130 case DW_AT_GNU_guarded_by:
7131 return "DW_AT_GNU_guarded_by";
7132 case DW_AT_GNU_pt_guarded_by:
7133 return "DW_AT_GNU_pt_guarded_by";
7134 case DW_AT_GNU_guarded:
7135 return "DW_AT_GNU_guarded";
7136 case DW_AT_GNU_pt_guarded:
7137 return "DW_AT_GNU_pt_guarded";
7138 case DW_AT_GNU_locks_excluded:
7139 return "DW_AT_GNU_locks_excluded";
7140 case DW_AT_GNU_exclusive_locks_required:
7141 return "DW_AT_GNU_exclusive_locks_required";
7142 case DW_AT_GNU_shared_locks_required:
7143 return "DW_AT_GNU_shared_locks_required";
7144 case DW_AT_GNU_odr_signature:
7145 return "DW_AT_GNU_odr_signature";
7146 case DW_AT_GNU_template_name:
7147 return "DW_AT_GNU_template_name";
7148 case DW_AT_GNU_call_site_value:
7149 return "DW_AT_GNU_call_site_value";
7150 case DW_AT_GNU_call_site_data_value:
7151 return "DW_AT_GNU_call_site_data_value";
7152 case DW_AT_GNU_call_site_target:
7153 return "DW_AT_GNU_call_site_target";
7154 case DW_AT_GNU_call_site_target_clobbered:
7155 return "DW_AT_GNU_call_site_target_clobbered";
7156 case DW_AT_GNU_tail_call:
7157 return "DW_AT_GNU_tail_call";
7158 case DW_AT_GNU_all_tail_call_sites:
7159 return "DW_AT_GNU_all_tail_call_sites";
7160 case DW_AT_GNU_all_call_sites:
7161 return "DW_AT_GNU_all_call_sites";
7162 case DW_AT_GNU_all_source_call_sites:
7163 return "DW_AT_GNU_all_source_call_sites";
7165 case DW_AT_VMS_rtnbeg_pd_address:
7166 return "DW_AT_VMS_rtnbeg_pd_address";
7169 return "DW_AT_<unknown>";
7173 /* Convert a DWARF value form code into its string name. */
7176 dwarf_form_name (unsigned int form)
7181 return "DW_FORM_addr";
7182 case DW_FORM_block2:
7183 return "DW_FORM_block2";
7184 case DW_FORM_block4:
7185 return "DW_FORM_block4";
7187 return "DW_FORM_data2";
7189 return "DW_FORM_data4";
7191 return "DW_FORM_data8";
7192 case DW_FORM_string:
7193 return "DW_FORM_string";
7195 return "DW_FORM_block";
7196 case DW_FORM_block1:
7197 return "DW_FORM_block1";
7199 return "DW_FORM_data1";
7201 return "DW_FORM_flag";
7203 return "DW_FORM_sdata";
7205 return "DW_FORM_strp";
7207 return "DW_FORM_udata";
7208 case DW_FORM_ref_addr:
7209 return "DW_FORM_ref_addr";
7211 return "DW_FORM_ref1";
7213 return "DW_FORM_ref2";
7215 return "DW_FORM_ref4";
7217 return "DW_FORM_ref8";
7218 case DW_FORM_ref_udata:
7219 return "DW_FORM_ref_udata";
7220 case DW_FORM_indirect:
7221 return "DW_FORM_indirect";
7222 case DW_FORM_sec_offset:
7223 return "DW_FORM_sec_offset";
7224 case DW_FORM_exprloc:
7225 return "DW_FORM_exprloc";
7226 case DW_FORM_flag_present:
7227 return "DW_FORM_flag_present";
7228 case DW_FORM_ref_sig8:
7229 return "DW_FORM_ref_sig8";
7231 return "DW_FORM_<unknown>";
7235 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7236 instance of an inlined instance of a decl which is local to an inline
7237 function, so we have to trace all of the way back through the origin chain
7238 to find out what sort of node actually served as the original seed for the
7242 decl_ultimate_origin (const_tree decl)
7244 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7247 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7248 nodes in the function to point to themselves; ignore that if
7249 we're trying to output the abstract instance of this function. */
7250 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7253 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7254 most distant ancestor, this should never happen. */
7255 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7257 return DECL_ABSTRACT_ORIGIN (decl);
7260 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7261 of a virtual function may refer to a base class, so we check the 'this'
7265 decl_class_context (tree decl)
7267 tree context = NULL_TREE;
7269 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7270 context = DECL_CONTEXT (decl);
7272 context = TYPE_MAIN_VARIANT
7273 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7275 if (context && !TYPE_P (context))
7276 context = NULL_TREE;
7281 /* Add an attribute/value pair to a DIE. */
7284 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7286 /* Maybe this should be an assert? */
7290 if (die->die_attr == NULL)
7291 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7292 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7295 static inline enum dw_val_class
7296 AT_class (dw_attr_ref a)
7298 return a->dw_attr_val.val_class;
7301 /* Add a flag value attribute to a DIE. */
7304 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7308 attr.dw_attr = attr_kind;
7309 attr.dw_attr_val.val_class = dw_val_class_flag;
7310 attr.dw_attr_val.v.val_flag = flag;
7311 add_dwarf_attr (die, &attr);
7314 static inline unsigned
7315 AT_flag (dw_attr_ref a)
7317 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7318 return a->dw_attr_val.v.val_flag;
7321 /* Add a signed integer attribute value to a DIE. */
7324 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7328 attr.dw_attr = attr_kind;
7329 attr.dw_attr_val.val_class = dw_val_class_const;
7330 attr.dw_attr_val.v.val_int = int_val;
7331 add_dwarf_attr (die, &attr);
7334 static inline HOST_WIDE_INT
7335 AT_int (dw_attr_ref a)
7337 gcc_assert (a && AT_class (a) == dw_val_class_const);
7338 return a->dw_attr_val.v.val_int;
7341 /* Add an unsigned integer attribute value to a DIE. */
7344 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7345 unsigned HOST_WIDE_INT unsigned_val)
7349 attr.dw_attr = attr_kind;
7350 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7351 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7352 add_dwarf_attr (die, &attr);
7355 static inline unsigned HOST_WIDE_INT
7356 AT_unsigned (dw_attr_ref a)
7358 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7359 return a->dw_attr_val.v.val_unsigned;
7362 /* Add an unsigned double integer attribute value to a DIE. */
7365 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7366 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7370 attr.dw_attr = attr_kind;
7371 attr.dw_attr_val.val_class = dw_val_class_const_double;
7372 attr.dw_attr_val.v.val_double.high = high;
7373 attr.dw_attr_val.v.val_double.low = low;
7374 add_dwarf_attr (die, &attr);
7377 /* Add a floating point attribute value to a DIE and return it. */
7380 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7381 unsigned int length, unsigned int elt_size, unsigned char *array)
7385 attr.dw_attr = attr_kind;
7386 attr.dw_attr_val.val_class = dw_val_class_vec;
7387 attr.dw_attr_val.v.val_vec.length = length;
7388 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7389 attr.dw_attr_val.v.val_vec.array = array;
7390 add_dwarf_attr (die, &attr);
7393 /* Add an 8-byte data attribute value to a DIE. */
7396 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7397 unsigned char data8[8])
7401 attr.dw_attr = attr_kind;
7402 attr.dw_attr_val.val_class = dw_val_class_data8;
7403 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7404 add_dwarf_attr (die, &attr);
7407 /* Hash and equality functions for debug_str_hash. */
7410 debug_str_do_hash (const void *x)
7412 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7416 debug_str_eq (const void *x1, const void *x2)
7418 return strcmp ((((const struct indirect_string_node *)x1)->str),
7419 (const char *)x2) == 0;
7422 /* Add STR to the indirect string hash table. */
7424 static struct indirect_string_node *
7425 find_AT_string (const char *str)
7427 struct indirect_string_node *node;
7430 if (! debug_str_hash)
7431 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7432 debug_str_eq, NULL);
7434 slot = htab_find_slot_with_hash (debug_str_hash, str,
7435 htab_hash_string (str), INSERT);
7438 node = ggc_alloc_cleared_indirect_string_node ();
7439 node->str = ggc_strdup (str);
7443 node = (struct indirect_string_node *) *slot;
7449 /* Add a string attribute value to a DIE. */
7452 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7455 struct indirect_string_node *node;
7457 node = find_AT_string (str);
7459 attr.dw_attr = attr_kind;
7460 attr.dw_attr_val.val_class = dw_val_class_str;
7461 attr.dw_attr_val.v.val_str = node;
7462 add_dwarf_attr (die, &attr);
7465 /* Create a label for an indirect string node, ensuring it is going to
7466 be output, unless its reference count goes down to zero. */
7469 gen_label_for_indirect_string (struct indirect_string_node *node)
7476 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7477 ++dw2_string_counter;
7478 node->label = xstrdup (label);
7481 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7482 debug string STR. */
7485 get_debug_string_label (const char *str)
7487 struct indirect_string_node *node = find_AT_string (str);
7489 debug_str_hash_forced = true;
7491 gen_label_for_indirect_string (node);
7493 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7496 static inline const char *
7497 AT_string (dw_attr_ref a)
7499 gcc_assert (a && AT_class (a) == dw_val_class_str);
7500 return a->dw_attr_val.v.val_str->str;
7503 /* Find out whether a string should be output inline in DIE
7504 or out-of-line in .debug_str section. */
7506 static enum dwarf_form
7507 AT_string_form (dw_attr_ref a)
7509 struct indirect_string_node *node;
7512 gcc_assert (a && AT_class (a) == dw_val_class_str);
7514 node = a->dw_attr_val.v.val_str;
7518 len = strlen (node->str) + 1;
7520 /* If the string is shorter or equal to the size of the reference, it is
7521 always better to put it inline. */
7522 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7523 return node->form = DW_FORM_string;
7525 /* If we cannot expect the linker to merge strings in .debug_str
7526 section, only put it into .debug_str if it is worth even in this
7528 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7529 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7530 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7531 return node->form = DW_FORM_string;
7533 gen_label_for_indirect_string (node);
7535 return node->form = DW_FORM_strp;
7538 /* Add a DIE reference attribute value to a DIE. */
7541 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7545 #ifdef ENABLE_CHECKING
7546 gcc_assert (targ_die != NULL);
7548 /* With LTO we can end up trying to reference something we didn't create
7549 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7550 if (targ_die == NULL)
7554 attr.dw_attr = attr_kind;
7555 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7556 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7557 attr.dw_attr_val.v.val_die_ref.external = 0;
7558 add_dwarf_attr (die, &attr);
7561 /* Add an AT_specification attribute to a DIE, and also make the back
7562 pointer from the specification to the definition. */
7565 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7567 add_AT_die_ref (die, DW_AT_specification, targ_die);
7568 gcc_assert (!targ_die->die_definition);
7569 targ_die->die_definition = die;
7572 static inline dw_die_ref
7573 AT_ref (dw_attr_ref a)
7575 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7576 return a->dw_attr_val.v.val_die_ref.die;
7580 AT_ref_external (dw_attr_ref a)
7582 if (a && AT_class (a) == dw_val_class_die_ref)
7583 return a->dw_attr_val.v.val_die_ref.external;
7589 set_AT_ref_external (dw_attr_ref a, int i)
7591 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7592 a->dw_attr_val.v.val_die_ref.external = i;
7595 /* Add an FDE reference attribute value to a DIE. */
7598 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7602 attr.dw_attr = attr_kind;
7603 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7604 attr.dw_attr_val.v.val_fde_index = targ_fde;
7605 add_dwarf_attr (die, &attr);
7608 /* Add a location description attribute value to a DIE. */
7611 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7615 attr.dw_attr = attr_kind;
7616 attr.dw_attr_val.val_class = dw_val_class_loc;
7617 attr.dw_attr_val.v.val_loc = loc;
7618 add_dwarf_attr (die, &attr);
7621 static inline dw_loc_descr_ref
7622 AT_loc (dw_attr_ref a)
7624 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7625 return a->dw_attr_val.v.val_loc;
7629 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7633 attr.dw_attr = attr_kind;
7634 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7635 attr.dw_attr_val.v.val_loc_list = loc_list;
7636 add_dwarf_attr (die, &attr);
7637 have_location_lists = true;
7640 static inline dw_loc_list_ref
7641 AT_loc_list (dw_attr_ref a)
7643 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7644 return a->dw_attr_val.v.val_loc_list;
7647 static inline dw_loc_list_ref *
7648 AT_loc_list_ptr (dw_attr_ref a)
7650 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7651 return &a->dw_attr_val.v.val_loc_list;
7654 /* Add an address constant attribute value to a DIE. */
7657 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7661 attr.dw_attr = attr_kind;
7662 attr.dw_attr_val.val_class = dw_val_class_addr;
7663 attr.dw_attr_val.v.val_addr = addr;
7664 add_dwarf_attr (die, &attr);
7667 /* Get the RTX from to an address DIE attribute. */
7670 AT_addr (dw_attr_ref a)
7672 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7673 return a->dw_attr_val.v.val_addr;
7676 /* Add a file attribute value to a DIE. */
7679 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7680 struct dwarf_file_data *fd)
7684 attr.dw_attr = attr_kind;
7685 attr.dw_attr_val.val_class = dw_val_class_file;
7686 attr.dw_attr_val.v.val_file = fd;
7687 add_dwarf_attr (die, &attr);
7690 /* Get the dwarf_file_data from a file DIE attribute. */
7692 static inline struct dwarf_file_data *
7693 AT_file (dw_attr_ref a)
7695 gcc_assert (a && AT_class (a) == dw_val_class_file);
7696 return a->dw_attr_val.v.val_file;
7699 /* Add a vms delta attribute value to a DIE. */
7702 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7703 const char *lbl1, const char *lbl2)
7707 attr.dw_attr = attr_kind;
7708 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7709 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7710 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7711 add_dwarf_attr (die, &attr);
7714 /* Add a label identifier attribute value to a DIE. */
7717 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7721 attr.dw_attr = attr_kind;
7722 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7723 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7724 add_dwarf_attr (die, &attr);
7727 /* Add a section offset attribute value to a DIE, an offset into the
7728 debug_line section. */
7731 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7736 attr.dw_attr = attr_kind;
7737 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7738 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7739 add_dwarf_attr (die, &attr);
7742 /* Add a section offset attribute value to a DIE, an offset into the
7743 debug_macinfo section. */
7746 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7751 attr.dw_attr = attr_kind;
7752 attr.dw_attr_val.val_class = dw_val_class_macptr;
7753 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7754 add_dwarf_attr (die, &attr);
7757 /* Add an offset attribute value to a DIE. */
7760 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7761 unsigned HOST_WIDE_INT offset)
7765 attr.dw_attr = attr_kind;
7766 attr.dw_attr_val.val_class = dw_val_class_offset;
7767 attr.dw_attr_val.v.val_offset = offset;
7768 add_dwarf_attr (die, &attr);
7771 /* Add an range_list attribute value to a DIE. */
7774 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7775 long unsigned int offset)
7779 attr.dw_attr = attr_kind;
7780 attr.dw_attr_val.val_class = dw_val_class_range_list;
7781 attr.dw_attr_val.v.val_offset = offset;
7782 add_dwarf_attr (die, &attr);
7785 /* Return the start label of a delta attribute. */
7787 static inline const char *
7788 AT_vms_delta1 (dw_attr_ref a)
7790 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7791 return a->dw_attr_val.v.val_vms_delta.lbl1;
7794 /* Return the end label of a delta attribute. */
7796 static inline const char *
7797 AT_vms_delta2 (dw_attr_ref a)
7799 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7800 return a->dw_attr_val.v.val_vms_delta.lbl2;
7803 static inline const char *
7804 AT_lbl (dw_attr_ref a)
7806 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7807 || AT_class (a) == dw_val_class_lineptr
7808 || AT_class (a) == dw_val_class_macptr));
7809 return a->dw_attr_val.v.val_lbl_id;
7812 /* Get the attribute of type attr_kind. */
7815 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7819 dw_die_ref spec = NULL;
7824 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7825 if (a->dw_attr == attr_kind)
7827 else if (a->dw_attr == DW_AT_specification
7828 || a->dw_attr == DW_AT_abstract_origin)
7832 return get_AT (spec, attr_kind);
7837 /* Return the "low pc" attribute value, typically associated with a subprogram
7838 DIE. Return null if the "low pc" attribute is either not present, or if it
7839 cannot be represented as an assembler label identifier. */
7841 static inline const char *
7842 get_AT_low_pc (dw_die_ref die)
7844 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7846 return a ? AT_lbl (a) : NULL;
7849 /* Return the "high pc" attribute value, typically associated with a subprogram
7850 DIE. Return null if the "high pc" attribute is either not present, or if it
7851 cannot be represented as an assembler label identifier. */
7853 static inline const char *
7854 get_AT_hi_pc (dw_die_ref die)
7856 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7858 return a ? AT_lbl (a) : NULL;
7861 /* Return the value of the string attribute designated by ATTR_KIND, or
7862 NULL if it is not present. */
7864 static inline const char *
7865 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7867 dw_attr_ref a = get_AT (die, attr_kind);
7869 return a ? AT_string (a) : NULL;
7872 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7873 if it is not present. */
7876 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7878 dw_attr_ref a = get_AT (die, attr_kind);
7880 return a ? AT_flag (a) : 0;
7883 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7884 if it is not present. */
7886 static inline unsigned
7887 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7889 dw_attr_ref a = get_AT (die, attr_kind);
7891 return a ? AT_unsigned (a) : 0;
7894 static inline dw_die_ref
7895 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7897 dw_attr_ref a = get_AT (die, attr_kind);
7899 return a ? AT_ref (a) : NULL;
7902 static inline struct dwarf_file_data *
7903 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7905 dw_attr_ref a = get_AT (die, attr_kind);
7907 return a ? AT_file (a) : NULL;
7910 /* Return TRUE if the language is C++. */
7915 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7917 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7920 /* Return TRUE if the language is Fortran. */
7925 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7927 return (lang == DW_LANG_Fortran77
7928 || lang == DW_LANG_Fortran90
7929 || lang == DW_LANG_Fortran95);
7932 /* Return TRUE if the language is Ada. */
7937 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7939 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7942 /* Remove the specified attribute if present. */
7945 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7953 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7954 if (a->dw_attr == attr_kind)
7956 if (AT_class (a) == dw_val_class_str)
7957 if (a->dw_attr_val.v.val_str->refcount)
7958 a->dw_attr_val.v.val_str->refcount--;
7960 /* VEC_ordered_remove should help reduce the number of abbrevs
7962 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7967 /* Remove CHILD from its parent. PREV must have the property that
7968 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7971 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7973 gcc_assert (child->die_parent == prev->die_parent);
7974 gcc_assert (prev->die_sib == child);
7977 gcc_assert (child->die_parent->die_child == child);
7981 prev->die_sib = child->die_sib;
7982 if (child->die_parent->die_child == child)
7983 child->die_parent->die_child = prev;
7986 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7987 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7990 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
7992 dw_die_ref parent = old_child->die_parent;
7994 gcc_assert (parent == prev->die_parent);
7995 gcc_assert (prev->die_sib == old_child);
7997 new_child->die_parent = parent;
7998 if (prev == old_child)
8000 gcc_assert (parent->die_child == old_child);
8001 new_child->die_sib = new_child;
8005 prev->die_sib = new_child;
8006 new_child->die_sib = old_child->die_sib;
8008 if (old_child->die_parent->die_child == old_child)
8009 old_child->die_parent->die_child = new_child;
8012 /* Move all children from OLD_PARENT to NEW_PARENT. */
8015 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
8018 new_parent->die_child = old_parent->die_child;
8019 old_parent->die_child = NULL;
8020 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
8023 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8027 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8033 dw_die_ref prev = c;
8035 while (c->die_tag == tag)
8037 remove_child_with_prev (c, prev);
8038 /* Might have removed every child. */
8039 if (c == c->die_sib)
8043 } while (c != die->die_child);
8046 /* Add a CHILD_DIE as the last child of DIE. */
8049 add_child_die (dw_die_ref die, dw_die_ref child_die)
8051 /* FIXME this should probably be an assert. */
8052 if (! die || ! child_die)
8054 gcc_assert (die != child_die);
8056 child_die->die_parent = die;
8059 child_die->die_sib = die->die_child->die_sib;
8060 die->die_child->die_sib = child_die;
8063 child_die->die_sib = child_die;
8064 die->die_child = child_die;
8067 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8068 is the specification, to the end of PARENT's list of children.
8069 This is done by removing and re-adding it. */
8072 splice_child_die (dw_die_ref parent, dw_die_ref child)
8076 /* We want the declaration DIE from inside the class, not the
8077 specification DIE at toplevel. */
8078 if (child->die_parent != parent)
8080 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8086 gcc_assert (child->die_parent == parent
8087 || (child->die_parent
8088 == get_AT_ref (parent, DW_AT_specification)));
8090 for (p = child->die_parent->die_child; ; p = p->die_sib)
8091 if (p->die_sib == child)
8093 remove_child_with_prev (child, p);
8097 add_child_die (parent, child);
8100 /* Return a pointer to a newly created DIE node. */
8102 static inline dw_die_ref
8103 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8105 dw_die_ref die = ggc_alloc_cleared_die_node ();
8107 die->die_tag = tag_value;
8109 if (parent_die != NULL)
8110 add_child_die (parent_die, die);
8113 limbo_die_node *limbo_node;
8115 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8116 limbo_node->die = die;
8117 limbo_node->created_for = t;
8118 limbo_node->next = limbo_die_list;
8119 limbo_die_list = limbo_node;
8125 /* Return the DIE associated with the given type specifier. */
8127 static inline dw_die_ref
8128 lookup_type_die (tree type)
8130 return TYPE_SYMTAB_DIE (type);
8133 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8134 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8135 anonymous type instead the one of the naming typedef. */
8137 static inline dw_die_ref
8138 strip_naming_typedef (tree type, dw_die_ref type_die)
8141 && TREE_CODE (type) == RECORD_TYPE
8143 && type_die->die_tag == DW_TAG_typedef
8144 && is_naming_typedef_decl (TYPE_NAME (type)))
8145 type_die = get_AT_ref (type_die, DW_AT_type);
8149 /* Like lookup_type_die, but if type is an anonymous type named by a
8150 typedef[1], return the DIE of the anonymous type instead the one of
8151 the naming typedef. This is because in gen_typedef_die, we did
8152 equate the anonymous struct named by the typedef with the DIE of
8153 the naming typedef. So by default, lookup_type_die on an anonymous
8154 struct yields the DIE of the naming typedef.
8156 [1]: Read the comment of is_naming_typedef_decl to learn about what
8157 a naming typedef is. */
8159 static inline dw_die_ref
8160 lookup_type_die_strip_naming_typedef (tree type)
8162 dw_die_ref die = lookup_type_die (type);
8163 return strip_naming_typedef (type, die);
8166 /* Equate a DIE to a given type specifier. */
8169 equate_type_number_to_die (tree type, dw_die_ref type_die)
8171 TYPE_SYMTAB_DIE (type) = type_die;
8174 /* Returns a hash value for X (which really is a die_struct). */
8177 decl_die_table_hash (const void *x)
8179 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8182 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8185 decl_die_table_eq (const void *x, const void *y)
8187 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8190 /* Return the DIE associated with a given declaration. */
8192 static inline dw_die_ref
8193 lookup_decl_die (tree decl)
8195 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8198 /* Returns a hash value for X (which really is a var_loc_list). */
8201 decl_loc_table_hash (const void *x)
8203 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8206 /* Return nonzero if decl_id of var_loc_list X is the same as
8210 decl_loc_table_eq (const void *x, const void *y)
8212 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8215 /* Return the var_loc list associated with a given declaration. */
8217 static inline var_loc_list *
8218 lookup_decl_loc (const_tree decl)
8220 if (!decl_loc_table)
8222 return (var_loc_list *)
8223 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8226 /* Equate a DIE to a particular declaration. */
8229 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8231 unsigned int decl_id = DECL_UID (decl);
8234 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8236 decl_die->decl_id = decl_id;
8239 /* Return how many bits covers PIECE EXPR_LIST. */
8242 decl_piece_bitsize (rtx piece)
8244 int ret = (int) GET_MODE (piece);
8247 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8248 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8249 return INTVAL (XEXP (XEXP (piece, 0), 0));
8252 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8255 decl_piece_varloc_ptr (rtx piece)
8257 if ((int) GET_MODE (piece))
8258 return &XEXP (piece, 0);
8260 return &XEXP (XEXP (piece, 0), 1);
8263 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8264 Next is the chain of following piece nodes. */
8267 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8269 if (bitsize <= (int) MAX_MACHINE_MODE)
8270 return alloc_EXPR_LIST (bitsize, loc_note, next);
8272 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8277 /* Return rtx that should be stored into loc field for
8278 LOC_NOTE and BITPOS/BITSIZE. */
8281 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8282 HOST_WIDE_INT bitsize)
8286 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8288 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8293 /* This function either modifies location piece list *DEST in
8294 place (if SRC and INNER is NULL), or copies location piece list
8295 *SRC to *DEST while modifying it. Location BITPOS is modified
8296 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8297 not copied and if needed some padding around it is added.
8298 When modifying in place, DEST should point to EXPR_LIST where
8299 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8300 to the start of the whole list and INNER points to the EXPR_LIST
8301 where earlier pieces cover PIECE_BITPOS bits. */
8304 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8305 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8306 HOST_WIDE_INT bitsize, rtx loc_note)
8309 bool copy = inner != NULL;
8313 /* First copy all nodes preceeding the current bitpos. */
8314 while (src != inner)
8316 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8317 decl_piece_bitsize (*src), NULL_RTX);
8318 dest = &XEXP (*dest, 1);
8319 src = &XEXP (*src, 1);
8322 /* Add padding if needed. */
8323 if (bitpos != piece_bitpos)
8325 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8326 copy ? NULL_RTX : *dest);
8327 dest = &XEXP (*dest, 1);
8329 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8332 /* A piece with correct bitpos and bitsize already exist,
8333 just update the location for it and return. */
8334 *decl_piece_varloc_ptr (*dest) = loc_note;
8337 /* Add the piece that changed. */
8338 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8339 dest = &XEXP (*dest, 1);
8340 /* Skip over pieces that overlap it. */
8341 diff = bitpos - piece_bitpos + bitsize;
8344 while (diff > 0 && *src)
8347 diff -= decl_piece_bitsize (piece);
8349 src = &XEXP (piece, 1);
8352 *src = XEXP (piece, 1);
8353 free_EXPR_LIST_node (piece);
8356 /* Add padding if needed. */
8357 if (diff < 0 && *src)
8361 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8362 dest = &XEXP (*dest, 1);
8366 /* Finally copy all nodes following it. */
8369 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8370 decl_piece_bitsize (*src), NULL_RTX);
8371 dest = &XEXP (*dest, 1);
8372 src = &XEXP (*src, 1);
8376 /* Add a variable location node to the linked list for DECL. */
8378 static struct var_loc_node *
8379 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8381 unsigned int decl_id;
8384 struct var_loc_node *loc = NULL;
8385 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8387 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8389 tree realdecl = DECL_DEBUG_EXPR (decl);
8390 if (realdecl && handled_component_p (realdecl))
8392 HOST_WIDE_INT maxsize;
8395 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8396 if (!DECL_P (innerdecl)
8397 || DECL_IGNORED_P (innerdecl)
8398 || TREE_STATIC (innerdecl)
8400 || bitpos + bitsize > 256
8401 || bitsize != maxsize)
8407 decl_id = DECL_UID (decl);
8408 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8411 temp = ggc_alloc_cleared_var_loc_list ();
8412 temp->decl_id = decl_id;
8416 temp = (var_loc_list *) *slot;
8420 struct var_loc_node *last = temp->last, *unused = NULL;
8421 rtx *piece_loc = NULL, last_loc_note;
8422 int piece_bitpos = 0;
8426 gcc_assert (last->next == NULL);
8428 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8430 piece_loc = &last->loc;
8433 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8434 if (piece_bitpos + cur_bitsize > bitpos)
8436 piece_bitpos += cur_bitsize;
8437 piece_loc = &XEXP (*piece_loc, 1);
8441 /* TEMP->LAST here is either pointer to the last but one or
8442 last element in the chained list, LAST is pointer to the
8444 if (label && strcmp (last->label, label) == 0)
8446 /* For SRA optimized variables if there weren't any real
8447 insns since last note, just modify the last node. */
8448 if (piece_loc != NULL)
8450 adjust_piece_list (piece_loc, NULL, NULL,
8451 bitpos, piece_bitpos, bitsize, loc_note);
8454 /* If the last note doesn't cover any instructions, remove it. */
8455 if (temp->last != last)
8457 temp->last->next = NULL;
8460 gcc_assert (strcmp (last->label, label) != 0);
8464 gcc_assert (temp->first == temp->last);
8465 memset (temp->last, '\0', sizeof (*temp->last));
8466 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8470 if (bitsize == -1 && NOTE_P (last->loc))
8471 last_loc_note = last->loc;
8472 else if (piece_loc != NULL
8473 && *piece_loc != NULL_RTX
8474 && piece_bitpos == bitpos
8475 && decl_piece_bitsize (*piece_loc) == bitsize)
8476 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8478 last_loc_note = NULL_RTX;
8479 /* If the current location is the same as the end of the list,
8480 and either both or neither of the locations is uninitialized,
8481 we have nothing to do. */
8482 if (last_loc_note == NULL_RTX
8483 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8484 NOTE_VAR_LOCATION_LOC (loc_note)))
8485 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8486 != NOTE_VAR_LOCATION_STATUS (loc_note))
8487 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8488 == VAR_INIT_STATUS_UNINITIALIZED)
8489 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8490 == VAR_INIT_STATUS_UNINITIALIZED))))
8492 /* Add LOC to the end of list and update LAST. If the last
8493 element of the list has been removed above, reuse its
8494 memory for the new node, otherwise allocate a new one. */
8498 memset (loc, '\0', sizeof (*loc));
8501 loc = ggc_alloc_cleared_var_loc_node ();
8502 if (bitsize == -1 || piece_loc == NULL)
8503 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8505 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8506 bitpos, piece_bitpos, bitsize, loc_note);
8508 /* Ensure TEMP->LAST will point either to the new last but one
8509 element of the chain, or to the last element in it. */
8510 if (last != temp->last)
8518 loc = ggc_alloc_cleared_var_loc_node ();
8521 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8526 /* Keep track of the number of spaces used to indent the
8527 output of the debugging routines that print the structure of
8528 the DIE internal representation. */
8529 static int print_indent;
8531 /* Indent the line the number of spaces given by print_indent. */
8534 print_spaces (FILE *outfile)
8536 fprintf (outfile, "%*s", print_indent, "");
8539 /* Print a type signature in hex. */
8542 print_signature (FILE *outfile, char *sig)
8546 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8547 fprintf (outfile, "%02x", sig[i] & 0xff);
8550 /* Print the information associated with a given DIE, and its children.
8551 This routine is a debugging aid only. */
8554 print_die (dw_die_ref die, FILE *outfile)
8560 print_spaces (outfile);
8561 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8562 die->die_offset, dwarf_tag_name (die->die_tag),
8564 print_spaces (outfile);
8565 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8566 fprintf (outfile, " offset: %ld", die->die_offset);
8567 fprintf (outfile, " mark: %d\n", die->die_mark);
8569 if (dwarf_version >= 4 && die->die_id.die_type_node)
8571 print_spaces (outfile);
8572 fprintf (outfile, " signature: ");
8573 print_signature (outfile, die->die_id.die_type_node->signature);
8574 fprintf (outfile, "\n");
8577 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8579 print_spaces (outfile);
8580 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8582 switch (AT_class (a))
8584 case dw_val_class_addr:
8585 fprintf (outfile, "address");
8587 case dw_val_class_offset:
8588 fprintf (outfile, "offset");
8590 case dw_val_class_loc:
8591 fprintf (outfile, "location descriptor");
8593 case dw_val_class_loc_list:
8594 fprintf (outfile, "location list -> label:%s",
8595 AT_loc_list (a)->ll_symbol);
8597 case dw_val_class_range_list:
8598 fprintf (outfile, "range list");
8600 case dw_val_class_const:
8601 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8603 case dw_val_class_unsigned_const:
8604 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8606 case dw_val_class_const_double:
8607 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8608 HOST_WIDE_INT_PRINT_UNSIGNED")",
8609 a->dw_attr_val.v.val_double.high,
8610 a->dw_attr_val.v.val_double.low);
8612 case dw_val_class_vec:
8613 fprintf (outfile, "floating-point or vector constant");
8615 case dw_val_class_flag:
8616 fprintf (outfile, "%u", AT_flag (a));
8618 case dw_val_class_die_ref:
8619 if (AT_ref (a) != NULL)
8621 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8623 fprintf (outfile, "die -> signature: ");
8624 print_signature (outfile,
8625 AT_ref (a)->die_id.die_type_node->signature);
8627 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8628 fprintf (outfile, "die -> label: %s",
8629 AT_ref (a)->die_id.die_symbol);
8631 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8632 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8635 fprintf (outfile, "die -> <null>");
8637 case dw_val_class_vms_delta:
8638 fprintf (outfile, "delta: @slotcount(%s-%s)",
8639 AT_vms_delta2 (a), AT_vms_delta1 (a));
8641 case dw_val_class_lbl_id:
8642 case dw_val_class_lineptr:
8643 case dw_val_class_macptr:
8644 fprintf (outfile, "label: %s", AT_lbl (a));
8646 case dw_val_class_str:
8647 if (AT_string (a) != NULL)
8648 fprintf (outfile, "\"%s\"", AT_string (a));
8650 fprintf (outfile, "<null>");
8652 case dw_val_class_file:
8653 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8654 AT_file (a)->emitted_number);
8656 case dw_val_class_data8:
8660 for (i = 0; i < 8; i++)
8661 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8668 fprintf (outfile, "\n");
8671 if (die->die_child != NULL)
8674 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8677 if (print_indent == 0)
8678 fprintf (outfile, "\n");
8681 /* Print the contents of the source code line number correspondence table.
8682 This routine is a debugging aid only. */
8685 print_dwarf_line_table (FILE *outfile)
8688 dw_line_info_ref line_info;
8690 fprintf (outfile, "\n\nDWARF source line information\n");
8691 for (i = 1; i < line_info_table_in_use; i++)
8693 line_info = &line_info_table[i];
8694 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8695 line_info->dw_file_num,
8696 line_info->dw_line_num);
8699 fprintf (outfile, "\n\n");
8702 /* Print the information collected for a given DIE. */
8705 debug_dwarf_die (dw_die_ref die)
8707 print_die (die, stderr);
8710 /* Print all DWARF information collected for the compilation unit.
8711 This routine is a debugging aid only. */
8717 print_die (comp_unit_die (), stderr);
8718 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8719 print_dwarf_line_table (stderr);
8722 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8723 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8724 DIE that marks the start of the DIEs for this include file. */
8727 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8729 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8730 dw_die_ref new_unit = gen_compile_unit_die (filename);
8732 new_unit->die_sib = old_unit;
8736 /* Close an include-file CU and reopen the enclosing one. */
8739 pop_compile_unit (dw_die_ref old_unit)
8741 dw_die_ref new_unit = old_unit->die_sib;
8743 old_unit->die_sib = NULL;
8747 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8748 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8750 /* Calculate the checksum of a location expression. */
8753 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8757 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8759 CHECKSUM (loc->dw_loc_oprnd1);
8760 CHECKSUM (loc->dw_loc_oprnd2);
8763 /* Calculate the checksum of an attribute. */
8766 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8768 dw_loc_descr_ref loc;
8771 CHECKSUM (at->dw_attr);
8773 /* We don't care that this was compiled with a different compiler
8774 snapshot; if the output is the same, that's what matters. */
8775 if (at->dw_attr == DW_AT_producer)
8778 switch (AT_class (at))
8780 case dw_val_class_const:
8781 CHECKSUM (at->dw_attr_val.v.val_int);
8783 case dw_val_class_unsigned_const:
8784 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8786 case dw_val_class_const_double:
8787 CHECKSUM (at->dw_attr_val.v.val_double);
8789 case dw_val_class_vec:
8790 CHECKSUM (at->dw_attr_val.v.val_vec);
8792 case dw_val_class_flag:
8793 CHECKSUM (at->dw_attr_val.v.val_flag);
8795 case dw_val_class_str:
8796 CHECKSUM_STRING (AT_string (at));
8799 case dw_val_class_addr:
8801 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8802 CHECKSUM_STRING (XSTR (r, 0));
8805 case dw_val_class_offset:
8806 CHECKSUM (at->dw_attr_val.v.val_offset);
8809 case dw_val_class_loc:
8810 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8811 loc_checksum (loc, ctx);
8814 case dw_val_class_die_ref:
8815 die_checksum (AT_ref (at), ctx, mark);
8818 case dw_val_class_fde_ref:
8819 case dw_val_class_vms_delta:
8820 case dw_val_class_lbl_id:
8821 case dw_val_class_lineptr:
8822 case dw_val_class_macptr:
8825 case dw_val_class_file:
8826 CHECKSUM_STRING (AT_file (at)->filename);
8829 case dw_val_class_data8:
8830 CHECKSUM (at->dw_attr_val.v.val_data8);
8838 /* Calculate the checksum of a DIE. */
8841 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8847 /* To avoid infinite recursion. */
8850 CHECKSUM (die->die_mark);
8853 die->die_mark = ++(*mark);
8855 CHECKSUM (die->die_tag);
8857 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8858 attr_checksum (a, ctx, mark);
8860 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8864 #undef CHECKSUM_STRING
8866 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8867 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8868 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8869 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8870 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8871 #define CHECKSUM_ATTR(FOO) \
8872 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8874 /* Calculate the checksum of a number in signed LEB128 format. */
8877 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8884 byte = (value & 0x7f);
8886 more = !((value == 0 && (byte & 0x40) == 0)
8887 || (value == -1 && (byte & 0x40) != 0));
8896 /* Calculate the checksum of a number in unsigned LEB128 format. */
8899 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8903 unsigned char byte = (value & 0x7f);
8906 /* More bytes to follow. */
8914 /* Checksum the context of the DIE. This adds the names of any
8915 surrounding namespaces or structures to the checksum. */
8918 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8922 int tag = die->die_tag;
8924 if (tag != DW_TAG_namespace
8925 && tag != DW_TAG_structure_type
8926 && tag != DW_TAG_class_type)
8929 name = get_AT_string (die, DW_AT_name);
8931 spec = get_AT_ref (die, DW_AT_specification);
8935 if (die->die_parent != NULL)
8936 checksum_die_context (die->die_parent, ctx);
8938 CHECKSUM_ULEB128 ('C');
8939 CHECKSUM_ULEB128 (tag);
8941 CHECKSUM_STRING (name);
8944 /* Calculate the checksum of a location expression. */
8947 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8949 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8950 were emitted as a DW_FORM_sdata instead of a location expression. */
8951 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8953 CHECKSUM_ULEB128 (DW_FORM_sdata);
8954 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8958 /* Otherwise, just checksum the raw location expression. */
8961 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8962 CHECKSUM (loc->dw_loc_oprnd1);
8963 CHECKSUM (loc->dw_loc_oprnd2);
8964 loc = loc->dw_loc_next;
8968 /* Calculate the checksum of an attribute. */
8971 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8972 struct md5_ctx *ctx, int *mark)
8974 dw_loc_descr_ref loc;
8977 if (AT_class (at) == dw_val_class_die_ref)
8979 dw_die_ref target_die = AT_ref (at);
8981 /* For pointer and reference types, we checksum only the (qualified)
8982 name of the target type (if there is a name). For friend entries,
8983 we checksum only the (qualified) name of the target type or function.
8984 This allows the checksum to remain the same whether the target type
8985 is complete or not. */
8986 if ((at->dw_attr == DW_AT_type
8987 && (tag == DW_TAG_pointer_type
8988 || tag == DW_TAG_reference_type
8989 || tag == DW_TAG_rvalue_reference_type
8990 || tag == DW_TAG_ptr_to_member_type))
8991 || (at->dw_attr == DW_AT_friend
8992 && tag == DW_TAG_friend))
8994 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
8996 if (name_attr != NULL)
8998 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9002 CHECKSUM_ULEB128 ('N');
9003 CHECKSUM_ULEB128 (at->dw_attr);
9004 if (decl->die_parent != NULL)
9005 checksum_die_context (decl->die_parent, ctx);
9006 CHECKSUM_ULEB128 ('E');
9007 CHECKSUM_STRING (AT_string (name_attr));
9012 /* For all other references to another DIE, we check to see if the
9013 target DIE has already been visited. If it has, we emit a
9014 backward reference; if not, we descend recursively. */
9015 if (target_die->die_mark > 0)
9017 CHECKSUM_ULEB128 ('R');
9018 CHECKSUM_ULEB128 (at->dw_attr);
9019 CHECKSUM_ULEB128 (target_die->die_mark);
9023 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9027 target_die->die_mark = ++(*mark);
9028 CHECKSUM_ULEB128 ('T');
9029 CHECKSUM_ULEB128 (at->dw_attr);
9030 if (decl->die_parent != NULL)
9031 checksum_die_context (decl->die_parent, ctx);
9032 die_checksum_ordered (target_die, ctx, mark);
9037 CHECKSUM_ULEB128 ('A');
9038 CHECKSUM_ULEB128 (at->dw_attr);
9040 switch (AT_class (at))
9042 case dw_val_class_const:
9043 CHECKSUM_ULEB128 (DW_FORM_sdata);
9044 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9047 case dw_val_class_unsigned_const:
9048 CHECKSUM_ULEB128 (DW_FORM_sdata);
9049 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9052 case dw_val_class_const_double:
9053 CHECKSUM_ULEB128 (DW_FORM_block);
9054 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9055 CHECKSUM (at->dw_attr_val.v.val_double);
9058 case dw_val_class_vec:
9059 CHECKSUM_ULEB128 (DW_FORM_block);
9060 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9061 CHECKSUM (at->dw_attr_val.v.val_vec);
9064 case dw_val_class_flag:
9065 CHECKSUM_ULEB128 (DW_FORM_flag);
9066 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9069 case dw_val_class_str:
9070 CHECKSUM_ULEB128 (DW_FORM_string);
9071 CHECKSUM_STRING (AT_string (at));
9074 case dw_val_class_addr:
9076 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9077 CHECKSUM_ULEB128 (DW_FORM_string);
9078 CHECKSUM_STRING (XSTR (r, 0));
9081 case dw_val_class_offset:
9082 CHECKSUM_ULEB128 (DW_FORM_sdata);
9083 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9086 case dw_val_class_loc:
9087 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9088 loc_checksum_ordered (loc, ctx);
9091 case dw_val_class_fde_ref:
9092 case dw_val_class_lbl_id:
9093 case dw_val_class_lineptr:
9094 case dw_val_class_macptr:
9097 case dw_val_class_file:
9098 CHECKSUM_ULEB128 (DW_FORM_string);
9099 CHECKSUM_STRING (AT_file (at)->filename);
9102 case dw_val_class_data8:
9103 CHECKSUM (at->dw_attr_val.v.val_data8);
9111 struct checksum_attributes
9113 dw_attr_ref at_name;
9114 dw_attr_ref at_type;
9115 dw_attr_ref at_friend;
9116 dw_attr_ref at_accessibility;
9117 dw_attr_ref at_address_class;
9118 dw_attr_ref at_allocated;
9119 dw_attr_ref at_artificial;
9120 dw_attr_ref at_associated;
9121 dw_attr_ref at_binary_scale;
9122 dw_attr_ref at_bit_offset;
9123 dw_attr_ref at_bit_size;
9124 dw_attr_ref at_bit_stride;
9125 dw_attr_ref at_byte_size;
9126 dw_attr_ref at_byte_stride;
9127 dw_attr_ref at_const_value;
9128 dw_attr_ref at_containing_type;
9129 dw_attr_ref at_count;
9130 dw_attr_ref at_data_location;
9131 dw_attr_ref at_data_member_location;
9132 dw_attr_ref at_decimal_scale;
9133 dw_attr_ref at_decimal_sign;
9134 dw_attr_ref at_default_value;
9135 dw_attr_ref at_digit_count;
9136 dw_attr_ref at_discr;
9137 dw_attr_ref at_discr_list;
9138 dw_attr_ref at_discr_value;
9139 dw_attr_ref at_encoding;
9140 dw_attr_ref at_endianity;
9141 dw_attr_ref at_explicit;
9142 dw_attr_ref at_is_optional;
9143 dw_attr_ref at_location;
9144 dw_attr_ref at_lower_bound;
9145 dw_attr_ref at_mutable;
9146 dw_attr_ref at_ordering;
9147 dw_attr_ref at_picture_string;
9148 dw_attr_ref at_prototyped;
9149 dw_attr_ref at_small;
9150 dw_attr_ref at_segment;
9151 dw_attr_ref at_string_length;
9152 dw_attr_ref at_threads_scaled;
9153 dw_attr_ref at_upper_bound;
9154 dw_attr_ref at_use_location;
9155 dw_attr_ref at_use_UTF8;
9156 dw_attr_ref at_variable_parameter;
9157 dw_attr_ref at_virtuality;
9158 dw_attr_ref at_visibility;
9159 dw_attr_ref at_vtable_elem_location;
9162 /* Collect the attributes that we will want to use for the checksum. */
9165 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9170 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9181 attrs->at_friend = a;
9183 case DW_AT_accessibility:
9184 attrs->at_accessibility = a;
9186 case DW_AT_address_class:
9187 attrs->at_address_class = a;
9189 case DW_AT_allocated:
9190 attrs->at_allocated = a;
9192 case DW_AT_artificial:
9193 attrs->at_artificial = a;
9195 case DW_AT_associated:
9196 attrs->at_associated = a;
9198 case DW_AT_binary_scale:
9199 attrs->at_binary_scale = a;
9201 case DW_AT_bit_offset:
9202 attrs->at_bit_offset = a;
9204 case DW_AT_bit_size:
9205 attrs->at_bit_size = a;
9207 case DW_AT_bit_stride:
9208 attrs->at_bit_stride = a;
9210 case DW_AT_byte_size:
9211 attrs->at_byte_size = a;
9213 case DW_AT_byte_stride:
9214 attrs->at_byte_stride = a;
9216 case DW_AT_const_value:
9217 attrs->at_const_value = a;
9219 case DW_AT_containing_type:
9220 attrs->at_containing_type = a;
9223 attrs->at_count = a;
9225 case DW_AT_data_location:
9226 attrs->at_data_location = a;
9228 case DW_AT_data_member_location:
9229 attrs->at_data_member_location = a;
9231 case DW_AT_decimal_scale:
9232 attrs->at_decimal_scale = a;
9234 case DW_AT_decimal_sign:
9235 attrs->at_decimal_sign = a;
9237 case DW_AT_default_value:
9238 attrs->at_default_value = a;
9240 case DW_AT_digit_count:
9241 attrs->at_digit_count = a;
9244 attrs->at_discr = a;
9246 case DW_AT_discr_list:
9247 attrs->at_discr_list = a;
9249 case DW_AT_discr_value:
9250 attrs->at_discr_value = a;
9252 case DW_AT_encoding:
9253 attrs->at_encoding = a;
9255 case DW_AT_endianity:
9256 attrs->at_endianity = a;
9258 case DW_AT_explicit:
9259 attrs->at_explicit = a;
9261 case DW_AT_is_optional:
9262 attrs->at_is_optional = a;
9264 case DW_AT_location:
9265 attrs->at_location = a;
9267 case DW_AT_lower_bound:
9268 attrs->at_lower_bound = a;
9271 attrs->at_mutable = a;
9273 case DW_AT_ordering:
9274 attrs->at_ordering = a;
9276 case DW_AT_picture_string:
9277 attrs->at_picture_string = a;
9279 case DW_AT_prototyped:
9280 attrs->at_prototyped = a;
9283 attrs->at_small = a;
9286 attrs->at_segment = a;
9288 case DW_AT_string_length:
9289 attrs->at_string_length = a;
9291 case DW_AT_threads_scaled:
9292 attrs->at_threads_scaled = a;
9294 case DW_AT_upper_bound:
9295 attrs->at_upper_bound = a;
9297 case DW_AT_use_location:
9298 attrs->at_use_location = a;
9300 case DW_AT_use_UTF8:
9301 attrs->at_use_UTF8 = a;
9303 case DW_AT_variable_parameter:
9304 attrs->at_variable_parameter = a;
9306 case DW_AT_virtuality:
9307 attrs->at_virtuality = a;
9309 case DW_AT_visibility:
9310 attrs->at_visibility = a;
9312 case DW_AT_vtable_elem_location:
9313 attrs->at_vtable_elem_location = a;
9321 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9324 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9328 struct checksum_attributes attrs;
9330 CHECKSUM_ULEB128 ('D');
9331 CHECKSUM_ULEB128 (die->die_tag);
9333 memset (&attrs, 0, sizeof (attrs));
9335 decl = get_AT_ref (die, DW_AT_specification);
9337 collect_checksum_attributes (&attrs, decl);
9338 collect_checksum_attributes (&attrs, die);
9340 CHECKSUM_ATTR (attrs.at_name);
9341 CHECKSUM_ATTR (attrs.at_accessibility);
9342 CHECKSUM_ATTR (attrs.at_address_class);
9343 CHECKSUM_ATTR (attrs.at_allocated);
9344 CHECKSUM_ATTR (attrs.at_artificial);
9345 CHECKSUM_ATTR (attrs.at_associated);
9346 CHECKSUM_ATTR (attrs.at_binary_scale);
9347 CHECKSUM_ATTR (attrs.at_bit_offset);
9348 CHECKSUM_ATTR (attrs.at_bit_size);
9349 CHECKSUM_ATTR (attrs.at_bit_stride);
9350 CHECKSUM_ATTR (attrs.at_byte_size);
9351 CHECKSUM_ATTR (attrs.at_byte_stride);
9352 CHECKSUM_ATTR (attrs.at_const_value);
9353 CHECKSUM_ATTR (attrs.at_containing_type);
9354 CHECKSUM_ATTR (attrs.at_count);
9355 CHECKSUM_ATTR (attrs.at_data_location);
9356 CHECKSUM_ATTR (attrs.at_data_member_location);
9357 CHECKSUM_ATTR (attrs.at_decimal_scale);
9358 CHECKSUM_ATTR (attrs.at_decimal_sign);
9359 CHECKSUM_ATTR (attrs.at_default_value);
9360 CHECKSUM_ATTR (attrs.at_digit_count);
9361 CHECKSUM_ATTR (attrs.at_discr);
9362 CHECKSUM_ATTR (attrs.at_discr_list);
9363 CHECKSUM_ATTR (attrs.at_discr_value);
9364 CHECKSUM_ATTR (attrs.at_encoding);
9365 CHECKSUM_ATTR (attrs.at_endianity);
9366 CHECKSUM_ATTR (attrs.at_explicit);
9367 CHECKSUM_ATTR (attrs.at_is_optional);
9368 CHECKSUM_ATTR (attrs.at_location);
9369 CHECKSUM_ATTR (attrs.at_lower_bound);
9370 CHECKSUM_ATTR (attrs.at_mutable);
9371 CHECKSUM_ATTR (attrs.at_ordering);
9372 CHECKSUM_ATTR (attrs.at_picture_string);
9373 CHECKSUM_ATTR (attrs.at_prototyped);
9374 CHECKSUM_ATTR (attrs.at_small);
9375 CHECKSUM_ATTR (attrs.at_segment);
9376 CHECKSUM_ATTR (attrs.at_string_length);
9377 CHECKSUM_ATTR (attrs.at_threads_scaled);
9378 CHECKSUM_ATTR (attrs.at_upper_bound);
9379 CHECKSUM_ATTR (attrs.at_use_location);
9380 CHECKSUM_ATTR (attrs.at_use_UTF8);
9381 CHECKSUM_ATTR (attrs.at_variable_parameter);
9382 CHECKSUM_ATTR (attrs.at_virtuality);
9383 CHECKSUM_ATTR (attrs.at_visibility);
9384 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9385 CHECKSUM_ATTR (attrs.at_type);
9386 CHECKSUM_ATTR (attrs.at_friend);
9388 /* Checksum the child DIEs, except for nested types and member functions. */
9391 dw_attr_ref name_attr;
9394 name_attr = get_AT (c, DW_AT_name);
9395 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9396 && name_attr != NULL)
9398 CHECKSUM_ULEB128 ('S');
9399 CHECKSUM_ULEB128 (c->die_tag);
9400 CHECKSUM_STRING (AT_string (name_attr));
9404 /* Mark this DIE so it gets processed when unmarking. */
9405 if (c->die_mark == 0)
9407 die_checksum_ordered (c, ctx, mark);
9409 } while (c != die->die_child);
9411 CHECKSUM_ULEB128 (0);
9415 #undef CHECKSUM_STRING
9416 #undef CHECKSUM_ATTR
9417 #undef CHECKSUM_LEB128
9418 #undef CHECKSUM_ULEB128
9420 /* Generate the type signature for DIE. This is computed by generating an
9421 MD5 checksum over the DIE's tag, its relevant attributes, and its
9422 children. Attributes that are references to other DIEs are processed
9423 by recursion, using the MARK field to prevent infinite recursion.
9424 If the DIE is nested inside a namespace or another type, we also
9425 need to include that context in the signature. The lower 64 bits
9426 of the resulting MD5 checksum comprise the signature. */
9429 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9433 unsigned char checksum[16];
9437 name = get_AT_string (die, DW_AT_name);
9438 decl = get_AT_ref (die, DW_AT_specification);
9440 /* First, compute a signature for just the type name (and its surrounding
9441 context, if any. This is stored in the type unit DIE for link-time
9442 ODR (one-definition rule) checking. */
9444 if (is_cxx() && name != NULL)
9446 md5_init_ctx (&ctx);
9448 /* Checksum the names of surrounding namespaces and structures. */
9449 if (decl != NULL && decl->die_parent != NULL)
9450 checksum_die_context (decl->die_parent, &ctx);
9452 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9453 md5_process_bytes (name, strlen (name) + 1, &ctx);
9454 md5_finish_ctx (&ctx, checksum);
9456 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9459 /* Next, compute the complete type signature. */
9461 md5_init_ctx (&ctx);
9463 die->die_mark = mark;
9465 /* Checksum the names of surrounding namespaces and structures. */
9466 if (decl != NULL && decl->die_parent != NULL)
9467 checksum_die_context (decl->die_parent, &ctx);
9469 /* Checksum the DIE and its children. */
9470 die_checksum_ordered (die, &ctx, &mark);
9471 unmark_all_dies (die);
9472 md5_finish_ctx (&ctx, checksum);
9474 /* Store the signature in the type node and link the type DIE and the
9475 type node together. */
9476 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9477 DWARF_TYPE_SIGNATURE_SIZE);
9478 die->die_id.die_type_node = type_node;
9479 type_node->type_die = die;
9481 /* If the DIE is a specification, link its declaration to the type node
9484 decl->die_id.die_type_node = type_node;
9487 /* Do the location expressions look same? */
9489 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9491 return loc1->dw_loc_opc == loc2->dw_loc_opc
9492 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9493 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9496 /* Do the values look the same? */
9498 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9500 dw_loc_descr_ref loc1, loc2;
9503 if (v1->val_class != v2->val_class)
9506 switch (v1->val_class)
9508 case dw_val_class_const:
9509 return v1->v.val_int == v2->v.val_int;
9510 case dw_val_class_unsigned_const:
9511 return v1->v.val_unsigned == v2->v.val_unsigned;
9512 case dw_val_class_const_double:
9513 return v1->v.val_double.high == v2->v.val_double.high
9514 && v1->v.val_double.low == v2->v.val_double.low;
9515 case dw_val_class_vec:
9516 if (v1->v.val_vec.length != v2->v.val_vec.length
9517 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9519 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9520 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9523 case dw_val_class_flag:
9524 return v1->v.val_flag == v2->v.val_flag;
9525 case dw_val_class_str:
9526 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9528 case dw_val_class_addr:
9529 r1 = v1->v.val_addr;
9530 r2 = v2->v.val_addr;
9531 if (GET_CODE (r1) != GET_CODE (r2))
9533 return !rtx_equal_p (r1, r2);
9535 case dw_val_class_offset:
9536 return v1->v.val_offset == v2->v.val_offset;
9538 case dw_val_class_loc:
9539 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9541 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9542 if (!same_loc_p (loc1, loc2, mark))
9544 return !loc1 && !loc2;
9546 case dw_val_class_die_ref:
9547 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9549 case dw_val_class_fde_ref:
9550 case dw_val_class_vms_delta:
9551 case dw_val_class_lbl_id:
9552 case dw_val_class_lineptr:
9553 case dw_val_class_macptr:
9556 case dw_val_class_file:
9557 return v1->v.val_file == v2->v.val_file;
9559 case dw_val_class_data8:
9560 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9567 /* Do the attributes look the same? */
9570 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9572 if (at1->dw_attr != at2->dw_attr)
9575 /* We don't care that this was compiled with a different compiler
9576 snapshot; if the output is the same, that's what matters. */
9577 if (at1->dw_attr == DW_AT_producer)
9580 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9583 /* Do the dies look the same? */
9586 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9592 /* To avoid infinite recursion. */
9594 return die1->die_mark == die2->die_mark;
9595 die1->die_mark = die2->die_mark = ++(*mark);
9597 if (die1->die_tag != die2->die_tag)
9600 if (VEC_length (dw_attr_node, die1->die_attr)
9601 != VEC_length (dw_attr_node, die2->die_attr))
9604 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9605 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9608 c1 = die1->die_child;
9609 c2 = die2->die_child;
9618 if (!same_die_p (c1, c2, mark))
9622 if (c1 == die1->die_child)
9624 if (c2 == die2->die_child)
9634 /* Do the dies look the same? Wrapper around same_die_p. */
9637 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9640 int ret = same_die_p (die1, die2, &mark);
9642 unmark_all_dies (die1);
9643 unmark_all_dies (die2);
9648 /* The prefix to attach to symbols on DIEs in the current comdat debug
9650 static char *comdat_symbol_id;
9652 /* The index of the current symbol within the current comdat CU. */
9653 static unsigned int comdat_symbol_number;
9655 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9656 children, and set comdat_symbol_id accordingly. */
9659 compute_section_prefix (dw_die_ref unit_die)
9661 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9662 const char *base = die_name ? lbasename (die_name) : "anonymous";
9663 char *name = XALLOCAVEC (char, strlen (base) + 64);
9666 unsigned char checksum[16];
9669 /* Compute the checksum of the DIE, then append part of it as hex digits to
9670 the name filename of the unit. */
9672 md5_init_ctx (&ctx);
9674 die_checksum (unit_die, &ctx, &mark);
9675 unmark_all_dies (unit_die);
9676 md5_finish_ctx (&ctx, checksum);
9678 sprintf (name, "%s.", base);
9679 clean_symbol_name (name);
9681 p = name + strlen (name);
9682 for (i = 0; i < 4; i++)
9684 sprintf (p, "%.2x", checksum[i]);
9688 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9689 comdat_symbol_number = 0;
9692 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9695 is_type_die (dw_die_ref die)
9697 switch (die->die_tag)
9699 case DW_TAG_array_type:
9700 case DW_TAG_class_type:
9701 case DW_TAG_interface_type:
9702 case DW_TAG_enumeration_type:
9703 case DW_TAG_pointer_type:
9704 case DW_TAG_reference_type:
9705 case DW_TAG_rvalue_reference_type:
9706 case DW_TAG_string_type:
9707 case DW_TAG_structure_type:
9708 case DW_TAG_subroutine_type:
9709 case DW_TAG_union_type:
9710 case DW_TAG_ptr_to_member_type:
9711 case DW_TAG_set_type:
9712 case DW_TAG_subrange_type:
9713 case DW_TAG_base_type:
9714 case DW_TAG_const_type:
9715 case DW_TAG_file_type:
9716 case DW_TAG_packed_type:
9717 case DW_TAG_volatile_type:
9718 case DW_TAG_typedef:
9725 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9726 Basically, we want to choose the bits that are likely to be shared between
9727 compilations (types) and leave out the bits that are specific to individual
9728 compilations (functions). */
9731 is_comdat_die (dw_die_ref c)
9733 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9734 we do for stabs. The advantage is a greater likelihood of sharing between
9735 objects that don't include headers in the same order (and therefore would
9736 put the base types in a different comdat). jason 8/28/00 */
9738 if (c->die_tag == DW_TAG_base_type)
9741 if (c->die_tag == DW_TAG_pointer_type
9742 || c->die_tag == DW_TAG_reference_type
9743 || c->die_tag == DW_TAG_rvalue_reference_type
9744 || c->die_tag == DW_TAG_const_type
9745 || c->die_tag == DW_TAG_volatile_type)
9747 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9749 return t ? is_comdat_die (t) : 0;
9752 return is_type_die (c);
9755 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9756 compilation unit. */
9759 is_symbol_die (dw_die_ref c)
9761 return (is_type_die (c)
9762 || is_declaration_die (c)
9763 || c->die_tag == DW_TAG_namespace
9764 || c->die_tag == DW_TAG_module);
9767 /* Returns true iff C is a compile-unit DIE. */
9770 is_cu_die (dw_die_ref c)
9772 return c && c->die_tag == DW_TAG_compile_unit;
9776 gen_internal_sym (const char *prefix)
9780 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9781 return xstrdup (buf);
9784 /* Assign symbols to all worthy DIEs under DIE. */
9787 assign_symbol_names (dw_die_ref die)
9791 if (is_symbol_die (die))
9793 if (comdat_symbol_id)
9795 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9797 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9798 comdat_symbol_id, comdat_symbol_number++);
9799 die->die_id.die_symbol = xstrdup (p);
9802 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9805 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9808 struct cu_hash_table_entry
9811 unsigned min_comdat_num, max_comdat_num;
9812 struct cu_hash_table_entry *next;
9815 /* Routines to manipulate hash table of CUs. */
9817 htab_cu_hash (const void *of)
9819 const struct cu_hash_table_entry *const entry =
9820 (const struct cu_hash_table_entry *) of;
9822 return htab_hash_string (entry->cu->die_id.die_symbol);
9826 htab_cu_eq (const void *of1, const void *of2)
9828 const struct cu_hash_table_entry *const entry1 =
9829 (const struct cu_hash_table_entry *) of1;
9830 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9832 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9836 htab_cu_del (void *what)
9838 struct cu_hash_table_entry *next,
9839 *entry = (struct cu_hash_table_entry *) what;
9849 /* Check whether we have already seen this CU and set up SYM_NUM
9852 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9854 struct cu_hash_table_entry dummy;
9855 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9857 dummy.max_comdat_num = 0;
9859 slot = (struct cu_hash_table_entry **)
9860 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9864 for (; entry; last = entry, entry = entry->next)
9866 if (same_die_p_wrap (cu, entry->cu))
9872 *sym_num = entry->min_comdat_num;
9876 entry = XCNEW (struct cu_hash_table_entry);
9878 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9879 entry->next = *slot;
9885 /* Record SYM_NUM to record of CU in HTABLE. */
9887 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9889 struct cu_hash_table_entry **slot, *entry;
9891 slot = (struct cu_hash_table_entry **)
9892 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9896 entry->max_comdat_num = sym_num;
9899 /* Traverse the DIE (which is always comp_unit_die), and set up
9900 additional compilation units for each of the include files we see
9901 bracketed by BINCL/EINCL. */
9904 break_out_includes (dw_die_ref die)
9907 dw_die_ref unit = NULL;
9908 limbo_die_node *node, **pnode;
9909 htab_t cu_hash_table;
9913 dw_die_ref prev = c;
9915 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9916 || (unit && is_comdat_die (c)))
9918 dw_die_ref next = c->die_sib;
9920 /* This DIE is for a secondary CU; remove it from the main one. */
9921 remove_child_with_prev (c, prev);
9923 if (c->die_tag == DW_TAG_GNU_BINCL)
9924 unit = push_new_compile_unit (unit, c);
9925 else if (c->die_tag == DW_TAG_GNU_EINCL)
9926 unit = pop_compile_unit (unit);
9928 add_child_die (unit, c);
9930 if (c == die->die_child)
9933 } while (c != die->die_child);
9936 /* We can only use this in debugging, since the frontend doesn't check
9937 to make sure that we leave every include file we enter. */
9941 assign_symbol_names (die);
9942 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9943 for (node = limbo_die_list, pnode = &limbo_die_list;
9949 compute_section_prefix (node->die);
9950 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9951 &comdat_symbol_number);
9952 assign_symbol_names (node->die);
9954 *pnode = node->next;
9957 pnode = &node->next;
9958 record_comdat_symbol_number (node->die, cu_hash_table,
9959 comdat_symbol_number);
9962 htab_delete (cu_hash_table);
9965 /* Return non-zero if this DIE is a declaration. */
9968 is_declaration_die (dw_die_ref die)
9973 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9974 if (a->dw_attr == DW_AT_declaration)
9980 /* Return non-zero if this DIE is nested inside a subprogram. */
9983 is_nested_in_subprogram (dw_die_ref die)
9985 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
9989 return local_scope_p (decl);
9992 /* Return non-zero if this is a type DIE that should be moved to a
9993 COMDAT .debug_types section. */
9996 should_move_die_to_comdat (dw_die_ref die)
9998 switch (die->die_tag)
10000 case DW_TAG_class_type:
10001 case DW_TAG_structure_type:
10002 case DW_TAG_enumeration_type:
10003 case DW_TAG_union_type:
10004 /* Don't move declarations, inlined instances, or types nested in a
10006 if (is_declaration_die (die)
10007 || get_AT (die, DW_AT_abstract_origin)
10008 || is_nested_in_subprogram (die))
10011 case DW_TAG_array_type:
10012 case DW_TAG_interface_type:
10013 case DW_TAG_pointer_type:
10014 case DW_TAG_reference_type:
10015 case DW_TAG_rvalue_reference_type:
10016 case DW_TAG_string_type:
10017 case DW_TAG_subroutine_type:
10018 case DW_TAG_ptr_to_member_type:
10019 case DW_TAG_set_type:
10020 case DW_TAG_subrange_type:
10021 case DW_TAG_base_type:
10022 case DW_TAG_const_type:
10023 case DW_TAG_file_type:
10024 case DW_TAG_packed_type:
10025 case DW_TAG_volatile_type:
10026 case DW_TAG_typedef:
10032 /* Make a clone of DIE. */
10035 clone_die (dw_die_ref die)
10041 clone = ggc_alloc_cleared_die_node ();
10042 clone->die_tag = die->die_tag;
10044 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10045 add_dwarf_attr (clone, a);
10050 /* Make a clone of the tree rooted at DIE. */
10053 clone_tree (dw_die_ref die)
10056 dw_die_ref clone = clone_die (die);
10058 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10063 /* Make a clone of DIE as a declaration. */
10066 clone_as_declaration (dw_die_ref die)
10073 /* If the DIE is already a declaration, just clone it. */
10074 if (is_declaration_die (die))
10075 return clone_die (die);
10077 /* If the DIE is a specification, just clone its declaration DIE. */
10078 decl = get_AT_ref (die, DW_AT_specification);
10080 return clone_die (decl);
10082 clone = ggc_alloc_cleared_die_node ();
10083 clone->die_tag = die->die_tag;
10085 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10087 /* We don't want to copy over all attributes.
10088 For example we don't want DW_AT_byte_size because otherwise we will no
10089 longer have a declaration and GDB will treat it as a definition. */
10091 switch (a->dw_attr)
10093 case DW_AT_artificial:
10094 case DW_AT_containing_type:
10095 case DW_AT_external:
10098 case DW_AT_virtuality:
10099 case DW_AT_linkage_name:
10100 case DW_AT_MIPS_linkage_name:
10101 add_dwarf_attr (clone, a);
10103 case DW_AT_byte_size:
10109 if (die->die_id.die_type_node)
10110 add_AT_die_ref (clone, DW_AT_signature, die);
10112 add_AT_flag (clone, DW_AT_declaration, 1);
10116 /* Copy the declaration context to the new compile unit DIE. This includes
10117 any surrounding namespace or type declarations. If the DIE has an
10118 AT_specification attribute, it also includes attributes and children
10119 attached to the specification. */
10122 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10125 dw_die_ref new_decl;
10127 decl = get_AT_ref (die, DW_AT_specification);
10136 /* Copy the type node pointer from the new DIE to the original
10137 declaration DIE so we can forward references later. */
10138 decl->die_id.die_type_node = die->die_id.die_type_node;
10140 remove_AT (die, DW_AT_specification);
10142 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10144 if (a->dw_attr != DW_AT_name
10145 && a->dw_attr != DW_AT_declaration
10146 && a->dw_attr != DW_AT_external)
10147 add_dwarf_attr (die, a);
10150 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10153 if (decl->die_parent != NULL
10154 && decl->die_parent->die_tag != DW_TAG_compile_unit
10155 && decl->die_parent->die_tag != DW_TAG_type_unit)
10157 new_decl = copy_ancestor_tree (unit, decl, NULL);
10158 if (new_decl != NULL)
10160 remove_AT (new_decl, DW_AT_signature);
10161 add_AT_specification (die, new_decl);
10166 /* Generate the skeleton ancestor tree for the given NODE, then clone
10167 the DIE and add the clone into the tree. */
10170 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10172 if (node->new_die != NULL)
10175 node->new_die = clone_as_declaration (node->old_die);
10177 if (node->parent != NULL)
10179 generate_skeleton_ancestor_tree (node->parent);
10180 add_child_die (node->parent->new_die, node->new_die);
10184 /* Generate a skeleton tree of DIEs containing any declarations that are
10185 found in the original tree. We traverse the tree looking for declaration
10186 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10189 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10191 skeleton_chain_node node;
10194 dw_die_ref prev = NULL;
10195 dw_die_ref next = NULL;
10197 node.parent = parent;
10199 first = c = parent->old_die->die_child;
10203 if (prev == NULL || prev->die_sib == c)
10206 next = (c == first ? NULL : c->die_sib);
10208 node.new_die = NULL;
10209 if (is_declaration_die (c))
10211 /* Clone the existing DIE, move the original to the skeleton
10212 tree (which is in the main CU), and put the clone, with
10213 all the original's children, where the original came from. */
10214 dw_die_ref clone = clone_die (c);
10215 move_all_children (c, clone);
10217 replace_child (c, clone, prev);
10218 generate_skeleton_ancestor_tree (parent);
10219 add_child_die (parent->new_die, c);
10223 generate_skeleton_bottom_up (&node);
10224 } while (next != NULL);
10227 /* Wrapper function for generate_skeleton_bottom_up. */
10230 generate_skeleton (dw_die_ref die)
10232 skeleton_chain_node node;
10234 node.old_die = die;
10235 node.new_die = NULL;
10236 node.parent = NULL;
10238 /* If this type definition is nested inside another type,
10239 always leave at least a declaration in its place. */
10240 if (die->die_parent != NULL && is_type_die (die->die_parent))
10241 node.new_die = clone_as_declaration (die);
10243 generate_skeleton_bottom_up (&node);
10244 return node.new_die;
10247 /* Remove the DIE from its parent, possibly replacing it with a cloned
10248 declaration. The original DIE will be moved to a new compile unit
10249 so that existing references to it follow it to the new location. If
10250 any of the original DIE's descendants is a declaration, we need to
10251 replace the original DIE with a skeleton tree and move the
10252 declarations back into the skeleton tree. */
10255 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10257 dw_die_ref skeleton;
10259 skeleton = generate_skeleton (child);
10260 if (skeleton == NULL)
10261 remove_child_with_prev (child, prev);
10264 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10265 replace_child (child, skeleton, prev);
10271 /* Traverse the DIE and set up additional .debug_types sections for each
10272 type worthy of being placed in a COMDAT section. */
10275 break_out_comdat_types (dw_die_ref die)
10279 dw_die_ref prev = NULL;
10280 dw_die_ref next = NULL;
10281 dw_die_ref unit = NULL;
10283 first = c = die->die_child;
10287 if (prev == NULL || prev->die_sib == c)
10290 next = (c == first ? NULL : c->die_sib);
10291 if (should_move_die_to_comdat (c))
10293 dw_die_ref replacement;
10294 comdat_type_node_ref type_node;
10296 /* Create a new type unit DIE as the root for the new tree, and
10297 add it to the list of comdat types. */
10298 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10299 add_AT_unsigned (unit, DW_AT_language,
10300 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10301 type_node = ggc_alloc_cleared_comdat_type_node ();
10302 type_node->root_die = unit;
10303 type_node->next = comdat_type_list;
10304 comdat_type_list = type_node;
10306 /* Generate the type signature. */
10307 generate_type_signature (c, type_node);
10309 /* Copy the declaration context, attributes, and children of the
10310 declaration into the new compile unit DIE. */
10311 copy_declaration_context (unit, c);
10313 /* Remove this DIE from the main CU. */
10314 replacement = remove_child_or_replace_with_skeleton (c, prev);
10316 /* Break out nested types into their own type units. */
10317 break_out_comdat_types (c);
10319 /* Add the DIE to the new compunit. */
10320 add_child_die (unit, c);
10322 if (replacement != NULL)
10325 else if (c->die_tag == DW_TAG_namespace
10326 || c->die_tag == DW_TAG_class_type
10327 || c->die_tag == DW_TAG_structure_type
10328 || c->die_tag == DW_TAG_union_type)
10330 /* Look for nested types that can be broken out. */
10331 break_out_comdat_types (c);
10333 } while (next != NULL);
10336 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10338 struct decl_table_entry
10344 /* Routines to manipulate hash table of copied declarations. */
10347 htab_decl_hash (const void *of)
10349 const struct decl_table_entry *const entry =
10350 (const struct decl_table_entry *) of;
10352 return htab_hash_pointer (entry->orig);
10356 htab_decl_eq (const void *of1, const void *of2)
10358 const struct decl_table_entry *const entry1 =
10359 (const struct decl_table_entry *) of1;
10360 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10362 return entry1->orig == entry2;
10366 htab_decl_del (void *what)
10368 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10373 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10374 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10375 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10376 to check if the ancestor has already been copied into UNIT. */
10379 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10381 dw_die_ref parent = die->die_parent;
10382 dw_die_ref new_parent = unit;
10384 void **slot = NULL;
10385 struct decl_table_entry *entry = NULL;
10389 /* Check if the entry has already been copied to UNIT. */
10390 slot = htab_find_slot_with_hash (decl_table, die,
10391 htab_hash_pointer (die), INSERT);
10392 if (*slot != HTAB_EMPTY_ENTRY)
10394 entry = (struct decl_table_entry *) *slot;
10395 return entry->copy;
10398 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10399 entry = XCNEW (struct decl_table_entry);
10401 entry->copy = NULL;
10405 if (parent != NULL)
10407 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10410 if (parent->die_tag != DW_TAG_compile_unit
10411 && parent->die_tag != DW_TAG_type_unit)
10412 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10415 copy = clone_as_declaration (die);
10416 add_child_die (new_parent, copy);
10418 if (decl_table != NULL)
10420 /* Record the pointer to the copy. */
10421 entry->copy = copy;
10427 /* Walk the DIE and its children, looking for references to incomplete
10428 or trivial types that are unmarked (i.e., that are not in the current
10432 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10438 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10440 if (AT_class (a) == dw_val_class_die_ref)
10442 dw_die_ref targ = AT_ref (a);
10443 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10445 struct decl_table_entry *entry;
10447 if (targ->die_mark != 0 || type_node != NULL)
10450 slot = htab_find_slot_with_hash (decl_table, targ,
10451 htab_hash_pointer (targ), INSERT);
10453 if (*slot != HTAB_EMPTY_ENTRY)
10455 /* TARG has already been copied, so we just need to
10456 modify the reference to point to the copy. */
10457 entry = (struct decl_table_entry *) *slot;
10458 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10462 dw_die_ref parent = unit;
10463 dw_die_ref copy = clone_tree (targ);
10465 /* Make sure the cloned tree is marked as part of the
10469 /* Record in DECL_TABLE that TARG has been copied.
10470 Need to do this now, before the recursive call,
10471 because DECL_TABLE may be expanded and SLOT
10472 would no longer be a valid pointer. */
10473 entry = XCNEW (struct decl_table_entry);
10474 entry->orig = targ;
10475 entry->copy = copy;
10478 /* If TARG has surrounding context, copy its ancestor tree
10479 into the new type unit. */
10480 if (targ->die_parent != NULL
10481 && targ->die_parent->die_tag != DW_TAG_compile_unit
10482 && targ->die_parent->die_tag != DW_TAG_type_unit)
10483 parent = copy_ancestor_tree (unit, targ->die_parent,
10486 add_child_die (parent, copy);
10487 a->dw_attr_val.v.val_die_ref.die = copy;
10489 /* Make sure the newly-copied DIE is walked. If it was
10490 installed in a previously-added context, it won't
10491 get visited otherwise. */
10492 if (parent != unit)
10494 /* Find the highest point of the newly-added tree,
10495 mark each node along the way, and walk from there. */
10496 parent->die_mark = 1;
10497 while (parent->die_parent
10498 && parent->die_parent->die_mark == 0)
10500 parent = parent->die_parent;
10501 parent->die_mark = 1;
10503 copy_decls_walk (unit, parent, decl_table);
10509 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10512 /* Copy declarations for "unworthy" types into the new comdat section.
10513 Incomplete types, modified types, and certain other types aren't broken
10514 out into comdat sections of their own, so they don't have a signature,
10515 and we need to copy the declaration into the same section so that we
10516 don't have an external reference. */
10519 copy_decls_for_unworthy_types (dw_die_ref unit)
10524 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10525 copy_decls_walk (unit, unit, decl_table);
10526 htab_delete (decl_table);
10527 unmark_dies (unit);
10530 /* Traverse the DIE and add a sibling attribute if it may have the
10531 effect of speeding up access to siblings. To save some space,
10532 avoid generating sibling attributes for DIE's without children. */
10535 add_sibling_attributes (dw_die_ref die)
10539 if (! die->die_child)
10542 if (die->die_parent && die != die->die_parent->die_child)
10543 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10545 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10548 /* Output all location lists for the DIE and its children. */
10551 output_location_lists (dw_die_ref die)
10557 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10558 if (AT_class (a) == dw_val_class_loc_list)
10559 output_loc_list (AT_loc_list (a));
10561 FOR_EACH_CHILD (die, c, output_location_lists (c));
10564 /* The format of each DIE (and its attribute value pairs) is encoded in an
10565 abbreviation table. This routine builds the abbreviation table and assigns
10566 a unique abbreviation id for each abbreviation entry. The children of each
10567 die are visited recursively. */
10570 build_abbrev_table (dw_die_ref die)
10572 unsigned long abbrev_id;
10573 unsigned int n_alloc;
10578 /* Scan the DIE references, and mark as external any that refer to
10579 DIEs from other CUs (i.e. those which are not marked). */
10580 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10581 if (AT_class (a) == dw_val_class_die_ref
10582 && AT_ref (a)->die_mark == 0)
10584 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10585 set_AT_ref_external (a, 1);
10588 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10590 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10591 dw_attr_ref die_a, abbrev_a;
10595 if (abbrev->die_tag != die->die_tag)
10597 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10600 if (VEC_length (dw_attr_node, abbrev->die_attr)
10601 != VEC_length (dw_attr_node, die->die_attr))
10604 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10606 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10607 if ((abbrev_a->dw_attr != die_a->dw_attr)
10608 || (value_format (abbrev_a) != value_format (die_a)))
10618 if (abbrev_id >= abbrev_die_table_in_use)
10620 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10622 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10623 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10626 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10627 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10628 abbrev_die_table_allocated = n_alloc;
10631 ++abbrev_die_table_in_use;
10632 abbrev_die_table[abbrev_id] = die;
10635 die->die_abbrev = abbrev_id;
10636 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10639 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10642 constant_size (unsigned HOST_WIDE_INT value)
10649 log = floor_log2 (value);
10652 log = 1 << (floor_log2 (log) + 1);
10657 /* Return the size of a DIE as it is represented in the
10658 .debug_info section. */
10660 static unsigned long
10661 size_of_die (dw_die_ref die)
10663 unsigned long size = 0;
10667 size += size_of_uleb128 (die->die_abbrev);
10668 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10670 switch (AT_class (a))
10672 case dw_val_class_addr:
10673 size += DWARF2_ADDR_SIZE;
10675 case dw_val_class_offset:
10676 size += DWARF_OFFSET_SIZE;
10678 case dw_val_class_loc:
10680 unsigned long lsize = size_of_locs (AT_loc (a));
10682 /* Block length. */
10683 if (dwarf_version >= 4)
10684 size += size_of_uleb128 (lsize);
10686 size += constant_size (lsize);
10690 case dw_val_class_loc_list:
10691 size += DWARF_OFFSET_SIZE;
10693 case dw_val_class_range_list:
10694 size += DWARF_OFFSET_SIZE;
10696 case dw_val_class_const:
10697 size += size_of_sleb128 (AT_int (a));
10699 case dw_val_class_unsigned_const:
10700 size += constant_size (AT_unsigned (a));
10702 case dw_val_class_const_double:
10703 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10704 if (HOST_BITS_PER_WIDE_INT >= 64)
10705 size++; /* block */
10707 case dw_val_class_vec:
10708 size += constant_size (a->dw_attr_val.v.val_vec.length
10709 * a->dw_attr_val.v.val_vec.elt_size)
10710 + a->dw_attr_val.v.val_vec.length
10711 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10713 case dw_val_class_flag:
10714 if (dwarf_version >= 4)
10715 /* Currently all add_AT_flag calls pass in 1 as last argument,
10716 so DW_FORM_flag_present can be used. If that ever changes,
10717 we'll need to use DW_FORM_flag and have some optimization
10718 in build_abbrev_table that will change those to
10719 DW_FORM_flag_present if it is set to 1 in all DIEs using
10720 the same abbrev entry. */
10721 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10725 case dw_val_class_die_ref:
10726 if (AT_ref_external (a))
10728 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10729 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10730 is sized by target address length, whereas in DWARF3
10731 it's always sized as an offset. */
10732 if (dwarf_version >= 4)
10733 size += DWARF_TYPE_SIGNATURE_SIZE;
10734 else if (dwarf_version == 2)
10735 size += DWARF2_ADDR_SIZE;
10737 size += DWARF_OFFSET_SIZE;
10740 size += DWARF_OFFSET_SIZE;
10742 case dw_val_class_fde_ref:
10743 size += DWARF_OFFSET_SIZE;
10745 case dw_val_class_lbl_id:
10746 size += DWARF2_ADDR_SIZE;
10748 case dw_val_class_lineptr:
10749 case dw_val_class_macptr:
10750 size += DWARF_OFFSET_SIZE;
10752 case dw_val_class_str:
10753 if (AT_string_form (a) == DW_FORM_strp)
10754 size += DWARF_OFFSET_SIZE;
10756 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10758 case dw_val_class_file:
10759 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10761 case dw_val_class_data8:
10764 case dw_val_class_vms_delta:
10765 size += DWARF_OFFSET_SIZE;
10768 gcc_unreachable ();
10775 /* Size the debugging information associated with a given DIE. Visits the
10776 DIE's children recursively. Updates the global variable next_die_offset, on
10777 each time through. Uses the current value of next_die_offset to update the
10778 die_offset field in each DIE. */
10781 calc_die_sizes (dw_die_ref die)
10785 die->die_offset = next_die_offset;
10786 next_die_offset += size_of_die (die);
10788 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10790 if (die->die_child != NULL)
10791 /* Count the null byte used to terminate sibling lists. */
10792 next_die_offset += 1;
10795 /* Set the marks for a die and its children. We do this so
10796 that we know whether or not a reference needs to use FORM_ref_addr; only
10797 DIEs in the same CU will be marked. We used to clear out the offset
10798 and use that as the flag, but ran into ordering problems. */
10801 mark_dies (dw_die_ref die)
10805 gcc_assert (!die->die_mark);
10808 FOR_EACH_CHILD (die, c, mark_dies (c));
10811 /* Clear the marks for a die and its children. */
10814 unmark_dies (dw_die_ref die)
10818 if (dwarf_version < 4)
10819 gcc_assert (die->die_mark);
10822 FOR_EACH_CHILD (die, c, unmark_dies (c));
10825 /* Clear the marks for a die, its children and referred dies. */
10828 unmark_all_dies (dw_die_ref die)
10834 if (!die->die_mark)
10838 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10840 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10841 if (AT_class (a) == dw_val_class_die_ref)
10842 unmark_all_dies (AT_ref (a));
10845 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10846 generated for the compilation unit. */
10848 static unsigned long
10849 size_of_pubnames (VEC (pubname_entry, gc) * names)
10851 unsigned long size;
10855 size = DWARF_PUBNAMES_HEADER_SIZE;
10856 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10857 if (names != pubtype_table
10858 || p->die->die_offset != 0
10859 || !flag_eliminate_unused_debug_types)
10860 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10862 size += DWARF_OFFSET_SIZE;
10866 /* Return the size of the information in the .debug_aranges section. */
10868 static unsigned long
10869 size_of_aranges (void)
10871 unsigned long size;
10873 size = DWARF_ARANGES_HEADER_SIZE;
10875 /* Count the address/length pair for this compilation unit. */
10876 if (text_section_used)
10877 size += 2 * DWARF2_ADDR_SIZE;
10878 if (cold_text_section_used)
10879 size += 2 * DWARF2_ADDR_SIZE;
10880 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
10882 /* Count the two zero words used to terminated the address range table. */
10883 size += 2 * DWARF2_ADDR_SIZE;
10887 /* Select the encoding of an attribute value. */
10889 static enum dwarf_form
10890 value_format (dw_attr_ref a)
10892 switch (a->dw_attr_val.val_class)
10894 case dw_val_class_addr:
10895 /* Only very few attributes allow DW_FORM_addr. */
10896 switch (a->dw_attr)
10899 case DW_AT_high_pc:
10900 case DW_AT_entry_pc:
10901 case DW_AT_trampoline:
10902 return DW_FORM_addr;
10906 switch (DWARF2_ADDR_SIZE)
10909 return DW_FORM_data1;
10911 return DW_FORM_data2;
10913 return DW_FORM_data4;
10915 return DW_FORM_data8;
10917 gcc_unreachable ();
10919 case dw_val_class_range_list:
10920 case dw_val_class_loc_list:
10921 if (dwarf_version >= 4)
10922 return DW_FORM_sec_offset;
10924 case dw_val_class_vms_delta:
10925 case dw_val_class_offset:
10926 switch (DWARF_OFFSET_SIZE)
10929 return DW_FORM_data4;
10931 return DW_FORM_data8;
10933 gcc_unreachable ();
10935 case dw_val_class_loc:
10936 if (dwarf_version >= 4)
10937 return DW_FORM_exprloc;
10938 switch (constant_size (size_of_locs (AT_loc (a))))
10941 return DW_FORM_block1;
10943 return DW_FORM_block2;
10945 gcc_unreachable ();
10947 case dw_val_class_const:
10948 return DW_FORM_sdata;
10949 case dw_val_class_unsigned_const:
10950 switch (constant_size (AT_unsigned (a)))
10953 return DW_FORM_data1;
10955 return DW_FORM_data2;
10957 return DW_FORM_data4;
10959 return DW_FORM_data8;
10961 gcc_unreachable ();
10963 case dw_val_class_const_double:
10964 switch (HOST_BITS_PER_WIDE_INT)
10967 return DW_FORM_data2;
10969 return DW_FORM_data4;
10971 return DW_FORM_data8;
10974 return DW_FORM_block1;
10976 case dw_val_class_vec:
10977 switch (constant_size (a->dw_attr_val.v.val_vec.length
10978 * a->dw_attr_val.v.val_vec.elt_size))
10981 return DW_FORM_block1;
10983 return DW_FORM_block2;
10985 return DW_FORM_block4;
10987 gcc_unreachable ();
10989 case dw_val_class_flag:
10990 if (dwarf_version >= 4)
10992 /* Currently all add_AT_flag calls pass in 1 as last argument,
10993 so DW_FORM_flag_present can be used. If that ever changes,
10994 we'll need to use DW_FORM_flag and have some optimization
10995 in build_abbrev_table that will change those to
10996 DW_FORM_flag_present if it is set to 1 in all DIEs using
10997 the same abbrev entry. */
10998 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10999 return DW_FORM_flag_present;
11001 return DW_FORM_flag;
11002 case dw_val_class_die_ref:
11003 if (AT_ref_external (a))
11004 return dwarf_version >= 4 ? DW_FORM_sig8 : DW_FORM_ref_addr;
11006 return DW_FORM_ref;
11007 case dw_val_class_fde_ref:
11008 return DW_FORM_data;
11009 case dw_val_class_lbl_id:
11010 return DW_FORM_addr;
11011 case dw_val_class_lineptr:
11012 case dw_val_class_macptr:
11013 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11014 case dw_val_class_str:
11015 return AT_string_form (a);
11016 case dw_val_class_file:
11017 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11020 return DW_FORM_data1;
11022 return DW_FORM_data2;
11024 return DW_FORM_data4;
11026 gcc_unreachable ();
11029 case dw_val_class_data8:
11030 return DW_FORM_data8;
11033 gcc_unreachable ();
11037 /* Output the encoding of an attribute value. */
11040 output_value_format (dw_attr_ref a)
11042 enum dwarf_form form = value_format (a);
11044 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11047 /* Output the .debug_abbrev section which defines the DIE abbreviation
11051 output_abbrev_section (void)
11053 unsigned long abbrev_id;
11055 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11057 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11059 dw_attr_ref a_attr;
11061 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11062 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11063 dwarf_tag_name (abbrev->die_tag));
11065 if (abbrev->die_child != NULL)
11066 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11068 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11070 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11073 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11074 dwarf_attr_name (a_attr->dw_attr));
11075 output_value_format (a_attr);
11078 dw2_asm_output_data (1, 0, NULL);
11079 dw2_asm_output_data (1, 0, NULL);
11082 /* Terminate the table. */
11083 dw2_asm_output_data (1, 0, NULL);
11086 /* Output a symbol we can use to refer to this DIE from another CU. */
11089 output_die_symbol (dw_die_ref die)
11091 char *sym = die->die_id.die_symbol;
11096 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11097 /* We make these global, not weak; if the target doesn't support
11098 .linkonce, it doesn't support combining the sections, so debugging
11100 targetm.asm_out.globalize_label (asm_out_file, sym);
11102 ASM_OUTPUT_LABEL (asm_out_file, sym);
11105 /* Return a new location list, given the begin and end range, and the
11108 static inline dw_loc_list_ref
11109 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11110 const char *section)
11112 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11114 retlist->begin = begin;
11115 retlist->end = end;
11116 retlist->expr = expr;
11117 retlist->section = section;
11122 /* Generate a new internal symbol for this location list node, if it
11123 hasn't got one yet. */
11126 gen_llsym (dw_loc_list_ref list)
11128 gcc_assert (!list->ll_symbol);
11129 list->ll_symbol = gen_internal_sym ("LLST");
11132 /* Output the location list given to us. */
11135 output_loc_list (dw_loc_list_ref list_head)
11137 dw_loc_list_ref curr = list_head;
11139 if (list_head->emitted)
11141 list_head->emitted = true;
11143 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11145 /* Walk the location list, and output each range + expression. */
11146 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11148 unsigned long size;
11149 /* Don't output an entry that starts and ends at the same address. */
11150 if (strcmp (curr->begin, curr->end) == 0)
11152 if (!have_multiple_function_sections)
11154 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11155 "Location list begin address (%s)",
11156 list_head->ll_symbol);
11157 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11158 "Location list end address (%s)",
11159 list_head->ll_symbol);
11163 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11164 "Location list begin address (%s)",
11165 list_head->ll_symbol);
11166 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11167 "Location list end address (%s)",
11168 list_head->ll_symbol);
11170 size = size_of_locs (curr->expr);
11172 /* Output the block length for this list of location operations. */
11173 gcc_assert (size <= 0xffff);
11174 dw2_asm_output_data (2, size, "%s", "Location expression size");
11176 output_loc_sequence (curr->expr, -1);
11179 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11180 "Location list terminator begin (%s)",
11181 list_head->ll_symbol);
11182 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11183 "Location list terminator end (%s)",
11184 list_head->ll_symbol);
11187 /* Output a type signature. */
11190 output_signature (const char *sig, const char *name)
11194 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11195 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11198 /* Output the DIE and its attributes. Called recursively to generate
11199 the definitions of each child DIE. */
11202 output_die (dw_die_ref die)
11206 unsigned long size;
11209 /* If someone in another CU might refer to us, set up a symbol for
11210 them to point to. */
11211 if (dwarf_version < 4 && die->die_id.die_symbol)
11212 output_die_symbol (die);
11214 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11215 (unsigned long)die->die_offset,
11216 dwarf_tag_name (die->die_tag));
11218 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11220 const char *name = dwarf_attr_name (a->dw_attr);
11222 switch (AT_class (a))
11224 case dw_val_class_addr:
11225 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11228 case dw_val_class_offset:
11229 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11233 case dw_val_class_range_list:
11235 char *p = strchr (ranges_section_label, '\0');
11237 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11238 a->dw_attr_val.v.val_offset);
11239 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11240 debug_ranges_section, "%s", name);
11245 case dw_val_class_loc:
11246 size = size_of_locs (AT_loc (a));
11248 /* Output the block length for this list of location operations. */
11249 if (dwarf_version >= 4)
11250 dw2_asm_output_data_uleb128 (size, "%s", name);
11252 dw2_asm_output_data (constant_size (size), size, "%s", name);
11254 output_loc_sequence (AT_loc (a), -1);
11257 case dw_val_class_const:
11258 /* ??? It would be slightly more efficient to use a scheme like is
11259 used for unsigned constants below, but gdb 4.x does not sign
11260 extend. Gdb 5.x does sign extend. */
11261 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11264 case dw_val_class_unsigned_const:
11265 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11266 AT_unsigned (a), "%s", name);
11269 case dw_val_class_const_double:
11271 unsigned HOST_WIDE_INT first, second;
11273 if (HOST_BITS_PER_WIDE_INT >= 64)
11274 dw2_asm_output_data (1,
11275 2 * HOST_BITS_PER_WIDE_INT
11276 / HOST_BITS_PER_CHAR,
11279 if (WORDS_BIG_ENDIAN)
11281 first = a->dw_attr_val.v.val_double.high;
11282 second = a->dw_attr_val.v.val_double.low;
11286 first = a->dw_attr_val.v.val_double.low;
11287 second = a->dw_attr_val.v.val_double.high;
11290 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11292 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11297 case dw_val_class_vec:
11299 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11300 unsigned int len = a->dw_attr_val.v.val_vec.length;
11304 dw2_asm_output_data (constant_size (len * elt_size),
11305 len * elt_size, "%s", name);
11306 if (elt_size > sizeof (HOST_WIDE_INT))
11311 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11313 i++, p += elt_size)
11314 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11315 "fp or vector constant word %u", i);
11319 case dw_val_class_flag:
11320 if (dwarf_version >= 4)
11322 /* Currently all add_AT_flag calls pass in 1 as last argument,
11323 so DW_FORM_flag_present can be used. If that ever changes,
11324 we'll need to use DW_FORM_flag and have some optimization
11325 in build_abbrev_table that will change those to
11326 DW_FORM_flag_present if it is set to 1 in all DIEs using
11327 the same abbrev entry. */
11328 gcc_assert (AT_flag (a) == 1);
11329 if (flag_debug_asm)
11330 fprintf (asm_out_file, "\t\t\t%s %s\n",
11331 ASM_COMMENT_START, name);
11334 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11337 case dw_val_class_loc_list:
11339 char *sym = AT_loc_list (a)->ll_symbol;
11342 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11347 case dw_val_class_die_ref:
11348 if (AT_ref_external (a))
11350 if (dwarf_version >= 4)
11352 comdat_type_node_ref type_node =
11353 AT_ref (a)->die_id.die_type_node;
11355 gcc_assert (type_node);
11356 output_signature (type_node->signature, name);
11360 char *sym = AT_ref (a)->die_id.die_symbol;
11364 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11365 length, whereas in DWARF3 it's always sized as an
11367 if (dwarf_version == 2)
11368 size = DWARF2_ADDR_SIZE;
11370 size = DWARF_OFFSET_SIZE;
11371 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11377 gcc_assert (AT_ref (a)->die_offset);
11378 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11383 case dw_val_class_fde_ref:
11387 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11388 a->dw_attr_val.v.val_fde_index * 2);
11389 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11394 case dw_val_class_vms_delta:
11395 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11396 AT_vms_delta2 (a), AT_vms_delta1 (a),
11400 case dw_val_class_lbl_id:
11401 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11404 case dw_val_class_lineptr:
11405 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11406 debug_line_section, "%s", name);
11409 case dw_val_class_macptr:
11410 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11411 debug_macinfo_section, "%s", name);
11414 case dw_val_class_str:
11415 if (AT_string_form (a) == DW_FORM_strp)
11416 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11417 a->dw_attr_val.v.val_str->label,
11419 "%s: \"%s\"", name, AT_string (a));
11421 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11424 case dw_val_class_file:
11426 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11428 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11429 a->dw_attr_val.v.val_file->filename);
11433 case dw_val_class_data8:
11437 for (i = 0; i < 8; i++)
11438 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11439 i == 0 ? "%s" : NULL, name);
11444 gcc_unreachable ();
11448 FOR_EACH_CHILD (die, c, output_die (c));
11450 /* Add null byte to terminate sibling list. */
11451 if (die->die_child != NULL)
11452 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11453 (unsigned long) die->die_offset);
11456 /* Output the compilation unit that appears at the beginning of the
11457 .debug_info section, and precedes the DIE descriptions. */
11460 output_compilation_unit_header (void)
11462 int ver = dwarf_version;
11464 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11465 dw2_asm_output_data (4, 0xffffffff,
11466 "Initial length escape value indicating 64-bit DWARF extension");
11467 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11468 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11469 "Length of Compilation Unit Info");
11470 dw2_asm_output_data (2, ver, "DWARF version number");
11471 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11472 debug_abbrev_section,
11473 "Offset Into Abbrev. Section");
11474 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11477 /* Output the compilation unit DIE and its children. */
11480 output_comp_unit (dw_die_ref die, int output_if_empty)
11482 const char *secname;
11483 char *oldsym, *tmp;
11485 /* Unless we are outputting main CU, we may throw away empty ones. */
11486 if (!output_if_empty && die->die_child == NULL)
11489 /* Even if there are no children of this DIE, we must output the information
11490 about the compilation unit. Otherwise, on an empty translation unit, we
11491 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11492 will then complain when examining the file. First mark all the DIEs in
11493 this CU so we know which get local refs. */
11496 build_abbrev_table (die);
11498 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11499 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11500 calc_die_sizes (die);
11502 oldsym = die->die_id.die_symbol;
11505 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11507 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11509 die->die_id.die_symbol = NULL;
11510 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11514 switch_to_section (debug_info_section);
11515 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11516 info_section_emitted = true;
11519 /* Output debugging information. */
11520 output_compilation_unit_header ();
11523 /* Leave the marks on the main CU, so we can check them in
11524 output_pubnames. */
11528 die->die_id.die_symbol = oldsym;
11532 /* Output a comdat type unit DIE and its children. */
11535 output_comdat_type_unit (comdat_type_node *node)
11537 const char *secname;
11540 #if defined (OBJECT_FORMAT_ELF)
11544 /* First mark all the DIEs in this CU so we know which get local refs. */
11545 mark_dies (node->root_die);
11547 build_abbrev_table (node->root_die);
11549 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11550 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11551 calc_die_sizes (node->root_die);
11553 #if defined (OBJECT_FORMAT_ELF)
11554 secname = ".debug_types";
11555 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11556 sprintf (tmp, "wt.");
11557 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11558 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11559 comdat_key = get_identifier (tmp);
11560 targetm.asm_out.named_section (secname,
11561 SECTION_DEBUG | SECTION_LINKONCE,
11564 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11565 sprintf (tmp, ".gnu.linkonce.wt.");
11566 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11567 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11569 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11572 /* Output debugging information. */
11573 output_compilation_unit_header ();
11574 output_signature (node->signature, "Type Signature");
11575 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11576 "Offset to Type DIE");
11577 output_die (node->root_die);
11579 unmark_dies (node->root_die);
11582 /* Return the DWARF2/3 pubname associated with a decl. */
11584 static const char *
11585 dwarf2_name (tree decl, int scope)
11587 if (DECL_NAMELESS (decl))
11589 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11592 /* Add a new entry to .debug_pubnames if appropriate. */
11595 add_pubname_string (const char *str, dw_die_ref die)
11597 if (targetm.want_debug_pub_sections)
11602 e.name = xstrdup (str);
11603 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11608 add_pubname (tree decl, dw_die_ref die)
11610 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11612 const char *name = dwarf2_name (decl, 1);
11614 add_pubname_string (name, die);
11618 /* Add a new entry to .debug_pubtypes if appropriate. */
11621 add_pubtype (tree decl, dw_die_ref die)
11625 if (!targetm.want_debug_pub_sections)
11629 if ((TREE_PUBLIC (decl)
11630 || is_cu_die (die->die_parent))
11631 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11636 if (TYPE_NAME (decl))
11638 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11639 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11640 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11641 && DECL_NAME (TYPE_NAME (decl)))
11642 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11644 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11649 e.name = dwarf2_name (decl, 1);
11651 e.name = xstrdup (e.name);
11654 /* If we don't have a name for the type, there's no point in adding
11655 it to the table. */
11656 if (e.name && e.name[0] != '\0')
11657 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11661 /* Output the public names table used to speed up access to externally
11662 visible names; or the public types table used to find type definitions. */
11665 output_pubnames (VEC (pubname_entry, gc) * names)
11668 unsigned long pubnames_length = size_of_pubnames (names);
11671 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11672 dw2_asm_output_data (4, 0xffffffff,
11673 "Initial length escape value indicating 64-bit DWARF extension");
11674 if (names == pubname_table)
11675 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11676 "Length of Public Names Info");
11678 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11679 "Length of Public Type Names Info");
11680 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11681 dw2_asm_output_data (2, 2, "DWARF Version");
11682 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11683 debug_info_section,
11684 "Offset of Compilation Unit Info");
11685 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11686 "Compilation Unit Length");
11688 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11690 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11691 if (names == pubname_table)
11692 gcc_assert (pub->die->die_mark);
11694 if (names != pubtype_table
11695 || pub->die->die_offset != 0
11696 || !flag_eliminate_unused_debug_types)
11698 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11701 dw2_asm_output_nstring (pub->name, -1, "external name");
11705 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11708 /* Add a new entry to .debug_aranges if appropriate. */
11711 add_arange (tree decl, dw_die_ref die)
11713 if (! DECL_SECTION_NAME (decl))
11716 if (arange_table_in_use == arange_table_allocated)
11718 arange_table_allocated += ARANGE_TABLE_INCREMENT;
11719 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
11720 arange_table_allocated);
11721 memset (arange_table + arange_table_in_use, 0,
11722 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
11725 arange_table[arange_table_in_use++] = die;
11728 /* Output the information that goes into the .debug_aranges table.
11729 Namely, define the beginning and ending address range of the
11730 text section generated for this compilation unit. */
11733 output_aranges (void)
11736 unsigned long aranges_length = size_of_aranges ();
11738 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11739 dw2_asm_output_data (4, 0xffffffff,
11740 "Initial length escape value indicating 64-bit DWARF extension");
11741 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11742 "Length of Address Ranges Info");
11743 /* Version number for aranges is still 2, even in DWARF3. */
11744 dw2_asm_output_data (2, 2, "DWARF Version");
11745 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11746 debug_info_section,
11747 "Offset of Compilation Unit Info");
11748 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11749 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11751 /* We need to align to twice the pointer size here. */
11752 if (DWARF_ARANGES_PAD_SIZE)
11754 /* Pad using a 2 byte words so that padding is correct for any
11756 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11757 2 * DWARF2_ADDR_SIZE);
11758 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11759 dw2_asm_output_data (2, 0, NULL);
11762 /* It is necessary not to output these entries if the sections were
11763 not used; if the sections were not used, the length will be 0 and
11764 the address may end up as 0 if the section is discarded by ld
11765 --gc-sections, leaving an invalid (0, 0) entry that can be
11766 confused with the terminator. */
11767 if (text_section_used)
11769 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11770 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11771 text_section_label, "Length");
11773 if (cold_text_section_used)
11775 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11777 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11778 cold_text_section_label, "Length");
11781 for (i = 0; i < arange_table_in_use; i++)
11783 dw_die_ref die = arange_table[i];
11785 /* We shouldn't see aranges for DIEs outside of the main CU. */
11786 gcc_assert (die->die_mark);
11788 if (die->die_tag == DW_TAG_subprogram)
11790 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
11792 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
11793 get_AT_low_pc (die), "Length");
11797 /* A static variable; extract the symbol from DW_AT_location.
11798 Note that this code isn't currently hit, as we only emit
11799 aranges for functions (jason 9/23/99). */
11800 dw_attr_ref a = get_AT (die, DW_AT_location);
11801 dw_loc_descr_ref loc;
11803 gcc_assert (a && AT_class (a) == dw_val_class_loc);
11806 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
11808 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
11809 loc->dw_loc_oprnd1.v.val_addr, "Address");
11810 dw2_asm_output_data (DWARF2_ADDR_SIZE,
11811 get_AT_unsigned (die, DW_AT_byte_size),
11816 /* Output the terminator words. */
11817 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11818 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11821 /* Add a new entry to .debug_ranges. Return the offset at which it
11824 static unsigned int
11825 add_ranges_num (int num)
11827 unsigned int in_use = ranges_table_in_use;
11829 if (in_use == ranges_table_allocated)
11831 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11832 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11833 ranges_table_allocated);
11834 memset (ranges_table + ranges_table_in_use, 0,
11835 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11838 ranges_table[in_use].num = num;
11839 ranges_table_in_use = in_use + 1;
11841 return in_use * 2 * DWARF2_ADDR_SIZE;
11844 /* Add a new entry to .debug_ranges corresponding to a block, or a
11845 range terminator if BLOCK is NULL. */
11847 static unsigned int
11848 add_ranges (const_tree block)
11850 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11853 /* Add a new entry to .debug_ranges corresponding to a pair of
11857 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11860 unsigned int in_use = ranges_by_label_in_use;
11861 unsigned int offset;
11863 if (in_use == ranges_by_label_allocated)
11865 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11866 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11868 ranges_by_label_allocated);
11869 memset (ranges_by_label + ranges_by_label_in_use, 0,
11870 RANGES_TABLE_INCREMENT
11871 * sizeof (struct dw_ranges_by_label_struct));
11874 ranges_by_label[in_use].begin = begin;
11875 ranges_by_label[in_use].end = end;
11876 ranges_by_label_in_use = in_use + 1;
11878 offset = add_ranges_num (-(int)in_use - 1);
11881 add_AT_range_list (die, DW_AT_ranges, offset);
11887 output_ranges (void)
11890 static const char *const start_fmt = "Offset %#x";
11891 const char *fmt = start_fmt;
11893 for (i = 0; i < ranges_table_in_use; i++)
11895 int block_num = ranges_table[i].num;
11899 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11900 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11902 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11903 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11905 /* If all code is in the text section, then the compilation
11906 unit base address defaults to DW_AT_low_pc, which is the
11907 base of the text section. */
11908 if (!have_multiple_function_sections)
11910 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11911 text_section_label,
11912 fmt, i * 2 * DWARF2_ADDR_SIZE);
11913 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11914 text_section_label, NULL);
11917 /* Otherwise, the compilation unit base address is zero,
11918 which allows us to use absolute addresses, and not worry
11919 about whether the target supports cross-section
11923 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11924 fmt, i * 2 * DWARF2_ADDR_SIZE);
11925 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11931 /* Negative block_num stands for an index into ranges_by_label. */
11932 else if (block_num < 0)
11934 int lab_idx = - block_num - 1;
11936 if (!have_multiple_function_sections)
11938 gcc_unreachable ();
11940 /* If we ever use add_ranges_by_labels () for a single
11941 function section, all we have to do is to take out
11942 the #if 0 above. */
11943 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11944 ranges_by_label[lab_idx].begin,
11945 text_section_label,
11946 fmt, i * 2 * DWARF2_ADDR_SIZE);
11947 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11948 ranges_by_label[lab_idx].end,
11949 text_section_label, NULL);
11954 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11955 ranges_by_label[lab_idx].begin,
11956 fmt, i * 2 * DWARF2_ADDR_SIZE);
11957 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11958 ranges_by_label[lab_idx].end,
11964 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11965 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11971 /* Data structure containing information about input files. */
11974 const char *path; /* Complete file name. */
11975 const char *fname; /* File name part. */
11976 int length; /* Length of entire string. */
11977 struct dwarf_file_data * file_idx; /* Index in input file table. */
11978 int dir_idx; /* Index in directory table. */
11981 /* Data structure containing information about directories with source
11985 const char *path; /* Path including directory name. */
11986 int length; /* Path length. */
11987 int prefix; /* Index of directory entry which is a prefix. */
11988 int count; /* Number of files in this directory. */
11989 int dir_idx; /* Index of directory used as base. */
11992 /* Callback function for file_info comparison. We sort by looking at
11993 the directories in the path. */
11996 file_info_cmp (const void *p1, const void *p2)
11998 const struct file_info *const s1 = (const struct file_info *) p1;
11999 const struct file_info *const s2 = (const struct file_info *) p2;
12000 const unsigned char *cp1;
12001 const unsigned char *cp2;
12003 /* Take care of file names without directories. We need to make sure that
12004 we return consistent values to qsort since some will get confused if
12005 we return the same value when identical operands are passed in opposite
12006 orders. So if neither has a directory, return 0 and otherwise return
12007 1 or -1 depending on which one has the directory. */
12008 if ((s1->path == s1->fname || s2->path == s2->fname))
12009 return (s2->path == s2->fname) - (s1->path == s1->fname);
12011 cp1 = (const unsigned char *) s1->path;
12012 cp2 = (const unsigned char *) s2->path;
12018 /* Reached the end of the first path? If so, handle like above. */
12019 if ((cp1 == (const unsigned char *) s1->fname)
12020 || (cp2 == (const unsigned char *) s2->fname))
12021 return ((cp2 == (const unsigned char *) s2->fname)
12022 - (cp1 == (const unsigned char *) s1->fname));
12024 /* Character of current path component the same? */
12025 else if (*cp1 != *cp2)
12026 return *cp1 - *cp2;
12030 struct file_name_acquire_data
12032 struct file_info *files;
12037 /* Traversal function for the hash table. */
12040 file_name_acquire (void ** slot, void *data)
12042 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12043 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12044 struct file_info *fi;
12047 gcc_assert (fnad->max_files >= d->emitted_number);
12049 if (! d->emitted_number)
12052 gcc_assert (fnad->max_files != fnad->used_files);
12054 fi = fnad->files + fnad->used_files++;
12056 /* Skip all leading "./". */
12058 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12061 /* Create a new array entry. */
12063 fi->length = strlen (f);
12066 /* Search for the file name part. */
12067 f = strrchr (f, DIR_SEPARATOR);
12068 #if defined (DIR_SEPARATOR_2)
12070 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12074 if (f == NULL || f < g)
12080 fi->fname = f == NULL ? fi->path : f + 1;
12084 /* Output the directory table and the file name table. We try to minimize
12085 the total amount of memory needed. A heuristic is used to avoid large
12086 slowdowns with many input files. */
12089 output_file_names (void)
12091 struct file_name_acquire_data fnad;
12093 struct file_info *files;
12094 struct dir_info *dirs;
12102 if (!last_emitted_file)
12104 dw2_asm_output_data (1, 0, "End directory table");
12105 dw2_asm_output_data (1, 0, "End file name table");
12109 numfiles = last_emitted_file->emitted_number;
12111 /* Allocate the various arrays we need. */
12112 files = XALLOCAVEC (struct file_info, numfiles);
12113 dirs = XALLOCAVEC (struct dir_info, numfiles);
12115 fnad.files = files;
12116 fnad.used_files = 0;
12117 fnad.max_files = numfiles;
12118 htab_traverse (file_table, file_name_acquire, &fnad);
12119 gcc_assert (fnad.used_files == fnad.max_files);
12121 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12123 /* Find all the different directories used. */
12124 dirs[0].path = files[0].path;
12125 dirs[0].length = files[0].fname - files[0].path;
12126 dirs[0].prefix = -1;
12128 dirs[0].dir_idx = 0;
12129 files[0].dir_idx = 0;
12132 for (i = 1; i < numfiles; i++)
12133 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12134 && memcmp (dirs[ndirs - 1].path, files[i].path,
12135 dirs[ndirs - 1].length) == 0)
12137 /* Same directory as last entry. */
12138 files[i].dir_idx = ndirs - 1;
12139 ++dirs[ndirs - 1].count;
12145 /* This is a new directory. */
12146 dirs[ndirs].path = files[i].path;
12147 dirs[ndirs].length = files[i].fname - files[i].path;
12148 dirs[ndirs].count = 1;
12149 dirs[ndirs].dir_idx = ndirs;
12150 files[i].dir_idx = ndirs;
12152 /* Search for a prefix. */
12153 dirs[ndirs].prefix = -1;
12154 for (j = 0; j < ndirs; j++)
12155 if (dirs[j].length < dirs[ndirs].length
12156 && dirs[j].length > 1
12157 && (dirs[ndirs].prefix == -1
12158 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12159 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12160 dirs[ndirs].prefix = j;
12165 /* Now to the actual work. We have to find a subset of the directories which
12166 allow expressing the file name using references to the directory table
12167 with the least amount of characters. We do not do an exhaustive search
12168 where we would have to check out every combination of every single
12169 possible prefix. Instead we use a heuristic which provides nearly optimal
12170 results in most cases and never is much off. */
12171 saved = XALLOCAVEC (int, ndirs);
12172 savehere = XALLOCAVEC (int, ndirs);
12174 memset (saved, '\0', ndirs * sizeof (saved[0]));
12175 for (i = 0; i < ndirs; i++)
12180 /* We can always save some space for the current directory. But this
12181 does not mean it will be enough to justify adding the directory. */
12182 savehere[i] = dirs[i].length;
12183 total = (savehere[i] - saved[i]) * dirs[i].count;
12185 for (j = i + 1; j < ndirs; j++)
12188 if (saved[j] < dirs[i].length)
12190 /* Determine whether the dirs[i] path is a prefix of the
12194 k = dirs[j].prefix;
12195 while (k != -1 && k != (int) i)
12196 k = dirs[k].prefix;
12200 /* Yes it is. We can possibly save some memory by
12201 writing the filenames in dirs[j] relative to
12203 savehere[j] = dirs[i].length;
12204 total += (savehere[j] - saved[j]) * dirs[j].count;
12209 /* Check whether we can save enough to justify adding the dirs[i]
12211 if (total > dirs[i].length + 1)
12213 /* It's worthwhile adding. */
12214 for (j = i; j < ndirs; j++)
12215 if (savehere[j] > 0)
12217 /* Remember how much we saved for this directory so far. */
12218 saved[j] = savehere[j];
12220 /* Remember the prefix directory. */
12221 dirs[j].dir_idx = i;
12226 /* Emit the directory name table. */
12227 idx_offset = dirs[0].length > 0 ? 1 : 0;
12228 for (i = 1 - idx_offset; i < ndirs; i++)
12229 dw2_asm_output_nstring (dirs[i].path,
12231 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12232 "Directory Entry: %#x", i + idx_offset);
12234 dw2_asm_output_data (1, 0, "End directory table");
12236 /* We have to emit them in the order of emitted_number since that's
12237 used in the debug info generation. To do this efficiently we
12238 generate a back-mapping of the indices first. */
12239 backmap = XALLOCAVEC (int, numfiles);
12240 for (i = 0; i < numfiles; i++)
12241 backmap[files[i].file_idx->emitted_number - 1] = i;
12243 /* Now write all the file names. */
12244 for (i = 0; i < numfiles; i++)
12246 int file_idx = backmap[i];
12247 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12249 #ifdef VMS_DEBUGGING_INFO
12250 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12252 /* Setting these fields can lead to debugger miscomparisons,
12253 but VMS Debug requires them to be set correctly. */
12258 int maxfilelen = strlen (files[file_idx].path)
12259 + dirs[dir_idx].length
12260 + MAX_VMS_VERSION_LEN + 1;
12261 char *filebuf = XALLOCAVEC (char, maxfilelen);
12263 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12264 snprintf (filebuf, maxfilelen, "%s;%d",
12265 files[file_idx].path + dirs[dir_idx].length, ver);
12267 dw2_asm_output_nstring
12268 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12270 /* Include directory index. */
12271 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12273 /* Modification time. */
12274 dw2_asm_output_data_uleb128
12275 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12279 /* File length in bytes. */
12280 dw2_asm_output_data_uleb128
12281 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12285 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12286 "File Entry: %#x", (unsigned) i + 1);
12288 /* Include directory index. */
12289 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12291 /* Modification time. */
12292 dw2_asm_output_data_uleb128 (0, NULL);
12294 /* File length in bytes. */
12295 dw2_asm_output_data_uleb128 (0, NULL);
12296 #endif /* VMS_DEBUGGING_INFO */
12299 dw2_asm_output_data (1, 0, "End file name table");
12303 /* Output the source line number correspondence information. This
12304 information goes into the .debug_line section. */
12307 output_line_info (void)
12309 char l1[20], l2[20], p1[20], p2[20];
12310 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12311 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12313 unsigned n_op_args;
12314 unsigned long lt_index;
12315 unsigned long current_line;
12318 unsigned long current_file;
12319 unsigned long function;
12320 int ver = dwarf_version;
12322 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12323 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12324 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12325 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12327 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12328 dw2_asm_output_data (4, 0xffffffff,
12329 "Initial length escape value indicating 64-bit DWARF extension");
12330 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12331 "Length of Source Line Info");
12332 ASM_OUTPUT_LABEL (asm_out_file, l1);
12334 dw2_asm_output_data (2, ver, "DWARF Version");
12335 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12336 ASM_OUTPUT_LABEL (asm_out_file, p1);
12338 /* Define the architecture-dependent minimum instruction length (in
12339 bytes). In this implementation of DWARF, this field is used for
12340 information purposes only. Since GCC generates assembly language,
12341 we have no a priori knowledge of how many instruction bytes are
12342 generated for each source line, and therefore can use only the
12343 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12344 commands. Accordingly, we fix this as `1', which is "correct
12345 enough" for all architectures, and don't let the target override. */
12346 dw2_asm_output_data (1, 1,
12347 "Minimum Instruction Length");
12350 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12351 "Maximum Operations Per Instruction");
12352 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12353 "Default is_stmt_start flag");
12354 dw2_asm_output_data (1, DWARF_LINE_BASE,
12355 "Line Base Value (Special Opcodes)");
12356 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12357 "Line Range Value (Special Opcodes)");
12358 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12359 "Special Opcode Base");
12361 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12365 case DW_LNS_advance_pc:
12366 case DW_LNS_advance_line:
12367 case DW_LNS_set_file:
12368 case DW_LNS_set_column:
12369 case DW_LNS_fixed_advance_pc:
12377 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12381 /* Write out the information about the files we use. */
12382 output_file_names ();
12383 ASM_OUTPUT_LABEL (asm_out_file, p2);
12385 /* We used to set the address register to the first location in the text
12386 section here, but that didn't accomplish anything since we already
12387 have a line note for the opening brace of the first function. */
12389 /* Generate the line number to PC correspondence table, encoded as
12390 a series of state machine operations. */
12394 if (cfun && in_cold_section_p)
12395 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12397 strcpy (prev_line_label, text_section_label);
12398 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12400 dw_line_info_ref line_info = &line_info_table[lt_index];
12403 /* Disable this optimization for now; GDB wants to see two line notes
12404 at the beginning of a function so it can find the end of the
12407 /* Don't emit anything for redundant notes. Just updating the
12408 address doesn't accomplish anything, because we already assume
12409 that anything after the last address is this line. */
12410 if (line_info->dw_line_num == current_line
12411 && line_info->dw_file_num == current_file)
12415 /* Emit debug info for the address of the current line.
12417 Unfortunately, we have little choice here currently, and must always
12418 use the most general form. GCC does not know the address delta
12419 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12420 attributes which will give an upper bound on the address range. We
12421 could perhaps use length attributes to determine when it is safe to
12422 use DW_LNS_fixed_advance_pc. */
12424 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12427 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12428 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12429 "DW_LNS_fixed_advance_pc");
12430 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12434 /* This can handle any delta. This takes
12435 4+DWARF2_ADDR_SIZE bytes. */
12436 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12437 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12438 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12439 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12442 strcpy (prev_line_label, line_label);
12444 /* Emit debug info for the source file of the current line, if
12445 different from the previous line. */
12446 if (line_info->dw_file_num != current_file)
12448 current_file = line_info->dw_file_num;
12449 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12450 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12453 /* Emit debug info for the current line number, choosing the encoding
12454 that uses the least amount of space. */
12455 if (line_info->dw_line_num != current_line)
12457 line_offset = line_info->dw_line_num - current_line;
12458 line_delta = line_offset - DWARF_LINE_BASE;
12459 current_line = line_info->dw_line_num;
12460 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12461 /* This can handle deltas from -10 to 234, using the current
12462 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12464 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12465 "line %lu", current_line);
12468 /* This can handle any delta. This takes at least 4 bytes,
12469 depending on the value being encoded. */
12470 dw2_asm_output_data (1, DW_LNS_advance_line,
12471 "advance to line %lu", current_line);
12472 dw2_asm_output_data_sleb128 (line_offset, NULL);
12473 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12477 /* We still need to start a new row, so output a copy insn. */
12478 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12481 /* Emit debug info for the address of the end of the function. */
12484 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12485 "DW_LNS_fixed_advance_pc");
12486 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12490 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12491 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12492 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12493 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12496 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12497 dw2_asm_output_data_uleb128 (1, NULL);
12498 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12503 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12505 dw_separate_line_info_ref line_info
12506 = &separate_line_info_table[lt_index];
12509 /* Don't emit anything for redundant notes. */
12510 if (line_info->dw_line_num == current_line
12511 && line_info->dw_file_num == current_file
12512 && line_info->function == function)
12516 /* Emit debug info for the address of the current line. If this is
12517 a new function, or the first line of a function, then we need
12518 to handle it differently. */
12519 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12521 if (function != line_info->function)
12523 function = line_info->function;
12525 /* Set the address register to the first line in the function. */
12526 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12527 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12528 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12529 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12533 /* ??? See the DW_LNS_advance_pc comment above. */
12536 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12537 "DW_LNS_fixed_advance_pc");
12538 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12542 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12543 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12544 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12545 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12549 strcpy (prev_line_label, line_label);
12551 /* Emit debug info for the source file of the current line, if
12552 different from the previous line. */
12553 if (line_info->dw_file_num != current_file)
12555 current_file = line_info->dw_file_num;
12556 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12557 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12560 /* Emit debug info for the current line number, choosing the encoding
12561 that uses the least amount of space. */
12562 if (line_info->dw_line_num != current_line)
12564 line_offset = line_info->dw_line_num - current_line;
12565 line_delta = line_offset - DWARF_LINE_BASE;
12566 current_line = line_info->dw_line_num;
12567 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12568 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12569 "line %lu", current_line);
12572 dw2_asm_output_data (1, DW_LNS_advance_line,
12573 "advance to line %lu", current_line);
12574 dw2_asm_output_data_sleb128 (line_offset, NULL);
12575 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12579 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12587 /* If we're done with a function, end its sequence. */
12588 if (lt_index == separate_line_info_table_in_use
12589 || separate_line_info_table[lt_index].function != function)
12594 /* Emit debug info for the address of the end of the function. */
12595 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12598 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12599 "DW_LNS_fixed_advance_pc");
12600 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12604 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12605 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12606 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12607 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12610 /* Output the marker for the end of this sequence. */
12611 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12612 dw2_asm_output_data_uleb128 (1, NULL);
12613 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12617 /* Output the marker for the end of the line number info. */
12618 ASM_OUTPUT_LABEL (asm_out_file, l2);
12621 /* Given a pointer to a tree node for some base type, return a pointer to
12622 a DIE that describes the given type.
12624 This routine must only be called for GCC type nodes that correspond to
12625 Dwarf base (fundamental) types. */
12628 base_type_die (tree type)
12630 dw_die_ref base_type_result;
12631 enum dwarf_type encoding;
12633 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12636 /* If this is a subtype that should not be emitted as a subrange type,
12637 use the base type. See subrange_type_for_debug_p. */
12638 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12639 type = TREE_TYPE (type);
12641 switch (TREE_CODE (type))
12644 if ((dwarf_version >= 4 || !dwarf_strict)
12645 && TYPE_NAME (type)
12646 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12647 && DECL_IS_BUILTIN (TYPE_NAME (type))
12648 && DECL_NAME (TYPE_NAME (type)))
12650 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12651 if (strcmp (name, "char16_t") == 0
12652 || strcmp (name, "char32_t") == 0)
12654 encoding = DW_ATE_UTF;
12658 if (TYPE_STRING_FLAG (type))
12660 if (TYPE_UNSIGNED (type))
12661 encoding = DW_ATE_unsigned_char;
12663 encoding = DW_ATE_signed_char;
12665 else if (TYPE_UNSIGNED (type))
12666 encoding = DW_ATE_unsigned;
12668 encoding = DW_ATE_signed;
12672 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12674 if (dwarf_version >= 3 || !dwarf_strict)
12675 encoding = DW_ATE_decimal_float;
12677 encoding = DW_ATE_lo_user;
12680 encoding = DW_ATE_float;
12683 case FIXED_POINT_TYPE:
12684 if (!(dwarf_version >= 3 || !dwarf_strict))
12685 encoding = DW_ATE_lo_user;
12686 else if (TYPE_UNSIGNED (type))
12687 encoding = DW_ATE_unsigned_fixed;
12689 encoding = DW_ATE_signed_fixed;
12692 /* Dwarf2 doesn't know anything about complex ints, so use
12693 a user defined type for it. */
12695 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12696 encoding = DW_ATE_complex_float;
12698 encoding = DW_ATE_lo_user;
12702 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12703 encoding = DW_ATE_boolean;
12707 /* No other TREE_CODEs are Dwarf fundamental types. */
12708 gcc_unreachable ();
12711 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12713 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12714 int_size_in_bytes (type));
12715 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12717 return base_type_result;
12720 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12721 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12724 is_base_type (tree type)
12726 switch (TREE_CODE (type))
12732 case FIXED_POINT_TYPE:
12740 case QUAL_UNION_TYPE:
12741 case ENUMERAL_TYPE:
12742 case FUNCTION_TYPE:
12745 case REFERENCE_TYPE:
12753 gcc_unreachable ();
12759 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12760 node, return the size in bits for the type if it is a constant, or else
12761 return the alignment for the type if the type's size is not constant, or
12762 else return BITS_PER_WORD if the type actually turns out to be an
12763 ERROR_MARK node. */
12765 static inline unsigned HOST_WIDE_INT
12766 simple_type_size_in_bits (const_tree type)
12768 if (TREE_CODE (type) == ERROR_MARK)
12769 return BITS_PER_WORD;
12770 else if (TYPE_SIZE (type) == NULL_TREE)
12772 else if (host_integerp (TYPE_SIZE (type), 1))
12773 return tree_low_cst (TYPE_SIZE (type), 1);
12775 return TYPE_ALIGN (type);
12778 /* Similarly, but return a double_int instead of UHWI. */
12780 static inline double_int
12781 double_int_type_size_in_bits (const_tree type)
12783 if (TREE_CODE (type) == ERROR_MARK)
12784 return uhwi_to_double_int (BITS_PER_WORD);
12785 else if (TYPE_SIZE (type) == NULL_TREE)
12786 return double_int_zero;
12787 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12788 return tree_to_double_int (TYPE_SIZE (type));
12790 return uhwi_to_double_int (TYPE_ALIGN (type));
12793 /* Given a pointer to a tree node for a subrange type, return a pointer
12794 to a DIE that describes the given type. */
12797 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12799 dw_die_ref subrange_die;
12800 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12802 if (context_die == NULL)
12803 context_die = comp_unit_die ();
12805 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12807 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12809 /* The size of the subrange type and its base type do not match,
12810 so we need to generate a size attribute for the subrange type. */
12811 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12815 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12817 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12819 return subrange_die;
12822 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12823 entry that chains various modifiers in front of the given type. */
12826 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12827 dw_die_ref context_die)
12829 enum tree_code code = TREE_CODE (type);
12830 dw_die_ref mod_type_die;
12831 dw_die_ref sub_die = NULL;
12832 tree item_type = NULL;
12833 tree qualified_type;
12834 tree name, low, high;
12836 if (code == ERROR_MARK)
12839 /* See if we already have the appropriately qualified variant of
12842 = get_qualified_type (type,
12843 ((is_const_type ? TYPE_QUAL_CONST : 0)
12844 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12846 if (qualified_type == sizetype
12847 && TYPE_NAME (qualified_type)
12848 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12850 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
12852 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
12853 && TYPE_PRECISION (t)
12854 == TYPE_PRECISION (qualified_type)
12855 && TYPE_UNSIGNED (t)
12856 == TYPE_UNSIGNED (qualified_type));
12857 qualified_type = t;
12860 /* If we do, then we can just use its DIE, if it exists. */
12861 if (qualified_type)
12863 mod_type_die = lookup_type_die (qualified_type);
12865 return mod_type_die;
12868 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12870 /* Handle C typedef types. */
12871 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12872 && !DECL_ARTIFICIAL (name))
12874 tree dtype = TREE_TYPE (name);
12876 if (qualified_type == dtype)
12878 /* For a named type, use the typedef. */
12879 gen_type_die (qualified_type, context_die);
12880 return lookup_type_die (qualified_type);
12882 else if (is_const_type < TYPE_READONLY (dtype)
12883 || is_volatile_type < TYPE_VOLATILE (dtype)
12884 || (is_const_type <= TYPE_READONLY (dtype)
12885 && is_volatile_type <= TYPE_VOLATILE (dtype)
12886 && DECL_ORIGINAL_TYPE (name) != type))
12887 /* cv-unqualified version of named type. Just use the unnamed
12888 type to which it refers. */
12889 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12890 is_const_type, is_volatile_type,
12892 /* Else cv-qualified version of named type; fall through. */
12896 /* If both is_const_type and is_volatile_type, prefer the path
12897 which leads to a qualified type. */
12898 && (!is_volatile_type
12899 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
12900 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
12902 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
12903 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12905 else if (is_volatile_type)
12907 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
12908 sub_die = modified_type_die (type, is_const_type, 0, context_die);
12910 else if (code == POINTER_TYPE)
12912 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
12913 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12914 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12915 item_type = TREE_TYPE (type);
12916 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12917 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12918 TYPE_ADDR_SPACE (item_type));
12920 else if (code == REFERENCE_TYPE)
12922 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
12923 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
12926 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
12927 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12928 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12929 item_type = TREE_TYPE (type);
12930 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12931 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12932 TYPE_ADDR_SPACE (item_type));
12934 else if (code == INTEGER_TYPE
12935 && TREE_TYPE (type) != NULL_TREE
12936 && subrange_type_for_debug_p (type, &low, &high))
12938 mod_type_die = subrange_type_die (type, low, high, context_die);
12939 item_type = TREE_TYPE (type);
12941 else if (is_base_type (type))
12942 mod_type_die = base_type_die (type);
12945 gen_type_die (type, context_die);
12947 /* We have to get the type_main_variant here (and pass that to the
12948 `lookup_type_die' routine) because the ..._TYPE node we have
12949 might simply be a *copy* of some original type node (where the
12950 copy was created to help us keep track of typedef names) and
12951 that copy might have a different TYPE_UID from the original
12953 if (TREE_CODE (type) != VECTOR_TYPE)
12954 return lookup_type_die (type_main_variant (type));
12956 /* Vectors have the debugging information in the type,
12957 not the main variant. */
12958 return lookup_type_die (type);
12961 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12962 don't output a DW_TAG_typedef, since there isn't one in the
12963 user's program; just attach a DW_AT_name to the type.
12964 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12965 if the base type already has the same name. */
12967 && ((TREE_CODE (name) != TYPE_DECL
12968 && (qualified_type == TYPE_MAIN_VARIANT (type)
12969 || (!is_const_type && !is_volatile_type)))
12970 || (TREE_CODE (name) == TYPE_DECL
12971 && TREE_TYPE (name) == qualified_type
12972 && DECL_NAME (name))))
12974 if (TREE_CODE (name) == TYPE_DECL)
12975 /* Could just call add_name_and_src_coords_attributes here,
12976 but since this is a builtin type it doesn't have any
12977 useful source coordinates anyway. */
12978 name = DECL_NAME (name);
12979 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12981 /* This probably indicates a bug. */
12982 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12983 add_name_attribute (mod_type_die, "__unknown__");
12985 if (qualified_type)
12986 equate_type_number_to_die (qualified_type, mod_type_die);
12989 /* We must do this after the equate_type_number_to_die call, in case
12990 this is a recursive type. This ensures that the modified_type_die
12991 recursion will terminate even if the type is recursive. Recursive
12992 types are possible in Ada. */
12993 sub_die = modified_type_die (item_type,
12994 TYPE_READONLY (item_type),
12995 TYPE_VOLATILE (item_type),
12998 if (sub_die != NULL)
12999 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
13001 return mod_type_die;
13004 /* Generate DIEs for the generic parameters of T.
13005 T must be either a generic type or a generic function.
13006 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13009 gen_generic_params_dies (tree t)
13013 dw_die_ref die = NULL;
13015 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13019 die = lookup_type_die (t);
13020 else if (DECL_P (t))
13021 die = lookup_decl_die (t);
13025 parms = lang_hooks.get_innermost_generic_parms (t);
13027 /* T has no generic parameter. It means T is neither a generic type
13028 or function. End of story. */
13031 parms_num = TREE_VEC_LENGTH (parms);
13032 args = lang_hooks.get_innermost_generic_args (t);
13033 for (i = 0; i < parms_num; i++)
13035 tree parm, arg, arg_pack_elems;
13037 parm = TREE_VEC_ELT (parms, i);
13038 arg = TREE_VEC_ELT (args, i);
13039 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13040 gcc_assert (parm && TREE_VALUE (parm) && arg);
13042 if (parm && TREE_VALUE (parm) && arg)
13044 /* If PARM represents a template parameter pack,
13045 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13046 by DW_TAG_template_*_parameter DIEs for the argument
13047 pack elements of ARG. Note that ARG would then be
13048 an argument pack. */
13049 if (arg_pack_elems)
13050 template_parameter_pack_die (TREE_VALUE (parm),
13054 generic_parameter_die (TREE_VALUE (parm), arg,
13055 true /* Emit DW_AT_name */, die);
13060 /* Create and return a DIE for PARM which should be
13061 the representation of a generic type parameter.
13062 For instance, in the C++ front end, PARM would be a template parameter.
13063 ARG is the argument to PARM.
13064 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13066 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13067 as a child node. */
13070 generic_parameter_die (tree parm, tree arg,
13072 dw_die_ref parent_die)
13074 dw_die_ref tmpl_die = NULL;
13075 const char *name = NULL;
13077 if (!parm || !DECL_NAME (parm) || !arg)
13080 /* We support non-type generic parameters and arguments,
13081 type generic parameters and arguments, as well as
13082 generic generic parameters (a.k.a. template template parameters in C++)
13084 if (TREE_CODE (parm) == PARM_DECL)
13085 /* PARM is a nontype generic parameter */
13086 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13087 else if (TREE_CODE (parm) == TYPE_DECL)
13088 /* PARM is a type generic parameter. */
13089 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13090 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13091 /* PARM is a generic generic parameter.
13092 Its DIE is a GNU extension. It shall have a
13093 DW_AT_name attribute to represent the name of the template template
13094 parameter, and a DW_AT_GNU_template_name attribute to represent the
13095 name of the template template argument. */
13096 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13099 gcc_unreachable ();
13105 /* If PARM is a generic parameter pack, it means we are
13106 emitting debug info for a template argument pack element.
13107 In other terms, ARG is a template argument pack element.
13108 In that case, we don't emit any DW_AT_name attribute for
13112 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13114 add_AT_string (tmpl_die, DW_AT_name, name);
13117 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13119 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13120 TMPL_DIE should have a child DW_AT_type attribute that is set
13121 to the type of the argument to PARM, which is ARG.
13122 If PARM is a type generic parameter, TMPL_DIE should have a
13123 child DW_AT_type that is set to ARG. */
13124 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13125 add_type_attribute (tmpl_die, tmpl_type, 0,
13126 TREE_THIS_VOLATILE (tmpl_type),
13131 /* So TMPL_DIE is a DIE representing a
13132 a generic generic template parameter, a.k.a template template
13133 parameter in C++ and arg is a template. */
13135 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13136 to the name of the argument. */
13137 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13139 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13142 if (TREE_CODE (parm) == PARM_DECL)
13143 /* So PARM is a non-type generic parameter.
13144 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13145 attribute of TMPL_DIE which value represents the value
13147 We must be careful here:
13148 The value of ARG might reference some function decls.
13149 We might currently be emitting debug info for a generic
13150 type and types are emitted before function decls, we don't
13151 know if the function decls referenced by ARG will actually be
13152 emitted after cgraph computations.
13153 So must defer the generation of the DW_AT_const_value to
13154 after cgraph is ready. */
13155 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13161 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13162 PARM_PACK must be a template parameter pack. The returned DIE
13163 will be child DIE of PARENT_DIE. */
13166 template_parameter_pack_die (tree parm_pack,
13167 tree parm_pack_args,
13168 dw_die_ref parent_die)
13173 gcc_assert (parent_die && parm_pack);
13175 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13176 add_name_and_src_coords_attributes (die, parm_pack);
13177 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13178 generic_parameter_die (parm_pack,
13179 TREE_VEC_ELT (parm_pack_args, j),
13180 false /* Don't emit DW_AT_name */,
13185 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13186 an enumerated type. */
13189 type_is_enum (const_tree type)
13191 return TREE_CODE (type) == ENUMERAL_TYPE;
13194 /* Return the DBX register number described by a given RTL node. */
13196 static unsigned int
13197 dbx_reg_number (const_rtx rtl)
13199 unsigned regno = REGNO (rtl);
13201 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13203 #ifdef LEAF_REG_REMAP
13204 if (current_function_uses_only_leaf_regs)
13206 int leaf_reg = LEAF_REG_REMAP (regno);
13207 if (leaf_reg != -1)
13208 regno = (unsigned) leaf_reg;
13212 return DBX_REGISTER_NUMBER (regno);
13215 /* Optionally add a DW_OP_piece term to a location description expression.
13216 DW_OP_piece is only added if the location description expression already
13217 doesn't end with DW_OP_piece. */
13220 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13222 dw_loc_descr_ref loc;
13224 if (*list_head != NULL)
13226 /* Find the end of the chain. */
13227 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13230 if (loc->dw_loc_opc != DW_OP_piece)
13231 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13235 /* Return a location descriptor that designates a machine register or
13236 zero if there is none. */
13238 static dw_loc_descr_ref
13239 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13243 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13246 /* We only use "frame base" when we're sure we're talking about the
13247 post-prologue local stack frame. We do this by *not* running
13248 register elimination until this point, and recognizing the special
13249 argument pointer and soft frame pointer rtx's.
13250 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13251 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13252 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13254 dw_loc_descr_ref result = NULL;
13256 if (dwarf_version >= 4 || !dwarf_strict)
13258 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13260 add_loc_descr (&result,
13261 new_loc_descr (DW_OP_stack_value, 0, 0));
13266 regs = targetm.dwarf_register_span (rtl);
13268 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13269 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13271 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13274 /* Return a location descriptor that designates a machine register for
13275 a given hard register number. */
13277 static dw_loc_descr_ref
13278 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13280 dw_loc_descr_ref reg_loc_descr;
13284 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13286 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13288 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13289 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13291 return reg_loc_descr;
13294 /* Given an RTL of a register, return a location descriptor that
13295 designates a value that spans more than one register. */
13297 static dw_loc_descr_ref
13298 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13299 enum var_init_status initialized)
13301 int nregs, size, i;
13303 dw_loc_descr_ref loc_result = NULL;
13306 #ifdef LEAF_REG_REMAP
13307 if (current_function_uses_only_leaf_regs)
13309 int leaf_reg = LEAF_REG_REMAP (reg);
13310 if (leaf_reg != -1)
13311 reg = (unsigned) leaf_reg;
13314 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13315 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13317 /* Simple, contiguous registers. */
13318 if (regs == NULL_RTX)
13320 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13325 dw_loc_descr_ref t;
13327 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13328 VAR_INIT_STATUS_INITIALIZED);
13329 add_loc_descr (&loc_result, t);
13330 add_loc_descr_op_piece (&loc_result, size);
13336 /* Now onto stupid register sets in non contiguous locations. */
13338 gcc_assert (GET_CODE (regs) == PARALLEL);
13340 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13343 for (i = 0; i < XVECLEN (regs, 0); ++i)
13345 dw_loc_descr_ref t;
13347 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13348 VAR_INIT_STATUS_INITIALIZED);
13349 add_loc_descr (&loc_result, t);
13350 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13351 add_loc_descr_op_piece (&loc_result, size);
13354 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13355 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13359 /* Return a location descriptor that designates a constant. */
13361 static dw_loc_descr_ref
13362 int_loc_descriptor (HOST_WIDE_INT i)
13364 enum dwarf_location_atom op;
13366 /* Pick the smallest representation of a constant, rather than just
13367 defaulting to the LEB encoding. */
13371 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13372 else if (i <= 0xff)
13373 op = DW_OP_const1u;
13374 else if (i <= 0xffff)
13375 op = DW_OP_const2u;
13376 else if (HOST_BITS_PER_WIDE_INT == 32
13377 || i <= 0xffffffff)
13378 op = DW_OP_const4u;
13385 op = DW_OP_const1s;
13386 else if (i >= -0x8000)
13387 op = DW_OP_const2s;
13388 else if (HOST_BITS_PER_WIDE_INT == 32
13389 || i >= -0x80000000)
13390 op = DW_OP_const4s;
13395 return new_loc_descr (op, i, 0);
13398 /* Return loc description representing "address" of integer value.
13399 This can appear only as toplevel expression. */
13401 static dw_loc_descr_ref
13402 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13405 dw_loc_descr_ref loc_result = NULL;
13407 if (!(dwarf_version >= 4 || !dwarf_strict))
13414 else if (i <= 0xff)
13416 else if (i <= 0xffff)
13418 else if (HOST_BITS_PER_WIDE_INT == 32
13419 || i <= 0xffffffff)
13422 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13428 else if (i >= -0x8000)
13430 else if (HOST_BITS_PER_WIDE_INT == 32
13431 || i >= -0x80000000)
13434 litsize = 1 + size_of_sleb128 (i);
13436 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13437 is more compact. For DW_OP_stack_value we need:
13438 litsize + 1 (DW_OP_stack_value)
13439 and for DW_OP_implicit_value:
13440 1 (DW_OP_implicit_value) + 1 (length) + size. */
13441 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13443 loc_result = int_loc_descriptor (i);
13444 add_loc_descr (&loc_result,
13445 new_loc_descr (DW_OP_stack_value, 0, 0));
13449 loc_result = new_loc_descr (DW_OP_implicit_value,
13451 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13452 loc_result->dw_loc_oprnd2.v.val_int = i;
13456 /* Return a location descriptor that designates a base+offset location. */
13458 static dw_loc_descr_ref
13459 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13460 enum var_init_status initialized)
13462 unsigned int regno;
13463 dw_loc_descr_ref result;
13464 dw_fde_ref fde = current_fde ();
13466 /* We only use "frame base" when we're sure we're talking about the
13467 post-prologue local stack frame. We do this by *not* running
13468 register elimination until this point, and recognizing the special
13469 argument pointer and soft frame pointer rtx's. */
13470 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13472 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13476 if (GET_CODE (elim) == PLUS)
13478 offset += INTVAL (XEXP (elim, 1));
13479 elim = XEXP (elim, 0);
13481 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13482 && (elim == hard_frame_pointer_rtx
13483 || elim == stack_pointer_rtx))
13484 || elim == (frame_pointer_needed
13485 ? hard_frame_pointer_rtx
13486 : stack_pointer_rtx));
13488 /* If drap register is used to align stack, use frame
13489 pointer + offset to access stack variables. If stack
13490 is aligned without drap, use stack pointer + offset to
13491 access stack variables. */
13492 if (crtl->stack_realign_tried
13493 && reg == frame_pointer_rtx)
13496 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13497 ? HARD_FRAME_POINTER_REGNUM
13498 : STACK_POINTER_REGNUM);
13499 return new_reg_loc_descr (base_reg, offset);
13502 offset += frame_pointer_fb_offset;
13503 return new_loc_descr (DW_OP_fbreg, offset, 0);
13508 && (fde->drap_reg == REGNO (reg)
13509 || fde->vdrap_reg == REGNO (reg)))
13511 /* Use cfa+offset to represent the location of arguments passed
13512 on the stack when drap is used to align stack.
13513 Only do this when not optimizing, for optimized code var-tracking
13514 is supposed to track where the arguments live and the register
13515 used as vdrap or drap in some spot might be used for something
13516 else in other part of the routine. */
13517 return new_loc_descr (DW_OP_fbreg, offset, 0);
13520 regno = dbx_reg_number (reg);
13522 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13525 result = new_loc_descr (DW_OP_bregx, regno, offset);
13527 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13528 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13533 /* Return true if this RTL expression describes a base+offset calculation. */
13536 is_based_loc (const_rtx rtl)
13538 return (GET_CODE (rtl) == PLUS
13539 && ((REG_P (XEXP (rtl, 0))
13540 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13541 && CONST_INT_P (XEXP (rtl, 1)))));
13544 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13547 static dw_loc_descr_ref
13548 tls_mem_loc_descriptor (rtx mem)
13551 dw_loc_descr_ref loc_result;
13553 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13556 base = get_base_address (MEM_EXPR (mem));
13558 || TREE_CODE (base) != VAR_DECL
13559 || !DECL_THREAD_LOCAL_P (base))
13562 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13563 if (loc_result == NULL)
13566 if (INTVAL (MEM_OFFSET (mem)))
13567 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13572 /* Output debug info about reason why we failed to expand expression as dwarf
13576 expansion_failed (tree expr, rtx rtl, char const *reason)
13578 if (dump_file && (dump_flags & TDF_DETAILS))
13580 fprintf (dump_file, "Failed to expand as dwarf: ");
13582 print_generic_expr (dump_file, expr, dump_flags);
13585 fprintf (dump_file, "\n");
13586 print_rtl (dump_file, rtl);
13588 fprintf (dump_file, "\nReason: %s\n", reason);
13592 /* Helper function for const_ok_for_output, called either directly
13593 or via for_each_rtx. */
13596 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13600 if (GET_CODE (rtl) == UNSPEC)
13602 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13603 we can't express it in the debug info. */
13604 #ifdef ENABLE_CHECKING
13605 /* Don't complain about TLS UNSPECs, those are just too hard to
13607 if (XVECLEN (rtl, 0) != 1
13608 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13609 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13610 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13611 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13612 inform (current_function_decl
13613 ? DECL_SOURCE_LOCATION (current_function_decl)
13614 : UNKNOWN_LOCATION,
13615 "non-delegitimized UNSPEC %d found in variable location",
13618 expansion_failed (NULL_TREE, rtl,
13619 "UNSPEC hasn't been delegitimized.\n");
13623 if (GET_CODE (rtl) != SYMBOL_REF)
13626 if (CONSTANT_POOL_ADDRESS_P (rtl))
13629 get_pool_constant_mark (rtl, &marked);
13630 /* If all references to this pool constant were optimized away,
13631 it was not output and thus we can't represent it. */
13634 expansion_failed (NULL_TREE, rtl,
13635 "Constant was removed from constant pool.\n");
13640 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13643 /* Avoid references to external symbols in debug info, on several targets
13644 the linker might even refuse to link when linking a shared library,
13645 and in many other cases the relocations for .debug_info/.debug_loc are
13646 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13647 to be defined within the same shared library or executable are fine. */
13648 if (SYMBOL_REF_EXTERNAL_P (rtl))
13650 tree decl = SYMBOL_REF_DECL (rtl);
13652 if (decl == NULL || !targetm.binds_local_p (decl))
13654 expansion_failed (NULL_TREE, rtl,
13655 "Symbol not defined in current TU.\n");
13663 /* Return true if constant RTL can be emitted in DW_OP_addr or
13664 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13665 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13668 const_ok_for_output (rtx rtl)
13670 if (GET_CODE (rtl) == SYMBOL_REF)
13671 return const_ok_for_output_1 (&rtl, NULL) == 0;
13673 if (GET_CODE (rtl) == CONST)
13674 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13679 /* The following routine converts the RTL for a variable or parameter
13680 (resident in memory) into an equivalent Dwarf representation of a
13681 mechanism for getting the address of that same variable onto the top of a
13682 hypothetical "address evaluation" stack.
13684 When creating memory location descriptors, we are effectively transforming
13685 the RTL for a memory-resident object into its Dwarf postfix expression
13686 equivalent. This routine recursively descends an RTL tree, turning
13687 it into Dwarf postfix code as it goes.
13689 MODE is the mode of the memory reference, needed to handle some
13690 autoincrement addressing modes.
13692 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13693 location list for RTL.
13695 Return 0 if we can't represent the location. */
13697 static dw_loc_descr_ref
13698 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13699 enum var_init_status initialized)
13701 dw_loc_descr_ref mem_loc_result = NULL;
13702 enum dwarf_location_atom op;
13703 dw_loc_descr_ref op0, op1;
13705 /* Note that for a dynamically sized array, the location we will generate a
13706 description of here will be the lowest numbered location which is
13707 actually within the array. That's *not* necessarily the same as the
13708 zeroth element of the array. */
13710 rtl = targetm.delegitimize_address (rtl);
13712 switch (GET_CODE (rtl))
13717 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13720 /* The case of a subreg may arise when we have a local (register)
13721 variable or a formal (register) parameter which doesn't quite fill
13722 up an entire register. For now, just assume that it is
13723 legitimate to make the Dwarf info refer to the whole register which
13724 contains the given subreg. */
13725 if (!subreg_lowpart_p (rtl))
13727 rtl = SUBREG_REG (rtl);
13728 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13730 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13732 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13736 /* Whenever a register number forms a part of the description of the
13737 method for calculating the (dynamic) address of a memory resident
13738 object, DWARF rules require the register number be referred to as
13739 a "base register". This distinction is not based in any way upon
13740 what category of register the hardware believes the given register
13741 belongs to. This is strictly DWARF terminology we're dealing with
13742 here. Note that in cases where the location of a memory-resident
13743 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13744 OP_CONST (0)) the actual DWARF location descriptor that we generate
13745 may just be OP_BASEREG (basereg). This may look deceptively like
13746 the object in question was allocated to a register (rather than in
13747 memory) so DWARF consumers need to be aware of the subtle
13748 distinction between OP_REG and OP_BASEREG. */
13749 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13750 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13751 else if (stack_realign_drap
13753 && crtl->args.internal_arg_pointer == rtl
13754 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13756 /* If RTL is internal_arg_pointer, which has been optimized
13757 out, use DRAP instead. */
13758 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13759 VAR_INIT_STATUS_INITIALIZED);
13765 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13766 VAR_INIT_STATUS_INITIALIZED);
13771 int shift = DWARF2_ADDR_SIZE
13772 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13773 shift *= BITS_PER_UNIT;
13774 if (GET_CODE (rtl) == SIGN_EXTEND)
13778 mem_loc_result = op0;
13779 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13780 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13781 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13782 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13787 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13788 VAR_INIT_STATUS_INITIALIZED);
13789 if (mem_loc_result == NULL)
13790 mem_loc_result = tls_mem_loc_descriptor (rtl);
13791 if (mem_loc_result != 0)
13793 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13795 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13798 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13799 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13801 add_loc_descr (&mem_loc_result,
13802 new_loc_descr (DW_OP_deref_size,
13803 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13807 rtx new_rtl = avoid_constant_pool_reference (rtl);
13808 if (new_rtl != rtl)
13809 return mem_loc_descriptor (new_rtl, mode, initialized);
13814 rtl = XEXP (rtl, 1);
13816 /* ... fall through ... */
13819 /* Some ports can transform a symbol ref into a label ref, because
13820 the symbol ref is too far away and has to be dumped into a constant
13824 if (GET_CODE (rtl) == SYMBOL_REF
13825 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13827 dw_loc_descr_ref temp;
13829 /* If this is not defined, we have no way to emit the data. */
13830 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13833 /* We used to emit DW_OP_addr here, but that's wrong, since
13834 DW_OP_addr should be relocated by the debug info consumer,
13835 while DW_OP_GNU_push_tls_address operand should not. */
13836 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13837 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13838 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13839 temp->dw_loc_oprnd1.v.val_addr = rtl;
13840 temp->dtprel = true;
13842 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13843 add_loc_descr (&mem_loc_result, temp);
13848 if (!const_ok_for_output (rtl))
13852 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13853 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13854 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13855 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13861 case DEBUG_IMPLICIT_PTR:
13862 expansion_failed (NULL_TREE, rtl,
13863 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13869 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
13870 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
13871 if (REG_P (ENTRY_VALUE_EXP (rtl)))
13872 mem_loc_result->dw_loc_oprnd1.v.val_loc
13873 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
13874 VAR_INIT_STATUS_INITIALIZED);
13875 else if (MEM_P (ENTRY_VALUE_EXP (rtl)) && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
13877 dw_loc_descr_ref ref
13878 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), GET_MODE (rtl),
13879 VAR_INIT_STATUS_INITIALIZED);
13882 mem_loc_result->dw_loc_oprnd1.v.val_loc = ref;
13885 gcc_unreachable ();
13886 return mem_loc_result;
13889 /* Extract the PLUS expression nested inside and fall into
13890 PLUS code below. */
13891 rtl = XEXP (rtl, 1);
13896 /* Turn these into a PLUS expression and fall into the PLUS code
13898 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13899 GEN_INT (GET_CODE (rtl) == PRE_INC
13900 ? GET_MODE_UNIT_SIZE (mode)
13901 : -GET_MODE_UNIT_SIZE (mode)));
13903 /* ... fall through ... */
13907 if (is_based_loc (rtl))
13908 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13909 INTVAL (XEXP (rtl, 1)),
13910 VAR_INIT_STATUS_INITIALIZED);
13913 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13914 VAR_INIT_STATUS_INITIALIZED);
13915 if (mem_loc_result == 0)
13918 if (CONST_INT_P (XEXP (rtl, 1)))
13919 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13922 dw_loc_descr_ref mem_loc_result2
13923 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13924 VAR_INIT_STATUS_INITIALIZED);
13925 if (mem_loc_result2 == 0)
13927 add_loc_descr (&mem_loc_result, mem_loc_result2);
13928 add_loc_descr (&mem_loc_result,
13929 new_loc_descr (DW_OP_plus, 0, 0));
13934 /* If a pseudo-reg is optimized away, it is possible for it to
13935 be replaced with a MEM containing a multiply or shift. */
13977 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13978 VAR_INIT_STATUS_INITIALIZED);
13979 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13980 VAR_INIT_STATUS_INITIALIZED);
13982 if (op0 == 0 || op1 == 0)
13985 mem_loc_result = op0;
13986 add_loc_descr (&mem_loc_result, op1);
13987 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13991 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13992 VAR_INIT_STATUS_INITIALIZED);
13993 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13994 VAR_INIT_STATUS_INITIALIZED);
13996 if (op0 == 0 || op1 == 0)
13999 mem_loc_result = op0;
14000 add_loc_descr (&mem_loc_result, op1);
14001 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14002 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14003 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
14004 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14005 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
14021 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14022 VAR_INIT_STATUS_INITIALIZED);
14027 mem_loc_result = op0;
14028 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14032 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
14060 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14061 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14065 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14067 if (op_mode == VOIDmode)
14068 op_mode = GET_MODE (XEXP (rtl, 1));
14069 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14072 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14073 VAR_INIT_STATUS_INITIALIZED);
14074 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14075 VAR_INIT_STATUS_INITIALIZED);
14077 if (op0 == 0 || op1 == 0)
14080 if (op_mode != VOIDmode
14081 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14083 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
14084 shift *= BITS_PER_UNIT;
14085 /* For eq/ne, if the operands are known to be zero-extended,
14086 there is no need to do the fancy shifting up. */
14087 if (op == DW_OP_eq || op == DW_OP_ne)
14089 dw_loc_descr_ref last0, last1;
14091 last0->dw_loc_next != NULL;
14092 last0 = last0->dw_loc_next)
14095 last1->dw_loc_next != NULL;
14096 last1 = last1->dw_loc_next)
14098 /* deref_size zero extends, and for constants we can check
14099 whether they are zero extended or not. */
14100 if (((last0->dw_loc_opc == DW_OP_deref_size
14101 && last0->dw_loc_oprnd1.v.val_int
14102 <= GET_MODE_SIZE (op_mode))
14103 || (CONST_INT_P (XEXP (rtl, 0))
14104 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14105 == (INTVAL (XEXP (rtl, 0))
14106 & GET_MODE_MASK (op_mode))))
14107 && ((last1->dw_loc_opc == DW_OP_deref_size
14108 && last1->dw_loc_oprnd1.v.val_int
14109 <= GET_MODE_SIZE (op_mode))
14110 || (CONST_INT_P (XEXP (rtl, 1))
14111 && (unsigned HOST_WIDE_INT)
14112 INTVAL (XEXP (rtl, 1))
14113 == (INTVAL (XEXP (rtl, 1))
14114 & GET_MODE_MASK (op_mode)))))
14117 add_loc_descr (&op0, int_loc_descriptor (shift));
14118 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14119 if (CONST_INT_P (XEXP (rtl, 1)))
14120 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14123 add_loc_descr (&op1, int_loc_descriptor (shift));
14124 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14130 mem_loc_result = op0;
14131 add_loc_descr (&mem_loc_result, op1);
14132 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14133 if (STORE_FLAG_VALUE != 1)
14135 add_loc_descr (&mem_loc_result,
14136 int_loc_descriptor (STORE_FLAG_VALUE));
14137 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14158 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14159 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14163 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14165 if (op_mode == VOIDmode)
14166 op_mode = GET_MODE (XEXP (rtl, 1));
14167 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14170 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14171 VAR_INIT_STATUS_INITIALIZED);
14172 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14173 VAR_INIT_STATUS_INITIALIZED);
14175 if (op0 == 0 || op1 == 0)
14178 if (op_mode != VOIDmode
14179 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14181 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14182 dw_loc_descr_ref last0, last1;
14184 last0->dw_loc_next != NULL;
14185 last0 = last0->dw_loc_next)
14188 last1->dw_loc_next != NULL;
14189 last1 = last1->dw_loc_next)
14191 if (CONST_INT_P (XEXP (rtl, 0)))
14192 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14193 /* deref_size zero extends, so no need to mask it again. */
14194 else if (last0->dw_loc_opc != DW_OP_deref_size
14195 || last0->dw_loc_oprnd1.v.val_int
14196 > GET_MODE_SIZE (op_mode))
14198 add_loc_descr (&op0, int_loc_descriptor (mask));
14199 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14201 if (CONST_INT_P (XEXP (rtl, 1)))
14202 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14203 /* deref_size zero extends, so no need to mask it again. */
14204 else if (last1->dw_loc_opc != DW_OP_deref_size
14205 || last1->dw_loc_oprnd1.v.val_int
14206 > GET_MODE_SIZE (op_mode))
14208 add_loc_descr (&op1, int_loc_descriptor (mask));
14209 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14214 HOST_WIDE_INT bias = 1;
14215 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14216 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14217 if (CONST_INT_P (XEXP (rtl, 1)))
14218 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14219 + INTVAL (XEXP (rtl, 1)));
14221 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14231 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14232 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14233 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14236 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14237 VAR_INIT_STATUS_INITIALIZED);
14238 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14239 VAR_INIT_STATUS_INITIALIZED);
14241 if (op0 == 0 || op1 == 0)
14244 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14245 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14246 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14247 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14249 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14251 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14252 add_loc_descr (&op0, int_loc_descriptor (mask));
14253 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14254 add_loc_descr (&op1, int_loc_descriptor (mask));
14255 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14259 HOST_WIDE_INT bias = 1;
14260 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14261 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14262 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14265 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14267 int shift = DWARF2_ADDR_SIZE
14268 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14269 shift *= BITS_PER_UNIT;
14270 add_loc_descr (&op0, int_loc_descriptor (shift));
14271 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14272 add_loc_descr (&op1, int_loc_descriptor (shift));
14273 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14276 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14280 mem_loc_result = op0;
14281 add_loc_descr (&mem_loc_result, op1);
14282 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14284 dw_loc_descr_ref bra_node, drop_node;
14286 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14287 add_loc_descr (&mem_loc_result, bra_node);
14288 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14289 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14290 add_loc_descr (&mem_loc_result, drop_node);
14291 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14292 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14298 if (CONST_INT_P (XEXP (rtl, 1))
14299 && CONST_INT_P (XEXP (rtl, 2))
14300 && ((unsigned) INTVAL (XEXP (rtl, 1))
14301 + (unsigned) INTVAL (XEXP (rtl, 2))
14302 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14303 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14304 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14307 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14308 VAR_INIT_STATUS_INITIALIZED);
14311 if (GET_CODE (rtl) == SIGN_EXTRACT)
14315 mem_loc_result = op0;
14316 size = INTVAL (XEXP (rtl, 1));
14317 shift = INTVAL (XEXP (rtl, 2));
14318 if (BITS_BIG_ENDIAN)
14319 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14321 if (shift + size != (int) DWARF2_ADDR_SIZE)
14323 add_loc_descr (&mem_loc_result,
14324 int_loc_descriptor (DWARF2_ADDR_SIZE
14326 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14328 if (size != (int) DWARF2_ADDR_SIZE)
14330 add_loc_descr (&mem_loc_result,
14331 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14332 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14339 dw_loc_descr_ref op2, bra_node, drop_node;
14340 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14341 VAR_INIT_STATUS_INITIALIZED);
14342 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14343 VAR_INIT_STATUS_INITIALIZED);
14344 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
14345 VAR_INIT_STATUS_INITIALIZED);
14346 if (op0 == NULL || op1 == NULL || op2 == NULL)
14349 mem_loc_result = op1;
14350 add_loc_descr (&mem_loc_result, op2);
14351 add_loc_descr (&mem_loc_result, op0);
14352 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14353 add_loc_descr (&mem_loc_result, bra_node);
14354 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14355 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14356 add_loc_descr (&mem_loc_result, drop_node);
14357 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14358 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14366 /* In theory, we could implement the above. */
14367 /* DWARF cannot represent the unsigned compare operations
14394 case FLOAT_TRUNCATE:
14396 case UNSIGNED_FLOAT:
14399 case FRACT_CONVERT:
14400 case UNSIGNED_FRACT_CONVERT:
14402 case UNSIGNED_SAT_FRACT:
14414 case VEC_DUPLICATE:
14417 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14418 can't express it in the debug info. This can happen e.g. with some
14423 resolve_one_addr (&rtl, NULL);
14427 #ifdef ENABLE_CHECKING
14428 print_rtl (stderr, rtl);
14429 gcc_unreachable ();
14435 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14436 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14438 return mem_loc_result;
14441 /* Return a descriptor that describes the concatenation of two locations.
14442 This is typically a complex variable. */
14444 static dw_loc_descr_ref
14445 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14447 dw_loc_descr_ref cc_loc_result = NULL;
14448 dw_loc_descr_ref x0_ref
14449 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14450 dw_loc_descr_ref x1_ref
14451 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14453 if (x0_ref == 0 || x1_ref == 0)
14456 cc_loc_result = x0_ref;
14457 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14459 add_loc_descr (&cc_loc_result, x1_ref);
14460 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14462 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14463 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14465 return cc_loc_result;
14468 /* Return a descriptor that describes the concatenation of N
14471 static dw_loc_descr_ref
14472 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14475 dw_loc_descr_ref cc_loc_result = NULL;
14476 unsigned int n = XVECLEN (concatn, 0);
14478 for (i = 0; i < n; ++i)
14480 dw_loc_descr_ref ref;
14481 rtx x = XVECEXP (concatn, 0, i);
14483 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14487 add_loc_descr (&cc_loc_result, ref);
14488 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14491 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14492 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14494 return cc_loc_result;
14497 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14498 for DEBUG_IMPLICIT_PTR RTL. */
14500 static dw_loc_descr_ref
14501 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14503 dw_loc_descr_ref ret;
14508 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14509 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14510 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14511 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14512 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14513 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14516 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14517 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14518 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14522 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14523 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14528 /* Output a proper Dwarf location descriptor for a variable or parameter
14529 which is either allocated in a register or in a memory location. For a
14530 register, we just generate an OP_REG and the register number. For a
14531 memory location we provide a Dwarf postfix expression describing how to
14532 generate the (dynamic) address of the object onto the address stack.
14534 MODE is mode of the decl if this loc_descriptor is going to be used in
14535 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14536 allowed, VOIDmode otherwise.
14538 If we don't know how to describe it, return 0. */
14540 static dw_loc_descr_ref
14541 loc_descriptor (rtx rtl, enum machine_mode mode,
14542 enum var_init_status initialized)
14544 dw_loc_descr_ref loc_result = NULL;
14546 switch (GET_CODE (rtl))
14549 /* The case of a subreg may arise when we have a local (register)
14550 variable or a formal (register) parameter which doesn't quite fill
14551 up an entire register. For now, just assume that it is
14552 legitimate to make the Dwarf info refer to the whole register which
14553 contains the given subreg. */
14554 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14558 loc_result = reg_loc_descriptor (rtl, initialized);
14562 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14564 if (loc_result == NULL)
14565 loc_result = tls_mem_loc_descriptor (rtl);
14566 if (loc_result == NULL)
14568 rtx new_rtl = avoid_constant_pool_reference (rtl);
14569 if (new_rtl != rtl)
14570 loc_result = loc_descriptor (new_rtl, mode, initialized);
14575 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14580 loc_result = concatn_loc_descriptor (rtl, initialized);
14585 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14587 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14588 if (GET_CODE (loc) == EXPR_LIST)
14589 loc = XEXP (loc, 0);
14590 loc_result = loc_descriptor (loc, mode, initialized);
14594 rtl = XEXP (rtl, 1);
14599 rtvec par_elems = XVEC (rtl, 0);
14600 int num_elem = GET_NUM_ELEM (par_elems);
14601 enum machine_mode mode;
14604 /* Create the first one, so we have something to add to. */
14605 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14606 VOIDmode, initialized);
14607 if (loc_result == NULL)
14609 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14610 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14611 for (i = 1; i < num_elem; i++)
14613 dw_loc_descr_ref temp;
14615 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14616 VOIDmode, initialized);
14619 add_loc_descr (&loc_result, temp);
14620 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14621 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14627 if (mode != VOIDmode && mode != BLKmode)
14628 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14633 if (mode == VOIDmode)
14634 mode = GET_MODE (rtl);
14636 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14638 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14640 /* Note that a CONST_DOUBLE rtx could represent either an integer
14641 or a floating-point constant. A CONST_DOUBLE is used whenever
14642 the constant requires more than one word in order to be
14643 adequately represented. We output CONST_DOUBLEs as blocks. */
14644 loc_result = new_loc_descr (DW_OP_implicit_value,
14645 GET_MODE_SIZE (mode), 0);
14646 if (SCALAR_FLOAT_MODE_P (mode))
14648 unsigned int length = GET_MODE_SIZE (mode);
14649 unsigned char *array
14650 = (unsigned char*) ggc_alloc_atomic (length);
14652 insert_float (rtl, array);
14653 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14654 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14655 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14656 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14660 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14661 loc_result->dw_loc_oprnd2.v.val_double
14662 = rtx_to_double_int (rtl);
14668 if (mode == VOIDmode)
14669 mode = GET_MODE (rtl);
14671 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14673 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14674 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14675 unsigned char *array = (unsigned char *)
14676 ggc_alloc_atomic (length * elt_size);
14680 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14681 switch (GET_MODE_CLASS (mode))
14683 case MODE_VECTOR_INT:
14684 for (i = 0, p = array; i < length; i++, p += elt_size)
14686 rtx elt = CONST_VECTOR_ELT (rtl, i);
14687 double_int val = rtx_to_double_int (elt);
14689 if (elt_size <= sizeof (HOST_WIDE_INT))
14690 insert_int (double_int_to_shwi (val), elt_size, p);
14693 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14694 insert_double (val, p);
14699 case MODE_VECTOR_FLOAT:
14700 for (i = 0, p = array; i < length; i++, p += elt_size)
14702 rtx elt = CONST_VECTOR_ELT (rtl, i);
14703 insert_float (elt, p);
14708 gcc_unreachable ();
14711 loc_result = new_loc_descr (DW_OP_implicit_value,
14712 length * elt_size, 0);
14713 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14714 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14715 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14716 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14721 if (mode == VOIDmode
14722 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14723 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14724 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14726 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14731 if (!const_ok_for_output (rtl))
14734 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14735 && (dwarf_version >= 4 || !dwarf_strict))
14737 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14738 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14739 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14740 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14741 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14745 case DEBUG_IMPLICIT_PTR:
14746 loc_result = implicit_ptr_descriptor (rtl, 0);
14750 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14751 && CONST_INT_P (XEXP (rtl, 1)))
14754 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14759 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14760 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14761 && (dwarf_version >= 4 || !dwarf_strict))
14763 /* Value expression. */
14764 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14766 add_loc_descr (&loc_result,
14767 new_loc_descr (DW_OP_stack_value, 0, 0));
14775 /* We need to figure out what section we should use as the base for the
14776 address ranges where a given location is valid.
14777 1. If this particular DECL has a section associated with it, use that.
14778 2. If this function has a section associated with it, use that.
14779 3. Otherwise, use the text section.
14780 XXX: If you split a variable across multiple sections, we won't notice. */
14782 static const char *
14783 secname_for_decl (const_tree decl)
14785 const char *secname;
14787 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14789 tree sectree = DECL_SECTION_NAME (decl);
14790 secname = TREE_STRING_POINTER (sectree);
14792 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14794 tree sectree = DECL_SECTION_NAME (current_function_decl);
14795 secname = TREE_STRING_POINTER (sectree);
14797 else if (cfun && in_cold_section_p)
14798 secname = crtl->subsections.cold_section_label;
14800 secname = text_section_label;
14805 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14808 decl_by_reference_p (tree decl)
14810 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14811 || TREE_CODE (decl) == VAR_DECL)
14812 && DECL_BY_REFERENCE (decl));
14815 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14818 static dw_loc_descr_ref
14819 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14820 enum var_init_status initialized)
14822 int have_address = 0;
14823 dw_loc_descr_ref descr;
14824 enum machine_mode mode;
14826 if (want_address != 2)
14828 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14830 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14832 varloc = PAT_VAR_LOCATION_LOC (varloc);
14833 if (GET_CODE (varloc) == EXPR_LIST)
14834 varloc = XEXP (varloc, 0);
14835 mode = GET_MODE (varloc);
14836 if (MEM_P (varloc))
14838 rtx addr = XEXP (varloc, 0);
14839 descr = mem_loc_descriptor (addr, mode, initialized);
14844 rtx x = avoid_constant_pool_reference (varloc);
14846 descr = mem_loc_descriptor (x, mode, initialized);
14850 descr = mem_loc_descriptor (varloc, mode, initialized);
14857 if (GET_CODE (varloc) == VAR_LOCATION)
14858 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14860 mode = DECL_MODE (loc);
14861 descr = loc_descriptor (varloc, mode, initialized);
14868 if (want_address == 2 && !have_address
14869 && (dwarf_version >= 4 || !dwarf_strict))
14871 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14873 expansion_failed (loc, NULL_RTX,
14874 "DWARF address size mismatch");
14877 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14880 /* Show if we can't fill the request for an address. */
14881 if (want_address && !have_address)
14883 expansion_failed (loc, NULL_RTX,
14884 "Want address and only have value");
14888 /* If we've got an address and don't want one, dereference. */
14889 if (!want_address && have_address)
14891 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14892 enum dwarf_location_atom op;
14894 if (size > DWARF2_ADDR_SIZE || size == -1)
14896 expansion_failed (loc, NULL_RTX,
14897 "DWARF address size mismatch");
14900 else if (size == DWARF2_ADDR_SIZE)
14903 op = DW_OP_deref_size;
14905 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14911 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14912 if it is not possible. */
14914 static dw_loc_descr_ref
14915 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14917 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14918 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14919 else if (dwarf_version >= 3 || !dwarf_strict)
14920 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14925 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14926 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14928 static dw_loc_descr_ref
14929 dw_sra_loc_expr (tree decl, rtx loc)
14932 unsigned int padsize = 0;
14933 dw_loc_descr_ref descr, *descr_tail;
14934 unsigned HOST_WIDE_INT decl_size;
14936 enum var_init_status initialized;
14938 if (DECL_SIZE (decl) == NULL
14939 || !host_integerp (DECL_SIZE (decl), 1))
14942 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14944 descr_tail = &descr;
14946 for (p = loc; p; p = XEXP (p, 1))
14948 unsigned int bitsize = decl_piece_bitsize (p);
14949 rtx loc_note = *decl_piece_varloc_ptr (p);
14950 dw_loc_descr_ref cur_descr;
14951 dw_loc_descr_ref *tail, last = NULL;
14952 unsigned int opsize = 0;
14954 if (loc_note == NULL_RTX
14955 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14957 padsize += bitsize;
14960 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14961 varloc = NOTE_VAR_LOCATION (loc_note);
14962 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14963 if (cur_descr == NULL)
14965 padsize += bitsize;
14969 /* Check that cur_descr either doesn't use
14970 DW_OP_*piece operations, or their sum is equal
14971 to bitsize. Otherwise we can't embed it. */
14972 for (tail = &cur_descr; *tail != NULL;
14973 tail = &(*tail)->dw_loc_next)
14974 if ((*tail)->dw_loc_opc == DW_OP_piece)
14976 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14980 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14982 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14986 if (last != NULL && opsize != bitsize)
14988 padsize += bitsize;
14992 /* If there is a hole, add DW_OP_*piece after empty DWARF
14993 expression, which means that those bits are optimized out. */
14996 if (padsize > decl_size)
14998 decl_size -= padsize;
14999 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
15000 if (*descr_tail == NULL)
15002 descr_tail = &(*descr_tail)->dw_loc_next;
15005 *descr_tail = cur_descr;
15007 if (bitsize > decl_size)
15009 decl_size -= bitsize;
15012 HOST_WIDE_INT offset = 0;
15013 if (GET_CODE (varloc) == VAR_LOCATION
15014 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15016 varloc = PAT_VAR_LOCATION_LOC (varloc);
15017 if (GET_CODE (varloc) == EXPR_LIST)
15018 varloc = XEXP (varloc, 0);
15022 if (GET_CODE (varloc) == CONST
15023 || GET_CODE (varloc) == SIGN_EXTEND
15024 || GET_CODE (varloc) == ZERO_EXTEND)
15025 varloc = XEXP (varloc, 0);
15026 else if (GET_CODE (varloc) == SUBREG)
15027 varloc = SUBREG_REG (varloc);
15032 /* DW_OP_bit_size offset should be zero for register
15033 or implicit location descriptions and empty location
15034 descriptions, but for memory addresses needs big endian
15036 if (MEM_P (varloc))
15038 unsigned HOST_WIDE_INT memsize
15039 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
15040 if (memsize != bitsize)
15042 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
15043 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
15045 if (memsize < bitsize)
15047 if (BITS_BIG_ENDIAN)
15048 offset = memsize - bitsize;
15052 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
15053 if (*descr_tail == NULL)
15055 descr_tail = &(*descr_tail)->dw_loc_next;
15059 /* If there were any non-empty expressions, add padding till the end of
15061 if (descr != NULL && decl_size != 0)
15063 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
15064 if (*descr_tail == NULL)
15070 /* Return the dwarf representation of the location list LOC_LIST of
15071 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
15074 static dw_loc_list_ref
15075 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
15077 const char *endname, *secname;
15079 enum var_init_status initialized;
15080 struct var_loc_node *node;
15081 dw_loc_descr_ref descr;
15082 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15083 dw_loc_list_ref list = NULL;
15084 dw_loc_list_ref *listp = &list;
15086 /* Now that we know what section we are using for a base,
15087 actually construct the list of locations.
15088 The first location information is what is passed to the
15089 function that creates the location list, and the remaining
15090 locations just get added on to that list.
15091 Note that we only know the start address for a location
15092 (IE location changes), so to build the range, we use
15093 the range [current location start, next location start].
15094 This means we have to special case the last node, and generate
15095 a range of [last location start, end of function label]. */
15097 secname = secname_for_decl (decl);
15099 for (node = loc_list->first; node; node = node->next)
15100 if (GET_CODE (node->loc) == EXPR_LIST
15101 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
15103 if (GET_CODE (node->loc) == EXPR_LIST)
15105 /* This requires DW_OP_{,bit_}piece, which is not usable
15106 inside DWARF expressions. */
15107 if (want_address != 2)
15109 descr = dw_sra_loc_expr (decl, node->loc);
15115 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15116 varloc = NOTE_VAR_LOCATION (node->loc);
15117 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15121 /* The variable has a location between NODE->LABEL and
15122 NODE->NEXT->LABEL. */
15124 endname = node->next->label;
15125 /* If the variable has a location at the last label
15126 it keeps its location until the end of function. */
15127 else if (!current_function_decl)
15128 endname = text_end_label;
15131 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15132 current_function_funcdef_no);
15133 endname = ggc_strdup (label_id);
15136 *listp = new_loc_list (descr, node->label, endname, secname);
15137 listp = &(*listp)->dw_loc_next;
15141 /* Try to avoid the overhead of a location list emitting a location
15142 expression instead, but only if we didn't have more than one
15143 location entry in the first place. If some entries were not
15144 representable, we don't want to pretend a single entry that was
15145 applies to the entire scope in which the variable is
15147 if (list && loc_list->first->next)
15153 /* Return if the loc_list has only single element and thus can be represented
15154 as location description. */
15157 single_element_loc_list_p (dw_loc_list_ref list)
15159 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15160 return !list->ll_symbol;
15163 /* To each location in list LIST add loc descr REF. */
15166 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15168 dw_loc_descr_ref copy;
15169 add_loc_descr (&list->expr, ref);
15170 list = list->dw_loc_next;
15173 copy = ggc_alloc_dw_loc_descr_node ();
15174 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15175 add_loc_descr (&list->expr, copy);
15176 while (copy->dw_loc_next)
15178 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15179 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15180 copy->dw_loc_next = new_copy;
15183 list = list->dw_loc_next;
15187 /* Given two lists RET and LIST
15188 produce location list that is result of adding expression in LIST
15189 to expression in RET on each possition in program.
15190 Might be destructive on both RET and LIST.
15192 TODO: We handle only simple cases of RET or LIST having at most one
15193 element. General case would inolve sorting the lists in program order
15194 and merging them that will need some additional work.
15195 Adding that will improve quality of debug info especially for SRA-ed
15199 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15208 if (!list->dw_loc_next)
15210 add_loc_descr_to_each (*ret, list->expr);
15213 if (!(*ret)->dw_loc_next)
15215 add_loc_descr_to_each (list, (*ret)->expr);
15219 expansion_failed (NULL_TREE, NULL_RTX,
15220 "Don't know how to merge two non-trivial"
15221 " location lists.\n");
15226 /* LOC is constant expression. Try a luck, look it up in constant
15227 pool and return its loc_descr of its address. */
15229 static dw_loc_descr_ref
15230 cst_pool_loc_descr (tree loc)
15232 /* Get an RTL for this, if something has been emitted. */
15233 rtx rtl = lookup_constant_def (loc);
15234 enum machine_mode mode;
15236 if (!rtl || !MEM_P (rtl))
15241 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15243 /* TODO: We might get more coverage if we was actually delaying expansion
15244 of all expressions till end of compilation when constant pools are fully
15246 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15248 expansion_failed (loc, NULL_RTX,
15249 "CST value in contant pool but not marked.");
15252 mode = GET_MODE (rtl);
15253 rtl = XEXP (rtl, 0);
15254 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15257 /* Return dw_loc_list representing address of addr_expr LOC
15258 by looking for innder INDIRECT_REF expression and turing it
15259 into simple arithmetics. */
15261 static dw_loc_list_ref
15262 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15265 HOST_WIDE_INT bitsize, bitpos, bytepos;
15266 enum machine_mode mode;
15268 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15269 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15271 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15272 &bitsize, &bitpos, &offset, &mode,
15273 &unsignedp, &volatilep, false);
15275 if (bitpos % BITS_PER_UNIT)
15277 expansion_failed (loc, NULL_RTX, "bitfield access");
15280 if (!INDIRECT_REF_P (obj))
15282 expansion_failed (obj,
15283 NULL_RTX, "no indirect ref in inner refrence");
15286 if (!offset && !bitpos)
15287 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15289 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15290 && (dwarf_version >= 4 || !dwarf_strict))
15292 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15297 /* Variable offset. */
15298 list_ret1 = loc_list_from_tree (offset, 0);
15299 if (list_ret1 == 0)
15301 add_loc_list (&list_ret, list_ret1);
15304 add_loc_descr_to_each (list_ret,
15305 new_loc_descr (DW_OP_plus, 0, 0));
15307 bytepos = bitpos / BITS_PER_UNIT;
15309 add_loc_descr_to_each (list_ret,
15310 new_loc_descr (DW_OP_plus_uconst,
15312 else if (bytepos < 0)
15313 loc_list_plus_const (list_ret, bytepos);
15314 add_loc_descr_to_each (list_ret,
15315 new_loc_descr (DW_OP_stack_value, 0, 0));
15321 /* Generate Dwarf location list representing LOC.
15322 If WANT_ADDRESS is false, expression computing LOC will be computed
15323 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15324 if WANT_ADDRESS is 2, expression computing address useable in location
15325 will be returned (i.e. DW_OP_reg can be used
15326 to refer to register values). */
15328 static dw_loc_list_ref
15329 loc_list_from_tree (tree loc, int want_address)
15331 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15332 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15333 int have_address = 0;
15334 enum dwarf_location_atom op;
15336 /* ??? Most of the time we do not take proper care for sign/zero
15337 extending the values properly. Hopefully this won't be a real
15340 switch (TREE_CODE (loc))
15343 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15346 case PLACEHOLDER_EXPR:
15347 /* This case involves extracting fields from an object to determine the
15348 position of other fields. We don't try to encode this here. The
15349 only user of this is Ada, which encodes the needed information using
15350 the names of types. */
15351 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15355 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15356 /* There are no opcodes for these operations. */
15359 case PREINCREMENT_EXPR:
15360 case PREDECREMENT_EXPR:
15361 case POSTINCREMENT_EXPR:
15362 case POSTDECREMENT_EXPR:
15363 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15364 /* There are no opcodes for these operations. */
15368 /* If we already want an address, see if there is INDIRECT_REF inside
15369 e.g. for &this->field. */
15372 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15373 (loc, want_address == 2);
15376 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15377 && (ret = cst_pool_loc_descr (loc)))
15380 /* Otherwise, process the argument and look for the address. */
15381 if (!list_ret && !ret)
15382 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15386 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15392 if (DECL_THREAD_LOCAL_P (loc))
15395 enum dwarf_location_atom first_op;
15396 enum dwarf_location_atom second_op;
15397 bool dtprel = false;
15399 if (targetm.have_tls)
15401 /* If this is not defined, we have no way to emit the
15403 if (!targetm.asm_out.output_dwarf_dtprel)
15406 /* The way DW_OP_GNU_push_tls_address is specified, we
15407 can only look up addresses of objects in the current
15408 module. We used DW_OP_addr as first op, but that's
15409 wrong, because DW_OP_addr is relocated by the debug
15410 info consumer, while DW_OP_GNU_push_tls_address
15411 operand shouldn't be. */
15412 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15414 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15416 second_op = DW_OP_GNU_push_tls_address;
15420 if (!targetm.emutls.debug_form_tls_address
15421 || !(dwarf_version >= 3 || !dwarf_strict))
15423 /* We stuffed the control variable into the DECL_VALUE_EXPR
15424 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15425 no longer appear in gimple code. We used the control
15426 variable in specific so that we could pick it up here. */
15427 loc = DECL_VALUE_EXPR (loc);
15428 first_op = DW_OP_addr;
15429 second_op = DW_OP_form_tls_address;
15432 rtl = rtl_for_decl_location (loc);
15433 if (rtl == NULL_RTX)
15438 rtl = XEXP (rtl, 0);
15439 if (! CONSTANT_P (rtl))
15442 ret = new_loc_descr (first_op, 0, 0);
15443 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15444 ret->dw_loc_oprnd1.v.val_addr = rtl;
15445 ret->dtprel = dtprel;
15447 ret1 = new_loc_descr (second_op, 0, 0);
15448 add_loc_descr (&ret, ret1);
15457 if (DECL_HAS_VALUE_EXPR_P (loc))
15458 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15462 case FUNCTION_DECL:
15465 var_loc_list *loc_list = lookup_decl_loc (loc);
15467 if (loc_list && loc_list->first)
15469 list_ret = dw_loc_list (loc_list, loc, want_address);
15470 have_address = want_address != 0;
15473 rtl = rtl_for_decl_location (loc);
15474 if (rtl == NULL_RTX)
15476 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15479 else if (CONST_INT_P (rtl))
15481 HOST_WIDE_INT val = INTVAL (rtl);
15482 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15483 val &= GET_MODE_MASK (DECL_MODE (loc));
15484 ret = int_loc_descriptor (val);
15486 else if (GET_CODE (rtl) == CONST_STRING)
15488 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15491 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15493 ret = new_loc_descr (DW_OP_addr, 0, 0);
15494 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15495 ret->dw_loc_oprnd1.v.val_addr = rtl;
15499 enum machine_mode mode;
15501 /* Certain constructs can only be represented at top-level. */
15502 if (want_address == 2)
15504 ret = loc_descriptor (rtl, VOIDmode,
15505 VAR_INIT_STATUS_INITIALIZED);
15510 mode = GET_MODE (rtl);
15513 rtl = XEXP (rtl, 0);
15516 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15519 expansion_failed (loc, rtl,
15520 "failed to produce loc descriptor for rtl");
15527 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15531 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15535 case COMPOUND_EXPR:
15536 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15539 case VIEW_CONVERT_EXPR:
15542 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15544 case COMPONENT_REF:
15545 case BIT_FIELD_REF:
15547 case ARRAY_RANGE_REF:
15548 case REALPART_EXPR:
15549 case IMAGPART_EXPR:
15552 HOST_WIDE_INT bitsize, bitpos, bytepos;
15553 enum machine_mode mode;
15555 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15557 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15558 &unsignedp, &volatilep, false);
15560 gcc_assert (obj != loc);
15562 list_ret = loc_list_from_tree (obj,
15564 && !bitpos && !offset ? 2 : 1);
15565 /* TODO: We can extract value of the small expression via shifting even
15566 for nonzero bitpos. */
15569 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15571 expansion_failed (loc, NULL_RTX,
15572 "bitfield access");
15576 if (offset != NULL_TREE)
15578 /* Variable offset. */
15579 list_ret1 = loc_list_from_tree (offset, 0);
15580 if (list_ret1 == 0)
15582 add_loc_list (&list_ret, list_ret1);
15585 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15588 bytepos = bitpos / BITS_PER_UNIT;
15590 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15591 else if (bytepos < 0)
15592 loc_list_plus_const (list_ret, bytepos);
15599 if ((want_address || !host_integerp (loc, 0))
15600 && (ret = cst_pool_loc_descr (loc)))
15602 else if (want_address == 2
15603 && host_integerp (loc, 0)
15604 && (ret = address_of_int_loc_descriptor
15605 (int_size_in_bytes (TREE_TYPE (loc)),
15606 tree_low_cst (loc, 0))))
15608 else if (host_integerp (loc, 0))
15609 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15612 expansion_failed (loc, NULL_RTX,
15613 "Integer operand is not host integer");
15622 if ((ret = cst_pool_loc_descr (loc)))
15625 /* We can construct small constants here using int_loc_descriptor. */
15626 expansion_failed (loc, NULL_RTX,
15627 "constructor or constant not in constant pool");
15630 case TRUTH_AND_EXPR:
15631 case TRUTH_ANDIF_EXPR:
15636 case TRUTH_XOR_EXPR:
15641 case TRUTH_OR_EXPR:
15642 case TRUTH_ORIF_EXPR:
15647 case FLOOR_DIV_EXPR:
15648 case CEIL_DIV_EXPR:
15649 case ROUND_DIV_EXPR:
15650 case TRUNC_DIV_EXPR:
15651 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15660 case FLOOR_MOD_EXPR:
15661 case CEIL_MOD_EXPR:
15662 case ROUND_MOD_EXPR:
15663 case TRUNC_MOD_EXPR:
15664 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15669 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15670 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15671 if (list_ret == 0 || list_ret1 == 0)
15674 add_loc_list (&list_ret, list_ret1);
15677 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15678 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15679 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15680 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15681 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15693 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15696 case POINTER_PLUS_EXPR:
15698 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15700 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15704 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15712 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15719 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15726 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15733 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15748 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15749 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15750 if (list_ret == 0 || list_ret1 == 0)
15753 add_loc_list (&list_ret, list_ret1);
15756 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15759 case TRUTH_NOT_EXPR:
15773 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15777 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15783 const enum tree_code code =
15784 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15786 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15787 build2 (code, integer_type_node,
15788 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15789 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15792 /* ... fall through ... */
15796 dw_loc_descr_ref lhs
15797 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15798 dw_loc_list_ref rhs
15799 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15800 dw_loc_descr_ref bra_node, jump_node, tmp;
15802 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15803 if (list_ret == 0 || lhs == 0 || rhs == 0)
15806 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15807 add_loc_descr_to_each (list_ret, bra_node);
15809 add_loc_list (&list_ret, rhs);
15810 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15811 add_loc_descr_to_each (list_ret, jump_node);
15813 add_loc_descr_to_each (list_ret, lhs);
15814 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15815 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15817 /* ??? Need a node to point the skip at. Use a nop. */
15818 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15819 add_loc_descr_to_each (list_ret, tmp);
15820 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15821 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15825 case FIX_TRUNC_EXPR:
15829 /* Leave front-end specific codes as simply unknown. This comes
15830 up, for instance, with the C STMT_EXPR. */
15831 if ((unsigned int) TREE_CODE (loc)
15832 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15834 expansion_failed (loc, NULL_RTX,
15835 "language specific tree node");
15839 #ifdef ENABLE_CHECKING
15840 /* Otherwise this is a generic code; we should just lists all of
15841 these explicitly. We forgot one. */
15842 gcc_unreachable ();
15844 /* In a release build, we want to degrade gracefully: better to
15845 generate incomplete debugging information than to crash. */
15850 if (!ret && !list_ret)
15853 if (want_address == 2 && !have_address
15854 && (dwarf_version >= 4 || !dwarf_strict))
15856 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15858 expansion_failed (loc, NULL_RTX,
15859 "DWARF address size mismatch");
15863 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15865 add_loc_descr_to_each (list_ret,
15866 new_loc_descr (DW_OP_stack_value, 0, 0));
15869 /* Show if we can't fill the request for an address. */
15870 if (want_address && !have_address)
15872 expansion_failed (loc, NULL_RTX,
15873 "Want address and only have value");
15877 gcc_assert (!ret || !list_ret);
15879 /* If we've got an address and don't want one, dereference. */
15880 if (!want_address && have_address)
15882 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15884 if (size > DWARF2_ADDR_SIZE || size == -1)
15886 expansion_failed (loc, NULL_RTX,
15887 "DWARF address size mismatch");
15890 else if (size == DWARF2_ADDR_SIZE)
15893 op = DW_OP_deref_size;
15896 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15898 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15901 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15906 /* Same as above but return only single location expression. */
15907 static dw_loc_descr_ref
15908 loc_descriptor_from_tree (tree loc, int want_address)
15910 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15913 if (ret->dw_loc_next)
15915 expansion_failed (loc, NULL_RTX,
15916 "Location list where only loc descriptor needed");
15922 /* Given a value, round it up to the lowest multiple of `boundary'
15923 which is not less than the value itself. */
15925 static inline HOST_WIDE_INT
15926 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15928 return (((value + boundary - 1) / boundary) * boundary);
15931 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15932 pointer to the declared type for the relevant field variable, or return
15933 `integer_type_node' if the given node turns out to be an
15934 ERROR_MARK node. */
15937 field_type (const_tree decl)
15941 if (TREE_CODE (decl) == ERROR_MARK)
15942 return integer_type_node;
15944 type = DECL_BIT_FIELD_TYPE (decl);
15945 if (type == NULL_TREE)
15946 type = TREE_TYPE (decl);
15951 /* Given a pointer to a tree node, return the alignment in bits for
15952 it, or else return BITS_PER_WORD if the node actually turns out to
15953 be an ERROR_MARK node. */
15955 static inline unsigned
15956 simple_type_align_in_bits (const_tree type)
15958 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15961 static inline unsigned
15962 simple_decl_align_in_bits (const_tree decl)
15964 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15967 /* Return the result of rounding T up to ALIGN. */
15969 static inline double_int
15970 round_up_to_align (double_int t, unsigned int align)
15972 double_int alignd = uhwi_to_double_int (align);
15973 t = double_int_add (t, alignd);
15974 t = double_int_add (t, double_int_minus_one);
15975 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
15976 t = double_int_mul (t, alignd);
15980 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15981 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15982 or return 0 if we are unable to determine what that offset is, either
15983 because the argument turns out to be a pointer to an ERROR_MARK node, or
15984 because the offset is actually variable. (We can't handle the latter case
15987 static HOST_WIDE_INT
15988 field_byte_offset (const_tree decl)
15990 double_int object_offset_in_bits;
15991 double_int object_offset_in_bytes;
15992 double_int bitpos_int;
15994 if (TREE_CODE (decl) == ERROR_MARK)
15997 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15999 /* We cannot yet cope with fields whose positions are variable, so
16000 for now, when we see such things, we simply return 0. Someday, we may
16001 be able to handle such cases, but it will be damn difficult. */
16002 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
16005 bitpos_int = tree_to_double_int (bit_position (decl));
16007 #ifdef PCC_BITFIELD_TYPE_MATTERS
16008 if (PCC_BITFIELD_TYPE_MATTERS)
16011 tree field_size_tree;
16012 double_int deepest_bitpos;
16013 double_int field_size_in_bits;
16014 unsigned int type_align_in_bits;
16015 unsigned int decl_align_in_bits;
16016 double_int type_size_in_bits;
16018 type = field_type (decl);
16019 type_size_in_bits = double_int_type_size_in_bits (type);
16020 type_align_in_bits = simple_type_align_in_bits (type);
16022 field_size_tree = DECL_SIZE (decl);
16024 /* The size could be unspecified if there was an error, or for
16025 a flexible array member. */
16026 if (!field_size_tree)
16027 field_size_tree = bitsize_zero_node;
16029 /* If the size of the field is not constant, use the type size. */
16030 if (TREE_CODE (field_size_tree) == INTEGER_CST)
16031 field_size_in_bits = tree_to_double_int (field_size_tree);
16033 field_size_in_bits = type_size_in_bits;
16035 decl_align_in_bits = simple_decl_align_in_bits (decl);
16037 /* The GCC front-end doesn't make any attempt to keep track of the
16038 starting bit offset (relative to the start of the containing
16039 structure type) of the hypothetical "containing object" for a
16040 bit-field. Thus, when computing the byte offset value for the
16041 start of the "containing object" of a bit-field, we must deduce
16042 this information on our own. This can be rather tricky to do in
16043 some cases. For example, handling the following structure type
16044 definition when compiling for an i386/i486 target (which only
16045 aligns long long's to 32-bit boundaries) can be very tricky:
16047 struct S { int field1; long long field2:31; };
16049 Fortunately, there is a simple rule-of-thumb which can be used
16050 in such cases. When compiling for an i386/i486, GCC will
16051 allocate 8 bytes for the structure shown above. It decides to
16052 do this based upon one simple rule for bit-field allocation.
16053 GCC allocates each "containing object" for each bit-field at
16054 the first (i.e. lowest addressed) legitimate alignment boundary
16055 (based upon the required minimum alignment for the declared
16056 type of the field) which it can possibly use, subject to the
16057 condition that there is still enough available space remaining
16058 in the containing object (when allocated at the selected point)
16059 to fully accommodate all of the bits of the bit-field itself.
16061 This simple rule makes it obvious why GCC allocates 8 bytes for
16062 each object of the structure type shown above. When looking
16063 for a place to allocate the "containing object" for `field2',
16064 the compiler simply tries to allocate a 64-bit "containing
16065 object" at each successive 32-bit boundary (starting at zero)
16066 until it finds a place to allocate that 64- bit field such that
16067 at least 31 contiguous (and previously unallocated) bits remain
16068 within that selected 64 bit field. (As it turns out, for the
16069 example above, the compiler finds it is OK to allocate the
16070 "containing object" 64-bit field at bit-offset zero within the
16073 Here we attempt to work backwards from the limited set of facts
16074 we're given, and we try to deduce from those facts, where GCC
16075 must have believed that the containing object started (within
16076 the structure type). The value we deduce is then used (by the
16077 callers of this routine) to generate DW_AT_location and
16078 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16079 the case of DW_AT_location, regular fields as well). */
16081 /* Figure out the bit-distance from the start of the structure to
16082 the "deepest" bit of the bit-field. */
16083 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16085 /* This is the tricky part. Use some fancy footwork to deduce
16086 where the lowest addressed bit of the containing object must
16088 object_offset_in_bits
16089 = double_int_sub (deepest_bitpos, type_size_in_bits);
16091 /* Round up to type_align by default. This works best for
16093 object_offset_in_bits
16094 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16096 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16098 object_offset_in_bits
16099 = double_int_sub (deepest_bitpos, type_size_in_bits);
16101 /* Round up to decl_align instead. */
16102 object_offset_in_bits
16103 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16107 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16108 object_offset_in_bits = bitpos_int;
16110 object_offset_in_bytes
16111 = double_int_div (object_offset_in_bits,
16112 uhwi_to_double_int (BITS_PER_UNIT), true,
16114 return double_int_to_shwi (object_offset_in_bytes);
16117 /* The following routines define various Dwarf attributes and any data
16118 associated with them. */
16120 /* Add a location description attribute value to a DIE.
16122 This emits location attributes suitable for whole variables and
16123 whole parameters. Note that the location attributes for struct fields are
16124 generated by the routine `data_member_location_attribute' below. */
16127 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16128 dw_loc_list_ref descr)
16132 if (single_element_loc_list_p (descr))
16133 add_AT_loc (die, attr_kind, descr->expr);
16135 add_AT_loc_list (die, attr_kind, descr);
16138 /* Add DW_AT_accessibility attribute to DIE if needed. */
16141 add_accessibility_attribute (dw_die_ref die, tree decl)
16143 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16144 children, otherwise the default is DW_ACCESS_public. In DWARF2
16145 the default has always been DW_ACCESS_public. */
16146 if (TREE_PROTECTED (decl))
16147 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16148 else if (TREE_PRIVATE (decl))
16150 if (dwarf_version == 2
16151 || die->die_parent == NULL
16152 || die->die_parent->die_tag != DW_TAG_class_type)
16153 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16155 else if (dwarf_version > 2
16157 && die->die_parent->die_tag == DW_TAG_class_type)
16158 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16161 /* Attach the specialized form of location attribute used for data members of
16162 struct and union types. In the special case of a FIELD_DECL node which
16163 represents a bit-field, the "offset" part of this special location
16164 descriptor must indicate the distance in bytes from the lowest-addressed
16165 byte of the containing struct or union type to the lowest-addressed byte of
16166 the "containing object" for the bit-field. (See the `field_byte_offset'
16169 For any given bit-field, the "containing object" is a hypothetical object
16170 (of some integral or enum type) within which the given bit-field lives. The
16171 type of this hypothetical "containing object" is always the same as the
16172 declared type of the individual bit-field itself (for GCC anyway... the
16173 DWARF spec doesn't actually mandate this). Note that it is the size (in
16174 bytes) of the hypothetical "containing object" which will be given in the
16175 DW_AT_byte_size attribute for this bit-field. (See the
16176 `byte_size_attribute' function below.) It is also used when calculating the
16177 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16178 function below.) */
16181 add_data_member_location_attribute (dw_die_ref die, tree decl)
16183 HOST_WIDE_INT offset;
16184 dw_loc_descr_ref loc_descr = 0;
16186 if (TREE_CODE (decl) == TREE_BINFO)
16188 /* We're working on the TAG_inheritance for a base class. */
16189 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16191 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16192 aren't at a fixed offset from all (sub)objects of the same
16193 type. We need to extract the appropriate offset from our
16194 vtable. The following dwarf expression means
16196 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16198 This is specific to the V3 ABI, of course. */
16200 dw_loc_descr_ref tmp;
16202 /* Make a copy of the object address. */
16203 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16204 add_loc_descr (&loc_descr, tmp);
16206 /* Extract the vtable address. */
16207 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16208 add_loc_descr (&loc_descr, tmp);
16210 /* Calculate the address of the offset. */
16211 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16212 gcc_assert (offset < 0);
16214 tmp = int_loc_descriptor (-offset);
16215 add_loc_descr (&loc_descr, tmp);
16216 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16217 add_loc_descr (&loc_descr, tmp);
16219 /* Extract the offset. */
16220 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16221 add_loc_descr (&loc_descr, tmp);
16223 /* Add it to the object address. */
16224 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16225 add_loc_descr (&loc_descr, tmp);
16228 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16231 offset = field_byte_offset (decl);
16235 if (dwarf_version > 2)
16237 /* Don't need to output a location expression, just the constant. */
16239 add_AT_int (die, DW_AT_data_member_location, offset);
16241 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16246 enum dwarf_location_atom op;
16248 /* The DWARF2 standard says that we should assume that the structure
16249 address is already on the stack, so we can specify a structure
16250 field address by using DW_OP_plus_uconst. */
16252 #ifdef MIPS_DEBUGGING_INFO
16253 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16254 operator correctly. It works only if we leave the offset on the
16258 op = DW_OP_plus_uconst;
16261 loc_descr = new_loc_descr (op, offset, 0);
16265 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16268 /* Writes integer values to dw_vec_const array. */
16271 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16275 *dest++ = val & 0xff;
16281 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16283 static HOST_WIDE_INT
16284 extract_int (const unsigned char *src, unsigned int size)
16286 HOST_WIDE_INT val = 0;
16292 val |= *--src & 0xff;
16298 /* Writes double_int values to dw_vec_const array. */
16301 insert_double (double_int val, unsigned char *dest)
16303 unsigned char *p0 = dest;
16304 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16306 if (WORDS_BIG_ENDIAN)
16312 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16313 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16316 /* Writes floating point values to dw_vec_const array. */
16319 insert_float (const_rtx rtl, unsigned char *array)
16321 REAL_VALUE_TYPE rv;
16325 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16326 real_to_target (val, &rv, GET_MODE (rtl));
16328 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16329 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16331 insert_int (val[i], 4, array);
16336 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16337 does not have a "location" either in memory or in a register. These
16338 things can arise in GNU C when a constant is passed as an actual parameter
16339 to an inlined function. They can also arise in C++ where declared
16340 constants do not necessarily get memory "homes". */
16343 add_const_value_attribute (dw_die_ref die, rtx rtl)
16345 switch (GET_CODE (rtl))
16349 HOST_WIDE_INT val = INTVAL (rtl);
16352 add_AT_int (die, DW_AT_const_value, val);
16354 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16359 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16360 floating-point constant. A CONST_DOUBLE is used whenever the
16361 constant requires more than one word in order to be adequately
16364 enum machine_mode mode = GET_MODE (rtl);
16366 if (SCALAR_FLOAT_MODE_P (mode))
16368 unsigned int length = GET_MODE_SIZE (mode);
16369 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16371 insert_float (rtl, array);
16372 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16375 add_AT_double (die, DW_AT_const_value,
16376 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16382 enum machine_mode mode = GET_MODE (rtl);
16383 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16384 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16385 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16386 (length * elt_size);
16390 switch (GET_MODE_CLASS (mode))
16392 case MODE_VECTOR_INT:
16393 for (i = 0, p = array; i < length; i++, p += elt_size)
16395 rtx elt = CONST_VECTOR_ELT (rtl, i);
16396 double_int val = rtx_to_double_int (elt);
16398 if (elt_size <= sizeof (HOST_WIDE_INT))
16399 insert_int (double_int_to_shwi (val), elt_size, p);
16402 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16403 insert_double (val, p);
16408 case MODE_VECTOR_FLOAT:
16409 for (i = 0, p = array; i < length; i++, p += elt_size)
16411 rtx elt = CONST_VECTOR_ELT (rtl, i);
16412 insert_float (elt, p);
16417 gcc_unreachable ();
16420 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16425 if (dwarf_version >= 4 || !dwarf_strict)
16427 dw_loc_descr_ref loc_result;
16428 resolve_one_addr (&rtl, NULL);
16430 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16431 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16432 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16433 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16434 add_AT_loc (die, DW_AT_location, loc_result);
16435 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16441 if (CONSTANT_P (XEXP (rtl, 0)))
16442 return add_const_value_attribute (die, XEXP (rtl, 0));
16445 if (!const_ok_for_output (rtl))
16448 if (dwarf_version >= 4 || !dwarf_strict)
16453 /* In cases where an inlined instance of an inline function is passed
16454 the address of an `auto' variable (which is local to the caller) we
16455 can get a situation where the DECL_RTL of the artificial local
16456 variable (for the inlining) which acts as a stand-in for the
16457 corresponding formal parameter (of the inline function) will look
16458 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16459 exactly a compile-time constant expression, but it isn't the address
16460 of the (artificial) local variable either. Rather, it represents the
16461 *value* which the artificial local variable always has during its
16462 lifetime. We currently have no way to represent such quasi-constant
16463 values in Dwarf, so for now we just punt and generate nothing. */
16471 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16472 && MEM_READONLY_P (rtl)
16473 && GET_MODE (rtl) == BLKmode)
16475 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16481 /* No other kinds of rtx should be possible here. */
16482 gcc_unreachable ();
16487 /* Determine whether the evaluation of EXPR references any variables
16488 or functions which aren't otherwise used (and therefore may not be
16491 reference_to_unused (tree * tp, int * walk_subtrees,
16492 void * data ATTRIBUTE_UNUSED)
16494 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16495 *walk_subtrees = 0;
16497 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16498 && ! TREE_ASM_WRITTEN (*tp))
16500 /* ??? The C++ FE emits debug information for using decls, so
16501 putting gcc_unreachable here falls over. See PR31899. For now
16502 be conservative. */
16503 else if (!cgraph_global_info_ready
16504 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16506 else if (TREE_CODE (*tp) == VAR_DECL)
16508 struct varpool_node *node = varpool_get_node (*tp);
16509 if (!node || !node->needed)
16512 else if (TREE_CODE (*tp) == FUNCTION_DECL
16513 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16515 /* The call graph machinery must have finished analyzing,
16516 optimizing and gimplifying the CU by now.
16517 So if *TP has no call graph node associated
16518 to it, it means *TP will not be emitted. */
16519 if (!cgraph_get_node (*tp))
16522 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16528 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16529 for use in a later add_const_value_attribute call. */
16532 rtl_for_decl_init (tree init, tree type)
16534 rtx rtl = NULL_RTX;
16538 /* If a variable is initialized with a string constant without embedded
16539 zeros, build CONST_STRING. */
16540 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16542 tree enttype = TREE_TYPE (type);
16543 tree domain = TYPE_DOMAIN (type);
16544 enum machine_mode mode = TYPE_MODE (enttype);
16546 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16548 && integer_zerop (TYPE_MIN_VALUE (domain))
16549 && compare_tree_int (TYPE_MAX_VALUE (domain),
16550 TREE_STRING_LENGTH (init) - 1) == 0
16551 && ((size_t) TREE_STRING_LENGTH (init)
16552 == strlen (TREE_STRING_POINTER (init)) + 1))
16554 rtl = gen_rtx_CONST_STRING (VOIDmode,
16555 ggc_strdup (TREE_STRING_POINTER (init)));
16556 rtl = gen_rtx_MEM (BLKmode, rtl);
16557 MEM_READONLY_P (rtl) = 1;
16560 /* Other aggregates, and complex values, could be represented using
16562 else if (AGGREGATE_TYPE_P (type)
16563 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
16564 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
16565 || TREE_CODE (type) == COMPLEX_TYPE)
16567 /* Vectors only work if their mode is supported by the target.
16568 FIXME: generic vectors ought to work too. */
16569 else if (TREE_CODE (type) == VECTOR_TYPE
16570 && !VECTOR_MODE_P (TYPE_MODE (type)))
16572 /* If the initializer is something that we know will expand into an
16573 immediate RTL constant, expand it now. We must be careful not to
16574 reference variables which won't be output. */
16575 else if (initializer_constant_valid_p (init, type)
16576 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16578 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16580 if (TREE_CODE (type) == VECTOR_TYPE)
16581 switch (TREE_CODE (init))
16586 if (TREE_CONSTANT (init))
16588 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16589 bool constant_p = true;
16591 unsigned HOST_WIDE_INT ix;
16593 /* Even when ctor is constant, it might contain non-*_CST
16594 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16595 belong into VECTOR_CST nodes. */
16596 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16597 if (!CONSTANT_CLASS_P (value))
16599 constant_p = false;
16605 init = build_vector_from_ctor (type, elts);
16615 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16617 /* If expand_expr returns a MEM, it wasn't immediate. */
16618 gcc_assert (!rtl || !MEM_P (rtl));
16624 /* Generate RTL for the variable DECL to represent its location. */
16627 rtl_for_decl_location (tree decl)
16631 /* Here we have to decide where we are going to say the parameter "lives"
16632 (as far as the debugger is concerned). We only have a couple of
16633 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16635 DECL_RTL normally indicates where the parameter lives during most of the
16636 activation of the function. If optimization is enabled however, this
16637 could be either NULL or else a pseudo-reg. Both of those cases indicate
16638 that the parameter doesn't really live anywhere (as far as the code
16639 generation parts of GCC are concerned) during most of the function's
16640 activation. That will happen (for example) if the parameter is never
16641 referenced within the function.
16643 We could just generate a location descriptor here for all non-NULL
16644 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16645 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16646 where DECL_RTL is NULL or is a pseudo-reg.
16648 Note however that we can only get away with using DECL_INCOMING_RTL as
16649 a backup substitute for DECL_RTL in certain limited cases. In cases
16650 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16651 we can be sure that the parameter was passed using the same type as it is
16652 declared to have within the function, and that its DECL_INCOMING_RTL
16653 points us to a place where a value of that type is passed.
16655 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16656 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16657 because in these cases DECL_INCOMING_RTL points us to a value of some
16658 type which is *different* from the type of the parameter itself. Thus,
16659 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16660 such cases, the debugger would end up (for example) trying to fetch a
16661 `float' from a place which actually contains the first part of a
16662 `double'. That would lead to really incorrect and confusing
16663 output at debug-time.
16665 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16666 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16667 are a couple of exceptions however. On little-endian machines we can
16668 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16669 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16670 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16671 when (on a little-endian machine) a non-prototyped function has a
16672 parameter declared to be of type `short' or `char'. In such cases,
16673 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16674 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16675 passed `int' value. If the debugger then uses that address to fetch
16676 a `short' or a `char' (on a little-endian machine) the result will be
16677 the correct data, so we allow for such exceptional cases below.
16679 Note that our goal here is to describe the place where the given formal
16680 parameter lives during most of the function's activation (i.e. between the
16681 end of the prologue and the start of the epilogue). We'll do that as best
16682 as we can. Note however that if the given formal parameter is modified
16683 sometime during the execution of the function, then a stack backtrace (at
16684 debug-time) will show the function as having been called with the *new*
16685 value rather than the value which was originally passed in. This happens
16686 rarely enough that it is not a major problem, but it *is* a problem, and
16687 I'd like to fix it.
16689 A future version of dwarf2out.c may generate two additional attributes for
16690 any given DW_TAG_formal_parameter DIE which will describe the "passed
16691 type" and the "passed location" for the given formal parameter in addition
16692 to the attributes we now generate to indicate the "declared type" and the
16693 "active location" for each parameter. This additional set of attributes
16694 could be used by debuggers for stack backtraces. Separately, note that
16695 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16696 This happens (for example) for inlined-instances of inline function formal
16697 parameters which are never referenced. This really shouldn't be
16698 happening. All PARM_DECL nodes should get valid non-NULL
16699 DECL_INCOMING_RTL values. FIXME. */
16701 /* Use DECL_RTL as the "location" unless we find something better. */
16702 rtl = DECL_RTL_IF_SET (decl);
16704 /* When generating abstract instances, ignore everything except
16705 constants, symbols living in memory, and symbols living in
16706 fixed registers. */
16707 if (! reload_completed)
16710 && (CONSTANT_P (rtl)
16712 && CONSTANT_P (XEXP (rtl, 0)))
16714 && TREE_CODE (decl) == VAR_DECL
16715 && TREE_STATIC (decl))))
16717 rtl = targetm.delegitimize_address (rtl);
16722 else if (TREE_CODE (decl) == PARM_DECL)
16724 if (rtl == NULL_RTX
16725 || is_pseudo_reg (rtl)
16727 && is_pseudo_reg (XEXP (rtl, 0))
16728 && DECL_INCOMING_RTL (decl)
16729 && MEM_P (DECL_INCOMING_RTL (decl))
16730 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
16732 tree declared_type = TREE_TYPE (decl);
16733 tree passed_type = DECL_ARG_TYPE (decl);
16734 enum machine_mode dmode = TYPE_MODE (declared_type);
16735 enum machine_mode pmode = TYPE_MODE (passed_type);
16737 /* This decl represents a formal parameter which was optimized out.
16738 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16739 all cases where (rtl == NULL_RTX) just below. */
16740 if (dmode == pmode)
16741 rtl = DECL_INCOMING_RTL (decl);
16742 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
16743 && SCALAR_INT_MODE_P (dmode)
16744 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16745 && DECL_INCOMING_RTL (decl))
16747 rtx inc = DECL_INCOMING_RTL (decl);
16750 else if (MEM_P (inc))
16752 if (BYTES_BIG_ENDIAN)
16753 rtl = adjust_address_nv (inc, dmode,
16754 GET_MODE_SIZE (pmode)
16755 - GET_MODE_SIZE (dmode));
16762 /* If the parm was passed in registers, but lives on the stack, then
16763 make a big endian correction if the mode of the type of the
16764 parameter is not the same as the mode of the rtl. */
16765 /* ??? This is the same series of checks that are made in dbxout.c before
16766 we reach the big endian correction code there. It isn't clear if all
16767 of these checks are necessary here, but keeping them all is the safe
16769 else if (MEM_P (rtl)
16770 && XEXP (rtl, 0) != const0_rtx
16771 && ! CONSTANT_P (XEXP (rtl, 0))
16772 /* Not passed in memory. */
16773 && !MEM_P (DECL_INCOMING_RTL (decl))
16774 /* Not passed by invisible reference. */
16775 && (!REG_P (XEXP (rtl, 0))
16776 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16777 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16778 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16779 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16782 /* Big endian correction check. */
16783 && BYTES_BIG_ENDIAN
16784 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16785 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16788 int offset = (UNITS_PER_WORD
16789 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16791 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16792 plus_constant (XEXP (rtl, 0), offset));
16795 else if (TREE_CODE (decl) == VAR_DECL
16798 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16799 && BYTES_BIG_ENDIAN)
16801 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16802 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16804 /* If a variable is declared "register" yet is smaller than
16805 a register, then if we store the variable to memory, it
16806 looks like we're storing a register-sized value, when in
16807 fact we are not. We need to adjust the offset of the
16808 storage location to reflect the actual value's bytes,
16809 else gdb will not be able to display it. */
16811 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16812 plus_constant (XEXP (rtl, 0), rsize-dsize));
16815 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16816 and will have been substituted directly into all expressions that use it.
16817 C does not have such a concept, but C++ and other languages do. */
16818 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16819 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16822 rtl = targetm.delegitimize_address (rtl);
16824 /* If we don't look past the constant pool, we risk emitting a
16825 reference to a constant pool entry that isn't referenced from
16826 code, and thus is not emitted. */
16828 rtl = avoid_constant_pool_reference (rtl);
16830 /* Try harder to get a rtl. If this symbol ends up not being emitted
16831 in the current CU, resolve_addr will remove the expression referencing
16833 if (rtl == NULL_RTX
16834 && TREE_CODE (decl) == VAR_DECL
16835 && !DECL_EXTERNAL (decl)
16836 && TREE_STATIC (decl)
16837 && DECL_NAME (decl)
16838 && !DECL_HARD_REGISTER (decl)
16839 && DECL_MODE (decl) != VOIDmode)
16841 rtl = make_decl_rtl_for_debug (decl);
16843 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16844 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16851 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16852 returned. If so, the decl for the COMMON block is returned, and the
16853 value is the offset into the common block for the symbol. */
16856 fortran_common (tree decl, HOST_WIDE_INT *value)
16858 tree val_expr, cvar;
16859 enum machine_mode mode;
16860 HOST_WIDE_INT bitsize, bitpos;
16862 int volatilep = 0, unsignedp = 0;
16864 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16865 it does not have a value (the offset into the common area), or if it
16866 is thread local (as opposed to global) then it isn't common, and shouldn't
16867 be handled as such. */
16868 if (TREE_CODE (decl) != VAR_DECL
16869 || !TREE_STATIC (decl)
16870 || !DECL_HAS_VALUE_EXPR_P (decl)
16874 val_expr = DECL_VALUE_EXPR (decl);
16875 if (TREE_CODE (val_expr) != COMPONENT_REF)
16878 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16879 &mode, &unsignedp, &volatilep, true);
16881 if (cvar == NULL_TREE
16882 || TREE_CODE (cvar) != VAR_DECL
16883 || DECL_ARTIFICIAL (cvar)
16884 || !TREE_PUBLIC (cvar))
16888 if (offset != NULL)
16890 if (!host_integerp (offset, 0))
16892 *value = tree_low_cst (offset, 0);
16895 *value += bitpos / BITS_PER_UNIT;
16900 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16901 data attribute for a variable or a parameter. We generate the
16902 DW_AT_const_value attribute only in those cases where the given variable
16903 or parameter does not have a true "location" either in memory or in a
16904 register. This can happen (for example) when a constant is passed as an
16905 actual argument in a call to an inline function. (It's possible that
16906 these things can crop up in other ways also.) Note that one type of
16907 constant value which can be passed into an inlined function is a constant
16908 pointer. This can happen for example if an actual argument in an inlined
16909 function call evaluates to a compile-time constant address. */
16912 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
16913 enum dwarf_attribute attr)
16916 dw_loc_list_ref list;
16917 var_loc_list *loc_list;
16919 if (TREE_CODE (decl) == ERROR_MARK)
16922 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16923 || TREE_CODE (decl) == RESULT_DECL);
16925 /* Try to get some constant RTL for this decl, and use that as the value of
16928 rtl = rtl_for_decl_location (decl);
16929 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16930 && add_const_value_attribute (die, rtl))
16933 /* See if we have single element location list that is equivalent to
16934 a constant value. That way we are better to use add_const_value_attribute
16935 rather than expanding constant value equivalent. */
16936 loc_list = lookup_decl_loc (decl);
16939 && loc_list->first->next == NULL
16940 && NOTE_P (loc_list->first->loc)
16941 && NOTE_VAR_LOCATION (loc_list->first->loc)
16942 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16944 struct var_loc_node *node;
16946 node = loc_list->first;
16947 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16948 if (GET_CODE (rtl) == EXPR_LIST)
16949 rtl = XEXP (rtl, 0);
16950 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16951 && add_const_value_attribute (die, rtl))
16954 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
16957 add_AT_location_description (die, attr, list);
16960 /* None of that worked, so it must not really have a location;
16961 try adding a constant value attribute from the DECL_INITIAL. */
16962 return tree_add_const_value_attribute_for_decl (die, decl);
16965 /* Add VARIABLE and DIE into deferred locations list. */
16968 defer_location (tree variable, dw_die_ref die)
16970 deferred_locations entry;
16971 entry.variable = variable;
16973 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
16976 /* Helper function for tree_add_const_value_attribute. Natively encode
16977 initializer INIT into an array. Return true if successful. */
16980 native_encode_initializer (tree init, unsigned char *array, int size)
16984 if (init == NULL_TREE)
16988 switch (TREE_CODE (init))
16991 type = TREE_TYPE (init);
16992 if (TREE_CODE (type) == ARRAY_TYPE)
16994 tree enttype = TREE_TYPE (type);
16995 enum machine_mode mode = TYPE_MODE (enttype);
16997 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16999 if (int_size_in_bytes (type) != size)
17001 if (size > TREE_STRING_LENGTH (init))
17003 memcpy (array, TREE_STRING_POINTER (init),
17004 TREE_STRING_LENGTH (init));
17005 memset (array + TREE_STRING_LENGTH (init),
17006 '\0', size - TREE_STRING_LENGTH (init));
17009 memcpy (array, TREE_STRING_POINTER (init), size);
17014 type = TREE_TYPE (init);
17015 if (int_size_in_bytes (type) != size)
17017 if (TREE_CODE (type) == ARRAY_TYPE)
17019 HOST_WIDE_INT min_index;
17020 unsigned HOST_WIDE_INT cnt;
17021 int curpos = 0, fieldsize;
17022 constructor_elt *ce;
17024 if (TYPE_DOMAIN (type) == NULL_TREE
17025 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
17028 fieldsize = int_size_in_bytes (TREE_TYPE (type));
17029 if (fieldsize <= 0)
17032 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
17033 memset (array, '\0', size);
17034 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17036 tree val = ce->value;
17037 tree index = ce->index;
17039 if (index && TREE_CODE (index) == RANGE_EXPR)
17040 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
17043 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
17048 if (!native_encode_initializer (val, array + pos, fieldsize))
17051 curpos = pos + fieldsize;
17052 if (index && TREE_CODE (index) == RANGE_EXPR)
17054 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17055 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17059 memcpy (array + curpos, array + pos, fieldsize);
17060 curpos += fieldsize;
17063 gcc_assert (curpos <= size);
17067 else if (TREE_CODE (type) == RECORD_TYPE
17068 || TREE_CODE (type) == UNION_TYPE)
17070 tree field = NULL_TREE;
17071 unsigned HOST_WIDE_INT cnt;
17072 constructor_elt *ce;
17074 if (int_size_in_bytes (type) != size)
17077 if (TREE_CODE (type) == RECORD_TYPE)
17078 field = TYPE_FIELDS (type);
17080 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17082 tree val = ce->value;
17083 int pos, fieldsize;
17085 if (ce->index != 0)
17091 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17094 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17095 && TYPE_DOMAIN (TREE_TYPE (field))
17096 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17098 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17099 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17101 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17102 pos = int_byte_position (field);
17103 gcc_assert (pos + fieldsize <= size);
17105 && !native_encode_initializer (val, array + pos, fieldsize))
17111 case VIEW_CONVERT_EXPR:
17112 case NON_LVALUE_EXPR:
17113 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17115 return native_encode_expr (init, array, size) == size;
17119 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17120 attribute is the const value T. */
17123 tree_add_const_value_attribute (dw_die_ref die, tree t)
17126 tree type = TREE_TYPE (t);
17129 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17133 gcc_assert (!DECL_P (init));
17135 rtl = rtl_for_decl_init (init, type);
17137 return add_const_value_attribute (die, rtl);
17138 /* If the host and target are sane, try harder. */
17139 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17140 && initializer_constant_valid_p (init, type))
17142 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17143 if (size > 0 && (int) size == size)
17145 unsigned char *array = (unsigned char *)
17146 ggc_alloc_cleared_atomic (size);
17148 if (native_encode_initializer (init, array, size))
17150 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17158 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17159 attribute is the const value of T, where T is an integral constant
17160 variable with static storage duration
17161 (so it can't be a PARM_DECL or a RESULT_DECL). */
17164 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17168 || (TREE_CODE (decl) != VAR_DECL
17169 && TREE_CODE (decl) != CONST_DECL))
17172 if (TREE_READONLY (decl)
17173 && ! TREE_THIS_VOLATILE (decl)
17174 && DECL_INITIAL (decl))
17179 /* Don't add DW_AT_const_value if abstract origin already has one. */
17180 if (get_AT (var_die, DW_AT_const_value))
17183 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17186 /* Convert the CFI instructions for the current function into a
17187 location list. This is used for DW_AT_frame_base when we targeting
17188 a dwarf2 consumer that does not support the dwarf3
17189 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17192 static dw_loc_list_ref
17193 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17196 dw_loc_list_ref list, *list_tail;
17198 dw_cfa_location last_cfa, next_cfa;
17199 const char *start_label, *last_label, *section;
17200 dw_cfa_location remember;
17202 fde = current_fde ();
17203 gcc_assert (fde != NULL);
17205 section = secname_for_decl (current_function_decl);
17209 memset (&next_cfa, 0, sizeof (next_cfa));
17210 next_cfa.reg = INVALID_REGNUM;
17211 remember = next_cfa;
17213 start_label = fde->dw_fde_begin;
17215 /* ??? Bald assumption that the CIE opcode list does not contain
17216 advance opcodes. */
17217 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
17218 lookup_cfa_1 (cfi, &next_cfa, &remember);
17220 last_cfa = next_cfa;
17221 last_label = start_label;
17223 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17224 switch (cfi->dw_cfi_opc)
17226 case DW_CFA_set_loc:
17227 case DW_CFA_advance_loc1:
17228 case DW_CFA_advance_loc2:
17229 case DW_CFA_advance_loc4:
17230 if (!cfa_equal_p (&last_cfa, &next_cfa))
17232 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17233 start_label, last_label, section);
17235 list_tail = &(*list_tail)->dw_loc_next;
17236 last_cfa = next_cfa;
17237 start_label = last_label;
17239 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17242 case DW_CFA_advance_loc:
17243 /* The encoding is complex enough that we should never emit this. */
17244 gcc_unreachable ();
17247 lookup_cfa_1 (cfi, &next_cfa, &remember);
17251 if (!cfa_equal_p (&last_cfa, &next_cfa))
17253 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17254 start_label, last_label, section);
17255 list_tail = &(*list_tail)->dw_loc_next;
17256 start_label = last_label;
17259 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17260 start_label, fde->dw_fde_end, section);
17262 if (list && list->dw_loc_next)
17268 /* Compute a displacement from the "steady-state frame pointer" to the
17269 frame base (often the same as the CFA), and store it in
17270 frame_pointer_fb_offset. OFFSET is added to the displacement
17271 before the latter is negated. */
17274 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17278 #ifdef FRAME_POINTER_CFA_OFFSET
17279 reg = frame_pointer_rtx;
17280 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17282 reg = arg_pointer_rtx;
17283 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17286 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17287 if (GET_CODE (elim) == PLUS)
17289 offset += INTVAL (XEXP (elim, 1));
17290 elim = XEXP (elim, 0);
17293 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17294 && (elim == hard_frame_pointer_rtx
17295 || elim == stack_pointer_rtx))
17296 || elim == (frame_pointer_needed
17297 ? hard_frame_pointer_rtx
17298 : stack_pointer_rtx));
17300 frame_pointer_fb_offset = -offset;
17303 /* Generate a DW_AT_name attribute given some string value to be included as
17304 the value of the attribute. */
17307 add_name_attribute (dw_die_ref die, const char *name_string)
17309 if (name_string != NULL && *name_string != 0)
17311 if (demangle_name_func)
17312 name_string = (*demangle_name_func) (name_string);
17314 add_AT_string (die, DW_AT_name, name_string);
17318 /* Generate a DW_AT_comp_dir attribute for DIE. */
17321 add_comp_dir_attribute (dw_die_ref die)
17323 const char *wd = get_src_pwd ();
17329 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17333 wdlen = strlen (wd);
17334 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17336 wd1 [wdlen] = DIR_SEPARATOR;
17337 wd1 [wdlen + 1] = 0;
17341 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17344 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17348 lower_bound_default (void)
17350 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17355 case DW_LANG_C_plus_plus:
17357 case DW_LANG_ObjC_plus_plus:
17360 case DW_LANG_Fortran77:
17361 case DW_LANG_Fortran90:
17362 case DW_LANG_Fortran95:
17366 case DW_LANG_Python:
17367 return dwarf_version >= 4 ? 0 : -1;
17368 case DW_LANG_Ada95:
17369 case DW_LANG_Ada83:
17370 case DW_LANG_Cobol74:
17371 case DW_LANG_Cobol85:
17372 case DW_LANG_Pascal83:
17373 case DW_LANG_Modula2:
17375 return dwarf_version >= 4 ? 1 : -1;
17381 /* Given a tree node describing an array bound (either lower or upper) output
17382 a representation for that bound. */
17385 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17387 switch (TREE_CODE (bound))
17392 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17395 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17398 /* Use the default if possible. */
17399 if (bound_attr == DW_AT_lower_bound
17400 && host_integerp (bound, 0)
17401 && (dflt = lower_bound_default ()) != -1
17402 && tree_low_cst (bound, 0) == dflt)
17405 /* Otherwise represent the bound as an unsigned value with the
17406 precision of its type. The precision and signedness of the
17407 type will be necessary to re-interpret it unambiguously. */
17408 else if (prec < HOST_BITS_PER_WIDE_INT)
17410 unsigned HOST_WIDE_INT mask
17411 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17412 add_AT_unsigned (subrange_die, bound_attr,
17413 TREE_INT_CST_LOW (bound) & mask);
17415 else if (prec == HOST_BITS_PER_WIDE_INT
17416 || TREE_INT_CST_HIGH (bound) == 0)
17417 add_AT_unsigned (subrange_die, bound_attr,
17418 TREE_INT_CST_LOW (bound));
17420 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17421 TREE_INT_CST_LOW (bound));
17426 case VIEW_CONVERT_EXPR:
17427 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17437 dw_die_ref decl_die = lookup_decl_die (bound);
17439 /* ??? Can this happen, or should the variable have been bound
17440 first? Probably it can, since I imagine that we try to create
17441 the types of parameters in the order in which they exist in
17442 the list, and won't have created a forward reference to a
17443 later parameter. */
17444 if (decl_die != NULL)
17446 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17454 /* Otherwise try to create a stack operation procedure to
17455 evaluate the value of the array bound. */
17457 dw_die_ref ctx, decl_die;
17458 dw_loc_list_ref list;
17460 list = loc_list_from_tree (bound, 2);
17461 if (list == NULL || single_element_loc_list_p (list))
17463 /* If DW_AT_*bound is not a reference nor constant, it is
17464 a DWARF expression rather than location description.
17465 For that loc_list_from_tree (bound, 0) is needed.
17466 If that fails to give a single element list,
17467 fall back to outputting this as a reference anyway. */
17468 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17469 if (list2 && single_element_loc_list_p (list2))
17471 add_AT_loc (subrange_die, bound_attr, list2->expr);
17478 if (current_function_decl == 0)
17479 ctx = comp_unit_die ();
17481 ctx = lookup_decl_die (current_function_decl);
17483 decl_die = new_die (DW_TAG_variable, ctx, bound);
17484 add_AT_flag (decl_die, DW_AT_artificial, 1);
17485 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17486 add_AT_location_description (decl_die, DW_AT_location, list);
17487 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17493 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17494 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17495 Note that the block of subscript information for an array type also
17496 includes information about the element type of the given array type. */
17499 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17501 unsigned dimension_number;
17503 dw_die_ref subrange_die;
17505 for (dimension_number = 0;
17506 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17507 type = TREE_TYPE (type), dimension_number++)
17509 tree domain = TYPE_DOMAIN (type);
17511 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17514 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17515 and (in GNU C only) variable bounds. Handle all three forms
17517 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17520 /* We have an array type with specified bounds. */
17521 lower = TYPE_MIN_VALUE (domain);
17522 upper = TYPE_MAX_VALUE (domain);
17524 /* Define the index type. */
17525 if (TREE_TYPE (domain))
17527 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17528 TREE_TYPE field. We can't emit debug info for this
17529 because it is an unnamed integral type. */
17530 if (TREE_CODE (domain) == INTEGER_TYPE
17531 && TYPE_NAME (domain) == NULL_TREE
17532 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17533 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17536 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17540 /* ??? If upper is NULL, the array has unspecified length,
17541 but it does have a lower bound. This happens with Fortran
17543 Since the debugger is definitely going to need to know N
17544 to produce useful results, go ahead and output the lower
17545 bound solo, and hope the debugger can cope. */
17547 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17549 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17552 /* Otherwise we have an array type with an unspecified length. The
17553 DWARF-2 spec does not say how to handle this; let's just leave out the
17559 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17563 switch (TREE_CODE (tree_node))
17568 case ENUMERAL_TYPE:
17571 case QUAL_UNION_TYPE:
17572 size = int_size_in_bytes (tree_node);
17575 /* For a data member of a struct or union, the DW_AT_byte_size is
17576 generally given as the number of bytes normally allocated for an
17577 object of the *declared* type of the member itself. This is true
17578 even for bit-fields. */
17579 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17582 gcc_unreachable ();
17585 /* Note that `size' might be -1 when we get to this point. If it is, that
17586 indicates that the byte size of the entity in question is variable. We
17587 have no good way of expressing this fact in Dwarf at the present time,
17588 so just let the -1 pass on through. */
17589 add_AT_unsigned (die, DW_AT_byte_size, size);
17592 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17593 which specifies the distance in bits from the highest order bit of the
17594 "containing object" for the bit-field to the highest order bit of the
17597 For any given bit-field, the "containing object" is a hypothetical object
17598 (of some integral or enum type) within which the given bit-field lives. The
17599 type of this hypothetical "containing object" is always the same as the
17600 declared type of the individual bit-field itself. The determination of the
17601 exact location of the "containing object" for a bit-field is rather
17602 complicated. It's handled by the `field_byte_offset' function (above).
17604 Note that it is the size (in bytes) of the hypothetical "containing object"
17605 which will be given in the DW_AT_byte_size attribute for this bit-field.
17606 (See `byte_size_attribute' above). */
17609 add_bit_offset_attribute (dw_die_ref die, tree decl)
17611 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17612 tree type = DECL_BIT_FIELD_TYPE (decl);
17613 HOST_WIDE_INT bitpos_int;
17614 HOST_WIDE_INT highest_order_object_bit_offset;
17615 HOST_WIDE_INT highest_order_field_bit_offset;
17616 HOST_WIDE_INT bit_offset;
17618 /* Must be a field and a bit field. */
17619 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17621 /* We can't yet handle bit-fields whose offsets are variable, so if we
17622 encounter such things, just return without generating any attribute
17623 whatsoever. Likewise for variable or too large size. */
17624 if (! host_integerp (bit_position (decl), 0)
17625 || ! host_integerp (DECL_SIZE (decl), 1))
17628 bitpos_int = int_bit_position (decl);
17630 /* Note that the bit offset is always the distance (in bits) from the
17631 highest-order bit of the "containing object" to the highest-order bit of
17632 the bit-field itself. Since the "high-order end" of any object or field
17633 is different on big-endian and little-endian machines, the computation
17634 below must take account of these differences. */
17635 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17636 highest_order_field_bit_offset = bitpos_int;
17638 if (! BYTES_BIG_ENDIAN)
17640 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17641 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17645 = (! BYTES_BIG_ENDIAN
17646 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17647 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17649 if (bit_offset < 0)
17650 add_AT_int (die, DW_AT_bit_offset, bit_offset);
17652 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
17655 /* For a FIELD_DECL node which represents a bit field, output an attribute
17656 which specifies the length in bits of the given field. */
17659 add_bit_size_attribute (dw_die_ref die, tree decl)
17661 /* Must be a field and a bit field. */
17662 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17663 && DECL_BIT_FIELD_TYPE (decl));
17665 if (host_integerp (DECL_SIZE (decl), 1))
17666 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17669 /* If the compiled language is ANSI C, then add a 'prototyped'
17670 attribute, if arg types are given for the parameters of a function. */
17673 add_prototyped_attribute (dw_die_ref die, tree func_type)
17675 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
17676 && prototype_p (func_type))
17677 add_AT_flag (die, DW_AT_prototyped, 1);
17680 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17681 by looking in either the type declaration or object declaration
17684 static inline dw_die_ref
17685 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17687 dw_die_ref origin_die = NULL;
17689 if (TREE_CODE (origin) != FUNCTION_DECL)
17691 /* We may have gotten separated from the block for the inlined
17692 function, if we're in an exception handler or some such; make
17693 sure that the abstract function has been written out.
17695 Doing this for nested functions is wrong, however; functions are
17696 distinct units, and our context might not even be inline. */
17700 fn = TYPE_STUB_DECL (fn);
17702 fn = decl_function_context (fn);
17704 dwarf2out_abstract_function (fn);
17707 if (DECL_P (origin))
17708 origin_die = lookup_decl_die (origin);
17709 else if (TYPE_P (origin))
17710 origin_die = lookup_type_die (origin);
17712 /* XXX: Functions that are never lowered don't always have correct block
17713 trees (in the case of java, they simply have no block tree, in some other
17714 languages). For these functions, there is nothing we can really do to
17715 output correct debug info for inlined functions in all cases. Rather
17716 than die, we'll just produce deficient debug info now, in that we will
17717 have variables without a proper abstract origin. In the future, when all
17718 functions are lowered, we should re-add a gcc_assert (origin_die)
17722 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17726 /* We do not currently support the pure_virtual attribute. */
17729 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17731 if (DECL_VINDEX (func_decl))
17733 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17735 if (host_integerp (DECL_VINDEX (func_decl), 0))
17736 add_AT_loc (die, DW_AT_vtable_elem_location,
17737 new_loc_descr (DW_OP_constu,
17738 tree_low_cst (DECL_VINDEX (func_decl), 0),
17741 /* GNU extension: Record what type this method came from originally. */
17742 if (debug_info_level > DINFO_LEVEL_TERSE
17743 && DECL_CONTEXT (func_decl))
17744 add_AT_die_ref (die, DW_AT_containing_type,
17745 lookup_type_die (DECL_CONTEXT (func_decl)));
17749 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17750 given decl. This used to be a vendor extension until after DWARF 4
17751 standardized it. */
17754 add_linkage_attr (dw_die_ref die, tree decl)
17756 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17758 /* Mimic what assemble_name_raw does with a leading '*'. */
17759 if (name[0] == '*')
17762 if (dwarf_version >= 4)
17763 add_AT_string (die, DW_AT_linkage_name, name);
17765 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17768 /* Add source coordinate attributes for the given decl. */
17771 add_src_coords_attributes (dw_die_ref die, tree decl)
17773 expanded_location s;
17775 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
17777 s = expand_location (DECL_SOURCE_LOCATION (decl));
17778 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17779 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17782 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17785 add_linkage_name (dw_die_ref die, tree decl)
17787 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17788 && TREE_PUBLIC (decl)
17789 && !DECL_ABSTRACT (decl)
17790 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17791 && die->die_tag != DW_TAG_member)
17793 /* Defer until we have an assembler name set. */
17794 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17796 limbo_die_node *asm_name;
17798 asm_name = ggc_alloc_cleared_limbo_die_node ();
17799 asm_name->die = die;
17800 asm_name->created_for = decl;
17801 asm_name->next = deferred_asm_name;
17802 deferred_asm_name = asm_name;
17804 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17805 add_linkage_attr (die, decl);
17809 /* Add a DW_AT_name attribute and source coordinate attribute for the
17810 given decl, but only if it actually has a name. */
17813 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17817 decl_name = DECL_NAME (decl);
17818 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17820 const char *name = dwarf2_name (decl, 0);
17822 add_name_attribute (die, name);
17823 if (! DECL_ARTIFICIAL (decl))
17824 add_src_coords_attributes (die, decl);
17826 add_linkage_name (die, decl);
17829 #ifdef VMS_DEBUGGING_INFO
17830 /* Get the function's name, as described by its RTL. This may be different
17831 from the DECL_NAME name used in the source file. */
17832 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17834 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17835 XEXP (DECL_RTL (decl), 0));
17836 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17838 #endif /* VMS_DEBUGGING_INFO */
17841 #ifdef VMS_DEBUGGING_INFO
17842 /* Output the debug main pointer die for VMS */
17845 dwarf2out_vms_debug_main_pointer (void)
17847 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17850 /* Allocate the VMS debug main subprogram die. */
17851 die = ggc_alloc_cleared_die_node ();
17852 die->die_tag = DW_TAG_subprogram;
17853 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17854 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17855 current_function_funcdef_no);
17856 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17858 /* Make it the first child of comp_unit_die (). */
17859 die->die_parent = comp_unit_die ();
17860 if (comp_unit_die ()->die_child)
17862 die->die_sib = comp_unit_die ()->die_child->die_sib;
17863 comp_unit_die ()->die_child->die_sib = die;
17867 die->die_sib = die;
17868 comp_unit_die ()->die_child = die;
17871 #endif /* VMS_DEBUGGING_INFO */
17873 /* Push a new declaration scope. */
17876 push_decl_scope (tree scope)
17878 VEC_safe_push (tree, gc, decl_scope_table, scope);
17881 /* Pop a declaration scope. */
17884 pop_decl_scope (void)
17886 VEC_pop (tree, decl_scope_table);
17889 /* Return the DIE for the scope that immediately contains this type.
17890 Non-named types get global scope. Named types nested in other
17891 types get their containing scope if it's open, or global scope
17892 otherwise. All other types (i.e. function-local named types) get
17893 the current active scope. */
17896 scope_die_for (tree t, dw_die_ref context_die)
17898 dw_die_ref scope_die = NULL;
17899 tree containing_scope;
17902 /* Non-types always go in the current scope. */
17903 gcc_assert (TYPE_P (t));
17905 containing_scope = TYPE_CONTEXT (t);
17907 /* Use the containing namespace if it was passed in (for a declaration). */
17908 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17910 if (context_die == lookup_decl_die (containing_scope))
17913 containing_scope = NULL_TREE;
17916 /* Ignore function type "scopes" from the C frontend. They mean that
17917 a tagged type is local to a parmlist of a function declarator, but
17918 that isn't useful to DWARF. */
17919 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17920 containing_scope = NULL_TREE;
17922 if (SCOPE_FILE_SCOPE_P (containing_scope))
17923 scope_die = comp_unit_die ();
17924 else if (TYPE_P (containing_scope))
17926 /* For types, we can just look up the appropriate DIE. But
17927 first we check to see if we're in the middle of emitting it
17928 so we know where the new DIE should go. */
17929 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
17930 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
17935 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
17936 || TREE_ASM_WRITTEN (containing_scope));
17937 /*We are not in the middle of emitting the type
17938 CONTAINING_SCOPE. Let's see if it's emitted already. */
17939 scope_die = lookup_type_die (containing_scope);
17941 /* If none of the current dies are suitable, we get file scope. */
17942 if (scope_die == NULL)
17943 scope_die = comp_unit_die ();
17946 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
17949 scope_die = context_die;
17954 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17957 local_scope_p (dw_die_ref context_die)
17959 for (; context_die; context_die = context_die->die_parent)
17960 if (context_die->die_tag == DW_TAG_inlined_subroutine
17961 || context_die->die_tag == DW_TAG_subprogram)
17967 /* Returns nonzero if CONTEXT_DIE is a class. */
17970 class_scope_p (dw_die_ref context_die)
17972 return (context_die
17973 && (context_die->die_tag == DW_TAG_structure_type
17974 || context_die->die_tag == DW_TAG_class_type
17975 || context_die->die_tag == DW_TAG_interface_type
17976 || context_die->die_tag == DW_TAG_union_type));
17979 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17980 whether or not to treat a DIE in this context as a declaration. */
17983 class_or_namespace_scope_p (dw_die_ref context_die)
17985 return (class_scope_p (context_die)
17986 || (context_die && context_die->die_tag == DW_TAG_namespace));
17989 /* Many forms of DIEs require a "type description" attribute. This
17990 routine locates the proper "type descriptor" die for the type given
17991 by 'type', and adds a DW_AT_type attribute below the given die. */
17994 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
17995 int decl_volatile, dw_die_ref context_die)
17997 enum tree_code code = TREE_CODE (type);
17998 dw_die_ref type_die = NULL;
18000 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18001 or fixed-point type, use the inner type. This is because we have no
18002 support for unnamed types in base_type_die. This can happen if this is
18003 an Ada subrange type. Correct solution is emit a subrange type die. */
18004 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
18005 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
18006 type = TREE_TYPE (type), code = TREE_CODE (type);
18008 if (code == ERROR_MARK
18009 /* Handle a special case. For functions whose return type is void, we
18010 generate *no* type attribute. (Note that no object may have type
18011 `void', so this only applies to function return types). */
18012 || code == VOID_TYPE)
18015 type_die = modified_type_die (type,
18016 decl_const || TYPE_READONLY (type),
18017 decl_volatile || TYPE_VOLATILE (type),
18020 if (type_die != NULL)
18021 add_AT_die_ref (object_die, DW_AT_type, type_die);
18024 /* Given an object die, add the calling convention attribute for the
18025 function call type. */
18027 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
18029 enum dwarf_calling_convention value = DW_CC_normal;
18031 value = ((enum dwarf_calling_convention)
18032 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
18035 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
18037 /* DWARF 2 doesn't provide a way to identify a program's source-level
18038 entry point. DW_AT_calling_convention attributes are only meant
18039 to describe functions' calling conventions. However, lacking a
18040 better way to signal the Fortran main program, we used this for
18041 a long time, following existing custom. Now, DWARF 4 has
18042 DW_AT_main_subprogram, which we add below, but some tools still
18043 rely on the old way, which we thus keep. */
18044 value = DW_CC_program;
18046 if (dwarf_version >= 4 || !dwarf_strict)
18047 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
18050 /* Only add the attribute if the backend requests it, and
18051 is not DW_CC_normal. */
18052 if (value && (value != DW_CC_normal))
18053 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18056 /* Given a tree pointer to a struct, class, union, or enum type node, return
18057 a pointer to the (string) tag name for the given type, or zero if the type
18058 was declared without a tag. */
18060 static const char *
18061 type_tag (const_tree type)
18063 const char *name = 0;
18065 if (TYPE_NAME (type) != 0)
18069 /* Find the IDENTIFIER_NODE for the type name. */
18070 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18071 && !TYPE_NAMELESS (type))
18072 t = TYPE_NAME (type);
18074 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18075 a TYPE_DECL node, regardless of whether or not a `typedef' was
18077 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18078 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18080 /* We want to be extra verbose. Don't call dwarf_name if
18081 DECL_NAME isn't set. The default hook for decl_printable_name
18082 doesn't like that, and in this context it's correct to return
18083 0, instead of "<anonymous>" or the like. */
18084 if (DECL_NAME (TYPE_NAME (type))
18085 && !DECL_NAMELESS (TYPE_NAME (type)))
18086 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18089 /* Now get the name as a string, or invent one. */
18090 if (!name && t != 0)
18091 name = IDENTIFIER_POINTER (t);
18094 return (name == 0 || *name == '\0') ? 0 : name;
18097 /* Return the type associated with a data member, make a special check
18098 for bit field types. */
18101 member_declared_type (const_tree member)
18103 return (DECL_BIT_FIELD_TYPE (member)
18104 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18107 /* Get the decl's label, as described by its RTL. This may be different
18108 from the DECL_NAME name used in the source file. */
18111 static const char *
18112 decl_start_label (tree decl)
18115 const char *fnname;
18117 x = DECL_RTL (decl);
18118 gcc_assert (MEM_P (x));
18121 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18123 fnname = XSTR (x, 0);
18128 /* These routines generate the internal representation of the DIE's for
18129 the compilation unit. Debugging information is collected by walking
18130 the declaration trees passed in from dwarf2out_decl(). */
18133 gen_array_type_die (tree type, dw_die_ref context_die)
18135 dw_die_ref scope_die = scope_die_for (type, context_die);
18136 dw_die_ref array_die;
18138 /* GNU compilers represent multidimensional array types as sequences of one
18139 dimensional array types whose element types are themselves array types.
18140 We sometimes squish that down to a single array_type DIE with multiple
18141 subscripts in the Dwarf debugging info. The draft Dwarf specification
18142 say that we are allowed to do this kind of compression in C, because
18143 there is no difference between an array of arrays and a multidimensional
18144 array. We don't do this for Ada to remain as close as possible to the
18145 actual representation, which is especially important against the language
18146 flexibilty wrt arrays of variable size. */
18148 bool collapse_nested_arrays = !is_ada ();
18151 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18152 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18153 if (TYPE_STRING_FLAG (type)
18154 && TREE_CODE (type) == ARRAY_TYPE
18156 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18158 HOST_WIDE_INT size;
18160 array_die = new_die (DW_TAG_string_type, scope_die, type);
18161 add_name_attribute (array_die, type_tag (type));
18162 equate_type_number_to_die (type, array_die);
18163 size = int_size_in_bytes (type);
18165 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18166 else if (TYPE_DOMAIN (type) != NULL_TREE
18167 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18168 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18170 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18171 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18173 size = int_size_in_bytes (TREE_TYPE (szdecl));
18174 if (loc && size > 0)
18176 add_AT_location_description (array_die, DW_AT_string_length, loc);
18177 if (size != DWARF2_ADDR_SIZE)
18178 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18184 /* ??? The SGI dwarf reader fails for array of array of enum types
18185 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18186 array type comes before the outer array type. We thus call gen_type_die
18187 before we new_die and must prevent nested array types collapsing for this
18190 #ifdef MIPS_DEBUGGING_INFO
18191 gen_type_die (TREE_TYPE (type), context_die);
18192 collapse_nested_arrays = false;
18195 array_die = new_die (DW_TAG_array_type, scope_die, type);
18196 add_name_attribute (array_die, type_tag (type));
18197 equate_type_number_to_die (type, array_die);
18199 if (TREE_CODE (type) == VECTOR_TYPE)
18200 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18202 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18204 && TREE_CODE (type) == ARRAY_TYPE
18205 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18206 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18207 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18210 /* We default the array ordering. SDB will probably do
18211 the right things even if DW_AT_ordering is not present. It's not even
18212 an issue until we start to get into multidimensional arrays anyway. If
18213 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18214 then we'll have to put the DW_AT_ordering attribute back in. (But if
18215 and when we find out that we need to put these in, we will only do so
18216 for multidimensional arrays. */
18217 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18220 #ifdef MIPS_DEBUGGING_INFO
18221 /* The SGI compilers handle arrays of unknown bound by setting
18222 AT_declaration and not emitting any subrange DIEs. */
18223 if (TREE_CODE (type) == ARRAY_TYPE
18224 && ! TYPE_DOMAIN (type))
18225 add_AT_flag (array_die, DW_AT_declaration, 1);
18228 if (TREE_CODE (type) == VECTOR_TYPE)
18230 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18231 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18232 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18233 add_bound_info (subrange_die, DW_AT_upper_bound,
18234 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18237 add_subscript_info (array_die, type, collapse_nested_arrays);
18239 /* Add representation of the type of the elements of this array type and
18240 emit the corresponding DIE if we haven't done it already. */
18241 element_type = TREE_TYPE (type);
18242 if (collapse_nested_arrays)
18243 while (TREE_CODE (element_type) == ARRAY_TYPE)
18245 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18247 element_type = TREE_TYPE (element_type);
18250 #ifndef MIPS_DEBUGGING_INFO
18251 gen_type_die (element_type, context_die);
18254 add_type_attribute (array_die, element_type, 0, 0, context_die);
18256 if (get_AT (array_die, DW_AT_name))
18257 add_pubtype (type, array_die);
18260 static dw_loc_descr_ref
18261 descr_info_loc (tree val, tree base_decl)
18263 HOST_WIDE_INT size;
18264 dw_loc_descr_ref loc, loc2;
18265 enum dwarf_location_atom op;
18267 if (val == base_decl)
18268 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18270 switch (TREE_CODE (val))
18273 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18275 return loc_descriptor_from_tree (val, 0);
18277 if (host_integerp (val, 0))
18278 return int_loc_descriptor (tree_low_cst (val, 0));
18281 size = int_size_in_bytes (TREE_TYPE (val));
18284 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18287 if (size == DWARF2_ADDR_SIZE)
18288 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18290 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18292 case POINTER_PLUS_EXPR:
18294 if (host_integerp (TREE_OPERAND (val, 1), 1)
18295 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18298 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18301 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18307 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18310 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18313 add_loc_descr (&loc, loc2);
18314 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18336 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18337 tree val, tree base_decl)
18339 dw_loc_descr_ref loc;
18341 if (host_integerp (val, 0))
18343 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18347 loc = descr_info_loc (val, base_decl);
18351 add_AT_loc (die, attr, loc);
18354 /* This routine generates DIE for array with hidden descriptor, details
18355 are filled into *info by a langhook. */
18358 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18359 dw_die_ref context_die)
18361 dw_die_ref scope_die = scope_die_for (type, context_die);
18362 dw_die_ref array_die;
18365 array_die = new_die (DW_TAG_array_type, scope_die, type);
18366 add_name_attribute (array_die, type_tag (type));
18367 equate_type_number_to_die (type, array_die);
18369 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18371 && info->ndimensions >= 2)
18372 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18374 if (info->data_location)
18375 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18377 if (info->associated)
18378 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18380 if (info->allocated)
18381 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18384 for (dim = 0; dim < info->ndimensions; dim++)
18386 dw_die_ref subrange_die
18387 = new_die (DW_TAG_subrange_type, array_die, NULL);
18389 if (info->dimen[dim].lower_bound)
18391 /* If it is the default value, omit it. */
18394 if (host_integerp (info->dimen[dim].lower_bound, 0)
18395 && (dflt = lower_bound_default ()) != -1
18396 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18399 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18400 info->dimen[dim].lower_bound,
18403 if (info->dimen[dim].upper_bound)
18404 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18405 info->dimen[dim].upper_bound,
18407 if (info->dimen[dim].stride)
18408 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18409 info->dimen[dim].stride,
18413 gen_type_die (info->element_type, context_die);
18414 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18416 if (get_AT (array_die, DW_AT_name))
18417 add_pubtype (type, array_die);
18422 gen_entry_point_die (tree decl, dw_die_ref context_die)
18424 tree origin = decl_ultimate_origin (decl);
18425 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18427 if (origin != NULL)
18428 add_abstract_origin_attribute (decl_die, origin);
18431 add_name_and_src_coords_attributes (decl_die, decl);
18432 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18433 0, 0, context_die);
18436 if (DECL_ABSTRACT (decl))
18437 equate_decl_number_to_die (decl, decl_die);
18439 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18443 /* Walk through the list of incomplete types again, trying once more to
18444 emit full debugging info for them. */
18447 retry_incomplete_types (void)
18451 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18452 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18453 DINFO_USAGE_DIR_USE))
18454 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
18457 /* Determine what tag to use for a record type. */
18459 static enum dwarf_tag
18460 record_type_tag (tree type)
18462 if (! lang_hooks.types.classify_record)
18463 return DW_TAG_structure_type;
18465 switch (lang_hooks.types.classify_record (type))
18467 case RECORD_IS_STRUCT:
18468 return DW_TAG_structure_type;
18470 case RECORD_IS_CLASS:
18471 return DW_TAG_class_type;
18473 case RECORD_IS_INTERFACE:
18474 if (dwarf_version >= 3 || !dwarf_strict)
18475 return DW_TAG_interface_type;
18476 return DW_TAG_structure_type;
18479 gcc_unreachable ();
18483 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18484 include all of the information about the enumeration values also. Each
18485 enumerated type name/value is listed as a child of the enumerated type
18489 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18491 dw_die_ref type_die = lookup_type_die (type);
18493 if (type_die == NULL)
18495 type_die = new_die (DW_TAG_enumeration_type,
18496 scope_die_for (type, context_die), type);
18497 equate_type_number_to_die (type, type_die);
18498 add_name_attribute (type_die, type_tag (type));
18499 if (dwarf_version >= 4 || !dwarf_strict)
18501 if (ENUM_IS_SCOPED (type))
18502 add_AT_flag (type_die, DW_AT_enum_class, 1);
18503 if (ENUM_IS_OPAQUE (type))
18504 add_AT_flag (type_die, DW_AT_declaration, 1);
18507 else if (! TYPE_SIZE (type))
18510 remove_AT (type_die, DW_AT_declaration);
18512 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18513 given enum type is incomplete, do not generate the DW_AT_byte_size
18514 attribute or the DW_AT_element_list attribute. */
18515 if (TYPE_SIZE (type))
18519 TREE_ASM_WRITTEN (type) = 1;
18520 add_byte_size_attribute (type_die, type);
18521 if (TYPE_STUB_DECL (type) != NULL_TREE)
18523 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18524 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18527 /* If the first reference to this type was as the return type of an
18528 inline function, then it may not have a parent. Fix this now. */
18529 if (type_die->die_parent == NULL)
18530 add_child_die (scope_die_for (type, context_die), type_die);
18532 for (link = TYPE_VALUES (type);
18533 link != NULL; link = TREE_CHAIN (link))
18535 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18536 tree value = TREE_VALUE (link);
18538 add_name_attribute (enum_die,
18539 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18541 if (TREE_CODE (value) == CONST_DECL)
18542 value = DECL_INITIAL (value);
18544 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18545 /* DWARF2 does not provide a way of indicating whether or
18546 not enumeration constants are signed or unsigned. GDB
18547 always assumes the values are signed, so we output all
18548 values as if they were signed. That means that
18549 enumeration constants with very large unsigned values
18550 will appear to have negative values in the debugger. */
18551 add_AT_int (enum_die, DW_AT_const_value,
18552 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18556 add_AT_flag (type_die, DW_AT_declaration, 1);
18558 if (get_AT (type_die, DW_AT_name))
18559 add_pubtype (type, type_die);
18564 /* Generate a DIE to represent either a real live formal parameter decl or to
18565 represent just the type of some formal parameter position in some function
18568 Note that this routine is a bit unusual because its argument may be a
18569 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18570 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18571 node. If it's the former then this function is being called to output a
18572 DIE to represent a formal parameter object (or some inlining thereof). If
18573 it's the latter, then this function is only being called to output a
18574 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18575 argument type of some subprogram type.
18576 If EMIT_NAME_P is true, name and source coordinate attributes
18580 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18581 dw_die_ref context_die)
18583 tree node_or_origin = node ? node : origin;
18584 tree ultimate_origin;
18585 dw_die_ref parm_die
18586 = new_die (DW_TAG_formal_parameter, context_die, node);
18588 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18590 case tcc_declaration:
18591 ultimate_origin = decl_ultimate_origin (node_or_origin);
18592 if (node || ultimate_origin)
18593 origin = ultimate_origin;
18594 if (origin != NULL)
18595 add_abstract_origin_attribute (parm_die, origin);
18596 else if (emit_name_p)
18597 add_name_and_src_coords_attributes (parm_die, node);
18599 || (! DECL_ABSTRACT (node_or_origin)
18600 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18601 decl_function_context
18602 (node_or_origin))))
18604 tree type = TREE_TYPE (node_or_origin);
18605 if (decl_by_reference_p (node_or_origin))
18606 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18609 add_type_attribute (parm_die, type,
18610 TREE_READONLY (node_or_origin),
18611 TREE_THIS_VOLATILE (node_or_origin),
18614 if (origin == NULL && DECL_ARTIFICIAL (node))
18615 add_AT_flag (parm_die, DW_AT_artificial, 1);
18617 if (node && node != origin)
18618 equate_decl_number_to_die (node, parm_die);
18619 if (! DECL_ABSTRACT (node_or_origin))
18620 add_location_or_const_value_attribute (parm_die, node_or_origin,
18626 /* We were called with some kind of a ..._TYPE node. */
18627 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18631 gcc_unreachable ();
18637 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18638 children DW_TAG_formal_parameter DIEs representing the arguments of the
18641 PARM_PACK must be a function parameter pack.
18642 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18643 must point to the subsequent arguments of the function PACK_ARG belongs to.
18644 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18645 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18646 following the last one for which a DIE was generated. */
18649 gen_formal_parameter_pack_die (tree parm_pack,
18651 dw_die_ref subr_die,
18655 dw_die_ref parm_pack_die;
18657 gcc_assert (parm_pack
18658 && lang_hooks.function_parameter_pack_p (parm_pack)
18661 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18662 add_src_coords_attributes (parm_pack_die, parm_pack);
18664 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18666 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18669 gen_formal_parameter_die (arg, NULL,
18670 false /* Don't emit name attribute. */,
18675 return parm_pack_die;
18678 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18679 at the end of an (ANSI prototyped) formal parameters list. */
18682 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18684 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18687 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18688 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18689 parameters as specified in some function type specification (except for
18690 those which appear as part of a function *definition*). */
18693 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18696 tree formal_type = NULL;
18697 tree first_parm_type;
18700 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18702 arg = DECL_ARGUMENTS (function_or_method_type);
18703 function_or_method_type = TREE_TYPE (function_or_method_type);
18708 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18710 /* Make our first pass over the list of formal parameter types and output a
18711 DW_TAG_formal_parameter DIE for each one. */
18712 for (link = first_parm_type; link; )
18714 dw_die_ref parm_die;
18716 formal_type = TREE_VALUE (link);
18717 if (formal_type == void_type_node)
18720 /* Output a (nameless) DIE to represent the formal parameter itself. */
18721 parm_die = gen_formal_parameter_die (formal_type, NULL,
18722 true /* Emit name attribute. */,
18724 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18725 && link == first_parm_type)
18727 add_AT_flag (parm_die, DW_AT_artificial, 1);
18728 if (dwarf_version >= 3 || !dwarf_strict)
18729 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18731 else if (arg && DECL_ARTIFICIAL (arg))
18732 add_AT_flag (parm_die, DW_AT_artificial, 1);
18734 link = TREE_CHAIN (link);
18736 arg = DECL_CHAIN (arg);
18739 /* If this function type has an ellipsis, add a
18740 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18741 if (formal_type != void_type_node)
18742 gen_unspecified_parameters_die (function_or_method_type, context_die);
18744 /* Make our second (and final) pass over the list of formal parameter types
18745 and output DIEs to represent those types (as necessary). */
18746 for (link = TYPE_ARG_TYPES (function_or_method_type);
18747 link && TREE_VALUE (link);
18748 link = TREE_CHAIN (link))
18749 gen_type_die (TREE_VALUE (link), context_die);
18752 /* We want to generate the DIE for TYPE so that we can generate the
18753 die for MEMBER, which has been defined; we will need to refer back
18754 to the member declaration nested within TYPE. If we're trying to
18755 generate minimal debug info for TYPE, processing TYPE won't do the
18756 trick; we need to attach the member declaration by hand. */
18759 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18761 gen_type_die (type, context_die);
18763 /* If we're trying to avoid duplicate debug info, we may not have
18764 emitted the member decl for this function. Emit it now. */
18765 if (TYPE_STUB_DECL (type)
18766 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18767 && ! lookup_decl_die (member))
18769 dw_die_ref type_die;
18770 gcc_assert (!decl_ultimate_origin (member));
18772 push_decl_scope (type);
18773 type_die = lookup_type_die_strip_naming_typedef (type);
18774 if (TREE_CODE (member) == FUNCTION_DECL)
18775 gen_subprogram_die (member, type_die);
18776 else if (TREE_CODE (member) == FIELD_DECL)
18778 /* Ignore the nameless fields that are used to skip bits but handle
18779 C++ anonymous unions and structs. */
18780 if (DECL_NAME (member) != NULL_TREE
18781 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18782 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18784 gen_type_die (member_declared_type (member), type_die);
18785 gen_field_die (member, type_die);
18789 gen_variable_die (member, NULL_TREE, type_die);
18795 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18796 may later generate inlined and/or out-of-line instances of. */
18799 dwarf2out_abstract_function (tree decl)
18801 dw_die_ref old_die;
18805 htab_t old_decl_loc_table;
18806 int old_call_site_count, old_tail_call_site_count;
18807 struct call_arg_loc_node *old_call_arg_locations;
18809 /* Make sure we have the actual abstract inline, not a clone. */
18810 decl = DECL_ORIGIN (decl);
18812 old_die = lookup_decl_die (decl);
18813 if (old_die && get_AT (old_die, DW_AT_inline))
18814 /* We've already generated the abstract instance. */
18817 /* We can be called while recursively when seeing block defining inlined subroutine
18818 DIE. Be sure to not clobber the outer location table nor use it or we would
18819 get locations in abstract instantces. */
18820 old_decl_loc_table = decl_loc_table;
18821 decl_loc_table = NULL;
18822 old_call_arg_locations = call_arg_locations;
18823 call_arg_locations = NULL;
18824 old_call_site_count = call_site_count;
18825 call_site_count = -1;
18826 old_tail_call_site_count = tail_call_site_count;
18827 tail_call_site_count = -1;
18829 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18830 we don't get confused by DECL_ABSTRACT. */
18831 if (debug_info_level > DINFO_LEVEL_TERSE)
18833 context = decl_class_context (decl);
18835 gen_type_die_for_member
18836 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18839 /* Pretend we've just finished compiling this function. */
18840 save_fn = current_function_decl;
18841 current_function_decl = decl;
18842 push_cfun (DECL_STRUCT_FUNCTION (decl));
18844 was_abstract = DECL_ABSTRACT (decl);
18845 set_decl_abstract_flags (decl, 1);
18846 dwarf2out_decl (decl);
18847 if (! was_abstract)
18848 set_decl_abstract_flags (decl, 0);
18850 current_function_decl = save_fn;
18851 decl_loc_table = old_decl_loc_table;
18852 call_arg_locations = old_call_arg_locations;
18853 call_site_count = old_call_site_count;
18854 tail_call_site_count = old_tail_call_site_count;
18858 /* Helper function of premark_used_types() which gets called through
18861 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18862 marked as unused by prune_unused_types. */
18865 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
18870 type = (tree) *slot;
18871 die = lookup_type_die (type);
18873 die->die_perennial_p = 1;
18877 /* Helper function of premark_types_used_by_global_vars which gets called
18878 through htab_traverse.
18880 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18881 marked as unused by prune_unused_types. The DIE of the type is marked
18882 only if the global variable using the type will actually be emitted. */
18885 premark_types_used_by_global_vars_helper (void **slot,
18886 void *data ATTRIBUTE_UNUSED)
18888 struct types_used_by_vars_entry *entry;
18891 entry = (struct types_used_by_vars_entry *) *slot;
18892 gcc_assert (entry->type != NULL
18893 && entry->var_decl != NULL);
18894 die = lookup_type_die (entry->type);
18897 /* Ask cgraph if the global variable really is to be emitted.
18898 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18899 struct varpool_node *node = varpool_get_node (entry->var_decl);
18900 if (node && node->needed)
18902 die->die_perennial_p = 1;
18903 /* Keep the parent DIEs as well. */
18904 while ((die = die->die_parent) && die->die_perennial_p == 0)
18905 die->die_perennial_p = 1;
18911 /* Mark all members of used_types_hash as perennial. */
18914 premark_used_types (void)
18916 if (cfun && cfun->used_types_hash)
18917 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
18920 /* Mark all members of types_used_by_vars_entry as perennial. */
18923 premark_types_used_by_global_vars (void)
18925 if (types_used_by_vars_hash)
18926 htab_traverse (types_used_by_vars_hash,
18927 premark_types_used_by_global_vars_helper, NULL);
18930 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18931 for CA_LOC call arg loc node. */
18934 gen_call_site_die (tree decl, dw_die_ref subr_die,
18935 struct call_arg_loc_node *ca_loc)
18937 dw_die_ref stmt_die = NULL, die;
18938 tree block = ca_loc->block;
18941 && block != DECL_INITIAL (decl)
18942 && TREE_CODE (block) == BLOCK)
18944 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
18945 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
18948 block = BLOCK_SUPERCONTEXT (block);
18950 if (stmt_die == NULL)
18951 stmt_die = subr_die;
18952 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
18953 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
18954 if (ca_loc->tail_call_p)
18955 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
18956 if (ca_loc->symbol_ref)
18958 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
18960 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
18962 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
18967 /* Generate a DIE to represent a declared function (either file-scope or
18971 gen_subprogram_die (tree decl, dw_die_ref context_die)
18973 tree origin = decl_ultimate_origin (decl);
18974 dw_die_ref subr_die;
18976 dw_die_ref old_die = lookup_decl_die (decl);
18977 int declaration = (current_function_decl != decl
18978 || class_or_namespace_scope_p (context_die));
18980 premark_used_types ();
18982 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18983 started to generate the abstract instance of an inline, decided to output
18984 its containing class, and proceeded to emit the declaration of the inline
18985 from the member list for the class. If so, DECLARATION takes priority;
18986 we'll get back to the abstract instance when done with the class. */
18988 /* The class-scope declaration DIE must be the primary DIE. */
18989 if (origin && declaration && class_or_namespace_scope_p (context_die))
18992 gcc_assert (!old_die);
18995 /* Now that the C++ front end lazily declares artificial member fns, we
18996 might need to retrofit the declaration into its class. */
18997 if (!declaration && !origin && !old_die
18998 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
18999 && !class_or_namespace_scope_p (context_die)
19000 && debug_info_level > DINFO_LEVEL_TERSE)
19001 old_die = force_decl_die (decl);
19003 if (origin != NULL)
19005 gcc_assert (!declaration || local_scope_p (context_die));
19007 /* Fixup die_parent for the abstract instance of a nested
19008 inline function. */
19009 if (old_die && old_die->die_parent == NULL)
19010 add_child_die (context_die, old_die);
19012 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19013 add_abstract_origin_attribute (subr_die, origin);
19017 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19018 struct dwarf_file_data * file_index = lookup_filename (s.file);
19020 if (!get_AT_flag (old_die, DW_AT_declaration)
19021 /* We can have a normal definition following an inline one in the
19022 case of redefinition of GNU C extern inlines.
19023 It seems reasonable to use AT_specification in this case. */
19024 && !get_AT (old_die, DW_AT_inline))
19026 /* Detect and ignore this case, where we are trying to output
19027 something we have already output. */
19031 /* If the definition comes from the same place as the declaration,
19032 maybe use the old DIE. We always want the DIE for this function
19033 that has the *_pc attributes to be under comp_unit_die so the
19034 debugger can find it. We also need to do this for abstract
19035 instances of inlines, since the spec requires the out-of-line copy
19036 to have the same parent. For local class methods, this doesn't
19037 apply; we just use the old DIE. */
19038 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
19039 && (DECL_ARTIFICIAL (decl)
19040 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
19041 && (get_AT_unsigned (old_die, DW_AT_decl_line)
19042 == (unsigned) s.line))))
19044 subr_die = old_die;
19046 /* Clear out the declaration attribute and the formal parameters.
19047 Do not remove all children, because it is possible that this
19048 declaration die was forced using force_decl_die(). In such
19049 cases die that forced declaration die (e.g. TAG_imported_module)
19050 is one of the children that we do not want to remove. */
19051 remove_AT (subr_die, DW_AT_declaration);
19052 remove_AT (subr_die, DW_AT_object_pointer);
19053 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
19057 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19058 add_AT_specification (subr_die, old_die);
19059 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19060 add_AT_file (subr_die, DW_AT_decl_file, file_index);
19061 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19062 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
19067 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19069 if (TREE_PUBLIC (decl))
19070 add_AT_flag (subr_die, DW_AT_external, 1);
19072 add_name_and_src_coords_attributes (subr_die, decl);
19073 if (debug_info_level > DINFO_LEVEL_TERSE)
19075 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
19076 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
19077 0, 0, context_die);
19080 add_pure_or_virtual_attribute (subr_die, decl);
19081 if (DECL_ARTIFICIAL (decl))
19082 add_AT_flag (subr_die, DW_AT_artificial, 1);
19084 add_accessibility_attribute (subr_die, decl);
19089 if (!old_die || !get_AT (old_die, DW_AT_inline))
19091 add_AT_flag (subr_die, DW_AT_declaration, 1);
19093 /* If this is an explicit function declaration then generate
19094 a DW_AT_explicit attribute. */
19095 if (lang_hooks.decls.function_decl_explicit_p (decl)
19096 && (dwarf_version >= 3 || !dwarf_strict))
19097 add_AT_flag (subr_die, DW_AT_explicit, 1);
19099 /* The first time we see a member function, it is in the context of
19100 the class to which it belongs. We make sure of this by emitting
19101 the class first. The next time is the definition, which is
19102 handled above. The two may come from the same source text.
19104 Note that force_decl_die() forces function declaration die. It is
19105 later reused to represent definition. */
19106 equate_decl_number_to_die (decl, subr_die);
19109 else if (DECL_ABSTRACT (decl))
19111 if (DECL_DECLARED_INLINE_P (decl))
19113 if (cgraph_function_possibly_inlined_p (decl))
19114 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19116 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19120 if (cgraph_function_possibly_inlined_p (decl))
19121 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19123 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19126 if (DECL_DECLARED_INLINE_P (decl)
19127 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19128 add_AT_flag (subr_die, DW_AT_artificial, 1);
19130 equate_decl_number_to_die (decl, subr_die);
19132 else if (!DECL_EXTERNAL (decl))
19134 HOST_WIDE_INT cfa_fb_offset;
19136 if (!old_die || !get_AT (old_die, DW_AT_inline))
19137 equate_decl_number_to_die (decl, subr_die);
19139 if (!flag_reorder_blocks_and_partition)
19141 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19142 if (fde->dw_fde_begin)
19144 /* We have already generated the labels. */
19145 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19146 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19150 /* Create start/end labels and add the range. */
19151 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
19152 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19153 current_function_funcdef_no);
19154 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19155 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19156 current_function_funcdef_no);
19157 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19160 #if VMS_DEBUGGING_INFO
19161 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19162 Section 2.3 Prologue and Epilogue Attributes:
19163 When a breakpoint is set on entry to a function, it is generally
19164 desirable for execution to be suspended, not on the very first
19165 instruction of the function, but rather at a point after the
19166 function's frame has been set up, after any language defined local
19167 declaration processing has been completed, and before execution of
19168 the first statement of the function begins. Debuggers generally
19169 cannot properly determine where this point is. Similarly for a
19170 breakpoint set on exit from a function. The prologue and epilogue
19171 attributes allow a compiler to communicate the location(s) to use. */
19174 if (fde->dw_fde_vms_end_prologue)
19175 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19176 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19178 if (fde->dw_fde_vms_begin_epilogue)
19179 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19180 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19184 add_pubname (decl, subr_die);
19185 add_arange (decl, subr_die);
19188 { /* Generate pubnames entries for the split function code
19190 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19192 if (fde->dw_fde_switched_sections)
19194 if (dwarf_version >= 3 || !dwarf_strict)
19196 /* We should use ranges for non-contiguous code section
19197 addresses. Use the actual code range for the initial
19198 section, since the HOT/COLD labels might precede an
19199 alignment offset. */
19200 bool range_list_added = false;
19201 if (fde->in_std_section)
19203 add_ranges_by_labels (subr_die,
19206 &range_list_added);
19207 add_ranges_by_labels (subr_die,
19208 fde->dw_fde_unlikely_section_label,
19209 fde->dw_fde_unlikely_section_end_label,
19210 &range_list_added);
19214 add_ranges_by_labels (subr_die,
19217 &range_list_added);
19218 add_ranges_by_labels (subr_die,
19219 fde->dw_fde_hot_section_label,
19220 fde->dw_fde_hot_section_end_label,
19221 &range_list_added);
19223 add_pubname (decl, subr_die);
19224 if (range_list_added)
19229 /* There is no real support in DW2 for this .. so we make
19230 a work-around. First, emit the pub name for the segment
19231 containing the function label. Then make and emit a
19232 simplified subprogram DIE for the second segment with the
19233 name pre-fixed by __hot/cold_sect_of_. We use the same
19234 linkage name for the second die so that gdb will find both
19235 sections when given "b foo". */
19236 const char *name = NULL;
19237 tree decl_name = DECL_NAME (decl);
19238 dw_die_ref seg_die;
19240 /* Do the 'primary' section. */
19241 add_AT_lbl_id (subr_die, DW_AT_low_pc,
19242 fde->dw_fde_begin);
19243 add_AT_lbl_id (subr_die, DW_AT_high_pc,
19246 add_pubname (decl, subr_die);
19247 add_arange (decl, subr_die);
19249 /* Build a minimal DIE for the secondary section. */
19250 seg_die = new_die (DW_TAG_subprogram,
19251 subr_die->die_parent, decl);
19253 if (TREE_PUBLIC (decl))
19254 add_AT_flag (seg_die, DW_AT_external, 1);
19256 if (decl_name != NULL
19257 && IDENTIFIER_POINTER (decl_name) != NULL)
19259 name = dwarf2_name (decl, 1);
19260 if (! DECL_ARTIFICIAL (decl))
19261 add_src_coords_attributes (seg_die, decl);
19263 add_linkage_name (seg_die, decl);
19265 gcc_assert (name!=NULL);
19266 add_pure_or_virtual_attribute (seg_die, decl);
19267 if (DECL_ARTIFICIAL (decl))
19268 add_AT_flag (seg_die, DW_AT_artificial, 1);
19270 if (fde->in_std_section)
19272 name = concat ("__cold_sect_of_", name, NULL);
19273 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19274 fde->dw_fde_unlikely_section_label);
19275 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19276 fde->dw_fde_unlikely_section_end_label);
19280 name = concat ("__hot_sect_of_", name, NULL);
19281 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19282 fde->dw_fde_hot_section_label);
19283 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19284 fde->dw_fde_hot_section_end_label);
19286 add_name_attribute (seg_die, name);
19287 add_pubname_string (name, seg_die);
19288 add_arange (decl, seg_die);
19293 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19294 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19295 add_pubname (decl, subr_die);
19296 add_arange (decl, subr_die);
19300 #ifdef MIPS_DEBUGGING_INFO
19301 /* Add a reference to the FDE for this routine. */
19302 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19305 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19307 /* We define the "frame base" as the function's CFA. This is more
19308 convenient for several reasons: (1) It's stable across the prologue
19309 and epilogue, which makes it better than just a frame pointer,
19310 (2) With dwarf3, there exists a one-byte encoding that allows us
19311 to reference the .debug_frame data by proxy, but failing that,
19312 (3) We can at least reuse the code inspection and interpretation
19313 code that determines the CFA position at various points in the
19315 if (dwarf_version >= 3)
19317 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19318 add_AT_loc (subr_die, DW_AT_frame_base, op);
19322 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19323 if (list->dw_loc_next)
19324 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19326 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19329 /* Compute a displacement from the "steady-state frame pointer" to
19330 the CFA. The former is what all stack slots and argument slots
19331 will reference in the rtl; the later is what we've told the
19332 debugger about. We'll need to adjust all frame_base references
19333 by this displacement. */
19334 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19336 if (cfun->static_chain_decl)
19337 add_AT_location_description (subr_die, DW_AT_static_link,
19338 loc_list_from_tree (cfun->static_chain_decl, 2));
19341 /* Generate child dies for template paramaters. */
19342 if (debug_info_level > DINFO_LEVEL_TERSE)
19343 gen_generic_params_dies (decl);
19345 /* Now output descriptions of the arguments for this function. This gets
19346 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19347 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19348 `...' at the end of the formal parameter list. In order to find out if
19349 there was a trailing ellipsis or not, we must instead look at the type
19350 associated with the FUNCTION_DECL. This will be a node of type
19351 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19352 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19353 an ellipsis at the end. */
19355 /* In the case where we are describing a mere function declaration, all we
19356 need to do here (and all we *can* do here) is to describe the *types* of
19357 its formal parameters. */
19358 if (debug_info_level <= DINFO_LEVEL_TERSE)
19360 else if (declaration)
19361 gen_formal_types_die (decl, subr_die);
19364 /* Generate DIEs to represent all known formal parameters. */
19365 tree parm = DECL_ARGUMENTS (decl);
19366 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19367 tree generic_decl_parm = generic_decl
19368 ? DECL_ARGUMENTS (generic_decl)
19371 /* Now we want to walk the list of parameters of the function and
19372 emit their relevant DIEs.
19374 We consider the case of DECL being an instance of a generic function
19375 as well as it being a normal function.
19377 If DECL is an instance of a generic function we walk the
19378 parameters of the generic function declaration _and_ the parameters of
19379 DECL itself. This is useful because we want to emit specific DIEs for
19380 function parameter packs and those are declared as part of the
19381 generic function declaration. In that particular case,
19382 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19383 That DIE has children DIEs representing the set of arguments
19384 of the pack. Note that the set of pack arguments can be empty.
19385 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19388 Otherwise, we just consider the parameters of DECL. */
19389 while (generic_decl_parm || parm)
19391 if (generic_decl_parm
19392 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19393 gen_formal_parameter_pack_die (generic_decl_parm,
19398 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19400 if (parm == DECL_ARGUMENTS (decl)
19401 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19403 && (dwarf_version >= 3 || !dwarf_strict))
19404 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19406 parm = DECL_CHAIN (parm);
19409 if (generic_decl_parm)
19410 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19413 /* Decide whether we need an unspecified_parameters DIE at the end.
19414 There are 2 more cases to do this for: 1) the ansi ... declaration -
19415 this is detectable when the end of the arg list is not a
19416 void_type_node 2) an unprototyped function declaration (not a
19417 definition). This just means that we have no info about the
19418 parameters at all. */
19419 if (prototype_p (TREE_TYPE (decl)))
19421 /* This is the prototyped case, check for.... */
19422 if (stdarg_p (TREE_TYPE (decl)))
19423 gen_unspecified_parameters_die (decl, subr_die);
19425 else if (DECL_INITIAL (decl) == NULL_TREE)
19426 gen_unspecified_parameters_die (decl, subr_die);
19429 /* Output Dwarf info for all of the stuff within the body of the function
19430 (if it has one - it may be just a declaration). */
19431 outer_scope = DECL_INITIAL (decl);
19433 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19434 a function. This BLOCK actually represents the outermost binding contour
19435 for the function, i.e. the contour in which the function's formal
19436 parameters and labels get declared. Curiously, it appears that the front
19437 end doesn't actually put the PARM_DECL nodes for the current function onto
19438 the BLOCK_VARS list for this outer scope, but are strung off of the
19439 DECL_ARGUMENTS list for the function instead.
19441 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19442 the LABEL_DECL nodes for the function however, and we output DWARF info
19443 for those in decls_for_scope. Just within the `outer_scope' there will be
19444 a BLOCK node representing the function's outermost pair of curly braces,
19445 and any blocks used for the base and member initializers of a C++
19446 constructor function. */
19447 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19449 int call_site_note_count = 0;
19450 int tail_call_site_note_count = 0;
19452 /* Emit a DW_TAG_variable DIE for a named return value. */
19453 if (DECL_NAME (DECL_RESULT (decl)))
19454 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19456 current_function_has_inlines = 0;
19457 decls_for_scope (outer_scope, subr_die, 0);
19459 if (call_arg_locations && !dwarf_strict)
19461 struct call_arg_loc_node *ca_loc;
19462 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
19464 dw_die_ref die = NULL;
19465 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
19468 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
19469 arg; arg = next_arg)
19471 dw_loc_descr_ref reg, val;
19472 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
19475 next_arg = XEXP (arg, 1);
19476 if (REG_P (XEXP (XEXP (arg, 0), 0))
19478 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
19479 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
19480 && REGNO (XEXP (XEXP (arg, 0), 0))
19481 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
19482 next_arg = XEXP (next_arg, 1);
19483 if (mode == VOIDmode)
19485 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
19486 if (mode == VOIDmode)
19487 mode = GET_MODE (XEXP (arg, 0));
19489 if (GET_MODE_CLASS (mode) != MODE_INT
19490 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
19492 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
19494 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19495 tloc = XEXP (XEXP (arg, 0), 1);
19498 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
19499 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
19501 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19502 tlocc = XEXP (XEXP (arg, 0), 1);
19505 if (REG_P (XEXP (XEXP (arg, 0), 0)))
19506 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
19507 VAR_INIT_STATUS_INITIALIZED);
19508 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
19509 reg = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 0),
19511 VAR_INIT_STATUS_INITIALIZED);
19516 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), VOIDmode,
19517 VAR_INIT_STATUS_INITIALIZED);
19521 die = gen_call_site_die (decl, subr_die, ca_loc);
19522 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
19524 add_AT_loc (cdie, DW_AT_location, reg);
19525 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
19526 if (next_arg != XEXP (arg, 1))
19528 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
19530 VAR_INIT_STATUS_INITIALIZED);
19532 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
19536 && (ca_loc->symbol_ref || tloc))
19537 die = gen_call_site_die (decl, subr_die, ca_loc);
19538 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
19540 dw_loc_descr_ref tval = NULL;
19542 if (tloc != NULL_RTX)
19543 tval = mem_loc_descriptor (tloc, VOIDmode,
19544 VAR_INIT_STATUS_INITIALIZED);
19546 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
19547 else if (tlocc != NULL_RTX)
19549 tval = mem_loc_descriptor (tlocc, VOIDmode,
19550 VAR_INIT_STATUS_INITIALIZED);
19552 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
19558 call_site_note_count++;
19559 if (ca_loc->tail_call_p)
19560 tail_call_site_note_count++;
19564 call_arg_locations = NULL;
19565 call_arg_loc_last = NULL;
19566 if (tail_call_site_count >= 0
19567 && tail_call_site_count == tail_call_site_note_count
19570 if (call_site_count >= 0
19571 && call_site_count == call_site_note_count)
19572 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
19574 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
19576 call_site_count = -1;
19577 tail_call_site_count = -1;
19579 /* Add the calling convention attribute if requested. */
19580 add_calling_convention_attribute (subr_die, decl);
19584 /* Returns a hash value for X (which really is a die_struct). */
19587 common_block_die_table_hash (const void *x)
19589 const_dw_die_ref d = (const_dw_die_ref) x;
19590 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19593 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19594 as decl_id and die_parent of die_struct Y. */
19597 common_block_die_table_eq (const void *x, const void *y)
19599 const_dw_die_ref d = (const_dw_die_ref) x;
19600 const_dw_die_ref e = (const_dw_die_ref) y;
19601 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19604 /* Generate a DIE to represent a declared data object.
19605 Either DECL or ORIGIN must be non-null. */
19608 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19612 tree decl_or_origin = decl ? decl : origin;
19613 tree ultimate_origin;
19614 dw_die_ref var_die;
19615 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19616 dw_die_ref origin_die;
19617 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19618 || class_or_namespace_scope_p (context_die));
19619 bool specialization_p = false;
19621 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19622 if (decl || ultimate_origin)
19623 origin = ultimate_origin;
19624 com_decl = fortran_common (decl_or_origin, &off);
19626 /* Symbol in common gets emitted as a child of the common block, in the form
19627 of a data member. */
19630 dw_die_ref com_die;
19631 dw_loc_list_ref loc;
19632 die_node com_die_arg;
19634 var_die = lookup_decl_die (decl_or_origin);
19637 if (get_AT (var_die, DW_AT_location) == NULL)
19639 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19644 /* Optimize the common case. */
19645 if (single_element_loc_list_p (loc)
19646 && loc->expr->dw_loc_opc == DW_OP_addr
19647 && loc->expr->dw_loc_next == NULL
19648 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19650 loc->expr->dw_loc_oprnd1.v.val_addr
19651 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19653 loc_list_plus_const (loc, off);
19655 add_AT_location_description (var_die, DW_AT_location, loc);
19656 remove_AT (var_die, DW_AT_declaration);
19662 if (common_block_die_table == NULL)
19663 common_block_die_table
19664 = htab_create_ggc (10, common_block_die_table_hash,
19665 common_block_die_table_eq, NULL);
19667 com_die_arg.decl_id = DECL_UID (com_decl);
19668 com_die_arg.die_parent = context_die;
19669 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19670 loc = loc_list_from_tree (com_decl, 2);
19671 if (com_die == NULL)
19674 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19677 com_die = new_die (DW_TAG_common_block, context_die, decl);
19678 add_name_and_src_coords_attributes (com_die, com_decl);
19681 add_AT_location_description (com_die, DW_AT_location, loc);
19682 /* Avoid sharing the same loc descriptor between
19683 DW_TAG_common_block and DW_TAG_variable. */
19684 loc = loc_list_from_tree (com_decl, 2);
19686 else if (DECL_EXTERNAL (decl))
19687 add_AT_flag (com_die, DW_AT_declaration, 1);
19688 add_pubname_string (cnam, com_die); /* ??? needed? */
19689 com_die->decl_id = DECL_UID (com_decl);
19690 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19691 *slot = (void *) com_die;
19693 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19695 add_AT_location_description (com_die, DW_AT_location, loc);
19696 loc = loc_list_from_tree (com_decl, 2);
19697 remove_AT (com_die, DW_AT_declaration);
19699 var_die = new_die (DW_TAG_variable, com_die, decl);
19700 add_name_and_src_coords_attributes (var_die, decl);
19701 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19702 TREE_THIS_VOLATILE (decl), context_die);
19703 add_AT_flag (var_die, DW_AT_external, 1);
19708 /* Optimize the common case. */
19709 if (single_element_loc_list_p (loc)
19710 && loc->expr->dw_loc_opc == DW_OP_addr
19711 && loc->expr->dw_loc_next == NULL
19712 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19713 loc->expr->dw_loc_oprnd1.v.val_addr
19714 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19716 loc_list_plus_const (loc, off);
19718 add_AT_location_description (var_die, DW_AT_location, loc);
19720 else if (DECL_EXTERNAL (decl))
19721 add_AT_flag (var_die, DW_AT_declaration, 1);
19722 equate_decl_number_to_die (decl, var_die);
19726 /* If the compiler emitted a definition for the DECL declaration
19727 and if we already emitted a DIE for it, don't emit a second
19728 DIE for it again. Allow re-declarations of DECLs that are
19729 inside functions, though. */
19730 if (old_die && declaration && !local_scope_p (context_die))
19733 /* For static data members, the declaration in the class is supposed
19734 to have DW_TAG_member tag; the specification should still be
19735 DW_TAG_variable referencing the DW_TAG_member DIE. */
19736 if (declaration && class_scope_p (context_die))
19737 var_die = new_die (DW_TAG_member, context_die, decl);
19739 var_die = new_die (DW_TAG_variable, context_die, decl);
19742 if (origin != NULL)
19743 origin_die = add_abstract_origin_attribute (var_die, origin);
19745 /* Loop unrolling can create multiple blocks that refer to the same
19746 static variable, so we must test for the DW_AT_declaration flag.
19748 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19749 copy decls and set the DECL_ABSTRACT flag on them instead of
19752 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19754 ??? The declare_in_namespace support causes us to get two DIEs for one
19755 variable, both of which are declarations. We want to avoid considering
19756 one to be a specification, so we must test that this DIE is not a
19758 else if (old_die && TREE_STATIC (decl) && ! declaration
19759 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19761 /* This is a definition of a C++ class level static. */
19762 add_AT_specification (var_die, old_die);
19763 specialization_p = true;
19764 if (DECL_NAME (decl))
19766 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19767 struct dwarf_file_data * file_index = lookup_filename (s.file);
19769 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19770 add_AT_file (var_die, DW_AT_decl_file, file_index);
19772 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19773 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19775 if (old_die->die_tag == DW_TAG_member)
19776 add_linkage_name (var_die, decl);
19780 add_name_and_src_coords_attributes (var_die, decl);
19782 if ((origin == NULL && !specialization_p)
19784 && !DECL_ABSTRACT (decl_or_origin)
19785 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19786 decl_function_context
19787 (decl_or_origin))))
19789 tree type = TREE_TYPE (decl_or_origin);
19791 if (decl_by_reference_p (decl_or_origin))
19792 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19794 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19795 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19798 if (origin == NULL && !specialization_p)
19800 if (TREE_PUBLIC (decl))
19801 add_AT_flag (var_die, DW_AT_external, 1);
19803 if (DECL_ARTIFICIAL (decl))
19804 add_AT_flag (var_die, DW_AT_artificial, 1);
19806 add_accessibility_attribute (var_die, decl);
19810 add_AT_flag (var_die, DW_AT_declaration, 1);
19812 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19813 equate_decl_number_to_die (decl, var_die);
19816 && (! DECL_ABSTRACT (decl_or_origin)
19817 /* Local static vars are shared between all clones/inlines,
19818 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19820 || (TREE_CODE (decl_or_origin) == VAR_DECL
19821 && TREE_STATIC (decl_or_origin)
19822 && DECL_RTL_SET_P (decl_or_origin)))
19823 /* When abstract origin already has DW_AT_location attribute, no need
19824 to add it again. */
19825 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19827 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19828 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19829 defer_location (decl_or_origin, var_die);
19831 add_location_or_const_value_attribute (var_die,
19834 add_pubname (decl_or_origin, var_die);
19837 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19840 /* Generate a DIE to represent a named constant. */
19843 gen_const_die (tree decl, dw_die_ref context_die)
19845 dw_die_ref const_die;
19846 tree type = TREE_TYPE (decl);
19848 const_die = new_die (DW_TAG_constant, context_die, decl);
19849 add_name_and_src_coords_attributes (const_die, decl);
19850 add_type_attribute (const_die, type, 1, 0, context_die);
19851 if (TREE_PUBLIC (decl))
19852 add_AT_flag (const_die, DW_AT_external, 1);
19853 if (DECL_ARTIFICIAL (decl))
19854 add_AT_flag (const_die, DW_AT_artificial, 1);
19855 tree_add_const_value_attribute_for_decl (const_die, decl);
19858 /* Generate a DIE to represent a label identifier. */
19861 gen_label_die (tree decl, dw_die_ref context_die)
19863 tree origin = decl_ultimate_origin (decl);
19864 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19866 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19868 if (origin != NULL)
19869 add_abstract_origin_attribute (lbl_die, origin);
19871 add_name_and_src_coords_attributes (lbl_die, decl);
19873 if (DECL_ABSTRACT (decl))
19874 equate_decl_number_to_die (decl, lbl_die);
19877 insn = DECL_RTL_IF_SET (decl);
19879 /* Deleted labels are programmer specified labels which have been
19880 eliminated because of various optimizations. We still emit them
19881 here so that it is possible to put breakpoints on them. */
19885 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19887 /* When optimization is enabled (via -O) some parts of the compiler
19888 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19889 represent source-level labels which were explicitly declared by
19890 the user. This really shouldn't be happening though, so catch
19891 it if it ever does happen. */
19892 gcc_assert (!INSN_DELETED_P (insn));
19894 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19895 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19900 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19901 attributes to the DIE for a block STMT, to describe where the inlined
19902 function was called from. This is similar to add_src_coords_attributes. */
19905 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19907 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19909 if (dwarf_version >= 3 || !dwarf_strict)
19911 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19912 add_AT_unsigned (die, DW_AT_call_line, s.line);
19917 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19918 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19921 add_high_low_attributes (tree stmt, dw_die_ref die)
19923 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19925 if (BLOCK_FRAGMENT_CHAIN (stmt)
19926 && (dwarf_version >= 3 || !dwarf_strict))
19930 if (inlined_function_outer_scope_p (stmt))
19932 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19933 BLOCK_NUMBER (stmt));
19934 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19937 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19939 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19942 add_ranges (chain);
19943 chain = BLOCK_FRAGMENT_CHAIN (chain);
19950 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19951 BLOCK_NUMBER (stmt));
19952 add_AT_lbl_id (die, DW_AT_low_pc, label);
19953 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
19954 BLOCK_NUMBER (stmt));
19955 add_AT_lbl_id (die, DW_AT_high_pc, label);
19959 /* Generate a DIE for a lexical block. */
19962 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
19964 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19966 if (call_arg_locations)
19968 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
19969 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
19970 BLOCK_NUMBER (stmt) + 1);
19971 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
19974 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19975 add_high_low_attributes (stmt, stmt_die);
19977 decls_for_scope (stmt, stmt_die, depth);
19980 /* Generate a DIE for an inlined subprogram. */
19983 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
19987 /* The instance of function that is effectively being inlined shall not
19989 gcc_assert (! BLOCK_ABSTRACT (stmt));
19991 decl = block_ultimate_origin (stmt);
19993 /* Emit info for the abstract instance first, if we haven't yet. We
19994 must emit this even if the block is abstract, otherwise when we
19995 emit the block below (or elsewhere), we may end up trying to emit
19996 a die whose origin die hasn't been emitted, and crashing. */
19997 dwarf2out_abstract_function (decl);
19999 if (! BLOCK_ABSTRACT (stmt))
20001 dw_die_ref subr_die
20002 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
20004 if (call_arg_locations)
20006 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
20007 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
20008 BLOCK_NUMBER (stmt) + 1);
20009 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
20011 add_abstract_origin_attribute (subr_die, decl);
20012 if (TREE_ASM_WRITTEN (stmt))
20013 add_high_low_attributes (stmt, subr_die);
20014 add_call_src_coords_attributes (stmt, subr_die);
20016 decls_for_scope (stmt, subr_die, depth);
20017 current_function_has_inlines = 1;
20021 /* Generate a DIE for a field in a record, or structure. */
20024 gen_field_die (tree decl, dw_die_ref context_die)
20026 dw_die_ref decl_die;
20028 if (TREE_TYPE (decl) == error_mark_node)
20031 decl_die = new_die (DW_TAG_member, context_die, decl);
20032 add_name_and_src_coords_attributes (decl_die, decl);
20033 add_type_attribute (decl_die, member_declared_type (decl),
20034 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
20037 if (DECL_BIT_FIELD_TYPE (decl))
20039 add_byte_size_attribute (decl_die, decl);
20040 add_bit_size_attribute (decl_die, decl);
20041 add_bit_offset_attribute (decl_die, decl);
20044 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
20045 add_data_member_location_attribute (decl_die, decl);
20047 if (DECL_ARTIFICIAL (decl))
20048 add_AT_flag (decl_die, DW_AT_artificial, 1);
20050 add_accessibility_attribute (decl_die, decl);
20052 /* Equate decl number to die, so that we can look up this decl later on. */
20053 equate_decl_number_to_die (decl, decl_die);
20057 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20058 Use modified_type_die instead.
20059 We keep this code here just in case these types of DIEs may be needed to
20060 represent certain things in other languages (e.g. Pascal) someday. */
20063 gen_pointer_type_die (tree type, dw_die_ref context_die)
20066 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20068 equate_type_number_to_die (type, ptr_die);
20069 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20070 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20073 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20074 Use modified_type_die instead.
20075 We keep this code here just in case these types of DIEs may be needed to
20076 represent certain things in other languages (e.g. Pascal) someday. */
20079 gen_reference_type_die (tree type, dw_die_ref context_die)
20081 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20083 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
20084 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20086 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20088 equate_type_number_to_die (type, ref_die);
20089 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
20090 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20094 /* Generate a DIE for a pointer to a member type. */
20097 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20100 = new_die (DW_TAG_ptr_to_member_type,
20101 scope_die_for (type, context_die), type);
20103 equate_type_number_to_die (type, ptr_die);
20104 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20105 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20106 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20109 /* Generate the DIE for the compilation unit. */
20112 gen_compile_unit_die (const char *filename)
20115 char producer[250];
20116 const char *language_string = lang_hooks.name;
20119 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20123 add_name_attribute (die, filename);
20124 /* Don't add cwd for <built-in>. */
20125 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20126 add_comp_dir_attribute (die);
20129 sprintf (producer, "%s %s", language_string, version_string);
20131 #ifdef MIPS_DEBUGGING_INFO
20132 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20133 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20134 not appear in the producer string, the debugger reaches the conclusion
20135 that the object file is stripped and has no debugging information.
20136 To get the MIPS/SGI debugger to believe that there is debugging
20137 information in the object file, we add a -g to the producer string. */
20138 if (debug_info_level > DINFO_LEVEL_TERSE)
20139 strcat (producer, " -g");
20142 add_AT_string (die, DW_AT_producer, producer);
20144 /* If our producer is LTO try to figure out a common language to use
20145 from the global list of translation units. */
20146 if (strcmp (language_string, "GNU GIMPLE") == 0)
20150 const char *common_lang = NULL;
20152 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
20154 if (!TRANSLATION_UNIT_LANGUAGE (t))
20157 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20158 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20160 else if (strncmp (common_lang, "GNU C", 5) == 0
20161 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20162 /* Mixing C and C++ is ok, use C++ in that case. */
20163 common_lang = "GNU C++";
20166 /* Fall back to C. */
20167 common_lang = NULL;
20173 language_string = common_lang;
20176 language = DW_LANG_C89;
20177 if (strcmp (language_string, "GNU C++") == 0)
20178 language = DW_LANG_C_plus_plus;
20179 else if (strcmp (language_string, "GNU F77") == 0)
20180 language = DW_LANG_Fortran77;
20181 else if (strcmp (language_string, "GNU Pascal") == 0)
20182 language = DW_LANG_Pascal83;
20183 else if (dwarf_version >= 3 || !dwarf_strict)
20185 if (strcmp (language_string, "GNU Ada") == 0)
20186 language = DW_LANG_Ada95;
20187 else if (strcmp (language_string, "GNU Fortran") == 0)
20188 language = DW_LANG_Fortran95;
20189 else if (strcmp (language_string, "GNU Java") == 0)
20190 language = DW_LANG_Java;
20191 else if (strcmp (language_string, "GNU Objective-C") == 0)
20192 language = DW_LANG_ObjC;
20193 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20194 language = DW_LANG_ObjC_plus_plus;
20197 add_AT_unsigned (die, DW_AT_language, language);
20201 case DW_LANG_Fortran77:
20202 case DW_LANG_Fortran90:
20203 case DW_LANG_Fortran95:
20204 /* Fortran has case insensitive identifiers and the front-end
20205 lowercases everything. */
20206 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20209 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20215 /* Generate the DIE for a base class. */
20218 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20220 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20222 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
20223 add_data_member_location_attribute (die, binfo);
20225 if (BINFO_VIRTUAL_P (binfo))
20226 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20228 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20229 children, otherwise the default is DW_ACCESS_public. In DWARF2
20230 the default has always been DW_ACCESS_private. */
20231 if (access == access_public_node)
20233 if (dwarf_version == 2
20234 || context_die->die_tag == DW_TAG_class_type)
20235 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20237 else if (access == access_protected_node)
20238 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20239 else if (dwarf_version > 2
20240 && context_die->die_tag != DW_TAG_class_type)
20241 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20244 /* Generate a DIE for a class member. */
20247 gen_member_die (tree type, dw_die_ref context_die)
20250 tree binfo = TYPE_BINFO (type);
20253 /* If this is not an incomplete type, output descriptions of each of its
20254 members. Note that as we output the DIEs necessary to represent the
20255 members of this record or union type, we will also be trying to output
20256 DIEs to represent the *types* of those members. However the `type'
20257 function (above) will specifically avoid generating type DIEs for member
20258 types *within* the list of member DIEs for this (containing) type except
20259 for those types (of members) which are explicitly marked as also being
20260 members of this (containing) type themselves. The g++ front- end can
20261 force any given type to be treated as a member of some other (containing)
20262 type by setting the TYPE_CONTEXT of the given (member) type to point to
20263 the TREE node representing the appropriate (containing) type. */
20265 /* First output info about the base classes. */
20268 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
20272 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20273 gen_inheritance_die (base,
20274 (accesses ? VEC_index (tree, accesses, i)
20275 : access_public_node), context_die);
20278 /* Now output info about the data members and type members. */
20279 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20281 /* If we thought we were generating minimal debug info for TYPE
20282 and then changed our minds, some of the member declarations
20283 may have already been defined. Don't define them again, but
20284 do put them in the right order. */
20286 child = lookup_decl_die (member);
20288 splice_child_die (context_die, child);
20290 gen_decl_die (member, NULL, context_die);
20293 /* Now output info about the function members (if any). */
20294 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20296 /* Don't include clones in the member list. */
20297 if (DECL_ABSTRACT_ORIGIN (member))
20300 child = lookup_decl_die (member);
20302 splice_child_die (context_die, child);
20304 gen_decl_die (member, NULL, context_die);
20308 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20309 is set, we pretend that the type was never defined, so we only get the
20310 member DIEs needed by later specification DIEs. */
20313 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20314 enum debug_info_usage usage)
20316 dw_die_ref type_die = lookup_type_die (type);
20317 dw_die_ref scope_die = 0;
20319 int complete = (TYPE_SIZE (type)
20320 && (! TYPE_STUB_DECL (type)
20321 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20322 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20323 complete = complete && should_emit_struct_debug (type, usage);
20325 if (type_die && ! complete)
20328 if (TYPE_CONTEXT (type) != NULL_TREE
20329 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20330 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20333 scope_die = scope_die_for (type, context_die);
20335 if (! type_die || (nested && is_cu_die (scope_die)))
20336 /* First occurrence of type or toplevel definition of nested class. */
20338 dw_die_ref old_die = type_die;
20340 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20341 ? record_type_tag (type) : DW_TAG_union_type,
20343 equate_type_number_to_die (type, type_die);
20345 add_AT_specification (type_die, old_die);
20347 add_name_attribute (type_die, type_tag (type));
20350 remove_AT (type_die, DW_AT_declaration);
20352 /* Generate child dies for template paramaters. */
20353 if (debug_info_level > DINFO_LEVEL_TERSE
20354 && COMPLETE_TYPE_P (type))
20355 schedule_generic_params_dies_gen (type);
20357 /* If this type has been completed, then give it a byte_size attribute and
20358 then give a list of members. */
20359 if (complete && !ns_decl)
20361 /* Prevent infinite recursion in cases where the type of some member of
20362 this type is expressed in terms of this type itself. */
20363 TREE_ASM_WRITTEN (type) = 1;
20364 add_byte_size_attribute (type_die, type);
20365 if (TYPE_STUB_DECL (type) != NULL_TREE)
20367 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20368 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20371 /* If the first reference to this type was as the return type of an
20372 inline function, then it may not have a parent. Fix this now. */
20373 if (type_die->die_parent == NULL)
20374 add_child_die (scope_die, type_die);
20376 push_decl_scope (type);
20377 gen_member_die (type, type_die);
20380 /* GNU extension: Record what type our vtable lives in. */
20381 if (TYPE_VFIELD (type))
20383 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20385 gen_type_die (vtype, context_die);
20386 add_AT_die_ref (type_die, DW_AT_containing_type,
20387 lookup_type_die (vtype));
20392 add_AT_flag (type_die, DW_AT_declaration, 1);
20394 /* We don't need to do this for function-local types. */
20395 if (TYPE_STUB_DECL (type)
20396 && ! decl_function_context (TYPE_STUB_DECL (type)))
20397 VEC_safe_push (tree, gc, incomplete_types, type);
20400 if (get_AT (type_die, DW_AT_name))
20401 add_pubtype (type, type_die);
20404 /* Generate a DIE for a subroutine _type_. */
20407 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20409 tree return_type = TREE_TYPE (type);
20410 dw_die_ref subr_die
20411 = new_die (DW_TAG_subroutine_type,
20412 scope_die_for (type, context_die), type);
20414 equate_type_number_to_die (type, subr_die);
20415 add_prototyped_attribute (subr_die, type);
20416 add_type_attribute (subr_die, return_type, 0, 0, context_die);
20417 gen_formal_types_die (type, subr_die);
20419 if (get_AT (subr_die, DW_AT_name))
20420 add_pubtype (type, subr_die);
20423 /* Generate a DIE for a type definition. */
20426 gen_typedef_die (tree decl, dw_die_ref context_die)
20428 dw_die_ref type_die;
20431 if (TREE_ASM_WRITTEN (decl))
20434 TREE_ASM_WRITTEN (decl) = 1;
20435 type_die = new_die (DW_TAG_typedef, context_die, decl);
20436 origin = decl_ultimate_origin (decl);
20437 if (origin != NULL)
20438 add_abstract_origin_attribute (type_die, origin);
20443 add_name_and_src_coords_attributes (type_die, decl);
20444 if (DECL_ORIGINAL_TYPE (decl))
20446 type = DECL_ORIGINAL_TYPE (decl);
20448 gcc_assert (type != TREE_TYPE (decl));
20449 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20453 type = TREE_TYPE (decl);
20455 if (is_naming_typedef_decl (TYPE_NAME (type)))
20457 /* Here, we are in the case of decl being a typedef naming
20458 an anonymous type, e.g:
20459 typedef struct {...} foo;
20460 In that case TREE_TYPE (decl) is not a typedef variant
20461 type and TYPE_NAME of the anonymous type is set to the
20462 TYPE_DECL of the typedef. This construct is emitted by
20465 TYPE is the anonymous struct named by the typedef
20466 DECL. As we need the DW_AT_type attribute of the
20467 DW_TAG_typedef to point to the DIE of TYPE, let's
20468 generate that DIE right away. add_type_attribute
20469 called below will then pick (via lookup_type_die) that
20470 anonymous struct DIE. */
20471 if (!TREE_ASM_WRITTEN (type))
20472 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20474 /* This is a GNU Extension. We are adding a
20475 DW_AT_linkage_name attribute to the DIE of the
20476 anonymous struct TYPE. The value of that attribute
20477 is the name of the typedef decl naming the anonymous
20478 struct. This greatly eases the work of consumers of
20479 this debug info. */
20480 add_linkage_attr (lookup_type_die (type), decl);
20484 add_type_attribute (type_die, type, TREE_READONLY (decl),
20485 TREE_THIS_VOLATILE (decl), context_die);
20487 if (is_naming_typedef_decl (decl))
20488 /* We want that all subsequent calls to lookup_type_die with
20489 TYPE in argument yield the DW_TAG_typedef we have just
20491 equate_type_number_to_die (type, type_die);
20493 add_accessibility_attribute (type_die, decl);
20496 if (DECL_ABSTRACT (decl))
20497 equate_decl_number_to_die (decl, type_die);
20499 if (get_AT (type_die, DW_AT_name))
20500 add_pubtype (decl, type_die);
20503 /* Generate a DIE for a struct, class, enum or union type. */
20506 gen_tagged_type_die (tree type,
20507 dw_die_ref context_die,
20508 enum debug_info_usage usage)
20512 if (type == NULL_TREE
20513 || !is_tagged_type (type))
20516 /* If this is a nested type whose containing class hasn't been written
20517 out yet, writing it out will cover this one, too. This does not apply
20518 to instantiations of member class templates; they need to be added to
20519 the containing class as they are generated. FIXME: This hurts the
20520 idea of combining type decls from multiple TUs, since we can't predict
20521 what set of template instantiations we'll get. */
20522 if (TYPE_CONTEXT (type)
20523 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20524 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20526 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20528 if (TREE_ASM_WRITTEN (type))
20531 /* If that failed, attach ourselves to the stub. */
20532 push_decl_scope (TYPE_CONTEXT (type));
20533 context_die = lookup_type_die (TYPE_CONTEXT (type));
20536 else if (TYPE_CONTEXT (type) != NULL_TREE
20537 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20539 /* If this type is local to a function that hasn't been written
20540 out yet, use a NULL context for now; it will be fixed up in
20541 decls_for_scope. */
20542 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20543 /* A declaration DIE doesn't count; nested types need to go in the
20545 if (context_die && is_declaration_die (context_die))
20546 context_die = NULL;
20551 context_die = declare_in_namespace (type, context_die);
20555 if (TREE_CODE (type) == ENUMERAL_TYPE)
20557 /* This might have been written out by the call to
20558 declare_in_namespace. */
20559 if (!TREE_ASM_WRITTEN (type))
20560 gen_enumeration_type_die (type, context_die);
20563 gen_struct_or_union_type_die (type, context_die, usage);
20568 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20569 it up if it is ever completed. gen_*_type_die will set it for us
20570 when appropriate. */
20573 /* Generate a type description DIE. */
20576 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20577 enum debug_info_usage usage)
20579 struct array_descr_info info;
20581 if (type == NULL_TREE || type == error_mark_node)
20584 if (TYPE_NAME (type) != NULL_TREE
20585 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
20586 && is_redundant_typedef (TYPE_NAME (type))
20587 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
20588 /* The DECL of this type is a typedef we don't want to emit debug
20589 info for but we want debug info for its underlying typedef.
20590 This can happen for e.g, the injected-class-name of a C++
20592 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
20594 /* If TYPE is a typedef type variant, let's generate debug info
20595 for the parent typedef which TYPE is a type of. */
20596 if (typedef_variant_p (type))
20598 if (TREE_ASM_WRITTEN (type))
20601 /* Prevent broken recursion; we can't hand off to the same type. */
20602 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20604 /* Use the DIE of the containing namespace as the parent DIE of
20605 the type description DIE we want to generate. */
20606 if (DECL_CONTEXT (TYPE_NAME (type))
20607 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20608 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20610 TREE_ASM_WRITTEN (type) = 1;
20612 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20616 /* If type is an anonymous tagged type named by a typedef, let's
20617 generate debug info for the typedef. */
20618 if (is_naming_typedef_decl (TYPE_NAME (type)))
20620 /* Use the DIE of the containing namespace as the parent DIE of
20621 the type description DIE we want to generate. */
20622 if (DECL_CONTEXT (TYPE_NAME (type))
20623 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20624 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20626 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20630 /* If this is an array type with hidden descriptor, handle it first. */
20631 if (!TREE_ASM_WRITTEN (type)
20632 && lang_hooks.types.get_array_descr_info
20633 && lang_hooks.types.get_array_descr_info (type, &info)
20634 && (dwarf_version >= 3 || !dwarf_strict))
20636 gen_descr_array_type_die (type, &info, context_die);
20637 TREE_ASM_WRITTEN (type) = 1;
20641 /* We are going to output a DIE to represent the unqualified version
20642 of this type (i.e. without any const or volatile qualifiers) so
20643 get the main variant (i.e. the unqualified version) of this type
20644 now. (Vectors are special because the debugging info is in the
20645 cloned type itself). */
20646 if (TREE_CODE (type) != VECTOR_TYPE)
20647 type = type_main_variant (type);
20649 if (TREE_ASM_WRITTEN (type))
20652 switch (TREE_CODE (type))
20658 case REFERENCE_TYPE:
20659 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20660 ensures that the gen_type_die recursion will terminate even if the
20661 type is recursive. Recursive types are possible in Ada. */
20662 /* ??? We could perhaps do this for all types before the switch
20664 TREE_ASM_WRITTEN (type) = 1;
20666 /* For these types, all that is required is that we output a DIE (or a
20667 set of DIEs) to represent the "basis" type. */
20668 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20669 DINFO_USAGE_IND_USE);
20673 /* This code is used for C++ pointer-to-data-member types.
20674 Output a description of the relevant class type. */
20675 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20676 DINFO_USAGE_IND_USE);
20678 /* Output a description of the type of the object pointed to. */
20679 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20680 DINFO_USAGE_IND_USE);
20682 /* Now output a DIE to represent this pointer-to-data-member type
20684 gen_ptr_to_mbr_type_die (type, context_die);
20687 case FUNCTION_TYPE:
20688 /* Force out return type (in case it wasn't forced out already). */
20689 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20690 DINFO_USAGE_DIR_USE);
20691 gen_subroutine_type_die (type, context_die);
20695 /* Force out return type (in case it wasn't forced out already). */
20696 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20697 DINFO_USAGE_DIR_USE);
20698 gen_subroutine_type_die (type, context_die);
20702 gen_array_type_die (type, context_die);
20706 gen_array_type_die (type, context_die);
20709 case ENUMERAL_TYPE:
20712 case QUAL_UNION_TYPE:
20713 gen_tagged_type_die (type, context_die, usage);
20719 case FIXED_POINT_TYPE:
20722 /* No DIEs needed for fundamental types. */
20727 /* Just use DW_TAG_unspecified_type. */
20729 dw_die_ref type_die = lookup_type_die (type);
20730 if (type_die == NULL)
20732 tree name = TYPE_NAME (type);
20733 if (TREE_CODE (name) == TYPE_DECL)
20734 name = DECL_NAME (name);
20735 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
20736 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20737 equate_type_number_to_die (type, type_die);
20743 gcc_unreachable ();
20746 TREE_ASM_WRITTEN (type) = 1;
20750 gen_type_die (tree type, dw_die_ref context_die)
20752 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20755 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20756 things which are local to the given block. */
20759 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20761 int must_output_die = 0;
20764 /* Ignore blocks that are NULL. */
20765 if (stmt == NULL_TREE)
20768 inlined_func = inlined_function_outer_scope_p (stmt);
20770 /* If the block is one fragment of a non-contiguous block, do not
20771 process the variables, since they will have been done by the
20772 origin block. Do process subblocks. */
20773 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20777 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20778 gen_block_die (sub, context_die, depth + 1);
20783 /* Determine if we need to output any Dwarf DIEs at all to represent this
20786 /* The outer scopes for inlinings *must* always be represented. We
20787 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20788 must_output_die = 1;
20791 /* Determine if this block directly contains any "significant"
20792 local declarations which we will need to output DIEs for. */
20793 if (debug_info_level > DINFO_LEVEL_TERSE)
20794 /* We are not in terse mode so *any* local declaration counts
20795 as being a "significant" one. */
20796 must_output_die = ((BLOCK_VARS (stmt) != NULL
20797 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20798 && (TREE_USED (stmt)
20799 || TREE_ASM_WRITTEN (stmt)
20800 || BLOCK_ABSTRACT (stmt)));
20801 else if ((TREE_USED (stmt)
20802 || TREE_ASM_WRITTEN (stmt)
20803 || BLOCK_ABSTRACT (stmt))
20804 && !dwarf2out_ignore_block (stmt))
20805 must_output_die = 1;
20808 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20809 DIE for any block which contains no significant local declarations at
20810 all. Rather, in such cases we just call `decls_for_scope' so that any
20811 needed Dwarf info for any sub-blocks will get properly generated. Note
20812 that in terse mode, our definition of what constitutes a "significant"
20813 local declaration gets restricted to include only inlined function
20814 instances and local (nested) function definitions. */
20815 if (must_output_die)
20819 /* If STMT block is abstract, that means we have been called
20820 indirectly from dwarf2out_abstract_function.
20821 That function rightfully marks the descendent blocks (of
20822 the abstract function it is dealing with) as being abstract,
20823 precisely to prevent us from emitting any
20824 DW_TAG_inlined_subroutine DIE as a descendent
20825 of an abstract function instance. So in that case, we should
20826 not call gen_inlined_subroutine_die.
20828 Later though, when cgraph asks dwarf2out to emit info
20829 for the concrete instance of the function decl into which
20830 the concrete instance of STMT got inlined, the later will lead
20831 to the generation of a DW_TAG_inlined_subroutine DIE. */
20832 if (! BLOCK_ABSTRACT (stmt))
20833 gen_inlined_subroutine_die (stmt, context_die, depth);
20836 gen_lexical_block_die (stmt, context_die, depth);
20839 decls_for_scope (stmt, context_die, depth);
20842 /* Process variable DECL (or variable with origin ORIGIN) within
20843 block STMT and add it to CONTEXT_DIE. */
20845 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20848 tree decl_or_origin = decl ? decl : origin;
20850 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20851 die = lookup_decl_die (decl_or_origin);
20852 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20853 && TYPE_DECL_IS_STUB (decl_or_origin))
20854 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20858 if (die != NULL && die->die_parent == NULL)
20859 add_child_die (context_die, die);
20860 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20861 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20862 stmt, context_die);
20864 gen_decl_die (decl, origin, context_die);
20867 /* Generate all of the decls declared within a given scope and (recursively)
20868 all of its sub-blocks. */
20871 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20877 /* Ignore NULL blocks. */
20878 if (stmt == NULL_TREE)
20881 /* Output the DIEs to represent all of the data objects and typedefs
20882 declared directly within this block but not within any nested
20883 sub-blocks. Also, nested function and tag DIEs have been
20884 generated with a parent of NULL; fix that up now. */
20885 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20886 process_scope_var (stmt, decl, NULL_TREE, context_die);
20887 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20888 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20891 /* If we're at -g1, we're not interested in subblocks. */
20892 if (debug_info_level <= DINFO_LEVEL_TERSE)
20895 /* Output the DIEs to represent all sub-blocks (and the items declared
20896 therein) of this block. */
20897 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20899 subblocks = BLOCK_CHAIN (subblocks))
20900 gen_block_die (subblocks, context_die, depth + 1);
20903 /* Is this a typedef we can avoid emitting? */
20906 is_redundant_typedef (const_tree decl)
20908 if (TYPE_DECL_IS_STUB (decl))
20911 if (DECL_ARTIFICIAL (decl)
20912 && DECL_CONTEXT (decl)
20913 && is_tagged_type (DECL_CONTEXT (decl))
20914 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20915 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20916 /* Also ignore the artificial member typedef for the class name. */
20922 /* Return TRUE if TYPE is a typedef that names a type for linkage
20923 purposes. This kind of typedefs is produced by the C++ FE for
20926 typedef struct {...} foo;
20928 In that case, there is no typedef variant type produced for foo.
20929 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20933 is_naming_typedef_decl (const_tree decl)
20935 if (decl == NULL_TREE
20936 || TREE_CODE (decl) != TYPE_DECL
20937 || !is_tagged_type (TREE_TYPE (decl))
20938 || DECL_IS_BUILTIN (decl)
20939 || is_redundant_typedef (decl)
20940 /* It looks like Ada produces TYPE_DECLs that are very similar
20941 to C++ naming typedefs but that have different
20942 semantics. Let's be specific to c++ for now. */
20946 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
20947 && TYPE_NAME (TREE_TYPE (decl)) == decl
20948 && (TYPE_STUB_DECL (TREE_TYPE (decl))
20949 != TYPE_NAME (TREE_TYPE (decl))));
20952 /* Returns the DIE for a context. */
20954 static inline dw_die_ref
20955 get_context_die (tree context)
20959 /* Find die that represents this context. */
20960 if (TYPE_P (context))
20962 context = TYPE_MAIN_VARIANT (context);
20963 return strip_naming_typedef (context, force_type_die (context));
20966 return force_decl_die (context);
20968 return comp_unit_die ();
20971 /* Returns the DIE for decl. A DIE will always be returned. */
20974 force_decl_die (tree decl)
20976 dw_die_ref decl_die;
20977 unsigned saved_external_flag;
20978 tree save_fn = NULL_TREE;
20979 decl_die = lookup_decl_die (decl);
20982 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
20984 decl_die = lookup_decl_die (decl);
20988 switch (TREE_CODE (decl))
20990 case FUNCTION_DECL:
20991 /* Clear current_function_decl, so that gen_subprogram_die thinks
20992 that this is a declaration. At this point, we just want to force
20993 declaration die. */
20994 save_fn = current_function_decl;
20995 current_function_decl = NULL_TREE;
20996 gen_subprogram_die (decl, context_die);
20997 current_function_decl = save_fn;
21001 /* Set external flag to force declaration die. Restore it after
21002 gen_decl_die() call. */
21003 saved_external_flag = DECL_EXTERNAL (decl);
21004 DECL_EXTERNAL (decl) = 1;
21005 gen_decl_die (decl, NULL, context_die);
21006 DECL_EXTERNAL (decl) = saved_external_flag;
21009 case NAMESPACE_DECL:
21010 if (dwarf_version >= 3 || !dwarf_strict)
21011 dwarf2out_decl (decl);
21013 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21014 decl_die = comp_unit_die ();
21017 case TRANSLATION_UNIT_DECL:
21018 decl_die = comp_unit_die ();
21022 gcc_unreachable ();
21025 /* We should be able to find the DIE now. */
21027 decl_die = lookup_decl_die (decl);
21028 gcc_assert (decl_die);
21034 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21035 always returned. */
21038 force_type_die (tree type)
21040 dw_die_ref type_die;
21042 type_die = lookup_type_die (type);
21045 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21047 type_die = modified_type_die (type, TYPE_READONLY (type),
21048 TYPE_VOLATILE (type), context_die);
21049 gcc_assert (type_die);
21054 /* Force out any required namespaces to be able to output DECL,
21055 and return the new context_die for it, if it's changed. */
21058 setup_namespace_context (tree thing, dw_die_ref context_die)
21060 tree context = (DECL_P (thing)
21061 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21062 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21063 /* Force out the namespace. */
21064 context_die = force_decl_die (context);
21066 return context_die;
21069 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21070 type) within its namespace, if appropriate.
21072 For compatibility with older debuggers, namespace DIEs only contain
21073 declarations; all definitions are emitted at CU scope. */
21076 declare_in_namespace (tree thing, dw_die_ref context_die)
21078 dw_die_ref ns_context;
21080 if (debug_info_level <= DINFO_LEVEL_TERSE)
21081 return context_die;
21083 /* If this decl is from an inlined function, then don't try to emit it in its
21084 namespace, as we will get confused. It would have already been emitted
21085 when the abstract instance of the inline function was emitted anyways. */
21086 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21087 return context_die;
21089 ns_context = setup_namespace_context (thing, context_die);
21091 if (ns_context != context_die)
21095 if (DECL_P (thing))
21096 gen_decl_die (thing, NULL, ns_context);
21098 gen_type_die (thing, ns_context);
21100 return context_die;
21103 /* Generate a DIE for a namespace or namespace alias. */
21106 gen_namespace_die (tree decl, dw_die_ref context_die)
21108 dw_die_ref namespace_die;
21110 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21111 they are an alias of. */
21112 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21114 /* Output a real namespace or module. */
21115 context_die = setup_namespace_context (decl, comp_unit_die ());
21116 namespace_die = new_die (is_fortran ()
21117 ? DW_TAG_module : DW_TAG_namespace,
21118 context_die, decl);
21119 /* For Fortran modules defined in different CU don't add src coords. */
21120 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21122 const char *name = dwarf2_name (decl, 0);
21124 add_name_attribute (namespace_die, name);
21127 add_name_and_src_coords_attributes (namespace_die, decl);
21128 if (DECL_EXTERNAL (decl))
21129 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21130 equate_decl_number_to_die (decl, namespace_die);
21134 /* Output a namespace alias. */
21136 /* Force out the namespace we are an alias of, if necessary. */
21137 dw_die_ref origin_die
21138 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21140 if (DECL_FILE_SCOPE_P (decl)
21141 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21142 context_die = setup_namespace_context (decl, comp_unit_die ());
21143 /* Now create the namespace alias DIE. */
21144 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21145 add_name_and_src_coords_attributes (namespace_die, decl);
21146 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21147 equate_decl_number_to_die (decl, namespace_die);
21151 /* Generate Dwarf debug information for a decl described by DECL.
21152 The return value is currently only meaningful for PARM_DECLs,
21153 for all other decls it returns NULL. */
21156 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21158 tree decl_or_origin = decl ? decl : origin;
21159 tree class_origin = NULL, ultimate_origin;
21161 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21164 switch (TREE_CODE (decl_or_origin))
21170 if (!is_fortran () && !is_ada ())
21172 /* The individual enumerators of an enum type get output when we output
21173 the Dwarf representation of the relevant enum type itself. */
21177 /* Emit its type. */
21178 gen_type_die (TREE_TYPE (decl), context_die);
21180 /* And its containing namespace. */
21181 context_die = declare_in_namespace (decl, context_die);
21183 gen_const_die (decl, context_die);
21186 case FUNCTION_DECL:
21187 /* Don't output any DIEs to represent mere function declarations,
21188 unless they are class members or explicit block externs. */
21189 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21190 && DECL_FILE_SCOPE_P (decl_or_origin)
21191 && (current_function_decl == NULL_TREE
21192 || DECL_ARTIFICIAL (decl_or_origin)))
21197 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21198 on local redeclarations of global functions. That seems broken. */
21199 if (current_function_decl != decl)
21200 /* This is only a declaration. */;
21203 /* If we're emitting a clone, emit info for the abstract instance. */
21204 if (origin || DECL_ORIGIN (decl) != decl)
21205 dwarf2out_abstract_function (origin
21206 ? DECL_ORIGIN (origin)
21207 : DECL_ABSTRACT_ORIGIN (decl));
21209 /* If we're emitting an out-of-line copy of an inline function,
21210 emit info for the abstract instance and set up to refer to it. */
21211 else if (cgraph_function_possibly_inlined_p (decl)
21212 && ! DECL_ABSTRACT (decl)
21213 && ! class_or_namespace_scope_p (context_die)
21214 /* dwarf2out_abstract_function won't emit a die if this is just
21215 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21216 that case, because that works only if we have a die. */
21217 && DECL_INITIAL (decl) != NULL_TREE)
21219 dwarf2out_abstract_function (decl);
21220 set_decl_origin_self (decl);
21223 /* Otherwise we're emitting the primary DIE for this decl. */
21224 else if (debug_info_level > DINFO_LEVEL_TERSE)
21226 /* Before we describe the FUNCTION_DECL itself, make sure that we
21227 have its containing type. */
21229 origin = decl_class_context (decl);
21230 if (origin != NULL_TREE)
21231 gen_type_die (origin, context_die);
21233 /* And its return type. */
21234 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21236 /* And its virtual context. */
21237 if (DECL_VINDEX (decl) != NULL_TREE)
21238 gen_type_die (DECL_CONTEXT (decl), context_die);
21240 /* Make sure we have a member DIE for decl. */
21241 if (origin != NULL_TREE)
21242 gen_type_die_for_member (origin, decl, context_die);
21244 /* And its containing namespace. */
21245 context_die = declare_in_namespace (decl, context_die);
21248 /* Now output a DIE to represent the function itself. */
21250 gen_subprogram_die (decl, context_die);
21254 /* If we are in terse mode, don't generate any DIEs to represent any
21255 actual typedefs. */
21256 if (debug_info_level <= DINFO_LEVEL_TERSE)
21259 /* In the special case of a TYPE_DECL node representing the declaration
21260 of some type tag, if the given TYPE_DECL is marked as having been
21261 instantiated from some other (original) TYPE_DECL node (e.g. one which
21262 was generated within the original definition of an inline function) we
21263 used to generate a special (abbreviated) DW_TAG_structure_type,
21264 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21265 should be actually referencing those DIEs, as variable DIEs with that
21266 type would be emitted already in the abstract origin, so it was always
21267 removed during unused type prunning. Don't add anything in this
21269 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21272 if (is_redundant_typedef (decl))
21273 gen_type_die (TREE_TYPE (decl), context_die);
21275 /* Output a DIE to represent the typedef itself. */
21276 gen_typedef_die (decl, context_die);
21280 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21281 gen_label_die (decl, context_die);
21286 /* If we are in terse mode, don't generate any DIEs to represent any
21287 variable declarations or definitions. */
21288 if (debug_info_level <= DINFO_LEVEL_TERSE)
21291 /* Output any DIEs that are needed to specify the type of this data
21293 if (decl_by_reference_p (decl_or_origin))
21294 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21296 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21298 /* And its containing type. */
21299 class_origin = decl_class_context (decl_or_origin);
21300 if (class_origin != NULL_TREE)
21301 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21303 /* And its containing namespace. */
21304 context_die = declare_in_namespace (decl_or_origin, context_die);
21306 /* Now output the DIE to represent the data object itself. This gets
21307 complicated because of the possibility that the VAR_DECL really
21308 represents an inlined instance of a formal parameter for an inline
21310 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21311 if (ultimate_origin != NULL_TREE
21312 && TREE_CODE (ultimate_origin) == PARM_DECL)
21313 gen_formal_parameter_die (decl, origin,
21314 true /* Emit name attribute. */,
21317 gen_variable_die (decl, origin, context_die);
21321 /* Ignore the nameless fields that are used to skip bits but handle C++
21322 anonymous unions and structs. */
21323 if (DECL_NAME (decl) != NULL_TREE
21324 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21325 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21327 gen_type_die (member_declared_type (decl), context_die);
21328 gen_field_die (decl, context_die);
21333 if (DECL_BY_REFERENCE (decl_or_origin))
21334 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21336 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21337 return gen_formal_parameter_die (decl, origin,
21338 true /* Emit name attribute. */,
21341 case NAMESPACE_DECL:
21342 case IMPORTED_DECL:
21343 if (dwarf_version >= 3 || !dwarf_strict)
21344 gen_namespace_die (decl, context_die);
21348 /* Probably some frontend-internal decl. Assume we don't care. */
21349 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21356 /* Output debug information for global decl DECL. Called from toplev.c after
21357 compilation proper has finished. */
21360 dwarf2out_global_decl (tree decl)
21362 /* Output DWARF2 information for file-scope tentative data object
21363 declarations, file-scope (extern) function declarations (which
21364 had no corresponding body) and file-scope tagged type declarations
21365 and definitions which have not yet been forced out. */
21366 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
21367 dwarf2out_decl (decl);
21370 /* Output debug information for type decl DECL. Called from toplev.c
21371 and from language front ends (to record built-in types). */
21373 dwarf2out_type_decl (tree decl, int local)
21376 dwarf2out_decl (decl);
21379 /* Output debug information for imported module or decl DECL.
21380 NAME is non-NULL name in the lexical block if the decl has been renamed.
21381 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21382 that DECL belongs to.
21383 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21385 dwarf2out_imported_module_or_decl_1 (tree decl,
21387 tree lexical_block,
21388 dw_die_ref lexical_block_die)
21390 expanded_location xloc;
21391 dw_die_ref imported_die = NULL;
21392 dw_die_ref at_import_die;
21394 if (TREE_CODE (decl) == IMPORTED_DECL)
21396 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21397 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21401 xloc = expand_location (input_location);
21403 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21405 at_import_die = force_type_die (TREE_TYPE (decl));
21406 /* For namespace N { typedef void T; } using N::T; base_type_die
21407 returns NULL, but DW_TAG_imported_declaration requires
21408 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21409 if (!at_import_die)
21411 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21412 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21413 at_import_die = lookup_type_die (TREE_TYPE (decl));
21414 gcc_assert (at_import_die);
21419 at_import_die = lookup_decl_die (decl);
21420 if (!at_import_die)
21422 /* If we're trying to avoid duplicate debug info, we may not have
21423 emitted the member decl for this field. Emit it now. */
21424 if (TREE_CODE (decl) == FIELD_DECL)
21426 tree type = DECL_CONTEXT (decl);
21428 if (TYPE_CONTEXT (type)
21429 && TYPE_P (TYPE_CONTEXT (type))
21430 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21431 DINFO_USAGE_DIR_USE))
21433 gen_type_die_for_member (type, decl,
21434 get_context_die (TYPE_CONTEXT (type)));
21436 at_import_die = force_decl_die (decl);
21440 if (TREE_CODE (decl) == NAMESPACE_DECL)
21442 if (dwarf_version >= 3 || !dwarf_strict)
21443 imported_die = new_die (DW_TAG_imported_module,
21450 imported_die = new_die (DW_TAG_imported_declaration,
21454 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21455 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21457 add_AT_string (imported_die, DW_AT_name,
21458 IDENTIFIER_POINTER (name));
21459 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21462 /* Output debug information for imported module or decl DECL.
21463 NAME is non-NULL name in context if the decl has been renamed.
21464 CHILD is true if decl is one of the renamed decls as part of
21465 importing whole module. */
21468 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21471 /* dw_die_ref at_import_die; */
21472 dw_die_ref scope_die;
21474 if (debug_info_level <= DINFO_LEVEL_TERSE)
21479 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21480 We need decl DIE for reference and scope die. First, get DIE for the decl
21483 /* Get the scope die for decl context. Use comp_unit_die for global module
21484 or decl. If die is not found for non globals, force new die. */
21486 && TYPE_P (context)
21487 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21490 if (!(dwarf_version >= 3 || !dwarf_strict))
21493 scope_die = get_context_die (context);
21497 gcc_assert (scope_die->die_child);
21498 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21499 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21500 scope_die = scope_die->die_child;
21503 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21504 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21508 /* Write the debugging output for DECL. */
21511 dwarf2out_decl (tree decl)
21513 dw_die_ref context_die = comp_unit_die ();
21515 switch (TREE_CODE (decl))
21520 case FUNCTION_DECL:
21521 /* What we would really like to do here is to filter out all mere
21522 file-scope declarations of file-scope functions which are never
21523 referenced later within this translation unit (and keep all of ones
21524 that *are* referenced later on) but we aren't clairvoyant, so we have
21525 no idea which functions will be referenced in the future (i.e. later
21526 on within the current translation unit). So here we just ignore all
21527 file-scope function declarations which are not also definitions. If
21528 and when the debugger needs to know something about these functions,
21529 it will have to hunt around and find the DWARF information associated
21530 with the definition of the function.
21532 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21533 nodes represent definitions and which ones represent mere
21534 declarations. We have to check DECL_INITIAL instead. That's because
21535 the C front-end supports some weird semantics for "extern inline"
21536 function definitions. These can get inlined within the current
21537 translation unit (and thus, we need to generate Dwarf info for their
21538 abstract instances so that the Dwarf info for the concrete inlined
21539 instances can have something to refer to) but the compiler never
21540 generates any out-of-lines instances of such things (despite the fact
21541 that they *are* definitions).
21543 The important point is that the C front-end marks these "extern
21544 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21545 them anyway. Note that the C++ front-end also plays some similar games
21546 for inline function definitions appearing within include files which
21547 also contain `#pragma interface' pragmas. */
21548 if (DECL_INITIAL (decl) == NULL_TREE)
21551 /* If we're a nested function, initially use a parent of NULL; if we're
21552 a plain function, this will be fixed up in decls_for_scope. If
21553 we're a method, it will be ignored, since we already have a DIE. */
21554 if (decl_function_context (decl)
21555 /* But if we're in terse mode, we don't care about scope. */
21556 && debug_info_level > DINFO_LEVEL_TERSE)
21557 context_die = NULL;
21561 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21562 declaration and if the declaration was never even referenced from
21563 within this entire compilation unit. We suppress these DIEs in
21564 order to save space in the .debug section (by eliminating entries
21565 which are probably useless). Note that we must not suppress
21566 block-local extern declarations (whether used or not) because that
21567 would screw-up the debugger's name lookup mechanism and cause it to
21568 miss things which really ought to be in scope at a given point. */
21569 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
21572 /* For local statics lookup proper context die. */
21573 if (TREE_STATIC (decl) && decl_function_context (decl))
21574 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21576 /* If we are in terse mode, don't generate any DIEs to represent any
21577 variable declarations or definitions. */
21578 if (debug_info_level <= DINFO_LEVEL_TERSE)
21583 if (debug_info_level <= DINFO_LEVEL_TERSE)
21585 if (!is_fortran () && !is_ada ())
21587 if (TREE_STATIC (decl) && decl_function_context (decl))
21588 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21591 case NAMESPACE_DECL:
21592 case IMPORTED_DECL:
21593 if (debug_info_level <= DINFO_LEVEL_TERSE)
21595 if (lookup_decl_die (decl) != NULL)
21600 /* Don't emit stubs for types unless they are needed by other DIEs. */
21601 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21604 /* Don't bother trying to generate any DIEs to represent any of the
21605 normal built-in types for the language we are compiling. */
21606 if (DECL_IS_BUILTIN (decl))
21609 /* If we are in terse mode, don't generate any DIEs for types. */
21610 if (debug_info_level <= DINFO_LEVEL_TERSE)
21613 /* If we're a function-scope tag, initially use a parent of NULL;
21614 this will be fixed up in decls_for_scope. */
21615 if (decl_function_context (decl))
21616 context_die = NULL;
21624 gen_decl_die (decl, NULL, context_die);
21627 /* Write the debugging output for DECL. */
21630 dwarf2out_function_decl (tree decl)
21632 dwarf2out_decl (decl);
21633 call_arg_locations = NULL;
21634 call_arg_loc_last = NULL;
21635 call_site_count = -1;
21636 tail_call_site_count = -1;
21637 VEC_free (dw_die_ref, heap, block_map);
21638 htab_empty (decl_loc_table);
21641 /* Output a marker (i.e. a label) for the beginning of the generated code for
21642 a lexical block. */
21645 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21646 unsigned int blocknum)
21648 switch_to_section (current_function_section ());
21649 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21652 /* Output a marker (i.e. a label) for the end of the generated code for a
21656 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21658 switch_to_section (current_function_section ());
21659 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21662 /* Returns nonzero if it is appropriate not to emit any debugging
21663 information for BLOCK, because it doesn't contain any instructions.
21665 Don't allow this for blocks with nested functions or local classes
21666 as we would end up with orphans, and in the presence of scheduling
21667 we may end up calling them anyway. */
21670 dwarf2out_ignore_block (const_tree block)
21675 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21676 if (TREE_CODE (decl) == FUNCTION_DECL
21677 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21679 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21681 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21682 if (TREE_CODE (decl) == FUNCTION_DECL
21683 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21690 /* Hash table routines for file_hash. */
21693 file_table_eq (const void *p1_p, const void *p2_p)
21695 const struct dwarf_file_data *const p1 =
21696 (const struct dwarf_file_data *) p1_p;
21697 const char *const p2 = (const char *) p2_p;
21698 return filename_cmp (p1->filename, p2) == 0;
21702 file_table_hash (const void *p_p)
21704 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21705 return htab_hash_string (p->filename);
21708 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21709 dwarf2out.c) and return its "index". The index of each (known) filename is
21710 just a unique number which is associated with only that one filename. We
21711 need such numbers for the sake of generating labels (in the .debug_sfnames
21712 section) and references to those files numbers (in the .debug_srcinfo
21713 and.debug_macinfo sections). If the filename given as an argument is not
21714 found in our current list, add it to the list and assign it the next
21715 available unique index number. In order to speed up searches, we remember
21716 the index of the filename was looked up last. This handles the majority of
21719 static struct dwarf_file_data *
21720 lookup_filename (const char *file_name)
21723 struct dwarf_file_data * created;
21725 /* Check to see if the file name that was searched on the previous
21726 call matches this file name. If so, return the index. */
21727 if (file_table_last_lookup
21728 && (file_name == file_table_last_lookup->filename
21729 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
21730 return file_table_last_lookup;
21732 /* Didn't match the previous lookup, search the table. */
21733 slot = htab_find_slot_with_hash (file_table, file_name,
21734 htab_hash_string (file_name), INSERT);
21736 return (struct dwarf_file_data *) *slot;
21738 created = ggc_alloc_dwarf_file_data ();
21739 created->filename = file_name;
21740 created->emitted_number = 0;
21745 /* If the assembler will construct the file table, then translate the compiler
21746 internal file table number into the assembler file table number, and emit
21747 a .file directive if we haven't already emitted one yet. The file table
21748 numbers are different because we prune debug info for unused variables and
21749 types, which may include filenames. */
21752 maybe_emit_file (struct dwarf_file_data * fd)
21754 if (! fd->emitted_number)
21756 if (last_emitted_file)
21757 fd->emitted_number = last_emitted_file->emitted_number + 1;
21759 fd->emitted_number = 1;
21760 last_emitted_file = fd;
21762 if (DWARF2_ASM_LINE_DEBUG_INFO)
21764 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21765 output_quoted_string (asm_out_file,
21766 remap_debug_filename (fd->filename));
21767 fputc ('\n', asm_out_file);
21771 return fd->emitted_number;
21774 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21775 That generation should happen after function debug info has been
21776 generated. The value of the attribute is the constant value of ARG. */
21779 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21781 die_arg_entry entry;
21786 if (!tmpl_value_parm_die_table)
21787 tmpl_value_parm_die_table
21788 = VEC_alloc (die_arg_entry, gc, 32);
21792 VEC_safe_push (die_arg_entry, gc,
21793 tmpl_value_parm_die_table,
21797 /* Return TRUE if T is an instance of generic type, FALSE
21801 generic_type_p (tree t)
21803 if (t == NULL_TREE || !TYPE_P (t))
21805 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
21808 /* Schedule the generation of the generic parameter dies for the
21809 instance of generic type T. The proper generation itself is later
21810 done by gen_scheduled_generic_parms_dies. */
21813 schedule_generic_params_dies_gen (tree t)
21815 if (!generic_type_p (t))
21818 if (generic_type_instances == NULL)
21819 generic_type_instances = VEC_alloc (tree, gc, 256);
21821 VEC_safe_push (tree, gc, generic_type_instances, t);
21824 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21825 by append_entry_to_tmpl_value_parm_die_table. This function must
21826 be called after function DIEs have been generated. */
21829 gen_remaining_tmpl_value_param_die_attribute (void)
21831 if (tmpl_value_parm_die_table)
21836 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21837 tree_add_const_value_attribute (e->die, e->arg);
21841 /* Generate generic parameters DIEs for instances of generic types
21842 that have been previously scheduled by
21843 schedule_generic_params_dies_gen. This function must be called
21844 after all the types of the CU have been laid out. */
21847 gen_scheduled_generic_parms_dies (void)
21852 if (generic_type_instances == NULL)
21855 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
21856 gen_generic_params_dies (t);
21860 /* Replace DW_AT_name for the decl with name. */
21863 dwarf2out_set_name (tree decl, tree name)
21869 die = TYPE_SYMTAB_DIE (decl);
21873 dname = dwarf2_name (name, 0);
21877 attr = get_AT (die, DW_AT_name);
21880 struct indirect_string_node *node;
21882 node = find_AT_string (dname);
21883 /* replace the string. */
21884 attr->dw_attr_val.v.val_str = node;
21888 add_name_attribute (die, dname);
21891 /* Called by the final INSN scan whenever we see a var location. We
21892 use it to drop labels in the right places, and throw the location in
21893 our lookup table. */
21896 dwarf2out_var_location (rtx loc_note)
21898 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21899 struct var_loc_node *newloc;
21901 static const char *last_label;
21902 static const char *last_postcall_label;
21903 static bool last_in_cold_section_p;
21907 if (!NOTE_P (loc_note))
21909 if (CALL_P (loc_note))
21912 if (SIBLING_CALL_P (loc_note))
21913 tail_call_site_count++;
21918 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
21919 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21922 next_real = next_real_insn (loc_note);
21924 /* If there are no instructions which would be affected by this note,
21925 don't do anything. */
21927 && next_real == NULL_RTX
21928 && !NOTE_DURING_CALL_P (loc_note))
21931 if (next_real == NULL_RTX)
21932 next_real = get_last_insn ();
21934 /* If there were any real insns between note we processed last time
21935 and this note (or if it is the first note), clear
21936 last_{,postcall_}label so that they are not reused this time. */
21937 if (last_var_location_insn == NULL_RTX
21938 || last_var_location_insn != next_real
21939 || last_in_cold_section_p != in_cold_section_p)
21942 last_postcall_label = NULL;
21947 decl = NOTE_VAR_LOCATION_DECL (loc_note);
21948 newloc = add_var_loc_to_decl (decl, loc_note,
21949 NOTE_DURING_CALL_P (loc_note)
21950 ? last_postcall_label : last_label);
21951 if (newloc == NULL)
21960 /* If there were no real insns between note we processed last time
21961 and this note, use the label we emitted last time. Otherwise
21962 create a new label and emit it. */
21963 if (last_label == NULL)
21965 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
21966 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
21968 last_label = ggc_strdup (loclabel);
21973 struct call_arg_loc_node *ca_loc
21974 = ggc_alloc_cleared_call_arg_loc_node ();
21975 rtx prev = prev_real_insn (loc_note), x;
21976 ca_loc->call_arg_loc_note = loc_note;
21977 ca_loc->next = NULL;
21978 ca_loc->label = last_label;
21981 || (NONJUMP_INSN_P (prev)
21982 && GET_CODE (PATTERN (prev)) == SEQUENCE
21983 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
21984 if (!CALL_P (prev))
21985 prev = XVECEXP (PATTERN (prev), 0, 0);
21986 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
21987 x = PATTERN (prev);
21988 if (GET_CODE (x) == PARALLEL)
21989 x = XVECEXP (x, 0, 0);
21990 if (GET_CODE (x) == SET)
21992 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
21994 x = XEXP (XEXP (x, 0), 0);
21995 if (GET_CODE (x) == SYMBOL_REF
21996 && SYMBOL_REF_DECL (x)
21997 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
21998 ca_loc->symbol_ref = x;
22000 ca_loc->block = insn_scope (prev);
22001 if (call_arg_locations)
22002 call_arg_loc_last->next = ca_loc;
22004 call_arg_locations = ca_loc;
22005 call_arg_loc_last = ca_loc;
22007 else if (!NOTE_DURING_CALL_P (loc_note))
22008 newloc->label = last_label;
22011 if (!last_postcall_label)
22013 sprintf (loclabel, "%s-1", last_label);
22014 last_postcall_label = ggc_strdup (loclabel);
22016 newloc->label = last_postcall_label;
22019 last_var_location_insn = next_real;
22020 last_in_cold_section_p = in_cold_section_p;
22023 /* We need to reset the locations at the beginning of each
22024 function. We can't do this in the end_function hook, because the
22025 declarations that use the locations won't have been output when
22026 that hook is called. Also compute have_multiple_function_sections here. */
22029 dwarf2out_begin_function (tree fun)
22031 if (function_section (fun) != text_section)
22032 have_multiple_function_sections = true;
22033 else if (flag_reorder_blocks_and_partition && !cold_text_section)
22035 gcc_assert (current_function_decl == fun);
22036 cold_text_section = unlikely_text_section ();
22037 switch_to_section (cold_text_section);
22038 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22039 switch_to_section (current_function_section ());
22042 dwarf2out_note_section_used ();
22043 call_site_count = 0;
22044 tail_call_site_count = 0;
22047 /* Output a label to mark the beginning of a source code line entry
22048 and record information relating to this source line, in
22049 'line_info_table' for later output of the .debug_line section. */
22052 dwarf2out_source_line (unsigned int line, const char *filename,
22053 int discriminator, bool is_stmt)
22055 static bool last_is_stmt = true;
22057 if (debug_info_level >= DINFO_LEVEL_NORMAL
22060 int file_num = maybe_emit_file (lookup_filename (filename));
22062 switch_to_section (current_function_section ());
22064 /* If requested, emit something human-readable. */
22065 if (flag_debug_asm)
22066 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
22069 if (DWARF2_ASM_LINE_DEBUG_INFO)
22071 /* Emit the .loc directive understood by GNU as. */
22072 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
22073 if (is_stmt != last_is_stmt)
22075 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
22076 last_is_stmt = is_stmt;
22078 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
22079 fprintf (asm_out_file, " discriminator %d", discriminator);
22080 fputc ('\n', asm_out_file);
22082 /* Indicate that line number info exists. */
22083 line_info_table_in_use++;
22085 else if (function_section (current_function_decl) != text_section)
22087 dw_separate_line_info_ref line_info;
22088 targetm.asm_out.internal_label (asm_out_file,
22089 SEPARATE_LINE_CODE_LABEL,
22090 separate_line_info_table_in_use);
22092 /* Expand the line info table if necessary. */
22093 if (separate_line_info_table_in_use
22094 == separate_line_info_table_allocated)
22096 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22097 separate_line_info_table
22098 = GGC_RESIZEVEC (dw_separate_line_info_entry,
22099 separate_line_info_table,
22100 separate_line_info_table_allocated);
22101 memset (separate_line_info_table
22102 + separate_line_info_table_in_use,
22104 (LINE_INFO_TABLE_INCREMENT
22105 * sizeof (dw_separate_line_info_entry)));
22108 /* Add the new entry at the end of the line_info_table. */
22110 = &separate_line_info_table[separate_line_info_table_in_use++];
22111 line_info->dw_file_num = file_num;
22112 line_info->dw_line_num = line;
22113 line_info->function = current_function_funcdef_no;
22117 dw_line_info_ref line_info;
22119 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
22120 line_info_table_in_use);
22122 /* Expand the line info table if necessary. */
22123 if (line_info_table_in_use == line_info_table_allocated)
22125 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22127 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
22128 line_info_table_allocated);
22129 memset (line_info_table + line_info_table_in_use, 0,
22130 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
22133 /* Add the new entry at the end of the line_info_table. */
22134 line_info = &line_info_table[line_info_table_in_use++];
22135 line_info->dw_file_num = file_num;
22136 line_info->dw_line_num = line;
22141 /* Record the beginning of a new source file. */
22144 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22146 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22148 /* Record the beginning of the file for break_out_includes. */
22149 dw_die_ref bincl_die;
22151 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22152 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22155 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22158 e.code = DW_MACINFO_start_file;
22160 e.info = xstrdup (filename);
22161 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22165 /* Record the end of a source file. */
22168 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22170 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22171 /* Record the end of the file for break_out_includes. */
22172 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22174 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22177 e.code = DW_MACINFO_end_file;
22180 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22184 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22185 the tail part of the directive line, i.e. the part which is past the
22186 initial whitespace, #, whitespace, directive-name, whitespace part. */
22189 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22190 const char *buffer ATTRIBUTE_UNUSED)
22192 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22195 e.code = DW_MACINFO_define;
22197 e.info = xstrdup (buffer);;
22198 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22202 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22203 the tail part of the directive line, i.e. the part which is past the
22204 initial whitespace, #, whitespace, directive-name, whitespace part. */
22207 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22208 const char *buffer ATTRIBUTE_UNUSED)
22210 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22213 e.code = DW_MACINFO_undef;
22215 e.info = xstrdup (buffer);;
22216 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22221 output_macinfo (void)
22224 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
22225 macinfo_entry *ref;
22230 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
22234 case DW_MACINFO_start_file:
22236 int file_num = maybe_emit_file (lookup_filename (ref->info));
22237 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22238 dw2_asm_output_data_uleb128
22239 (ref->lineno, "Included from line number %lu",
22240 (unsigned long)ref->lineno);
22241 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22244 case DW_MACINFO_end_file:
22245 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22247 case DW_MACINFO_define:
22248 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
22249 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22250 (unsigned long)ref->lineno);
22251 dw2_asm_output_nstring (ref->info, -1, "The macro");
22253 case DW_MACINFO_undef:
22254 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
22255 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22256 (unsigned long)ref->lineno);
22257 dw2_asm_output_nstring (ref->info, -1, "The macro");
22260 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22261 ASM_COMMENT_START, (unsigned long)ref->code);
22267 /* Set up for Dwarf output at the start of compilation. */
22270 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
22272 /* Allocate the file_table. */
22273 file_table = htab_create_ggc (50, file_table_hash,
22274 file_table_eq, NULL);
22276 /* Allocate the decl_die_table. */
22277 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
22278 decl_die_table_eq, NULL);
22280 /* Allocate the decl_loc_table. */
22281 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
22282 decl_loc_table_eq, NULL);
22284 /* Allocate the initial hunk of the decl_scope_table. */
22285 decl_scope_table = VEC_alloc (tree, gc, 256);
22287 /* Allocate the initial hunk of the abbrev_die_table. */
22288 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
22289 (ABBREV_DIE_TABLE_INCREMENT);
22290 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
22291 /* Zero-th entry is allocated, but unused. */
22292 abbrev_die_table_in_use = 1;
22294 /* Allocate the initial hunk of the line_info_table. */
22295 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
22296 (LINE_INFO_TABLE_INCREMENT);
22297 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
22299 /* Zero-th entry is allocated, but unused. */
22300 line_info_table_in_use = 1;
22302 /* Allocate the pubtypes and pubnames vectors. */
22303 pubname_table = VEC_alloc (pubname_entry, gc, 32);
22304 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
22306 incomplete_types = VEC_alloc (tree, gc, 64);
22308 used_rtx_array = VEC_alloc (rtx, gc, 32);
22310 debug_info_section = get_section (DEBUG_INFO_SECTION,
22311 SECTION_DEBUG, NULL);
22312 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
22313 SECTION_DEBUG, NULL);
22314 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
22315 SECTION_DEBUG, NULL);
22316 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
22317 SECTION_DEBUG, NULL);
22318 debug_line_section = get_section (DEBUG_LINE_SECTION,
22319 SECTION_DEBUG, NULL);
22320 debug_loc_section = get_section (DEBUG_LOC_SECTION,
22321 SECTION_DEBUG, NULL);
22322 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
22323 SECTION_DEBUG, NULL);
22324 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
22325 SECTION_DEBUG, NULL);
22326 debug_str_section = get_section (DEBUG_STR_SECTION,
22327 DEBUG_STR_SECTION_FLAGS, NULL);
22328 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
22329 SECTION_DEBUG, NULL);
22330 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
22331 SECTION_DEBUG, NULL);
22333 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
22334 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
22335 DEBUG_ABBREV_SECTION_LABEL, 0);
22336 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
22337 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
22338 COLD_TEXT_SECTION_LABEL, 0);
22339 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
22341 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
22342 DEBUG_INFO_SECTION_LABEL, 0);
22343 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
22344 DEBUG_LINE_SECTION_LABEL, 0);
22345 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
22346 DEBUG_RANGES_SECTION_LABEL, 0);
22347 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
22348 DEBUG_MACINFO_SECTION_LABEL, 0);
22350 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22351 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
22353 switch_to_section (text_section);
22354 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
22357 /* Called before cgraph_optimize starts outputtting functions, variables
22358 and toplevel asms into assembly. */
22361 dwarf2out_assembly_start (void)
22363 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22364 && dwarf2out_do_cfi_asm ()
22365 && (!(flag_unwind_tables || flag_exceptions)
22366 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
22367 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
22370 /* A helper function for dwarf2out_finish called through
22371 htab_traverse. Emit one queued .debug_str string. */
22374 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22376 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22378 if (node->label && node->refcount)
22380 switch_to_section (debug_str_section);
22381 ASM_OUTPUT_LABEL (asm_out_file, node->label);
22382 assemble_string (node->str, strlen (node->str) + 1);
22388 #if ENABLE_ASSERT_CHECKING
22389 /* Verify that all marks are clear. */
22392 verify_marks_clear (dw_die_ref die)
22396 gcc_assert (! die->die_mark);
22397 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
22399 #endif /* ENABLE_ASSERT_CHECKING */
22401 /* Clear the marks for a die and its children.
22402 Be cool if the mark isn't set. */
22405 prune_unmark_dies (dw_die_ref die)
22411 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
22414 /* Given DIE that we're marking as used, find any other dies
22415 it references as attributes and mark them as used. */
22418 prune_unused_types_walk_attribs (dw_die_ref die)
22423 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22425 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
22427 /* A reference to another DIE.
22428 Make sure that it will get emitted.
22429 If it was broken out into a comdat group, don't follow it. */
22430 if (dwarf_version < 4
22431 || a->dw_attr == DW_AT_specification
22432 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
22433 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
22435 /* Set the string's refcount to 0 so that prune_unused_types_mark
22436 accounts properly for it. */
22437 if (AT_class (a) == dw_val_class_str)
22438 a->dw_attr_val.v.val_str->refcount = 0;
22442 /* Mark the generic parameters and arguments children DIEs of DIE. */
22445 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
22449 if (die == NULL || die->die_child == NULL)
22451 c = die->die_child;
22454 switch (c->die_tag)
22456 case DW_TAG_template_type_param:
22457 case DW_TAG_template_value_param:
22458 case DW_TAG_GNU_template_template_param:
22459 case DW_TAG_GNU_template_parameter_pack:
22460 prune_unused_types_mark (c, 1);
22466 } while (c && c != die->die_child);
22469 /* Mark DIE as being used. If DOKIDS is true, then walk down
22470 to DIE's children. */
22473 prune_unused_types_mark (dw_die_ref die, int dokids)
22477 if (die->die_mark == 0)
22479 /* We haven't done this node yet. Mark it as used. */
22481 /* If this is the DIE of a generic type instantiation,
22482 mark the children DIEs that describe its generic parms and
22484 prune_unused_types_mark_generic_parms_dies (die);
22486 /* We also have to mark its parents as used.
22487 (But we don't want to mark our parents' kids due to this.) */
22488 if (die->die_parent)
22489 prune_unused_types_mark (die->die_parent, 0);
22491 /* Mark any referenced nodes. */
22492 prune_unused_types_walk_attribs (die);
22494 /* If this node is a specification,
22495 also mark the definition, if it exists. */
22496 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
22497 prune_unused_types_mark (die->die_definition, 1);
22500 if (dokids && die->die_mark != 2)
22502 /* We need to walk the children, but haven't done so yet.
22503 Remember that we've walked the kids. */
22506 /* If this is an array type, we need to make sure our
22507 kids get marked, even if they're types. If we're
22508 breaking out types into comdat sections, do this
22509 for all type definitions. */
22510 if (die->die_tag == DW_TAG_array_type
22511 || (dwarf_version >= 4
22512 && is_type_die (die) && ! is_declaration_die (die)))
22513 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
22515 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22519 /* For local classes, look if any static member functions were emitted
22520 and if so, mark them. */
22523 prune_unused_types_walk_local_classes (dw_die_ref die)
22527 if (die->die_mark == 2)
22530 switch (die->die_tag)
22532 case DW_TAG_structure_type:
22533 case DW_TAG_union_type:
22534 case DW_TAG_class_type:
22537 case DW_TAG_subprogram:
22538 if (!get_AT_flag (die, DW_AT_declaration)
22539 || die->die_definition != NULL)
22540 prune_unused_types_mark (die, 1);
22547 /* Mark children. */
22548 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
22551 /* Walk the tree DIE and mark types that we actually use. */
22554 prune_unused_types_walk (dw_die_ref die)
22558 /* Don't do anything if this node is already marked and
22559 children have been marked as well. */
22560 if (die->die_mark == 2)
22563 switch (die->die_tag)
22565 case DW_TAG_structure_type:
22566 case DW_TAG_union_type:
22567 case DW_TAG_class_type:
22568 if (die->die_perennial_p)
22571 for (c = die->die_parent; c; c = c->die_parent)
22572 if (c->die_tag == DW_TAG_subprogram)
22575 /* Finding used static member functions inside of classes
22576 is needed just for local classes, because for other classes
22577 static member function DIEs with DW_AT_specification
22578 are emitted outside of the DW_TAG_*_type. If we ever change
22579 it, we'd need to call this even for non-local classes. */
22581 prune_unused_types_walk_local_classes (die);
22583 /* It's a type node --- don't mark it. */
22586 case DW_TAG_const_type:
22587 case DW_TAG_packed_type:
22588 case DW_TAG_pointer_type:
22589 case DW_TAG_reference_type:
22590 case DW_TAG_rvalue_reference_type:
22591 case DW_TAG_volatile_type:
22592 case DW_TAG_typedef:
22593 case DW_TAG_array_type:
22594 case DW_TAG_interface_type:
22595 case DW_TAG_friend:
22596 case DW_TAG_variant_part:
22597 case DW_TAG_enumeration_type:
22598 case DW_TAG_subroutine_type:
22599 case DW_TAG_string_type:
22600 case DW_TAG_set_type:
22601 case DW_TAG_subrange_type:
22602 case DW_TAG_ptr_to_member_type:
22603 case DW_TAG_file_type:
22604 if (die->die_perennial_p)
22607 /* It's a type node --- don't mark it. */
22611 /* Mark everything else. */
22615 if (die->die_mark == 0)
22619 /* Now, mark any dies referenced from here. */
22620 prune_unused_types_walk_attribs (die);
22625 /* Mark children. */
22626 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22629 /* Increment the string counts on strings referred to from DIE's
22633 prune_unused_types_update_strings (dw_die_ref die)
22638 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22639 if (AT_class (a) == dw_val_class_str)
22641 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22643 /* Avoid unnecessarily putting strings that are used less than
22644 twice in the hash table. */
22646 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22649 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22650 htab_hash_string (s->str),
22652 gcc_assert (*slot == NULL);
22658 /* Remove from the tree DIE any dies that aren't marked. */
22661 prune_unused_types_prune (dw_die_ref die)
22665 gcc_assert (die->die_mark);
22666 prune_unused_types_update_strings (die);
22668 if (! die->die_child)
22671 c = die->die_child;
22673 dw_die_ref prev = c;
22674 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22675 if (c == die->die_child)
22677 /* No marked children between 'prev' and the end of the list. */
22679 /* No marked children at all. */
22680 die->die_child = NULL;
22683 prev->die_sib = c->die_sib;
22684 die->die_child = prev;
22689 if (c != prev->die_sib)
22691 prune_unused_types_prune (c);
22692 } while (c != die->die_child);
22695 /* A helper function for dwarf2out_finish called through
22696 htab_traverse. Clear .debug_str strings that we haven't already
22697 decided to emit. */
22700 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22702 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22704 if (!node->label || !node->refcount)
22705 htab_clear_slot (debug_str_hash, h);
22710 /* Remove dies representing declarations that we never use. */
22713 prune_unused_types (void)
22716 limbo_die_node *node;
22717 comdat_type_node *ctnode;
22720 #if ENABLE_ASSERT_CHECKING
22721 /* All the marks should already be clear. */
22722 verify_marks_clear (comp_unit_die ());
22723 for (node = limbo_die_list; node; node = node->next)
22724 verify_marks_clear (node->die);
22725 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22726 verify_marks_clear (ctnode->root_die);
22727 #endif /* ENABLE_ASSERT_CHECKING */
22729 /* Mark types that are used in global variables. */
22730 premark_types_used_by_global_vars ();
22732 /* Set the mark on nodes that are actually used. */
22733 prune_unused_types_walk (comp_unit_die ());
22734 for (node = limbo_die_list; node; node = node->next)
22735 prune_unused_types_walk (node->die);
22736 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22738 prune_unused_types_walk (ctnode->root_die);
22739 prune_unused_types_mark (ctnode->type_die, 1);
22742 /* Also set the mark on nodes referenced from the
22743 pubname_table or arange_table. */
22744 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22745 prune_unused_types_mark (pub->die, 1);
22746 for (i = 0; i < arange_table_in_use; i++)
22747 prune_unused_types_mark (arange_table[i], 1);
22749 /* Get rid of nodes that aren't marked; and update the string counts. */
22750 if (debug_str_hash && debug_str_hash_forced)
22751 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22752 else if (debug_str_hash)
22753 htab_empty (debug_str_hash);
22754 prune_unused_types_prune (comp_unit_die ());
22755 for (node = limbo_die_list; node; node = node->next)
22756 prune_unused_types_prune (node->die);
22757 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22758 prune_unused_types_prune (ctnode->root_die);
22760 /* Leave the marks clear. */
22761 prune_unmark_dies (comp_unit_die ());
22762 for (node = limbo_die_list; node; node = node->next)
22763 prune_unmark_dies (node->die);
22764 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22765 prune_unmark_dies (ctnode->root_die);
22768 /* Set the parameter to true if there are any relative pathnames in
22771 file_table_relative_p (void ** slot, void *param)
22773 bool *p = (bool *) param;
22774 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22775 if (!IS_ABSOLUTE_PATH (d->filename))
22783 /* Routines to manipulate hash table of comdat type units. */
22786 htab_ct_hash (const void *of)
22789 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22791 memcpy (&h, type_node->signature, sizeof (h));
22796 htab_ct_eq (const void *of1, const void *of2)
22798 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22799 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22801 return (! memcmp (type_node_1->signature, type_node_2->signature,
22802 DWARF_TYPE_SIGNATURE_SIZE));
22805 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22806 to the location it would have been added, should we know its
22807 DECL_ASSEMBLER_NAME when we added other attributes. This will
22808 probably improve compactness of debug info, removing equivalent
22809 abbrevs, and hide any differences caused by deferring the
22810 computation of the assembler name, triggered by e.g. PCH. */
22813 move_linkage_attr (dw_die_ref die)
22815 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22816 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22818 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22819 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22823 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22825 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22829 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22831 VEC_pop (dw_attr_node, die->die_attr);
22832 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22836 /* Helper function for resolve_addr, attempt to resolve
22837 one CONST_STRING, return non-zero if not successful. Similarly verify that
22838 SYMBOL_REFs refer to variables emitted in the current CU. */
22841 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22845 if (GET_CODE (rtl) == CONST_STRING)
22847 size_t len = strlen (XSTR (rtl, 0)) + 1;
22848 tree t = build_string (len, XSTR (rtl, 0));
22849 tree tlen = build_int_cst (NULL_TREE, len - 1);
22851 = build_array_type (char_type_node, build_index_type (tlen));
22852 rtl = lookup_constant_def (t);
22853 if (!rtl || !MEM_P (rtl))
22855 rtl = XEXP (rtl, 0);
22856 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22861 if (GET_CODE (rtl) == SYMBOL_REF
22862 && SYMBOL_REF_DECL (rtl))
22864 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
22866 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
22869 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22873 if (GET_CODE (rtl) == CONST
22874 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22880 /* Helper function for resolve_addr, handle one location
22881 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22882 the location list couldn't be resolved. */
22885 resolve_addr_in_expr (dw_loc_descr_ref loc)
22887 for (; loc; loc = loc->dw_loc_next)
22888 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22889 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22890 || (loc->dw_loc_opc == DW_OP_implicit_value
22891 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22892 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22894 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
22895 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
22898 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
22901 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
22902 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
22903 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
22908 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22909 an address in .rodata section if the string literal is emitted there,
22910 or remove the containing location list or replace DW_AT_const_value
22911 with DW_AT_location and empty location expression, if it isn't found
22912 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22913 to something that has been emitted in the current CU. */
22916 resolve_addr (dw_die_ref die)
22920 dw_loc_list_ref *curr;
22923 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22924 switch (AT_class (a))
22926 case dw_val_class_loc_list:
22927 curr = AT_loc_list_ptr (a);
22930 if (!resolve_addr_in_expr ((*curr)->expr))
22932 dw_loc_list_ref next = (*curr)->dw_loc_next;
22933 if (next && (*curr)->ll_symbol)
22935 gcc_assert (!next->ll_symbol);
22936 next->ll_symbol = (*curr)->ll_symbol;
22941 curr = &(*curr)->dw_loc_next;
22943 if (!AT_loc_list (a))
22945 remove_AT (die, a->dw_attr);
22949 case dw_val_class_loc:
22950 if (!resolve_addr_in_expr (AT_loc (a)))
22952 remove_AT (die, a->dw_attr);
22956 case dw_val_class_addr:
22957 if (a->dw_attr == DW_AT_const_value
22958 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
22960 remove_AT (die, a->dw_attr);
22963 if (die->die_tag == DW_TAG_GNU_call_site
22964 && a->dw_attr == DW_AT_abstract_origin)
22966 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
22967 dw_die_ref tdie = lookup_decl_die (tdecl);
22968 if (tdie == NULL && DECL_EXTERNAL (tdecl))
22970 force_decl_die (tdecl);
22971 tdie = lookup_decl_die (tdecl);
22975 a->dw_attr_val.val_class = dw_val_class_die_ref;
22976 a->dw_attr_val.v.val_die_ref.die = tdie;
22977 a->dw_attr_val.v.val_die_ref.external = 0;
22981 remove_AT (die, a->dw_attr);
22990 FOR_EACH_CHILD (die, c, resolve_addr (c));
22993 /* Helper routines for optimize_location_lists.
22994 This pass tries to share identical local lists in .debug_loc
22997 /* Iteratively hash operands of LOC opcode. */
22999 static inline hashval_t
23000 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
23002 dw_val_ref val1 = &loc->dw_loc_oprnd1;
23003 dw_val_ref val2 = &loc->dw_loc_oprnd2;
23005 switch (loc->dw_loc_opc)
23007 case DW_OP_const4u:
23008 case DW_OP_const8u:
23012 case DW_OP_const1u:
23013 case DW_OP_const1s:
23014 case DW_OP_const2u:
23015 case DW_OP_const2s:
23016 case DW_OP_const4s:
23017 case DW_OP_const8s:
23021 case DW_OP_plus_uconst:
23057 case DW_OP_deref_size:
23058 case DW_OP_xderef_size:
23059 hash = iterative_hash_object (val1->v.val_int, hash);
23066 gcc_assert (val1->val_class == dw_val_class_loc);
23067 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
23068 hash = iterative_hash_object (offset, hash);
23071 case DW_OP_implicit_value:
23072 hash = iterative_hash_object (val1->v.val_unsigned, hash);
23073 switch (val2->val_class)
23075 case dw_val_class_const:
23076 hash = iterative_hash_object (val2->v.val_int, hash);
23078 case dw_val_class_vec:
23080 unsigned int elt_size = val2->v.val_vec.elt_size;
23081 unsigned int len = val2->v.val_vec.length;
23083 hash = iterative_hash_object (elt_size, hash);
23084 hash = iterative_hash_object (len, hash);
23085 hash = iterative_hash (val2->v.val_vec.array,
23086 len * elt_size, hash);
23089 case dw_val_class_const_double:
23090 hash = iterative_hash_object (val2->v.val_double.low, hash);
23091 hash = iterative_hash_object (val2->v.val_double.high, hash);
23093 case dw_val_class_addr:
23094 hash = iterative_hash_rtx (val2->v.val_addr, hash);
23097 gcc_unreachable ();
23101 case DW_OP_bit_piece:
23102 hash = iterative_hash_object (val1->v.val_int, hash);
23103 hash = iterative_hash_object (val2->v.val_int, hash);
23109 unsigned char dtprel = 0xd1;
23110 hash = iterative_hash_object (dtprel, hash);
23112 hash = iterative_hash_rtx (val1->v.val_addr, hash);
23114 case DW_OP_GNU_implicit_pointer:
23115 hash = iterative_hash_object (val2->v.val_int, hash);
23119 /* Other codes have no operands. */
23125 /* Iteratively hash the whole DWARF location expression LOC. */
23127 static inline hashval_t
23128 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
23130 dw_loc_descr_ref l;
23131 bool sizes_computed = false;
23132 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23133 size_of_locs (loc);
23135 for (l = loc; l != NULL; l = l->dw_loc_next)
23137 enum dwarf_location_atom opc = l->dw_loc_opc;
23138 hash = iterative_hash_object (opc, hash);
23139 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
23141 size_of_locs (loc);
23142 sizes_computed = true;
23144 hash = hash_loc_operands (l, hash);
23149 /* Compute hash of the whole location list LIST_HEAD. */
23152 hash_loc_list (dw_loc_list_ref list_head)
23154 dw_loc_list_ref curr = list_head;
23155 hashval_t hash = 0;
23157 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
23159 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
23160 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
23162 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
23164 hash = hash_locs (curr->expr, hash);
23166 list_head->hash = hash;
23169 /* Return true if X and Y opcodes have the same operands. */
23172 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
23174 dw_val_ref valx1 = &x->dw_loc_oprnd1;
23175 dw_val_ref valx2 = &x->dw_loc_oprnd2;
23176 dw_val_ref valy1 = &y->dw_loc_oprnd1;
23177 dw_val_ref valy2 = &y->dw_loc_oprnd2;
23179 switch (x->dw_loc_opc)
23181 case DW_OP_const4u:
23182 case DW_OP_const8u:
23186 case DW_OP_const1u:
23187 case DW_OP_const1s:
23188 case DW_OP_const2u:
23189 case DW_OP_const2s:
23190 case DW_OP_const4s:
23191 case DW_OP_const8s:
23195 case DW_OP_plus_uconst:
23231 case DW_OP_deref_size:
23232 case DW_OP_xderef_size:
23233 return valx1->v.val_int == valy1->v.val_int;
23236 gcc_assert (valx1->val_class == dw_val_class_loc
23237 && valy1->val_class == dw_val_class_loc
23238 && x->dw_loc_addr == y->dw_loc_addr);
23239 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
23240 case DW_OP_implicit_value:
23241 if (valx1->v.val_unsigned != valy1->v.val_unsigned
23242 || valx2->val_class != valy2->val_class)
23244 switch (valx2->val_class)
23246 case dw_val_class_const:
23247 return valx2->v.val_int == valy2->v.val_int;
23248 case dw_val_class_vec:
23249 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
23250 && valx2->v.val_vec.length == valy2->v.val_vec.length
23251 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
23252 valx2->v.val_vec.elt_size
23253 * valx2->v.val_vec.length) == 0;
23254 case dw_val_class_const_double:
23255 return valx2->v.val_double.low == valy2->v.val_double.low
23256 && valx2->v.val_double.high == valy2->v.val_double.high;
23257 case dw_val_class_addr:
23258 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
23260 gcc_unreachable ();
23263 case DW_OP_bit_piece:
23264 return valx1->v.val_int == valy1->v.val_int
23265 && valx2->v.val_int == valy2->v.val_int;
23268 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
23269 case DW_OP_GNU_implicit_pointer:
23270 return valx1->val_class == dw_val_class_die_ref
23271 && valx1->val_class == valy1->val_class
23272 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
23273 && valx2->v.val_int == valy2->v.val_int;
23275 /* Other codes have no operands. */
23280 /* Return true if DWARF location expressions X and Y are the same. */
23283 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
23285 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
23286 if (x->dw_loc_opc != y->dw_loc_opc
23287 || x->dtprel != y->dtprel
23288 || !compare_loc_operands (x, y))
23290 return x == NULL && y == NULL;
23293 /* Return precomputed hash of location list X. */
23296 loc_list_hash (const void *x)
23298 return ((const struct dw_loc_list_struct *) x)->hash;
23301 /* Return 1 if location lists X and Y are the same. */
23304 loc_list_eq (const void *x, const void *y)
23306 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
23307 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
23310 if (a->hash != b->hash)
23312 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
23313 if (strcmp (a->begin, b->begin) != 0
23314 || strcmp (a->end, b->end) != 0
23315 || (a->section == NULL) != (b->section == NULL)
23316 || (a->section && strcmp (a->section, b->section) != 0)
23317 || !compare_locs (a->expr, b->expr))
23319 return a == NULL && b == NULL;
23322 /* Recursively optimize location lists referenced from DIE
23323 children and share them whenever possible. */
23326 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
23333 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23334 if (AT_class (a) == dw_val_class_loc_list)
23336 dw_loc_list_ref list = AT_loc_list (a);
23337 /* TODO: perform some optimizations here, before hashing
23338 it and storing into the hash table. */
23339 hash_loc_list (list);
23340 slot = htab_find_slot_with_hash (htab, list, list->hash,
23343 *slot = (void *) list;
23345 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
23348 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
23351 /* Optimize location lists referenced from DIE
23352 children and share them whenever possible. */
23355 optimize_location_lists (dw_die_ref die)
23357 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
23358 optimize_location_lists_1 (die, htab);
23359 htab_delete (htab);
23362 /* Output stuff that dwarf requires at the end of every file,
23363 and generate the DWARF-2 debugging info. */
23366 dwarf2out_finish (const char *filename)
23368 limbo_die_node *node, *next_node;
23369 comdat_type_node *ctnode;
23370 htab_t comdat_type_table;
23373 gen_scheduled_generic_parms_dies ();
23374 gen_remaining_tmpl_value_param_die_attribute ();
23376 /* Add the name for the main input file now. We delayed this from
23377 dwarf2out_init to avoid complications with PCH. */
23378 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
23379 if (!IS_ABSOLUTE_PATH (filename))
23380 add_comp_dir_attribute (comp_unit_die ());
23381 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
23384 htab_traverse (file_table, file_table_relative_p, &p);
23386 add_comp_dir_attribute (comp_unit_die ());
23389 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
23391 add_location_or_const_value_attribute (
23392 VEC_index (deferred_locations, deferred_locations_list, i)->die,
23393 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
23397 /* Traverse the limbo die list, and add parent/child links. The only
23398 dies without parents that should be here are concrete instances of
23399 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23400 For concrete instances, we can get the parent die from the abstract
23402 for (node = limbo_die_list; node; node = next_node)
23404 dw_die_ref die = node->die;
23405 next_node = node->next;
23407 if (die->die_parent == NULL)
23409 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
23412 add_child_die (origin->die_parent, die);
23413 else if (is_cu_die (die))
23415 else if (seen_error ())
23416 /* It's OK to be confused by errors in the input. */
23417 add_child_die (comp_unit_die (), die);
23420 /* In certain situations, the lexical block containing a
23421 nested function can be optimized away, which results
23422 in the nested function die being orphaned. Likewise
23423 with the return type of that nested function. Force
23424 this to be a child of the containing function.
23426 It may happen that even the containing function got fully
23427 inlined and optimized out. In that case we are lost and
23428 assign the empty child. This should not be big issue as
23429 the function is likely unreachable too. */
23430 tree context = NULL_TREE;
23432 gcc_assert (node->created_for);
23434 if (DECL_P (node->created_for))
23435 context = DECL_CONTEXT (node->created_for);
23436 else if (TYPE_P (node->created_for))
23437 context = TYPE_CONTEXT (node->created_for);
23439 gcc_assert (context
23440 && (TREE_CODE (context) == FUNCTION_DECL
23441 || TREE_CODE (context) == NAMESPACE_DECL));
23443 origin = lookup_decl_die (context);
23445 add_child_die (origin, die);
23447 add_child_die (comp_unit_die (), die);
23452 limbo_die_list = NULL;
23454 resolve_addr (comp_unit_die ());
23456 for (node = deferred_asm_name; node; node = node->next)
23458 tree decl = node->created_for;
23459 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
23461 add_linkage_attr (node->die, decl);
23462 move_linkage_attr (node->die);
23466 deferred_asm_name = NULL;
23468 /* Walk through the list of incomplete types again, trying once more to
23469 emit full debugging info for them. */
23470 retry_incomplete_types ();
23472 if (flag_eliminate_unused_debug_types)
23473 prune_unused_types ();
23475 /* Generate separate CUs for each of the include files we've seen.
23476 They will go into limbo_die_list. */
23477 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
23478 break_out_includes (comp_unit_die ());
23480 /* Generate separate COMDAT sections for type DIEs. */
23481 if (dwarf_version >= 4)
23483 break_out_comdat_types (comp_unit_die ());
23485 /* Each new type_unit DIE was added to the limbo die list when created.
23486 Since these have all been added to comdat_type_list, clear the
23488 limbo_die_list = NULL;
23490 /* For each new comdat type unit, copy declarations for incomplete
23491 types to make the new unit self-contained (i.e., no direct
23492 references to the main compile unit). */
23493 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23494 copy_decls_for_unworthy_types (ctnode->root_die);
23495 copy_decls_for_unworthy_types (comp_unit_die ());
23497 /* In the process of copying declarations from one unit to another,
23498 we may have left some declarations behind that are no longer
23499 referenced. Prune them. */
23500 prune_unused_types ();
23503 /* Traverse the DIE's and add add sibling attributes to those DIE's
23504 that have children. */
23505 add_sibling_attributes (comp_unit_die ());
23506 for (node = limbo_die_list; node; node = node->next)
23507 add_sibling_attributes (node->die);
23508 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23509 add_sibling_attributes (ctnode->root_die);
23511 /* Output a terminator label for the .text section. */
23512 switch_to_section (text_section);
23513 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
23514 if (cold_text_section)
23516 switch_to_section (cold_text_section);
23517 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
23520 /* We can only use the low/high_pc attributes if all of the code was
23522 if (!have_multiple_function_sections
23523 || (dwarf_version < 3 && dwarf_strict))
23525 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
23526 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
23531 unsigned fde_idx = 0;
23532 bool range_list_added = false;
23534 /* We need to give .debug_loc and .debug_ranges an appropriate
23535 "base address". Use zero so that these addresses become
23536 absolute. Historically, we've emitted the unexpected
23537 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23538 Emit both to give time for other tools to adapt. */
23539 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
23540 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
23542 if (text_section_used)
23543 add_ranges_by_labels (comp_unit_die (), text_section_label,
23544 text_end_label, &range_list_added);
23545 if (flag_reorder_blocks_and_partition && cold_text_section_used)
23546 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
23547 cold_end_label, &range_list_added);
23549 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
23551 dw_fde_ref fde = &fde_table[fde_idx];
23553 if (fde->dw_fde_switched_sections)
23555 if (!fde->in_std_section)
23556 add_ranges_by_labels (comp_unit_die (),
23557 fde->dw_fde_hot_section_label,
23558 fde->dw_fde_hot_section_end_label,
23559 &range_list_added);
23560 if (!fde->cold_in_std_section)
23561 add_ranges_by_labels (comp_unit_die (),
23562 fde->dw_fde_unlikely_section_label,
23563 fde->dw_fde_unlikely_section_end_label,
23564 &range_list_added);
23566 else if (!fde->in_std_section)
23567 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
23568 fde->dw_fde_end, &range_list_added);
23571 if (range_list_added)
23575 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23576 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
23577 debug_line_section_label);
23579 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23580 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
23582 if (have_location_lists)
23583 optimize_location_lists (comp_unit_die ());
23585 /* Output all of the compilation units. We put the main one last so that
23586 the offsets are available to output_pubnames. */
23587 for (node = limbo_die_list; node; node = node->next)
23588 output_comp_unit (node->die, 0);
23590 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
23591 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23593 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
23595 /* Don't output duplicate types. */
23596 if (*slot != HTAB_EMPTY_ENTRY)
23599 /* Add a pointer to the line table for the main compilation unit
23600 so that the debugger can make sense of DW_AT_decl_file
23602 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23603 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
23604 debug_line_section_label);
23606 output_comdat_type_unit (ctnode);
23609 htab_delete (comdat_type_table);
23611 /* Output the main compilation unit if non-empty or if .debug_macinfo
23612 will be emitted. */
23613 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
23615 /* Output the abbreviation table. */
23616 switch_to_section (debug_abbrev_section);
23617 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
23618 output_abbrev_section ();
23620 /* Output location list section if necessary. */
23621 if (have_location_lists)
23623 /* Output the location lists info. */
23624 switch_to_section (debug_loc_section);
23625 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
23626 DEBUG_LOC_SECTION_LABEL, 0);
23627 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
23628 output_location_lists (comp_unit_die ());
23631 /* Output public names table if necessary. */
23632 if (!VEC_empty (pubname_entry, pubname_table))
23634 gcc_assert (info_section_emitted);
23635 switch_to_section (debug_pubnames_section);
23636 output_pubnames (pubname_table);
23639 /* Output public types table if necessary. */
23640 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23641 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23642 simply won't look for the section. */
23643 if (!VEC_empty (pubname_entry, pubtype_table))
23645 bool empty = false;
23647 if (flag_eliminate_unused_debug_types)
23649 /* The pubtypes table might be emptied by pruning unused items. */
23653 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
23654 if (p->die->die_offset != 0)
23662 gcc_assert (info_section_emitted);
23663 switch_to_section (debug_pubtypes_section);
23664 output_pubnames (pubtype_table);
23668 /* Output the address range information. We only put functions in the arange
23669 table, so don't write it out if we don't have any. */
23670 if ((text_section_used || cold_text_section_used || arange_table_in_use)
23671 && info_section_emitted)
23673 switch_to_section (debug_aranges_section);
23677 /* Output ranges section if necessary. */
23678 if (ranges_table_in_use)
23680 switch_to_section (debug_ranges_section);
23681 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
23685 /* Output the source line correspondence table. We must do this
23686 even if there is no line information. Otherwise, on an empty
23687 translation unit, we will generate a present, but empty,
23688 .debug_info section. IRIX 6.5 `nm' will then complain when
23689 examining the file. This is done late so that any filenames
23690 used by the debug_info section are marked as 'used'. */
23691 switch_to_section (debug_line_section);
23692 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
23693 if (! DWARF2_ASM_LINE_DEBUG_INFO)
23694 output_line_info ();
23696 /* Have to end the macro section. */
23697 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23699 switch_to_section (debug_macinfo_section);
23700 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
23701 if (!VEC_empty (macinfo_entry, macinfo_table))
23703 dw2_asm_output_data (1, 0, "End compilation unit");
23706 /* If we emitted any DW_FORM_strp form attribute, output the string
23708 if (debug_str_hash)
23709 htab_traverse (debug_str_hash, output_indirect_string, NULL);
23712 #include "gt-dwarf2out.h"