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 enum dwarf_call_frame_info dw_cfi_opc;
271 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
273 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
278 DEF_VEC_P (dw_cfi_ref);
279 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
280 DEF_VEC_ALLOC_P (dw_cfi_ref, gc);
282 typedef VEC(dw_cfi_ref, gc) *cfi_vec;
284 /* This is how we define the location of the CFA. We use to handle it
285 as REG + OFFSET all the time, but now it can be more complex.
286 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
287 Instead of passing around REG and OFFSET, we pass a copy
288 of this structure. */
289 typedef struct cfa_loc {
290 HOST_WIDE_INT offset;
291 HOST_WIDE_INT base_offset;
293 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
294 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
297 /* All call frame descriptions (FDE's) in the GCC generated DWARF
298 refer to a single Common Information Entry (CIE), defined at
299 the beginning of the .debug_frame section. This use of a single
300 CIE obviates the need to keep track of multiple CIE's
301 in the DWARF generation routines below. */
303 typedef struct GTY(()) dw_fde_struct {
305 const char *dw_fde_begin;
306 const char *dw_fde_current_label;
307 const char *dw_fde_end;
308 const char *dw_fde_vms_end_prologue;
309 const char *dw_fde_vms_begin_epilogue;
310 const char *dw_fde_second_begin;
311 const char *dw_fde_second_end;
313 int dw_fde_switch_cfi_index; /* Last CFI before switching sections. */
314 HOST_WIDE_INT stack_realignment;
315 unsigned funcdef_number;
316 /* Dynamic realign argument pointer register. */
317 unsigned int drap_reg;
318 /* Virtual dynamic realign argument pointer register. */
319 unsigned int vdrap_reg;
320 /* These 3 flags are copied from rtl_data in function.h. */
321 unsigned all_throwers_are_sibcalls : 1;
322 unsigned uses_eh_lsda : 1;
323 unsigned nothrow : 1;
324 /* Whether we did stack realign in this call frame. */
325 unsigned stack_realign : 1;
326 /* Whether dynamic realign argument pointer register has been saved. */
327 unsigned drap_reg_saved: 1;
328 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
329 unsigned in_std_section : 1;
330 /* True iff dw_fde_second_begin label is in text_section or
331 cold_text_section. */
332 unsigned second_in_std_section : 1;
336 /* Maximum size (in bytes) of an artificially generated label. */
337 #define MAX_ARTIFICIAL_LABEL_BYTES 30
339 /* The size of addresses as they appear in the Dwarf 2 data.
340 Some architectures use word addresses to refer to code locations,
341 but Dwarf 2 info always uses byte addresses. On such machines,
342 Dwarf 2 addresses need to be larger than the architecture's
344 #ifndef DWARF2_ADDR_SIZE
345 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
348 /* The size in bytes of a DWARF field indicating an offset or length
349 relative to a debug info section, specified to be 4 bytes in the
350 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
353 #ifndef DWARF_OFFSET_SIZE
354 #define DWARF_OFFSET_SIZE 4
357 /* The size in bytes of a DWARF 4 type signature. */
359 #ifndef DWARF_TYPE_SIGNATURE_SIZE
360 #define DWARF_TYPE_SIGNATURE_SIZE 8
363 /* According to the (draft) DWARF 3 specification, the initial length
364 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
365 bytes are 0xffffffff, followed by the length stored in the next 8
368 However, the SGI/MIPS ABI uses an initial length which is equal to
369 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
371 #ifndef DWARF_INITIAL_LENGTH_SIZE
372 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
375 /* Round SIZE up to the nearest BOUNDARY. */
376 #define DWARF_ROUND(SIZE,BOUNDARY) \
377 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
379 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
380 #ifndef DWARF_CIE_DATA_ALIGNMENT
381 #ifdef STACK_GROWS_DOWNWARD
382 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
384 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
388 /* CIE identifier. */
389 #if HOST_BITS_PER_WIDE_INT >= 64
390 #define DWARF_CIE_ID \
391 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
393 #define DWARF_CIE_ID DW_CIE_ID
396 /* A pointer to the base of a table that contains frame description
397 information for each routine. */
398 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
400 /* Number of elements currently allocated for fde_table. */
401 static GTY(()) unsigned fde_table_allocated;
403 /* Number of elements in fde_table currently in use. */
404 static GTY(()) unsigned fde_table_in_use;
406 /* Size (in elements) of increments by which we may expand the
408 #define FDE_TABLE_INCREMENT 256
410 /* Get the current fde_table entry we should use. */
412 static inline dw_fde_ref
415 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
418 /* A vector of call frame insns for the CIE. */
419 static GTY(()) cfi_vec cie_cfi_vec;
421 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
422 attribute that accelerates the lookup of the FDE associated
423 with the subprogram. This variable holds the table index of the FDE
424 associated with the current function (body) definition. */
425 static unsigned current_funcdef_fde;
427 struct GTY(()) indirect_string_node {
429 unsigned int refcount;
430 enum dwarf_form form;
434 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
436 static GTY(()) int dw2_string_counter;
437 static GTY(()) unsigned long dwarf2out_cfi_label_num;
439 /* True if the compilation unit places functions in more than one section. */
440 static GTY(()) bool have_multiple_function_sections = false;
442 /* Whether the default text and cold text sections have been used at all. */
444 static GTY(()) bool text_section_used = false;
445 static GTY(()) bool cold_text_section_used = false;
447 /* The default cold text section. */
448 static GTY(()) section *cold_text_section;
450 /* Forward declarations for functions defined in this file. */
452 static char *stripattributes (const char *);
453 static const char *dwarf_cfi_name (unsigned);
454 static dw_cfi_ref new_cfi (void);
455 static void add_cfi (cfi_vec *, dw_cfi_ref);
456 static void add_fde_cfi (const char *, dw_cfi_ref);
457 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
458 static void lookup_cfa (dw_cfa_location *);
459 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
460 static void initial_return_save (rtx);
461 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
463 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
464 static void output_cfi_directive (dw_cfi_ref);
465 static void output_call_frame_info (int);
466 static void dwarf2out_note_section_used (void);
467 static bool clobbers_queued_reg_save (const_rtx);
468 static void dwarf2out_frame_debug_expr (rtx, const char *);
470 /* Support for complex CFA locations. */
471 static void output_cfa_loc (dw_cfi_ref, int);
472 static void output_cfa_loc_raw (dw_cfi_ref);
473 static void get_cfa_from_loc_descr (dw_cfa_location *,
474 struct dw_loc_descr_struct *);
475 static struct dw_loc_descr_struct *build_cfa_loc
476 (dw_cfa_location *, HOST_WIDE_INT);
477 static struct dw_loc_descr_struct *build_cfa_aligned_loc
478 (HOST_WIDE_INT, HOST_WIDE_INT);
479 static void def_cfa_1 (const char *, dw_cfa_location *);
480 static struct dw_loc_descr_struct *mem_loc_descriptor
481 (rtx, enum machine_mode mode, enum machine_mode mem_mode,
482 enum var_init_status);
484 /* How to start an assembler comment. */
485 #ifndef ASM_COMMENT_START
486 #define ASM_COMMENT_START ";#"
489 /* Data and reference forms for relocatable data. */
490 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
491 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
493 #ifndef DEBUG_FRAME_SECTION
494 #define DEBUG_FRAME_SECTION ".debug_frame"
497 #ifndef FUNC_BEGIN_LABEL
498 #define FUNC_BEGIN_LABEL "LFB"
501 #ifndef FUNC_END_LABEL
502 #define FUNC_END_LABEL "LFE"
505 #ifndef PROLOGUE_END_LABEL
506 #define PROLOGUE_END_LABEL "LPE"
509 #ifndef EPILOGUE_BEGIN_LABEL
510 #define EPILOGUE_BEGIN_LABEL "LEB"
513 #ifndef FRAME_BEGIN_LABEL
514 #define FRAME_BEGIN_LABEL "Lframe"
516 #define CIE_AFTER_SIZE_LABEL "LSCIE"
517 #define CIE_END_LABEL "LECIE"
518 #define FDE_LABEL "LSFDE"
519 #define FDE_AFTER_SIZE_LABEL "LASFDE"
520 #define FDE_END_LABEL "LEFDE"
521 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
522 #define LINE_NUMBER_END_LABEL "LELT"
523 #define LN_PROLOG_AS_LABEL "LASLTP"
524 #define LN_PROLOG_END_LABEL "LELTP"
525 #define DIE_LABEL_PREFIX "DW"
527 /* The DWARF 2 CFA column which tracks the return address. Normally this
528 is the column for PC, or the first column after all of the hard
530 #ifndef DWARF_FRAME_RETURN_COLUMN
532 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
534 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
538 /* The mapping from gcc register number to DWARF 2 CFA column number. By
539 default, we just provide columns for all registers. */
540 #ifndef DWARF_FRAME_REGNUM
541 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
544 /* Match the base name of a file to the base name of a compilation unit. */
547 matches_main_base (const char *path)
549 /* Cache the last query. */
550 static const char *last_path = NULL;
551 static int last_match = 0;
552 if (path != last_path)
555 int length = base_of_path (path, &base);
557 last_match = (length == main_input_baselength
558 && memcmp (base, main_input_basename, length) == 0);
563 #ifdef DEBUG_DEBUG_STRUCT
566 dump_struct_debug (tree type, enum debug_info_usage usage,
567 enum debug_struct_file criterion, int generic,
568 int matches, int result)
570 /* Find the type name. */
571 tree type_decl = TYPE_STUB_DECL (type);
573 const char *name = 0;
574 if (TREE_CODE (t) == TYPE_DECL)
577 name = IDENTIFIER_POINTER (t);
579 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
581 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
582 matches ? "bas" : "hdr",
583 generic ? "gen" : "ord",
584 usage == DINFO_USAGE_DFN ? ";" :
585 usage == DINFO_USAGE_DIR_USE ? "." : "*",
587 (void*) type_decl, name);
590 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
591 dump_struct_debug (type, usage, criterion, generic, matches, result)
595 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
601 should_emit_struct_debug (tree type, enum debug_info_usage usage)
603 enum debug_struct_file criterion;
605 bool generic = lang_hooks.types.generic_p (type);
608 criterion = debug_struct_generic[usage];
610 criterion = debug_struct_ordinary[usage];
612 if (criterion == DINFO_STRUCT_FILE_NONE)
613 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
614 if (criterion == DINFO_STRUCT_FILE_ANY)
615 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
617 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
619 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
620 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
622 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
623 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
624 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
627 /* Hook used by __throw. */
630 expand_builtin_dwarf_sp_column (void)
632 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
633 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
636 /* Return a pointer to a copy of the section string name S with all
637 attributes stripped off, and an asterisk prepended (for assemble_name). */
640 stripattributes (const char *s)
642 char *stripped = XNEWVEC (char, strlen (s) + 2);
647 while (*s && *s != ',')
654 /* MEM is a memory reference for the register size table, each element of
655 which has mode MODE. Initialize column C as a return address column. */
658 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
660 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
661 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
662 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
665 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
667 static inline HOST_WIDE_INT
668 div_data_align (HOST_WIDE_INT off)
670 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
671 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
675 /* Return true if we need a signed version of a given opcode
676 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
679 need_data_align_sf_opcode (HOST_WIDE_INT off)
681 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
684 /* Generate code to initialize the register size table. */
687 expand_builtin_init_dwarf_reg_sizes (tree address)
690 enum machine_mode mode = TYPE_MODE (char_type_node);
691 rtx addr = expand_normal (address);
692 rtx mem = gen_rtx_MEM (BLKmode, addr);
693 bool wrote_return_column = false;
695 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
697 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
699 if (rnum < DWARF_FRAME_REGISTERS)
701 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
702 enum machine_mode save_mode = reg_raw_mode[i];
705 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
706 save_mode = choose_hard_reg_mode (i, 1, true);
707 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
709 if (save_mode == VOIDmode)
711 wrote_return_column = true;
713 size = GET_MODE_SIZE (save_mode);
717 emit_move_insn (adjust_address (mem, mode, offset),
718 gen_int_mode (size, mode));
722 if (!wrote_return_column)
723 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
725 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
726 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
729 targetm.init_dwarf_reg_sizes_extra (address);
732 /* Convert a DWARF call frame info. operation to its string name */
735 dwarf_cfi_name (unsigned int cfi_opc)
739 case DW_CFA_advance_loc:
740 return "DW_CFA_advance_loc";
742 return "DW_CFA_offset";
744 return "DW_CFA_restore";
748 return "DW_CFA_set_loc";
749 case DW_CFA_advance_loc1:
750 return "DW_CFA_advance_loc1";
751 case DW_CFA_advance_loc2:
752 return "DW_CFA_advance_loc2";
753 case DW_CFA_advance_loc4:
754 return "DW_CFA_advance_loc4";
755 case DW_CFA_offset_extended:
756 return "DW_CFA_offset_extended";
757 case DW_CFA_restore_extended:
758 return "DW_CFA_restore_extended";
759 case DW_CFA_undefined:
760 return "DW_CFA_undefined";
761 case DW_CFA_same_value:
762 return "DW_CFA_same_value";
763 case DW_CFA_register:
764 return "DW_CFA_register";
765 case DW_CFA_remember_state:
766 return "DW_CFA_remember_state";
767 case DW_CFA_restore_state:
768 return "DW_CFA_restore_state";
770 return "DW_CFA_def_cfa";
771 case DW_CFA_def_cfa_register:
772 return "DW_CFA_def_cfa_register";
773 case DW_CFA_def_cfa_offset:
774 return "DW_CFA_def_cfa_offset";
777 case DW_CFA_def_cfa_expression:
778 return "DW_CFA_def_cfa_expression";
779 case DW_CFA_expression:
780 return "DW_CFA_expression";
781 case DW_CFA_offset_extended_sf:
782 return "DW_CFA_offset_extended_sf";
783 case DW_CFA_def_cfa_sf:
784 return "DW_CFA_def_cfa_sf";
785 case DW_CFA_def_cfa_offset_sf:
786 return "DW_CFA_def_cfa_offset_sf";
788 /* SGI/MIPS specific */
789 case DW_CFA_MIPS_advance_loc8:
790 return "DW_CFA_MIPS_advance_loc8";
793 case DW_CFA_GNU_window_save:
794 return "DW_CFA_GNU_window_save";
795 case DW_CFA_GNU_args_size:
796 return "DW_CFA_GNU_args_size";
797 case DW_CFA_GNU_negative_offset_extended:
798 return "DW_CFA_GNU_negative_offset_extended";
801 return "DW_CFA_<unknown>";
805 /* Return a pointer to a newly allocated Call Frame Instruction. */
807 static inline dw_cfi_ref
810 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
812 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
813 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
818 /* Add a Call Frame Instruction to list of instructions. */
821 add_cfi (cfi_vec *vec, dw_cfi_ref cfi)
823 dw_fde_ref fde = current_fde ();
825 /* When DRAP is used, CFA is defined with an expression. Redefine
826 CFA may lead to a different CFA value. */
827 /* ??? Of course, this heuristic fails when we're annotating epilogues,
828 because of course we'll always want to redefine the CFA back to the
829 stack pointer on the way out. Where should we move this check? */
830 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
831 switch (cfi->dw_cfi_opc)
833 case DW_CFA_def_cfa_register:
834 case DW_CFA_def_cfa_offset:
835 case DW_CFA_def_cfa_offset_sf:
837 case DW_CFA_def_cfa_sf:
844 VEC_safe_push (dw_cfi_ref, gc, *vec, cfi);
847 /* Generate a new label for the CFI info to refer to. FORCE is true
848 if a label needs to be output even when using .cfi_* directives. */
851 dwarf2out_cfi_label (bool force)
853 static char label[20];
855 if (!force && dwarf2out_do_cfi_asm ())
857 /* In this case, we will be emitting the asm directive instead of
858 the label, so just return a placeholder to keep the rest of the
860 strcpy (label, "<do not output>");
864 int num = dwarf2out_cfi_label_num++;
865 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
866 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
872 /* True if remember_state should be emitted before following CFI directive. */
873 static bool emit_cfa_remember;
875 /* True if any CFI directives were emitted at the current insn. */
876 static bool any_cfis_emitted;
878 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
879 or to the CIE if LABEL is NULL. */
882 add_fde_cfi (const char *label, dw_cfi_ref cfi)
886 if (cie_cfi_vec == NULL)
887 cie_cfi_vec = VEC_alloc (dw_cfi_ref, gc, 20);
891 if (emit_cfa_remember)
893 dw_cfi_ref cfi_remember;
895 /* Emit the state save. */
896 emit_cfa_remember = false;
897 cfi_remember = new_cfi ();
898 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
899 add_fde_cfi (label, cfi_remember);
902 if (dwarf2out_do_cfi_asm ())
906 dw_fde_ref fde = current_fde ();
908 gcc_assert (fde != NULL);
910 /* We still have to add the cfi to the list so that lookup_cfa
911 works later on. When -g2 and above we even need to force
912 emitting of CFI labels and add to list a DW_CFA_set_loc for
913 convert_cfa_to_fb_loc_list purposes. If we're generating
914 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
915 convert_cfa_to_fb_loc_list. */
916 if (dwarf_version == 2
917 && debug_info_level > DINFO_LEVEL_TERSE
918 && (write_symbols == DWARF2_DEBUG
919 || write_symbols == VMS_AND_DWARF2_DEBUG))
921 switch (cfi->dw_cfi_opc)
923 case DW_CFA_def_cfa_offset:
924 case DW_CFA_def_cfa_offset_sf:
925 case DW_CFA_def_cfa_register:
927 case DW_CFA_def_cfa_sf:
928 case DW_CFA_def_cfa_expression:
929 case DW_CFA_restore_state:
930 if (*label == 0 || strcmp (label, "<do not output>") == 0)
931 label = dwarf2out_cfi_label (true);
933 if (fde->dw_fde_current_label == NULL
934 || strcmp (label, fde->dw_fde_current_label) != 0)
938 label = xstrdup (label);
940 /* Set the location counter to the new label. */
942 /* It doesn't metter whether DW_CFA_set_loc
943 or DW_CFA_advance_loc4 is added here, those aren't
944 emitted into assembly, only looked up by
945 convert_cfa_to_fb_loc_list. */
946 xcfi->dw_cfi_opc = DW_CFA_set_loc;
947 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
948 add_cfi (&fde->dw_fde_cfi, xcfi);
949 fde->dw_fde_current_label = label;
957 output_cfi_directive (cfi);
959 vec = &fde->dw_fde_cfi;
960 any_cfis_emitted = true;
962 /* ??? If this is a CFI for the CIE, we don't emit. This
963 assumes that the standard CIE contents that the assembler
964 uses matches the standard CIE contents that the compiler
965 uses. This is probably a bad assumption. I'm not quite
966 sure how to address this for now. */
970 dw_fde_ref fde = current_fde ();
972 gcc_assert (fde != NULL);
975 label = dwarf2out_cfi_label (false);
977 if (fde->dw_fde_current_label == NULL
978 || strcmp (label, fde->dw_fde_current_label) != 0)
982 label = xstrdup (label);
984 /* Set the location counter to the new label. */
986 /* If we have a current label, advance from there, otherwise
987 set the location directly using set_loc. */
988 xcfi->dw_cfi_opc = fde->dw_fde_current_label
989 ? DW_CFA_advance_loc4
991 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
992 add_cfi (&fde->dw_fde_cfi, xcfi);
994 fde->dw_fde_current_label = label;
997 vec = &fde->dw_fde_cfi;
998 any_cfis_emitted = true;
1004 /* Subroutine of lookup_cfa. */
1007 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
1009 switch (cfi->dw_cfi_opc)
1011 case DW_CFA_def_cfa_offset:
1012 case DW_CFA_def_cfa_offset_sf:
1013 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
1015 case DW_CFA_def_cfa_register:
1016 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1018 case DW_CFA_def_cfa:
1019 case DW_CFA_def_cfa_sf:
1020 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1021 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
1023 case DW_CFA_def_cfa_expression:
1024 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
1027 case DW_CFA_remember_state:
1028 gcc_assert (!remember->in_use);
1030 remember->in_use = 1;
1032 case DW_CFA_restore_state:
1033 gcc_assert (remember->in_use);
1035 remember->in_use = 0;
1043 /* Find the previous value for the CFA. */
1046 lookup_cfa (dw_cfa_location *loc)
1051 dw_cfa_location remember;
1053 memset (loc, 0, sizeof (*loc));
1054 loc->reg = INVALID_REGNUM;
1057 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
1058 lookup_cfa_1 (cfi, loc, &remember);
1060 fde = current_fde ();
1062 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
1063 lookup_cfa_1 (cfi, loc, &remember);
1066 /* The current rule for calculating the DWARF2 canonical frame address. */
1067 static dw_cfa_location cfa;
1069 /* The register used for saving registers to the stack, and its offset
1071 static dw_cfa_location cfa_store;
1073 /* The current save location around an epilogue. */
1074 static dw_cfa_location cfa_remember;
1076 /* The running total of the size of arguments pushed onto the stack. */
1077 static HOST_WIDE_INT args_size;
1079 /* The last args_size we actually output. */
1080 static HOST_WIDE_INT old_args_size;
1082 /* Entry point to update the canonical frame address (CFA).
1083 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1084 calculated from REG+OFFSET. */
1087 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1089 dw_cfa_location loc;
1091 loc.base_offset = 0;
1093 loc.offset = offset;
1094 def_cfa_1 (label, &loc);
1097 /* Determine if two dw_cfa_location structures define the same data. */
1100 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1102 return (loc1->reg == loc2->reg
1103 && loc1->offset == loc2->offset
1104 && loc1->indirect == loc2->indirect
1105 && (loc1->indirect == 0
1106 || loc1->base_offset == loc2->base_offset));
1109 /* This routine does the actual work. The CFA is now calculated from
1110 the dw_cfa_location structure. */
1113 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1116 dw_cfa_location old_cfa, loc;
1121 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1122 cfa_store.offset = loc.offset;
1124 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1125 lookup_cfa (&old_cfa);
1127 /* If nothing changed, no need to issue any call frame instructions. */
1128 if (cfa_equal_p (&loc, &old_cfa))
1133 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1135 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1136 the CFA register did not change but the offset did. The data
1137 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1138 in the assembler via the .cfi_def_cfa_offset directive. */
1140 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1142 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1143 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1146 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1147 else if (loc.offset == old_cfa.offset
1148 && old_cfa.reg != INVALID_REGNUM
1150 && !old_cfa.indirect)
1152 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1153 indicating the CFA register has changed to <register> but the
1154 offset has not changed. */
1155 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1156 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1160 else if (loc.indirect == 0)
1162 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1163 indicating the CFA register has changed to <register> with
1164 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1165 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1168 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1170 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1171 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1172 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1176 /* Construct a DW_CFA_def_cfa_expression instruction to
1177 calculate the CFA using a full location expression since no
1178 register-offset pair is available. */
1179 struct dw_loc_descr_struct *loc_list;
1181 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1182 loc_list = build_cfa_loc (&loc, 0);
1183 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1186 add_fde_cfi (label, cfi);
1189 /* Add the CFI for saving a register. REG is the CFA column number.
1190 LABEL is passed to add_fde_cfi.
1191 If SREG is -1, the register is saved at OFFSET from the CFA;
1192 otherwise it is saved in SREG. */
1195 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1197 dw_cfi_ref cfi = new_cfi ();
1198 dw_fde_ref fde = current_fde ();
1200 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1202 /* When stack is aligned, store REG using DW_CFA_expression with
1205 && fde->stack_realign
1206 && sreg == INVALID_REGNUM)
1208 cfi->dw_cfi_opc = DW_CFA_expression;
1209 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1210 cfi->dw_cfi_oprnd2.dw_cfi_loc
1211 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1213 else if (sreg == INVALID_REGNUM)
1215 if (need_data_align_sf_opcode (offset))
1216 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1217 else if (reg & ~0x3f)
1218 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1220 cfi->dw_cfi_opc = DW_CFA_offset;
1221 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1223 else if (sreg == reg)
1224 cfi->dw_cfi_opc = DW_CFA_same_value;
1227 cfi->dw_cfi_opc = DW_CFA_register;
1228 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1231 add_fde_cfi (label, cfi);
1234 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1235 This CFI tells the unwinder that it needs to restore the window registers
1236 from the previous frame's window save area.
1238 ??? Perhaps we should note in the CIE where windows are saved (instead of
1239 assuming 0(cfa)) and what registers are in the window. */
1242 dwarf2out_window_save (const char *label)
1244 dw_cfi_ref cfi = new_cfi ();
1246 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1247 add_fde_cfi (label, cfi);
1250 /* Entry point for saving a register to the stack. REG is the GCC register
1251 number. LABEL and OFFSET are passed to reg_save. */
1254 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1256 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1259 /* Entry point for saving the return address in the stack.
1260 LABEL and OFFSET are passed to reg_save. */
1263 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1265 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1268 /* Entry point for saving the return address in a register.
1269 LABEL and SREG are passed to reg_save. */
1272 dwarf2out_return_reg (const char *label, unsigned int sreg)
1274 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1277 /* Record the initial position of the return address. RTL is
1278 INCOMING_RETURN_ADDR_RTX. */
1281 initial_return_save (rtx rtl)
1283 unsigned int reg = INVALID_REGNUM;
1284 HOST_WIDE_INT offset = 0;
1286 switch (GET_CODE (rtl))
1289 /* RA is in a register. */
1290 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1294 /* RA is on the stack. */
1295 rtl = XEXP (rtl, 0);
1296 switch (GET_CODE (rtl))
1299 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1304 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1305 offset = INTVAL (XEXP (rtl, 1));
1309 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1310 offset = -INTVAL (XEXP (rtl, 1));
1320 /* The return address is at some offset from any value we can
1321 actually load. For instance, on the SPARC it is in %i7+8. Just
1322 ignore the offset for now; it doesn't matter for unwinding frames. */
1323 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1324 initial_return_save (XEXP (rtl, 0));
1331 if (reg != DWARF_FRAME_RETURN_COLUMN)
1332 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1335 /* Given a SET, calculate the amount of stack adjustment it
1338 static HOST_WIDE_INT
1339 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1340 HOST_WIDE_INT cur_offset)
1342 const_rtx src = SET_SRC (pattern);
1343 const_rtx dest = SET_DEST (pattern);
1344 HOST_WIDE_INT offset = 0;
1347 if (dest == stack_pointer_rtx)
1349 code = GET_CODE (src);
1351 /* Assume (set (reg sp) (reg whatever)) sets args_size
1353 if (code == REG && src != stack_pointer_rtx)
1355 offset = -cur_args_size;
1356 #ifndef STACK_GROWS_DOWNWARD
1359 return offset - cur_offset;
1362 if (! (code == PLUS || code == MINUS)
1363 || XEXP (src, 0) != stack_pointer_rtx
1364 || !CONST_INT_P (XEXP (src, 1)))
1367 /* (set (reg sp) (plus (reg sp) (const_int))) */
1368 offset = INTVAL (XEXP (src, 1));
1374 if (MEM_P (src) && !MEM_P (dest))
1378 /* (set (mem (pre_dec (reg sp))) (foo)) */
1379 src = XEXP (dest, 0);
1380 code = GET_CODE (src);
1386 if (XEXP (src, 0) == stack_pointer_rtx)
1388 rtx val = XEXP (XEXP (src, 1), 1);
1389 /* We handle only adjustments by constant amount. */
1390 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1391 && CONST_INT_P (val));
1392 offset = -INTVAL (val);
1399 if (XEXP (src, 0) == stack_pointer_rtx)
1401 offset = GET_MODE_SIZE (GET_MODE (dest));
1408 if (XEXP (src, 0) == stack_pointer_rtx)
1410 offset = -GET_MODE_SIZE (GET_MODE (dest));
1425 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1426 indexed by INSN_UID. */
1428 static HOST_WIDE_INT *barrier_args_size;
1430 /* Helper function for compute_barrier_args_size. Handle one insn. */
1432 static HOST_WIDE_INT
1433 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1434 VEC (rtx, heap) **next)
1436 HOST_WIDE_INT offset = 0;
1439 if (! RTX_FRAME_RELATED_P (insn))
1441 if (prologue_epilogue_contains (insn))
1443 else if (GET_CODE (PATTERN (insn)) == SET)
1444 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1445 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1446 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1448 /* There may be stack adjustments inside compound insns. Search
1450 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1451 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1452 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1453 cur_args_size, offset);
1458 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1462 expr = XEXP (expr, 0);
1463 if (GET_CODE (expr) == PARALLEL
1464 || GET_CODE (expr) == SEQUENCE)
1465 for (i = 1; i < XVECLEN (expr, 0); i++)
1467 rtx elem = XVECEXP (expr, 0, i);
1469 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1470 offset += stack_adjust_offset (elem, cur_args_size, offset);
1475 #ifndef STACK_GROWS_DOWNWARD
1479 cur_args_size += offset;
1480 if (cur_args_size < 0)
1485 rtx dest = JUMP_LABEL (insn);
1489 if (barrier_args_size [INSN_UID (dest)] < 0)
1491 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1492 VEC_safe_push (rtx, heap, *next, dest);
1497 return cur_args_size;
1500 /* Walk the whole function and compute args_size on BARRIERs. */
1503 compute_barrier_args_size (void)
1505 int max_uid = get_max_uid (), i;
1507 VEC (rtx, heap) *worklist, *next, *tmp;
1509 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1510 for (i = 0; i < max_uid; i++)
1511 barrier_args_size[i] = -1;
1513 worklist = VEC_alloc (rtx, heap, 20);
1514 next = VEC_alloc (rtx, heap, 20);
1515 insn = get_insns ();
1516 barrier_args_size[INSN_UID (insn)] = 0;
1517 VEC_quick_push (rtx, worklist, insn);
1520 while (!VEC_empty (rtx, worklist))
1522 rtx prev, body, first_insn;
1523 HOST_WIDE_INT cur_args_size;
1525 first_insn = insn = VEC_pop (rtx, worklist);
1526 cur_args_size = barrier_args_size[INSN_UID (insn)];
1527 prev = prev_nonnote_insn (insn);
1528 if (prev && BARRIER_P (prev))
1529 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1531 for (; insn; insn = NEXT_INSN (insn))
1533 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1535 if (BARRIER_P (insn))
1540 if (insn == first_insn)
1542 else if (barrier_args_size[INSN_UID (insn)] < 0)
1544 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1549 /* The insns starting with this label have been
1550 already scanned or are in the worklist. */
1555 body = PATTERN (insn);
1556 if (GET_CODE (body) == SEQUENCE)
1558 HOST_WIDE_INT dest_args_size = cur_args_size;
1559 for (i = 1; i < XVECLEN (body, 0); i++)
1560 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1561 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1563 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1564 dest_args_size, &next);
1567 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1568 cur_args_size, &next);
1570 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1571 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1572 dest_args_size, &next);
1575 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1576 cur_args_size, &next);
1580 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1584 if (VEC_empty (rtx, next))
1587 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1591 VEC_truncate (rtx, next, 0);
1594 VEC_free (rtx, heap, worklist);
1595 VEC_free (rtx, heap, next);
1598 /* Add a CFI to update the running total of the size of arguments
1599 pushed onto the stack. */
1602 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1606 if (size == old_args_size)
1609 old_args_size = size;
1612 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1613 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1614 add_fde_cfi (label, cfi);
1617 /* Record a stack adjustment of OFFSET bytes. */
1620 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1622 if (cfa.reg == STACK_POINTER_REGNUM)
1623 cfa.offset += offset;
1625 if (cfa_store.reg == STACK_POINTER_REGNUM)
1626 cfa_store.offset += offset;
1628 if (ACCUMULATE_OUTGOING_ARGS)
1631 #ifndef STACK_GROWS_DOWNWARD
1635 args_size += offset;
1639 def_cfa_1 (label, &cfa);
1640 if (flag_asynchronous_unwind_tables)
1641 dwarf2out_args_size (label, args_size);
1644 /* Check INSN to see if it looks like a push or a stack adjustment, and
1645 make a note of it if it does. EH uses this information to find out
1646 how much extra space it needs to pop off the stack. */
1649 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1651 HOST_WIDE_INT offset;
1655 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1656 with this function. Proper support would require all frame-related
1657 insns to be marked, and to be able to handle saving state around
1658 epilogues textually in the middle of the function. */
1659 if (prologue_epilogue_contains (insn))
1662 /* If INSN is an instruction from target of an annulled branch, the
1663 effects are for the target only and so current argument size
1664 shouldn't change at all. */
1666 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1667 && INSN_FROM_TARGET_P (insn))
1670 /* If only calls can throw, and we have a frame pointer,
1671 save up adjustments until we see the CALL_INSN. */
1672 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1674 if (CALL_P (insn) && !after_p)
1676 /* Extract the size of the args from the CALL rtx itself. */
1677 insn = PATTERN (insn);
1678 if (GET_CODE (insn) == PARALLEL)
1679 insn = XVECEXP (insn, 0, 0);
1680 if (GET_CODE (insn) == SET)
1681 insn = SET_SRC (insn);
1682 gcc_assert (GET_CODE (insn) == CALL);
1683 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1688 if (CALL_P (insn) && !after_p)
1690 if (!flag_asynchronous_unwind_tables)
1691 dwarf2out_args_size ("", args_size);
1694 else if (BARRIER_P (insn))
1696 /* Don't call compute_barrier_args_size () if the only
1697 BARRIER is at the end of function. */
1698 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1699 compute_barrier_args_size ();
1700 if (barrier_args_size == NULL)
1704 offset = barrier_args_size[INSN_UID (insn)];
1709 offset -= args_size;
1710 #ifndef STACK_GROWS_DOWNWARD
1714 else if (GET_CODE (PATTERN (insn)) == SET)
1715 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1716 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1717 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1719 /* There may be stack adjustments inside compound insns. Search
1721 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1722 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1723 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1732 label = dwarf2out_cfi_label (false);
1733 dwarf2out_stack_adjust (offset, label);
1736 /* We delay emitting a register save until either (a) we reach the end
1737 of the prologue or (b) the register is clobbered. This clusters
1738 register saves so that there are fewer pc advances. */
1740 struct GTY(()) queued_reg_save {
1741 struct queued_reg_save *next;
1743 HOST_WIDE_INT cfa_offset;
1747 static GTY(()) struct queued_reg_save *queued_reg_saves;
1749 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1750 struct GTY(()) reg_saved_in_data {
1755 /* A list of registers saved in other registers.
1756 The list intentionally has a small maximum capacity of 4; if your
1757 port needs more than that, you might consider implementing a
1758 more efficient data structure. */
1759 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1760 static GTY(()) size_t num_regs_saved_in_regs;
1762 static const char *last_reg_save_label;
1764 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1765 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1768 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1770 struct queued_reg_save *q;
1772 /* Duplicates waste space, but it's also necessary to remove them
1773 for correctness, since the queue gets output in reverse
1775 for (q = queued_reg_saves; q != NULL; q = q->next)
1776 if (REGNO (q->reg) == REGNO (reg))
1781 q = ggc_alloc_queued_reg_save ();
1782 q->next = queued_reg_saves;
1783 queued_reg_saves = q;
1787 q->cfa_offset = offset;
1788 q->saved_reg = sreg;
1790 last_reg_save_label = label;
1793 /* Output all the entries in QUEUED_REG_SAVES. */
1796 dwarf2out_flush_queued_reg_saves (void)
1798 struct queued_reg_save *q;
1800 for (q = queued_reg_saves; q; q = q->next)
1803 unsigned int reg, sreg;
1805 for (i = 0; i < num_regs_saved_in_regs; i++)
1806 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1808 if (q->saved_reg && i == num_regs_saved_in_regs)
1810 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1811 num_regs_saved_in_regs++;
1813 if (i != num_regs_saved_in_regs)
1815 regs_saved_in_regs[i].orig_reg = q->reg;
1816 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1819 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1821 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1823 sreg = INVALID_REGNUM;
1824 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1827 queued_reg_saves = NULL;
1828 last_reg_save_label = NULL;
1831 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1832 location for? Or, does it clobber a register which we've previously
1833 said that some other register is saved in, and for which we now
1834 have a new location for? */
1837 clobbers_queued_reg_save (const_rtx insn)
1839 struct queued_reg_save *q;
1841 for (q = queued_reg_saves; q; q = q->next)
1844 if (modified_in_p (q->reg, insn))
1846 for (i = 0; i < num_regs_saved_in_regs; i++)
1847 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1848 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1855 /* Entry point for saving the first register into the second. */
1858 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1861 unsigned int regno, sregno;
1863 for (i = 0; i < num_regs_saved_in_regs; i++)
1864 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1866 if (i == num_regs_saved_in_regs)
1868 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1869 num_regs_saved_in_regs++;
1871 regs_saved_in_regs[i].orig_reg = reg;
1872 regs_saved_in_regs[i].saved_in_reg = sreg;
1874 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1875 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1876 reg_save (label, regno, sregno, 0);
1879 /* What register, if any, is currently saved in REG? */
1882 reg_saved_in (rtx reg)
1884 unsigned int regn = REGNO (reg);
1886 struct queued_reg_save *q;
1888 for (q = queued_reg_saves; q; q = q->next)
1889 if (q->saved_reg && regn == REGNO (q->saved_reg))
1892 for (i = 0; i < num_regs_saved_in_regs; i++)
1893 if (regs_saved_in_regs[i].saved_in_reg
1894 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1895 return regs_saved_in_regs[i].orig_reg;
1901 /* A temporary register holding an integral value used in adjusting SP
1902 or setting up the store_reg. The "offset" field holds the integer
1903 value, not an offset. */
1904 static dw_cfa_location cfa_temp;
1906 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1909 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1911 memset (&cfa, 0, sizeof (cfa));
1913 switch (GET_CODE (pat))
1916 cfa.reg = REGNO (XEXP (pat, 0));
1917 cfa.offset = INTVAL (XEXP (pat, 1));
1921 cfa.reg = REGNO (pat);
1926 pat = XEXP (pat, 0);
1927 if (GET_CODE (pat) == PLUS)
1929 cfa.base_offset = INTVAL (XEXP (pat, 1));
1930 pat = XEXP (pat, 0);
1932 cfa.reg = REGNO (pat);
1936 /* Recurse and define an expression. */
1940 def_cfa_1 (label, &cfa);
1943 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1946 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1950 gcc_assert (GET_CODE (pat) == SET);
1951 dest = XEXP (pat, 0);
1952 src = XEXP (pat, 1);
1954 switch (GET_CODE (src))
1957 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1958 cfa.offset -= INTVAL (XEXP (src, 1));
1968 cfa.reg = REGNO (dest);
1969 gcc_assert (cfa.indirect == 0);
1971 def_cfa_1 (label, &cfa);
1974 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1977 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1979 HOST_WIDE_INT offset;
1980 rtx src, addr, span;
1982 src = XEXP (set, 1);
1983 addr = XEXP (set, 0);
1984 gcc_assert (MEM_P (addr));
1985 addr = XEXP (addr, 0);
1987 /* As documented, only consider extremely simple addresses. */
1988 switch (GET_CODE (addr))
1991 gcc_assert (REGNO (addr) == cfa.reg);
1992 offset = -cfa.offset;
1995 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1996 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2002 span = targetm.dwarf_register_span (src);
2004 /* ??? We'd like to use queue_reg_save, but we need to come up with
2005 a different flushing heuristic for epilogues. */
2007 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2010 /* We have a PARALLEL describing where the contents of SRC live.
2011 Queue register saves for each piece of the PARALLEL. */
2014 HOST_WIDE_INT span_offset = offset;
2016 gcc_assert (GET_CODE (span) == PARALLEL);
2018 limit = XVECLEN (span, 0);
2019 for (par_index = 0; par_index < limit; par_index++)
2021 rtx elem = XVECEXP (span, 0, par_index);
2023 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2024 INVALID_REGNUM, span_offset);
2025 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2030 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2033 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2036 unsigned sregno, dregno;
2038 src = XEXP (set, 1);
2039 dest = XEXP (set, 0);
2042 sregno = DWARF_FRAME_RETURN_COLUMN;
2044 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2046 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2048 /* ??? We'd like to use queue_reg_save, but we need to come up with
2049 a different flushing heuristic for epilogues. */
2050 reg_save (label, sregno, dregno, 0);
2053 /* Helper function to get mode of MEM's address. */
2055 static inline enum machine_mode
2056 get_address_mode (rtx mem)
2058 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
2059 if (mode != VOIDmode)
2061 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
2064 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2067 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2069 rtx src, dest, span;
2070 dw_cfi_ref cfi = new_cfi ();
2072 dest = SET_DEST (set);
2073 src = SET_SRC (set);
2075 gcc_assert (REG_P (src));
2076 gcc_assert (MEM_P (dest));
2078 span = targetm.dwarf_register_span (src);
2081 cfi->dw_cfi_opc = DW_CFA_expression;
2082 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2083 cfi->dw_cfi_oprnd2.dw_cfi_loc
2084 = mem_loc_descriptor (XEXP (dest, 0), get_address_mode (dest),
2085 GET_MODE (dest), VAR_INIT_STATUS_INITIALIZED);
2087 /* ??? We'd like to use queue_reg_save, were the interface different,
2088 and, as above, we could manage flushing for epilogues. */
2089 add_fde_cfi (label, cfi);
2092 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2095 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2097 dw_cfi_ref cfi = new_cfi ();
2098 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2100 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2101 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2103 add_fde_cfi (label, cfi);
2106 /* Record call frame debugging information for an expression EXPR,
2107 which either sets SP or FP (adjusting how we calculate the frame
2108 address) or saves a register to the stack or another register.
2109 LABEL indicates the address of EXPR.
2111 This function encodes a state machine mapping rtxes to actions on
2112 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2113 users need not read the source code.
2115 The High-Level Picture
2117 Changes in the register we use to calculate the CFA: Currently we
2118 assume that if you copy the CFA register into another register, we
2119 should take the other one as the new CFA register; this seems to
2120 work pretty well. If it's wrong for some target, it's simple
2121 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2123 Changes in the register we use for saving registers to the stack:
2124 This is usually SP, but not always. Again, we deduce that if you
2125 copy SP into another register (and SP is not the CFA register),
2126 then the new register is the one we will be using for register
2127 saves. This also seems to work.
2129 Register saves: There's not much guesswork about this one; if
2130 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2131 register save, and the register used to calculate the destination
2132 had better be the one we think we're using for this purpose.
2133 It's also assumed that a copy from a call-saved register to another
2134 register is saving that register if RTX_FRAME_RELATED_P is set on
2135 that instruction. If the copy is from a call-saved register to
2136 the *same* register, that means that the register is now the same
2137 value as in the caller.
2139 Except: If the register being saved is the CFA register, and the
2140 offset is nonzero, we are saving the CFA, so we assume we have to
2141 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2142 the intent is to save the value of SP from the previous frame.
2144 In addition, if a register has previously been saved to a different
2147 Invariants / Summaries of Rules
2149 cfa current rule for calculating the CFA. It usually
2150 consists of a register and an offset.
2151 cfa_store register used by prologue code to save things to the stack
2152 cfa_store.offset is the offset from the value of
2153 cfa_store.reg to the actual CFA
2154 cfa_temp register holding an integral value. cfa_temp.offset
2155 stores the value, which will be used to adjust the
2156 stack pointer. cfa_temp is also used like cfa_store,
2157 to track stores to the stack via fp or a temp reg.
2159 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2160 with cfa.reg as the first operand changes the cfa.reg and its
2161 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2164 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2165 expression yielding a constant. This sets cfa_temp.reg
2166 and cfa_temp.offset.
2168 Rule 5: Create a new register cfa_store used to save items to the
2171 Rules 10-14: Save a register to the stack. Define offset as the
2172 difference of the original location and cfa_store's
2173 location (or cfa_temp's location if cfa_temp is used).
2175 Rules 16-20: If AND operation happens on sp in prologue, we assume
2176 stack is realigned. We will use a group of DW_OP_XXX
2177 expressions to represent the location of the stored
2178 register instead of CFA+offset.
2182 "{a,b}" indicates a choice of a xor b.
2183 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2186 (set <reg1> <reg2>:cfa.reg)
2187 effects: cfa.reg = <reg1>
2188 cfa.offset unchanged
2189 cfa_temp.reg = <reg1>
2190 cfa_temp.offset = cfa.offset
2193 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2194 {<const_int>,<reg>:cfa_temp.reg}))
2195 effects: cfa.reg = sp if fp used
2196 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2197 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2198 if cfa_store.reg==sp
2201 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2202 effects: cfa.reg = fp
2203 cfa_offset += +/- <const_int>
2206 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2207 constraints: <reg1> != fp
2209 effects: cfa.reg = <reg1>
2210 cfa_temp.reg = <reg1>
2211 cfa_temp.offset = cfa.offset
2214 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2215 constraints: <reg1> != fp
2217 effects: cfa_store.reg = <reg1>
2218 cfa_store.offset = cfa.offset - cfa_temp.offset
2221 (set <reg> <const_int>)
2222 effects: cfa_temp.reg = <reg>
2223 cfa_temp.offset = <const_int>
2226 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2227 effects: cfa_temp.reg = <reg1>
2228 cfa_temp.offset |= <const_int>
2231 (set <reg> (high <exp>))
2235 (set <reg> (lo_sum <exp> <const_int>))
2236 effects: cfa_temp.reg = <reg>
2237 cfa_temp.offset = <const_int>
2240 (set (mem ({pre,post}_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2241 effects: cfa_store.offset -= <const_int>
2242 cfa.offset = cfa_store.offset if cfa.reg == sp
2244 cfa.base_offset = -cfa_store.offset
2247 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2248 effects: cfa_store.offset += -/+ mode_size(mem)
2249 cfa.offset = cfa_store.offset if cfa.reg == sp
2251 cfa.base_offset = -cfa_store.offset
2254 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2257 effects: cfa.reg = <reg1>
2258 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2261 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2262 effects: cfa.reg = <reg1>
2263 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2266 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2267 effects: cfa.reg = <reg1>
2268 cfa.base_offset = -cfa_temp.offset
2269 cfa_temp.offset -= mode_size(mem)
2272 (set <reg> {unspec, unspec_volatile})
2273 effects: target-dependent
2276 (set sp (and: sp <const_int>))
2277 constraints: cfa_store.reg == sp
2278 effects: current_fde.stack_realign = 1
2279 cfa_store.offset = 0
2280 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2283 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2284 effects: cfa_store.offset += -/+ mode_size(mem)
2287 (set (mem ({pre_inc, pre_dec} sp)) fp)
2288 constraints: fde->stack_realign == 1
2289 effects: cfa_store.offset = 0
2290 cfa.reg != HARD_FRAME_POINTER_REGNUM
2293 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2294 constraints: fde->stack_realign == 1
2296 && cfa.indirect == 0
2297 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2298 effects: Use DW_CFA_def_cfa_expression to define cfa
2299 cfa.reg == fde->drap_reg */
2302 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2304 rtx src, dest, span;
2305 HOST_WIDE_INT offset;
2308 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2309 the PARALLEL independently. The first element is always processed if
2310 it is a SET. This is for backward compatibility. Other elements
2311 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2312 flag is set in them. */
2313 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2316 int limit = XVECLEN (expr, 0);
2319 /* PARALLELs have strict read-modify-write semantics, so we
2320 ought to evaluate every rvalue before changing any lvalue.
2321 It's cumbersome to do that in general, but there's an
2322 easy approximation that is enough for all current users:
2323 handle register saves before register assignments. */
2324 if (GET_CODE (expr) == PARALLEL)
2325 for (par_index = 0; par_index < limit; par_index++)
2327 elem = XVECEXP (expr, 0, par_index);
2328 if (GET_CODE (elem) == SET
2329 && MEM_P (SET_DEST (elem))
2330 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2331 dwarf2out_frame_debug_expr (elem, label);
2334 for (par_index = 0; par_index < limit; par_index++)
2336 elem = XVECEXP (expr, 0, par_index);
2337 if (GET_CODE (elem) == SET
2338 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2339 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2340 dwarf2out_frame_debug_expr (elem, label);
2341 else if (GET_CODE (elem) == SET
2343 && !RTX_FRAME_RELATED_P (elem))
2345 /* Stack adjustment combining might combine some post-prologue
2346 stack adjustment into a prologue stack adjustment. */
2347 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2350 dwarf2out_stack_adjust (offset, label);
2356 gcc_assert (GET_CODE (expr) == SET);
2358 src = SET_SRC (expr);
2359 dest = SET_DEST (expr);
2363 rtx rsi = reg_saved_in (src);
2368 fde = current_fde ();
2370 switch (GET_CODE (dest))
2373 switch (GET_CODE (src))
2375 /* Setting FP from SP. */
2377 if (cfa.reg == (unsigned) REGNO (src))
2380 /* Update the CFA rule wrt SP or FP. Make sure src is
2381 relative to the current CFA register.
2383 We used to require that dest be either SP or FP, but the
2384 ARM copies SP to a temporary register, and from there to
2385 FP. So we just rely on the backends to only set
2386 RTX_FRAME_RELATED_P on appropriate insns. */
2387 cfa.reg = REGNO (dest);
2388 cfa_temp.reg = cfa.reg;
2389 cfa_temp.offset = cfa.offset;
2393 /* Saving a register in a register. */
2394 gcc_assert (!fixed_regs [REGNO (dest)]
2395 /* For the SPARC and its register window. */
2396 || (DWARF_FRAME_REGNUM (REGNO (src))
2397 == DWARF_FRAME_RETURN_COLUMN));
2399 /* After stack is aligned, we can only save SP in FP
2400 if drap register is used. In this case, we have
2401 to restore stack pointer with the CFA value and we
2402 don't generate this DWARF information. */
2404 && fde->stack_realign
2405 && REGNO (src) == STACK_POINTER_REGNUM)
2406 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2407 && fde->drap_reg != INVALID_REGNUM
2408 && cfa.reg != REGNO (src));
2410 queue_reg_save (label, src, dest, 0);
2417 if (dest == stack_pointer_rtx)
2421 switch (GET_CODE (XEXP (src, 1)))
2424 offset = INTVAL (XEXP (src, 1));
2427 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2429 offset = cfa_temp.offset;
2435 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2437 /* Restoring SP from FP in the epilogue. */
2438 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2439 cfa.reg = STACK_POINTER_REGNUM;
2441 else if (GET_CODE (src) == LO_SUM)
2442 /* Assume we've set the source reg of the LO_SUM from sp. */
2445 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2447 if (GET_CODE (src) != MINUS)
2449 if (cfa.reg == STACK_POINTER_REGNUM)
2450 cfa.offset += offset;
2451 if (cfa_store.reg == STACK_POINTER_REGNUM)
2452 cfa_store.offset += offset;
2454 else if (dest == hard_frame_pointer_rtx)
2457 /* Either setting the FP from an offset of the SP,
2458 or adjusting the FP */
2459 gcc_assert (frame_pointer_needed);
2461 gcc_assert (REG_P (XEXP (src, 0))
2462 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2463 && CONST_INT_P (XEXP (src, 1)));
2464 offset = INTVAL (XEXP (src, 1));
2465 if (GET_CODE (src) != MINUS)
2467 cfa.offset += offset;
2468 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2472 gcc_assert (GET_CODE (src) != MINUS);
2475 if (REG_P (XEXP (src, 0))
2476 && REGNO (XEXP (src, 0)) == cfa.reg
2477 && CONST_INT_P (XEXP (src, 1)))
2479 /* Setting a temporary CFA register that will be copied
2480 into the FP later on. */
2481 offset = - INTVAL (XEXP (src, 1));
2482 cfa.offset += offset;
2483 cfa.reg = REGNO (dest);
2484 /* Or used to save regs to the stack. */
2485 cfa_temp.reg = cfa.reg;
2486 cfa_temp.offset = cfa.offset;
2490 else if (REG_P (XEXP (src, 0))
2491 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2492 && XEXP (src, 1) == stack_pointer_rtx)
2494 /* Setting a scratch register that we will use instead
2495 of SP for saving registers to the stack. */
2496 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2497 cfa_store.reg = REGNO (dest);
2498 cfa_store.offset = cfa.offset - cfa_temp.offset;
2502 else if (GET_CODE (src) == LO_SUM
2503 && CONST_INT_P (XEXP (src, 1)))
2505 cfa_temp.reg = REGNO (dest);
2506 cfa_temp.offset = INTVAL (XEXP (src, 1));
2515 cfa_temp.reg = REGNO (dest);
2516 cfa_temp.offset = INTVAL (src);
2521 gcc_assert (REG_P (XEXP (src, 0))
2522 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2523 && CONST_INT_P (XEXP (src, 1)));
2525 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2526 cfa_temp.reg = REGNO (dest);
2527 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2530 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2531 which will fill in all of the bits. */
2538 case UNSPEC_VOLATILE:
2539 gcc_assert (targetm.dwarf_handle_frame_unspec);
2540 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2545 /* If this AND operation happens on stack pointer in prologue,
2546 we assume the stack is realigned and we extract the
2548 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2550 /* We interpret reg_save differently with stack_realign set.
2551 Thus we must flush whatever we have queued first. */
2552 dwarf2out_flush_queued_reg_saves ();
2554 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2555 fde->stack_realign = 1;
2556 fde->stack_realignment = INTVAL (XEXP (src, 1));
2557 cfa_store.offset = 0;
2559 if (cfa.reg != STACK_POINTER_REGNUM
2560 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2561 fde->drap_reg = cfa.reg;
2569 def_cfa_1 (label, &cfa);
2574 /* Saving a register to the stack. Make sure dest is relative to the
2576 switch (GET_CODE (XEXP (dest, 0)))
2582 /* We can't handle variable size modifications. */
2583 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2585 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2587 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2588 && cfa_store.reg == STACK_POINTER_REGNUM);
2590 cfa_store.offset += offset;
2591 if (cfa.reg == STACK_POINTER_REGNUM)
2592 cfa.offset = cfa_store.offset;
2594 if (GET_CODE (XEXP (dest, 0)) == POST_MODIFY)
2595 offset -= cfa_store.offset;
2597 offset = -cfa_store.offset;
2604 offset = GET_MODE_SIZE (GET_MODE (dest));
2605 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2608 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2609 == STACK_POINTER_REGNUM)
2610 && cfa_store.reg == STACK_POINTER_REGNUM);
2612 cfa_store.offset += offset;
2614 /* Rule 18: If stack is aligned, we will use FP as a
2615 reference to represent the address of the stored
2618 && fde->stack_realign
2619 && src == hard_frame_pointer_rtx)
2621 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2622 cfa_store.offset = 0;
2625 if (cfa.reg == STACK_POINTER_REGNUM)
2626 cfa.offset = cfa_store.offset;
2628 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
2629 offset += -cfa_store.offset;
2631 offset = -cfa_store.offset;
2635 /* With an offset. */
2642 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2643 && REG_P (XEXP (XEXP (dest, 0), 0)));
2644 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2645 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2648 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2650 if (cfa.reg == (unsigned) regno)
2651 offset -= cfa.offset;
2652 else if (cfa_store.reg == (unsigned) regno)
2653 offset -= cfa_store.offset;
2656 gcc_assert (cfa_temp.reg == (unsigned) regno);
2657 offset -= cfa_temp.offset;
2663 /* Without an offset. */
2666 int regno = REGNO (XEXP (dest, 0));
2668 if (cfa.reg == (unsigned) regno)
2669 offset = -cfa.offset;
2670 else if (cfa_store.reg == (unsigned) regno)
2671 offset = -cfa_store.offset;
2674 gcc_assert (cfa_temp.reg == (unsigned) regno);
2675 offset = -cfa_temp.offset;
2682 gcc_assert (cfa_temp.reg
2683 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2684 offset = -cfa_temp.offset;
2685 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2693 /* If the source operand of this MEM operation is not a
2694 register, basically the source is return address. Here
2695 we only care how much stack grew and we don't save it. */
2699 if (REGNO (src) != STACK_POINTER_REGNUM
2700 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2701 && (unsigned) REGNO (src) == cfa.reg)
2703 /* We're storing the current CFA reg into the stack. */
2705 if (cfa.offset == 0)
2708 /* If stack is aligned, putting CFA reg into stack means
2709 we can no longer use reg + offset to represent CFA.
2710 Here we use DW_CFA_def_cfa_expression instead. The
2711 result of this expression equals to the original CFA
2714 && fde->stack_realign
2715 && cfa.indirect == 0
2716 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2718 dw_cfa_location cfa_exp;
2720 gcc_assert (fde->drap_reg == cfa.reg);
2722 cfa_exp.indirect = 1;
2723 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2724 cfa_exp.base_offset = offset;
2727 fde->drap_reg_saved = 1;
2729 def_cfa_1 (label, &cfa_exp);
2733 /* If the source register is exactly the CFA, assume
2734 we're saving SP like any other register; this happens
2736 def_cfa_1 (label, &cfa);
2737 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2742 /* Otherwise, we'll need to look in the stack to
2743 calculate the CFA. */
2744 rtx x = XEXP (dest, 0);
2748 gcc_assert (REG_P (x));
2750 cfa.reg = REGNO (x);
2751 cfa.base_offset = offset;
2753 def_cfa_1 (label, &cfa);
2758 def_cfa_1 (label, &cfa);
2760 span = targetm.dwarf_register_span (src);
2763 queue_reg_save (label, src, NULL_RTX, offset);
2766 /* We have a PARALLEL describing where the contents of SRC
2767 live. Queue register saves for each piece of the
2771 HOST_WIDE_INT span_offset = offset;
2773 gcc_assert (GET_CODE (span) == PARALLEL);
2775 limit = XVECLEN (span, 0);
2776 for (par_index = 0; par_index < limit; par_index++)
2778 rtx elem = XVECEXP (span, 0, par_index);
2780 queue_reg_save (label, elem, NULL_RTX, span_offset);
2781 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2792 /* Record call frame debugging information for INSN, which either
2793 sets SP or FP (adjusting how we calculate the frame address) or saves a
2794 register to the stack. If INSN is NULL_RTX, initialize our state.
2796 If AFTER_P is false, we're being called before the insn is emitted,
2797 otherwise after. Call instructions get invoked twice. */
2800 dwarf2out_frame_debug (rtx insn, bool after_p)
2804 bool handled_one = false;
2806 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2807 dwarf2out_flush_queued_reg_saves ();
2809 if (!RTX_FRAME_RELATED_P (insn))
2811 /* ??? This should be done unconditionally since stack adjustments
2812 matter if the stack pointer is not the CFA register anymore but
2813 is still used to save registers. */
2814 if (!ACCUMULATE_OUTGOING_ARGS)
2815 dwarf2out_notice_stack_adjust (insn, after_p);
2819 label = dwarf2out_cfi_label (false);
2820 any_cfis_emitted = false;
2822 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2823 switch (REG_NOTE_KIND (note))
2825 case REG_FRAME_RELATED_EXPR:
2826 insn = XEXP (note, 0);
2829 case REG_CFA_DEF_CFA:
2830 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2834 case REG_CFA_ADJUST_CFA:
2839 if (GET_CODE (n) == PARALLEL)
2840 n = XVECEXP (n, 0, 0);
2842 dwarf2out_frame_debug_adjust_cfa (n, label);
2846 case REG_CFA_OFFSET:
2849 n = single_set (insn);
2850 dwarf2out_frame_debug_cfa_offset (n, label);
2854 case REG_CFA_REGISTER:
2859 if (GET_CODE (n) == PARALLEL)
2860 n = XVECEXP (n, 0, 0);
2862 dwarf2out_frame_debug_cfa_register (n, label);
2866 case REG_CFA_EXPRESSION:
2869 n = single_set (insn);
2870 dwarf2out_frame_debug_cfa_expression (n, label);
2874 case REG_CFA_RESTORE:
2879 if (GET_CODE (n) == PARALLEL)
2880 n = XVECEXP (n, 0, 0);
2883 dwarf2out_frame_debug_cfa_restore (n, label);
2887 case REG_CFA_SET_VDRAP:
2891 dw_fde_ref fde = current_fde ();
2894 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2896 fde->vdrap_reg = REGNO (n);
2907 if (any_cfis_emitted)
2908 dwarf2out_flush_queued_reg_saves ();
2912 insn = PATTERN (insn);
2914 dwarf2out_frame_debug_expr (insn, label);
2916 /* Check again. A parallel can save and update the same register.
2917 We could probably check just once, here, but this is safer than
2918 removing the check above. */
2919 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2920 dwarf2out_flush_queued_reg_saves ();
2923 /* Called once at the start of final to initialize some data for the
2924 current function. */
2926 dwarf2out_frame_debug_init (void)
2930 /* Flush any queued register saves. */
2931 dwarf2out_flush_queued_reg_saves ();
2933 /* Set up state for generating call frame debug info. */
2936 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2938 cfa.reg = STACK_POINTER_REGNUM;
2941 cfa_temp.offset = 0;
2943 for (i = 0; i < num_regs_saved_in_regs; i++)
2945 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2946 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2948 num_regs_saved_in_regs = 0;
2950 if (barrier_args_size)
2952 XDELETEVEC (barrier_args_size);
2953 barrier_args_size = NULL;
2957 /* Determine if we need to save and restore CFI information around this
2958 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2959 we do need to save/restore, then emit the save now, and insert a
2960 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2963 dwarf2out_cfi_begin_epilogue (rtx insn)
2965 bool saw_frp = false;
2968 /* Scan forward to the return insn, noticing if there are possible
2969 frame related insns. */
2970 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2975 /* Look for both regular and sibcalls to end the block. */
2976 if (returnjump_p (i))
2978 if (CALL_P (i) && SIBLING_CALL_P (i))
2981 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2984 rtx seq = PATTERN (i);
2986 if (returnjump_p (XVECEXP (seq, 0, 0)))
2988 if (CALL_P (XVECEXP (seq, 0, 0))
2989 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2992 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2993 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2997 if (RTX_FRAME_RELATED_P (i))
3001 /* If the port doesn't emit epilogue unwind info, we don't need a
3002 save/restore pair. */
3006 /* Otherwise, search forward to see if the return insn was the last
3007 basic block of the function. If so, we don't need save/restore. */
3008 gcc_assert (i != NULL);
3009 i = next_real_insn (i);
3013 /* Insert the restore before that next real insn in the stream, and before
3014 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3015 properly nested. This should be after any label or alignment. This
3016 will be pushed into the CFI stream by the function below. */
3019 rtx p = PREV_INSN (i);
3022 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3026 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3028 emit_cfa_remember = true;
3030 /* And emulate the state save. */
3031 gcc_assert (!cfa_remember.in_use);
3033 cfa_remember.in_use = 1;
3036 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3040 dwarf2out_frame_debug_restore_state (void)
3042 dw_cfi_ref cfi = new_cfi ();
3043 const char *label = dwarf2out_cfi_label (false);
3045 cfi->dw_cfi_opc = DW_CFA_restore_state;
3046 add_fde_cfi (label, cfi);
3048 gcc_assert (cfa_remember.in_use);
3050 cfa_remember.in_use = 0;
3053 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3054 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3055 (enum dwarf_call_frame_info cfi);
3057 static enum dw_cfi_oprnd_type
3058 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3063 case DW_CFA_GNU_window_save:
3064 case DW_CFA_remember_state:
3065 case DW_CFA_restore_state:
3066 return dw_cfi_oprnd_unused;
3068 case DW_CFA_set_loc:
3069 case DW_CFA_advance_loc1:
3070 case DW_CFA_advance_loc2:
3071 case DW_CFA_advance_loc4:
3072 case DW_CFA_MIPS_advance_loc8:
3073 return dw_cfi_oprnd_addr;
3076 case DW_CFA_offset_extended:
3077 case DW_CFA_def_cfa:
3078 case DW_CFA_offset_extended_sf:
3079 case DW_CFA_def_cfa_sf:
3080 case DW_CFA_restore:
3081 case DW_CFA_restore_extended:
3082 case DW_CFA_undefined:
3083 case DW_CFA_same_value:
3084 case DW_CFA_def_cfa_register:
3085 case DW_CFA_register:
3086 case DW_CFA_expression:
3087 return dw_cfi_oprnd_reg_num;
3089 case DW_CFA_def_cfa_offset:
3090 case DW_CFA_GNU_args_size:
3091 case DW_CFA_def_cfa_offset_sf:
3092 return dw_cfi_oprnd_offset;
3094 case DW_CFA_def_cfa_expression:
3095 return dw_cfi_oprnd_loc;
3102 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3103 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3104 (enum dwarf_call_frame_info cfi);
3106 static enum dw_cfi_oprnd_type
3107 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3111 case DW_CFA_def_cfa:
3112 case DW_CFA_def_cfa_sf:
3114 case DW_CFA_offset_extended_sf:
3115 case DW_CFA_offset_extended:
3116 return dw_cfi_oprnd_offset;
3118 case DW_CFA_register:
3119 return dw_cfi_oprnd_reg_num;
3121 case DW_CFA_expression:
3122 return dw_cfi_oprnd_loc;
3125 return dw_cfi_oprnd_unused;
3129 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3130 switch to the data section instead, and write out a synthetic start label
3131 for collect2 the first time around. */
3134 switch_to_eh_frame_section (bool back)
3138 #ifdef EH_FRAME_SECTION_NAME
3139 if (eh_frame_section == 0)
3143 if (EH_TABLES_CAN_BE_READ_ONLY)
3149 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3151 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3153 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3155 flags = ((! flag_pic
3156 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3157 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3158 && (per_encoding & 0x70) != DW_EH_PE_absptr
3159 && (per_encoding & 0x70) != DW_EH_PE_aligned
3160 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3161 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3162 ? 0 : SECTION_WRITE);
3165 flags = SECTION_WRITE;
3166 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3168 #endif /* EH_FRAME_SECTION_NAME */
3170 if (eh_frame_section)
3171 switch_to_section (eh_frame_section);
3174 /* We have no special eh_frame section. Put the information in
3175 the data section and emit special labels to guide collect2. */
3176 switch_to_section (data_section);
3180 label = get_file_function_name ("F");
3181 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3182 targetm.asm_out.globalize_label (asm_out_file,
3183 IDENTIFIER_POINTER (label));
3184 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3189 /* Switch [BACK] to the eh or debug frame table section, depending on
3193 switch_to_frame_table_section (int for_eh, bool back)
3196 switch_to_eh_frame_section (back);
3199 if (!debug_frame_section)
3200 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3201 SECTION_DEBUG, NULL);
3202 switch_to_section (debug_frame_section);
3206 /* Output a Call Frame Information opcode and its operand(s). */
3209 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3214 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3215 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3216 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3217 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3218 ((unsigned HOST_WIDE_INT)
3219 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3220 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3222 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3223 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3224 "DW_CFA_offset, column %#lx", r);
3225 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3226 dw2_asm_output_data_uleb128 (off, NULL);
3228 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3230 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3231 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3232 "DW_CFA_restore, column %#lx", r);
3236 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3237 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3239 switch (cfi->dw_cfi_opc)
3241 case DW_CFA_set_loc:
3243 dw2_asm_output_encoded_addr_rtx (
3244 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3245 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3248 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3249 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3250 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3253 case DW_CFA_advance_loc1:
3254 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3255 fde->dw_fde_current_label, NULL);
3256 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3259 case DW_CFA_advance_loc2:
3260 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3261 fde->dw_fde_current_label, NULL);
3262 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3265 case DW_CFA_advance_loc4:
3266 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3267 fde->dw_fde_current_label, NULL);
3268 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3271 case DW_CFA_MIPS_advance_loc8:
3272 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3273 fde->dw_fde_current_label, NULL);
3274 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3277 case DW_CFA_offset_extended:
3278 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3279 dw2_asm_output_data_uleb128 (r, NULL);
3280 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3281 dw2_asm_output_data_uleb128 (off, NULL);
3284 case DW_CFA_def_cfa:
3285 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3286 dw2_asm_output_data_uleb128 (r, NULL);
3287 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3290 case DW_CFA_offset_extended_sf:
3291 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3292 dw2_asm_output_data_uleb128 (r, NULL);
3293 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3294 dw2_asm_output_data_sleb128 (off, NULL);
3297 case DW_CFA_def_cfa_sf:
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 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3301 dw2_asm_output_data_sleb128 (off, NULL);
3304 case DW_CFA_restore_extended:
3305 case DW_CFA_undefined:
3306 case DW_CFA_same_value:
3307 case DW_CFA_def_cfa_register:
3308 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3309 dw2_asm_output_data_uleb128 (r, NULL);
3312 case DW_CFA_register:
3313 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3314 dw2_asm_output_data_uleb128 (r, NULL);
3315 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3316 dw2_asm_output_data_uleb128 (r, NULL);
3319 case DW_CFA_def_cfa_offset:
3320 case DW_CFA_GNU_args_size:
3321 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3324 case DW_CFA_def_cfa_offset_sf:
3325 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3326 dw2_asm_output_data_sleb128 (off, NULL);
3329 case DW_CFA_GNU_window_save:
3332 case DW_CFA_def_cfa_expression:
3333 case DW_CFA_expression:
3334 output_cfa_loc (cfi, for_eh);
3337 case DW_CFA_GNU_negative_offset_extended:
3338 /* Obsoleted by DW_CFA_offset_extended_sf. */
3347 /* Similar, but do it via assembler directives instead. */
3350 output_cfi_directive (dw_cfi_ref cfi)
3352 unsigned long r, r2;
3354 switch (cfi->dw_cfi_opc)
3356 case DW_CFA_advance_loc:
3357 case DW_CFA_advance_loc1:
3358 case DW_CFA_advance_loc2:
3359 case DW_CFA_advance_loc4:
3360 case DW_CFA_MIPS_advance_loc8:
3361 case DW_CFA_set_loc:
3362 /* Should only be created by add_fde_cfi in a code path not
3363 followed when emitting via directives. The assembler is
3364 going to take care of this for us. */
3368 case DW_CFA_offset_extended:
3369 case DW_CFA_offset_extended_sf:
3370 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3371 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3372 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3375 case DW_CFA_restore:
3376 case DW_CFA_restore_extended:
3377 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3378 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3381 case DW_CFA_undefined:
3382 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3383 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3386 case DW_CFA_same_value:
3387 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3388 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3391 case DW_CFA_def_cfa:
3392 case DW_CFA_def_cfa_sf:
3393 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3394 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3395 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3398 case DW_CFA_def_cfa_register:
3399 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3400 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3403 case DW_CFA_register:
3404 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3405 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3406 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3409 case DW_CFA_def_cfa_offset:
3410 case DW_CFA_def_cfa_offset_sf:
3411 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3412 HOST_WIDE_INT_PRINT_DEC"\n",
3413 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3416 case DW_CFA_remember_state:
3417 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3419 case DW_CFA_restore_state:
3420 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3423 case DW_CFA_GNU_args_size:
3424 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3425 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3427 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3428 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3429 fputc ('\n', asm_out_file);
3432 case DW_CFA_GNU_window_save:
3433 fprintf (asm_out_file, "\t.cfi_window_save\n");
3436 case DW_CFA_def_cfa_expression:
3437 case DW_CFA_expression:
3438 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3439 output_cfa_loc_raw (cfi);
3440 fputc ('\n', asm_out_file);
3448 /* Output CFIs from VEC, up to index UPTO, to bring current FDE to the
3449 same state as after executing CFIs in CFI chain. DO_CFI_ASM is
3450 true if .cfi_* directives shall be emitted, false otherwise. If it
3451 is false, FDE and FOR_EH are the other arguments to pass to
3455 output_cfis (cfi_vec vec, int upto, bool do_cfi_asm,
3456 dw_fde_ref fde, bool for_eh)
3459 struct dw_cfi_struct cfi_buf;
3461 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3462 VEC(dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3463 unsigned int len, idx;
3465 for (ix = 0; ix < upto + 1; ix++)
3467 dw_cfi_ref cfi = ix < upto ? VEC_index (dw_cfi_ref, vec, ix) : NULL;
3468 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3470 case DW_CFA_advance_loc:
3471 case DW_CFA_advance_loc1:
3472 case DW_CFA_advance_loc2:
3473 case DW_CFA_advance_loc4:
3474 case DW_CFA_MIPS_advance_loc8:
3475 case DW_CFA_set_loc:
3476 /* All advances should be ignored. */
3478 case DW_CFA_remember_state:
3480 dw_cfi_ref args_size = cfi_args_size;
3482 /* Skip everything between .cfi_remember_state and
3483 .cfi_restore_state. */
3488 for (; ix < upto; ix++)
3490 cfi2 = VEC_index (dw_cfi_ref, vec, ix);
3491 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3493 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3496 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3499 cfi_args_size = args_size;
3502 case DW_CFA_GNU_args_size:
3503 cfi_args_size = cfi;
3505 case DW_CFA_GNU_window_save:
3508 case DW_CFA_offset_extended:
3509 case DW_CFA_offset_extended_sf:
3510 case DW_CFA_restore:
3511 case DW_CFA_restore_extended:
3512 case DW_CFA_undefined:
3513 case DW_CFA_same_value:
3514 case DW_CFA_register:
3515 case DW_CFA_val_offset:
3516 case DW_CFA_val_offset_sf:
3517 case DW_CFA_expression:
3518 case DW_CFA_val_expression:
3519 case DW_CFA_GNU_negative_offset_extended:
3520 if (VEC_length (dw_cfi_ref, regs)
3521 <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3522 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3523 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3524 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
3527 case DW_CFA_def_cfa:
3528 case DW_CFA_def_cfa_sf:
3529 case DW_CFA_def_cfa_expression:
3531 cfi_cfa_offset = cfi;
3533 case DW_CFA_def_cfa_register:
3536 case DW_CFA_def_cfa_offset:
3537 case DW_CFA_def_cfa_offset_sf:
3538 cfi_cfa_offset = cfi;
3541 gcc_assert (cfi == NULL);
3543 len = VEC_length (dw_cfi_ref, regs);
3544 for (idx = 0; idx < len; idx++)
3546 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3548 && cfi2->dw_cfi_opc != DW_CFA_restore
3549 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3552 output_cfi_directive (cfi2);
3554 output_cfi (cfi2, fde, for_eh);
3557 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3559 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3561 switch (cfi_cfa_offset->dw_cfi_opc)
3563 case DW_CFA_def_cfa_offset:
3564 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3565 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3567 case DW_CFA_def_cfa_offset_sf:
3568 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3569 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3571 case DW_CFA_def_cfa:
3572 case DW_CFA_def_cfa_sf:
3573 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3574 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3581 else if (cfi_cfa_offset)
3582 cfi_cfa = cfi_cfa_offset;
3586 output_cfi_directive (cfi_cfa);
3588 output_cfi (cfi_cfa, fde, for_eh);
3591 cfi_cfa_offset = NULL;
3593 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3596 output_cfi_directive (cfi_args_size);
3598 output_cfi (cfi_args_size, fde, for_eh);
3600 cfi_args_size = NULL;
3603 VEC_free (dw_cfi_ref, heap, regs);
3606 else if (do_cfi_asm)
3607 output_cfi_directive (cfi);
3609 output_cfi (cfi, fde, for_eh);
3617 /* Like output_cfis, but emit all CFIs in the vector. */
3619 output_all_cfis (cfi_vec vec, bool do_cfi_asm,
3620 dw_fde_ref fde, bool for_eh)
3622 output_cfis (vec, VEC_length (dw_cfi_ref, vec), do_cfi_asm, fde, for_eh);
3625 /* Output one FDE. */
3628 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3629 char *section_start_label, int fde_encoding, char *augmentation,
3630 bool any_lsda_needed, int lsda_encoding)
3633 const char *begin, *end;
3634 static unsigned int j;
3635 char l1[20], l2[20];
3638 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3640 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3642 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3643 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3644 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3645 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3646 " indicating 64-bit DWARF extension");
3647 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3649 ASM_OUTPUT_LABEL (asm_out_file, l1);
3652 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3654 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3655 debug_frame_section, "FDE CIE offset");
3657 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
3658 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
3662 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3663 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3664 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3665 "FDE initial location");
3666 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3667 end, begin, "FDE address range");
3671 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3672 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3675 if (augmentation[0])
3677 if (any_lsda_needed)
3679 int size = size_of_encoded_value (lsda_encoding);
3681 if (lsda_encoding == DW_EH_PE_aligned)
3683 int offset = ( 4 /* Length */
3684 + 4 /* CIE offset */
3685 + 2 * size_of_encoded_value (fde_encoding)
3686 + 1 /* Augmentation size */ );
3687 int pad = -offset & (PTR_SIZE - 1);
3690 gcc_assert (size_of_uleb128 (size) == 1);
3693 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3695 if (fde->uses_eh_lsda)
3697 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3698 fde->funcdef_number);
3699 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3700 gen_rtx_SYMBOL_REF (Pmode, l1),
3702 "Language Specific Data Area");
3706 if (lsda_encoding == DW_EH_PE_aligned)
3707 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3708 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3709 "Language Specific Data Area (none)");
3713 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3716 /* Loop through the Call Frame Instructions associated with
3718 fde->dw_fde_current_label = begin;
3719 if (fde->dw_fde_second_begin == NULL)
3720 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
3721 output_cfi (cfi, fde, for_eh);
3724 if (fde->dw_fde_switch_cfi_index > 0)
3725 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
3727 if (ix == fde->dw_fde_switch_cfi_index)
3729 output_cfi (cfi, fde, for_eh);
3735 int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
3737 if (fde->dw_fde_switch_cfi_index > 0)
3739 from = fde->dw_fde_switch_cfi_index;
3740 output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh);
3742 for (i = from; i < until; i++)
3743 output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i),
3747 /* If we are to emit a ref/link from function bodies to their frame tables,
3748 do it now. This is typically performed to make sure that tables
3749 associated with functions are dragged with them and not discarded in
3750 garbage collecting links. We need to do this on a per function basis to
3751 cope with -ffunction-sections. */
3753 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3754 /* Switch to the function section, emit the ref to the tables, and
3755 switch *back* into the table section. */
3756 switch_to_section (function_section (fde->decl));
3757 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3758 switch_to_frame_table_section (for_eh, true);
3761 /* Pad the FDE out to an address sized boundary. */
3762 ASM_OUTPUT_ALIGN (asm_out_file,
3763 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3764 ASM_OUTPUT_LABEL (asm_out_file, l2);
3769 /* Return true if frame description entry FDE is needed for EH. */
3772 fde_needed_for_eh_p (dw_fde_ref fde)
3774 if (flag_asynchronous_unwind_tables)
3777 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3780 if (fde->uses_eh_lsda)
3783 /* If exceptions are enabled, we have collected nothrow info. */
3784 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3790 /* Output the call frame information used to record information
3791 that relates to calculating the frame pointer, and records the
3792 location of saved registers. */
3795 output_call_frame_info (int for_eh)
3800 char l1[20], l2[20], section_start_label[20];
3801 bool any_lsda_needed = false;
3802 char augmentation[6];
3803 int augmentation_size;
3804 int fde_encoding = DW_EH_PE_absptr;
3805 int per_encoding = DW_EH_PE_absptr;
3806 int lsda_encoding = DW_EH_PE_absptr;
3808 rtx personality = NULL;
3811 /* Don't emit a CIE if there won't be any FDEs. */
3812 if (fde_table_in_use == 0)
3815 /* Nothing to do if the assembler's doing it all. */
3816 if (dwarf2out_do_cfi_asm ())
3819 /* If we don't have any functions we'll want to unwind out of, don't emit
3820 any EH unwind information. If we make FDEs linkonce, we may have to
3821 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3822 want to avoid having an FDE kept around when the function it refers to
3823 is discarded. Example where this matters: a primary function template
3824 in C++ requires EH information, an explicit specialization doesn't. */
3827 bool any_eh_needed = false;
3829 for (i = 0; i < fde_table_in_use; i++)
3830 if (fde_table[i].uses_eh_lsda)
3831 any_eh_needed = any_lsda_needed = true;
3832 else if (fde_needed_for_eh_p (&fde_table[i]))
3833 any_eh_needed = true;
3834 else if (TARGET_USES_WEAK_UNWIND_INFO)
3835 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3842 /* We're going to be generating comments, so turn on app. */
3846 /* Switch to the proper frame section, first time. */
3847 switch_to_frame_table_section (for_eh, false);
3849 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3850 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3852 /* Output the CIE. */
3853 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3854 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3855 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3856 dw2_asm_output_data (4, 0xffffffff,
3857 "Initial length escape value indicating 64-bit DWARF extension");
3858 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3859 "Length of Common Information Entry");
3860 ASM_OUTPUT_LABEL (asm_out_file, l1);
3862 /* Now that the CIE pointer is PC-relative for EH,
3863 use 0 to identify the CIE. */
3864 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3865 (for_eh ? 0 : DWARF_CIE_ID),
3866 "CIE Identifier Tag");
3868 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3869 use CIE version 1, unless that would produce incorrect results
3870 due to overflowing the return register column. */
3871 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3873 if (return_reg >= 256 || dwarf_version > 2)
3875 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3877 augmentation[0] = 0;
3878 augmentation_size = 0;
3880 personality = current_unit_personality;
3886 z Indicates that a uleb128 is present to size the
3887 augmentation section.
3888 L Indicates the encoding (and thus presence) of
3889 an LSDA pointer in the FDE augmentation.
3890 R Indicates a non-default pointer encoding for
3892 P Indicates the presence of an encoding + language
3893 personality routine in the CIE augmentation. */
3895 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3896 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3897 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3899 p = augmentation + 1;
3903 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3904 assemble_external_libcall (personality);
3906 if (any_lsda_needed)
3909 augmentation_size += 1;
3911 if (fde_encoding != DW_EH_PE_absptr)
3914 augmentation_size += 1;
3916 if (p > augmentation + 1)
3918 augmentation[0] = 'z';
3922 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3923 if (personality && per_encoding == DW_EH_PE_aligned)
3925 int offset = ( 4 /* Length */
3927 + 1 /* CIE version */
3928 + strlen (augmentation) + 1 /* Augmentation */
3929 + size_of_uleb128 (1) /* Code alignment */
3930 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3932 + 1 /* Augmentation size */
3933 + 1 /* Personality encoding */ );
3934 int pad = -offset & (PTR_SIZE - 1);
3936 augmentation_size += pad;
3938 /* Augmentations should be small, so there's scarce need to
3939 iterate for a solution. Die if we exceed one uleb128 byte. */
3940 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3944 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3945 if (dw_cie_version >= 4)
3947 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3948 dw2_asm_output_data (1, 0, "CIE Segment Size");
3950 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3951 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3952 "CIE Data Alignment Factor");
3954 if (dw_cie_version == 1)
3955 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3957 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3959 if (augmentation[0])
3961 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3964 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3965 eh_data_format_name (per_encoding));
3966 dw2_asm_output_encoded_addr_rtx (per_encoding,
3971 if (any_lsda_needed)
3972 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3973 eh_data_format_name (lsda_encoding));
3975 if (fde_encoding != DW_EH_PE_absptr)
3976 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3977 eh_data_format_name (fde_encoding));
3980 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
3981 output_cfi (cfi, NULL, for_eh);
3983 /* Pad the CIE out to an address sized boundary. */
3984 ASM_OUTPUT_ALIGN (asm_out_file,
3985 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3986 ASM_OUTPUT_LABEL (asm_out_file, l2);
3988 /* Loop through all of the FDE's. */
3989 for (i = 0; i < fde_table_in_use; i++)
3992 fde = &fde_table[i];
3994 /* Don't emit EH unwind info for leaf functions that don't need it. */
3995 if (for_eh && !fde_needed_for_eh_p (fde))
3998 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
3999 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
4000 augmentation, any_lsda_needed, lsda_encoding);
4003 if (for_eh && targetm.terminate_dw2_eh_frame_info)
4004 dw2_asm_output_data (4, 0, "End of Table");
4005 #ifdef MIPS_DEBUGGING_INFO
4006 /* Work around Irix 6 assembler bug whereby labels at the end of a section
4007 get a value of 0. Putting .align 0 after the label fixes it. */
4008 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4011 /* Turn off app to make assembly quicker. */
4016 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4019 dwarf2out_do_cfi_startproc (bool second)
4023 rtx personality = get_personality_function (current_function_decl);
4025 fprintf (asm_out_file, "\t.cfi_startproc\n");
4029 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4032 /* ??? The GAS support isn't entirely consistent. We have to
4033 handle indirect support ourselves, but PC-relative is done
4034 in the assembler. Further, the assembler can't handle any
4035 of the weirder relocation types. */
4036 if (enc & DW_EH_PE_indirect)
4037 ref = dw2_force_const_mem (ref, true);
4039 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4040 output_addr_const (asm_out_file, ref);
4041 fputc ('\n', asm_out_file);
4044 if (crtl->uses_eh_lsda)
4048 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4049 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4050 current_function_funcdef_no);
4051 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4052 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4054 if (enc & DW_EH_PE_indirect)
4055 ref = dw2_force_const_mem (ref, true);
4057 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4058 output_addr_const (asm_out_file, ref);
4059 fputc ('\n', asm_out_file);
4063 /* Output a marker (i.e. a label) for the beginning of a function, before
4067 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4068 const char *file ATTRIBUTE_UNUSED)
4070 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4076 current_function_func_begin_label = NULL;
4078 do_frame = dwarf2out_do_frame ();
4080 /* ??? current_function_func_begin_label is also used by except.c for
4081 call-site information. We must emit this label if it might be used. */
4083 && (!flag_exceptions
4084 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4087 fnsec = function_section (current_function_decl);
4088 switch_to_section (fnsec);
4089 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4090 current_function_funcdef_no);
4091 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4092 current_function_funcdef_no);
4093 dup_label = xstrdup (label);
4094 current_function_func_begin_label = dup_label;
4096 /* We can elide the fde allocation if we're not emitting debug info. */
4100 /* Expand the fde table if necessary. */
4101 if (fde_table_in_use == fde_table_allocated)
4103 fde_table_allocated += FDE_TABLE_INCREMENT;
4104 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4105 memset (fde_table + fde_table_in_use, 0,
4106 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4109 /* Record the FDE associated with this function. */
4110 current_funcdef_fde = fde_table_in_use;
4112 /* Add the new FDE at the end of the fde_table. */
4113 fde = &fde_table[fde_table_in_use++];
4114 fde->decl = current_function_decl;
4115 fde->dw_fde_begin = dup_label;
4116 fde->dw_fde_end = NULL;
4117 fde->dw_fde_current_label = dup_label;
4118 fde->dw_fde_second_begin = NULL;
4119 fde->dw_fde_second_end = NULL;
4120 fde->dw_fde_vms_end_prologue = NULL;
4121 fde->dw_fde_vms_begin_epilogue = NULL;
4122 fde->dw_fde_cfi = VEC_alloc (dw_cfi_ref, gc, 20);
4123 fde->dw_fde_switch_cfi_index = 0;
4124 fde->funcdef_number = current_function_funcdef_no;
4125 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4126 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4127 fde->nothrow = crtl->nothrow;
4128 fde->drap_reg = INVALID_REGNUM;
4129 fde->vdrap_reg = INVALID_REGNUM;
4130 fde->in_std_section = (fnsec == text_section
4131 || (cold_text_section && fnsec == cold_text_section));
4132 fde->second_in_std_section = 0;
4134 args_size = old_args_size = 0;
4136 /* We only want to output line number information for the genuine dwarf2
4137 prologue case, not the eh frame case. */
4138 #ifdef DWARF2_DEBUGGING_INFO
4140 dwarf2out_source_line (line, file, 0, true);
4143 if (dwarf2out_do_cfi_asm ())
4144 dwarf2out_do_cfi_startproc (false);
4147 rtx personality = get_personality_function (current_function_decl);
4148 if (!current_unit_personality)
4149 current_unit_personality = personality;
4151 /* We cannot keep a current personality per function as without CFI
4152 asm, at the point where we emit the CFI data, there is no current
4153 function anymore. */
4154 if (personality && current_unit_personality != personality)
4155 sorry ("multiple EH personalities are supported only with assemblers "
4156 "supporting .cfi_personality directive");
4160 /* Output a marker (i.e. a label) for the end of the generated code
4161 for a function prologue. This gets called *after* the prologue code has
4165 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4166 const char *file ATTRIBUTE_UNUSED)
4169 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4171 /* Output a label to mark the endpoint of the code generated for this
4173 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4174 current_function_funcdef_no);
4175 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4176 current_function_funcdef_no);
4177 fde = &fde_table[fde_table_in_use - 1];
4178 fde->dw_fde_vms_end_prologue = xstrdup (label);
4181 /* Output a marker (i.e. a label) for the beginning of the generated code
4182 for a function epilogue. This gets called *before* the prologue code has
4186 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4187 const char *file ATTRIBUTE_UNUSED)
4190 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4192 fde = &fde_table[fde_table_in_use - 1];
4193 if (fde->dw_fde_vms_begin_epilogue)
4196 /* Output a label to mark the endpoint of the code generated for this
4198 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4199 current_function_funcdef_no);
4200 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4201 current_function_funcdef_no);
4202 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4205 /* Output a marker (i.e. a label) for the absolute end of the generated code
4206 for a function definition. This gets called *after* the epilogue code has
4210 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4211 const char *file ATTRIBUTE_UNUSED)
4214 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4216 last_var_location_insn = NULL_RTX;
4218 if (dwarf2out_do_cfi_asm ())
4219 fprintf (asm_out_file, "\t.cfi_endproc\n");
4221 /* Output a label to mark the endpoint of the code generated for this
4223 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4224 current_function_funcdef_no);
4225 ASM_OUTPUT_LABEL (asm_out_file, label);
4226 fde = current_fde ();
4227 gcc_assert (fde != NULL);
4228 if (fde->dw_fde_second_begin == NULL)
4229 fde->dw_fde_end = xstrdup (label);
4233 dwarf2out_frame_init (void)
4235 /* Allocate the initial hunk of the fde_table. */
4236 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4237 fde_table_allocated = FDE_TABLE_INCREMENT;
4238 fde_table_in_use = 0;
4240 /* Generate the CFA instructions common to all FDE's. Do it now for the
4241 sake of lookup_cfa. */
4243 /* On entry, the Canonical Frame Address is at SP. */
4244 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4246 if (targetm.debug_unwind_info () == UI_DWARF2
4247 || targetm.except_unwind_info (&global_options) == UI_DWARF2)
4248 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4252 dwarf2out_frame_finish (void)
4254 /* Output call frame information. */
4255 if (targetm.debug_unwind_info () == UI_DWARF2)
4256 output_call_frame_info (0);
4258 /* Output another copy for the unwinder. */
4259 if ((flag_unwind_tables || flag_exceptions)
4260 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
4261 output_call_frame_info (1);
4264 /* Note that the current function section is being used for code. */
4267 dwarf2out_note_section_used (void)
4269 section *sec = current_function_section ();
4270 if (sec == text_section)
4271 text_section_used = true;
4272 else if (sec == cold_text_section)
4273 cold_text_section_used = true;
4276 static void var_location_switch_text_section (void);
4277 static void set_cur_line_info_table (section *);
4280 dwarf2out_switch_text_section (void)
4283 dw_fde_ref fde = current_fde ();
4285 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
4287 if (!in_cold_section_p)
4289 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
4290 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
4291 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
4295 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
4296 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
4297 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
4299 have_multiple_function_sections = true;
4301 /* Reset the current label on switching text sections, so that we
4302 don't attempt to advance_loc4 between labels in different sections. */
4303 fde->dw_fde_current_label = NULL;
4305 /* There is no need to mark used sections when not debugging. */
4306 if (cold_text_section != NULL)
4307 dwarf2out_note_section_used ();
4309 if (dwarf2out_do_cfi_asm ())
4310 fprintf (asm_out_file, "\t.cfi_endproc\n");
4312 /* Now do the real section switch. */
4313 sect = current_function_section ();
4314 switch_to_section (sect);
4316 fde->second_in_std_section
4317 = (sect == text_section
4318 || (cold_text_section && sect == cold_text_section));
4320 if (dwarf2out_do_cfi_asm ())
4322 dwarf2out_do_cfi_startproc (true);
4323 /* As this is a different FDE, insert all current CFI instructions
4325 output_all_cfis (fde->dw_fde_cfi, true, fde, true);
4327 fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
4328 var_location_switch_text_section ();
4330 set_cur_line_info_table (sect);
4333 /* And now, the subset of the debugging information support code necessary
4334 for emitting location expressions. */
4336 /* Data about a single source file. */
4337 struct GTY(()) dwarf_file_data {
4338 const char * filename;
4342 typedef struct dw_val_struct *dw_val_ref;
4343 typedef struct die_struct *dw_die_ref;
4344 typedef const struct die_struct *const_dw_die_ref;
4345 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4346 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4348 typedef struct GTY(()) deferred_locations_struct
4352 } deferred_locations;
4354 DEF_VEC_O(deferred_locations);
4355 DEF_VEC_ALLOC_O(deferred_locations,gc);
4357 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4359 DEF_VEC_P(dw_die_ref);
4360 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4362 /* Each DIE may have a series of attribute/value pairs. Values
4363 can take on several forms. The forms that are used in this
4364 implementation are listed below. */
4369 dw_val_class_offset,
4371 dw_val_class_loc_list,
4372 dw_val_class_range_list,
4374 dw_val_class_unsigned_const,
4375 dw_val_class_const_double,
4378 dw_val_class_die_ref,
4379 dw_val_class_fde_ref,
4380 dw_val_class_lbl_id,
4381 dw_val_class_lineptr,
4383 dw_val_class_macptr,
4386 dw_val_class_decl_ref,
4387 dw_val_class_vms_delta
4390 /* Describe a floating point constant value, or a vector constant value. */
4392 typedef struct GTY(()) dw_vec_struct {
4393 unsigned char * GTY((length ("%h.length"))) array;
4399 /* The dw_val_node describes an attribute's value, as it is
4400 represented internally. */
4402 typedef struct GTY(()) dw_val_struct {
4403 enum dw_val_class val_class;
4404 union dw_val_struct_union
4406 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4407 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4408 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4409 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4410 HOST_WIDE_INT GTY ((default)) val_int;
4411 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4412 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4413 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4414 struct dw_val_die_union
4418 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4419 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4420 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4421 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4422 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4423 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4424 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4425 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4426 struct dw_val_vms_delta_union
4430 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4432 GTY ((desc ("%1.val_class"))) v;
4436 /* Locations in memory are described using a sequence of stack machine
4439 typedef struct GTY(()) dw_loc_descr_struct {
4440 dw_loc_descr_ref dw_loc_next;
4441 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4442 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4443 from DW_OP_addr with a dtp-relative symbol relocation. */
4444 unsigned int dtprel : 1;
4446 dw_val_node dw_loc_oprnd1;
4447 dw_val_node dw_loc_oprnd2;
4451 /* Location lists are ranges + location descriptions for that range,
4452 so you can track variables that are in different places over
4453 their entire life. */
4454 typedef struct GTY(()) dw_loc_list_struct {
4455 dw_loc_list_ref dw_loc_next;
4456 const char *begin; /* Label for begin address of range */
4457 const char *end; /* Label for end address of range */
4458 char *ll_symbol; /* Label for beginning of location list.
4459 Only on head of list */
4460 const char *section; /* Section this loclist is relative to */
4461 dw_loc_descr_ref expr;
4463 /* True if all addresses in this and subsequent lists are known to be
4466 /* True if this list has been replaced by dw_loc_next. */
4471 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4473 /* Convert a DWARF stack opcode into its string name. */
4476 dwarf_stack_op_name (unsigned int op)
4481 return "DW_OP_addr";
4483 return "DW_OP_deref";
4485 return "DW_OP_const1u";
4487 return "DW_OP_const1s";
4489 return "DW_OP_const2u";
4491 return "DW_OP_const2s";
4493 return "DW_OP_const4u";
4495 return "DW_OP_const4s";
4497 return "DW_OP_const8u";
4499 return "DW_OP_const8s";
4501 return "DW_OP_constu";
4503 return "DW_OP_consts";
4507 return "DW_OP_drop";
4509 return "DW_OP_over";
4511 return "DW_OP_pick";
4513 return "DW_OP_swap";
4517 return "DW_OP_xderef";
4525 return "DW_OP_minus";
4537 return "DW_OP_plus";
4538 case DW_OP_plus_uconst:
4539 return "DW_OP_plus_uconst";
4545 return "DW_OP_shra";
4563 return "DW_OP_skip";
4565 return "DW_OP_lit0";
4567 return "DW_OP_lit1";
4569 return "DW_OP_lit2";
4571 return "DW_OP_lit3";
4573 return "DW_OP_lit4";
4575 return "DW_OP_lit5";
4577 return "DW_OP_lit6";
4579 return "DW_OP_lit7";
4581 return "DW_OP_lit8";
4583 return "DW_OP_lit9";
4585 return "DW_OP_lit10";
4587 return "DW_OP_lit11";
4589 return "DW_OP_lit12";
4591 return "DW_OP_lit13";
4593 return "DW_OP_lit14";
4595 return "DW_OP_lit15";
4597 return "DW_OP_lit16";
4599 return "DW_OP_lit17";
4601 return "DW_OP_lit18";
4603 return "DW_OP_lit19";
4605 return "DW_OP_lit20";
4607 return "DW_OP_lit21";
4609 return "DW_OP_lit22";
4611 return "DW_OP_lit23";
4613 return "DW_OP_lit24";
4615 return "DW_OP_lit25";
4617 return "DW_OP_lit26";
4619 return "DW_OP_lit27";
4621 return "DW_OP_lit28";
4623 return "DW_OP_lit29";
4625 return "DW_OP_lit30";
4627 return "DW_OP_lit31";
4629 return "DW_OP_reg0";
4631 return "DW_OP_reg1";
4633 return "DW_OP_reg2";
4635 return "DW_OP_reg3";
4637 return "DW_OP_reg4";
4639 return "DW_OP_reg5";
4641 return "DW_OP_reg6";
4643 return "DW_OP_reg7";
4645 return "DW_OP_reg8";
4647 return "DW_OP_reg9";
4649 return "DW_OP_reg10";
4651 return "DW_OP_reg11";
4653 return "DW_OP_reg12";
4655 return "DW_OP_reg13";
4657 return "DW_OP_reg14";
4659 return "DW_OP_reg15";
4661 return "DW_OP_reg16";
4663 return "DW_OP_reg17";
4665 return "DW_OP_reg18";
4667 return "DW_OP_reg19";
4669 return "DW_OP_reg20";
4671 return "DW_OP_reg21";
4673 return "DW_OP_reg22";
4675 return "DW_OP_reg23";
4677 return "DW_OP_reg24";
4679 return "DW_OP_reg25";
4681 return "DW_OP_reg26";
4683 return "DW_OP_reg27";
4685 return "DW_OP_reg28";
4687 return "DW_OP_reg29";
4689 return "DW_OP_reg30";
4691 return "DW_OP_reg31";
4693 return "DW_OP_breg0";
4695 return "DW_OP_breg1";
4697 return "DW_OP_breg2";
4699 return "DW_OP_breg3";
4701 return "DW_OP_breg4";
4703 return "DW_OP_breg5";
4705 return "DW_OP_breg6";
4707 return "DW_OP_breg7";
4709 return "DW_OP_breg8";
4711 return "DW_OP_breg9";
4713 return "DW_OP_breg10";
4715 return "DW_OP_breg11";
4717 return "DW_OP_breg12";
4719 return "DW_OP_breg13";
4721 return "DW_OP_breg14";
4723 return "DW_OP_breg15";
4725 return "DW_OP_breg16";
4727 return "DW_OP_breg17";
4729 return "DW_OP_breg18";
4731 return "DW_OP_breg19";
4733 return "DW_OP_breg20";
4735 return "DW_OP_breg21";
4737 return "DW_OP_breg22";
4739 return "DW_OP_breg23";
4741 return "DW_OP_breg24";
4743 return "DW_OP_breg25";
4745 return "DW_OP_breg26";
4747 return "DW_OP_breg27";
4749 return "DW_OP_breg28";
4751 return "DW_OP_breg29";
4753 return "DW_OP_breg30";
4755 return "DW_OP_breg31";
4757 return "DW_OP_regx";
4759 return "DW_OP_fbreg";
4761 return "DW_OP_bregx";
4763 return "DW_OP_piece";
4764 case DW_OP_deref_size:
4765 return "DW_OP_deref_size";
4766 case DW_OP_xderef_size:
4767 return "DW_OP_xderef_size";
4771 case DW_OP_push_object_address:
4772 return "DW_OP_push_object_address";
4774 return "DW_OP_call2";
4776 return "DW_OP_call4";
4777 case DW_OP_call_ref:
4778 return "DW_OP_call_ref";
4779 case DW_OP_implicit_value:
4780 return "DW_OP_implicit_value";
4781 case DW_OP_stack_value:
4782 return "DW_OP_stack_value";
4783 case DW_OP_form_tls_address:
4784 return "DW_OP_form_tls_address";
4785 case DW_OP_call_frame_cfa:
4786 return "DW_OP_call_frame_cfa";
4787 case DW_OP_bit_piece:
4788 return "DW_OP_bit_piece";
4790 case DW_OP_GNU_push_tls_address:
4791 return "DW_OP_GNU_push_tls_address";
4792 case DW_OP_GNU_uninit:
4793 return "DW_OP_GNU_uninit";
4794 case DW_OP_GNU_encoded_addr:
4795 return "DW_OP_GNU_encoded_addr";
4796 case DW_OP_GNU_implicit_pointer:
4797 return "DW_OP_GNU_implicit_pointer";
4798 case DW_OP_GNU_entry_value:
4799 return "DW_OP_GNU_entry_value";
4800 case DW_OP_GNU_const_type:
4801 return "DW_OP_GNU_const_type";
4802 case DW_OP_GNU_regval_type:
4803 return "DW_OP_GNU_regval_type";
4804 case DW_OP_GNU_deref_type:
4805 return "DW_OP_GNU_deref_type";
4806 case DW_OP_GNU_convert:
4807 return "DW_OP_GNU_convert";
4808 case DW_OP_GNU_reinterpret:
4809 return "DW_OP_GNU_reinterpret";
4812 return "OP_<unknown>";
4816 /* Return a pointer to a newly allocated location description. Location
4817 descriptions are simple expression terms that can be strung
4818 together to form more complicated location (address) descriptions. */
4820 static inline dw_loc_descr_ref
4821 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4822 unsigned HOST_WIDE_INT oprnd2)
4824 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4826 descr->dw_loc_opc = op;
4827 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4828 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4829 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4830 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4835 /* Return a pointer to a newly allocated location description for
4838 static inline dw_loc_descr_ref
4839 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4842 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4845 return new_loc_descr (DW_OP_bregx, reg, offset);
4848 /* Add a location description term to a location description expression. */
4851 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4853 dw_loc_descr_ref *d;
4855 /* Find the end of the chain. */
4856 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4862 /* Add a constant OFFSET to a location expression. */
4865 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4867 dw_loc_descr_ref loc;
4870 gcc_assert (*list_head != NULL);
4875 /* Find the end of the chain. */
4876 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4880 if (loc->dw_loc_opc == DW_OP_fbreg
4881 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4882 p = &loc->dw_loc_oprnd1.v.val_int;
4883 else if (loc->dw_loc_opc == DW_OP_bregx)
4884 p = &loc->dw_loc_oprnd2.v.val_int;
4886 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4887 offset. Don't optimize if an signed integer overflow would happen. */
4889 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4890 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4893 else if (offset > 0)
4894 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4898 loc->dw_loc_next = int_loc_descriptor (-offset);
4899 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4903 /* Add a constant OFFSET to a location list. */
4906 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4909 for (d = list_head; d != NULL; d = d->dw_loc_next)
4910 loc_descr_plus_const (&d->expr, offset);
4913 #define DWARF_REF_SIZE \
4914 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4916 static unsigned long size_of_locs (dw_loc_descr_ref);
4917 static unsigned long int get_base_type_offset (dw_die_ref);
4919 /* Return the size of a location descriptor. */
4921 static unsigned long
4922 size_of_loc_descr (dw_loc_descr_ref loc)
4924 unsigned long size = 1;
4926 switch (loc->dw_loc_opc)
4929 size += DWARF2_ADDR_SIZE;
4948 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4951 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4956 case DW_OP_plus_uconst:
4957 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4995 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4998 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5001 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
5004 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5005 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5008 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5010 case DW_OP_bit_piece:
5011 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5012 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
5014 case DW_OP_deref_size:
5015 case DW_OP_xderef_size:
5024 case DW_OP_call_ref:
5025 size += DWARF_REF_SIZE;
5027 case DW_OP_implicit_value:
5028 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5029 + loc->dw_loc_oprnd1.v.val_unsigned;
5031 case DW_OP_GNU_implicit_pointer:
5032 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5034 case DW_OP_GNU_entry_value:
5036 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
5037 size += size_of_uleb128 (op_size) + op_size;
5040 case DW_OP_GNU_const_type:
5043 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
5044 size += size_of_uleb128 (o) + 1;
5045 switch (loc->dw_loc_oprnd2.val_class)
5047 case dw_val_class_vec:
5048 size += loc->dw_loc_oprnd2.v.val_vec.length
5049 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
5051 case dw_val_class_const:
5052 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
5054 case dw_val_class_const_double:
5055 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
5062 case DW_OP_GNU_regval_type:
5065 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
5066 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5067 + size_of_uleb128 (o);
5070 case DW_OP_GNU_deref_type:
5073 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
5074 size += 1 + size_of_uleb128 (o);
5077 case DW_OP_GNU_convert:
5078 case DW_OP_GNU_reinterpret:
5081 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
5082 size += size_of_uleb128 (o);
5091 /* Return the size of a series of location descriptors. */
5093 static unsigned long
5094 size_of_locs (dw_loc_descr_ref loc)
5099 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5100 field, to avoid writing to a PCH file. */
5101 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5103 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5105 size += size_of_loc_descr (l);
5110 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5112 l->dw_loc_addr = size;
5113 size += size_of_loc_descr (l);
5119 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5120 static void get_ref_die_offset_label (char *, dw_die_ref);
5121 static void output_loc_sequence (dw_loc_descr_ref, int);
5123 /* Output location description stack opcode's operands (if any).
5124 The for_eh_or_skip parameter controls whether register numbers are
5125 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5126 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5127 info). This should be suppressed for the cases that have not been converted
5128 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5131 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5133 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5134 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5136 switch (loc->dw_loc_opc)
5138 #ifdef DWARF2_DEBUGGING_INFO
5141 dw2_asm_output_data (2, val1->v.val_int, NULL);
5146 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5147 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5149 fputc ('\n', asm_out_file);
5154 dw2_asm_output_data (4, val1->v.val_int, NULL);
5159 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5160 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5162 fputc ('\n', asm_out_file);
5167 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5168 dw2_asm_output_data (8, val1->v.val_int, NULL);
5175 gcc_assert (val1->val_class == dw_val_class_loc);
5176 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5178 dw2_asm_output_data (2, offset, NULL);
5181 case DW_OP_implicit_value:
5182 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5183 switch (val2->val_class)
5185 case dw_val_class_const:
5186 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5188 case dw_val_class_vec:
5190 unsigned int elt_size = val2->v.val_vec.elt_size;
5191 unsigned int len = val2->v.val_vec.length;
5195 if (elt_size > sizeof (HOST_WIDE_INT))
5200 for (i = 0, p = val2->v.val_vec.array;
5203 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5204 "fp or vector constant word %u", i);
5207 case dw_val_class_const_double:
5209 unsigned HOST_WIDE_INT first, second;
5211 if (WORDS_BIG_ENDIAN)
5213 first = val2->v.val_double.high;
5214 second = val2->v.val_double.low;
5218 first = val2->v.val_double.low;
5219 second = val2->v.val_double.high;
5221 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5223 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5227 case dw_val_class_addr:
5228 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5229 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5244 case DW_OP_implicit_value:
5245 /* We currently don't make any attempt to make sure these are
5246 aligned properly like we do for the main unwind info, so
5247 don't support emitting things larger than a byte if we're
5248 only doing unwinding. */
5253 dw2_asm_output_data (1, val1->v.val_int, NULL);
5256 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5259 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5262 dw2_asm_output_data (1, val1->v.val_int, NULL);
5264 case DW_OP_plus_uconst:
5265 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5299 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5303 unsigned r = val1->v.val_unsigned;
5304 if (for_eh_or_skip >= 0)
5305 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5306 gcc_assert (size_of_uleb128 (r)
5307 == size_of_uleb128 (val1->v.val_unsigned));
5308 dw2_asm_output_data_uleb128 (r, NULL);
5312 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5316 unsigned r = val1->v.val_unsigned;
5317 if (for_eh_or_skip >= 0)
5318 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5319 gcc_assert (size_of_uleb128 (r)
5320 == size_of_uleb128 (val1->v.val_unsigned));
5321 dw2_asm_output_data_uleb128 (r, NULL);
5322 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5326 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5328 case DW_OP_bit_piece:
5329 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5330 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5332 case DW_OP_deref_size:
5333 case DW_OP_xderef_size:
5334 dw2_asm_output_data (1, val1->v.val_int, NULL);
5340 if (targetm.asm_out.output_dwarf_dtprel)
5342 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5345 fputc ('\n', asm_out_file);
5352 #ifdef DWARF2_DEBUGGING_INFO
5353 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5360 case DW_OP_GNU_implicit_pointer:
5362 char label[MAX_ARTIFICIAL_LABEL_BYTES
5363 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5364 gcc_assert (val1->val_class == dw_val_class_die_ref);
5365 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5366 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5367 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5371 case DW_OP_GNU_entry_value:
5372 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5373 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5376 case DW_OP_GNU_const_type:
5378 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
5380 dw2_asm_output_data_uleb128 (o, NULL);
5381 switch (val2->val_class)
5383 case dw_val_class_const:
5384 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5385 dw2_asm_output_data (1, l, NULL);
5386 dw2_asm_output_data (l, val2->v.val_int, NULL);
5388 case dw_val_class_vec:
5390 unsigned int elt_size = val2->v.val_vec.elt_size;
5391 unsigned int len = val2->v.val_vec.length;
5396 dw2_asm_output_data (1, l, NULL);
5397 if (elt_size > sizeof (HOST_WIDE_INT))
5402 for (i = 0, p = val2->v.val_vec.array;
5405 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5406 "fp or vector constant word %u", i);
5409 case dw_val_class_const_double:
5411 unsigned HOST_WIDE_INT first, second;
5412 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5414 dw2_asm_output_data (1, 2 * l, NULL);
5415 if (WORDS_BIG_ENDIAN)
5417 first = val2->v.val_double.high;
5418 second = val2->v.val_double.low;
5422 first = val2->v.val_double.low;
5423 second = val2->v.val_double.high;
5425 dw2_asm_output_data (l, first, NULL);
5426 dw2_asm_output_data (l, second, NULL);
5434 case DW_OP_GNU_regval_type:
5436 unsigned r = val1->v.val_unsigned;
5437 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
5439 if (for_eh_or_skip >= 0)
5441 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5442 gcc_assert (size_of_uleb128 (r)
5443 == size_of_uleb128 (val1->v.val_unsigned));
5445 dw2_asm_output_data_uleb128 (r, NULL);
5446 dw2_asm_output_data_uleb128 (o, NULL);
5449 case DW_OP_GNU_deref_type:
5451 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
5453 dw2_asm_output_data (1, val1->v.val_int, NULL);
5454 dw2_asm_output_data_uleb128 (o, NULL);
5457 case DW_OP_GNU_convert:
5458 case DW_OP_GNU_reinterpret:
5460 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
5462 dw2_asm_output_data_uleb128 (o, NULL);
5467 /* Other codes have no operands. */
5472 /* Output a sequence of location operations.
5473 The for_eh_or_skip parameter controls whether register numbers are
5474 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5475 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5476 info). This should be suppressed for the cases that have not been converted
5477 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5480 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5482 for (; loc != NULL; loc = loc->dw_loc_next)
5484 enum dwarf_location_atom opc = loc->dw_loc_opc;
5485 /* Output the opcode. */
5486 if (for_eh_or_skip >= 0
5487 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5489 unsigned r = (opc - DW_OP_breg0);
5490 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5491 gcc_assert (r <= 31);
5492 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5494 else if (for_eh_or_skip >= 0
5495 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5497 unsigned r = (opc - DW_OP_reg0);
5498 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5499 gcc_assert (r <= 31);
5500 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5503 dw2_asm_output_data (1, opc,
5504 "%s", dwarf_stack_op_name (opc));
5506 /* Output the operand(s) (if any). */
5507 output_loc_operands (loc, for_eh_or_skip);
5511 /* Output location description stack opcode's operands (if any).
5512 The output is single bytes on a line, suitable for .cfi_escape. */
5515 output_loc_operands_raw (dw_loc_descr_ref loc)
5517 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5518 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5520 switch (loc->dw_loc_opc)
5523 case DW_OP_implicit_value:
5524 /* We cannot output addresses in .cfi_escape, only bytes. */
5530 case DW_OP_deref_size:
5531 case DW_OP_xderef_size:
5532 fputc (',', asm_out_file);
5533 dw2_asm_output_data_raw (1, val1->v.val_int);
5538 fputc (',', asm_out_file);
5539 dw2_asm_output_data_raw (2, val1->v.val_int);
5544 fputc (',', asm_out_file);
5545 dw2_asm_output_data_raw (4, val1->v.val_int);
5550 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5551 fputc (',', asm_out_file);
5552 dw2_asm_output_data_raw (8, val1->v.val_int);
5560 gcc_assert (val1->val_class == dw_val_class_loc);
5561 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5563 fputc (',', asm_out_file);
5564 dw2_asm_output_data_raw (2, offset);
5570 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5571 gcc_assert (size_of_uleb128 (r)
5572 == size_of_uleb128 (val1->v.val_unsigned));
5573 fputc (',', asm_out_file);
5574 dw2_asm_output_data_uleb128_raw (r);
5579 case DW_OP_plus_uconst:
5581 fputc (',', asm_out_file);
5582 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5585 case DW_OP_bit_piece:
5586 fputc (',', asm_out_file);
5587 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5588 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5625 fputc (',', asm_out_file);
5626 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5631 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5632 gcc_assert (size_of_uleb128 (r)
5633 == size_of_uleb128 (val1->v.val_unsigned));
5634 fputc (',', asm_out_file);
5635 dw2_asm_output_data_uleb128_raw (r);
5636 fputc (',', asm_out_file);
5637 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5641 case DW_OP_GNU_implicit_pointer:
5642 case DW_OP_GNU_entry_value:
5643 case DW_OP_GNU_const_type:
5644 case DW_OP_GNU_regval_type:
5645 case DW_OP_GNU_deref_type:
5646 case DW_OP_GNU_convert:
5647 case DW_OP_GNU_reinterpret:
5652 /* Other codes have no operands. */
5658 output_loc_sequence_raw (dw_loc_descr_ref loc)
5662 enum dwarf_location_atom opc = loc->dw_loc_opc;
5663 /* Output the opcode. */
5664 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5666 unsigned r = (opc - DW_OP_breg0);
5667 r = DWARF2_FRAME_REG_OUT (r, 1);
5668 gcc_assert (r <= 31);
5669 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5671 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5673 unsigned r = (opc - DW_OP_reg0);
5674 r = DWARF2_FRAME_REG_OUT (r, 1);
5675 gcc_assert (r <= 31);
5676 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5678 /* Output the opcode. */
5679 fprintf (asm_out_file, "%#x", opc);
5680 output_loc_operands_raw (loc);
5682 if (!loc->dw_loc_next)
5684 loc = loc->dw_loc_next;
5686 fputc (',', asm_out_file);
5690 /* This routine will generate the correct assembly data for a location
5691 description based on a cfi entry with a complex address. */
5694 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5696 dw_loc_descr_ref loc;
5699 if (cfi->dw_cfi_opc == DW_CFA_expression)
5702 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5703 dw2_asm_output_data (1, r, NULL);
5704 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5707 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5709 /* Output the size of the block. */
5710 size = size_of_locs (loc);
5711 dw2_asm_output_data_uleb128 (size, NULL);
5713 /* Now output the operations themselves. */
5714 output_loc_sequence (loc, for_eh);
5717 /* Similar, but used for .cfi_escape. */
5720 output_cfa_loc_raw (dw_cfi_ref cfi)
5722 dw_loc_descr_ref loc;
5725 if (cfi->dw_cfi_opc == DW_CFA_expression)
5728 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5729 fprintf (asm_out_file, "%#x,", r);
5730 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5733 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5735 /* Output the size of the block. */
5736 size = size_of_locs (loc);
5737 dw2_asm_output_data_uleb128_raw (size);
5738 fputc (',', asm_out_file);
5740 /* Now output the operations themselves. */
5741 output_loc_sequence_raw (loc);
5744 /* This function builds a dwarf location descriptor sequence from a
5745 dw_cfa_location, adding the given OFFSET to the result of the
5748 static struct dw_loc_descr_struct *
5749 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5751 struct dw_loc_descr_struct *head, *tmp;
5753 offset += cfa->offset;
5757 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5758 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5759 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5760 add_loc_descr (&head, tmp);
5763 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5764 add_loc_descr (&head, tmp);
5768 head = new_reg_loc_descr (cfa->reg, offset);
5773 /* This function builds a dwarf location descriptor sequence for
5774 the address at OFFSET from the CFA when stack is aligned to
5777 static struct dw_loc_descr_struct *
5778 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5780 struct dw_loc_descr_struct *head;
5781 unsigned int dwarf_fp
5782 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5784 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5785 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5787 head = new_reg_loc_descr (dwarf_fp, 0);
5788 add_loc_descr (&head, int_loc_descriptor (alignment));
5789 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5790 loc_descr_plus_const (&head, offset);
5793 head = new_reg_loc_descr (dwarf_fp, offset);
5797 /* This function fills in aa dw_cfa_location structure from a dwarf location
5798 descriptor sequence. */
5801 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5803 struct dw_loc_descr_struct *ptr;
5805 cfa->base_offset = 0;
5809 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5811 enum dwarf_location_atom op = ptr->dw_loc_opc;
5847 cfa->reg = op - DW_OP_reg0;
5850 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5884 cfa->reg = op - DW_OP_breg0;
5885 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5888 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5889 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5894 case DW_OP_plus_uconst:
5895 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5898 internal_error ("DW_LOC_OP %s not implemented",
5899 dwarf_stack_op_name (ptr->dw_loc_opc));
5904 /* And now, the support for symbolic debugging information. */
5906 /* .debug_str support. */
5907 static int output_indirect_string (void **, void *);
5909 static void dwarf2out_init (const char *);
5910 static void dwarf2out_finish (const char *);
5911 static void dwarf2out_assembly_start (void);
5912 static void dwarf2out_define (unsigned int, const char *);
5913 static void dwarf2out_undef (unsigned int, const char *);
5914 static void dwarf2out_start_source_file (unsigned, const char *);
5915 static void dwarf2out_end_source_file (unsigned);
5916 static void dwarf2out_function_decl (tree);
5917 static void dwarf2out_begin_block (unsigned, unsigned);
5918 static void dwarf2out_end_block (unsigned, unsigned);
5919 static bool dwarf2out_ignore_block (const_tree);
5920 static void dwarf2out_global_decl (tree);
5921 static void dwarf2out_type_decl (tree, int);
5922 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5923 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5925 static void dwarf2out_abstract_function (tree);
5926 static void dwarf2out_var_location (rtx);
5927 static void dwarf2out_begin_function (tree);
5928 static void dwarf2out_set_name (tree, tree);
5930 /* The debug hooks structure. */
5932 const struct gcc_debug_hooks dwarf2_debug_hooks =
5936 dwarf2out_assembly_start,
5939 dwarf2out_start_source_file,
5940 dwarf2out_end_source_file,
5941 dwarf2out_begin_block,
5942 dwarf2out_end_block,
5943 dwarf2out_ignore_block,
5944 dwarf2out_source_line,
5945 dwarf2out_begin_prologue,
5946 #if VMS_DEBUGGING_INFO
5947 dwarf2out_vms_end_prologue,
5948 dwarf2out_vms_begin_epilogue,
5950 debug_nothing_int_charstar,
5951 debug_nothing_int_charstar,
5953 dwarf2out_end_epilogue,
5954 dwarf2out_begin_function,
5955 debug_nothing_int, /* end_function */
5956 dwarf2out_function_decl, /* function_decl */
5957 dwarf2out_global_decl,
5958 dwarf2out_type_decl, /* type_decl */
5959 dwarf2out_imported_module_or_decl,
5960 debug_nothing_tree, /* deferred_inline_function */
5961 /* The DWARF 2 backend tries to reduce debugging bloat by not
5962 emitting the abstract description of inline functions until
5963 something tries to reference them. */
5964 dwarf2out_abstract_function, /* outlining_inline_function */
5965 debug_nothing_rtx, /* label */
5966 debug_nothing_int, /* handle_pch */
5967 dwarf2out_var_location,
5968 dwarf2out_switch_text_section,
5970 1, /* start_end_main_source_file */
5971 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5974 /* NOTE: In the comments in this file, many references are made to
5975 "Debugging Information Entries". This term is abbreviated as `DIE'
5976 throughout the remainder of this file. */
5978 /* An internal representation of the DWARF output is built, and then
5979 walked to generate the DWARF debugging info. The walk of the internal
5980 representation is done after the entire program has been compiled.
5981 The types below are used to describe the internal representation. */
5983 /* Whether to put type DIEs into their own section .debug_types instead
5984 of making them part of the .debug_info section. Only supported for
5985 Dwarf V4 or higher and the user didn't disable them through
5986 -fno-debug-types-section. It is more efficient to put them in a
5987 separate comdat sections since the linker will then be able to
5988 remove duplicates. But not all tools support .debug_types sections
5991 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
5993 /* Various DIE's use offsets relative to the beginning of the
5994 .debug_info section to refer to each other. */
5996 typedef long int dw_offset;
5998 /* Define typedefs here to avoid circular dependencies. */
6000 typedef struct dw_attr_struct *dw_attr_ref;
6001 typedef struct dw_line_info_struct *dw_line_info_ref;
6002 typedef struct pubname_struct *pubname_ref;
6003 typedef struct dw_ranges_struct *dw_ranges_ref;
6004 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
6005 typedef struct comdat_type_struct *comdat_type_node_ref;
6007 /* The entries in the line_info table more-or-less mirror the opcodes
6008 that are used in the real dwarf line table. Arrays of these entries
6009 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
6012 enum dw_line_info_opcode {
6013 /* Emit DW_LNE_set_address; the operand is the label index. */
6016 /* Emit a row to the matrix with the given line. This may be done
6017 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
6021 /* Emit a DW_LNS_set_file. */
6024 /* Emit a DW_LNS_set_column. */
6027 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
6030 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
6031 LI_set_prologue_end,
6032 LI_set_epilogue_begin,
6034 /* Emit a DW_LNE_set_discriminator. */
6035 LI_set_discriminator
6038 typedef struct GTY(()) dw_line_info_struct {
6039 enum dw_line_info_opcode opcode;
6041 } dw_line_info_entry;
6043 DEF_VEC_O(dw_line_info_entry);
6044 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
6046 typedef struct GTY(()) dw_line_info_table_struct {
6047 /* The label that marks the end of this section. */
6048 const char *end_label;
6050 /* The values for the last row of the matrix, as collected in the table.
6051 These are used to minimize the changes to the next row. */
6052 unsigned int file_num;
6053 unsigned int line_num;
6054 unsigned int column_num;
6059 VEC(dw_line_info_entry, gc) *entries;
6060 } dw_line_info_table;
6062 typedef dw_line_info_table *dw_line_info_table_p;
6064 DEF_VEC_P(dw_line_info_table_p);
6065 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
6067 /* Each DIE attribute has a field specifying the attribute kind,
6068 a link to the next attribute in the chain, and an attribute value.
6069 Attributes are typically linked below the DIE they modify. */
6071 typedef struct GTY(()) dw_attr_struct {
6072 enum dwarf_attribute dw_attr;
6073 dw_val_node dw_attr_val;
6077 DEF_VEC_O(dw_attr_node);
6078 DEF_VEC_ALLOC_O(dw_attr_node,gc);
6080 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
6081 The children of each node form a circular list linked by
6082 die_sib. die_child points to the node *before* the "first" child node. */
6084 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
6085 union die_symbol_or_type_node
6087 char * GTY ((tag ("0"))) die_symbol;
6088 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
6090 GTY ((desc ("use_debug_types"))) die_id;
6091 VEC(dw_attr_node,gc) * die_attr;
6092 dw_die_ref die_parent;
6093 dw_die_ref die_child;
6095 dw_die_ref die_definition; /* ref from a specification to its definition */
6096 dw_offset die_offset;
6097 unsigned long die_abbrev;
6099 /* Die is used and must not be pruned as unused. */
6100 int die_perennial_p;
6101 unsigned int decl_id;
6102 enum dwarf_tag die_tag;
6106 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
6107 #define FOR_EACH_CHILD(die, c, expr) do { \
6108 c = die->die_child; \
6112 } while (c != die->die_child); \
6115 /* The pubname structure */
6117 typedef struct GTY(()) pubname_struct {
6123 DEF_VEC_O(pubname_entry);
6124 DEF_VEC_ALLOC_O(pubname_entry, gc);
6126 struct GTY(()) dw_ranges_struct {
6127 /* If this is positive, it's a block number, otherwise it's a
6128 bitwise-negated index into dw_ranges_by_label. */
6132 /* A structure to hold a macinfo entry. */
6134 typedef struct GTY(()) macinfo_struct {
6135 unsigned HOST_WIDE_INT code;
6136 unsigned HOST_WIDE_INT lineno;
6141 DEF_VEC_O(macinfo_entry);
6142 DEF_VEC_ALLOC_O(macinfo_entry, gc);
6144 struct GTY(()) dw_ranges_by_label_struct {
6149 /* The comdat type node structure. */
6150 typedef struct GTY(()) comdat_type_struct
6152 dw_die_ref root_die;
6153 dw_die_ref type_die;
6154 char signature[DWARF_TYPE_SIGNATURE_SIZE];
6155 struct comdat_type_struct *next;
6159 /* The limbo die list structure. */
6160 typedef struct GTY(()) limbo_die_struct {
6163 struct limbo_die_struct *next;
6167 typedef struct skeleton_chain_struct
6171 struct skeleton_chain_struct *parent;
6173 skeleton_chain_node;
6175 /* How to start an assembler comment. */
6176 #ifndef ASM_COMMENT_START
6177 #define ASM_COMMENT_START ";#"
6180 /* Define a macro which returns nonzero for a TYPE_DECL which was
6181 implicitly generated for a tagged type.
6183 Note that unlike the gcc front end (which generates a NULL named
6184 TYPE_DECL node for each complete tagged type, each array type, and
6185 each function type node created) the g++ front end generates a
6186 _named_ TYPE_DECL node for each tagged type node created.
6187 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
6188 generate a DW_TAG_typedef DIE for them. */
6190 #define TYPE_DECL_IS_STUB(decl) \
6191 (DECL_NAME (decl) == NULL_TREE \
6192 || (DECL_ARTIFICIAL (decl) \
6193 && is_tagged_type (TREE_TYPE (decl)) \
6194 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
6195 /* This is necessary for stub decls that \
6196 appear in nested inline functions. */ \
6197 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6198 && (decl_ultimate_origin (decl) \
6199 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6201 /* Information concerning the compilation unit's programming
6202 language, and compiler version. */
6204 /* Fixed size portion of the DWARF compilation unit header. */
6205 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6206 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6208 /* Fixed size portion of the DWARF comdat type unit header. */
6209 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6210 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6211 + DWARF_OFFSET_SIZE)
6213 /* Fixed size portion of public names info. */
6214 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6216 /* Fixed size portion of the address range info. */
6217 #define DWARF_ARANGES_HEADER_SIZE \
6218 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6219 DWARF2_ADDR_SIZE * 2) \
6220 - DWARF_INITIAL_LENGTH_SIZE)
6222 /* Size of padding portion in the address range info. It must be
6223 aligned to twice the pointer size. */
6224 #define DWARF_ARANGES_PAD_SIZE \
6225 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6226 DWARF2_ADDR_SIZE * 2) \
6227 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6229 /* Use assembler line directives if available. */
6230 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6231 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6232 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6234 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6238 /* Minimum line offset in a special line info. opcode.
6239 This value was chosen to give a reasonable range of values. */
6240 #define DWARF_LINE_BASE -10
6242 /* First special line opcode - leave room for the standard opcodes. */
6243 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
6245 /* Range of line offsets in a special line info. opcode. */
6246 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6248 /* Flag that indicates the initial value of the is_stmt_start flag.
6249 In the present implementation, we do not mark any lines as
6250 the beginning of a source statement, because that information
6251 is not made available by the GCC front-end. */
6252 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6254 /* Maximum number of operations per instruction bundle. */
6255 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6256 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6259 /* This location is used by calc_die_sizes() to keep track
6260 the offset of each DIE within the .debug_info section. */
6261 static unsigned long next_die_offset;
6263 /* Record the root of the DIE's built for the current compilation unit. */
6264 static GTY(()) dw_die_ref single_comp_unit_die;
6266 /* A list of type DIEs that have been separated into comdat sections. */
6267 static GTY(()) comdat_type_node *comdat_type_list;
6269 /* A list of DIEs with a NULL parent waiting to be relocated. */
6270 static GTY(()) limbo_die_node *limbo_die_list;
6272 /* A list of DIEs for which we may have to generate
6273 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6274 static GTY(()) limbo_die_node *deferred_asm_name;
6276 /* Filenames referenced by this compilation unit. */
6277 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6279 /* A hash table of references to DIE's that describe declarations.
6280 The key is a DECL_UID() which is a unique number identifying each decl. */
6281 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6283 /* A hash table of references to DIE's that describe COMMON blocks.
6284 The key is DECL_UID() ^ die_parent. */
6285 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6287 typedef struct GTY(()) die_arg_entry_struct {
6292 DEF_VEC_O(die_arg_entry);
6293 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6295 /* Node of the variable location list. */
6296 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6297 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6298 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6299 in mode of the EXPR_LIST node and first EXPR_LIST operand
6300 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6301 location or NULL for padding. For larger bitsizes,
6302 mode is 0 and first operand is a CONCAT with bitsize
6303 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6304 NULL as second operand. */
6306 const char * GTY (()) label;
6307 struct var_loc_node * GTY (()) next;
6310 /* Variable location list. */
6311 struct GTY (()) var_loc_list_def {
6312 struct var_loc_node * GTY (()) first;
6314 /* Pointer to the last but one or last element of the
6315 chained list. If the list is empty, both first and
6316 last are NULL, if the list contains just one node
6317 or the last node certainly is not redundant, it points
6318 to the last node, otherwise points to the last but one.
6319 Do not mark it for GC because it is marked through the chain. */
6320 struct var_loc_node * GTY ((skip ("%h"))) last;
6322 /* Pointer to the last element before section switch,
6323 if NULL, either sections weren't switched or first
6324 is after section switch. */
6325 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
6327 /* DECL_UID of the variable decl. */
6328 unsigned int decl_id;
6330 typedef struct var_loc_list_def var_loc_list;
6332 /* Call argument location list. */
6333 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6334 rtx GTY (()) call_arg_loc_note;
6335 const char * GTY (()) label;
6336 tree GTY (()) block;
6338 rtx GTY (()) symbol_ref;
6339 struct call_arg_loc_node * GTY (()) next;
6343 /* Table of decl location linked lists. */
6344 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6346 /* Head and tail of call_arg_loc chain. */
6347 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6348 static struct call_arg_loc_node *call_arg_loc_last;
6350 /* Number of call sites in the current function. */
6351 static int call_site_count = -1;
6352 /* Number of tail call sites in the current function. */
6353 static int tail_call_site_count = -1;
6355 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6357 static VEC (dw_die_ref, heap) *block_map;
6359 /* A cached location list. */
6360 struct GTY (()) cached_dw_loc_list_def {
6361 /* The DECL_UID of the decl that this entry describes. */
6362 unsigned int decl_id;
6364 /* The cached location list. */
6365 dw_loc_list_ref loc_list;
6367 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
6369 /* Table of cached location lists. */
6370 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
6372 /* A pointer to the base of a list of references to DIE's that
6373 are uniquely identified by their tag, presence/absence of
6374 children DIE's, and list of attribute/value pairs. */
6375 static GTY((length ("abbrev_die_table_allocated")))
6376 dw_die_ref *abbrev_die_table;
6378 /* Number of elements currently allocated for abbrev_die_table. */
6379 static GTY(()) unsigned abbrev_die_table_allocated;
6381 /* Number of elements in type_die_table currently in use. */
6382 static GTY(()) unsigned abbrev_die_table_in_use;
6384 /* Size (in elements) of increments by which we may expand the
6385 abbrev_die_table. */
6386 #define ABBREV_DIE_TABLE_INCREMENT 256
6388 /* A global counter for generating labels for line number data. */
6389 static unsigned int line_info_label_num;
6391 /* The current table to which we should emit line number information
6392 for the current function. This will be set up at the beginning of
6393 assembly for the function. */
6394 static dw_line_info_table *cur_line_info_table;
6396 /* The two default tables of line number info. */
6397 static GTY(()) dw_line_info_table *text_section_line_info;
6398 static GTY(()) dw_line_info_table *cold_text_section_line_info;
6400 /* The set of all non-default tables of line number info. */
6401 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
6403 /* A flag to tell pubnames/types export if there is an info section to
6405 static bool info_section_emitted;
6407 /* A pointer to the base of a table that contains a list of publicly
6408 accessible names. */
6409 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6411 /* A pointer to the base of a table that contains a list of publicly
6412 accessible types. */
6413 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6415 /* A pointer to the base of a table that contains a list of macro
6416 defines/undefines (and file start/end markers). */
6417 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6419 /* Array of dies for which we should generate .debug_ranges info. */
6420 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6422 /* Number of elements currently allocated for ranges_table. */
6423 static GTY(()) unsigned ranges_table_allocated;
6425 /* Number of elements in ranges_table currently in use. */
6426 static GTY(()) unsigned ranges_table_in_use;
6428 /* Array of pairs of labels referenced in ranges_table. */
6429 static GTY ((length ("ranges_by_label_allocated")))
6430 dw_ranges_by_label_ref ranges_by_label;
6432 /* Number of elements currently allocated for ranges_by_label. */
6433 static GTY(()) unsigned ranges_by_label_allocated;
6435 /* Number of elements in ranges_by_label currently in use. */
6436 static GTY(()) unsigned ranges_by_label_in_use;
6438 /* Size (in elements) of increments by which we may expand the
6440 #define RANGES_TABLE_INCREMENT 64
6442 /* Whether we have location lists that need outputting */
6443 static GTY(()) bool have_location_lists;
6445 /* Unique label counter. */
6446 static GTY(()) unsigned int loclabel_num;
6448 /* Unique label counter for point-of-call tables. */
6449 static GTY(()) unsigned int poc_label_num;
6451 /* Record whether the function being analyzed contains inlined functions. */
6452 static int current_function_has_inlines;
6454 /* The last file entry emitted by maybe_emit_file(). */
6455 static GTY(()) struct dwarf_file_data * last_emitted_file;
6457 /* Number of internal labels generated by gen_internal_sym(). */
6458 static GTY(()) int label_num;
6460 /* Cached result of previous call to lookup_filename. */
6461 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6463 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6465 /* Instances of generic types for which we need to generate debug
6466 info that describe their generic parameters and arguments. That
6467 generation needs to happen once all types are properly laid out so
6468 we do it at the end of compilation. */
6469 static GTY(()) VEC(tree,gc) *generic_type_instances;
6471 /* Offset from the "steady-state frame pointer" to the frame base,
6472 within the current function. */
6473 static HOST_WIDE_INT frame_pointer_fb_offset;
6475 static VEC (dw_die_ref, heap) *base_types;
6477 /* Forward declarations for functions defined in this file. */
6479 static int is_pseudo_reg (const_rtx);
6480 static tree type_main_variant (tree);
6481 static int is_tagged_type (const_tree);
6482 static const char *dwarf_tag_name (unsigned);
6483 static const char *dwarf_attr_name (unsigned);
6484 static const char *dwarf_form_name (unsigned);
6485 static tree decl_ultimate_origin (const_tree);
6486 static tree decl_class_context (tree);
6487 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6488 static inline enum dw_val_class AT_class (dw_attr_ref);
6489 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6490 static inline unsigned AT_flag (dw_attr_ref);
6491 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6492 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6493 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6494 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6495 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6496 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6497 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6498 unsigned int, unsigned char *);
6499 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6500 static hashval_t debug_str_do_hash (const void *);
6501 static int debug_str_eq (const void *, const void *);
6502 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6503 static inline const char *AT_string (dw_attr_ref);
6504 static enum dwarf_form AT_string_form (dw_attr_ref);
6505 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6506 static void add_AT_specification (dw_die_ref, dw_die_ref);
6507 static inline dw_die_ref AT_ref (dw_attr_ref);
6508 static inline int AT_ref_external (dw_attr_ref);
6509 static inline void set_AT_ref_external (dw_attr_ref, int);
6510 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6511 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6512 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6513 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6515 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6516 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6517 static inline rtx AT_addr (dw_attr_ref);
6518 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6519 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6520 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6521 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6522 unsigned HOST_WIDE_INT);
6523 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6525 static inline const char *AT_lbl (dw_attr_ref);
6526 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6527 static const char *get_AT_low_pc (dw_die_ref);
6528 static const char *get_AT_hi_pc (dw_die_ref);
6529 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6530 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6531 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6532 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6533 static bool is_cxx (void);
6534 static bool is_fortran (void);
6535 static bool is_ada (void);
6536 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6537 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6538 static void add_child_die (dw_die_ref, dw_die_ref);
6539 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6540 static dw_die_ref lookup_type_die (tree);
6541 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6542 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6543 static void equate_type_number_to_die (tree, dw_die_ref);
6544 static hashval_t decl_die_table_hash (const void *);
6545 static int decl_die_table_eq (const void *, const void *);
6546 static dw_die_ref lookup_decl_die (tree);
6547 static hashval_t common_block_die_table_hash (const void *);
6548 static int common_block_die_table_eq (const void *, const void *);
6549 static hashval_t decl_loc_table_hash (const void *);
6550 static int decl_loc_table_eq (const void *, const void *);
6551 static var_loc_list *lookup_decl_loc (const_tree);
6552 static void equate_decl_number_to_die (tree, dw_die_ref);
6553 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6554 static void print_spaces (FILE *);
6555 static void print_die (dw_die_ref, FILE *);
6556 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6557 static dw_die_ref pop_compile_unit (dw_die_ref);
6558 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6559 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6560 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6561 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6562 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6563 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6564 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6565 struct md5_ctx *, int *);
6566 struct checksum_attributes;
6567 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6568 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6569 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6570 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6571 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6572 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6573 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6574 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6575 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6576 static void compute_section_prefix (dw_die_ref);
6577 static int is_type_die (dw_die_ref);
6578 static int is_comdat_die (dw_die_ref);
6579 static int is_symbol_die (dw_die_ref);
6580 static void assign_symbol_names (dw_die_ref);
6581 static void break_out_includes (dw_die_ref);
6582 static int is_declaration_die (dw_die_ref);
6583 static int should_move_die_to_comdat (dw_die_ref);
6584 static dw_die_ref clone_as_declaration (dw_die_ref);
6585 static dw_die_ref clone_die (dw_die_ref);
6586 static dw_die_ref clone_tree (dw_die_ref);
6587 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6588 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6589 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6590 static dw_die_ref generate_skeleton (dw_die_ref);
6591 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6593 static void break_out_comdat_types (dw_die_ref);
6594 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6595 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6596 static void copy_decls_for_unworthy_types (dw_die_ref);
6598 static hashval_t htab_cu_hash (const void *);
6599 static int htab_cu_eq (const void *, const void *);
6600 static void htab_cu_del (void *);
6601 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6602 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6603 static void add_sibling_attributes (dw_die_ref);
6604 static void build_abbrev_table (dw_die_ref);
6605 static void output_location_lists (dw_die_ref);
6606 static int constant_size (unsigned HOST_WIDE_INT);
6607 static unsigned long size_of_die (dw_die_ref);
6608 static void calc_die_sizes (dw_die_ref);
6609 static void calc_base_type_die_sizes (void);
6610 static void mark_dies (dw_die_ref);
6611 static void unmark_dies (dw_die_ref);
6612 static void unmark_all_dies (dw_die_ref);
6613 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6614 static unsigned long size_of_aranges (void);
6615 static enum dwarf_form value_format (dw_attr_ref);
6616 static void output_value_format (dw_attr_ref);
6617 static void output_abbrev_section (void);
6618 static void output_die_symbol (dw_die_ref);
6619 static void output_die (dw_die_ref);
6620 static void output_compilation_unit_header (void);
6621 static void output_comp_unit (dw_die_ref, int);
6622 static void output_comdat_type_unit (comdat_type_node *);
6623 static const char *dwarf2_name (tree, int);
6624 static void add_pubname (tree, dw_die_ref);
6625 static void add_pubname_string (const char *, dw_die_ref);
6626 static void add_pubtype (tree, dw_die_ref);
6627 static void output_pubnames (VEC (pubname_entry,gc) *);
6628 static void output_aranges (unsigned long);
6629 static unsigned int add_ranges_num (int);
6630 static unsigned int add_ranges (const_tree);
6631 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6633 static void output_ranges (void);
6634 static dw_line_info_table *new_line_info_table (void);
6635 static void output_line_info (void);
6636 static void output_file_names (void);
6637 static dw_die_ref base_type_die (tree);
6638 static int is_base_type (tree);
6639 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6640 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6641 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6642 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6643 static int type_is_enum (const_tree);
6644 static unsigned int dbx_reg_number (const_rtx);
6645 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6646 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6647 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6648 enum var_init_status);
6649 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6650 enum var_init_status);
6651 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6652 enum var_init_status);
6653 static int is_based_loc (const_rtx);
6654 static int resolve_one_addr (rtx *, void *);
6655 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6656 enum var_init_status);
6657 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6658 enum var_init_status);
6659 static dw_loc_list_ref loc_list_from_tree (tree, int);
6660 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6661 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6662 static tree field_type (const_tree);
6663 static unsigned int simple_type_align_in_bits (const_tree);
6664 static unsigned int simple_decl_align_in_bits (const_tree);
6665 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6666 static HOST_WIDE_INT field_byte_offset (const_tree);
6667 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6669 static void add_data_member_location_attribute (dw_die_ref, tree);
6670 static bool add_const_value_attribute (dw_die_ref, rtx);
6671 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6672 static void insert_double (double_int, unsigned char *);
6673 static void insert_float (const_rtx, unsigned char *);
6674 static rtx rtl_for_decl_location (tree);
6675 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
6676 enum dwarf_attribute);
6677 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6678 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6679 static void add_name_attribute (dw_die_ref, const char *);
6680 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
6681 static void add_comp_dir_attribute (dw_die_ref);
6682 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6683 static void add_subscript_info (dw_die_ref, tree, bool);
6684 static void add_byte_size_attribute (dw_die_ref, tree);
6685 static void add_bit_offset_attribute (dw_die_ref, tree);
6686 static void add_bit_size_attribute (dw_die_ref, tree);
6687 static void add_prototyped_attribute (dw_die_ref, tree);
6688 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6689 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6690 static void add_src_coords_attributes (dw_die_ref, tree);
6691 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6692 static void push_decl_scope (tree);
6693 static void pop_decl_scope (void);
6694 static dw_die_ref scope_die_for (tree, dw_die_ref);
6695 static inline int local_scope_p (dw_die_ref);
6696 static inline int class_scope_p (dw_die_ref);
6697 static inline int class_or_namespace_scope_p (dw_die_ref);
6698 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6699 static void add_calling_convention_attribute (dw_die_ref, tree);
6700 static const char *type_tag (const_tree);
6701 static tree member_declared_type (const_tree);
6703 static const char *decl_start_label (tree);
6705 static void gen_array_type_die (tree, dw_die_ref);
6706 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6708 static void gen_entry_point_die (tree, dw_die_ref);
6710 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6711 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6712 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6713 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6714 static void gen_formal_types_die (tree, dw_die_ref);
6715 static void gen_subprogram_die (tree, dw_die_ref);
6716 static void gen_variable_die (tree, tree, dw_die_ref);
6717 static void gen_const_die (tree, dw_die_ref);
6718 static void gen_label_die (tree, dw_die_ref);
6719 static void gen_lexical_block_die (tree, dw_die_ref, int);
6720 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6721 static void gen_field_die (tree, dw_die_ref);
6722 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6723 static dw_die_ref gen_compile_unit_die (const char *);
6724 static void gen_inheritance_die (tree, tree, dw_die_ref);
6725 static void gen_member_die (tree, dw_die_ref);
6726 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6727 enum debug_info_usage);
6728 static void gen_subroutine_type_die (tree, dw_die_ref);
6729 static void gen_typedef_die (tree, dw_die_ref);
6730 static void gen_type_die (tree, dw_die_ref);
6731 static void gen_block_die (tree, dw_die_ref, int);
6732 static void decls_for_scope (tree, dw_die_ref, int);
6733 static inline int is_redundant_typedef (const_tree);
6734 static bool is_naming_typedef_decl (const_tree);
6735 static inline dw_die_ref get_context_die (tree);
6736 static void gen_namespace_die (tree, dw_die_ref);
6737 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6738 static dw_die_ref force_decl_die (tree);
6739 static dw_die_ref force_type_die (tree);
6740 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6741 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6742 static struct dwarf_file_data * lookup_filename (const char *);
6743 static void retry_incomplete_types (void);
6744 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6745 static void gen_generic_params_dies (tree);
6746 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6747 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6748 static void splice_child_die (dw_die_ref, dw_die_ref);
6749 static int file_info_cmp (const void *, const void *);
6750 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6751 const char *, const char *);
6752 static void output_loc_list (dw_loc_list_ref);
6753 static char *gen_internal_sym (const char *);
6755 static void prune_unmark_dies (dw_die_ref);
6756 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6757 static void prune_unused_types_mark (dw_die_ref, int);
6758 static void prune_unused_types_walk (dw_die_ref);
6759 static void prune_unused_types_walk_attribs (dw_die_ref);
6760 static void prune_unused_types_prune (dw_die_ref);
6761 static void prune_unused_types (void);
6762 static int maybe_emit_file (struct dwarf_file_data *fd);
6763 static inline const char *AT_vms_delta1 (dw_attr_ref);
6764 static inline const char *AT_vms_delta2 (dw_attr_ref);
6765 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6766 const char *, const char *);
6767 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6768 static void gen_remaining_tmpl_value_param_die_attribute (void);
6769 static bool generic_type_p (tree);
6770 static void schedule_generic_params_dies_gen (tree t);
6771 static void gen_scheduled_generic_parms_dies (void);
6773 /* Section names used to hold DWARF debugging information. */
6774 #ifndef DEBUG_INFO_SECTION
6775 #define DEBUG_INFO_SECTION ".debug_info"
6777 #ifndef DEBUG_ABBREV_SECTION
6778 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6780 #ifndef DEBUG_ARANGES_SECTION
6781 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6783 #ifndef DEBUG_MACINFO_SECTION
6784 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6786 #ifndef DEBUG_LINE_SECTION
6787 #define DEBUG_LINE_SECTION ".debug_line"
6789 #ifndef DEBUG_LOC_SECTION
6790 #define DEBUG_LOC_SECTION ".debug_loc"
6792 #ifndef DEBUG_PUBNAMES_SECTION
6793 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6795 #ifndef DEBUG_PUBTYPES_SECTION
6796 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6798 #ifndef DEBUG_STR_SECTION
6799 #define DEBUG_STR_SECTION ".debug_str"
6801 #ifndef DEBUG_RANGES_SECTION
6802 #define DEBUG_RANGES_SECTION ".debug_ranges"
6805 /* Standard ELF section names for compiled code and data. */
6806 #ifndef TEXT_SECTION_NAME
6807 #define TEXT_SECTION_NAME ".text"
6810 /* Section flags for .debug_str section. */
6811 #define DEBUG_STR_SECTION_FLAGS \
6812 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6813 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6816 /* Labels we insert at beginning sections we can reference instead of
6817 the section names themselves. */
6819 #ifndef TEXT_SECTION_LABEL
6820 #define TEXT_SECTION_LABEL "Ltext"
6822 #ifndef COLD_TEXT_SECTION_LABEL
6823 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6825 #ifndef DEBUG_LINE_SECTION_LABEL
6826 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6828 #ifndef DEBUG_INFO_SECTION_LABEL
6829 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6831 #ifndef DEBUG_ABBREV_SECTION_LABEL
6832 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6834 #ifndef DEBUG_LOC_SECTION_LABEL
6835 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6837 #ifndef DEBUG_RANGES_SECTION_LABEL
6838 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6840 #ifndef DEBUG_MACINFO_SECTION_LABEL
6841 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6845 /* Definitions of defaults for formats and names of various special
6846 (artificial) labels which may be generated within this file (when the -g
6847 options is used and DWARF2_DEBUGGING_INFO is in effect.
6848 If necessary, these may be overridden from within the tm.h file, but
6849 typically, overriding these defaults is unnecessary. */
6851 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6852 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6853 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6854 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6855 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6856 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6857 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6858 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6859 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6860 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6862 #ifndef TEXT_END_LABEL
6863 #define TEXT_END_LABEL "Letext"
6865 #ifndef COLD_END_LABEL
6866 #define COLD_END_LABEL "Letext_cold"
6868 #ifndef BLOCK_BEGIN_LABEL
6869 #define BLOCK_BEGIN_LABEL "LBB"
6871 #ifndef BLOCK_END_LABEL
6872 #define BLOCK_END_LABEL "LBE"
6874 #ifndef LINE_CODE_LABEL
6875 #define LINE_CODE_LABEL "LM"
6879 /* Return the root of the DIE's built for the current compilation unit. */
6881 comp_unit_die (void)
6883 if (!single_comp_unit_die)
6884 single_comp_unit_die = gen_compile_unit_die (NULL);
6885 return single_comp_unit_die;
6888 /* We allow a language front-end to designate a function that is to be
6889 called to "demangle" any name before it is put into a DIE. */
6891 static const char *(*demangle_name_func) (const char *);
6894 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6896 demangle_name_func = func;
6899 /* Test if rtl node points to a pseudo register. */
6902 is_pseudo_reg (const_rtx rtl)
6904 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6905 || (GET_CODE (rtl) == SUBREG
6906 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6909 /* Return a reference to a type, with its const and volatile qualifiers
6913 type_main_variant (tree type)
6915 type = TYPE_MAIN_VARIANT (type);
6917 /* ??? There really should be only one main variant among any group of
6918 variants of a given type (and all of the MAIN_VARIANT values for all
6919 members of the group should point to that one type) but sometimes the C
6920 front-end messes this up for array types, so we work around that bug
6922 if (TREE_CODE (type) == ARRAY_TYPE)
6923 while (type != TYPE_MAIN_VARIANT (type))
6924 type = TYPE_MAIN_VARIANT (type);
6929 /* Return nonzero if the given type node represents a tagged type. */
6932 is_tagged_type (const_tree type)
6934 enum tree_code code = TREE_CODE (type);
6936 return (code == RECORD_TYPE || code == UNION_TYPE
6937 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6940 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6943 get_ref_die_offset_label (char *label, dw_die_ref ref)
6945 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6948 /* Return die_offset of a DIE reference to a base type. */
6950 static unsigned long int
6951 get_base_type_offset (dw_die_ref ref)
6953 if (ref->die_offset)
6954 return ref->die_offset;
6955 if (comp_unit_die ()->die_abbrev)
6957 calc_base_type_die_sizes ();
6958 gcc_assert (ref->die_offset);
6960 return ref->die_offset;
6963 /* Convert a DIE tag into its string name. */
6966 dwarf_tag_name (unsigned int tag)
6970 case DW_TAG_padding:
6971 return "DW_TAG_padding";
6972 case DW_TAG_array_type:
6973 return "DW_TAG_array_type";
6974 case DW_TAG_class_type:
6975 return "DW_TAG_class_type";
6976 case DW_TAG_entry_point:
6977 return "DW_TAG_entry_point";
6978 case DW_TAG_enumeration_type:
6979 return "DW_TAG_enumeration_type";
6980 case DW_TAG_formal_parameter:
6981 return "DW_TAG_formal_parameter";
6982 case DW_TAG_imported_declaration:
6983 return "DW_TAG_imported_declaration";
6985 return "DW_TAG_label";
6986 case DW_TAG_lexical_block:
6987 return "DW_TAG_lexical_block";
6989 return "DW_TAG_member";
6990 case DW_TAG_pointer_type:
6991 return "DW_TAG_pointer_type";
6992 case DW_TAG_reference_type:
6993 return "DW_TAG_reference_type";
6994 case DW_TAG_compile_unit:
6995 return "DW_TAG_compile_unit";
6996 case DW_TAG_string_type:
6997 return "DW_TAG_string_type";
6998 case DW_TAG_structure_type:
6999 return "DW_TAG_structure_type";
7000 case DW_TAG_subroutine_type:
7001 return "DW_TAG_subroutine_type";
7002 case DW_TAG_typedef:
7003 return "DW_TAG_typedef";
7004 case DW_TAG_union_type:
7005 return "DW_TAG_union_type";
7006 case DW_TAG_unspecified_parameters:
7007 return "DW_TAG_unspecified_parameters";
7008 case DW_TAG_variant:
7009 return "DW_TAG_variant";
7010 case DW_TAG_common_block:
7011 return "DW_TAG_common_block";
7012 case DW_TAG_common_inclusion:
7013 return "DW_TAG_common_inclusion";
7014 case DW_TAG_inheritance:
7015 return "DW_TAG_inheritance";
7016 case DW_TAG_inlined_subroutine:
7017 return "DW_TAG_inlined_subroutine";
7019 return "DW_TAG_module";
7020 case DW_TAG_ptr_to_member_type:
7021 return "DW_TAG_ptr_to_member_type";
7022 case DW_TAG_set_type:
7023 return "DW_TAG_set_type";
7024 case DW_TAG_subrange_type:
7025 return "DW_TAG_subrange_type";
7026 case DW_TAG_with_stmt:
7027 return "DW_TAG_with_stmt";
7028 case DW_TAG_access_declaration:
7029 return "DW_TAG_access_declaration";
7030 case DW_TAG_base_type:
7031 return "DW_TAG_base_type";
7032 case DW_TAG_catch_block:
7033 return "DW_TAG_catch_block";
7034 case DW_TAG_const_type:
7035 return "DW_TAG_const_type";
7036 case DW_TAG_constant:
7037 return "DW_TAG_constant";
7038 case DW_TAG_enumerator:
7039 return "DW_TAG_enumerator";
7040 case DW_TAG_file_type:
7041 return "DW_TAG_file_type";
7043 return "DW_TAG_friend";
7044 case DW_TAG_namelist:
7045 return "DW_TAG_namelist";
7046 case DW_TAG_namelist_item:
7047 return "DW_TAG_namelist_item";
7048 case DW_TAG_packed_type:
7049 return "DW_TAG_packed_type";
7050 case DW_TAG_subprogram:
7051 return "DW_TAG_subprogram";
7052 case DW_TAG_template_type_param:
7053 return "DW_TAG_template_type_param";
7054 case DW_TAG_template_value_param:
7055 return "DW_TAG_template_value_param";
7056 case DW_TAG_thrown_type:
7057 return "DW_TAG_thrown_type";
7058 case DW_TAG_try_block:
7059 return "DW_TAG_try_block";
7060 case DW_TAG_variant_part:
7061 return "DW_TAG_variant_part";
7062 case DW_TAG_variable:
7063 return "DW_TAG_variable";
7064 case DW_TAG_volatile_type:
7065 return "DW_TAG_volatile_type";
7066 case DW_TAG_dwarf_procedure:
7067 return "DW_TAG_dwarf_procedure";
7068 case DW_TAG_restrict_type:
7069 return "DW_TAG_restrict_type";
7070 case DW_TAG_interface_type:
7071 return "DW_TAG_interface_type";
7072 case DW_TAG_namespace:
7073 return "DW_TAG_namespace";
7074 case DW_TAG_imported_module:
7075 return "DW_TAG_imported_module";
7076 case DW_TAG_unspecified_type:
7077 return "DW_TAG_unspecified_type";
7078 case DW_TAG_partial_unit:
7079 return "DW_TAG_partial_unit";
7080 case DW_TAG_imported_unit:
7081 return "DW_TAG_imported_unit";
7082 case DW_TAG_condition:
7083 return "DW_TAG_condition";
7084 case DW_TAG_shared_type:
7085 return "DW_TAG_shared_type";
7086 case DW_TAG_type_unit:
7087 return "DW_TAG_type_unit";
7088 case DW_TAG_rvalue_reference_type:
7089 return "DW_TAG_rvalue_reference_type";
7090 case DW_TAG_template_alias:
7091 return "DW_TAG_template_alias";
7092 case DW_TAG_GNU_template_parameter_pack:
7093 return "DW_TAG_GNU_template_parameter_pack";
7094 case DW_TAG_GNU_formal_parameter_pack:
7095 return "DW_TAG_GNU_formal_parameter_pack";
7096 case DW_TAG_MIPS_loop:
7097 return "DW_TAG_MIPS_loop";
7098 case DW_TAG_format_label:
7099 return "DW_TAG_format_label";
7100 case DW_TAG_function_template:
7101 return "DW_TAG_function_template";
7102 case DW_TAG_class_template:
7103 return "DW_TAG_class_template";
7104 case DW_TAG_GNU_BINCL:
7105 return "DW_TAG_GNU_BINCL";
7106 case DW_TAG_GNU_EINCL:
7107 return "DW_TAG_GNU_EINCL";
7108 case DW_TAG_GNU_template_template_param:
7109 return "DW_TAG_GNU_template_template_param";
7110 case DW_TAG_GNU_call_site:
7111 return "DW_TAG_GNU_call_site";
7112 case DW_TAG_GNU_call_site_parameter:
7113 return "DW_TAG_GNU_call_site_parameter";
7115 return "DW_TAG_<unknown>";
7119 /* Convert a DWARF attribute code into its string name. */
7122 dwarf_attr_name (unsigned int attr)
7127 return "DW_AT_sibling";
7128 case DW_AT_location:
7129 return "DW_AT_location";
7131 return "DW_AT_name";
7132 case DW_AT_ordering:
7133 return "DW_AT_ordering";
7134 case DW_AT_subscr_data:
7135 return "DW_AT_subscr_data";
7136 case DW_AT_byte_size:
7137 return "DW_AT_byte_size";
7138 case DW_AT_bit_offset:
7139 return "DW_AT_bit_offset";
7140 case DW_AT_bit_size:
7141 return "DW_AT_bit_size";
7142 case DW_AT_element_list:
7143 return "DW_AT_element_list";
7144 case DW_AT_stmt_list:
7145 return "DW_AT_stmt_list";
7147 return "DW_AT_low_pc";
7149 return "DW_AT_high_pc";
7150 case DW_AT_language:
7151 return "DW_AT_language";
7153 return "DW_AT_member";
7155 return "DW_AT_discr";
7156 case DW_AT_discr_value:
7157 return "DW_AT_discr_value";
7158 case DW_AT_visibility:
7159 return "DW_AT_visibility";
7161 return "DW_AT_import";
7162 case DW_AT_string_length:
7163 return "DW_AT_string_length";
7164 case DW_AT_common_reference:
7165 return "DW_AT_common_reference";
7166 case DW_AT_comp_dir:
7167 return "DW_AT_comp_dir";
7168 case DW_AT_const_value:
7169 return "DW_AT_const_value";
7170 case DW_AT_containing_type:
7171 return "DW_AT_containing_type";
7172 case DW_AT_default_value:
7173 return "DW_AT_default_value";
7175 return "DW_AT_inline";
7176 case DW_AT_is_optional:
7177 return "DW_AT_is_optional";
7178 case DW_AT_lower_bound:
7179 return "DW_AT_lower_bound";
7180 case DW_AT_producer:
7181 return "DW_AT_producer";
7182 case DW_AT_prototyped:
7183 return "DW_AT_prototyped";
7184 case DW_AT_return_addr:
7185 return "DW_AT_return_addr";
7186 case DW_AT_start_scope:
7187 return "DW_AT_start_scope";
7188 case DW_AT_bit_stride:
7189 return "DW_AT_bit_stride";
7190 case DW_AT_upper_bound:
7191 return "DW_AT_upper_bound";
7192 case DW_AT_abstract_origin:
7193 return "DW_AT_abstract_origin";
7194 case DW_AT_accessibility:
7195 return "DW_AT_accessibility";
7196 case DW_AT_address_class:
7197 return "DW_AT_address_class";
7198 case DW_AT_artificial:
7199 return "DW_AT_artificial";
7200 case DW_AT_base_types:
7201 return "DW_AT_base_types";
7202 case DW_AT_calling_convention:
7203 return "DW_AT_calling_convention";
7205 return "DW_AT_count";
7206 case DW_AT_data_member_location:
7207 return "DW_AT_data_member_location";
7208 case DW_AT_decl_column:
7209 return "DW_AT_decl_column";
7210 case DW_AT_decl_file:
7211 return "DW_AT_decl_file";
7212 case DW_AT_decl_line:
7213 return "DW_AT_decl_line";
7214 case DW_AT_declaration:
7215 return "DW_AT_declaration";
7216 case DW_AT_discr_list:
7217 return "DW_AT_discr_list";
7218 case DW_AT_encoding:
7219 return "DW_AT_encoding";
7220 case DW_AT_external:
7221 return "DW_AT_external";
7222 case DW_AT_explicit:
7223 return "DW_AT_explicit";
7224 case DW_AT_frame_base:
7225 return "DW_AT_frame_base";
7227 return "DW_AT_friend";
7228 case DW_AT_identifier_case:
7229 return "DW_AT_identifier_case";
7230 case DW_AT_macro_info:
7231 return "DW_AT_macro_info";
7232 case DW_AT_namelist_items:
7233 return "DW_AT_namelist_items";
7234 case DW_AT_priority:
7235 return "DW_AT_priority";
7237 return "DW_AT_segment";
7238 case DW_AT_specification:
7239 return "DW_AT_specification";
7240 case DW_AT_static_link:
7241 return "DW_AT_static_link";
7243 return "DW_AT_type";
7244 case DW_AT_use_location:
7245 return "DW_AT_use_location";
7246 case DW_AT_variable_parameter:
7247 return "DW_AT_variable_parameter";
7248 case DW_AT_virtuality:
7249 return "DW_AT_virtuality";
7250 case DW_AT_vtable_elem_location:
7251 return "DW_AT_vtable_elem_location";
7253 case DW_AT_allocated:
7254 return "DW_AT_allocated";
7255 case DW_AT_associated:
7256 return "DW_AT_associated";
7257 case DW_AT_data_location:
7258 return "DW_AT_data_location";
7259 case DW_AT_byte_stride:
7260 return "DW_AT_byte_stride";
7261 case DW_AT_entry_pc:
7262 return "DW_AT_entry_pc";
7263 case DW_AT_use_UTF8:
7264 return "DW_AT_use_UTF8";
7265 case DW_AT_extension:
7266 return "DW_AT_extension";
7268 return "DW_AT_ranges";
7269 case DW_AT_trampoline:
7270 return "DW_AT_trampoline";
7271 case DW_AT_call_column:
7272 return "DW_AT_call_column";
7273 case DW_AT_call_file:
7274 return "DW_AT_call_file";
7275 case DW_AT_call_line:
7276 return "DW_AT_call_line";
7277 case DW_AT_object_pointer:
7278 return "DW_AT_object_pointer";
7280 case DW_AT_signature:
7281 return "DW_AT_signature";
7282 case DW_AT_main_subprogram:
7283 return "DW_AT_main_subprogram";
7284 case DW_AT_data_bit_offset:
7285 return "DW_AT_data_bit_offset";
7286 case DW_AT_const_expr:
7287 return "DW_AT_const_expr";
7288 case DW_AT_enum_class:
7289 return "DW_AT_enum_class";
7290 case DW_AT_linkage_name:
7291 return "DW_AT_linkage_name";
7293 case DW_AT_MIPS_fde:
7294 return "DW_AT_MIPS_fde";
7295 case DW_AT_MIPS_loop_begin:
7296 return "DW_AT_MIPS_loop_begin";
7297 case DW_AT_MIPS_tail_loop_begin:
7298 return "DW_AT_MIPS_tail_loop_begin";
7299 case DW_AT_MIPS_epilog_begin:
7300 return "DW_AT_MIPS_epilog_begin";
7301 #if VMS_DEBUGGING_INFO
7302 case DW_AT_HP_prologue:
7303 return "DW_AT_HP_prologue";
7305 case DW_AT_MIPS_loop_unroll_factor:
7306 return "DW_AT_MIPS_loop_unroll_factor";
7308 case DW_AT_MIPS_software_pipeline_depth:
7309 return "DW_AT_MIPS_software_pipeline_depth";
7310 case DW_AT_MIPS_linkage_name:
7311 return "DW_AT_MIPS_linkage_name";
7312 #if VMS_DEBUGGING_INFO
7313 case DW_AT_HP_epilogue:
7314 return "DW_AT_HP_epilogue";
7316 case DW_AT_MIPS_stride:
7317 return "DW_AT_MIPS_stride";
7319 case DW_AT_MIPS_abstract_name:
7320 return "DW_AT_MIPS_abstract_name";
7321 case DW_AT_MIPS_clone_origin:
7322 return "DW_AT_MIPS_clone_origin";
7323 case DW_AT_MIPS_has_inlines:
7324 return "DW_AT_MIPS_has_inlines";
7326 case DW_AT_sf_names:
7327 return "DW_AT_sf_names";
7328 case DW_AT_src_info:
7329 return "DW_AT_src_info";
7330 case DW_AT_mac_info:
7331 return "DW_AT_mac_info";
7332 case DW_AT_src_coords:
7333 return "DW_AT_src_coords";
7334 case DW_AT_body_begin:
7335 return "DW_AT_body_begin";
7336 case DW_AT_body_end:
7337 return "DW_AT_body_end";
7339 case DW_AT_GNU_vector:
7340 return "DW_AT_GNU_vector";
7341 case DW_AT_GNU_guarded_by:
7342 return "DW_AT_GNU_guarded_by";
7343 case DW_AT_GNU_pt_guarded_by:
7344 return "DW_AT_GNU_pt_guarded_by";
7345 case DW_AT_GNU_guarded:
7346 return "DW_AT_GNU_guarded";
7347 case DW_AT_GNU_pt_guarded:
7348 return "DW_AT_GNU_pt_guarded";
7349 case DW_AT_GNU_locks_excluded:
7350 return "DW_AT_GNU_locks_excluded";
7351 case DW_AT_GNU_exclusive_locks_required:
7352 return "DW_AT_GNU_exclusive_locks_required";
7353 case DW_AT_GNU_shared_locks_required:
7354 return "DW_AT_GNU_shared_locks_required";
7355 case DW_AT_GNU_odr_signature:
7356 return "DW_AT_GNU_odr_signature";
7357 case DW_AT_GNU_template_name:
7358 return "DW_AT_GNU_template_name";
7359 case DW_AT_GNU_call_site_value:
7360 return "DW_AT_GNU_call_site_value";
7361 case DW_AT_GNU_call_site_data_value:
7362 return "DW_AT_GNU_call_site_data_value";
7363 case DW_AT_GNU_call_site_target:
7364 return "DW_AT_GNU_call_site_target";
7365 case DW_AT_GNU_call_site_target_clobbered:
7366 return "DW_AT_GNU_call_site_target_clobbered";
7367 case DW_AT_GNU_tail_call:
7368 return "DW_AT_GNU_tail_call";
7369 case DW_AT_GNU_all_tail_call_sites:
7370 return "DW_AT_GNU_all_tail_call_sites";
7371 case DW_AT_GNU_all_call_sites:
7372 return "DW_AT_GNU_all_call_sites";
7373 case DW_AT_GNU_all_source_call_sites:
7374 return "DW_AT_GNU_all_source_call_sites";
7376 case DW_AT_GNAT_descriptive_type:
7377 return "DW_AT_GNAT_descriptive_type";
7379 case DW_AT_VMS_rtnbeg_pd_address:
7380 return "DW_AT_VMS_rtnbeg_pd_address";
7383 return "DW_AT_<unknown>";
7387 /* Convert a DWARF value form code into its string name. */
7390 dwarf_form_name (unsigned int form)
7395 return "DW_FORM_addr";
7396 case DW_FORM_block2:
7397 return "DW_FORM_block2";
7398 case DW_FORM_block4:
7399 return "DW_FORM_block4";
7401 return "DW_FORM_data2";
7403 return "DW_FORM_data4";
7405 return "DW_FORM_data8";
7406 case DW_FORM_string:
7407 return "DW_FORM_string";
7409 return "DW_FORM_block";
7410 case DW_FORM_block1:
7411 return "DW_FORM_block1";
7413 return "DW_FORM_data1";
7415 return "DW_FORM_flag";
7417 return "DW_FORM_sdata";
7419 return "DW_FORM_strp";
7421 return "DW_FORM_udata";
7422 case DW_FORM_ref_addr:
7423 return "DW_FORM_ref_addr";
7425 return "DW_FORM_ref1";
7427 return "DW_FORM_ref2";
7429 return "DW_FORM_ref4";
7431 return "DW_FORM_ref8";
7432 case DW_FORM_ref_udata:
7433 return "DW_FORM_ref_udata";
7434 case DW_FORM_indirect:
7435 return "DW_FORM_indirect";
7436 case DW_FORM_sec_offset:
7437 return "DW_FORM_sec_offset";
7438 case DW_FORM_exprloc:
7439 return "DW_FORM_exprloc";
7440 case DW_FORM_flag_present:
7441 return "DW_FORM_flag_present";
7442 case DW_FORM_ref_sig8:
7443 return "DW_FORM_ref_sig8";
7445 return "DW_FORM_<unknown>";
7449 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7450 instance of an inlined instance of a decl which is local to an inline
7451 function, so we have to trace all of the way back through the origin chain
7452 to find out what sort of node actually served as the original seed for the
7456 decl_ultimate_origin (const_tree decl)
7458 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7461 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7462 nodes in the function to point to themselves; ignore that if
7463 we're trying to output the abstract instance of this function. */
7464 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7467 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7468 most distant ancestor, this should never happen. */
7469 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7471 return DECL_ABSTRACT_ORIGIN (decl);
7474 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7475 of a virtual function may refer to a base class, so we check the 'this'
7479 decl_class_context (tree decl)
7481 tree context = NULL_TREE;
7483 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7484 context = DECL_CONTEXT (decl);
7486 context = TYPE_MAIN_VARIANT
7487 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7489 if (context && !TYPE_P (context))
7490 context = NULL_TREE;
7495 /* Add an attribute/value pair to a DIE. */
7498 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7500 /* Maybe this should be an assert? */
7504 if (die->die_attr == NULL)
7505 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7506 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7509 static inline enum dw_val_class
7510 AT_class (dw_attr_ref a)
7512 return a->dw_attr_val.val_class;
7515 /* Add a flag value attribute to a DIE. */
7518 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7522 attr.dw_attr = attr_kind;
7523 attr.dw_attr_val.val_class = dw_val_class_flag;
7524 attr.dw_attr_val.v.val_flag = flag;
7525 add_dwarf_attr (die, &attr);
7528 static inline unsigned
7529 AT_flag (dw_attr_ref a)
7531 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7532 return a->dw_attr_val.v.val_flag;
7535 /* Add a signed integer attribute value to a DIE. */
7538 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7542 attr.dw_attr = attr_kind;
7543 attr.dw_attr_val.val_class = dw_val_class_const;
7544 attr.dw_attr_val.v.val_int = int_val;
7545 add_dwarf_attr (die, &attr);
7548 static inline HOST_WIDE_INT
7549 AT_int (dw_attr_ref a)
7551 gcc_assert (a && AT_class (a) == dw_val_class_const);
7552 return a->dw_attr_val.v.val_int;
7555 /* Add an unsigned integer attribute value to a DIE. */
7558 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7559 unsigned HOST_WIDE_INT unsigned_val)
7563 attr.dw_attr = attr_kind;
7564 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7565 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7566 add_dwarf_attr (die, &attr);
7569 static inline unsigned HOST_WIDE_INT
7570 AT_unsigned (dw_attr_ref a)
7572 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7573 return a->dw_attr_val.v.val_unsigned;
7576 /* Add an unsigned double integer attribute value to a DIE. */
7579 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7580 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7584 attr.dw_attr = attr_kind;
7585 attr.dw_attr_val.val_class = dw_val_class_const_double;
7586 attr.dw_attr_val.v.val_double.high = high;
7587 attr.dw_attr_val.v.val_double.low = low;
7588 add_dwarf_attr (die, &attr);
7591 /* Add a floating point attribute value to a DIE and return it. */
7594 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7595 unsigned int length, unsigned int elt_size, unsigned char *array)
7599 attr.dw_attr = attr_kind;
7600 attr.dw_attr_val.val_class = dw_val_class_vec;
7601 attr.dw_attr_val.v.val_vec.length = length;
7602 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7603 attr.dw_attr_val.v.val_vec.array = array;
7604 add_dwarf_attr (die, &attr);
7607 /* Add an 8-byte data attribute value to a DIE. */
7610 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7611 unsigned char data8[8])
7615 attr.dw_attr = attr_kind;
7616 attr.dw_attr_val.val_class = dw_val_class_data8;
7617 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7618 add_dwarf_attr (die, &attr);
7621 /* Hash and equality functions for debug_str_hash. */
7624 debug_str_do_hash (const void *x)
7626 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7630 debug_str_eq (const void *x1, const void *x2)
7632 return strcmp ((((const struct indirect_string_node *)x1)->str),
7633 (const char *)x2) == 0;
7636 /* Add STR to the indirect string hash table. */
7638 static struct indirect_string_node *
7639 find_AT_string (const char *str)
7641 struct indirect_string_node *node;
7644 if (! debug_str_hash)
7645 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7646 debug_str_eq, NULL);
7648 slot = htab_find_slot_with_hash (debug_str_hash, str,
7649 htab_hash_string (str), INSERT);
7652 node = ggc_alloc_cleared_indirect_string_node ();
7653 node->str = ggc_strdup (str);
7657 node = (struct indirect_string_node *) *slot;
7663 /* Add a string attribute value to a DIE. */
7666 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7669 struct indirect_string_node *node;
7671 node = find_AT_string (str);
7673 attr.dw_attr = attr_kind;
7674 attr.dw_attr_val.val_class = dw_val_class_str;
7675 attr.dw_attr_val.v.val_str = node;
7676 add_dwarf_attr (die, &attr);
7679 static inline const char *
7680 AT_string (dw_attr_ref a)
7682 gcc_assert (a && AT_class (a) == dw_val_class_str);
7683 return a->dw_attr_val.v.val_str->str;
7686 /* Find out whether a string should be output inline in DIE
7687 or out-of-line in .debug_str section. */
7689 static enum dwarf_form
7690 AT_string_form (dw_attr_ref a)
7692 struct indirect_string_node *node;
7696 gcc_assert (a && AT_class (a) == dw_val_class_str);
7698 node = a->dw_attr_val.v.val_str;
7702 len = strlen (node->str) + 1;
7704 /* If the string is shorter or equal to the size of the reference, it is
7705 always better to put it inline. */
7706 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7707 return node->form = DW_FORM_string;
7709 /* If we cannot expect the linker to merge strings in .debug_str
7710 section, only put it into .debug_str if it is worth even in this
7712 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7713 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7714 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7715 return node->form = DW_FORM_string;
7717 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7718 ++dw2_string_counter;
7719 node->label = xstrdup (label);
7721 return node->form = DW_FORM_strp;
7724 /* Add a DIE reference attribute value to a DIE. */
7727 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7731 #ifdef ENABLE_CHECKING
7732 gcc_assert (targ_die != NULL);
7734 /* With LTO we can end up trying to reference something we didn't create
7735 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7736 if (targ_die == NULL)
7740 attr.dw_attr = attr_kind;
7741 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7742 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7743 attr.dw_attr_val.v.val_die_ref.external = 0;
7744 add_dwarf_attr (die, &attr);
7747 /* Add an AT_specification attribute to a DIE, and also make the back
7748 pointer from the specification to the definition. */
7751 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7753 add_AT_die_ref (die, DW_AT_specification, targ_die);
7754 gcc_assert (!targ_die->die_definition);
7755 targ_die->die_definition = die;
7758 static inline dw_die_ref
7759 AT_ref (dw_attr_ref a)
7761 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7762 return a->dw_attr_val.v.val_die_ref.die;
7766 AT_ref_external (dw_attr_ref a)
7768 if (a && AT_class (a) == dw_val_class_die_ref)
7769 return a->dw_attr_val.v.val_die_ref.external;
7775 set_AT_ref_external (dw_attr_ref a, int i)
7777 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7778 a->dw_attr_val.v.val_die_ref.external = i;
7781 /* Add an FDE reference attribute value to a DIE. */
7784 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7788 attr.dw_attr = attr_kind;
7789 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7790 attr.dw_attr_val.v.val_fde_index = targ_fde;
7791 add_dwarf_attr (die, &attr);
7794 /* Add a location description attribute value to a DIE. */
7797 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7801 attr.dw_attr = attr_kind;
7802 attr.dw_attr_val.val_class = dw_val_class_loc;
7803 attr.dw_attr_val.v.val_loc = loc;
7804 add_dwarf_attr (die, &attr);
7807 static inline dw_loc_descr_ref
7808 AT_loc (dw_attr_ref a)
7810 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7811 return a->dw_attr_val.v.val_loc;
7815 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7819 attr.dw_attr = attr_kind;
7820 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7821 attr.dw_attr_val.v.val_loc_list = loc_list;
7822 add_dwarf_attr (die, &attr);
7823 have_location_lists = true;
7826 static inline dw_loc_list_ref
7827 AT_loc_list (dw_attr_ref a)
7829 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7830 return a->dw_attr_val.v.val_loc_list;
7833 static inline dw_loc_list_ref *
7834 AT_loc_list_ptr (dw_attr_ref a)
7836 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7837 return &a->dw_attr_val.v.val_loc_list;
7840 /* Add an address constant attribute value to a DIE. */
7843 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7847 attr.dw_attr = attr_kind;
7848 attr.dw_attr_val.val_class = dw_val_class_addr;
7849 attr.dw_attr_val.v.val_addr = addr;
7850 add_dwarf_attr (die, &attr);
7853 /* Get the RTX from to an address DIE attribute. */
7856 AT_addr (dw_attr_ref a)
7858 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7859 return a->dw_attr_val.v.val_addr;
7862 /* Add a file attribute value to a DIE. */
7865 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7866 struct dwarf_file_data *fd)
7870 attr.dw_attr = attr_kind;
7871 attr.dw_attr_val.val_class = dw_val_class_file;
7872 attr.dw_attr_val.v.val_file = fd;
7873 add_dwarf_attr (die, &attr);
7876 /* Get the dwarf_file_data from a file DIE attribute. */
7878 static inline struct dwarf_file_data *
7879 AT_file (dw_attr_ref a)
7881 gcc_assert (a && AT_class (a) == dw_val_class_file);
7882 return a->dw_attr_val.v.val_file;
7885 /* Add a vms delta attribute value to a DIE. */
7888 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7889 const char *lbl1, const char *lbl2)
7893 attr.dw_attr = attr_kind;
7894 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7895 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7896 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7897 add_dwarf_attr (die, &attr);
7900 /* Add a label identifier attribute value to a DIE. */
7903 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7907 attr.dw_attr = attr_kind;
7908 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7909 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7910 add_dwarf_attr (die, &attr);
7913 /* Add a section offset attribute value to a DIE, an offset into the
7914 debug_line section. */
7917 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7922 attr.dw_attr = attr_kind;
7923 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7924 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7925 add_dwarf_attr (die, &attr);
7928 /* Add a section offset attribute value to a DIE, an offset into the
7929 debug_macinfo section. */
7932 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7937 attr.dw_attr = attr_kind;
7938 attr.dw_attr_val.val_class = dw_val_class_macptr;
7939 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7940 add_dwarf_attr (die, &attr);
7943 /* Add an offset attribute value to a DIE. */
7946 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7947 unsigned HOST_WIDE_INT offset)
7951 attr.dw_attr = attr_kind;
7952 attr.dw_attr_val.val_class = dw_val_class_offset;
7953 attr.dw_attr_val.v.val_offset = offset;
7954 add_dwarf_attr (die, &attr);
7957 /* Add an range_list attribute value to a DIE. */
7960 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7961 long unsigned int offset)
7965 attr.dw_attr = attr_kind;
7966 attr.dw_attr_val.val_class = dw_val_class_range_list;
7967 attr.dw_attr_val.v.val_offset = offset;
7968 add_dwarf_attr (die, &attr);
7971 /* Return the start label of a delta attribute. */
7973 static inline const char *
7974 AT_vms_delta1 (dw_attr_ref a)
7976 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7977 return a->dw_attr_val.v.val_vms_delta.lbl1;
7980 /* Return the end label of a delta attribute. */
7982 static inline const char *
7983 AT_vms_delta2 (dw_attr_ref a)
7985 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7986 return a->dw_attr_val.v.val_vms_delta.lbl2;
7989 static inline const char *
7990 AT_lbl (dw_attr_ref a)
7992 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7993 || AT_class (a) == dw_val_class_lineptr
7994 || AT_class (a) == dw_val_class_macptr));
7995 return a->dw_attr_val.v.val_lbl_id;
7998 /* Get the attribute of type attr_kind. */
8001 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
8005 dw_die_ref spec = NULL;
8010 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8011 if (a->dw_attr == attr_kind)
8013 else if (a->dw_attr == DW_AT_specification
8014 || a->dw_attr == DW_AT_abstract_origin)
8018 return get_AT (spec, attr_kind);
8023 /* Return the "low pc" attribute value, typically associated with a subprogram
8024 DIE. Return null if the "low pc" attribute is either not present, or if it
8025 cannot be represented as an assembler label identifier. */
8027 static inline const char *
8028 get_AT_low_pc (dw_die_ref die)
8030 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
8032 return a ? AT_lbl (a) : NULL;
8035 /* Return the "high pc" attribute value, typically associated with a subprogram
8036 DIE. Return null if the "high pc" attribute is either not present, or if it
8037 cannot be represented as an assembler label identifier. */
8039 static inline const char *
8040 get_AT_hi_pc (dw_die_ref die)
8042 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
8044 return a ? AT_lbl (a) : NULL;
8047 /* Return the value of the string attribute designated by ATTR_KIND, or
8048 NULL if it is not present. */
8050 static inline const char *
8051 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
8053 dw_attr_ref a = get_AT (die, attr_kind);
8055 return a ? AT_string (a) : NULL;
8058 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
8059 if it is not present. */
8062 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
8064 dw_attr_ref a = get_AT (die, attr_kind);
8066 return a ? AT_flag (a) : 0;
8069 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
8070 if it is not present. */
8072 static inline unsigned
8073 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
8075 dw_attr_ref a = get_AT (die, attr_kind);
8077 return a ? AT_unsigned (a) : 0;
8080 static inline dw_die_ref
8081 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
8083 dw_attr_ref a = get_AT (die, attr_kind);
8085 return a ? AT_ref (a) : NULL;
8088 static inline struct dwarf_file_data *
8089 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
8091 dw_attr_ref a = get_AT (die, attr_kind);
8093 return a ? AT_file (a) : NULL;
8096 /* Return TRUE if the language is C++. */
8101 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8103 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
8106 /* Return TRUE if the language is Fortran. */
8111 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8113 return (lang == DW_LANG_Fortran77
8114 || lang == DW_LANG_Fortran90
8115 || lang == DW_LANG_Fortran95);
8118 /* Return TRUE if the language is Ada. */
8123 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8125 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
8128 /* Remove the specified attribute if present. */
8131 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
8139 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8140 if (a->dw_attr == attr_kind)
8142 if (AT_class (a) == dw_val_class_str)
8143 if (a->dw_attr_val.v.val_str->refcount)
8144 a->dw_attr_val.v.val_str->refcount--;
8146 /* VEC_ordered_remove should help reduce the number of abbrevs
8148 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
8153 /* Remove CHILD from its parent. PREV must have the property that
8154 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
8157 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
8159 gcc_assert (child->die_parent == prev->die_parent);
8160 gcc_assert (prev->die_sib == child);
8163 gcc_assert (child->die_parent->die_child == child);
8167 prev->die_sib = child->die_sib;
8168 if (child->die_parent->die_child == child)
8169 child->die_parent->die_child = prev;
8172 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
8173 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
8176 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
8178 dw_die_ref parent = old_child->die_parent;
8180 gcc_assert (parent == prev->die_parent);
8181 gcc_assert (prev->die_sib == old_child);
8183 new_child->die_parent = parent;
8184 if (prev == old_child)
8186 gcc_assert (parent->die_child == old_child);
8187 new_child->die_sib = new_child;
8191 prev->die_sib = new_child;
8192 new_child->die_sib = old_child->die_sib;
8194 if (old_child->die_parent->die_child == old_child)
8195 old_child->die_parent->die_child = new_child;
8198 /* Move all children from OLD_PARENT to NEW_PARENT. */
8201 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
8204 new_parent->die_child = old_parent->die_child;
8205 old_parent->die_child = NULL;
8206 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
8209 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8213 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8219 dw_die_ref prev = c;
8221 while (c->die_tag == tag)
8223 remove_child_with_prev (c, prev);
8224 /* Might have removed every child. */
8225 if (c == c->die_sib)
8229 } while (c != die->die_child);
8232 /* Add a CHILD_DIE as the last child of DIE. */
8235 add_child_die (dw_die_ref die, dw_die_ref child_die)
8237 /* FIXME this should probably be an assert. */
8238 if (! die || ! child_die)
8240 gcc_assert (die != child_die);
8242 child_die->die_parent = die;
8245 child_die->die_sib = die->die_child->die_sib;
8246 die->die_child->die_sib = child_die;
8249 child_die->die_sib = child_die;
8250 die->die_child = child_die;
8253 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8254 is the specification, to the end of PARENT's list of children.
8255 This is done by removing and re-adding it. */
8258 splice_child_die (dw_die_ref parent, dw_die_ref child)
8262 /* We want the declaration DIE from inside the class, not the
8263 specification DIE at toplevel. */
8264 if (child->die_parent != parent)
8266 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8272 gcc_assert (child->die_parent == parent
8273 || (child->die_parent
8274 == get_AT_ref (parent, DW_AT_specification)));
8276 for (p = child->die_parent->die_child; ; p = p->die_sib)
8277 if (p->die_sib == child)
8279 remove_child_with_prev (child, p);
8283 add_child_die (parent, child);
8286 /* Return a pointer to a newly created DIE node. */
8288 static inline dw_die_ref
8289 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8291 dw_die_ref die = ggc_alloc_cleared_die_node ();
8293 die->die_tag = tag_value;
8295 if (parent_die != NULL)
8296 add_child_die (parent_die, die);
8299 limbo_die_node *limbo_node;
8301 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8302 limbo_node->die = die;
8303 limbo_node->created_for = t;
8304 limbo_node->next = limbo_die_list;
8305 limbo_die_list = limbo_node;
8311 /* Return the DIE associated with the given type specifier. */
8313 static inline dw_die_ref
8314 lookup_type_die (tree type)
8316 return TYPE_SYMTAB_DIE (type);
8319 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8320 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8321 anonymous type instead the one of the naming typedef. */
8323 static inline dw_die_ref
8324 strip_naming_typedef (tree type, dw_die_ref type_die)
8327 && TREE_CODE (type) == RECORD_TYPE
8329 && type_die->die_tag == DW_TAG_typedef
8330 && is_naming_typedef_decl (TYPE_NAME (type)))
8331 type_die = get_AT_ref (type_die, DW_AT_type);
8335 /* Like lookup_type_die, but if type is an anonymous type named by a
8336 typedef[1], return the DIE of the anonymous type instead the one of
8337 the naming typedef. This is because in gen_typedef_die, we did
8338 equate the anonymous struct named by the typedef with the DIE of
8339 the naming typedef. So by default, lookup_type_die on an anonymous
8340 struct yields the DIE of the naming typedef.
8342 [1]: Read the comment of is_naming_typedef_decl to learn about what
8343 a naming typedef is. */
8345 static inline dw_die_ref
8346 lookup_type_die_strip_naming_typedef (tree type)
8348 dw_die_ref die = lookup_type_die (type);
8349 return strip_naming_typedef (type, die);
8352 /* Equate a DIE to a given type specifier. */
8355 equate_type_number_to_die (tree type, dw_die_ref type_die)
8357 TYPE_SYMTAB_DIE (type) = type_die;
8360 /* Returns a hash value for X (which really is a die_struct). */
8363 decl_die_table_hash (const void *x)
8365 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8368 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8371 decl_die_table_eq (const void *x, const void *y)
8373 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8376 /* Return the DIE associated with a given declaration. */
8378 static inline dw_die_ref
8379 lookup_decl_die (tree decl)
8381 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8384 /* Returns a hash value for X (which really is a var_loc_list). */
8387 decl_loc_table_hash (const void *x)
8389 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8392 /* Return nonzero if decl_id of var_loc_list X is the same as
8396 decl_loc_table_eq (const void *x, const void *y)
8398 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8401 /* Return the var_loc list associated with a given declaration. */
8403 static inline var_loc_list *
8404 lookup_decl_loc (const_tree decl)
8406 if (!decl_loc_table)
8408 return (var_loc_list *)
8409 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8412 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
8415 cached_dw_loc_list_table_hash (const void *x)
8417 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
8420 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
8424 cached_dw_loc_list_table_eq (const void *x, const void *y)
8426 return (((const cached_dw_loc_list *) x)->decl_id
8427 == DECL_UID ((const_tree) y));
8430 /* Equate a DIE to a particular declaration. */
8433 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8435 unsigned int decl_id = DECL_UID (decl);
8438 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8440 decl_die->decl_id = decl_id;
8443 /* Return how many bits covers PIECE EXPR_LIST. */
8446 decl_piece_bitsize (rtx piece)
8448 int ret = (int) GET_MODE (piece);
8451 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8452 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8453 return INTVAL (XEXP (XEXP (piece, 0), 0));
8456 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8459 decl_piece_varloc_ptr (rtx piece)
8461 if ((int) GET_MODE (piece))
8462 return &XEXP (piece, 0);
8464 return &XEXP (XEXP (piece, 0), 1);
8467 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8468 Next is the chain of following piece nodes. */
8471 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8473 if (bitsize <= (int) MAX_MACHINE_MODE)
8474 return alloc_EXPR_LIST (bitsize, loc_note, next);
8476 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8481 /* Return rtx that should be stored into loc field for
8482 LOC_NOTE and BITPOS/BITSIZE. */
8485 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8486 HOST_WIDE_INT bitsize)
8490 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8492 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8497 /* This function either modifies location piece list *DEST in
8498 place (if SRC and INNER is NULL), or copies location piece list
8499 *SRC to *DEST while modifying it. Location BITPOS is modified
8500 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8501 not copied and if needed some padding around it is added.
8502 When modifying in place, DEST should point to EXPR_LIST where
8503 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8504 to the start of the whole list and INNER points to the EXPR_LIST
8505 where earlier pieces cover PIECE_BITPOS bits. */
8508 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8509 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8510 HOST_WIDE_INT bitsize, rtx loc_note)
8513 bool copy = inner != NULL;
8517 /* First copy all nodes preceeding the current bitpos. */
8518 while (src != inner)
8520 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8521 decl_piece_bitsize (*src), NULL_RTX);
8522 dest = &XEXP (*dest, 1);
8523 src = &XEXP (*src, 1);
8526 /* Add padding if needed. */
8527 if (bitpos != piece_bitpos)
8529 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8530 copy ? NULL_RTX : *dest);
8531 dest = &XEXP (*dest, 1);
8533 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8536 /* A piece with correct bitpos and bitsize already exist,
8537 just update the location for it and return. */
8538 *decl_piece_varloc_ptr (*dest) = loc_note;
8541 /* Add the piece that changed. */
8542 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8543 dest = &XEXP (*dest, 1);
8544 /* Skip over pieces that overlap it. */
8545 diff = bitpos - piece_bitpos + bitsize;
8548 while (diff > 0 && *src)
8551 diff -= decl_piece_bitsize (piece);
8553 src = &XEXP (piece, 1);
8556 *src = XEXP (piece, 1);
8557 free_EXPR_LIST_node (piece);
8560 /* Add padding if needed. */
8561 if (diff < 0 && *src)
8565 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8566 dest = &XEXP (*dest, 1);
8570 /* Finally copy all nodes following it. */
8573 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8574 decl_piece_bitsize (*src), NULL_RTX);
8575 dest = &XEXP (*dest, 1);
8576 src = &XEXP (*src, 1);
8580 /* Add a variable location node to the linked list for DECL. */
8582 static struct var_loc_node *
8583 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8585 unsigned int decl_id;
8588 struct var_loc_node *loc = NULL;
8589 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8591 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8593 tree realdecl = DECL_DEBUG_EXPR (decl);
8594 if (realdecl && handled_component_p (realdecl))
8596 HOST_WIDE_INT maxsize;
8599 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8600 if (!DECL_P (innerdecl)
8601 || DECL_IGNORED_P (innerdecl)
8602 || TREE_STATIC (innerdecl)
8604 || bitpos + bitsize > 256
8605 || bitsize != maxsize)
8611 decl_id = DECL_UID (decl);
8612 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8615 temp = ggc_alloc_cleared_var_loc_list ();
8616 temp->decl_id = decl_id;
8620 temp = (var_loc_list *) *slot;
8624 struct var_loc_node *last = temp->last, *unused = NULL;
8625 rtx *piece_loc = NULL, last_loc_note;
8626 int piece_bitpos = 0;
8630 gcc_assert (last->next == NULL);
8632 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8634 piece_loc = &last->loc;
8637 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8638 if (piece_bitpos + cur_bitsize > bitpos)
8640 piece_bitpos += cur_bitsize;
8641 piece_loc = &XEXP (*piece_loc, 1);
8645 /* TEMP->LAST here is either pointer to the last but one or
8646 last element in the chained list, LAST is pointer to the
8648 if (label && strcmp (last->label, label) == 0)
8650 /* For SRA optimized variables if there weren't any real
8651 insns since last note, just modify the last node. */
8652 if (piece_loc != NULL)
8654 adjust_piece_list (piece_loc, NULL, NULL,
8655 bitpos, piece_bitpos, bitsize, loc_note);
8658 /* If the last note doesn't cover any instructions, remove it. */
8659 if (temp->last != last)
8661 temp->last->next = NULL;
8664 gcc_assert (strcmp (last->label, label) != 0);
8668 gcc_assert (temp->first == temp->last);
8669 memset (temp->last, '\0', sizeof (*temp->last));
8670 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8674 if (bitsize == -1 && NOTE_P (last->loc))
8675 last_loc_note = last->loc;
8676 else if (piece_loc != NULL
8677 && *piece_loc != NULL_RTX
8678 && piece_bitpos == bitpos
8679 && decl_piece_bitsize (*piece_loc) == bitsize)
8680 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8682 last_loc_note = NULL_RTX;
8683 /* If the current location is the same as the end of the list,
8684 and either both or neither of the locations is uninitialized,
8685 we have nothing to do. */
8686 if (last_loc_note == NULL_RTX
8687 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8688 NOTE_VAR_LOCATION_LOC (loc_note)))
8689 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8690 != NOTE_VAR_LOCATION_STATUS (loc_note))
8691 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8692 == VAR_INIT_STATUS_UNINITIALIZED)
8693 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8694 == VAR_INIT_STATUS_UNINITIALIZED))))
8696 /* Add LOC to the end of list and update LAST. If the last
8697 element of the list has been removed above, reuse its
8698 memory for the new node, otherwise allocate a new one. */
8702 memset (loc, '\0', sizeof (*loc));
8705 loc = ggc_alloc_cleared_var_loc_node ();
8706 if (bitsize == -1 || piece_loc == NULL)
8707 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8709 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8710 bitpos, piece_bitpos, bitsize, loc_note);
8712 /* Ensure TEMP->LAST will point either to the new last but one
8713 element of the chain, or to the last element in it. */
8714 if (last != temp->last)
8722 loc = ggc_alloc_cleared_var_loc_node ();
8725 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8730 /* Keep track of the number of spaces used to indent the
8731 output of the debugging routines that print the structure of
8732 the DIE internal representation. */
8733 static int print_indent;
8735 /* Indent the line the number of spaces given by print_indent. */
8738 print_spaces (FILE *outfile)
8740 fprintf (outfile, "%*s", print_indent, "");
8743 /* Print a type signature in hex. */
8746 print_signature (FILE *outfile, char *sig)
8750 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8751 fprintf (outfile, "%02x", sig[i] & 0xff);
8754 /* Print the information associated with a given DIE, and its children.
8755 This routine is a debugging aid only. */
8758 print_die (dw_die_ref die, FILE *outfile)
8764 print_spaces (outfile);
8765 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8766 die->die_offset, dwarf_tag_name (die->die_tag),
8768 print_spaces (outfile);
8769 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8770 fprintf (outfile, " offset: %ld", die->die_offset);
8771 fprintf (outfile, " mark: %d\n", die->die_mark);
8773 if (use_debug_types && die->die_id.die_type_node)
8775 print_spaces (outfile);
8776 fprintf (outfile, " signature: ");
8777 print_signature (outfile, die->die_id.die_type_node->signature);
8778 fprintf (outfile, "\n");
8781 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8783 print_spaces (outfile);
8784 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8786 switch (AT_class (a))
8788 case dw_val_class_addr:
8789 fprintf (outfile, "address");
8791 case dw_val_class_offset:
8792 fprintf (outfile, "offset");
8794 case dw_val_class_loc:
8795 fprintf (outfile, "location descriptor");
8797 case dw_val_class_loc_list:
8798 fprintf (outfile, "location list -> label:%s",
8799 AT_loc_list (a)->ll_symbol);
8801 case dw_val_class_range_list:
8802 fprintf (outfile, "range list");
8804 case dw_val_class_const:
8805 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8807 case dw_val_class_unsigned_const:
8808 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8810 case dw_val_class_const_double:
8811 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8812 HOST_WIDE_INT_PRINT_UNSIGNED")",
8813 a->dw_attr_val.v.val_double.high,
8814 a->dw_attr_val.v.val_double.low);
8816 case dw_val_class_vec:
8817 fprintf (outfile, "floating-point or vector constant");
8819 case dw_val_class_flag:
8820 fprintf (outfile, "%u", AT_flag (a));
8822 case dw_val_class_die_ref:
8823 if (AT_ref (a) != NULL)
8825 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
8827 fprintf (outfile, "die -> signature: ");
8828 print_signature (outfile,
8829 AT_ref (a)->die_id.die_type_node->signature);
8831 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
8832 fprintf (outfile, "die -> label: %s",
8833 AT_ref (a)->die_id.die_symbol);
8835 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8836 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8839 fprintf (outfile, "die -> <null>");
8841 case dw_val_class_vms_delta:
8842 fprintf (outfile, "delta: @slotcount(%s-%s)",
8843 AT_vms_delta2 (a), AT_vms_delta1 (a));
8845 case dw_val_class_lbl_id:
8846 case dw_val_class_lineptr:
8847 case dw_val_class_macptr:
8848 fprintf (outfile, "label: %s", AT_lbl (a));
8850 case dw_val_class_str:
8851 if (AT_string (a) != NULL)
8852 fprintf (outfile, "\"%s\"", AT_string (a));
8854 fprintf (outfile, "<null>");
8856 case dw_val_class_file:
8857 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8858 AT_file (a)->emitted_number);
8860 case dw_val_class_data8:
8864 for (i = 0; i < 8; i++)
8865 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8872 fprintf (outfile, "\n");
8875 if (die->die_child != NULL)
8878 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8881 if (print_indent == 0)
8882 fprintf (outfile, "\n");
8885 /* Print the information collected for a given DIE. */
8888 debug_dwarf_die (dw_die_ref die)
8890 print_die (die, stderr);
8893 /* Print all DWARF information collected for the compilation unit.
8894 This routine is a debugging aid only. */
8900 print_die (comp_unit_die (), stderr);
8903 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8904 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8905 DIE that marks the start of the DIEs for this include file. */
8908 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8910 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8911 dw_die_ref new_unit = gen_compile_unit_die (filename);
8913 new_unit->die_sib = old_unit;
8917 /* Close an include-file CU and reopen the enclosing one. */
8920 pop_compile_unit (dw_die_ref old_unit)
8922 dw_die_ref new_unit = old_unit->die_sib;
8924 old_unit->die_sib = NULL;
8928 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8929 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8931 /* Calculate the checksum of a location expression. */
8934 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8938 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8940 CHECKSUM (loc->dw_loc_oprnd1);
8941 CHECKSUM (loc->dw_loc_oprnd2);
8944 /* Calculate the checksum of an attribute. */
8947 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8949 dw_loc_descr_ref loc;
8952 CHECKSUM (at->dw_attr);
8954 /* We don't care that this was compiled with a different compiler
8955 snapshot; if the output is the same, that's what matters. */
8956 if (at->dw_attr == DW_AT_producer)
8959 switch (AT_class (at))
8961 case dw_val_class_const:
8962 CHECKSUM (at->dw_attr_val.v.val_int);
8964 case dw_val_class_unsigned_const:
8965 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8967 case dw_val_class_const_double:
8968 CHECKSUM (at->dw_attr_val.v.val_double);
8970 case dw_val_class_vec:
8971 CHECKSUM (at->dw_attr_val.v.val_vec);
8973 case dw_val_class_flag:
8974 CHECKSUM (at->dw_attr_val.v.val_flag);
8976 case dw_val_class_str:
8977 CHECKSUM_STRING (AT_string (at));
8980 case dw_val_class_addr:
8982 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8983 CHECKSUM_STRING (XSTR (r, 0));
8986 case dw_val_class_offset:
8987 CHECKSUM (at->dw_attr_val.v.val_offset);
8990 case dw_val_class_loc:
8991 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8992 loc_checksum (loc, ctx);
8995 case dw_val_class_die_ref:
8996 die_checksum (AT_ref (at), ctx, mark);
8999 case dw_val_class_fde_ref:
9000 case dw_val_class_vms_delta:
9001 case dw_val_class_lbl_id:
9002 case dw_val_class_lineptr:
9003 case dw_val_class_macptr:
9006 case dw_val_class_file:
9007 CHECKSUM_STRING (AT_file (at)->filename);
9010 case dw_val_class_data8:
9011 CHECKSUM (at->dw_attr_val.v.val_data8);
9019 /* Calculate the checksum of a DIE. */
9022 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9028 /* To avoid infinite recursion. */
9031 CHECKSUM (die->die_mark);
9034 die->die_mark = ++(*mark);
9036 CHECKSUM (die->die_tag);
9038 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9039 attr_checksum (a, ctx, mark);
9041 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
9045 #undef CHECKSUM_STRING
9047 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
9048 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
9049 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
9050 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
9051 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
9052 #define CHECKSUM_ATTR(FOO) \
9053 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
9055 /* Calculate the checksum of a number in signed LEB128 format. */
9058 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
9065 byte = (value & 0x7f);
9067 more = !((value == 0 && (byte & 0x40) == 0)
9068 || (value == -1 && (byte & 0x40) != 0));
9077 /* Calculate the checksum of a number in unsigned LEB128 format. */
9080 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
9084 unsigned char byte = (value & 0x7f);
9087 /* More bytes to follow. */
9095 /* Checksum the context of the DIE. This adds the names of any
9096 surrounding namespaces or structures to the checksum. */
9099 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
9103 int tag = die->die_tag;
9105 if (tag != DW_TAG_namespace
9106 && tag != DW_TAG_structure_type
9107 && tag != DW_TAG_class_type)
9110 name = get_AT_string (die, DW_AT_name);
9112 spec = get_AT_ref (die, DW_AT_specification);
9116 if (die->die_parent != NULL)
9117 checksum_die_context (die->die_parent, ctx);
9119 CHECKSUM_ULEB128 ('C');
9120 CHECKSUM_ULEB128 (tag);
9122 CHECKSUM_STRING (name);
9125 /* Calculate the checksum of a location expression. */
9128 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
9130 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
9131 were emitted as a DW_FORM_sdata instead of a location expression. */
9132 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
9134 CHECKSUM_ULEB128 (DW_FORM_sdata);
9135 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
9139 /* Otherwise, just checksum the raw location expression. */
9142 CHECKSUM_ULEB128 (loc->dw_loc_opc);
9143 CHECKSUM (loc->dw_loc_oprnd1);
9144 CHECKSUM (loc->dw_loc_oprnd2);
9145 loc = loc->dw_loc_next;
9149 /* Calculate the checksum of an attribute. */
9152 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
9153 struct md5_ctx *ctx, int *mark)
9155 dw_loc_descr_ref loc;
9158 if (AT_class (at) == dw_val_class_die_ref)
9160 dw_die_ref target_die = AT_ref (at);
9162 /* For pointer and reference types, we checksum only the (qualified)
9163 name of the target type (if there is a name). For friend entries,
9164 we checksum only the (qualified) name of the target type or function.
9165 This allows the checksum to remain the same whether the target type
9166 is complete or not. */
9167 if ((at->dw_attr == DW_AT_type
9168 && (tag == DW_TAG_pointer_type
9169 || tag == DW_TAG_reference_type
9170 || tag == DW_TAG_rvalue_reference_type
9171 || tag == DW_TAG_ptr_to_member_type))
9172 || (at->dw_attr == DW_AT_friend
9173 && tag == DW_TAG_friend))
9175 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
9177 if (name_attr != NULL)
9179 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9183 CHECKSUM_ULEB128 ('N');
9184 CHECKSUM_ULEB128 (at->dw_attr);
9185 if (decl->die_parent != NULL)
9186 checksum_die_context (decl->die_parent, ctx);
9187 CHECKSUM_ULEB128 ('E');
9188 CHECKSUM_STRING (AT_string (name_attr));
9193 /* For all other references to another DIE, we check to see if the
9194 target DIE has already been visited. If it has, we emit a
9195 backward reference; if not, we descend recursively. */
9196 if (target_die->die_mark > 0)
9198 CHECKSUM_ULEB128 ('R');
9199 CHECKSUM_ULEB128 (at->dw_attr);
9200 CHECKSUM_ULEB128 (target_die->die_mark);
9204 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9208 target_die->die_mark = ++(*mark);
9209 CHECKSUM_ULEB128 ('T');
9210 CHECKSUM_ULEB128 (at->dw_attr);
9211 if (decl->die_parent != NULL)
9212 checksum_die_context (decl->die_parent, ctx);
9213 die_checksum_ordered (target_die, ctx, mark);
9218 CHECKSUM_ULEB128 ('A');
9219 CHECKSUM_ULEB128 (at->dw_attr);
9221 switch (AT_class (at))
9223 case dw_val_class_const:
9224 CHECKSUM_ULEB128 (DW_FORM_sdata);
9225 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9228 case dw_val_class_unsigned_const:
9229 CHECKSUM_ULEB128 (DW_FORM_sdata);
9230 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9233 case dw_val_class_const_double:
9234 CHECKSUM_ULEB128 (DW_FORM_block);
9235 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9236 CHECKSUM (at->dw_attr_val.v.val_double);
9239 case dw_val_class_vec:
9240 CHECKSUM_ULEB128 (DW_FORM_block);
9241 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9242 CHECKSUM (at->dw_attr_val.v.val_vec);
9245 case dw_val_class_flag:
9246 CHECKSUM_ULEB128 (DW_FORM_flag);
9247 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9250 case dw_val_class_str:
9251 CHECKSUM_ULEB128 (DW_FORM_string);
9252 CHECKSUM_STRING (AT_string (at));
9255 case dw_val_class_addr:
9257 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9258 CHECKSUM_ULEB128 (DW_FORM_string);
9259 CHECKSUM_STRING (XSTR (r, 0));
9262 case dw_val_class_offset:
9263 CHECKSUM_ULEB128 (DW_FORM_sdata);
9264 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9267 case dw_val_class_loc:
9268 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9269 loc_checksum_ordered (loc, ctx);
9272 case dw_val_class_fde_ref:
9273 case dw_val_class_lbl_id:
9274 case dw_val_class_lineptr:
9275 case dw_val_class_macptr:
9278 case dw_val_class_file:
9279 CHECKSUM_ULEB128 (DW_FORM_string);
9280 CHECKSUM_STRING (AT_file (at)->filename);
9283 case dw_val_class_data8:
9284 CHECKSUM (at->dw_attr_val.v.val_data8);
9292 struct checksum_attributes
9294 dw_attr_ref at_name;
9295 dw_attr_ref at_type;
9296 dw_attr_ref at_friend;
9297 dw_attr_ref at_accessibility;
9298 dw_attr_ref at_address_class;
9299 dw_attr_ref at_allocated;
9300 dw_attr_ref at_artificial;
9301 dw_attr_ref at_associated;
9302 dw_attr_ref at_binary_scale;
9303 dw_attr_ref at_bit_offset;
9304 dw_attr_ref at_bit_size;
9305 dw_attr_ref at_bit_stride;
9306 dw_attr_ref at_byte_size;
9307 dw_attr_ref at_byte_stride;
9308 dw_attr_ref at_const_value;
9309 dw_attr_ref at_containing_type;
9310 dw_attr_ref at_count;
9311 dw_attr_ref at_data_location;
9312 dw_attr_ref at_data_member_location;
9313 dw_attr_ref at_decimal_scale;
9314 dw_attr_ref at_decimal_sign;
9315 dw_attr_ref at_default_value;
9316 dw_attr_ref at_digit_count;
9317 dw_attr_ref at_discr;
9318 dw_attr_ref at_discr_list;
9319 dw_attr_ref at_discr_value;
9320 dw_attr_ref at_encoding;
9321 dw_attr_ref at_endianity;
9322 dw_attr_ref at_explicit;
9323 dw_attr_ref at_is_optional;
9324 dw_attr_ref at_location;
9325 dw_attr_ref at_lower_bound;
9326 dw_attr_ref at_mutable;
9327 dw_attr_ref at_ordering;
9328 dw_attr_ref at_picture_string;
9329 dw_attr_ref at_prototyped;
9330 dw_attr_ref at_small;
9331 dw_attr_ref at_segment;
9332 dw_attr_ref at_string_length;
9333 dw_attr_ref at_threads_scaled;
9334 dw_attr_ref at_upper_bound;
9335 dw_attr_ref at_use_location;
9336 dw_attr_ref at_use_UTF8;
9337 dw_attr_ref at_variable_parameter;
9338 dw_attr_ref at_virtuality;
9339 dw_attr_ref at_visibility;
9340 dw_attr_ref at_vtable_elem_location;
9343 /* Collect the attributes that we will want to use for the checksum. */
9346 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9351 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9362 attrs->at_friend = a;
9364 case DW_AT_accessibility:
9365 attrs->at_accessibility = a;
9367 case DW_AT_address_class:
9368 attrs->at_address_class = a;
9370 case DW_AT_allocated:
9371 attrs->at_allocated = a;
9373 case DW_AT_artificial:
9374 attrs->at_artificial = a;
9376 case DW_AT_associated:
9377 attrs->at_associated = a;
9379 case DW_AT_binary_scale:
9380 attrs->at_binary_scale = a;
9382 case DW_AT_bit_offset:
9383 attrs->at_bit_offset = a;
9385 case DW_AT_bit_size:
9386 attrs->at_bit_size = a;
9388 case DW_AT_bit_stride:
9389 attrs->at_bit_stride = a;
9391 case DW_AT_byte_size:
9392 attrs->at_byte_size = a;
9394 case DW_AT_byte_stride:
9395 attrs->at_byte_stride = a;
9397 case DW_AT_const_value:
9398 attrs->at_const_value = a;
9400 case DW_AT_containing_type:
9401 attrs->at_containing_type = a;
9404 attrs->at_count = a;
9406 case DW_AT_data_location:
9407 attrs->at_data_location = a;
9409 case DW_AT_data_member_location:
9410 attrs->at_data_member_location = a;
9412 case DW_AT_decimal_scale:
9413 attrs->at_decimal_scale = a;
9415 case DW_AT_decimal_sign:
9416 attrs->at_decimal_sign = a;
9418 case DW_AT_default_value:
9419 attrs->at_default_value = a;
9421 case DW_AT_digit_count:
9422 attrs->at_digit_count = a;
9425 attrs->at_discr = a;
9427 case DW_AT_discr_list:
9428 attrs->at_discr_list = a;
9430 case DW_AT_discr_value:
9431 attrs->at_discr_value = a;
9433 case DW_AT_encoding:
9434 attrs->at_encoding = a;
9436 case DW_AT_endianity:
9437 attrs->at_endianity = a;
9439 case DW_AT_explicit:
9440 attrs->at_explicit = a;
9442 case DW_AT_is_optional:
9443 attrs->at_is_optional = a;
9445 case DW_AT_location:
9446 attrs->at_location = a;
9448 case DW_AT_lower_bound:
9449 attrs->at_lower_bound = a;
9452 attrs->at_mutable = a;
9454 case DW_AT_ordering:
9455 attrs->at_ordering = a;
9457 case DW_AT_picture_string:
9458 attrs->at_picture_string = a;
9460 case DW_AT_prototyped:
9461 attrs->at_prototyped = a;
9464 attrs->at_small = a;
9467 attrs->at_segment = a;
9469 case DW_AT_string_length:
9470 attrs->at_string_length = a;
9472 case DW_AT_threads_scaled:
9473 attrs->at_threads_scaled = a;
9475 case DW_AT_upper_bound:
9476 attrs->at_upper_bound = a;
9478 case DW_AT_use_location:
9479 attrs->at_use_location = a;
9481 case DW_AT_use_UTF8:
9482 attrs->at_use_UTF8 = a;
9484 case DW_AT_variable_parameter:
9485 attrs->at_variable_parameter = a;
9487 case DW_AT_virtuality:
9488 attrs->at_virtuality = a;
9490 case DW_AT_visibility:
9491 attrs->at_visibility = a;
9493 case DW_AT_vtable_elem_location:
9494 attrs->at_vtable_elem_location = a;
9502 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9505 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9509 struct checksum_attributes attrs;
9511 CHECKSUM_ULEB128 ('D');
9512 CHECKSUM_ULEB128 (die->die_tag);
9514 memset (&attrs, 0, sizeof (attrs));
9516 decl = get_AT_ref (die, DW_AT_specification);
9518 collect_checksum_attributes (&attrs, decl);
9519 collect_checksum_attributes (&attrs, die);
9521 CHECKSUM_ATTR (attrs.at_name);
9522 CHECKSUM_ATTR (attrs.at_accessibility);
9523 CHECKSUM_ATTR (attrs.at_address_class);
9524 CHECKSUM_ATTR (attrs.at_allocated);
9525 CHECKSUM_ATTR (attrs.at_artificial);
9526 CHECKSUM_ATTR (attrs.at_associated);
9527 CHECKSUM_ATTR (attrs.at_binary_scale);
9528 CHECKSUM_ATTR (attrs.at_bit_offset);
9529 CHECKSUM_ATTR (attrs.at_bit_size);
9530 CHECKSUM_ATTR (attrs.at_bit_stride);
9531 CHECKSUM_ATTR (attrs.at_byte_size);
9532 CHECKSUM_ATTR (attrs.at_byte_stride);
9533 CHECKSUM_ATTR (attrs.at_const_value);
9534 CHECKSUM_ATTR (attrs.at_containing_type);
9535 CHECKSUM_ATTR (attrs.at_count);
9536 CHECKSUM_ATTR (attrs.at_data_location);
9537 CHECKSUM_ATTR (attrs.at_data_member_location);
9538 CHECKSUM_ATTR (attrs.at_decimal_scale);
9539 CHECKSUM_ATTR (attrs.at_decimal_sign);
9540 CHECKSUM_ATTR (attrs.at_default_value);
9541 CHECKSUM_ATTR (attrs.at_digit_count);
9542 CHECKSUM_ATTR (attrs.at_discr);
9543 CHECKSUM_ATTR (attrs.at_discr_list);
9544 CHECKSUM_ATTR (attrs.at_discr_value);
9545 CHECKSUM_ATTR (attrs.at_encoding);
9546 CHECKSUM_ATTR (attrs.at_endianity);
9547 CHECKSUM_ATTR (attrs.at_explicit);
9548 CHECKSUM_ATTR (attrs.at_is_optional);
9549 CHECKSUM_ATTR (attrs.at_location);
9550 CHECKSUM_ATTR (attrs.at_lower_bound);
9551 CHECKSUM_ATTR (attrs.at_mutable);
9552 CHECKSUM_ATTR (attrs.at_ordering);
9553 CHECKSUM_ATTR (attrs.at_picture_string);
9554 CHECKSUM_ATTR (attrs.at_prototyped);
9555 CHECKSUM_ATTR (attrs.at_small);
9556 CHECKSUM_ATTR (attrs.at_segment);
9557 CHECKSUM_ATTR (attrs.at_string_length);
9558 CHECKSUM_ATTR (attrs.at_threads_scaled);
9559 CHECKSUM_ATTR (attrs.at_upper_bound);
9560 CHECKSUM_ATTR (attrs.at_use_location);
9561 CHECKSUM_ATTR (attrs.at_use_UTF8);
9562 CHECKSUM_ATTR (attrs.at_variable_parameter);
9563 CHECKSUM_ATTR (attrs.at_virtuality);
9564 CHECKSUM_ATTR (attrs.at_visibility);
9565 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9566 CHECKSUM_ATTR (attrs.at_type);
9567 CHECKSUM_ATTR (attrs.at_friend);
9569 /* Checksum the child DIEs, except for nested types and member functions. */
9572 dw_attr_ref name_attr;
9575 name_attr = get_AT (c, DW_AT_name);
9576 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9577 && name_attr != NULL)
9579 CHECKSUM_ULEB128 ('S');
9580 CHECKSUM_ULEB128 (c->die_tag);
9581 CHECKSUM_STRING (AT_string (name_attr));
9585 /* Mark this DIE so it gets processed when unmarking. */
9586 if (c->die_mark == 0)
9588 die_checksum_ordered (c, ctx, mark);
9590 } while (c != die->die_child);
9592 CHECKSUM_ULEB128 (0);
9596 #undef CHECKSUM_STRING
9597 #undef CHECKSUM_ATTR
9598 #undef CHECKSUM_LEB128
9599 #undef CHECKSUM_ULEB128
9601 /* Generate the type signature for DIE. This is computed by generating an
9602 MD5 checksum over the DIE's tag, its relevant attributes, and its
9603 children. Attributes that are references to other DIEs are processed
9604 by recursion, using the MARK field to prevent infinite recursion.
9605 If the DIE is nested inside a namespace or another type, we also
9606 need to include that context in the signature. The lower 64 bits
9607 of the resulting MD5 checksum comprise the signature. */
9610 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9614 unsigned char checksum[16];
9618 name = get_AT_string (die, DW_AT_name);
9619 decl = get_AT_ref (die, DW_AT_specification);
9621 /* First, compute a signature for just the type name (and its surrounding
9622 context, if any. This is stored in the type unit DIE for link-time
9623 ODR (one-definition rule) checking. */
9625 if (is_cxx() && name != NULL)
9627 md5_init_ctx (&ctx);
9629 /* Checksum the names of surrounding namespaces and structures. */
9630 if (decl != NULL && decl->die_parent != NULL)
9631 checksum_die_context (decl->die_parent, &ctx);
9633 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9634 md5_process_bytes (name, strlen (name) + 1, &ctx);
9635 md5_finish_ctx (&ctx, checksum);
9637 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9640 /* Next, compute the complete type signature. */
9642 md5_init_ctx (&ctx);
9644 die->die_mark = mark;
9646 /* Checksum the names of surrounding namespaces and structures. */
9647 if (decl != NULL && decl->die_parent != NULL)
9648 checksum_die_context (decl->die_parent, &ctx);
9650 /* Checksum the DIE and its children. */
9651 die_checksum_ordered (die, &ctx, &mark);
9652 unmark_all_dies (die);
9653 md5_finish_ctx (&ctx, checksum);
9655 /* Store the signature in the type node and link the type DIE and the
9656 type node together. */
9657 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9658 DWARF_TYPE_SIGNATURE_SIZE);
9659 die->die_id.die_type_node = type_node;
9660 type_node->type_die = die;
9662 /* If the DIE is a specification, link its declaration to the type node
9665 decl->die_id.die_type_node = type_node;
9668 /* Do the location expressions look same? */
9670 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9672 return loc1->dw_loc_opc == loc2->dw_loc_opc
9673 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9674 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9677 /* Do the values look the same? */
9679 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9681 dw_loc_descr_ref loc1, loc2;
9684 if (v1->val_class != v2->val_class)
9687 switch (v1->val_class)
9689 case dw_val_class_const:
9690 return v1->v.val_int == v2->v.val_int;
9691 case dw_val_class_unsigned_const:
9692 return v1->v.val_unsigned == v2->v.val_unsigned;
9693 case dw_val_class_const_double:
9694 return v1->v.val_double.high == v2->v.val_double.high
9695 && v1->v.val_double.low == v2->v.val_double.low;
9696 case dw_val_class_vec:
9697 if (v1->v.val_vec.length != v2->v.val_vec.length
9698 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9700 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9701 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9704 case dw_val_class_flag:
9705 return v1->v.val_flag == v2->v.val_flag;
9706 case dw_val_class_str:
9707 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9709 case dw_val_class_addr:
9710 r1 = v1->v.val_addr;
9711 r2 = v2->v.val_addr;
9712 if (GET_CODE (r1) != GET_CODE (r2))
9714 return !rtx_equal_p (r1, r2);
9716 case dw_val_class_offset:
9717 return v1->v.val_offset == v2->v.val_offset;
9719 case dw_val_class_loc:
9720 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9722 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9723 if (!same_loc_p (loc1, loc2, mark))
9725 return !loc1 && !loc2;
9727 case dw_val_class_die_ref:
9728 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9730 case dw_val_class_fde_ref:
9731 case dw_val_class_vms_delta:
9732 case dw_val_class_lbl_id:
9733 case dw_val_class_lineptr:
9734 case dw_val_class_macptr:
9737 case dw_val_class_file:
9738 return v1->v.val_file == v2->v.val_file;
9740 case dw_val_class_data8:
9741 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9748 /* Do the attributes look the same? */
9751 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9753 if (at1->dw_attr != at2->dw_attr)
9756 /* We don't care that this was compiled with a different compiler
9757 snapshot; if the output is the same, that's what matters. */
9758 if (at1->dw_attr == DW_AT_producer)
9761 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9764 /* Do the dies look the same? */
9767 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9773 /* To avoid infinite recursion. */
9775 return die1->die_mark == die2->die_mark;
9776 die1->die_mark = die2->die_mark = ++(*mark);
9778 if (die1->die_tag != die2->die_tag)
9781 if (VEC_length (dw_attr_node, die1->die_attr)
9782 != VEC_length (dw_attr_node, die2->die_attr))
9785 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9786 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9789 c1 = die1->die_child;
9790 c2 = die2->die_child;
9799 if (!same_die_p (c1, c2, mark))
9803 if (c1 == die1->die_child)
9805 if (c2 == die2->die_child)
9815 /* Do the dies look the same? Wrapper around same_die_p. */
9818 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9821 int ret = same_die_p (die1, die2, &mark);
9823 unmark_all_dies (die1);
9824 unmark_all_dies (die2);
9829 /* The prefix to attach to symbols on DIEs in the current comdat debug
9831 static char *comdat_symbol_id;
9833 /* The index of the current symbol within the current comdat CU. */
9834 static unsigned int comdat_symbol_number;
9836 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9837 children, and set comdat_symbol_id accordingly. */
9840 compute_section_prefix (dw_die_ref unit_die)
9842 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9843 const char *base = die_name ? lbasename (die_name) : "anonymous";
9844 char *name = XALLOCAVEC (char, strlen (base) + 64);
9847 unsigned char checksum[16];
9850 /* Compute the checksum of the DIE, then append part of it as hex digits to
9851 the name filename of the unit. */
9853 md5_init_ctx (&ctx);
9855 die_checksum (unit_die, &ctx, &mark);
9856 unmark_all_dies (unit_die);
9857 md5_finish_ctx (&ctx, checksum);
9859 sprintf (name, "%s.", base);
9860 clean_symbol_name (name);
9862 p = name + strlen (name);
9863 for (i = 0; i < 4; i++)
9865 sprintf (p, "%.2x", checksum[i]);
9869 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9870 comdat_symbol_number = 0;
9873 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9876 is_type_die (dw_die_ref die)
9878 switch (die->die_tag)
9880 case DW_TAG_array_type:
9881 case DW_TAG_class_type:
9882 case DW_TAG_interface_type:
9883 case DW_TAG_enumeration_type:
9884 case DW_TAG_pointer_type:
9885 case DW_TAG_reference_type:
9886 case DW_TAG_rvalue_reference_type:
9887 case DW_TAG_string_type:
9888 case DW_TAG_structure_type:
9889 case DW_TAG_subroutine_type:
9890 case DW_TAG_union_type:
9891 case DW_TAG_ptr_to_member_type:
9892 case DW_TAG_set_type:
9893 case DW_TAG_subrange_type:
9894 case DW_TAG_base_type:
9895 case DW_TAG_const_type:
9896 case DW_TAG_file_type:
9897 case DW_TAG_packed_type:
9898 case DW_TAG_volatile_type:
9899 case DW_TAG_typedef:
9906 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9907 Basically, we want to choose the bits that are likely to be shared between
9908 compilations (types) and leave out the bits that are specific to individual
9909 compilations (functions). */
9912 is_comdat_die (dw_die_ref c)
9914 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9915 we do for stabs. The advantage is a greater likelihood of sharing between
9916 objects that don't include headers in the same order (and therefore would
9917 put the base types in a different comdat). jason 8/28/00 */
9919 if (c->die_tag == DW_TAG_base_type)
9922 if (c->die_tag == DW_TAG_pointer_type
9923 || c->die_tag == DW_TAG_reference_type
9924 || c->die_tag == DW_TAG_rvalue_reference_type
9925 || c->die_tag == DW_TAG_const_type
9926 || c->die_tag == DW_TAG_volatile_type)
9928 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9930 return t ? is_comdat_die (t) : 0;
9933 return is_type_die (c);
9936 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9937 compilation unit. */
9940 is_symbol_die (dw_die_ref c)
9942 return (is_type_die (c)
9943 || is_declaration_die (c)
9944 || c->die_tag == DW_TAG_namespace
9945 || c->die_tag == DW_TAG_module);
9948 /* Returns true iff C is a compile-unit DIE. */
9951 is_cu_die (dw_die_ref c)
9953 return c && c->die_tag == DW_TAG_compile_unit;
9957 gen_internal_sym (const char *prefix)
9961 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9962 return xstrdup (buf);
9965 /* Assign symbols to all worthy DIEs under DIE. */
9968 assign_symbol_names (dw_die_ref die)
9972 if (is_symbol_die (die))
9974 if (comdat_symbol_id)
9976 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9978 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9979 comdat_symbol_id, comdat_symbol_number++);
9980 die->die_id.die_symbol = xstrdup (p);
9983 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9986 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9989 struct cu_hash_table_entry
9992 unsigned min_comdat_num, max_comdat_num;
9993 struct cu_hash_table_entry *next;
9996 /* Routines to manipulate hash table of CUs. */
9998 htab_cu_hash (const void *of)
10000 const struct cu_hash_table_entry *const entry =
10001 (const struct cu_hash_table_entry *) of;
10003 return htab_hash_string (entry->cu->die_id.die_symbol);
10007 htab_cu_eq (const void *of1, const void *of2)
10009 const struct cu_hash_table_entry *const entry1 =
10010 (const struct cu_hash_table_entry *) of1;
10011 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10013 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
10017 htab_cu_del (void *what)
10019 struct cu_hash_table_entry *next,
10020 *entry = (struct cu_hash_table_entry *) what;
10024 next = entry->next;
10030 /* Check whether we have already seen this CU and set up SYM_NUM
10033 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
10035 struct cu_hash_table_entry dummy;
10036 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
10038 dummy.max_comdat_num = 0;
10040 slot = (struct cu_hash_table_entry **)
10041 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
10045 for (; entry; last = entry, entry = entry->next)
10047 if (same_die_p_wrap (cu, entry->cu))
10053 *sym_num = entry->min_comdat_num;
10057 entry = XCNEW (struct cu_hash_table_entry);
10059 entry->min_comdat_num = *sym_num = last->max_comdat_num;
10060 entry->next = *slot;
10066 /* Record SYM_NUM to record of CU in HTABLE. */
10068 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
10070 struct cu_hash_table_entry **slot, *entry;
10072 slot = (struct cu_hash_table_entry **)
10073 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
10077 entry->max_comdat_num = sym_num;
10080 /* Traverse the DIE (which is always comp_unit_die), and set up
10081 additional compilation units for each of the include files we see
10082 bracketed by BINCL/EINCL. */
10085 break_out_includes (dw_die_ref die)
10088 dw_die_ref unit = NULL;
10089 limbo_die_node *node, **pnode;
10090 htab_t cu_hash_table;
10092 c = die->die_child;
10094 dw_die_ref prev = c;
10096 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
10097 || (unit && is_comdat_die (c)))
10099 dw_die_ref next = c->die_sib;
10101 /* This DIE is for a secondary CU; remove it from the main one. */
10102 remove_child_with_prev (c, prev);
10104 if (c->die_tag == DW_TAG_GNU_BINCL)
10105 unit = push_new_compile_unit (unit, c);
10106 else if (c->die_tag == DW_TAG_GNU_EINCL)
10107 unit = pop_compile_unit (unit);
10109 add_child_die (unit, c);
10111 if (c == die->die_child)
10114 } while (c != die->die_child);
10117 /* We can only use this in debugging, since the frontend doesn't check
10118 to make sure that we leave every include file we enter. */
10119 gcc_assert (!unit);
10122 assign_symbol_names (die);
10123 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
10124 for (node = limbo_die_list, pnode = &limbo_die_list;
10130 compute_section_prefix (node->die);
10131 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
10132 &comdat_symbol_number);
10133 assign_symbol_names (node->die);
10135 *pnode = node->next;
10138 pnode = &node->next;
10139 record_comdat_symbol_number (node->die, cu_hash_table,
10140 comdat_symbol_number);
10143 htab_delete (cu_hash_table);
10146 /* Return non-zero if this DIE is a declaration. */
10149 is_declaration_die (dw_die_ref die)
10154 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10155 if (a->dw_attr == DW_AT_declaration)
10161 /* Return non-zero if this DIE is nested inside a subprogram. */
10164 is_nested_in_subprogram (dw_die_ref die)
10166 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
10170 return local_scope_p (decl);
10173 /* Return non-zero if this DIE contains a defining declaration of a
10177 contains_subprogram_definition (dw_die_ref die)
10181 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
10183 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
10187 /* Return non-zero if this is a type DIE that should be moved to a
10188 COMDAT .debug_types section. */
10191 should_move_die_to_comdat (dw_die_ref die)
10193 switch (die->die_tag)
10195 case DW_TAG_class_type:
10196 case DW_TAG_structure_type:
10197 case DW_TAG_enumeration_type:
10198 case DW_TAG_union_type:
10199 /* Don't move declarations, inlined instances, or types nested in a
10201 if (is_declaration_die (die)
10202 || get_AT (die, DW_AT_abstract_origin)
10203 || is_nested_in_subprogram (die))
10205 /* A type definition should never contain a subprogram definition. */
10206 gcc_assert (!contains_subprogram_definition (die));
10208 case DW_TAG_array_type:
10209 case DW_TAG_interface_type:
10210 case DW_TAG_pointer_type:
10211 case DW_TAG_reference_type:
10212 case DW_TAG_rvalue_reference_type:
10213 case DW_TAG_string_type:
10214 case DW_TAG_subroutine_type:
10215 case DW_TAG_ptr_to_member_type:
10216 case DW_TAG_set_type:
10217 case DW_TAG_subrange_type:
10218 case DW_TAG_base_type:
10219 case DW_TAG_const_type:
10220 case DW_TAG_file_type:
10221 case DW_TAG_packed_type:
10222 case DW_TAG_volatile_type:
10223 case DW_TAG_typedef:
10229 /* Make a clone of DIE. */
10232 clone_die (dw_die_ref die)
10238 clone = ggc_alloc_cleared_die_node ();
10239 clone->die_tag = die->die_tag;
10241 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10242 add_dwarf_attr (clone, a);
10247 /* Make a clone of the tree rooted at DIE. */
10250 clone_tree (dw_die_ref die)
10253 dw_die_ref clone = clone_die (die);
10255 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10260 /* Make a clone of DIE as a declaration. */
10263 clone_as_declaration (dw_die_ref die)
10270 /* If the DIE is already a declaration, just clone it. */
10271 if (is_declaration_die (die))
10272 return clone_die (die);
10274 /* If the DIE is a specification, just clone its declaration DIE. */
10275 decl = get_AT_ref (die, DW_AT_specification);
10277 return clone_die (decl);
10279 clone = ggc_alloc_cleared_die_node ();
10280 clone->die_tag = die->die_tag;
10282 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10284 /* We don't want to copy over all attributes.
10285 For example we don't want DW_AT_byte_size because otherwise we will no
10286 longer have a declaration and GDB will treat it as a definition. */
10288 switch (a->dw_attr)
10290 case DW_AT_artificial:
10291 case DW_AT_containing_type:
10292 case DW_AT_external:
10295 case DW_AT_virtuality:
10296 case DW_AT_linkage_name:
10297 case DW_AT_MIPS_linkage_name:
10298 add_dwarf_attr (clone, a);
10300 case DW_AT_byte_size:
10306 if (die->die_id.die_type_node)
10307 add_AT_die_ref (clone, DW_AT_signature, die);
10309 add_AT_flag (clone, DW_AT_declaration, 1);
10313 /* Copy the declaration context to the new compile unit DIE. This includes
10314 any surrounding namespace or type declarations. If the DIE has an
10315 AT_specification attribute, it also includes attributes and children
10316 attached to the specification. */
10319 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10322 dw_die_ref new_decl;
10324 decl = get_AT_ref (die, DW_AT_specification);
10333 /* Copy the type node pointer from the new DIE to the original
10334 declaration DIE so we can forward references later. */
10335 decl->die_id.die_type_node = die->die_id.die_type_node;
10337 remove_AT (die, DW_AT_specification);
10339 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10341 if (a->dw_attr != DW_AT_name
10342 && a->dw_attr != DW_AT_declaration
10343 && a->dw_attr != DW_AT_external)
10344 add_dwarf_attr (die, a);
10347 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10350 if (decl->die_parent != NULL
10351 && decl->die_parent->die_tag != DW_TAG_compile_unit
10352 && decl->die_parent->die_tag != DW_TAG_type_unit)
10354 new_decl = copy_ancestor_tree (unit, decl, NULL);
10355 if (new_decl != NULL)
10357 remove_AT (new_decl, DW_AT_signature);
10358 add_AT_specification (die, new_decl);
10363 /* Generate the skeleton ancestor tree for the given NODE, then clone
10364 the DIE and add the clone into the tree. */
10367 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10369 if (node->new_die != NULL)
10372 node->new_die = clone_as_declaration (node->old_die);
10374 if (node->parent != NULL)
10376 generate_skeleton_ancestor_tree (node->parent);
10377 add_child_die (node->parent->new_die, node->new_die);
10381 /* Generate a skeleton tree of DIEs containing any declarations that are
10382 found in the original tree. We traverse the tree looking for declaration
10383 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10386 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10388 skeleton_chain_node node;
10391 dw_die_ref prev = NULL;
10392 dw_die_ref next = NULL;
10394 node.parent = parent;
10396 first = c = parent->old_die->die_child;
10400 if (prev == NULL || prev->die_sib == c)
10403 next = (c == first ? NULL : c->die_sib);
10405 node.new_die = NULL;
10406 if (is_declaration_die (c))
10408 /* Clone the existing DIE, move the original to the skeleton
10409 tree (which is in the main CU), and put the clone, with
10410 all the original's children, where the original came from. */
10411 dw_die_ref clone = clone_die (c);
10412 move_all_children (c, clone);
10414 replace_child (c, clone, prev);
10415 generate_skeleton_ancestor_tree (parent);
10416 add_child_die (parent->new_die, c);
10420 generate_skeleton_bottom_up (&node);
10421 } while (next != NULL);
10424 /* Wrapper function for generate_skeleton_bottom_up. */
10427 generate_skeleton (dw_die_ref die)
10429 skeleton_chain_node node;
10431 node.old_die = die;
10432 node.new_die = NULL;
10433 node.parent = NULL;
10435 /* If this type definition is nested inside another type,
10436 always leave at least a declaration in its place. */
10437 if (die->die_parent != NULL && is_type_die (die->die_parent))
10438 node.new_die = clone_as_declaration (die);
10440 generate_skeleton_bottom_up (&node);
10441 return node.new_die;
10444 /* Remove the DIE from its parent, possibly replacing it with a cloned
10445 declaration. The original DIE will be moved to a new compile unit
10446 so that existing references to it follow it to the new location. If
10447 any of the original DIE's descendants is a declaration, we need to
10448 replace the original DIE with a skeleton tree and move the
10449 declarations back into the skeleton tree. */
10452 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10454 dw_die_ref skeleton;
10456 skeleton = generate_skeleton (child);
10457 if (skeleton == NULL)
10458 remove_child_with_prev (child, prev);
10461 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10462 replace_child (child, skeleton, prev);
10468 /* Traverse the DIE and set up additional .debug_types sections for each
10469 type worthy of being placed in a COMDAT section. */
10472 break_out_comdat_types (dw_die_ref die)
10476 dw_die_ref prev = NULL;
10477 dw_die_ref next = NULL;
10478 dw_die_ref unit = NULL;
10480 first = c = die->die_child;
10484 if (prev == NULL || prev->die_sib == c)
10487 next = (c == first ? NULL : c->die_sib);
10488 if (should_move_die_to_comdat (c))
10490 dw_die_ref replacement;
10491 comdat_type_node_ref type_node;
10493 /* Create a new type unit DIE as the root for the new tree, and
10494 add it to the list of comdat types. */
10495 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10496 add_AT_unsigned (unit, DW_AT_language,
10497 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10498 type_node = ggc_alloc_cleared_comdat_type_node ();
10499 type_node->root_die = unit;
10500 type_node->next = comdat_type_list;
10501 comdat_type_list = type_node;
10503 /* Generate the type signature. */
10504 generate_type_signature (c, type_node);
10506 /* Copy the declaration context, attributes, and children of the
10507 declaration into the new compile unit DIE. */
10508 copy_declaration_context (unit, c);
10510 /* Remove this DIE from the main CU. */
10511 replacement = remove_child_or_replace_with_skeleton (c, prev);
10513 /* Break out nested types into their own type units. */
10514 break_out_comdat_types (c);
10516 /* Add the DIE to the new compunit. */
10517 add_child_die (unit, c);
10519 if (replacement != NULL)
10522 else if (c->die_tag == DW_TAG_namespace
10523 || c->die_tag == DW_TAG_class_type
10524 || c->die_tag == DW_TAG_structure_type
10525 || c->die_tag == DW_TAG_union_type)
10527 /* Look for nested types that can be broken out. */
10528 break_out_comdat_types (c);
10530 } while (next != NULL);
10533 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10535 struct decl_table_entry
10541 /* Routines to manipulate hash table of copied declarations. */
10544 htab_decl_hash (const void *of)
10546 const struct decl_table_entry *const entry =
10547 (const struct decl_table_entry *) of;
10549 return htab_hash_pointer (entry->orig);
10553 htab_decl_eq (const void *of1, const void *of2)
10555 const struct decl_table_entry *const entry1 =
10556 (const struct decl_table_entry *) of1;
10557 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10559 return entry1->orig == entry2;
10563 htab_decl_del (void *what)
10565 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10570 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10571 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10572 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10573 to check if the ancestor has already been copied into UNIT. */
10576 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10578 dw_die_ref parent = die->die_parent;
10579 dw_die_ref new_parent = unit;
10581 void **slot = NULL;
10582 struct decl_table_entry *entry = NULL;
10586 /* Check if the entry has already been copied to UNIT. */
10587 slot = htab_find_slot_with_hash (decl_table, die,
10588 htab_hash_pointer (die), INSERT);
10589 if (*slot != HTAB_EMPTY_ENTRY)
10591 entry = (struct decl_table_entry *) *slot;
10592 return entry->copy;
10595 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10596 entry = XCNEW (struct decl_table_entry);
10598 entry->copy = NULL;
10602 if (parent != NULL)
10604 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10607 if (parent->die_tag != DW_TAG_compile_unit
10608 && parent->die_tag != DW_TAG_type_unit)
10609 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10612 copy = clone_as_declaration (die);
10613 add_child_die (new_parent, copy);
10615 if (decl_table != NULL)
10617 /* Record the pointer to the copy. */
10618 entry->copy = copy;
10624 /* Walk the DIE and its children, looking for references to incomplete
10625 or trivial types that are unmarked (i.e., that are not in the current
10629 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10635 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10637 if (AT_class (a) == dw_val_class_die_ref)
10639 dw_die_ref targ = AT_ref (a);
10640 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10642 struct decl_table_entry *entry;
10644 if (targ->die_mark != 0 || type_node != NULL)
10647 slot = htab_find_slot_with_hash (decl_table, targ,
10648 htab_hash_pointer (targ), INSERT);
10650 if (*slot != HTAB_EMPTY_ENTRY)
10652 /* TARG has already been copied, so we just need to
10653 modify the reference to point to the copy. */
10654 entry = (struct decl_table_entry *) *slot;
10655 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10659 dw_die_ref parent = unit;
10660 dw_die_ref copy = clone_tree (targ);
10662 /* Make sure the cloned tree is marked as part of the
10666 /* Record in DECL_TABLE that TARG has been copied.
10667 Need to do this now, before the recursive call,
10668 because DECL_TABLE may be expanded and SLOT
10669 would no longer be a valid pointer. */
10670 entry = XCNEW (struct decl_table_entry);
10671 entry->orig = targ;
10672 entry->copy = copy;
10675 /* If TARG has surrounding context, copy its ancestor tree
10676 into the new type unit. */
10677 if (targ->die_parent != NULL
10678 && targ->die_parent->die_tag != DW_TAG_compile_unit
10679 && targ->die_parent->die_tag != DW_TAG_type_unit)
10680 parent = copy_ancestor_tree (unit, targ->die_parent,
10683 add_child_die (parent, copy);
10684 a->dw_attr_val.v.val_die_ref.die = copy;
10686 /* Make sure the newly-copied DIE is walked. If it was
10687 installed in a previously-added context, it won't
10688 get visited otherwise. */
10689 if (parent != unit)
10691 /* Find the highest point of the newly-added tree,
10692 mark each node along the way, and walk from there. */
10693 parent->die_mark = 1;
10694 while (parent->die_parent
10695 && parent->die_parent->die_mark == 0)
10697 parent = parent->die_parent;
10698 parent->die_mark = 1;
10700 copy_decls_walk (unit, parent, decl_table);
10706 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10709 /* Copy declarations for "unworthy" types into the new comdat section.
10710 Incomplete types, modified types, and certain other types aren't broken
10711 out into comdat sections of their own, so they don't have a signature,
10712 and we need to copy the declaration into the same section so that we
10713 don't have an external reference. */
10716 copy_decls_for_unworthy_types (dw_die_ref unit)
10721 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10722 copy_decls_walk (unit, unit, decl_table);
10723 htab_delete (decl_table);
10724 unmark_dies (unit);
10727 /* Traverse the DIE and add a sibling attribute if it may have the
10728 effect of speeding up access to siblings. To save some space,
10729 avoid generating sibling attributes for DIE's without children. */
10732 add_sibling_attributes (dw_die_ref die)
10736 if (! die->die_child)
10739 if (die->die_parent && die != die->die_parent->die_child)
10740 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10742 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10745 /* Output all location lists for the DIE and its children. */
10748 output_location_lists (dw_die_ref die)
10754 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10755 if (AT_class (a) == dw_val_class_loc_list)
10756 output_loc_list (AT_loc_list (a));
10758 FOR_EACH_CHILD (die, c, output_location_lists (c));
10761 /* The format of each DIE (and its attribute value pairs) is encoded in an
10762 abbreviation table. This routine builds the abbreviation table and assigns
10763 a unique abbreviation id for each abbreviation entry. The children of each
10764 die are visited recursively. */
10767 build_abbrev_table (dw_die_ref die)
10769 unsigned long abbrev_id;
10770 unsigned int n_alloc;
10775 /* Scan the DIE references, and mark as external any that refer to
10776 DIEs from other CUs (i.e. those which are not marked). */
10777 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10778 if (AT_class (a) == dw_val_class_die_ref
10779 && AT_ref (a)->die_mark == 0)
10781 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
10782 set_AT_ref_external (a, 1);
10785 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10787 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10788 dw_attr_ref die_a, abbrev_a;
10792 if (abbrev->die_tag != die->die_tag)
10794 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10797 if (VEC_length (dw_attr_node, abbrev->die_attr)
10798 != VEC_length (dw_attr_node, die->die_attr))
10801 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10803 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10804 if ((abbrev_a->dw_attr != die_a->dw_attr)
10805 || (value_format (abbrev_a) != value_format (die_a)))
10815 if (abbrev_id >= abbrev_die_table_in_use)
10817 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10819 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10820 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10823 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10824 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10825 abbrev_die_table_allocated = n_alloc;
10828 ++abbrev_die_table_in_use;
10829 abbrev_die_table[abbrev_id] = die;
10832 die->die_abbrev = abbrev_id;
10833 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10836 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10839 constant_size (unsigned HOST_WIDE_INT value)
10846 log = floor_log2 (value);
10849 log = 1 << (floor_log2 (log) + 1);
10854 /* Return the size of a DIE as it is represented in the
10855 .debug_info section. */
10857 static unsigned long
10858 size_of_die (dw_die_ref die)
10860 unsigned long size = 0;
10864 size += size_of_uleb128 (die->die_abbrev);
10865 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10867 switch (AT_class (a))
10869 case dw_val_class_addr:
10870 size += DWARF2_ADDR_SIZE;
10872 case dw_val_class_offset:
10873 size += DWARF_OFFSET_SIZE;
10875 case dw_val_class_loc:
10877 unsigned long lsize = size_of_locs (AT_loc (a));
10879 /* Block length. */
10880 if (dwarf_version >= 4)
10881 size += size_of_uleb128 (lsize);
10883 size += constant_size (lsize);
10887 case dw_val_class_loc_list:
10888 size += DWARF_OFFSET_SIZE;
10890 case dw_val_class_range_list:
10891 size += DWARF_OFFSET_SIZE;
10893 case dw_val_class_const:
10894 size += size_of_sleb128 (AT_int (a));
10896 case dw_val_class_unsigned_const:
10897 size += constant_size (AT_unsigned (a));
10899 case dw_val_class_const_double:
10900 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10901 if (HOST_BITS_PER_WIDE_INT >= 64)
10902 size++; /* block */
10904 case dw_val_class_vec:
10905 size += constant_size (a->dw_attr_val.v.val_vec.length
10906 * a->dw_attr_val.v.val_vec.elt_size)
10907 + a->dw_attr_val.v.val_vec.length
10908 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10910 case dw_val_class_flag:
10911 if (dwarf_version >= 4)
10912 /* Currently all add_AT_flag calls pass in 1 as last argument,
10913 so DW_FORM_flag_present can be used. If that ever changes,
10914 we'll need to use DW_FORM_flag and have some optimization
10915 in build_abbrev_table that will change those to
10916 DW_FORM_flag_present if it is set to 1 in all DIEs using
10917 the same abbrev entry. */
10918 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10922 case dw_val_class_die_ref:
10923 if (AT_ref_external (a))
10925 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
10926 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10927 is sized by target address length, whereas in DWARF3
10928 it's always sized as an offset. */
10929 if (use_debug_types)
10930 size += DWARF_TYPE_SIGNATURE_SIZE;
10931 else if (dwarf_version == 2)
10932 size += DWARF2_ADDR_SIZE;
10934 size += DWARF_OFFSET_SIZE;
10937 size += DWARF_OFFSET_SIZE;
10939 case dw_val_class_fde_ref:
10940 size += DWARF_OFFSET_SIZE;
10942 case dw_val_class_lbl_id:
10943 size += DWARF2_ADDR_SIZE;
10945 case dw_val_class_lineptr:
10946 case dw_val_class_macptr:
10947 size += DWARF_OFFSET_SIZE;
10949 case dw_val_class_str:
10950 if (AT_string_form (a) == DW_FORM_strp)
10951 size += DWARF_OFFSET_SIZE;
10953 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10955 case dw_val_class_file:
10956 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10958 case dw_val_class_data8:
10961 case dw_val_class_vms_delta:
10962 size += DWARF_OFFSET_SIZE;
10965 gcc_unreachable ();
10972 /* Size the debugging information associated with a given DIE. Visits the
10973 DIE's children recursively. Updates the global variable next_die_offset, on
10974 each time through. Uses the current value of next_die_offset to update the
10975 die_offset field in each DIE. */
10978 calc_die_sizes (dw_die_ref die)
10982 gcc_assert (die->die_offset == 0
10983 || (unsigned long int) die->die_offset == next_die_offset);
10984 die->die_offset = next_die_offset;
10985 next_die_offset += size_of_die (die);
10987 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10989 if (die->die_child != NULL)
10990 /* Count the null byte used to terminate sibling lists. */
10991 next_die_offset += 1;
10994 /* Size just the base type children at the start of the CU.
10995 This is needed because build_abbrev needs to size locs
10996 and sizing of type based stack ops needs to know die_offset
10997 values for the base types. */
11000 calc_base_type_die_sizes (void)
11002 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11004 dw_die_ref base_type;
11005 #if ENABLE_ASSERT_CHECKING
11006 dw_die_ref prev = comp_unit_die ()->die_child;
11009 die_offset += size_of_die (comp_unit_die ());
11010 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
11012 #if ENABLE_ASSERT_CHECKING
11013 gcc_assert (base_type->die_offset == 0
11014 && prev->die_sib == base_type
11015 && base_type->die_child == NULL
11016 && base_type->die_abbrev);
11019 base_type->die_offset = die_offset;
11020 die_offset += size_of_die (base_type);
11024 /* Set the marks for a die and its children. We do this so
11025 that we know whether or not a reference needs to use FORM_ref_addr; only
11026 DIEs in the same CU will be marked. We used to clear out the offset
11027 and use that as the flag, but ran into ordering problems. */
11030 mark_dies (dw_die_ref die)
11034 gcc_assert (!die->die_mark);
11037 FOR_EACH_CHILD (die, c, mark_dies (c));
11040 /* Clear the marks for a die and its children. */
11043 unmark_dies (dw_die_ref die)
11047 if (! use_debug_types)
11048 gcc_assert (die->die_mark);
11051 FOR_EACH_CHILD (die, c, unmark_dies (c));
11054 /* Clear the marks for a die, its children and referred dies. */
11057 unmark_all_dies (dw_die_ref die)
11063 if (!die->die_mark)
11067 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
11069 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11070 if (AT_class (a) == dw_val_class_die_ref)
11071 unmark_all_dies (AT_ref (a));
11074 /* Return the size of the .debug_pubnames or .debug_pubtypes table
11075 generated for the compilation unit. */
11077 static unsigned long
11078 size_of_pubnames (VEC (pubname_entry, gc) * names)
11080 unsigned long size;
11084 size = DWARF_PUBNAMES_HEADER_SIZE;
11085 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
11086 if (names != pubtype_table
11087 || p->die->die_offset != 0
11088 || !flag_eliminate_unused_debug_types)
11089 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
11091 size += DWARF_OFFSET_SIZE;
11095 /* Return the size of the information in the .debug_aranges section. */
11097 static unsigned long
11098 size_of_aranges (void)
11100 unsigned long size;
11102 size = DWARF_ARANGES_HEADER_SIZE;
11104 /* Count the address/length pair for this compilation unit. */
11105 if (text_section_used)
11106 size += 2 * DWARF2_ADDR_SIZE;
11107 if (cold_text_section_used)
11108 size += 2 * DWARF2_ADDR_SIZE;
11109 if (have_multiple_function_sections)
11111 unsigned fde_idx = 0;
11113 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
11115 dw_fde_ref fde = &fde_table[fde_idx];
11117 if (!fde->in_std_section)
11118 size += 2 * DWARF2_ADDR_SIZE;
11119 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11120 size += 2 * DWARF2_ADDR_SIZE;
11124 /* Count the two zero words used to terminated the address range table. */
11125 size += 2 * DWARF2_ADDR_SIZE;
11129 /* Select the encoding of an attribute value. */
11131 static enum dwarf_form
11132 value_format (dw_attr_ref a)
11134 switch (a->dw_attr_val.val_class)
11136 case dw_val_class_addr:
11137 /* Only very few attributes allow DW_FORM_addr. */
11138 switch (a->dw_attr)
11141 case DW_AT_high_pc:
11142 case DW_AT_entry_pc:
11143 case DW_AT_trampoline:
11144 return DW_FORM_addr;
11148 switch (DWARF2_ADDR_SIZE)
11151 return DW_FORM_data1;
11153 return DW_FORM_data2;
11155 return DW_FORM_data4;
11157 return DW_FORM_data8;
11159 gcc_unreachable ();
11161 case dw_val_class_range_list:
11162 case dw_val_class_loc_list:
11163 if (dwarf_version >= 4)
11164 return DW_FORM_sec_offset;
11166 case dw_val_class_vms_delta:
11167 case dw_val_class_offset:
11168 switch (DWARF_OFFSET_SIZE)
11171 return DW_FORM_data4;
11173 return DW_FORM_data8;
11175 gcc_unreachable ();
11177 case dw_val_class_loc:
11178 if (dwarf_version >= 4)
11179 return DW_FORM_exprloc;
11180 switch (constant_size (size_of_locs (AT_loc (a))))
11183 return DW_FORM_block1;
11185 return DW_FORM_block2;
11187 gcc_unreachable ();
11189 case dw_val_class_const:
11190 return DW_FORM_sdata;
11191 case dw_val_class_unsigned_const:
11192 switch (constant_size (AT_unsigned (a)))
11195 return DW_FORM_data1;
11197 return DW_FORM_data2;
11199 return DW_FORM_data4;
11201 return DW_FORM_data8;
11203 gcc_unreachable ();
11205 case dw_val_class_const_double:
11206 switch (HOST_BITS_PER_WIDE_INT)
11209 return DW_FORM_data2;
11211 return DW_FORM_data4;
11213 return DW_FORM_data8;
11216 return DW_FORM_block1;
11218 case dw_val_class_vec:
11219 switch (constant_size (a->dw_attr_val.v.val_vec.length
11220 * a->dw_attr_val.v.val_vec.elt_size))
11223 return DW_FORM_block1;
11225 return DW_FORM_block2;
11227 return DW_FORM_block4;
11229 gcc_unreachable ();
11231 case dw_val_class_flag:
11232 if (dwarf_version >= 4)
11234 /* Currently all add_AT_flag calls pass in 1 as last argument,
11235 so DW_FORM_flag_present can be used. If that ever changes,
11236 we'll need to use DW_FORM_flag and have some optimization
11237 in build_abbrev_table that will change those to
11238 DW_FORM_flag_present if it is set to 1 in all DIEs using
11239 the same abbrev entry. */
11240 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11241 return DW_FORM_flag_present;
11243 return DW_FORM_flag;
11244 case dw_val_class_die_ref:
11245 if (AT_ref_external (a))
11246 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
11248 return DW_FORM_ref;
11249 case dw_val_class_fde_ref:
11250 return DW_FORM_data;
11251 case dw_val_class_lbl_id:
11252 return DW_FORM_addr;
11253 case dw_val_class_lineptr:
11254 case dw_val_class_macptr:
11255 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11256 case dw_val_class_str:
11257 return AT_string_form (a);
11258 case dw_val_class_file:
11259 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11262 return DW_FORM_data1;
11264 return DW_FORM_data2;
11266 return DW_FORM_data4;
11268 gcc_unreachable ();
11271 case dw_val_class_data8:
11272 return DW_FORM_data8;
11275 gcc_unreachable ();
11279 /* Output the encoding of an attribute value. */
11282 output_value_format (dw_attr_ref a)
11284 enum dwarf_form form = value_format (a);
11286 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11289 /* Output the .debug_abbrev section which defines the DIE abbreviation
11293 output_abbrev_section (void)
11295 unsigned long abbrev_id;
11297 if (abbrev_die_table_in_use == 1)
11300 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11302 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11304 dw_attr_ref a_attr;
11306 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11307 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11308 dwarf_tag_name (abbrev->die_tag));
11310 if (abbrev->die_child != NULL)
11311 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11313 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11315 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11318 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11319 dwarf_attr_name (a_attr->dw_attr));
11320 output_value_format (a_attr);
11323 dw2_asm_output_data (1, 0, NULL);
11324 dw2_asm_output_data (1, 0, NULL);
11327 /* Terminate the table. */
11328 dw2_asm_output_data (1, 0, NULL);
11331 /* Output a symbol we can use to refer to this DIE from another CU. */
11334 output_die_symbol (dw_die_ref die)
11336 char *sym = die->die_id.die_symbol;
11341 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11342 /* We make these global, not weak; if the target doesn't support
11343 .linkonce, it doesn't support combining the sections, so debugging
11345 targetm.asm_out.globalize_label (asm_out_file, sym);
11347 ASM_OUTPUT_LABEL (asm_out_file, sym);
11350 /* Return a new location list, given the begin and end range, and the
11353 static inline dw_loc_list_ref
11354 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11355 const char *section)
11357 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11359 retlist->begin = begin;
11360 retlist->end = end;
11361 retlist->expr = expr;
11362 retlist->section = section;
11367 /* Generate a new internal symbol for this location list node, if it
11368 hasn't got one yet. */
11371 gen_llsym (dw_loc_list_ref list)
11373 gcc_assert (!list->ll_symbol);
11374 list->ll_symbol = gen_internal_sym ("LLST");
11377 /* Output the location list given to us. */
11380 output_loc_list (dw_loc_list_ref list_head)
11382 dw_loc_list_ref curr = list_head;
11384 if (list_head->emitted)
11386 list_head->emitted = true;
11388 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11390 /* Walk the location list, and output each range + expression. */
11391 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11393 unsigned long size;
11394 /* Don't output an entry that starts and ends at the same address. */
11395 if (strcmp (curr->begin, curr->end) == 0)
11397 if (!have_multiple_function_sections)
11399 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11400 "Location list begin address (%s)",
11401 list_head->ll_symbol);
11402 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11403 "Location list end address (%s)",
11404 list_head->ll_symbol);
11408 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11409 "Location list begin address (%s)",
11410 list_head->ll_symbol);
11411 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11412 "Location list end address (%s)",
11413 list_head->ll_symbol);
11415 size = size_of_locs (curr->expr);
11417 /* Output the block length for this list of location operations. */
11418 gcc_assert (size <= 0xffff);
11419 dw2_asm_output_data (2, size, "%s", "Location expression size");
11421 output_loc_sequence (curr->expr, -1);
11424 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11425 "Location list terminator begin (%s)",
11426 list_head->ll_symbol);
11427 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11428 "Location list terminator end (%s)",
11429 list_head->ll_symbol);
11432 /* Output a type signature. */
11435 output_signature (const char *sig, const char *name)
11439 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11440 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11443 /* Output the DIE and its attributes. Called recursively to generate
11444 the definitions of each child DIE. */
11447 output_die (dw_die_ref die)
11451 unsigned long size;
11454 /* If someone in another CU might refer to us, set up a symbol for
11455 them to point to. */
11456 if (! use_debug_types && die->die_id.die_symbol)
11457 output_die_symbol (die);
11459 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11460 (unsigned long)die->die_offset,
11461 dwarf_tag_name (die->die_tag));
11463 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11465 const char *name = dwarf_attr_name (a->dw_attr);
11467 switch (AT_class (a))
11469 case dw_val_class_addr:
11470 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11473 case dw_val_class_offset:
11474 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11478 case dw_val_class_range_list:
11480 char *p = strchr (ranges_section_label, '\0');
11482 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11483 a->dw_attr_val.v.val_offset);
11484 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11485 debug_ranges_section, "%s", name);
11490 case dw_val_class_loc:
11491 size = size_of_locs (AT_loc (a));
11493 /* Output the block length for this list of location operations. */
11494 if (dwarf_version >= 4)
11495 dw2_asm_output_data_uleb128 (size, "%s", name);
11497 dw2_asm_output_data (constant_size (size), size, "%s", name);
11499 output_loc_sequence (AT_loc (a), -1);
11502 case dw_val_class_const:
11503 /* ??? It would be slightly more efficient to use a scheme like is
11504 used for unsigned constants below, but gdb 4.x does not sign
11505 extend. Gdb 5.x does sign extend. */
11506 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11509 case dw_val_class_unsigned_const:
11510 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11511 AT_unsigned (a), "%s", name);
11514 case dw_val_class_const_double:
11516 unsigned HOST_WIDE_INT first, second;
11518 if (HOST_BITS_PER_WIDE_INT >= 64)
11519 dw2_asm_output_data (1,
11520 2 * HOST_BITS_PER_WIDE_INT
11521 / HOST_BITS_PER_CHAR,
11524 if (WORDS_BIG_ENDIAN)
11526 first = a->dw_attr_val.v.val_double.high;
11527 second = a->dw_attr_val.v.val_double.low;
11531 first = a->dw_attr_val.v.val_double.low;
11532 second = a->dw_attr_val.v.val_double.high;
11535 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11537 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11542 case dw_val_class_vec:
11544 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11545 unsigned int len = a->dw_attr_val.v.val_vec.length;
11549 dw2_asm_output_data (constant_size (len * elt_size),
11550 len * elt_size, "%s", name);
11551 if (elt_size > sizeof (HOST_WIDE_INT))
11556 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11558 i++, p += elt_size)
11559 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11560 "fp or vector constant word %u", i);
11564 case dw_val_class_flag:
11565 if (dwarf_version >= 4)
11567 /* Currently all add_AT_flag calls pass in 1 as last argument,
11568 so DW_FORM_flag_present can be used. If that ever changes,
11569 we'll need to use DW_FORM_flag and have some optimization
11570 in build_abbrev_table that will change those to
11571 DW_FORM_flag_present if it is set to 1 in all DIEs using
11572 the same abbrev entry. */
11573 gcc_assert (AT_flag (a) == 1);
11574 if (flag_debug_asm)
11575 fprintf (asm_out_file, "\t\t\t%s %s\n",
11576 ASM_COMMENT_START, name);
11579 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11582 case dw_val_class_loc_list:
11584 char *sym = AT_loc_list (a)->ll_symbol;
11587 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11592 case dw_val_class_die_ref:
11593 if (AT_ref_external (a))
11595 if (use_debug_types)
11597 comdat_type_node_ref type_node =
11598 AT_ref (a)->die_id.die_type_node;
11600 gcc_assert (type_node);
11601 output_signature (type_node->signature, name);
11605 char *sym = AT_ref (a)->die_id.die_symbol;
11609 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11610 length, whereas in DWARF3 it's always sized as an
11612 if (dwarf_version == 2)
11613 size = DWARF2_ADDR_SIZE;
11615 size = DWARF_OFFSET_SIZE;
11616 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11622 gcc_assert (AT_ref (a)->die_offset);
11623 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11628 case dw_val_class_fde_ref:
11632 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11633 a->dw_attr_val.v.val_fde_index * 2);
11634 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11639 case dw_val_class_vms_delta:
11640 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11641 AT_vms_delta2 (a), AT_vms_delta1 (a),
11645 case dw_val_class_lbl_id:
11646 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11649 case dw_val_class_lineptr:
11650 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11651 debug_line_section, "%s", name);
11654 case dw_val_class_macptr:
11655 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11656 debug_macinfo_section, "%s", name);
11659 case dw_val_class_str:
11660 if (AT_string_form (a) == DW_FORM_strp)
11661 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11662 a->dw_attr_val.v.val_str->label,
11664 "%s: \"%s\"", name, AT_string (a));
11666 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11669 case dw_val_class_file:
11671 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11673 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11674 a->dw_attr_val.v.val_file->filename);
11678 case dw_val_class_data8:
11682 for (i = 0; i < 8; i++)
11683 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11684 i == 0 ? "%s" : NULL, name);
11689 gcc_unreachable ();
11693 FOR_EACH_CHILD (die, c, output_die (c));
11695 /* Add null byte to terminate sibling list. */
11696 if (die->die_child != NULL)
11697 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11698 (unsigned long) die->die_offset);
11701 /* Output the compilation unit that appears at the beginning of the
11702 .debug_info section, and precedes the DIE descriptions. */
11705 output_compilation_unit_header (void)
11707 int ver = dwarf_version;
11709 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11710 dw2_asm_output_data (4, 0xffffffff,
11711 "Initial length escape value indicating 64-bit DWARF extension");
11712 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11713 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11714 "Length of Compilation Unit Info");
11715 dw2_asm_output_data (2, ver, "DWARF version number");
11716 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11717 debug_abbrev_section,
11718 "Offset Into Abbrev. Section");
11719 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11722 /* Output the compilation unit DIE and its children. */
11725 output_comp_unit (dw_die_ref die, int output_if_empty)
11727 const char *secname;
11728 char *oldsym, *tmp;
11730 /* Unless we are outputting main CU, we may throw away empty ones. */
11731 if (!output_if_empty && die->die_child == NULL)
11734 /* Even if there are no children of this DIE, we must output the information
11735 about the compilation unit. Otherwise, on an empty translation unit, we
11736 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11737 will then complain when examining the file. First mark all the DIEs in
11738 this CU so we know which get local refs. */
11741 build_abbrev_table (die);
11743 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11744 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11745 calc_die_sizes (die);
11747 oldsym = die->die_id.die_symbol;
11750 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11752 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11754 die->die_id.die_symbol = NULL;
11755 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11759 switch_to_section (debug_info_section);
11760 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11761 info_section_emitted = true;
11764 /* Output debugging information. */
11765 output_compilation_unit_header ();
11768 /* Leave the marks on the main CU, so we can check them in
11769 output_pubnames. */
11773 die->die_id.die_symbol = oldsym;
11777 /* Output a comdat type unit DIE and its children. */
11780 output_comdat_type_unit (comdat_type_node *node)
11782 const char *secname;
11785 #if defined (OBJECT_FORMAT_ELF)
11789 /* First mark all the DIEs in this CU so we know which get local refs. */
11790 mark_dies (node->root_die);
11792 build_abbrev_table (node->root_die);
11794 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11795 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11796 calc_die_sizes (node->root_die);
11798 #if defined (OBJECT_FORMAT_ELF)
11799 secname = ".debug_types";
11800 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11801 sprintf (tmp, "wt.");
11802 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11803 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11804 comdat_key = get_identifier (tmp);
11805 targetm.asm_out.named_section (secname,
11806 SECTION_DEBUG | SECTION_LINKONCE,
11809 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11810 sprintf (tmp, ".gnu.linkonce.wt.");
11811 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11812 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11814 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11817 /* Output debugging information. */
11818 output_compilation_unit_header ();
11819 output_signature (node->signature, "Type Signature");
11820 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11821 "Offset to Type DIE");
11822 output_die (node->root_die);
11824 unmark_dies (node->root_die);
11827 /* Return the DWARF2/3 pubname associated with a decl. */
11829 static const char *
11830 dwarf2_name (tree decl, int scope)
11832 if (DECL_NAMELESS (decl))
11834 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11837 /* Add a new entry to .debug_pubnames if appropriate. */
11840 add_pubname_string (const char *str, dw_die_ref die)
11842 if (targetm.want_debug_pub_sections)
11847 e.name = xstrdup (str);
11848 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11853 add_pubname (tree decl, dw_die_ref die)
11855 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11857 const char *name = dwarf2_name (decl, 1);
11859 add_pubname_string (name, die);
11863 /* Add a new entry to .debug_pubtypes if appropriate. */
11866 add_pubtype (tree decl, dw_die_ref die)
11870 if (!targetm.want_debug_pub_sections)
11874 if ((TREE_PUBLIC (decl)
11875 || is_cu_die (die->die_parent))
11876 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11881 if (TYPE_NAME (decl))
11883 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11884 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11885 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11886 && DECL_NAME (TYPE_NAME (decl)))
11887 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11889 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11894 e.name = dwarf2_name (decl, 1);
11896 e.name = xstrdup (e.name);
11899 /* If we don't have a name for the type, there's no point in adding
11900 it to the table. */
11901 if (e.name && e.name[0] != '\0')
11902 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11906 /* Output the public names table used to speed up access to externally
11907 visible names; or the public types table used to find type definitions. */
11910 output_pubnames (VEC (pubname_entry, gc) * names)
11913 unsigned long pubnames_length = size_of_pubnames (names);
11916 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11917 dw2_asm_output_data (4, 0xffffffff,
11918 "Initial length escape value indicating 64-bit DWARF extension");
11919 if (names == pubname_table)
11920 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11921 "Length of Public Names Info");
11923 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11924 "Length of Public Type Names Info");
11925 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11926 dw2_asm_output_data (2, 2, "DWARF Version");
11927 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11928 debug_info_section,
11929 "Offset of Compilation Unit Info");
11930 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11931 "Compilation Unit Length");
11933 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11935 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11936 if (names == pubname_table)
11937 gcc_assert (pub->die->die_mark);
11939 if (names != pubtype_table
11940 || pub->die->die_offset != 0
11941 || !flag_eliminate_unused_debug_types)
11943 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11946 dw2_asm_output_nstring (pub->name, -1, "external name");
11950 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11953 /* Output the information that goes into the .debug_aranges table.
11954 Namely, define the beginning and ending address range of the
11955 text section generated for this compilation unit. */
11958 output_aranges (unsigned long aranges_length)
11962 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11963 dw2_asm_output_data (4, 0xffffffff,
11964 "Initial length escape value indicating 64-bit DWARF extension");
11965 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11966 "Length of Address Ranges Info");
11967 /* Version number for aranges is still 2, even in DWARF3. */
11968 dw2_asm_output_data (2, 2, "DWARF Version");
11969 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11970 debug_info_section,
11971 "Offset of Compilation Unit Info");
11972 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11973 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11975 /* We need to align to twice the pointer size here. */
11976 if (DWARF_ARANGES_PAD_SIZE)
11978 /* Pad using a 2 byte words so that padding is correct for any
11980 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11981 2 * DWARF2_ADDR_SIZE);
11982 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11983 dw2_asm_output_data (2, 0, NULL);
11986 /* It is necessary not to output these entries if the sections were
11987 not used; if the sections were not used, the length will be 0 and
11988 the address may end up as 0 if the section is discarded by ld
11989 --gc-sections, leaving an invalid (0, 0) entry that can be
11990 confused with the terminator. */
11991 if (text_section_used)
11993 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11994 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11995 text_section_label, "Length");
11997 if (cold_text_section_used)
11999 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
12001 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
12002 cold_text_section_label, "Length");
12005 if (have_multiple_function_sections)
12007 unsigned fde_idx = 0;
12009 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
12011 dw_fde_ref fde = &fde_table[fde_idx];
12013 if (!fde->in_std_section)
12015 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
12017 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
12018 fde->dw_fde_begin, "Length");
12020 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
12022 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
12024 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
12025 fde->dw_fde_second_begin, "Length");
12030 /* Output the terminator words. */
12031 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12032 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12035 /* Add a new entry to .debug_ranges. Return the offset at which it
12038 static unsigned int
12039 add_ranges_num (int num)
12041 unsigned int in_use = ranges_table_in_use;
12043 if (in_use == ranges_table_allocated)
12045 ranges_table_allocated += RANGES_TABLE_INCREMENT;
12046 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
12047 ranges_table_allocated);
12048 memset (ranges_table + ranges_table_in_use, 0,
12049 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
12052 ranges_table[in_use].num = num;
12053 ranges_table_in_use = in_use + 1;
12055 return in_use * 2 * DWARF2_ADDR_SIZE;
12058 /* Add a new entry to .debug_ranges corresponding to a block, or a
12059 range terminator if BLOCK is NULL. */
12061 static unsigned int
12062 add_ranges (const_tree block)
12064 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
12067 /* Add a new entry to .debug_ranges corresponding to a pair of
12071 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
12074 unsigned int in_use = ranges_by_label_in_use;
12075 unsigned int offset;
12077 if (in_use == ranges_by_label_allocated)
12079 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
12080 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
12082 ranges_by_label_allocated);
12083 memset (ranges_by_label + ranges_by_label_in_use, 0,
12084 RANGES_TABLE_INCREMENT
12085 * sizeof (struct dw_ranges_by_label_struct));
12088 ranges_by_label[in_use].begin = begin;
12089 ranges_by_label[in_use].end = end;
12090 ranges_by_label_in_use = in_use + 1;
12092 offset = add_ranges_num (-(int)in_use - 1);
12095 add_AT_range_list (die, DW_AT_ranges, offset);
12101 output_ranges (void)
12104 static const char *const start_fmt = "Offset %#x";
12105 const char *fmt = start_fmt;
12107 for (i = 0; i < ranges_table_in_use; i++)
12109 int block_num = ranges_table[i].num;
12113 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12114 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12116 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12117 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12119 /* If all code is in the text section, then the compilation
12120 unit base address defaults to DW_AT_low_pc, which is the
12121 base of the text section. */
12122 if (!have_multiple_function_sections)
12124 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
12125 text_section_label,
12126 fmt, i * 2 * DWARF2_ADDR_SIZE);
12127 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
12128 text_section_label, NULL);
12131 /* Otherwise, the compilation unit base address is zero,
12132 which allows us to use absolute addresses, and not worry
12133 about whether the target supports cross-section
12137 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12138 fmt, i * 2 * DWARF2_ADDR_SIZE);
12139 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
12145 /* Negative block_num stands for an index into ranges_by_label. */
12146 else if (block_num < 0)
12148 int lab_idx = - block_num - 1;
12150 if (!have_multiple_function_sections)
12152 gcc_unreachable ();
12154 /* If we ever use add_ranges_by_labels () for a single
12155 function section, all we have to do is to take out
12156 the #if 0 above. */
12157 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12158 ranges_by_label[lab_idx].begin,
12159 text_section_label,
12160 fmt, i * 2 * DWARF2_ADDR_SIZE);
12161 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12162 ranges_by_label[lab_idx].end,
12163 text_section_label, NULL);
12168 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12169 ranges_by_label[lab_idx].begin,
12170 fmt, i * 2 * DWARF2_ADDR_SIZE);
12171 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12172 ranges_by_label[lab_idx].end,
12178 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12179 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12185 /* Data structure containing information about input files. */
12188 const char *path; /* Complete file name. */
12189 const char *fname; /* File name part. */
12190 int length; /* Length of entire string. */
12191 struct dwarf_file_data * file_idx; /* Index in input file table. */
12192 int dir_idx; /* Index in directory table. */
12195 /* Data structure containing information about directories with source
12199 const char *path; /* Path including directory name. */
12200 int length; /* Path length. */
12201 int prefix; /* Index of directory entry which is a prefix. */
12202 int count; /* Number of files in this directory. */
12203 int dir_idx; /* Index of directory used as base. */
12206 /* Callback function for file_info comparison. We sort by looking at
12207 the directories in the path. */
12210 file_info_cmp (const void *p1, const void *p2)
12212 const struct file_info *const s1 = (const struct file_info *) p1;
12213 const struct file_info *const s2 = (const struct file_info *) p2;
12214 const unsigned char *cp1;
12215 const unsigned char *cp2;
12217 /* Take care of file names without directories. We need to make sure that
12218 we return consistent values to qsort since some will get confused if
12219 we return the same value when identical operands are passed in opposite
12220 orders. So if neither has a directory, return 0 and otherwise return
12221 1 or -1 depending on which one has the directory. */
12222 if ((s1->path == s1->fname || s2->path == s2->fname))
12223 return (s2->path == s2->fname) - (s1->path == s1->fname);
12225 cp1 = (const unsigned char *) s1->path;
12226 cp2 = (const unsigned char *) s2->path;
12232 /* Reached the end of the first path? If so, handle like above. */
12233 if ((cp1 == (const unsigned char *) s1->fname)
12234 || (cp2 == (const unsigned char *) s2->fname))
12235 return ((cp2 == (const unsigned char *) s2->fname)
12236 - (cp1 == (const unsigned char *) s1->fname));
12238 /* Character of current path component the same? */
12239 else if (*cp1 != *cp2)
12240 return *cp1 - *cp2;
12244 struct file_name_acquire_data
12246 struct file_info *files;
12251 /* Traversal function for the hash table. */
12254 file_name_acquire (void ** slot, void *data)
12256 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12257 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12258 struct file_info *fi;
12261 gcc_assert (fnad->max_files >= d->emitted_number);
12263 if (! d->emitted_number)
12266 gcc_assert (fnad->max_files != fnad->used_files);
12268 fi = fnad->files + fnad->used_files++;
12270 /* Skip all leading "./". */
12272 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12275 /* Create a new array entry. */
12277 fi->length = strlen (f);
12280 /* Search for the file name part. */
12281 f = strrchr (f, DIR_SEPARATOR);
12282 #if defined (DIR_SEPARATOR_2)
12284 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12288 if (f == NULL || f < g)
12294 fi->fname = f == NULL ? fi->path : f + 1;
12298 /* Output the directory table and the file name table. We try to minimize
12299 the total amount of memory needed. A heuristic is used to avoid large
12300 slowdowns with many input files. */
12303 output_file_names (void)
12305 struct file_name_acquire_data fnad;
12307 struct file_info *files;
12308 struct dir_info *dirs;
12316 if (!last_emitted_file)
12318 dw2_asm_output_data (1, 0, "End directory table");
12319 dw2_asm_output_data (1, 0, "End file name table");
12323 numfiles = last_emitted_file->emitted_number;
12325 /* Allocate the various arrays we need. */
12326 files = XALLOCAVEC (struct file_info, numfiles);
12327 dirs = XALLOCAVEC (struct dir_info, numfiles);
12329 fnad.files = files;
12330 fnad.used_files = 0;
12331 fnad.max_files = numfiles;
12332 htab_traverse (file_table, file_name_acquire, &fnad);
12333 gcc_assert (fnad.used_files == fnad.max_files);
12335 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12337 /* Find all the different directories used. */
12338 dirs[0].path = files[0].path;
12339 dirs[0].length = files[0].fname - files[0].path;
12340 dirs[0].prefix = -1;
12342 dirs[0].dir_idx = 0;
12343 files[0].dir_idx = 0;
12346 for (i = 1; i < numfiles; i++)
12347 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12348 && memcmp (dirs[ndirs - 1].path, files[i].path,
12349 dirs[ndirs - 1].length) == 0)
12351 /* Same directory as last entry. */
12352 files[i].dir_idx = ndirs - 1;
12353 ++dirs[ndirs - 1].count;
12359 /* This is a new directory. */
12360 dirs[ndirs].path = files[i].path;
12361 dirs[ndirs].length = files[i].fname - files[i].path;
12362 dirs[ndirs].count = 1;
12363 dirs[ndirs].dir_idx = ndirs;
12364 files[i].dir_idx = ndirs;
12366 /* Search for a prefix. */
12367 dirs[ndirs].prefix = -1;
12368 for (j = 0; j < ndirs; j++)
12369 if (dirs[j].length < dirs[ndirs].length
12370 && dirs[j].length > 1
12371 && (dirs[ndirs].prefix == -1
12372 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12373 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12374 dirs[ndirs].prefix = j;
12379 /* Now to the actual work. We have to find a subset of the directories which
12380 allow expressing the file name using references to the directory table
12381 with the least amount of characters. We do not do an exhaustive search
12382 where we would have to check out every combination of every single
12383 possible prefix. Instead we use a heuristic which provides nearly optimal
12384 results in most cases and never is much off. */
12385 saved = XALLOCAVEC (int, ndirs);
12386 savehere = XALLOCAVEC (int, ndirs);
12388 memset (saved, '\0', ndirs * sizeof (saved[0]));
12389 for (i = 0; i < ndirs; i++)
12394 /* We can always save some space for the current directory. But this
12395 does not mean it will be enough to justify adding the directory. */
12396 savehere[i] = dirs[i].length;
12397 total = (savehere[i] - saved[i]) * dirs[i].count;
12399 for (j = i + 1; j < ndirs; j++)
12402 if (saved[j] < dirs[i].length)
12404 /* Determine whether the dirs[i] path is a prefix of the
12408 k = dirs[j].prefix;
12409 while (k != -1 && k != (int) i)
12410 k = dirs[k].prefix;
12414 /* Yes it is. We can possibly save some memory by
12415 writing the filenames in dirs[j] relative to
12417 savehere[j] = dirs[i].length;
12418 total += (savehere[j] - saved[j]) * dirs[j].count;
12423 /* Check whether we can save enough to justify adding the dirs[i]
12425 if (total > dirs[i].length + 1)
12427 /* It's worthwhile adding. */
12428 for (j = i; j < ndirs; j++)
12429 if (savehere[j] > 0)
12431 /* Remember how much we saved for this directory so far. */
12432 saved[j] = savehere[j];
12434 /* Remember the prefix directory. */
12435 dirs[j].dir_idx = i;
12440 /* Emit the directory name table. */
12441 idx_offset = dirs[0].length > 0 ? 1 : 0;
12442 for (i = 1 - idx_offset; i < ndirs; i++)
12443 dw2_asm_output_nstring (dirs[i].path,
12445 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12446 "Directory Entry: %#x", i + idx_offset);
12448 dw2_asm_output_data (1, 0, "End directory table");
12450 /* We have to emit them in the order of emitted_number since that's
12451 used in the debug info generation. To do this efficiently we
12452 generate a back-mapping of the indices first. */
12453 backmap = XALLOCAVEC (int, numfiles);
12454 for (i = 0; i < numfiles; i++)
12455 backmap[files[i].file_idx->emitted_number - 1] = i;
12457 /* Now write all the file names. */
12458 for (i = 0; i < numfiles; i++)
12460 int file_idx = backmap[i];
12461 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12463 #ifdef VMS_DEBUGGING_INFO
12464 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12466 /* Setting these fields can lead to debugger miscomparisons,
12467 but VMS Debug requires them to be set correctly. */
12472 int maxfilelen = strlen (files[file_idx].path)
12473 + dirs[dir_idx].length
12474 + MAX_VMS_VERSION_LEN + 1;
12475 char *filebuf = XALLOCAVEC (char, maxfilelen);
12477 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12478 snprintf (filebuf, maxfilelen, "%s;%d",
12479 files[file_idx].path + dirs[dir_idx].length, ver);
12481 dw2_asm_output_nstring
12482 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12484 /* Include directory index. */
12485 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12487 /* Modification time. */
12488 dw2_asm_output_data_uleb128
12489 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12493 /* File length in bytes. */
12494 dw2_asm_output_data_uleb128
12495 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12499 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12500 "File Entry: %#x", (unsigned) i + 1);
12502 /* Include directory index. */
12503 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12505 /* Modification time. */
12506 dw2_asm_output_data_uleb128 (0, NULL);
12508 /* File length in bytes. */
12509 dw2_asm_output_data_uleb128 (0, NULL);
12510 #endif /* VMS_DEBUGGING_INFO */
12513 dw2_asm_output_data (1, 0, "End file name table");
12517 /* Output one line number table into the .debug_line section. */
12520 output_one_line_info_table (dw_line_info_table *table)
12522 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12523 unsigned int current_line = 1;
12524 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
12525 dw_line_info_entry *ent;
12528 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
12530 switch (ent->opcode)
12532 case LI_set_address:
12533 /* ??? Unfortunately, we have little choice here currently, and
12534 must always use the most general form. GCC does not know the
12535 address delta itself, so we can't use DW_LNS_advance_pc. Many
12536 ports do have length attributes which will give an upper bound
12537 on the address range. We could perhaps use length attributes
12538 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12539 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
12541 /* This can handle any delta. This takes
12542 4+DWARF2_ADDR_SIZE bytes. */
12543 dw2_asm_output_data (1, 0, "set address %s", line_label);
12544 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12545 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12546 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12550 if (ent->val == current_line)
12552 /* We still need to start a new row, so output a copy insn. */
12553 dw2_asm_output_data (1, DW_LNS_copy,
12554 "copy line %u", current_line);
12558 int line_offset = ent->val - current_line;
12559 int line_delta = line_offset - DWARF_LINE_BASE;
12561 current_line = ent->val;
12562 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12564 /* This can handle deltas from -10 to 234, using the current
12565 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
12566 This takes 1 byte. */
12567 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12568 "line %u", current_line);
12572 /* This can handle any delta. This takes at least 4 bytes,
12573 depending on the value being encoded. */
12574 dw2_asm_output_data (1, DW_LNS_advance_line,
12575 "advance to line %u", current_line);
12576 dw2_asm_output_data_sleb128 (line_offset, NULL);
12577 dw2_asm_output_data (1, DW_LNS_copy, NULL);
12583 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
12584 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12587 case LI_set_column:
12588 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
12589 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12592 case LI_negate_stmt:
12593 current_is_stmt = !current_is_stmt;
12594 dw2_asm_output_data (1, DW_LNS_negate_stmt,
12595 "is_stmt %d", current_is_stmt);
12598 case LI_set_prologue_end:
12599 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
12600 "set prologue end");
12603 case LI_set_epilogue_begin:
12604 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
12605 "set epilogue begin");
12608 case LI_set_discriminator:
12609 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
12610 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
12611 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
12612 dw2_asm_output_data_uleb128 (ent->val, NULL);
12617 /* Emit debug info for the address of the end of the table. */
12618 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
12619 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12620 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12621 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
12623 dw2_asm_output_data (1, 0, "end sequence");
12624 dw2_asm_output_data_uleb128 (1, NULL);
12625 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12628 /* Output the source line number correspondence information. This
12629 information goes into the .debug_line section. */
12632 output_line_info (void)
12634 char l1[20], l2[20], p1[20], p2[20];
12635 int ver = dwarf_version;
12636 bool saw_one = false;
12639 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12640 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12641 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12642 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12644 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12645 dw2_asm_output_data (4, 0xffffffff,
12646 "Initial length escape value indicating 64-bit DWARF extension");
12647 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12648 "Length of Source Line Info");
12649 ASM_OUTPUT_LABEL (asm_out_file, l1);
12651 dw2_asm_output_data (2, ver, "DWARF Version");
12652 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12653 ASM_OUTPUT_LABEL (asm_out_file, p1);
12655 /* Define the architecture-dependent minimum instruction length (in bytes).
12656 In this implementation of DWARF, this field is used for information
12657 purposes only. Since GCC generates assembly language, we have no
12658 a priori knowledge of how many instruction bytes are generated for each
12659 source line, and therefore can use only the DW_LNE_set_address and
12660 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12661 this as '1', which is "correct enough" for all architectures,
12662 and don't let the target override. */
12663 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12666 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12667 "Maximum Operations Per Instruction");
12668 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12669 "Default is_stmt_start flag");
12670 dw2_asm_output_data (1, DWARF_LINE_BASE,
12671 "Line Base Value (Special Opcodes)");
12672 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12673 "Line Range Value (Special Opcodes)");
12674 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12675 "Special Opcode Base");
12677 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12682 case DW_LNS_advance_pc:
12683 case DW_LNS_advance_line:
12684 case DW_LNS_set_file:
12685 case DW_LNS_set_column:
12686 case DW_LNS_fixed_advance_pc:
12687 case DW_LNS_set_isa:
12695 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12699 /* Write out the information about the files we use. */
12700 output_file_names ();
12701 ASM_OUTPUT_LABEL (asm_out_file, p2);
12703 if (separate_line_info)
12705 dw_line_info_table *table;
12708 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
12711 output_one_line_info_table (table);
12715 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
12717 output_one_line_info_table (cold_text_section_line_info);
12721 /* ??? Some Darwin linkers crash on a .debug_line section with no
12722 sequences. Further, merely a DW_LNE_end_sequence entry is not
12723 sufficient -- the address column must also be initialized.
12724 Make sure to output at least one set_address/end_sequence pair,
12725 choosing .text since that section is always present. */
12726 if (text_section_line_info->in_use || !saw_one)
12727 output_one_line_info_table (text_section_line_info);
12729 /* Output the marker for the end of the line number info. */
12730 ASM_OUTPUT_LABEL (asm_out_file, l2);
12733 /* Given a pointer to a tree node for some base type, return a pointer to
12734 a DIE that describes the given type.
12736 This routine must only be called for GCC type nodes that correspond to
12737 Dwarf base (fundamental) types. */
12740 base_type_die (tree type)
12742 dw_die_ref base_type_result;
12743 enum dwarf_type encoding;
12745 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12748 /* If this is a subtype that should not be emitted as a subrange type,
12749 use the base type. See subrange_type_for_debug_p. */
12750 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12751 type = TREE_TYPE (type);
12753 switch (TREE_CODE (type))
12756 if ((dwarf_version >= 4 || !dwarf_strict)
12757 && TYPE_NAME (type)
12758 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12759 && DECL_IS_BUILTIN (TYPE_NAME (type))
12760 && DECL_NAME (TYPE_NAME (type)))
12762 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12763 if (strcmp (name, "char16_t") == 0
12764 || strcmp (name, "char32_t") == 0)
12766 encoding = DW_ATE_UTF;
12770 if (TYPE_STRING_FLAG (type))
12772 if (TYPE_UNSIGNED (type))
12773 encoding = DW_ATE_unsigned_char;
12775 encoding = DW_ATE_signed_char;
12777 else if (TYPE_UNSIGNED (type))
12778 encoding = DW_ATE_unsigned;
12780 encoding = DW_ATE_signed;
12784 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12786 if (dwarf_version >= 3 || !dwarf_strict)
12787 encoding = DW_ATE_decimal_float;
12789 encoding = DW_ATE_lo_user;
12792 encoding = DW_ATE_float;
12795 case FIXED_POINT_TYPE:
12796 if (!(dwarf_version >= 3 || !dwarf_strict))
12797 encoding = DW_ATE_lo_user;
12798 else if (TYPE_UNSIGNED (type))
12799 encoding = DW_ATE_unsigned_fixed;
12801 encoding = DW_ATE_signed_fixed;
12804 /* Dwarf2 doesn't know anything about complex ints, so use
12805 a user defined type for it. */
12807 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12808 encoding = DW_ATE_complex_float;
12810 encoding = DW_ATE_lo_user;
12814 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12815 encoding = DW_ATE_boolean;
12819 /* No other TREE_CODEs are Dwarf fundamental types. */
12820 gcc_unreachable ();
12823 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12825 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12826 int_size_in_bytes (type));
12827 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12829 return base_type_result;
12832 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12833 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12836 is_base_type (tree type)
12838 switch (TREE_CODE (type))
12844 case FIXED_POINT_TYPE:
12852 case QUAL_UNION_TYPE:
12853 case ENUMERAL_TYPE:
12854 case FUNCTION_TYPE:
12857 case REFERENCE_TYPE:
12865 gcc_unreachable ();
12871 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12872 node, return the size in bits for the type if it is a constant, or else
12873 return the alignment for the type if the type's size is not constant, or
12874 else return BITS_PER_WORD if the type actually turns out to be an
12875 ERROR_MARK node. */
12877 static inline unsigned HOST_WIDE_INT
12878 simple_type_size_in_bits (const_tree type)
12880 if (TREE_CODE (type) == ERROR_MARK)
12881 return BITS_PER_WORD;
12882 else if (TYPE_SIZE (type) == NULL_TREE)
12884 else if (host_integerp (TYPE_SIZE (type), 1))
12885 return tree_low_cst (TYPE_SIZE (type), 1);
12887 return TYPE_ALIGN (type);
12890 /* Similarly, but return a double_int instead of UHWI. */
12892 static inline double_int
12893 double_int_type_size_in_bits (const_tree type)
12895 if (TREE_CODE (type) == ERROR_MARK)
12896 return uhwi_to_double_int (BITS_PER_WORD);
12897 else if (TYPE_SIZE (type) == NULL_TREE)
12898 return double_int_zero;
12899 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12900 return tree_to_double_int (TYPE_SIZE (type));
12902 return uhwi_to_double_int (TYPE_ALIGN (type));
12905 /* Given a pointer to a tree node for a subrange type, return a pointer
12906 to a DIE that describes the given type. */
12909 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12911 dw_die_ref subrange_die;
12912 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12914 if (context_die == NULL)
12915 context_die = comp_unit_die ();
12917 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12919 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12921 /* The size of the subrange type and its base type do not match,
12922 so we need to generate a size attribute for the subrange type. */
12923 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12927 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12929 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12931 return subrange_die;
12934 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12935 entry that chains various modifiers in front of the given type. */
12938 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12939 dw_die_ref context_die)
12941 enum tree_code code = TREE_CODE (type);
12942 dw_die_ref mod_type_die;
12943 dw_die_ref sub_die = NULL;
12944 tree item_type = NULL;
12945 tree qualified_type;
12946 tree name, low, high;
12948 if (code == ERROR_MARK)
12951 /* See if we already have the appropriately qualified variant of
12954 = get_qualified_type (type,
12955 ((is_const_type ? TYPE_QUAL_CONST : 0)
12956 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12958 if (qualified_type == sizetype
12959 && TYPE_NAME (qualified_type)
12960 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12962 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
12964 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
12965 && TYPE_PRECISION (t)
12966 == TYPE_PRECISION (qualified_type)
12967 && TYPE_UNSIGNED (t)
12968 == TYPE_UNSIGNED (qualified_type));
12969 qualified_type = t;
12972 /* If we do, then we can just use its DIE, if it exists. */
12973 if (qualified_type)
12975 mod_type_die = lookup_type_die (qualified_type);
12977 return mod_type_die;
12980 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12982 /* Handle C typedef types. */
12983 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12984 && !DECL_ARTIFICIAL (name))
12986 tree dtype = TREE_TYPE (name);
12988 if (qualified_type == dtype)
12990 /* For a named type, use the typedef. */
12991 gen_type_die (qualified_type, context_die);
12992 return lookup_type_die (qualified_type);
12994 else if (is_const_type < TYPE_READONLY (dtype)
12995 || is_volatile_type < TYPE_VOLATILE (dtype)
12996 || (is_const_type <= TYPE_READONLY (dtype)
12997 && is_volatile_type <= TYPE_VOLATILE (dtype)
12998 && DECL_ORIGINAL_TYPE (name) != type))
12999 /* cv-unqualified version of named type. Just use the unnamed
13000 type to which it refers. */
13001 return modified_type_die (DECL_ORIGINAL_TYPE (name),
13002 is_const_type, is_volatile_type,
13004 /* Else cv-qualified version of named type; fall through. */
13008 /* If both is_const_type and is_volatile_type, prefer the path
13009 which leads to a qualified type. */
13010 && (!is_volatile_type
13011 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
13012 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
13014 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
13015 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
13017 else if (is_volatile_type)
13019 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
13020 sub_die = modified_type_die (type, is_const_type, 0, context_die);
13022 else if (code == POINTER_TYPE)
13024 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
13025 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13026 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13027 item_type = TREE_TYPE (type);
13028 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13029 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13030 TYPE_ADDR_SPACE (item_type));
13032 else if (code == REFERENCE_TYPE)
13034 if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
13035 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
13038 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
13039 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13040 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13041 item_type = TREE_TYPE (type);
13042 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13043 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13044 TYPE_ADDR_SPACE (item_type));
13046 else if (code == INTEGER_TYPE
13047 && TREE_TYPE (type) != NULL_TREE
13048 && subrange_type_for_debug_p (type, &low, &high))
13050 mod_type_die = subrange_type_die (type, low, high, context_die);
13051 item_type = TREE_TYPE (type);
13053 else if (is_base_type (type))
13054 mod_type_die = base_type_die (type);
13057 gen_type_die (type, context_die);
13059 /* We have to get the type_main_variant here (and pass that to the
13060 `lookup_type_die' routine) because the ..._TYPE node we have
13061 might simply be a *copy* of some original type node (where the
13062 copy was created to help us keep track of typedef names) and
13063 that copy might have a different TYPE_UID from the original
13065 if (TREE_CODE (type) != VECTOR_TYPE)
13066 return lookup_type_die (type_main_variant (type));
13068 /* Vectors have the debugging information in the type,
13069 not the main variant. */
13070 return lookup_type_die (type);
13073 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
13074 don't output a DW_TAG_typedef, since there isn't one in the
13075 user's program; just attach a DW_AT_name to the type.
13076 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
13077 if the base type already has the same name. */
13079 && ((TREE_CODE (name) != TYPE_DECL
13080 && (qualified_type == TYPE_MAIN_VARIANT (type)
13081 || (!is_const_type && !is_volatile_type)))
13082 || (TREE_CODE (name) == TYPE_DECL
13083 && TREE_TYPE (name) == qualified_type
13084 && DECL_NAME (name))))
13086 if (TREE_CODE (name) == TYPE_DECL)
13087 /* Could just call add_name_and_src_coords_attributes here,
13088 but since this is a builtin type it doesn't have any
13089 useful source coordinates anyway. */
13090 name = DECL_NAME (name);
13091 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
13092 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
13094 /* This probably indicates a bug. */
13095 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
13096 add_name_attribute (mod_type_die, "__unknown__");
13098 if (qualified_type)
13099 equate_type_number_to_die (qualified_type, mod_type_die);
13102 /* We must do this after the equate_type_number_to_die call, in case
13103 this is a recursive type. This ensures that the modified_type_die
13104 recursion will terminate even if the type is recursive. Recursive
13105 types are possible in Ada. */
13106 sub_die = modified_type_die (item_type,
13107 TYPE_READONLY (item_type),
13108 TYPE_VOLATILE (item_type),
13111 if (sub_die != NULL)
13112 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
13114 return mod_type_die;
13117 /* Generate DIEs for the generic parameters of T.
13118 T must be either a generic type or a generic function.
13119 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13122 gen_generic_params_dies (tree t)
13126 dw_die_ref die = NULL;
13128 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13132 die = lookup_type_die (t);
13133 else if (DECL_P (t))
13134 die = lookup_decl_die (t);
13138 parms = lang_hooks.get_innermost_generic_parms (t);
13140 /* T has no generic parameter. It means T is neither a generic type
13141 or function. End of story. */
13144 parms_num = TREE_VEC_LENGTH (parms);
13145 args = lang_hooks.get_innermost_generic_args (t);
13146 for (i = 0; i < parms_num; i++)
13148 tree parm, arg, arg_pack_elems;
13150 parm = TREE_VEC_ELT (parms, i);
13151 arg = TREE_VEC_ELT (args, i);
13152 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13153 gcc_assert (parm && TREE_VALUE (parm) && arg);
13155 if (parm && TREE_VALUE (parm) && arg)
13157 /* If PARM represents a template parameter pack,
13158 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13159 by DW_TAG_template_*_parameter DIEs for the argument
13160 pack elements of ARG. Note that ARG would then be
13161 an argument pack. */
13162 if (arg_pack_elems)
13163 template_parameter_pack_die (TREE_VALUE (parm),
13167 generic_parameter_die (TREE_VALUE (parm), arg,
13168 true /* Emit DW_AT_name */, die);
13173 /* Create and return a DIE for PARM which should be
13174 the representation of a generic type parameter.
13175 For instance, in the C++ front end, PARM would be a template parameter.
13176 ARG is the argument to PARM.
13177 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13179 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13180 as a child node. */
13183 generic_parameter_die (tree parm, tree arg,
13185 dw_die_ref parent_die)
13187 dw_die_ref tmpl_die = NULL;
13188 const char *name = NULL;
13190 if (!parm || !DECL_NAME (parm) || !arg)
13193 /* We support non-type generic parameters and arguments,
13194 type generic parameters and arguments, as well as
13195 generic generic parameters (a.k.a. template template parameters in C++)
13197 if (TREE_CODE (parm) == PARM_DECL)
13198 /* PARM is a nontype generic parameter */
13199 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13200 else if (TREE_CODE (parm) == TYPE_DECL)
13201 /* PARM is a type generic parameter. */
13202 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13203 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13204 /* PARM is a generic generic parameter.
13205 Its DIE is a GNU extension. It shall have a
13206 DW_AT_name attribute to represent the name of the template template
13207 parameter, and a DW_AT_GNU_template_name attribute to represent the
13208 name of the template template argument. */
13209 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13212 gcc_unreachable ();
13218 /* If PARM is a generic parameter pack, it means we are
13219 emitting debug info for a template argument pack element.
13220 In other terms, ARG is a template argument pack element.
13221 In that case, we don't emit any DW_AT_name attribute for
13225 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13227 add_AT_string (tmpl_die, DW_AT_name, name);
13230 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13232 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13233 TMPL_DIE should have a child DW_AT_type attribute that is set
13234 to the type of the argument to PARM, which is ARG.
13235 If PARM is a type generic parameter, TMPL_DIE should have a
13236 child DW_AT_type that is set to ARG. */
13237 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13238 add_type_attribute (tmpl_die, tmpl_type, 0,
13239 TREE_THIS_VOLATILE (tmpl_type),
13244 /* So TMPL_DIE is a DIE representing a
13245 a generic generic template parameter, a.k.a template template
13246 parameter in C++ and arg is a template. */
13248 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13249 to the name of the argument. */
13250 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13252 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13255 if (TREE_CODE (parm) == PARM_DECL)
13256 /* So PARM is a non-type generic parameter.
13257 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13258 attribute of TMPL_DIE which value represents the value
13260 We must be careful here:
13261 The value of ARG might reference some function decls.
13262 We might currently be emitting debug info for a generic
13263 type and types are emitted before function decls, we don't
13264 know if the function decls referenced by ARG will actually be
13265 emitted after cgraph computations.
13266 So must defer the generation of the DW_AT_const_value to
13267 after cgraph is ready. */
13268 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13274 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13275 PARM_PACK must be a template parameter pack. The returned DIE
13276 will be child DIE of PARENT_DIE. */
13279 template_parameter_pack_die (tree parm_pack,
13280 tree parm_pack_args,
13281 dw_die_ref parent_die)
13286 gcc_assert (parent_die && parm_pack);
13288 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13289 add_name_and_src_coords_attributes (die, parm_pack);
13290 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13291 generic_parameter_die (parm_pack,
13292 TREE_VEC_ELT (parm_pack_args, j),
13293 false /* Don't emit DW_AT_name */,
13298 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13299 an enumerated type. */
13302 type_is_enum (const_tree type)
13304 return TREE_CODE (type) == ENUMERAL_TYPE;
13307 /* Return the DBX register number described by a given RTL node. */
13309 static unsigned int
13310 dbx_reg_number (const_rtx rtl)
13312 unsigned regno = REGNO (rtl);
13314 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13316 #ifdef LEAF_REG_REMAP
13317 if (current_function_uses_only_leaf_regs)
13319 int leaf_reg = LEAF_REG_REMAP (regno);
13320 if (leaf_reg != -1)
13321 regno = (unsigned) leaf_reg;
13325 return DBX_REGISTER_NUMBER (regno);
13328 /* Optionally add a DW_OP_piece term to a location description expression.
13329 DW_OP_piece is only added if the location description expression already
13330 doesn't end with DW_OP_piece. */
13333 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13335 dw_loc_descr_ref loc;
13337 if (*list_head != NULL)
13339 /* Find the end of the chain. */
13340 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13343 if (loc->dw_loc_opc != DW_OP_piece)
13344 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13348 /* Return a location descriptor that designates a machine register or
13349 zero if there is none. */
13351 static dw_loc_descr_ref
13352 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13356 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13359 /* We only use "frame base" when we're sure we're talking about the
13360 post-prologue local stack frame. We do this by *not* running
13361 register elimination until this point, and recognizing the special
13362 argument pointer and soft frame pointer rtx's.
13363 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13364 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13365 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13367 dw_loc_descr_ref result = NULL;
13369 if (dwarf_version >= 4 || !dwarf_strict)
13371 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
13374 add_loc_descr (&result,
13375 new_loc_descr (DW_OP_stack_value, 0, 0));
13380 regs = targetm.dwarf_register_span (rtl);
13382 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13383 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13385 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13388 /* Return a location descriptor that designates a machine register for
13389 a given hard register number. */
13391 static dw_loc_descr_ref
13392 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13394 dw_loc_descr_ref reg_loc_descr;
13398 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13400 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13402 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13403 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13405 return reg_loc_descr;
13408 /* Given an RTL of a register, return a location descriptor that
13409 designates a value that spans more than one register. */
13411 static dw_loc_descr_ref
13412 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13413 enum var_init_status initialized)
13415 int nregs, size, i;
13417 dw_loc_descr_ref loc_result = NULL;
13420 #ifdef LEAF_REG_REMAP
13421 if (current_function_uses_only_leaf_regs)
13423 int leaf_reg = LEAF_REG_REMAP (reg);
13424 if (leaf_reg != -1)
13425 reg = (unsigned) leaf_reg;
13428 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13429 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13431 /* Simple, contiguous registers. */
13432 if (regs == NULL_RTX)
13434 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13439 dw_loc_descr_ref t;
13441 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13442 VAR_INIT_STATUS_INITIALIZED);
13443 add_loc_descr (&loc_result, t);
13444 add_loc_descr_op_piece (&loc_result, size);
13450 /* Now onto stupid register sets in non contiguous locations. */
13452 gcc_assert (GET_CODE (regs) == PARALLEL);
13454 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13457 for (i = 0; i < XVECLEN (regs, 0); ++i)
13459 dw_loc_descr_ref t;
13461 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13462 VAR_INIT_STATUS_INITIALIZED);
13463 add_loc_descr (&loc_result, t);
13464 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13465 add_loc_descr_op_piece (&loc_result, size);
13468 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13469 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13473 /* Return a location descriptor that designates a constant. */
13475 static dw_loc_descr_ref
13476 int_loc_descriptor (HOST_WIDE_INT i)
13478 enum dwarf_location_atom op;
13480 /* Pick the smallest representation of a constant, rather than just
13481 defaulting to the LEB encoding. */
13485 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13486 else if (i <= 0xff)
13487 op = DW_OP_const1u;
13488 else if (i <= 0xffff)
13489 op = DW_OP_const2u;
13490 else if (HOST_BITS_PER_WIDE_INT == 32
13491 || i <= 0xffffffff)
13492 op = DW_OP_const4u;
13499 op = DW_OP_const1s;
13500 else if (i >= -0x8000)
13501 op = DW_OP_const2s;
13502 else if (HOST_BITS_PER_WIDE_INT == 32
13503 || i >= -0x80000000)
13504 op = DW_OP_const4s;
13509 return new_loc_descr (op, i, 0);
13512 /* Return loc description representing "address" of integer value.
13513 This can appear only as toplevel expression. */
13515 static dw_loc_descr_ref
13516 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13519 dw_loc_descr_ref loc_result = NULL;
13521 if (!(dwarf_version >= 4 || !dwarf_strict))
13528 else if (i <= 0xff)
13530 else if (i <= 0xffff)
13532 else if (HOST_BITS_PER_WIDE_INT == 32
13533 || i <= 0xffffffff)
13536 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13542 else if (i >= -0x8000)
13544 else if (HOST_BITS_PER_WIDE_INT == 32
13545 || i >= -0x80000000)
13548 litsize = 1 + size_of_sleb128 (i);
13550 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13551 is more compact. For DW_OP_stack_value we need:
13552 litsize + 1 (DW_OP_stack_value)
13553 and for DW_OP_implicit_value:
13554 1 (DW_OP_implicit_value) + 1 (length) + size. */
13555 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13557 loc_result = int_loc_descriptor (i);
13558 add_loc_descr (&loc_result,
13559 new_loc_descr (DW_OP_stack_value, 0, 0));
13563 loc_result = new_loc_descr (DW_OP_implicit_value,
13565 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13566 loc_result->dw_loc_oprnd2.v.val_int = i;
13570 /* Return a location descriptor that designates a base+offset location. */
13572 static dw_loc_descr_ref
13573 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13574 enum var_init_status initialized)
13576 unsigned int regno;
13577 dw_loc_descr_ref result;
13578 dw_fde_ref fde = current_fde ();
13580 /* We only use "frame base" when we're sure we're talking about the
13581 post-prologue local stack frame. We do this by *not* running
13582 register elimination until this point, and recognizing the special
13583 argument pointer and soft frame pointer rtx's. */
13584 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13586 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13590 if (GET_CODE (elim) == PLUS)
13592 offset += INTVAL (XEXP (elim, 1));
13593 elim = XEXP (elim, 0);
13595 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13596 && (elim == hard_frame_pointer_rtx
13597 || elim == stack_pointer_rtx))
13598 || elim == (frame_pointer_needed
13599 ? hard_frame_pointer_rtx
13600 : stack_pointer_rtx));
13602 /* If drap register is used to align stack, use frame
13603 pointer + offset to access stack variables. If stack
13604 is aligned without drap, use stack pointer + offset to
13605 access stack variables. */
13606 if (crtl->stack_realign_tried
13607 && reg == frame_pointer_rtx)
13610 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13611 ? HARD_FRAME_POINTER_REGNUM
13613 return new_reg_loc_descr (base_reg, offset);
13616 offset += frame_pointer_fb_offset;
13617 return new_loc_descr (DW_OP_fbreg, offset, 0);
13622 && (fde->drap_reg == REGNO (reg)
13623 || fde->vdrap_reg == REGNO (reg)))
13625 /* Use cfa+offset to represent the location of arguments passed
13626 on the stack when drap is used to align stack.
13627 Only do this when not optimizing, for optimized code var-tracking
13628 is supposed to track where the arguments live and the register
13629 used as vdrap or drap in some spot might be used for something
13630 else in other part of the routine. */
13631 return new_loc_descr (DW_OP_fbreg, offset, 0);
13634 regno = dbx_reg_number (reg);
13636 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13639 result = new_loc_descr (DW_OP_bregx, regno, offset);
13641 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13642 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13647 /* Return true if this RTL expression describes a base+offset calculation. */
13650 is_based_loc (const_rtx rtl)
13652 return (GET_CODE (rtl) == PLUS
13653 && ((REG_P (XEXP (rtl, 0))
13654 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13655 && CONST_INT_P (XEXP (rtl, 1)))));
13658 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13661 static dw_loc_descr_ref
13662 tls_mem_loc_descriptor (rtx mem)
13665 dw_loc_descr_ref loc_result;
13667 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13670 base = get_base_address (MEM_EXPR (mem));
13672 || TREE_CODE (base) != VAR_DECL
13673 || !DECL_THREAD_LOCAL_P (base))
13676 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13677 if (loc_result == NULL)
13680 if (INTVAL (MEM_OFFSET (mem)))
13681 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13686 /* Output debug info about reason why we failed to expand expression as dwarf
13690 expansion_failed (tree expr, rtx rtl, char const *reason)
13692 if (dump_file && (dump_flags & TDF_DETAILS))
13694 fprintf (dump_file, "Failed to expand as dwarf: ");
13696 print_generic_expr (dump_file, expr, dump_flags);
13699 fprintf (dump_file, "\n");
13700 print_rtl (dump_file, rtl);
13702 fprintf (dump_file, "\nReason: %s\n", reason);
13706 /* Helper function for const_ok_for_output, called either directly
13707 or via for_each_rtx. */
13710 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13714 if (GET_CODE (rtl) == UNSPEC)
13716 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13717 we can't express it in the debug info. */
13718 #ifdef ENABLE_CHECKING
13719 /* Don't complain about TLS UNSPECs, those are just too hard to
13721 if (XVECLEN (rtl, 0) != 1
13722 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13723 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13724 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13725 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13726 inform (current_function_decl
13727 ? DECL_SOURCE_LOCATION (current_function_decl)
13728 : UNKNOWN_LOCATION,
13729 #if NUM_UNSPEC_VALUES > 0
13730 "non-delegitimized UNSPEC %s (%d) found in variable location",
13731 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
13732 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
13735 "non-delegitimized UNSPEC %d found in variable location",
13739 expansion_failed (NULL_TREE, rtl,
13740 "UNSPEC hasn't been delegitimized.\n");
13744 if (GET_CODE (rtl) != SYMBOL_REF)
13747 if (CONSTANT_POOL_ADDRESS_P (rtl))
13750 get_pool_constant_mark (rtl, &marked);
13751 /* If all references to this pool constant were optimized away,
13752 it was not output and thus we can't represent it. */
13755 expansion_failed (NULL_TREE, rtl,
13756 "Constant was removed from constant pool.\n");
13761 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13764 /* Avoid references to external symbols in debug info, on several targets
13765 the linker might even refuse to link when linking a shared library,
13766 and in many other cases the relocations for .debug_info/.debug_loc are
13767 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13768 to be defined within the same shared library or executable are fine. */
13769 if (SYMBOL_REF_EXTERNAL_P (rtl))
13771 tree decl = SYMBOL_REF_DECL (rtl);
13773 if (decl == NULL || !targetm.binds_local_p (decl))
13775 expansion_failed (NULL_TREE, rtl,
13776 "Symbol not defined in current TU.\n");
13784 /* Return true if constant RTL can be emitted in DW_OP_addr or
13785 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13786 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13789 const_ok_for_output (rtx rtl)
13791 if (GET_CODE (rtl) == SYMBOL_REF)
13792 return const_ok_for_output_1 (&rtl, NULL) == 0;
13794 if (GET_CODE (rtl) == CONST)
13795 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13800 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13801 if possible, NULL otherwise. */
13804 base_type_for_mode (enum machine_mode mode, bool unsignedp)
13806 dw_die_ref type_die;
13807 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
13811 switch (TREE_CODE (type))
13819 type_die = lookup_type_die (type);
13821 type_die = modified_type_die (type, false, false, comp_unit_die ());
13822 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
13827 /* The following routine converts the RTL for a variable or parameter
13828 (resident in memory) into an equivalent Dwarf representation of a
13829 mechanism for getting the address of that same variable onto the top of a
13830 hypothetical "address evaluation" stack.
13832 When creating memory location descriptors, we are effectively transforming
13833 the RTL for a memory-resident object into its Dwarf postfix expression
13834 equivalent. This routine recursively descends an RTL tree, turning
13835 it into Dwarf postfix code as it goes.
13837 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
13839 MEM_MODE is the mode of the memory reference, needed to handle some
13840 autoincrement addressing modes.
13842 Return 0 if we can't represent the location. */
13844 static dw_loc_descr_ref
13845 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13846 enum machine_mode mem_mode,
13847 enum var_init_status initialized)
13849 dw_loc_descr_ref mem_loc_result = NULL;
13850 enum dwarf_location_atom op;
13851 dw_loc_descr_ref op0, op1;
13853 if (mode == VOIDmode)
13854 mode = GET_MODE (rtl);
13856 /* Note that for a dynamically sized array, the location we will generate a
13857 description of here will be the lowest numbered location which is
13858 actually within the array. That's *not* necessarily the same as the
13859 zeroth element of the array. */
13861 rtl = targetm.delegitimize_address (rtl);
13863 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
13866 switch (GET_CODE (rtl))
13871 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
13874 /* The case of a subreg may arise when we have a local (register)
13875 variable or a formal (register) parameter which doesn't quite fill
13876 up an entire register. For now, just assume that it is
13877 legitimate to make the Dwarf info refer to the whole register which
13878 contains the given subreg. */
13879 if (!subreg_lowpart_p (rtl))
13881 if (GET_MODE_CLASS (mode) == MODE_INT
13882 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
13883 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
13884 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
13886 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
13887 GET_MODE (SUBREG_REG (rtl)),
13888 mem_mode, initialized);
13893 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
13895 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
13896 && (GET_MODE_CLASS (mode) != MODE_INT
13897 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
13901 dw_die_ref type_die;
13902 dw_loc_descr_ref cvt;
13904 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
13905 GET_MODE (SUBREG_REG (rtl)),
13906 mem_mode, initialized);
13907 if (mem_loc_result == NULL)
13909 type_die = base_type_for_mode (mode, 0);
13910 if (type_die == NULL)
13912 mem_loc_result = NULL;
13915 if (GET_MODE_SIZE (mode)
13916 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
13917 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13919 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
13920 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13921 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13922 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13923 add_loc_descr (&mem_loc_result, cvt);
13928 if (GET_MODE_CLASS (mode) != MODE_INT
13929 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
13930 #ifdef POINTERS_EXTEND_UNSIGNED
13931 && (mode != Pmode || mem_mode == VOIDmode)
13935 dw_die_ref type_die;
13939 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
13941 type_die = base_type_for_mode (mode, 0);
13942 if (type_die == NULL)
13944 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
13945 dbx_reg_number (rtl), 0);
13946 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
13947 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
13948 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
13951 /* Whenever a register number forms a part of the description of the
13952 method for calculating the (dynamic) address of a memory resident
13953 object, DWARF rules require the register number be referred to as
13954 a "base register". This distinction is not based in any way upon
13955 what category of register the hardware believes the given register
13956 belongs to. This is strictly DWARF terminology we're dealing with
13957 here. Note that in cases where the location of a memory-resident
13958 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13959 OP_CONST (0)) the actual DWARF location descriptor that we generate
13960 may just be OP_BASEREG (basereg). This may look deceptively like
13961 the object in question was allocated to a register (rather than in
13962 memory) so DWARF consumers need to be aware of the subtle
13963 distinction between OP_REG and OP_BASEREG. */
13964 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13965 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13966 else if (stack_realign_drap
13968 && crtl->args.internal_arg_pointer == rtl
13969 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13971 /* If RTL is internal_arg_pointer, which has been optimized
13972 out, use DRAP instead. */
13973 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13974 VAR_INIT_STATUS_INITIALIZED);
13980 gcc_assert (GET_MODE_CLASS (mode) == MODE_INT);
13981 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
13982 mem_mode, VAR_INIT_STATUS_INITIALIZED);
13985 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
13987 int shift = DWARF2_ADDR_SIZE
13988 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13989 shift *= BITS_PER_UNIT;
13990 if (GET_CODE (rtl) == SIGN_EXTEND)
13994 mem_loc_result = op0;
13995 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13996 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13997 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13998 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14000 else if (!dwarf_strict)
14002 dw_die_ref type_die1, type_die2;
14003 dw_loc_descr_ref cvt;
14005 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
14006 GET_CODE (rtl) == ZERO_EXTEND);
14007 if (type_die1 == NULL)
14009 type_die2 = base_type_for_mode (mode, 0);
14010 if (type_die2 == NULL)
14012 mem_loc_result = op0;
14013 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14014 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14015 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
14016 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14017 add_loc_descr (&mem_loc_result, cvt);
14018 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14019 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14020 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
14021 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14022 add_loc_descr (&mem_loc_result, cvt);
14027 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
14028 get_address_mode (rtl), mode,
14029 VAR_INIT_STATUS_INITIALIZED);
14030 if (mem_loc_result == NULL)
14031 mem_loc_result = tls_mem_loc_descriptor (rtl);
14032 if (mem_loc_result != 0)
14034 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14035 || GET_MODE_CLASS (mode) != MODE_INT)
14037 dw_die_ref type_die;
14038 dw_loc_descr_ref deref;
14042 type_die = base_type_for_mode (mode, 0);
14043 if (type_die == NULL)
14045 deref = new_loc_descr (DW_OP_GNU_deref_type,
14046 GET_MODE_SIZE (mode), 0);
14047 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
14048 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
14049 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
14050 add_loc_descr (&mem_loc_result, deref);
14052 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
14053 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
14055 add_loc_descr (&mem_loc_result,
14056 new_loc_descr (DW_OP_deref_size,
14057 GET_MODE_SIZE (mode), 0));
14061 rtx new_rtl = avoid_constant_pool_reference (rtl);
14062 if (new_rtl != rtl)
14063 return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
14068 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
14071 /* Some ports can transform a symbol ref into a label ref, because
14072 the symbol ref is too far away and has to be dumped into a constant
14076 if (GET_MODE_CLASS (mode) != MODE_INT
14077 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14078 #ifdef POINTERS_EXTEND_UNSIGNED
14079 && (mode != Pmode || mem_mode == VOIDmode)
14083 if (GET_CODE (rtl) == SYMBOL_REF
14084 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
14086 dw_loc_descr_ref temp;
14088 /* If this is not defined, we have no way to emit the data. */
14089 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
14092 /* We used to emit DW_OP_addr here, but that's wrong, since
14093 DW_OP_addr should be relocated by the debug info consumer,
14094 while DW_OP_GNU_push_tls_address operand should not. */
14095 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
14096 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
14097 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
14098 temp->dw_loc_oprnd1.v.val_addr = rtl;
14099 temp->dtprel = true;
14101 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
14102 add_loc_descr (&mem_loc_result, temp);
14107 if (!const_ok_for_output (rtl))
14111 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14112 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14113 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14114 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14120 case DEBUG_IMPLICIT_PTR:
14121 expansion_failed (NULL_TREE, rtl,
14122 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14128 if (REG_P (ENTRY_VALUE_EXP (rtl)))
14130 if (GET_MODE_CLASS (mode) != MODE_INT
14131 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
14132 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
14133 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14136 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
14137 VAR_INIT_STATUS_INITIALIZED);
14139 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
14140 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
14142 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
14143 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14144 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
14148 gcc_unreachable ();
14151 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
14152 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
14153 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
14154 return mem_loc_result;
14157 /* Extract the PLUS expression nested inside and fall into
14158 PLUS code below. */
14159 rtl = XEXP (rtl, 1);
14164 /* Turn these into a PLUS expression and fall into the PLUS code
14166 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
14167 GEN_INT (GET_CODE (rtl) == PRE_INC
14168 ? GET_MODE_UNIT_SIZE (mem_mode)
14169 : -GET_MODE_UNIT_SIZE (mem_mode)));
14171 /* ... fall through ... */
14175 if (is_based_loc (rtl)
14176 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14177 && GET_MODE_CLASS (mode) == MODE_INT)
14178 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
14179 INTVAL (XEXP (rtl, 1)),
14180 VAR_INIT_STATUS_INITIALIZED);
14183 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14184 VAR_INIT_STATUS_INITIALIZED);
14185 if (mem_loc_result == 0)
14188 if (CONST_INT_P (XEXP (rtl, 1))
14189 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
14190 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
14193 dw_loc_descr_ref mem_loc_result2
14194 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14195 VAR_INIT_STATUS_INITIALIZED);
14196 if (mem_loc_result2 == 0)
14198 add_loc_descr (&mem_loc_result, mem_loc_result2);
14199 add_loc_descr (&mem_loc_result,
14200 new_loc_descr (DW_OP_plus, 0, 0));
14205 /* If a pseudo-reg is optimized away, it is possible for it to
14206 be replaced with a MEM containing a multiply or shift. */
14236 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14237 VAR_INIT_STATUS_INITIALIZED);
14238 op1 = mem_loc_descriptor (XEXP (rtl, 1),
14239 GET_MODE (XEXP (rtl, 1)) == VOIDmode
14240 ? mode : GET_MODE (XEXP (rtl, 1)), mem_mode,
14241 VAR_INIT_STATUS_INITIALIZED);
14243 if (op0 == 0 || op1 == 0)
14246 mem_loc_result = op0;
14247 add_loc_descr (&mem_loc_result, op1);
14248 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14264 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14265 VAR_INIT_STATUS_INITIALIZED);
14266 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14267 VAR_INIT_STATUS_INITIALIZED);
14269 if (op0 == 0 || op1 == 0)
14272 mem_loc_result = op0;
14273 add_loc_descr (&mem_loc_result, op1);
14274 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14278 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14279 VAR_INIT_STATUS_INITIALIZED);
14280 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14281 VAR_INIT_STATUS_INITIALIZED);
14283 if (op0 == 0 || op1 == 0)
14286 mem_loc_result = op0;
14287 add_loc_descr (&mem_loc_result, op1);
14288 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14289 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14290 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
14291 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14292 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
14308 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14309 VAR_INIT_STATUS_INITIALIZED);
14314 mem_loc_result = op0;
14315 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14319 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14320 #ifdef POINTERS_EXTEND_UNSIGNED
14322 && mem_mode != VOIDmode
14323 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
14327 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
14331 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
14332 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
14334 dw_die_ref type_die = base_type_for_mode (mode, 0);
14335 if (type_die == NULL)
14337 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
14339 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14340 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14341 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
14342 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
14343 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
14346 mem_loc_result->dw_loc_oprnd2.val_class
14347 = dw_val_class_const_double;
14348 mem_loc_result->dw_loc_oprnd2.v.val_double
14349 = shwi_to_double_int (INTVAL (rtl));
14357 dw_die_ref type_die;
14359 /* Note that a CONST_DOUBLE rtx could represent either an integer
14360 or a floating-point constant. A CONST_DOUBLE is used whenever
14361 the constant requires more than one word in order to be
14362 adequately represented. We output CONST_DOUBLEs as blocks. */
14363 if (mode == VOIDmode
14364 || (GET_MODE (rtl) == VOIDmode
14365 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
14367 type_die = base_type_for_mode (mode, 0);
14368 if (type_die == NULL)
14370 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
14371 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14372 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14373 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
14374 if (SCALAR_FLOAT_MODE_P (mode))
14376 unsigned int length = GET_MODE_SIZE (mode);
14377 unsigned char *array
14378 = (unsigned char*) ggc_alloc_atomic (length);
14380 insert_float (rtl, array);
14381 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14382 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14383 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14384 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14388 mem_loc_result->dw_loc_oprnd2.val_class
14389 = dw_val_class_const_double;
14390 mem_loc_result->dw_loc_oprnd2.v.val_double
14391 = rtx_to_double_int (rtl);
14422 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14424 if (op_mode == VOIDmode)
14425 op_mode = GET_MODE (XEXP (rtl, 1));
14426 if (op_mode == VOIDmode)
14430 && (GET_MODE_CLASS (op_mode) != MODE_INT
14431 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
14434 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
14435 VAR_INIT_STATUS_INITIALIZED);
14436 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
14437 VAR_INIT_STATUS_INITIALIZED);
14439 if (op0 == 0 || op1 == 0)
14442 if (GET_MODE_CLASS (op_mode) == MODE_INT
14443 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14445 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
14446 shift *= BITS_PER_UNIT;
14447 /* For eq/ne, if the operands are known to be zero-extended,
14448 there is no need to do the fancy shifting up. */
14449 if (op == DW_OP_eq || op == DW_OP_ne)
14451 dw_loc_descr_ref last0, last1;
14453 last0->dw_loc_next != NULL;
14454 last0 = last0->dw_loc_next)
14457 last1->dw_loc_next != NULL;
14458 last1 = last1->dw_loc_next)
14460 /* deref_size zero extends, and for constants we can check
14461 whether they are zero extended or not. */
14462 if (((last0->dw_loc_opc == DW_OP_deref_size
14463 && last0->dw_loc_oprnd1.v.val_int
14464 <= GET_MODE_SIZE (op_mode))
14465 || (CONST_INT_P (XEXP (rtl, 0))
14466 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14467 == (INTVAL (XEXP (rtl, 0))
14468 & GET_MODE_MASK (op_mode))))
14469 && ((last1->dw_loc_opc == DW_OP_deref_size
14470 && last1->dw_loc_oprnd1.v.val_int
14471 <= GET_MODE_SIZE (op_mode))
14472 || (CONST_INT_P (XEXP (rtl, 1))
14473 && (unsigned HOST_WIDE_INT)
14474 INTVAL (XEXP (rtl, 1))
14475 == (INTVAL (XEXP (rtl, 1))
14476 & GET_MODE_MASK (op_mode)))))
14479 add_loc_descr (&op0, int_loc_descriptor (shift));
14480 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14481 if (CONST_INT_P (XEXP (rtl, 1)))
14482 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14485 add_loc_descr (&op1, int_loc_descriptor (shift));
14486 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14492 mem_loc_result = op0;
14493 add_loc_descr (&mem_loc_result, op1);
14494 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14495 if (STORE_FLAG_VALUE != 1)
14497 add_loc_descr (&mem_loc_result,
14498 int_loc_descriptor (STORE_FLAG_VALUE));
14499 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14521 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14523 if (op_mode == VOIDmode)
14524 op_mode = GET_MODE (XEXP (rtl, 1));
14525 if (op_mode == VOIDmode)
14527 if (GET_MODE_CLASS (op_mode) != MODE_INT)
14530 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
14533 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14536 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
14537 VAR_INIT_STATUS_INITIALIZED);
14538 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
14539 VAR_INIT_STATUS_INITIALIZED);
14541 if (op0 == 0 || op1 == 0)
14544 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14546 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14547 dw_loc_descr_ref last0, last1;
14549 last0->dw_loc_next != NULL;
14550 last0 = last0->dw_loc_next)
14553 last1->dw_loc_next != NULL;
14554 last1 = last1->dw_loc_next)
14556 if (CONST_INT_P (XEXP (rtl, 0)))
14557 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14558 /* deref_size zero extends, so no need to mask it again. */
14559 else if (last0->dw_loc_opc != DW_OP_deref_size
14560 || last0->dw_loc_oprnd1.v.val_int
14561 > GET_MODE_SIZE (op_mode))
14563 add_loc_descr (&op0, int_loc_descriptor (mask));
14564 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14566 if (CONST_INT_P (XEXP (rtl, 1)))
14567 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14568 /* deref_size zero extends, so no need to mask it again. */
14569 else if (last1->dw_loc_opc != DW_OP_deref_size
14570 || last1->dw_loc_oprnd1.v.val_int
14571 > GET_MODE_SIZE (op_mode))
14573 add_loc_descr (&op1, int_loc_descriptor (mask));
14574 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14577 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
14579 HOST_WIDE_INT bias = 1;
14580 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14581 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14582 if (CONST_INT_P (XEXP (rtl, 1)))
14583 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14584 + INTVAL (XEXP (rtl, 1)));
14586 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14591 dw_die_ref type_die = base_type_for_mode (mode, 1);
14592 dw_loc_descr_ref cvt;
14594 if (type_die == NULL)
14596 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14597 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14598 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14599 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14600 add_loc_descr (&op0, cvt);
14601 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14602 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14603 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14604 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14605 add_loc_descr (&op1, cvt);
14612 if (GET_MODE_CLASS (mode) != MODE_INT)
14618 && (GET_MODE_CLASS (mode) != MODE_INT
14619 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
14622 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14623 VAR_INIT_STATUS_INITIALIZED);
14624 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14625 VAR_INIT_STATUS_INITIALIZED);
14627 if (op0 == 0 || op1 == 0)
14630 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14631 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14632 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14633 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14635 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14637 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
14638 add_loc_descr (&op0, int_loc_descriptor (mask));
14639 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14640 add_loc_descr (&op1, int_loc_descriptor (mask));
14641 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14643 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
14645 HOST_WIDE_INT bias = 1;
14646 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14647 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14648 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14652 dw_die_ref type_die = base_type_for_mode (mode, 1);
14653 dw_loc_descr_ref cvt;
14655 if (type_die == NULL)
14657 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14658 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14659 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14660 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14661 add_loc_descr (&op0, cvt);
14662 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14663 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14664 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14665 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14666 add_loc_descr (&op1, cvt);
14669 else if (GET_MODE_CLASS (mode) == MODE_INT
14670 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14672 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode);
14673 shift *= BITS_PER_UNIT;
14674 add_loc_descr (&op0, int_loc_descriptor (shift));
14675 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14676 add_loc_descr (&op1, int_loc_descriptor (shift));
14677 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14680 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14684 mem_loc_result = op0;
14685 add_loc_descr (&mem_loc_result, op1);
14686 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14688 dw_loc_descr_ref bra_node, drop_node;
14690 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14691 add_loc_descr (&mem_loc_result, bra_node);
14692 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14693 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14694 add_loc_descr (&mem_loc_result, drop_node);
14695 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14696 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14702 if (CONST_INT_P (XEXP (rtl, 1))
14703 && CONST_INT_P (XEXP (rtl, 2))
14704 && ((unsigned) INTVAL (XEXP (rtl, 1))
14705 + (unsigned) INTVAL (XEXP (rtl, 2))
14706 <= GET_MODE_BITSIZE (mode))
14707 && GET_MODE_CLASS (mode) == MODE_INT
14708 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14709 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14712 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
14713 mem_mode, VAR_INIT_STATUS_INITIALIZED);
14716 if (GET_CODE (rtl) == SIGN_EXTRACT)
14720 mem_loc_result = op0;
14721 size = INTVAL (XEXP (rtl, 1));
14722 shift = INTVAL (XEXP (rtl, 2));
14723 if (BITS_BIG_ENDIAN)
14724 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14726 if (shift + size != (int) DWARF2_ADDR_SIZE)
14728 add_loc_descr (&mem_loc_result,
14729 int_loc_descriptor (DWARF2_ADDR_SIZE
14731 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14733 if (size != (int) DWARF2_ADDR_SIZE)
14735 add_loc_descr (&mem_loc_result,
14736 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14737 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14744 dw_loc_descr_ref op2, bra_node, drop_node;
14745 op0 = mem_loc_descriptor (XEXP (rtl, 0),
14746 GET_MODE (XEXP (rtl, 0)) == VOIDmode
14747 ? word_mode : GET_MODE (XEXP (rtl, 0)),
14748 mem_mode, VAR_INIT_STATUS_INITIALIZED);
14749 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14750 VAR_INIT_STATUS_INITIALIZED);
14751 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
14752 VAR_INIT_STATUS_INITIALIZED);
14753 if (op0 == NULL || op1 == NULL || op2 == NULL)
14756 mem_loc_result = op1;
14757 add_loc_descr (&mem_loc_result, op2);
14758 add_loc_descr (&mem_loc_result, op0);
14759 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14760 add_loc_descr (&mem_loc_result, bra_node);
14761 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14762 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14763 add_loc_descr (&mem_loc_result, drop_node);
14764 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14765 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14770 case FLOAT_TRUNCATE:
14772 case UNSIGNED_FLOAT:
14777 dw_die_ref type_die;
14778 dw_loc_descr_ref cvt;
14780 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
14781 mem_mode, VAR_INIT_STATUS_INITIALIZED);
14784 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
14785 && (GET_CODE (rtl) == UNSIGNED_FLOAT
14786 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
14787 <= DWARF2_ADDR_SIZE))
14789 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
14790 GET_CODE (rtl) == UNSIGNED_FLOAT);
14791 if (type_die == NULL)
14793 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14794 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14795 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14796 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14797 add_loc_descr (&op0, cvt);
14799 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
14800 if (type_die == NULL)
14802 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14803 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14804 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14805 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14806 add_loc_descr (&op0, cvt);
14807 if (GET_MODE_CLASS (mode) == MODE_INT
14808 && (GET_CODE (rtl) == UNSIGNED_FIX
14809 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
14811 enum machine_mode outer_mode = mode;
14812 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14814 outer_mode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
14816 if (outer_mode == BLKmode
14817 || GET_MODE_SIZE (outer_mode) != DWARF2_ADDR_SIZE)
14820 type_die = base_type_for_mode (outer_mode, 0);
14821 if (type_die == NULL)
14823 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14824 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14825 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14826 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14827 add_loc_descr (&op0, cvt);
14829 mem_loc_result = op0;
14837 /* In theory, we could implement the above. */
14838 /* DWARF cannot represent the unsigned compare operations
14864 case FRACT_CONVERT:
14865 case UNSIGNED_FRACT_CONVERT:
14867 case UNSIGNED_SAT_FRACT:
14879 case VEC_DUPLICATE:
14883 case STRICT_LOW_PART:
14886 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14887 can't express it in the debug info. This can happen e.g. with some
14892 resolve_one_addr (&rtl, NULL);
14896 #ifdef ENABLE_CHECKING
14897 print_rtl (stderr, rtl);
14898 gcc_unreachable ();
14904 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14905 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14907 return mem_loc_result;
14910 /* Return a descriptor that describes the concatenation of two locations.
14911 This is typically a complex variable. */
14913 static dw_loc_descr_ref
14914 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14916 dw_loc_descr_ref cc_loc_result = NULL;
14917 dw_loc_descr_ref x0_ref
14918 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14919 dw_loc_descr_ref x1_ref
14920 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14922 if (x0_ref == 0 || x1_ref == 0)
14925 cc_loc_result = x0_ref;
14926 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14928 add_loc_descr (&cc_loc_result, x1_ref);
14929 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14931 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14932 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14934 return cc_loc_result;
14937 /* Return a descriptor that describes the concatenation of N
14940 static dw_loc_descr_ref
14941 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14944 dw_loc_descr_ref cc_loc_result = NULL;
14945 unsigned int n = XVECLEN (concatn, 0);
14947 for (i = 0; i < n; ++i)
14949 dw_loc_descr_ref ref;
14950 rtx x = XVECEXP (concatn, 0, i);
14952 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14956 add_loc_descr (&cc_loc_result, ref);
14957 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14960 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14961 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14963 return cc_loc_result;
14966 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14967 for DEBUG_IMPLICIT_PTR RTL. */
14969 static dw_loc_descr_ref
14970 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14972 dw_loc_descr_ref ret;
14977 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14978 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14979 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14980 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14981 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14982 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14985 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14986 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14987 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14991 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14992 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14997 /* Output a proper Dwarf location descriptor for a variable or parameter
14998 which is either allocated in a register or in a memory location. For a
14999 register, we just generate an OP_REG and the register number. For a
15000 memory location we provide a Dwarf postfix expression describing how to
15001 generate the (dynamic) address of the object onto the address stack.
15003 MODE is mode of the decl if this loc_descriptor is going to be used in
15004 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15005 allowed, VOIDmode otherwise.
15007 If we don't know how to describe it, return 0. */
15009 static dw_loc_descr_ref
15010 loc_descriptor (rtx rtl, enum machine_mode mode,
15011 enum var_init_status initialized)
15013 dw_loc_descr_ref loc_result = NULL;
15015 switch (GET_CODE (rtl))
15018 /* The case of a subreg may arise when we have a local (register)
15019 variable or a formal (register) parameter which doesn't quite fill
15020 up an entire register. For now, just assume that it is
15021 legitimate to make the Dwarf info refer to the whole register which
15022 contains the given subreg. */
15023 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
15024 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
15030 loc_result = reg_loc_descriptor (rtl, initialized);
15034 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
15035 GET_MODE (rtl), initialized);
15036 if (loc_result == NULL)
15037 loc_result = tls_mem_loc_descriptor (rtl);
15038 if (loc_result == NULL)
15040 rtx new_rtl = avoid_constant_pool_reference (rtl);
15041 if (new_rtl != rtl)
15042 loc_result = loc_descriptor (new_rtl, mode, initialized);
15047 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
15052 loc_result = concatn_loc_descriptor (rtl, initialized);
15057 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
15059 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
15060 if (GET_CODE (loc) == EXPR_LIST)
15061 loc = XEXP (loc, 0);
15062 loc_result = loc_descriptor (loc, mode, initialized);
15066 rtl = XEXP (rtl, 1);
15071 rtvec par_elems = XVEC (rtl, 0);
15072 int num_elem = GET_NUM_ELEM (par_elems);
15073 enum machine_mode mode;
15076 /* Create the first one, so we have something to add to. */
15077 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
15078 VOIDmode, initialized);
15079 if (loc_result == NULL)
15081 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
15082 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
15083 for (i = 1; i < num_elem; i++)
15085 dw_loc_descr_ref temp;
15087 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
15088 VOIDmode, initialized);
15091 add_loc_descr (&loc_result, temp);
15092 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
15093 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
15099 if (mode != VOIDmode && mode != BLKmode)
15100 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
15105 if (mode == VOIDmode)
15106 mode = GET_MODE (rtl);
15108 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
15110 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
15112 /* Note that a CONST_DOUBLE rtx could represent either an integer
15113 or a floating-point constant. A CONST_DOUBLE is used whenever
15114 the constant requires more than one word in order to be
15115 adequately represented. We output CONST_DOUBLEs as blocks. */
15116 loc_result = new_loc_descr (DW_OP_implicit_value,
15117 GET_MODE_SIZE (mode), 0);
15118 if (SCALAR_FLOAT_MODE_P (mode))
15120 unsigned int length = GET_MODE_SIZE (mode);
15121 unsigned char *array
15122 = (unsigned char*) ggc_alloc_atomic (length);
15124 insert_float (rtl, array);
15125 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15126 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
15127 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
15128 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15132 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
15133 loc_result->dw_loc_oprnd2.v.val_double
15134 = rtx_to_double_int (rtl);
15140 if (mode == VOIDmode)
15141 mode = GET_MODE (rtl);
15143 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
15145 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
15146 unsigned int length = CONST_VECTOR_NUNITS (rtl);
15147 unsigned char *array = (unsigned char *)
15148 ggc_alloc_atomic (length * elt_size);
15152 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
15153 switch (GET_MODE_CLASS (mode))
15155 case MODE_VECTOR_INT:
15156 for (i = 0, p = array; i < length; i++, p += elt_size)
15158 rtx elt = CONST_VECTOR_ELT (rtl, i);
15159 double_int val = rtx_to_double_int (elt);
15161 if (elt_size <= sizeof (HOST_WIDE_INT))
15162 insert_int (double_int_to_shwi (val), elt_size, p);
15165 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
15166 insert_double (val, p);
15171 case MODE_VECTOR_FLOAT:
15172 for (i = 0, p = array; i < length; i++, p += elt_size)
15174 rtx elt = CONST_VECTOR_ELT (rtl, i);
15175 insert_float (elt, p);
15180 gcc_unreachable ();
15183 loc_result = new_loc_descr (DW_OP_implicit_value,
15184 length * elt_size, 0);
15185 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15186 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
15187 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
15188 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15193 if (mode == VOIDmode
15194 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
15195 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
15196 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
15198 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
15203 if (!const_ok_for_output (rtl))
15206 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
15207 && (dwarf_version >= 4 || !dwarf_strict))
15209 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
15210 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
15211 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
15212 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
15213 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
15217 case DEBUG_IMPLICIT_PTR:
15218 loc_result = implicit_ptr_descriptor (rtl, 0);
15222 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
15223 && CONST_INT_P (XEXP (rtl, 1)))
15226 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
15232 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
15233 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
15234 && dwarf_version >= 4)
15235 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
15237 /* Value expression. */
15238 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
15240 add_loc_descr (&loc_result,
15241 new_loc_descr (DW_OP_stack_value, 0, 0));
15249 /* We need to figure out what section we should use as the base for the
15250 address ranges where a given location is valid.
15251 1. If this particular DECL has a section associated with it, use that.
15252 2. If this function has a section associated with it, use that.
15253 3. Otherwise, use the text section.
15254 XXX: If you split a variable across multiple sections, we won't notice. */
15256 static const char *
15257 secname_for_decl (const_tree decl)
15259 const char *secname;
15261 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
15263 tree sectree = DECL_SECTION_NAME (decl);
15264 secname = TREE_STRING_POINTER (sectree);
15266 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
15268 tree sectree = DECL_SECTION_NAME (current_function_decl);
15269 secname = TREE_STRING_POINTER (sectree);
15271 else if (cfun && in_cold_section_p)
15272 secname = crtl->subsections.cold_section_label;
15274 secname = text_section_label;
15279 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
15282 decl_by_reference_p (tree decl)
15284 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
15285 || TREE_CODE (decl) == VAR_DECL)
15286 && DECL_BY_REFERENCE (decl));
15289 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15292 static dw_loc_descr_ref
15293 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
15294 enum var_init_status initialized)
15296 int have_address = 0;
15297 dw_loc_descr_ref descr;
15298 enum machine_mode mode;
15300 if (want_address != 2)
15302 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
15304 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15306 varloc = PAT_VAR_LOCATION_LOC (varloc);
15307 if (GET_CODE (varloc) == EXPR_LIST)
15308 varloc = XEXP (varloc, 0);
15309 mode = GET_MODE (varloc);
15310 if (MEM_P (varloc))
15312 rtx addr = XEXP (varloc, 0);
15313 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
15314 mode, initialized);
15319 rtx x = avoid_constant_pool_reference (varloc);
15321 descr = mem_loc_descriptor (x, mode, VOIDmode,
15326 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
15333 if (GET_CODE (varloc) == VAR_LOCATION)
15334 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
15336 mode = DECL_MODE (loc);
15337 descr = loc_descriptor (varloc, mode, initialized);
15344 if (want_address == 2 && !have_address
15345 && (dwarf_version >= 4 || !dwarf_strict))
15347 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15349 expansion_failed (loc, NULL_RTX,
15350 "DWARF address size mismatch");
15353 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
15356 /* Show if we can't fill the request for an address. */
15357 if (want_address && !have_address)
15359 expansion_failed (loc, NULL_RTX,
15360 "Want address and only have value");
15364 /* If we've got an address and don't want one, dereference. */
15365 if (!want_address && have_address)
15367 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15368 enum dwarf_location_atom op;
15370 if (size > DWARF2_ADDR_SIZE || size == -1)
15372 expansion_failed (loc, NULL_RTX,
15373 "DWARF address size mismatch");
15376 else if (size == DWARF2_ADDR_SIZE)
15379 op = DW_OP_deref_size;
15381 add_loc_descr (&descr, new_loc_descr (op, size, 0));
15387 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
15388 if it is not possible. */
15390 static dw_loc_descr_ref
15391 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
15393 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
15394 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
15395 else if (dwarf_version >= 3 || !dwarf_strict)
15396 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
15401 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15402 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
15404 static dw_loc_descr_ref
15405 dw_sra_loc_expr (tree decl, rtx loc)
15408 unsigned int padsize = 0;
15409 dw_loc_descr_ref descr, *descr_tail;
15410 unsigned HOST_WIDE_INT decl_size;
15412 enum var_init_status initialized;
15414 if (DECL_SIZE (decl) == NULL
15415 || !host_integerp (DECL_SIZE (decl), 1))
15418 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
15420 descr_tail = &descr;
15422 for (p = loc; p; p = XEXP (p, 1))
15424 unsigned int bitsize = decl_piece_bitsize (p);
15425 rtx loc_note = *decl_piece_varloc_ptr (p);
15426 dw_loc_descr_ref cur_descr;
15427 dw_loc_descr_ref *tail, last = NULL;
15428 unsigned int opsize = 0;
15430 if (loc_note == NULL_RTX
15431 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
15433 padsize += bitsize;
15436 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
15437 varloc = NOTE_VAR_LOCATION (loc_note);
15438 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
15439 if (cur_descr == NULL)
15441 padsize += bitsize;
15445 /* Check that cur_descr either doesn't use
15446 DW_OP_*piece operations, or their sum is equal
15447 to bitsize. Otherwise we can't embed it. */
15448 for (tail = &cur_descr; *tail != NULL;
15449 tail = &(*tail)->dw_loc_next)
15450 if ((*tail)->dw_loc_opc == DW_OP_piece)
15452 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
15456 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
15458 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
15462 if (last != NULL && opsize != bitsize)
15464 padsize += bitsize;
15468 /* If there is a hole, add DW_OP_*piece after empty DWARF
15469 expression, which means that those bits are optimized out. */
15472 if (padsize > decl_size)
15474 decl_size -= padsize;
15475 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
15476 if (*descr_tail == NULL)
15478 descr_tail = &(*descr_tail)->dw_loc_next;
15481 *descr_tail = cur_descr;
15483 if (bitsize > decl_size)
15485 decl_size -= bitsize;
15488 HOST_WIDE_INT offset = 0;
15489 if (GET_CODE (varloc) == VAR_LOCATION
15490 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15492 varloc = PAT_VAR_LOCATION_LOC (varloc);
15493 if (GET_CODE (varloc) == EXPR_LIST)
15494 varloc = XEXP (varloc, 0);
15498 if (GET_CODE (varloc) == CONST
15499 || GET_CODE (varloc) == SIGN_EXTEND
15500 || GET_CODE (varloc) == ZERO_EXTEND)
15501 varloc = XEXP (varloc, 0);
15502 else if (GET_CODE (varloc) == SUBREG)
15503 varloc = SUBREG_REG (varloc);
15508 /* DW_OP_bit_size offset should be zero for register
15509 or implicit location descriptions and empty location
15510 descriptions, but for memory addresses needs big endian
15512 if (MEM_P (varloc))
15514 unsigned HOST_WIDE_INT memsize
15515 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
15516 if (memsize != bitsize)
15518 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
15519 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
15521 if (memsize < bitsize)
15523 if (BITS_BIG_ENDIAN)
15524 offset = memsize - bitsize;
15528 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
15529 if (*descr_tail == NULL)
15531 descr_tail = &(*descr_tail)->dw_loc_next;
15535 /* If there were any non-empty expressions, add padding till the end of
15537 if (descr != NULL && decl_size != 0)
15539 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
15540 if (*descr_tail == NULL)
15546 /* Return the dwarf representation of the location list LOC_LIST of
15547 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
15550 static dw_loc_list_ref
15551 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
15553 const char *endname, *secname;
15555 enum var_init_status initialized;
15556 struct var_loc_node *node;
15557 dw_loc_descr_ref descr;
15558 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15559 dw_loc_list_ref list = NULL;
15560 dw_loc_list_ref *listp = &list;
15562 /* Now that we know what section we are using for a base,
15563 actually construct the list of locations.
15564 The first location information is what is passed to the
15565 function that creates the location list, and the remaining
15566 locations just get added on to that list.
15567 Note that we only know the start address for a location
15568 (IE location changes), so to build the range, we use
15569 the range [current location start, next location start].
15570 This means we have to special case the last node, and generate
15571 a range of [last location start, end of function label]. */
15573 secname = secname_for_decl (decl);
15575 for (node = loc_list->first; node; node = node->next)
15576 if (GET_CODE (node->loc) == EXPR_LIST
15577 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
15579 if (GET_CODE (node->loc) == EXPR_LIST)
15581 /* This requires DW_OP_{,bit_}piece, which is not usable
15582 inside DWARF expressions. */
15583 if (want_address != 2)
15585 descr = dw_sra_loc_expr (decl, node->loc);
15591 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15592 varloc = NOTE_VAR_LOCATION (node->loc);
15593 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15597 bool range_across_switch = false;
15598 /* If section switch happens in between node->label
15599 and node->next->label (or end of function) and
15600 we can't emit it as a single entry list,
15601 emit two ranges, first one ending at the end
15602 of first partition and second one starting at the
15603 beginning of second partition. */
15604 if (node == loc_list->last_before_switch
15605 && (node != loc_list->first || loc_list->first->next)
15606 && current_function_decl)
15608 endname = current_fde ()->dw_fde_end;
15609 range_across_switch = true;
15611 /* The variable has a location between NODE->LABEL and
15612 NODE->NEXT->LABEL. */
15613 else if (node->next)
15614 endname = node->next->label;
15615 /* If the variable has a location at the last label
15616 it keeps its location until the end of function. */
15617 else if (!current_function_decl)
15618 endname = text_end_label;
15621 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15622 current_function_funcdef_no);
15623 endname = ggc_strdup (label_id);
15626 *listp = new_loc_list (descr, node->label, endname, secname);
15627 listp = &(*listp)->dw_loc_next;
15629 if (range_across_switch)
15631 if (GET_CODE (node->loc) == EXPR_LIST)
15632 descr = dw_sra_loc_expr (decl, node->loc);
15635 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15636 varloc = NOTE_VAR_LOCATION (node->loc);
15637 descr = dw_loc_list_1 (decl, varloc, want_address,
15640 gcc_assert (descr);
15641 /* The variable has a location between NODE->LABEL and
15642 NODE->NEXT->LABEL. */
15644 endname = node->next->label;
15646 endname = current_fde ()->dw_fde_second_end;
15647 *listp = new_loc_list (descr,
15648 current_fde ()->dw_fde_second_begin,
15650 listp = &(*listp)->dw_loc_next;
15655 /* Try to avoid the overhead of a location list emitting a location
15656 expression instead, but only if we didn't have more than one
15657 location entry in the first place. If some entries were not
15658 representable, we don't want to pretend a single entry that was
15659 applies to the entire scope in which the variable is
15661 if (list && loc_list->first->next)
15667 /* Return if the loc_list has only single element and thus can be represented
15668 as location description. */
15671 single_element_loc_list_p (dw_loc_list_ref list)
15673 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15674 return !list->ll_symbol;
15677 /* To each location in list LIST add loc descr REF. */
15680 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15682 dw_loc_descr_ref copy;
15683 add_loc_descr (&list->expr, ref);
15684 list = list->dw_loc_next;
15687 copy = ggc_alloc_dw_loc_descr_node ();
15688 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15689 add_loc_descr (&list->expr, copy);
15690 while (copy->dw_loc_next)
15692 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15693 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15694 copy->dw_loc_next = new_copy;
15697 list = list->dw_loc_next;
15701 /* Given two lists RET and LIST
15702 produce location list that is result of adding expression in LIST
15703 to expression in RET on each possition in program.
15704 Might be destructive on both RET and LIST.
15706 TODO: We handle only simple cases of RET or LIST having at most one
15707 element. General case would inolve sorting the lists in program order
15708 and merging them that will need some additional work.
15709 Adding that will improve quality of debug info especially for SRA-ed
15713 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15722 if (!list->dw_loc_next)
15724 add_loc_descr_to_each (*ret, list->expr);
15727 if (!(*ret)->dw_loc_next)
15729 add_loc_descr_to_each (list, (*ret)->expr);
15733 expansion_failed (NULL_TREE, NULL_RTX,
15734 "Don't know how to merge two non-trivial"
15735 " location lists.\n");
15740 /* LOC is constant expression. Try a luck, look it up in constant
15741 pool and return its loc_descr of its address. */
15743 static dw_loc_descr_ref
15744 cst_pool_loc_descr (tree loc)
15746 /* Get an RTL for this, if something has been emitted. */
15747 rtx rtl = lookup_constant_def (loc);
15749 if (!rtl || !MEM_P (rtl))
15754 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15756 /* TODO: We might get more coverage if we was actually delaying expansion
15757 of all expressions till end of compilation when constant pools are fully
15759 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15761 expansion_failed (loc, NULL_RTX,
15762 "CST value in contant pool but not marked.");
15765 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
15766 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
15769 /* Return dw_loc_list representing address of addr_expr LOC
15770 by looking for innder INDIRECT_REF expression and turing it
15771 into simple arithmetics. */
15773 static dw_loc_list_ref
15774 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15777 HOST_WIDE_INT bitsize, bitpos, bytepos;
15778 enum machine_mode mode;
15780 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15781 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15783 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15784 &bitsize, &bitpos, &offset, &mode,
15785 &unsignedp, &volatilep, false);
15787 if (bitpos % BITS_PER_UNIT)
15789 expansion_failed (loc, NULL_RTX, "bitfield access");
15792 if (!INDIRECT_REF_P (obj))
15794 expansion_failed (obj,
15795 NULL_RTX, "no indirect ref in inner refrence");
15798 if (!offset && !bitpos)
15799 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15801 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15802 && (dwarf_version >= 4 || !dwarf_strict))
15804 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15809 /* Variable offset. */
15810 list_ret1 = loc_list_from_tree (offset, 0);
15811 if (list_ret1 == 0)
15813 add_loc_list (&list_ret, list_ret1);
15816 add_loc_descr_to_each (list_ret,
15817 new_loc_descr (DW_OP_plus, 0, 0));
15819 bytepos = bitpos / BITS_PER_UNIT;
15821 add_loc_descr_to_each (list_ret,
15822 new_loc_descr (DW_OP_plus_uconst,
15824 else if (bytepos < 0)
15825 loc_list_plus_const (list_ret, bytepos);
15826 add_loc_descr_to_each (list_ret,
15827 new_loc_descr (DW_OP_stack_value, 0, 0));
15833 /* Generate Dwarf location list representing LOC.
15834 If WANT_ADDRESS is false, expression computing LOC will be computed
15835 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15836 if WANT_ADDRESS is 2, expression computing address useable in location
15837 will be returned (i.e. DW_OP_reg can be used
15838 to refer to register values). */
15840 static dw_loc_list_ref
15841 loc_list_from_tree (tree loc, int want_address)
15843 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15844 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15845 int have_address = 0;
15846 enum dwarf_location_atom op;
15848 /* ??? Most of the time we do not take proper care for sign/zero
15849 extending the values properly. Hopefully this won't be a real
15852 switch (TREE_CODE (loc))
15855 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15858 case PLACEHOLDER_EXPR:
15859 /* This case involves extracting fields from an object to determine the
15860 position of other fields. We don't try to encode this here. The
15861 only user of this is Ada, which encodes the needed information using
15862 the names of types. */
15863 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15867 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15868 /* There are no opcodes for these operations. */
15871 case PREINCREMENT_EXPR:
15872 case PREDECREMENT_EXPR:
15873 case POSTINCREMENT_EXPR:
15874 case POSTDECREMENT_EXPR:
15875 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15876 /* There are no opcodes for these operations. */
15880 /* If we already want an address, see if there is INDIRECT_REF inside
15881 e.g. for &this->field. */
15884 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15885 (loc, want_address == 2);
15888 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15889 && (ret = cst_pool_loc_descr (loc)))
15892 /* Otherwise, process the argument and look for the address. */
15893 if (!list_ret && !ret)
15894 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15898 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15904 if (DECL_THREAD_LOCAL_P (loc))
15907 enum dwarf_location_atom first_op;
15908 enum dwarf_location_atom second_op;
15909 bool dtprel = false;
15911 if (targetm.have_tls)
15913 /* If this is not defined, we have no way to emit the
15915 if (!targetm.asm_out.output_dwarf_dtprel)
15918 /* The way DW_OP_GNU_push_tls_address is specified, we
15919 can only look up addresses of objects in the current
15920 module. We used DW_OP_addr as first op, but that's
15921 wrong, because DW_OP_addr is relocated by the debug
15922 info consumer, while DW_OP_GNU_push_tls_address
15923 operand shouldn't be. */
15924 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15926 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15928 second_op = DW_OP_GNU_push_tls_address;
15932 if (!targetm.emutls.debug_form_tls_address
15933 || !(dwarf_version >= 3 || !dwarf_strict))
15935 /* We stuffed the control variable into the DECL_VALUE_EXPR
15936 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15937 no longer appear in gimple code. We used the control
15938 variable in specific so that we could pick it up here. */
15939 loc = DECL_VALUE_EXPR (loc);
15940 first_op = DW_OP_addr;
15941 second_op = DW_OP_form_tls_address;
15944 rtl = rtl_for_decl_location (loc);
15945 if (rtl == NULL_RTX)
15950 rtl = XEXP (rtl, 0);
15951 if (! CONSTANT_P (rtl))
15954 ret = new_loc_descr (first_op, 0, 0);
15955 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15956 ret->dw_loc_oprnd1.v.val_addr = rtl;
15957 ret->dtprel = dtprel;
15959 ret1 = new_loc_descr (second_op, 0, 0);
15960 add_loc_descr (&ret, ret1);
15969 if (DECL_HAS_VALUE_EXPR_P (loc))
15970 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15974 case FUNCTION_DECL:
15977 var_loc_list *loc_list = lookup_decl_loc (loc);
15979 if (loc_list && loc_list->first)
15981 list_ret = dw_loc_list (loc_list, loc, want_address);
15982 have_address = want_address != 0;
15985 rtl = rtl_for_decl_location (loc);
15986 if (rtl == NULL_RTX)
15988 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15991 else if (CONST_INT_P (rtl))
15993 HOST_WIDE_INT val = INTVAL (rtl);
15994 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15995 val &= GET_MODE_MASK (DECL_MODE (loc));
15996 ret = int_loc_descriptor (val);
15998 else if (GET_CODE (rtl) == CONST_STRING)
16000 expansion_failed (loc, NULL_RTX, "CONST_STRING");
16003 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
16005 ret = new_loc_descr (DW_OP_addr, 0, 0);
16006 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
16007 ret->dw_loc_oprnd1.v.val_addr = rtl;
16011 enum machine_mode mode, mem_mode;
16013 /* Certain constructs can only be represented at top-level. */
16014 if (want_address == 2)
16016 ret = loc_descriptor (rtl, VOIDmode,
16017 VAR_INIT_STATUS_INITIALIZED);
16022 mode = GET_MODE (rtl);
16023 mem_mode = VOIDmode;
16027 mode = get_address_mode (rtl);
16028 rtl = XEXP (rtl, 0);
16031 ret = mem_loc_descriptor (rtl, mode, mem_mode,
16032 VAR_INIT_STATUS_INITIALIZED);
16035 expansion_failed (loc, rtl,
16036 "failed to produce loc descriptor for rtl");
16043 if (!integer_zerop (TREE_OPERAND (loc, 1)))
16047 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16051 case COMPOUND_EXPR:
16052 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
16055 case VIEW_CONVERT_EXPR:
16058 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
16060 case COMPONENT_REF:
16061 case BIT_FIELD_REF:
16063 case ARRAY_RANGE_REF:
16064 case REALPART_EXPR:
16065 case IMAGPART_EXPR:
16068 HOST_WIDE_INT bitsize, bitpos, bytepos;
16069 enum machine_mode mode;
16071 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
16073 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
16074 &unsignedp, &volatilep, false);
16076 gcc_assert (obj != loc);
16078 list_ret = loc_list_from_tree (obj,
16080 && !bitpos && !offset ? 2 : 1);
16081 /* TODO: We can extract value of the small expression via shifting even
16082 for nonzero bitpos. */
16085 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
16087 expansion_failed (loc, NULL_RTX,
16088 "bitfield access");
16092 if (offset != NULL_TREE)
16094 /* Variable offset. */
16095 list_ret1 = loc_list_from_tree (offset, 0);
16096 if (list_ret1 == 0)
16098 add_loc_list (&list_ret, list_ret1);
16101 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
16104 bytepos = bitpos / BITS_PER_UNIT;
16106 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
16107 else if (bytepos < 0)
16108 loc_list_plus_const (list_ret, bytepos);
16115 if ((want_address || !host_integerp (loc, 0))
16116 && (ret = cst_pool_loc_descr (loc)))
16118 else if (want_address == 2
16119 && host_integerp (loc, 0)
16120 && (ret = address_of_int_loc_descriptor
16121 (int_size_in_bytes (TREE_TYPE (loc)),
16122 tree_low_cst (loc, 0))))
16124 else if (host_integerp (loc, 0))
16125 ret = int_loc_descriptor (tree_low_cst (loc, 0));
16128 expansion_failed (loc, NULL_RTX,
16129 "Integer operand is not host integer");
16138 if ((ret = cst_pool_loc_descr (loc)))
16141 /* We can construct small constants here using int_loc_descriptor. */
16142 expansion_failed (loc, NULL_RTX,
16143 "constructor or constant not in constant pool");
16146 case TRUTH_AND_EXPR:
16147 case TRUTH_ANDIF_EXPR:
16152 case TRUTH_XOR_EXPR:
16157 case TRUTH_OR_EXPR:
16158 case TRUTH_ORIF_EXPR:
16163 case FLOOR_DIV_EXPR:
16164 case CEIL_DIV_EXPR:
16165 case ROUND_DIV_EXPR:
16166 case TRUNC_DIV_EXPR:
16167 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16176 case FLOOR_MOD_EXPR:
16177 case CEIL_MOD_EXPR:
16178 case ROUND_MOD_EXPR:
16179 case TRUNC_MOD_EXPR:
16180 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16185 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16186 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
16187 if (list_ret == 0 || list_ret1 == 0)
16190 add_loc_list (&list_ret, list_ret1);
16193 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16194 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16195 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
16196 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
16197 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
16209 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
16212 case POINTER_PLUS_EXPR:
16214 if (host_integerp (TREE_OPERAND (loc, 1), 0))
16216 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16220 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
16228 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16235 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16242 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16249 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16264 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16265 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
16266 if (list_ret == 0 || list_ret1 == 0)
16269 add_loc_list (&list_ret, list_ret1);
16272 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16275 case TRUTH_NOT_EXPR:
16289 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16293 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16299 const enum tree_code code =
16300 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
16302 loc = build3 (COND_EXPR, TREE_TYPE (loc),
16303 build2 (code, integer_type_node,
16304 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
16305 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
16308 /* ... fall through ... */
16312 dw_loc_descr_ref lhs
16313 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
16314 dw_loc_list_ref rhs
16315 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
16316 dw_loc_descr_ref bra_node, jump_node, tmp;
16318 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16319 if (list_ret == 0 || lhs == 0 || rhs == 0)
16322 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
16323 add_loc_descr_to_each (list_ret, bra_node);
16325 add_loc_list (&list_ret, rhs);
16326 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
16327 add_loc_descr_to_each (list_ret, jump_node);
16329 add_loc_descr_to_each (list_ret, lhs);
16330 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16331 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
16333 /* ??? Need a node to point the skip at. Use a nop. */
16334 tmp = new_loc_descr (DW_OP_nop, 0, 0);
16335 add_loc_descr_to_each (list_ret, tmp);
16336 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16337 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
16341 case FIX_TRUNC_EXPR:
16345 /* Leave front-end specific codes as simply unknown. This comes
16346 up, for instance, with the C STMT_EXPR. */
16347 if ((unsigned int) TREE_CODE (loc)
16348 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
16350 expansion_failed (loc, NULL_RTX,
16351 "language specific tree node");
16355 #ifdef ENABLE_CHECKING
16356 /* Otherwise this is a generic code; we should just lists all of
16357 these explicitly. We forgot one. */
16358 gcc_unreachable ();
16360 /* In a release build, we want to degrade gracefully: better to
16361 generate incomplete debugging information than to crash. */
16366 if (!ret && !list_ret)
16369 if (want_address == 2 && !have_address
16370 && (dwarf_version >= 4 || !dwarf_strict))
16372 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
16374 expansion_failed (loc, NULL_RTX,
16375 "DWARF address size mismatch");
16379 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
16381 add_loc_descr_to_each (list_ret,
16382 new_loc_descr (DW_OP_stack_value, 0, 0));
16385 /* Show if we can't fill the request for an address. */
16386 if (want_address && !have_address)
16388 expansion_failed (loc, NULL_RTX,
16389 "Want address and only have value");
16393 gcc_assert (!ret || !list_ret);
16395 /* If we've got an address and don't want one, dereference. */
16396 if (!want_address && have_address)
16398 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
16400 if (size > DWARF2_ADDR_SIZE || size == -1)
16402 expansion_failed (loc, NULL_RTX,
16403 "DWARF address size mismatch");
16406 else if (size == DWARF2_ADDR_SIZE)
16409 op = DW_OP_deref_size;
16412 add_loc_descr (&ret, new_loc_descr (op, size, 0));
16414 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
16417 list_ret = new_loc_list (ret, NULL, NULL, NULL);
16422 /* Same as above but return only single location expression. */
16423 static dw_loc_descr_ref
16424 loc_descriptor_from_tree (tree loc, int want_address)
16426 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
16429 if (ret->dw_loc_next)
16431 expansion_failed (loc, NULL_RTX,
16432 "Location list where only loc descriptor needed");
16438 /* Given a value, round it up to the lowest multiple of `boundary'
16439 which is not less than the value itself. */
16441 static inline HOST_WIDE_INT
16442 ceiling (HOST_WIDE_INT value, unsigned int boundary)
16444 return (((value + boundary - 1) / boundary) * boundary);
16447 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
16448 pointer to the declared type for the relevant field variable, or return
16449 `integer_type_node' if the given node turns out to be an
16450 ERROR_MARK node. */
16453 field_type (const_tree decl)
16457 if (TREE_CODE (decl) == ERROR_MARK)
16458 return integer_type_node;
16460 type = DECL_BIT_FIELD_TYPE (decl);
16461 if (type == NULL_TREE)
16462 type = TREE_TYPE (decl);
16467 /* Given a pointer to a tree node, return the alignment in bits for
16468 it, or else return BITS_PER_WORD if the node actually turns out to
16469 be an ERROR_MARK node. */
16471 static inline unsigned
16472 simple_type_align_in_bits (const_tree type)
16474 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
16477 static inline unsigned
16478 simple_decl_align_in_bits (const_tree decl)
16480 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
16483 /* Return the result of rounding T up to ALIGN. */
16485 static inline double_int
16486 round_up_to_align (double_int t, unsigned int align)
16488 double_int alignd = uhwi_to_double_int (align);
16489 t = double_int_add (t, alignd);
16490 t = double_int_add (t, double_int_minus_one);
16491 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
16492 t = double_int_mul (t, alignd);
16496 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
16497 lowest addressed byte of the "containing object" for the given FIELD_DECL,
16498 or return 0 if we are unable to determine what that offset is, either
16499 because the argument turns out to be a pointer to an ERROR_MARK node, or
16500 because the offset is actually variable. (We can't handle the latter case
16503 static HOST_WIDE_INT
16504 field_byte_offset (const_tree decl)
16506 double_int object_offset_in_bits;
16507 double_int object_offset_in_bytes;
16508 double_int bitpos_int;
16510 if (TREE_CODE (decl) == ERROR_MARK)
16513 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
16515 /* We cannot yet cope with fields whose positions are variable, so
16516 for now, when we see such things, we simply return 0. Someday, we may
16517 be able to handle such cases, but it will be damn difficult. */
16518 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
16521 bitpos_int = tree_to_double_int (bit_position (decl));
16523 #ifdef PCC_BITFIELD_TYPE_MATTERS
16524 if (PCC_BITFIELD_TYPE_MATTERS)
16527 tree field_size_tree;
16528 double_int deepest_bitpos;
16529 double_int field_size_in_bits;
16530 unsigned int type_align_in_bits;
16531 unsigned int decl_align_in_bits;
16532 double_int type_size_in_bits;
16534 type = field_type (decl);
16535 type_size_in_bits = double_int_type_size_in_bits (type);
16536 type_align_in_bits = simple_type_align_in_bits (type);
16538 field_size_tree = DECL_SIZE (decl);
16540 /* The size could be unspecified if there was an error, or for
16541 a flexible array member. */
16542 if (!field_size_tree)
16543 field_size_tree = bitsize_zero_node;
16545 /* If the size of the field is not constant, use the type size. */
16546 if (TREE_CODE (field_size_tree) == INTEGER_CST)
16547 field_size_in_bits = tree_to_double_int (field_size_tree);
16549 field_size_in_bits = type_size_in_bits;
16551 decl_align_in_bits = simple_decl_align_in_bits (decl);
16553 /* The GCC front-end doesn't make any attempt to keep track of the
16554 starting bit offset (relative to the start of the containing
16555 structure type) of the hypothetical "containing object" for a
16556 bit-field. Thus, when computing the byte offset value for the
16557 start of the "containing object" of a bit-field, we must deduce
16558 this information on our own. This can be rather tricky to do in
16559 some cases. For example, handling the following structure type
16560 definition when compiling for an i386/i486 target (which only
16561 aligns long long's to 32-bit boundaries) can be very tricky:
16563 struct S { int field1; long long field2:31; };
16565 Fortunately, there is a simple rule-of-thumb which can be used
16566 in such cases. When compiling for an i386/i486, GCC will
16567 allocate 8 bytes for the structure shown above. It decides to
16568 do this based upon one simple rule for bit-field allocation.
16569 GCC allocates each "containing object" for each bit-field at
16570 the first (i.e. lowest addressed) legitimate alignment boundary
16571 (based upon the required minimum alignment for the declared
16572 type of the field) which it can possibly use, subject to the
16573 condition that there is still enough available space remaining
16574 in the containing object (when allocated at the selected point)
16575 to fully accommodate all of the bits of the bit-field itself.
16577 This simple rule makes it obvious why GCC allocates 8 bytes for
16578 each object of the structure type shown above. When looking
16579 for a place to allocate the "containing object" for `field2',
16580 the compiler simply tries to allocate a 64-bit "containing
16581 object" at each successive 32-bit boundary (starting at zero)
16582 until it finds a place to allocate that 64- bit field such that
16583 at least 31 contiguous (and previously unallocated) bits remain
16584 within that selected 64 bit field. (As it turns out, for the
16585 example above, the compiler finds it is OK to allocate the
16586 "containing object" 64-bit field at bit-offset zero within the
16589 Here we attempt to work backwards from the limited set of facts
16590 we're given, and we try to deduce from those facts, where GCC
16591 must have believed that the containing object started (within
16592 the structure type). The value we deduce is then used (by the
16593 callers of this routine) to generate DW_AT_location and
16594 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16595 the case of DW_AT_location, regular fields as well). */
16597 /* Figure out the bit-distance from the start of the structure to
16598 the "deepest" bit of the bit-field. */
16599 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16601 /* This is the tricky part. Use some fancy footwork to deduce
16602 where the lowest addressed bit of the containing object must
16604 object_offset_in_bits
16605 = double_int_sub (deepest_bitpos, type_size_in_bits);
16607 /* Round up to type_align by default. This works best for
16609 object_offset_in_bits
16610 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16612 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16614 object_offset_in_bits
16615 = double_int_sub (deepest_bitpos, type_size_in_bits);
16617 /* Round up to decl_align instead. */
16618 object_offset_in_bits
16619 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16623 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16624 object_offset_in_bits = bitpos_int;
16626 object_offset_in_bytes
16627 = double_int_div (object_offset_in_bits,
16628 uhwi_to_double_int (BITS_PER_UNIT), true,
16630 return double_int_to_shwi (object_offset_in_bytes);
16633 /* The following routines define various Dwarf attributes and any data
16634 associated with them. */
16636 /* Add a location description attribute value to a DIE.
16638 This emits location attributes suitable for whole variables and
16639 whole parameters. Note that the location attributes for struct fields are
16640 generated by the routine `data_member_location_attribute' below. */
16643 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16644 dw_loc_list_ref descr)
16648 if (single_element_loc_list_p (descr))
16649 add_AT_loc (die, attr_kind, descr->expr);
16651 add_AT_loc_list (die, attr_kind, descr);
16654 /* Add DW_AT_accessibility attribute to DIE if needed. */
16657 add_accessibility_attribute (dw_die_ref die, tree decl)
16659 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16660 children, otherwise the default is DW_ACCESS_public. In DWARF2
16661 the default has always been DW_ACCESS_public. */
16662 if (TREE_PROTECTED (decl))
16663 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16664 else if (TREE_PRIVATE (decl))
16666 if (dwarf_version == 2
16667 || die->die_parent == NULL
16668 || die->die_parent->die_tag != DW_TAG_class_type)
16669 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16671 else if (dwarf_version > 2
16673 && die->die_parent->die_tag == DW_TAG_class_type)
16674 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16677 /* Attach the specialized form of location attribute used for data members of
16678 struct and union types. In the special case of a FIELD_DECL node which
16679 represents a bit-field, the "offset" part of this special location
16680 descriptor must indicate the distance in bytes from the lowest-addressed
16681 byte of the containing struct or union type to the lowest-addressed byte of
16682 the "containing object" for the bit-field. (See the `field_byte_offset'
16685 For any given bit-field, the "containing object" is a hypothetical object
16686 (of some integral or enum type) within which the given bit-field lives. The
16687 type of this hypothetical "containing object" is always the same as the
16688 declared type of the individual bit-field itself (for GCC anyway... the
16689 DWARF spec doesn't actually mandate this). Note that it is the size (in
16690 bytes) of the hypothetical "containing object" which will be given in the
16691 DW_AT_byte_size attribute for this bit-field. (See the
16692 `byte_size_attribute' function below.) It is also used when calculating the
16693 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16694 function below.) */
16697 add_data_member_location_attribute (dw_die_ref die, tree decl)
16699 HOST_WIDE_INT offset;
16700 dw_loc_descr_ref loc_descr = 0;
16702 if (TREE_CODE (decl) == TREE_BINFO)
16704 /* We're working on the TAG_inheritance for a base class. */
16705 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16707 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16708 aren't at a fixed offset from all (sub)objects of the same
16709 type. We need to extract the appropriate offset from our
16710 vtable. The following dwarf expression means
16712 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16714 This is specific to the V3 ABI, of course. */
16716 dw_loc_descr_ref tmp;
16718 /* Make a copy of the object address. */
16719 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16720 add_loc_descr (&loc_descr, tmp);
16722 /* Extract the vtable address. */
16723 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16724 add_loc_descr (&loc_descr, tmp);
16726 /* Calculate the address of the offset. */
16727 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16728 gcc_assert (offset < 0);
16730 tmp = int_loc_descriptor (-offset);
16731 add_loc_descr (&loc_descr, tmp);
16732 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16733 add_loc_descr (&loc_descr, tmp);
16735 /* Extract the offset. */
16736 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16737 add_loc_descr (&loc_descr, tmp);
16739 /* Add it to the object address. */
16740 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16741 add_loc_descr (&loc_descr, tmp);
16744 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16747 offset = field_byte_offset (decl);
16751 if (dwarf_version > 2)
16753 /* Don't need to output a location expression, just the constant. */
16755 add_AT_int (die, DW_AT_data_member_location, offset);
16757 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16762 enum dwarf_location_atom op;
16764 /* The DWARF2 standard says that we should assume that the structure
16765 address is already on the stack, so we can specify a structure
16766 field address by using DW_OP_plus_uconst. */
16768 #ifdef MIPS_DEBUGGING_INFO
16769 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16770 operator correctly. It works only if we leave the offset on the
16774 op = DW_OP_plus_uconst;
16777 loc_descr = new_loc_descr (op, offset, 0);
16781 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16784 /* Writes integer values to dw_vec_const array. */
16787 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16791 *dest++ = val & 0xff;
16797 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16799 static HOST_WIDE_INT
16800 extract_int (const unsigned char *src, unsigned int size)
16802 HOST_WIDE_INT val = 0;
16808 val |= *--src & 0xff;
16814 /* Writes double_int values to dw_vec_const array. */
16817 insert_double (double_int val, unsigned char *dest)
16819 unsigned char *p0 = dest;
16820 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16822 if (WORDS_BIG_ENDIAN)
16828 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16829 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16832 /* Writes floating point values to dw_vec_const array. */
16835 insert_float (const_rtx rtl, unsigned char *array)
16837 REAL_VALUE_TYPE rv;
16841 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16842 real_to_target (val, &rv, GET_MODE (rtl));
16844 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16845 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16847 insert_int (val[i], 4, array);
16852 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16853 does not have a "location" either in memory or in a register. These
16854 things can arise in GNU C when a constant is passed as an actual parameter
16855 to an inlined function. They can also arise in C++ where declared
16856 constants do not necessarily get memory "homes". */
16859 add_const_value_attribute (dw_die_ref die, rtx rtl)
16861 switch (GET_CODE (rtl))
16865 HOST_WIDE_INT val = INTVAL (rtl);
16868 add_AT_int (die, DW_AT_const_value, val);
16870 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16875 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16876 floating-point constant. A CONST_DOUBLE is used whenever the
16877 constant requires more than one word in order to be adequately
16880 enum machine_mode mode = GET_MODE (rtl);
16882 if (SCALAR_FLOAT_MODE_P (mode))
16884 unsigned int length = GET_MODE_SIZE (mode);
16885 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16887 insert_float (rtl, array);
16888 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16891 add_AT_double (die, DW_AT_const_value,
16892 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16898 enum machine_mode mode = GET_MODE (rtl);
16899 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16900 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16901 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16902 (length * elt_size);
16906 switch (GET_MODE_CLASS (mode))
16908 case MODE_VECTOR_INT:
16909 for (i = 0, p = array; i < length; i++, p += elt_size)
16911 rtx elt = CONST_VECTOR_ELT (rtl, i);
16912 double_int val = rtx_to_double_int (elt);
16914 if (elt_size <= sizeof (HOST_WIDE_INT))
16915 insert_int (double_int_to_shwi (val), elt_size, p);
16918 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16919 insert_double (val, p);
16924 case MODE_VECTOR_FLOAT:
16925 for (i = 0, p = array; i < length; i++, p += elt_size)
16927 rtx elt = CONST_VECTOR_ELT (rtl, i);
16928 insert_float (elt, p);
16933 gcc_unreachable ();
16936 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16941 if (dwarf_version >= 4 || !dwarf_strict)
16943 dw_loc_descr_ref loc_result;
16944 resolve_one_addr (&rtl, NULL);
16946 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16947 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16948 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16949 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16950 add_AT_loc (die, DW_AT_location, loc_result);
16951 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16957 if (CONSTANT_P (XEXP (rtl, 0)))
16958 return add_const_value_attribute (die, XEXP (rtl, 0));
16961 if (!const_ok_for_output (rtl))
16964 if (dwarf_version >= 4 || !dwarf_strict)
16969 /* In cases where an inlined instance of an inline function is passed
16970 the address of an `auto' variable (which is local to the caller) we
16971 can get a situation where the DECL_RTL of the artificial local
16972 variable (for the inlining) which acts as a stand-in for the
16973 corresponding formal parameter (of the inline function) will look
16974 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16975 exactly a compile-time constant expression, but it isn't the address
16976 of the (artificial) local variable either. Rather, it represents the
16977 *value* which the artificial local variable always has during its
16978 lifetime. We currently have no way to represent such quasi-constant
16979 values in Dwarf, so for now we just punt and generate nothing. */
16987 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16988 && MEM_READONLY_P (rtl)
16989 && GET_MODE (rtl) == BLKmode)
16991 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16997 /* No other kinds of rtx should be possible here. */
16998 gcc_unreachable ();
17003 /* Determine whether the evaluation of EXPR references any variables
17004 or functions which aren't otherwise used (and therefore may not be
17007 reference_to_unused (tree * tp, int * walk_subtrees,
17008 void * data ATTRIBUTE_UNUSED)
17010 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
17011 *walk_subtrees = 0;
17013 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
17014 && ! TREE_ASM_WRITTEN (*tp))
17016 /* ??? The C++ FE emits debug information for using decls, so
17017 putting gcc_unreachable here falls over. See PR31899. For now
17018 be conservative. */
17019 else if (!cgraph_global_info_ready
17020 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
17022 else if (TREE_CODE (*tp) == VAR_DECL)
17024 struct varpool_node *node = varpool_get_node (*tp);
17025 if (!node || !node->needed)
17028 else if (TREE_CODE (*tp) == FUNCTION_DECL
17029 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
17031 /* The call graph machinery must have finished analyzing,
17032 optimizing and gimplifying the CU by now.
17033 So if *TP has no call graph node associated
17034 to it, it means *TP will not be emitted. */
17035 if (!cgraph_get_node (*tp))
17038 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
17044 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
17045 for use in a later add_const_value_attribute call. */
17048 rtl_for_decl_init (tree init, tree type)
17050 rtx rtl = NULL_RTX;
17054 /* If a variable is initialized with a string constant without embedded
17055 zeros, build CONST_STRING. */
17056 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
17058 tree enttype = TREE_TYPE (type);
17059 tree domain = TYPE_DOMAIN (type);
17060 enum machine_mode mode = TYPE_MODE (enttype);
17062 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
17064 && integer_zerop (TYPE_MIN_VALUE (domain))
17065 && compare_tree_int (TYPE_MAX_VALUE (domain),
17066 TREE_STRING_LENGTH (init) - 1) == 0
17067 && ((size_t) TREE_STRING_LENGTH (init)
17068 == strlen (TREE_STRING_POINTER (init)) + 1))
17070 rtl = gen_rtx_CONST_STRING (VOIDmode,
17071 ggc_strdup (TREE_STRING_POINTER (init)));
17072 rtl = gen_rtx_MEM (BLKmode, rtl);
17073 MEM_READONLY_P (rtl) = 1;
17076 /* Other aggregates, and complex values, could be represented using
17078 else if (AGGREGATE_TYPE_P (type)
17079 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
17080 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
17081 || TREE_CODE (type) == COMPLEX_TYPE)
17083 /* Vectors only work if their mode is supported by the target.
17084 FIXME: generic vectors ought to work too. */
17085 else if (TREE_CODE (type) == VECTOR_TYPE
17086 && !VECTOR_MODE_P (TYPE_MODE (type)))
17088 /* If the initializer is something that we know will expand into an
17089 immediate RTL constant, expand it now. We must be careful not to
17090 reference variables which won't be output. */
17091 else if (initializer_constant_valid_p (init, type)
17092 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
17094 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
17096 if (TREE_CODE (type) == VECTOR_TYPE)
17097 switch (TREE_CODE (init))
17102 if (TREE_CONSTANT (init))
17104 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
17105 bool constant_p = true;
17107 unsigned HOST_WIDE_INT ix;
17109 /* Even when ctor is constant, it might contain non-*_CST
17110 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
17111 belong into VECTOR_CST nodes. */
17112 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
17113 if (!CONSTANT_CLASS_P (value))
17115 constant_p = false;
17121 init = build_vector_from_ctor (type, elts);
17131 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
17133 /* If expand_expr returns a MEM, it wasn't immediate. */
17134 gcc_assert (!rtl || !MEM_P (rtl));
17140 /* Generate RTL for the variable DECL to represent its location. */
17143 rtl_for_decl_location (tree decl)
17147 /* Here we have to decide where we are going to say the parameter "lives"
17148 (as far as the debugger is concerned). We only have a couple of
17149 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
17151 DECL_RTL normally indicates where the parameter lives during most of the
17152 activation of the function. If optimization is enabled however, this
17153 could be either NULL or else a pseudo-reg. Both of those cases indicate
17154 that the parameter doesn't really live anywhere (as far as the code
17155 generation parts of GCC are concerned) during most of the function's
17156 activation. That will happen (for example) if the parameter is never
17157 referenced within the function.
17159 We could just generate a location descriptor here for all non-NULL
17160 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
17161 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
17162 where DECL_RTL is NULL or is a pseudo-reg.
17164 Note however that we can only get away with using DECL_INCOMING_RTL as
17165 a backup substitute for DECL_RTL in certain limited cases. In cases
17166 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
17167 we can be sure that the parameter was passed using the same type as it is
17168 declared to have within the function, and that its DECL_INCOMING_RTL
17169 points us to a place where a value of that type is passed.
17171 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
17172 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
17173 because in these cases DECL_INCOMING_RTL points us to a value of some
17174 type which is *different* from the type of the parameter itself. Thus,
17175 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
17176 such cases, the debugger would end up (for example) trying to fetch a
17177 `float' from a place which actually contains the first part of a
17178 `double'. That would lead to really incorrect and confusing
17179 output at debug-time.
17181 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
17182 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
17183 are a couple of exceptions however. On little-endian machines we can
17184 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
17185 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
17186 an integral type that is smaller than TREE_TYPE (decl). These cases arise
17187 when (on a little-endian machine) a non-prototyped function has a
17188 parameter declared to be of type `short' or `char'. In such cases,
17189 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
17190 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
17191 passed `int' value. If the debugger then uses that address to fetch
17192 a `short' or a `char' (on a little-endian machine) the result will be
17193 the correct data, so we allow for such exceptional cases below.
17195 Note that our goal here is to describe the place where the given formal
17196 parameter lives during most of the function's activation (i.e. between the
17197 end of the prologue and the start of the epilogue). We'll do that as best
17198 as we can. Note however that if the given formal parameter is modified
17199 sometime during the execution of the function, then a stack backtrace (at
17200 debug-time) will show the function as having been called with the *new*
17201 value rather than the value which was originally passed in. This happens
17202 rarely enough that it is not a major problem, but it *is* a problem, and
17203 I'd like to fix it.
17205 A future version of dwarf2out.c may generate two additional attributes for
17206 any given DW_TAG_formal_parameter DIE which will describe the "passed
17207 type" and the "passed location" for the given formal parameter in addition
17208 to the attributes we now generate to indicate the "declared type" and the
17209 "active location" for each parameter. This additional set of attributes
17210 could be used by debuggers for stack backtraces. Separately, note that
17211 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
17212 This happens (for example) for inlined-instances of inline function formal
17213 parameters which are never referenced. This really shouldn't be
17214 happening. All PARM_DECL nodes should get valid non-NULL
17215 DECL_INCOMING_RTL values. FIXME. */
17217 /* Use DECL_RTL as the "location" unless we find something better. */
17218 rtl = DECL_RTL_IF_SET (decl);
17220 /* When generating abstract instances, ignore everything except
17221 constants, symbols living in memory, and symbols living in
17222 fixed registers. */
17223 if (! reload_completed)
17226 && (CONSTANT_P (rtl)
17228 && CONSTANT_P (XEXP (rtl, 0)))
17230 && TREE_CODE (decl) == VAR_DECL
17231 && TREE_STATIC (decl))))
17233 rtl = targetm.delegitimize_address (rtl);
17238 else if (TREE_CODE (decl) == PARM_DECL)
17240 if (rtl == NULL_RTX
17241 || is_pseudo_reg (rtl)
17243 && is_pseudo_reg (XEXP (rtl, 0))
17244 && DECL_INCOMING_RTL (decl)
17245 && MEM_P (DECL_INCOMING_RTL (decl))
17246 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
17248 tree declared_type = TREE_TYPE (decl);
17249 tree passed_type = DECL_ARG_TYPE (decl);
17250 enum machine_mode dmode = TYPE_MODE (declared_type);
17251 enum machine_mode pmode = TYPE_MODE (passed_type);
17253 /* This decl represents a formal parameter which was optimized out.
17254 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
17255 all cases where (rtl == NULL_RTX) just below. */
17256 if (dmode == pmode)
17257 rtl = DECL_INCOMING_RTL (decl);
17258 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
17259 && SCALAR_INT_MODE_P (dmode)
17260 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
17261 && DECL_INCOMING_RTL (decl))
17263 rtx inc = DECL_INCOMING_RTL (decl);
17266 else if (MEM_P (inc))
17268 if (BYTES_BIG_ENDIAN)
17269 rtl = adjust_address_nv (inc, dmode,
17270 GET_MODE_SIZE (pmode)
17271 - GET_MODE_SIZE (dmode));
17278 /* If the parm was passed in registers, but lives on the stack, then
17279 make a big endian correction if the mode of the type of the
17280 parameter is not the same as the mode of the rtl. */
17281 /* ??? This is the same series of checks that are made in dbxout.c before
17282 we reach the big endian correction code there. It isn't clear if all
17283 of these checks are necessary here, but keeping them all is the safe
17285 else if (MEM_P (rtl)
17286 && XEXP (rtl, 0) != const0_rtx
17287 && ! CONSTANT_P (XEXP (rtl, 0))
17288 /* Not passed in memory. */
17289 && !MEM_P (DECL_INCOMING_RTL (decl))
17290 /* Not passed by invisible reference. */
17291 && (!REG_P (XEXP (rtl, 0))
17292 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
17293 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
17294 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
17295 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
17298 /* Big endian correction check. */
17299 && BYTES_BIG_ENDIAN
17300 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
17301 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
17304 int offset = (UNITS_PER_WORD
17305 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
17307 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17308 plus_constant (XEXP (rtl, 0), offset));
17311 else if (TREE_CODE (decl) == VAR_DECL
17314 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
17315 && BYTES_BIG_ENDIAN)
17317 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
17318 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
17320 /* If a variable is declared "register" yet is smaller than
17321 a register, then if we store the variable to memory, it
17322 looks like we're storing a register-sized value, when in
17323 fact we are not. We need to adjust the offset of the
17324 storage location to reflect the actual value's bytes,
17325 else gdb will not be able to display it. */
17327 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17328 plus_constant (XEXP (rtl, 0), rsize-dsize));
17331 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
17332 and will have been substituted directly into all expressions that use it.
17333 C does not have such a concept, but C++ and other languages do. */
17334 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
17335 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
17338 rtl = targetm.delegitimize_address (rtl);
17340 /* If we don't look past the constant pool, we risk emitting a
17341 reference to a constant pool entry that isn't referenced from
17342 code, and thus is not emitted. */
17344 rtl = avoid_constant_pool_reference (rtl);
17346 /* Try harder to get a rtl. If this symbol ends up not being emitted
17347 in the current CU, resolve_addr will remove the expression referencing
17349 if (rtl == NULL_RTX
17350 && TREE_CODE (decl) == VAR_DECL
17351 && !DECL_EXTERNAL (decl)
17352 && TREE_STATIC (decl)
17353 && DECL_NAME (decl)
17354 && !DECL_HARD_REGISTER (decl)
17355 && DECL_MODE (decl) != VOIDmode)
17357 rtl = make_decl_rtl_for_debug (decl);
17359 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
17360 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
17367 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17368 returned. If so, the decl for the COMMON block is returned, and the
17369 value is the offset into the common block for the symbol. */
17372 fortran_common (tree decl, HOST_WIDE_INT *value)
17374 tree val_expr, cvar;
17375 enum machine_mode mode;
17376 HOST_WIDE_INT bitsize, bitpos;
17378 int volatilep = 0, unsignedp = 0;
17380 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
17381 it does not have a value (the offset into the common area), or if it
17382 is thread local (as opposed to global) then it isn't common, and shouldn't
17383 be handled as such. */
17384 if (TREE_CODE (decl) != VAR_DECL
17385 || !TREE_STATIC (decl)
17386 || !DECL_HAS_VALUE_EXPR_P (decl)
17390 val_expr = DECL_VALUE_EXPR (decl);
17391 if (TREE_CODE (val_expr) != COMPONENT_REF)
17394 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
17395 &mode, &unsignedp, &volatilep, true);
17397 if (cvar == NULL_TREE
17398 || TREE_CODE (cvar) != VAR_DECL
17399 || DECL_ARTIFICIAL (cvar)
17400 || !TREE_PUBLIC (cvar))
17404 if (offset != NULL)
17406 if (!host_integerp (offset, 0))
17408 *value = tree_low_cst (offset, 0);
17411 *value += bitpos / BITS_PER_UNIT;
17416 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
17417 data attribute for a variable or a parameter. We generate the
17418 DW_AT_const_value attribute only in those cases where the given variable
17419 or parameter does not have a true "location" either in memory or in a
17420 register. This can happen (for example) when a constant is passed as an
17421 actual argument in a call to an inline function. (It's possible that
17422 these things can crop up in other ways also.) Note that one type of
17423 constant value which can be passed into an inlined function is a constant
17424 pointer. This can happen for example if an actual argument in an inlined
17425 function call evaluates to a compile-time constant address.
17427 CACHE_P is true if it is worth caching the location list for DECL,
17428 so that future calls can reuse it rather than regenerate it from scratch.
17429 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
17430 since we will need to refer to them each time the function is inlined. */
17433 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
17434 enum dwarf_attribute attr)
17437 dw_loc_list_ref list;
17438 var_loc_list *loc_list;
17439 cached_dw_loc_list *cache;
17442 if (TREE_CODE (decl) == ERROR_MARK)
17445 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
17446 || TREE_CODE (decl) == RESULT_DECL);
17448 /* Try to get some constant RTL for this decl, and use that as the value of
17451 rtl = rtl_for_decl_location (decl);
17452 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17453 && add_const_value_attribute (die, rtl))
17456 /* See if we have single element location list that is equivalent to
17457 a constant value. That way we are better to use add_const_value_attribute
17458 rather than expanding constant value equivalent. */
17459 loc_list = lookup_decl_loc (decl);
17462 && loc_list->first->next == NULL
17463 && NOTE_P (loc_list->first->loc)
17464 && NOTE_VAR_LOCATION (loc_list->first->loc)
17465 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
17467 struct var_loc_node *node;
17469 node = loc_list->first;
17470 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
17471 if (GET_CODE (rtl) == EXPR_LIST)
17472 rtl = XEXP (rtl, 0);
17473 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17474 && add_const_value_attribute (die, rtl))
17477 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
17478 list several times. See if we've already cached the contents. */
17480 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
17484 cache = (cached_dw_loc_list *)
17485 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
17487 list = cache->loc_list;
17491 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
17492 /* It is usually worth caching this result if the decl is from
17493 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
17494 if (cache_p && list && list->dw_loc_next)
17496 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
17497 DECL_UID (decl), INSERT);
17498 cache = ggc_alloc_cleared_cached_dw_loc_list ();
17499 cache->decl_id = DECL_UID (decl);
17500 cache->loc_list = list;
17506 add_AT_location_description (die, attr, list);
17509 /* None of that worked, so it must not really have a location;
17510 try adding a constant value attribute from the DECL_INITIAL. */
17511 return tree_add_const_value_attribute_for_decl (die, decl);
17514 /* Add VARIABLE and DIE into deferred locations list. */
17517 defer_location (tree variable, dw_die_ref die)
17519 deferred_locations entry;
17520 entry.variable = variable;
17522 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
17525 /* Helper function for tree_add_const_value_attribute. Natively encode
17526 initializer INIT into an array. Return true if successful. */
17529 native_encode_initializer (tree init, unsigned char *array, int size)
17533 if (init == NULL_TREE)
17537 switch (TREE_CODE (init))
17540 type = TREE_TYPE (init);
17541 if (TREE_CODE (type) == ARRAY_TYPE)
17543 tree enttype = TREE_TYPE (type);
17544 enum machine_mode mode = TYPE_MODE (enttype);
17546 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
17548 if (int_size_in_bytes (type) != size)
17550 if (size > TREE_STRING_LENGTH (init))
17552 memcpy (array, TREE_STRING_POINTER (init),
17553 TREE_STRING_LENGTH (init));
17554 memset (array + TREE_STRING_LENGTH (init),
17555 '\0', size - TREE_STRING_LENGTH (init));
17558 memcpy (array, TREE_STRING_POINTER (init), size);
17563 type = TREE_TYPE (init);
17564 if (int_size_in_bytes (type) != size)
17566 if (TREE_CODE (type) == ARRAY_TYPE)
17568 HOST_WIDE_INT min_index;
17569 unsigned HOST_WIDE_INT cnt;
17570 int curpos = 0, fieldsize;
17571 constructor_elt *ce;
17573 if (TYPE_DOMAIN (type) == NULL_TREE
17574 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
17577 fieldsize = int_size_in_bytes (TREE_TYPE (type));
17578 if (fieldsize <= 0)
17581 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
17582 memset (array, '\0', size);
17583 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17585 tree val = ce->value;
17586 tree index = ce->index;
17588 if (index && TREE_CODE (index) == RANGE_EXPR)
17589 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
17592 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
17597 if (!native_encode_initializer (val, array + pos, fieldsize))
17600 curpos = pos + fieldsize;
17601 if (index && TREE_CODE (index) == RANGE_EXPR)
17603 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17604 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17608 memcpy (array + curpos, array + pos, fieldsize);
17609 curpos += fieldsize;
17612 gcc_assert (curpos <= size);
17616 else if (TREE_CODE (type) == RECORD_TYPE
17617 || TREE_CODE (type) == UNION_TYPE)
17619 tree field = NULL_TREE;
17620 unsigned HOST_WIDE_INT cnt;
17621 constructor_elt *ce;
17623 if (int_size_in_bytes (type) != size)
17626 if (TREE_CODE (type) == RECORD_TYPE)
17627 field = TYPE_FIELDS (type);
17629 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17631 tree val = ce->value;
17632 int pos, fieldsize;
17634 if (ce->index != 0)
17640 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17643 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17644 && TYPE_DOMAIN (TREE_TYPE (field))
17645 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17647 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17648 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17650 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17651 pos = int_byte_position (field);
17652 gcc_assert (pos + fieldsize <= size);
17654 && !native_encode_initializer (val, array + pos, fieldsize))
17660 case VIEW_CONVERT_EXPR:
17661 case NON_LVALUE_EXPR:
17662 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17664 return native_encode_expr (init, array, size) == size;
17668 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17669 attribute is the const value T. */
17672 tree_add_const_value_attribute (dw_die_ref die, tree t)
17675 tree type = TREE_TYPE (t);
17678 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17682 gcc_assert (!DECL_P (init));
17684 rtl = rtl_for_decl_init (init, type);
17686 return add_const_value_attribute (die, rtl);
17687 /* If the host and target are sane, try harder. */
17688 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17689 && initializer_constant_valid_p (init, type))
17691 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17692 if (size > 0 && (int) size == size)
17694 unsigned char *array = (unsigned char *)
17695 ggc_alloc_cleared_atomic (size);
17697 if (native_encode_initializer (init, array, size))
17699 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17707 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17708 attribute is the const value of T, where T is an integral constant
17709 variable with static storage duration
17710 (so it can't be a PARM_DECL or a RESULT_DECL). */
17713 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17717 || (TREE_CODE (decl) != VAR_DECL
17718 && TREE_CODE (decl) != CONST_DECL))
17721 if (TREE_READONLY (decl)
17722 && ! TREE_THIS_VOLATILE (decl)
17723 && DECL_INITIAL (decl))
17728 /* Don't add DW_AT_const_value if abstract origin already has one. */
17729 if (get_AT (var_die, DW_AT_const_value))
17732 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17735 /* Convert the CFI instructions for the current function into a
17736 location list. This is used for DW_AT_frame_base when we targeting
17737 a dwarf2 consumer that does not support the dwarf3
17738 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17741 static dw_loc_list_ref
17742 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17746 dw_loc_list_ref list, *list_tail;
17748 dw_cfa_location last_cfa, next_cfa;
17749 const char *start_label, *last_label, *section;
17750 dw_cfa_location remember;
17752 fde = current_fde ();
17753 gcc_assert (fde != NULL);
17755 section = secname_for_decl (current_function_decl);
17759 memset (&next_cfa, 0, sizeof (next_cfa));
17760 next_cfa.reg = INVALID_REGNUM;
17761 remember = next_cfa;
17763 start_label = fde->dw_fde_begin;
17765 /* ??? Bald assumption that the CIE opcode list does not contain
17766 advance opcodes. */
17767 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
17768 lookup_cfa_1 (cfi, &next_cfa, &remember);
17770 last_cfa = next_cfa;
17771 last_label = start_label;
17773 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
17775 /* If the first partition contained no CFI adjustments, the
17776 CIE opcodes apply to the whole first partition. */
17777 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17778 fde->dw_fde_begin, fde->dw_fde_end, section);
17779 list_tail =&(*list_tail)->dw_loc_next;
17780 start_label = last_label = fde->dw_fde_second_begin;
17783 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
17785 switch (cfi->dw_cfi_opc)
17787 case DW_CFA_set_loc:
17788 case DW_CFA_advance_loc1:
17789 case DW_CFA_advance_loc2:
17790 case DW_CFA_advance_loc4:
17791 if (!cfa_equal_p (&last_cfa, &next_cfa))
17793 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17794 start_label, last_label, section);
17796 list_tail = &(*list_tail)->dw_loc_next;
17797 last_cfa = next_cfa;
17798 start_label = last_label;
17800 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17803 case DW_CFA_advance_loc:
17804 /* The encoding is complex enough that we should never emit this. */
17805 gcc_unreachable ();
17808 lookup_cfa_1 (cfi, &next_cfa, &remember);
17811 if (ix + 1 == fde->dw_fde_switch_cfi_index)
17813 if (!cfa_equal_p (&last_cfa, &next_cfa))
17815 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17816 start_label, last_label, section);
17818 list_tail = &(*list_tail)->dw_loc_next;
17819 last_cfa = next_cfa;
17820 start_label = last_label;
17822 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17823 start_label, fde->dw_fde_end, section);
17824 list_tail = &(*list_tail)->dw_loc_next;
17825 start_label = last_label = fde->dw_fde_second_begin;
17829 if (!cfa_equal_p (&last_cfa, &next_cfa))
17831 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17832 start_label, last_label, section);
17833 list_tail = &(*list_tail)->dw_loc_next;
17834 start_label = last_label;
17837 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17839 fde->dw_fde_second_begin
17840 ? fde->dw_fde_second_end : fde->dw_fde_end,
17843 if (list && list->dw_loc_next)
17849 /* Compute a displacement from the "steady-state frame pointer" to the
17850 frame base (often the same as the CFA), and store it in
17851 frame_pointer_fb_offset. OFFSET is added to the displacement
17852 before the latter is negated. */
17855 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17859 #ifdef FRAME_POINTER_CFA_OFFSET
17860 reg = frame_pointer_rtx;
17861 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17863 reg = arg_pointer_rtx;
17864 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17867 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17868 if (GET_CODE (elim) == PLUS)
17870 offset += INTVAL (XEXP (elim, 1));
17871 elim = XEXP (elim, 0);
17874 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17875 && (elim == hard_frame_pointer_rtx
17876 || elim == stack_pointer_rtx))
17877 || elim == (frame_pointer_needed
17878 ? hard_frame_pointer_rtx
17879 : stack_pointer_rtx));
17881 frame_pointer_fb_offset = -offset;
17884 /* Generate a DW_AT_name attribute given some string value to be included as
17885 the value of the attribute. */
17888 add_name_attribute (dw_die_ref die, const char *name_string)
17890 if (name_string != NULL && *name_string != 0)
17892 if (demangle_name_func)
17893 name_string = (*demangle_name_func) (name_string);
17895 add_AT_string (die, DW_AT_name, name_string);
17899 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
17900 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
17901 of TYPE accordingly.
17903 ??? This is a temporary measure until after we're able to generate
17904 regular DWARF for the complex Ada type system. */
17907 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
17908 dw_die_ref context_die)
17911 dw_die_ref dtype_die;
17913 if (!lang_hooks.types.descriptive_type)
17916 dtype = lang_hooks.types.descriptive_type (type);
17920 dtype_die = lookup_type_die (dtype);
17923 gen_type_die (dtype, context_die);
17924 dtype_die = lookup_type_die (dtype);
17925 gcc_assert (dtype_die);
17928 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
17931 /* Generate a DW_AT_comp_dir attribute for DIE. */
17934 add_comp_dir_attribute (dw_die_ref die)
17936 const char *wd = get_src_pwd ();
17942 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17946 wdlen = strlen (wd);
17947 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17949 wd1 [wdlen] = DIR_SEPARATOR;
17950 wd1 [wdlen + 1] = 0;
17954 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17957 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17961 lower_bound_default (void)
17963 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17968 case DW_LANG_C_plus_plus:
17970 case DW_LANG_ObjC_plus_plus:
17973 case DW_LANG_Fortran77:
17974 case DW_LANG_Fortran90:
17975 case DW_LANG_Fortran95:
17979 case DW_LANG_Python:
17980 return dwarf_version >= 4 ? 0 : -1;
17981 case DW_LANG_Ada95:
17982 case DW_LANG_Ada83:
17983 case DW_LANG_Cobol74:
17984 case DW_LANG_Cobol85:
17985 case DW_LANG_Pascal83:
17986 case DW_LANG_Modula2:
17988 return dwarf_version >= 4 ? 1 : -1;
17994 /* Given a tree node describing an array bound (either lower or upper) output
17995 a representation for that bound. */
17998 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
18000 switch (TREE_CODE (bound))
18005 /* All fixed-bounds are represented by INTEGER_CST nodes. */
18008 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
18011 /* Use the default if possible. */
18012 if (bound_attr == DW_AT_lower_bound
18013 && host_integerp (bound, 0)
18014 && (dflt = lower_bound_default ()) != -1
18015 && tree_low_cst (bound, 0) == dflt)
18018 /* Otherwise represent the bound as an unsigned value with the
18019 precision of its type. The precision and signedness of the
18020 type will be necessary to re-interpret it unambiguously. */
18021 else if (prec < HOST_BITS_PER_WIDE_INT)
18023 unsigned HOST_WIDE_INT mask
18024 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
18025 add_AT_unsigned (subrange_die, bound_attr,
18026 TREE_INT_CST_LOW (bound) & mask);
18028 else if (prec == HOST_BITS_PER_WIDE_INT
18029 || TREE_INT_CST_HIGH (bound) == 0)
18030 add_AT_unsigned (subrange_die, bound_attr,
18031 TREE_INT_CST_LOW (bound));
18033 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
18034 TREE_INT_CST_LOW (bound));
18039 case VIEW_CONVERT_EXPR:
18040 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
18050 dw_die_ref decl_die = lookup_decl_die (bound);
18052 /* ??? Can this happen, or should the variable have been bound
18053 first? Probably it can, since I imagine that we try to create
18054 the types of parameters in the order in which they exist in
18055 the list, and won't have created a forward reference to a
18056 later parameter. */
18057 if (decl_die != NULL)
18059 add_AT_die_ref (subrange_die, bound_attr, decl_die);
18067 /* Otherwise try to create a stack operation procedure to
18068 evaluate the value of the array bound. */
18070 dw_die_ref ctx, decl_die;
18071 dw_loc_list_ref list;
18073 list = loc_list_from_tree (bound, 2);
18074 if (list == NULL || single_element_loc_list_p (list))
18076 /* If DW_AT_*bound is not a reference nor constant, it is
18077 a DWARF expression rather than location description.
18078 For that loc_list_from_tree (bound, 0) is needed.
18079 If that fails to give a single element list,
18080 fall back to outputting this as a reference anyway. */
18081 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
18082 if (list2 && single_element_loc_list_p (list2))
18084 add_AT_loc (subrange_die, bound_attr, list2->expr);
18091 if (current_function_decl == 0)
18092 ctx = comp_unit_die ();
18094 ctx = lookup_decl_die (current_function_decl);
18096 decl_die = new_die (DW_TAG_variable, ctx, bound);
18097 add_AT_flag (decl_die, DW_AT_artificial, 1);
18098 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
18099 add_AT_location_description (decl_die, DW_AT_location, list);
18100 add_AT_die_ref (subrange_die, bound_attr, decl_die);
18106 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
18107 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
18108 Note that the block of subscript information for an array type also
18109 includes information about the element type of the given array type. */
18112 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
18114 unsigned dimension_number;
18116 dw_die_ref subrange_die;
18118 for (dimension_number = 0;
18119 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
18120 type = TREE_TYPE (type), dimension_number++)
18122 tree domain = TYPE_DOMAIN (type);
18124 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
18127 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
18128 and (in GNU C only) variable bounds. Handle all three forms
18130 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
18133 /* We have an array type with specified bounds. */
18134 lower = TYPE_MIN_VALUE (domain);
18135 upper = TYPE_MAX_VALUE (domain);
18137 /* Define the index type. */
18138 if (TREE_TYPE (domain))
18140 /* ??? This is probably an Ada unnamed subrange type. Ignore the
18141 TREE_TYPE field. We can't emit debug info for this
18142 because it is an unnamed integral type. */
18143 if (TREE_CODE (domain) == INTEGER_TYPE
18144 && TYPE_NAME (domain) == NULL_TREE
18145 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
18146 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
18149 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
18153 /* ??? If upper is NULL, the array has unspecified length,
18154 but it does have a lower bound. This happens with Fortran
18156 Since the debugger is definitely going to need to know N
18157 to produce useful results, go ahead and output the lower
18158 bound solo, and hope the debugger can cope. */
18160 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
18162 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
18165 /* Otherwise we have an array type with an unspecified length. The
18166 DWARF-2 spec does not say how to handle this; let's just leave out the
18172 add_byte_size_attribute (dw_die_ref die, tree tree_node)
18176 switch (TREE_CODE (tree_node))
18181 case ENUMERAL_TYPE:
18184 case QUAL_UNION_TYPE:
18185 size = int_size_in_bytes (tree_node);
18188 /* For a data member of a struct or union, the DW_AT_byte_size is
18189 generally given as the number of bytes normally allocated for an
18190 object of the *declared* type of the member itself. This is true
18191 even for bit-fields. */
18192 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
18195 gcc_unreachable ();
18198 /* Note that `size' might be -1 when we get to this point. If it is, that
18199 indicates that the byte size of the entity in question is variable. We
18200 have no good way of expressing this fact in Dwarf at the present time,
18201 so just let the -1 pass on through. */
18202 add_AT_unsigned (die, DW_AT_byte_size, size);
18205 /* For a FIELD_DECL node which represents a bit-field, output an attribute
18206 which specifies the distance in bits from the highest order bit of the
18207 "containing object" for the bit-field to the highest order bit of the
18210 For any given bit-field, the "containing object" is a hypothetical object
18211 (of some integral or enum type) within which the given bit-field lives. The
18212 type of this hypothetical "containing object" is always the same as the
18213 declared type of the individual bit-field itself. The determination of the
18214 exact location of the "containing object" for a bit-field is rather
18215 complicated. It's handled by the `field_byte_offset' function (above).
18217 Note that it is the size (in bytes) of the hypothetical "containing object"
18218 which will be given in the DW_AT_byte_size attribute for this bit-field.
18219 (See `byte_size_attribute' above). */
18222 add_bit_offset_attribute (dw_die_ref die, tree decl)
18224 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
18225 tree type = DECL_BIT_FIELD_TYPE (decl);
18226 HOST_WIDE_INT bitpos_int;
18227 HOST_WIDE_INT highest_order_object_bit_offset;
18228 HOST_WIDE_INT highest_order_field_bit_offset;
18229 HOST_WIDE_INT bit_offset;
18231 /* Must be a field and a bit field. */
18232 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
18234 /* We can't yet handle bit-fields whose offsets are variable, so if we
18235 encounter such things, just return without generating any attribute
18236 whatsoever. Likewise for variable or too large size. */
18237 if (! host_integerp (bit_position (decl), 0)
18238 || ! host_integerp (DECL_SIZE (decl), 1))
18241 bitpos_int = int_bit_position (decl);
18243 /* Note that the bit offset is always the distance (in bits) from the
18244 highest-order bit of the "containing object" to the highest-order bit of
18245 the bit-field itself. Since the "high-order end" of any object or field
18246 is different on big-endian and little-endian machines, the computation
18247 below must take account of these differences. */
18248 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
18249 highest_order_field_bit_offset = bitpos_int;
18251 if (! BYTES_BIG_ENDIAN)
18253 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
18254 highest_order_object_bit_offset += simple_type_size_in_bits (type);
18258 = (! BYTES_BIG_ENDIAN
18259 ? highest_order_object_bit_offset - highest_order_field_bit_offset
18260 : highest_order_field_bit_offset - highest_order_object_bit_offset);
18262 if (bit_offset < 0)
18263 add_AT_int (die, DW_AT_bit_offset, bit_offset);
18265 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
18268 /* For a FIELD_DECL node which represents a bit field, output an attribute
18269 which specifies the length in bits of the given field. */
18272 add_bit_size_attribute (dw_die_ref die, tree decl)
18274 /* Must be a field and a bit field. */
18275 gcc_assert (TREE_CODE (decl) == FIELD_DECL
18276 && DECL_BIT_FIELD_TYPE (decl));
18278 if (host_integerp (DECL_SIZE (decl), 1))
18279 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
18282 /* If the compiled language is ANSI C, then add a 'prototyped'
18283 attribute, if arg types are given for the parameters of a function. */
18286 add_prototyped_attribute (dw_die_ref die, tree func_type)
18288 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
18289 && prototype_p (func_type))
18290 add_AT_flag (die, DW_AT_prototyped, 1);
18293 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
18294 by looking in either the type declaration or object declaration
18297 static inline dw_die_ref
18298 add_abstract_origin_attribute (dw_die_ref die, tree origin)
18300 dw_die_ref origin_die = NULL;
18302 if (TREE_CODE (origin) != FUNCTION_DECL)
18304 /* We may have gotten separated from the block for the inlined
18305 function, if we're in an exception handler or some such; make
18306 sure that the abstract function has been written out.
18308 Doing this for nested functions is wrong, however; functions are
18309 distinct units, and our context might not even be inline. */
18313 fn = TYPE_STUB_DECL (fn);
18315 fn = decl_function_context (fn);
18317 dwarf2out_abstract_function (fn);
18320 if (DECL_P (origin))
18321 origin_die = lookup_decl_die (origin);
18322 else if (TYPE_P (origin))
18323 origin_die = lookup_type_die (origin);
18325 /* XXX: Functions that are never lowered don't always have correct block
18326 trees (in the case of java, they simply have no block tree, in some other
18327 languages). For these functions, there is nothing we can really do to
18328 output correct debug info for inlined functions in all cases. Rather
18329 than die, we'll just produce deficient debug info now, in that we will
18330 have variables without a proper abstract origin. In the future, when all
18331 functions are lowered, we should re-add a gcc_assert (origin_die)
18335 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
18339 /* We do not currently support the pure_virtual attribute. */
18342 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
18344 if (DECL_VINDEX (func_decl))
18346 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18348 if (host_integerp (DECL_VINDEX (func_decl), 0))
18349 add_AT_loc (die, DW_AT_vtable_elem_location,
18350 new_loc_descr (DW_OP_constu,
18351 tree_low_cst (DECL_VINDEX (func_decl), 0),
18354 /* GNU extension: Record what type this method came from originally. */
18355 if (debug_info_level > DINFO_LEVEL_TERSE
18356 && DECL_CONTEXT (func_decl))
18357 add_AT_die_ref (die, DW_AT_containing_type,
18358 lookup_type_die (DECL_CONTEXT (func_decl)));
18362 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
18363 given decl. This used to be a vendor extension until after DWARF 4
18364 standardized it. */
18367 add_linkage_attr (dw_die_ref die, tree decl)
18369 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
18371 /* Mimic what assemble_name_raw does with a leading '*'. */
18372 if (name[0] == '*')
18375 if (dwarf_version >= 4)
18376 add_AT_string (die, DW_AT_linkage_name, name);
18378 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
18381 /* Add source coordinate attributes for the given decl. */
18384 add_src_coords_attributes (dw_die_ref die, tree decl)
18386 expanded_location s;
18388 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
18390 s = expand_location (DECL_SOURCE_LOCATION (decl));
18391 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
18392 add_AT_unsigned (die, DW_AT_decl_line, s.line);
18395 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
18398 add_linkage_name (dw_die_ref die, tree decl)
18400 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
18401 && TREE_PUBLIC (decl)
18402 && !DECL_ABSTRACT (decl)
18403 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
18404 && die->die_tag != DW_TAG_member)
18406 /* Defer until we have an assembler name set. */
18407 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
18409 limbo_die_node *asm_name;
18411 asm_name = ggc_alloc_cleared_limbo_die_node ();
18412 asm_name->die = die;
18413 asm_name->created_for = decl;
18414 asm_name->next = deferred_asm_name;
18415 deferred_asm_name = asm_name;
18417 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
18418 add_linkage_attr (die, decl);
18422 /* Add a DW_AT_name attribute and source coordinate attribute for the
18423 given decl, but only if it actually has a name. */
18426 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
18430 decl_name = DECL_NAME (decl);
18431 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
18433 const char *name = dwarf2_name (decl, 0);
18435 add_name_attribute (die, name);
18436 if (! DECL_ARTIFICIAL (decl))
18437 add_src_coords_attributes (die, decl);
18439 add_linkage_name (die, decl);
18442 #ifdef VMS_DEBUGGING_INFO
18443 /* Get the function's name, as described by its RTL. This may be different
18444 from the DECL_NAME name used in the source file. */
18445 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
18447 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
18448 XEXP (DECL_RTL (decl), 0));
18449 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
18451 #endif /* VMS_DEBUGGING_INFO */
18454 #ifdef VMS_DEBUGGING_INFO
18455 /* Output the debug main pointer die for VMS */
18458 dwarf2out_vms_debug_main_pointer (void)
18460 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18463 /* Allocate the VMS debug main subprogram die. */
18464 die = ggc_alloc_cleared_die_node ();
18465 die->die_tag = DW_TAG_subprogram;
18466 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
18467 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
18468 current_function_funcdef_no);
18469 add_AT_lbl_id (die, DW_AT_entry_pc, label);
18471 /* Make it the first child of comp_unit_die (). */
18472 die->die_parent = comp_unit_die ();
18473 if (comp_unit_die ()->die_child)
18475 die->die_sib = comp_unit_die ()->die_child->die_sib;
18476 comp_unit_die ()->die_child->die_sib = die;
18480 die->die_sib = die;
18481 comp_unit_die ()->die_child = die;
18484 #endif /* VMS_DEBUGGING_INFO */
18486 /* Push a new declaration scope. */
18489 push_decl_scope (tree scope)
18491 VEC_safe_push (tree, gc, decl_scope_table, scope);
18494 /* Pop a declaration scope. */
18497 pop_decl_scope (void)
18499 VEC_pop (tree, decl_scope_table);
18502 /* Return the DIE for the scope that immediately contains this type.
18503 Non-named types get global scope. Named types nested in other
18504 types get their containing scope if it's open, or global scope
18505 otherwise. All other types (i.e. function-local named types) get
18506 the current active scope. */
18509 scope_die_for (tree t, dw_die_ref context_die)
18511 dw_die_ref scope_die = NULL;
18512 tree containing_scope;
18515 /* Non-types always go in the current scope. */
18516 gcc_assert (TYPE_P (t));
18518 containing_scope = TYPE_CONTEXT (t);
18520 /* Use the containing namespace if it was passed in (for a declaration). */
18521 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
18523 if (context_die == lookup_decl_die (containing_scope))
18526 containing_scope = NULL_TREE;
18529 /* Ignore function type "scopes" from the C frontend. They mean that
18530 a tagged type is local to a parmlist of a function declarator, but
18531 that isn't useful to DWARF. */
18532 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
18533 containing_scope = NULL_TREE;
18535 if (SCOPE_FILE_SCOPE_P (containing_scope))
18536 scope_die = comp_unit_die ();
18537 else if (TYPE_P (containing_scope))
18539 /* For types, we can just look up the appropriate DIE. But
18540 first we check to see if we're in the middle of emitting it
18541 so we know where the new DIE should go. */
18542 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
18543 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
18548 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
18549 || TREE_ASM_WRITTEN (containing_scope));
18550 /*We are not in the middle of emitting the type
18551 CONTAINING_SCOPE. Let's see if it's emitted already. */
18552 scope_die = lookup_type_die (containing_scope);
18554 /* If none of the current dies are suitable, we get file scope. */
18555 if (scope_die == NULL)
18556 scope_die = comp_unit_die ();
18559 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
18562 scope_die = context_die;
18567 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
18570 local_scope_p (dw_die_ref context_die)
18572 for (; context_die; context_die = context_die->die_parent)
18573 if (context_die->die_tag == DW_TAG_inlined_subroutine
18574 || context_die->die_tag == DW_TAG_subprogram)
18580 /* Returns nonzero if CONTEXT_DIE is a class. */
18583 class_scope_p (dw_die_ref context_die)
18585 return (context_die
18586 && (context_die->die_tag == DW_TAG_structure_type
18587 || context_die->die_tag == DW_TAG_class_type
18588 || context_die->die_tag == DW_TAG_interface_type
18589 || context_die->die_tag == DW_TAG_union_type));
18592 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
18593 whether or not to treat a DIE in this context as a declaration. */
18596 class_or_namespace_scope_p (dw_die_ref context_die)
18598 return (class_scope_p (context_die)
18599 || (context_die && context_die->die_tag == DW_TAG_namespace));
18602 /* Many forms of DIEs require a "type description" attribute. This
18603 routine locates the proper "type descriptor" die for the type given
18604 by 'type', and adds a DW_AT_type attribute below the given die. */
18607 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
18608 int decl_volatile, dw_die_ref context_die)
18610 enum tree_code code = TREE_CODE (type);
18611 dw_die_ref type_die = NULL;
18613 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18614 or fixed-point type, use the inner type. This is because we have no
18615 support for unnamed types in base_type_die. This can happen if this is
18616 an Ada subrange type. Correct solution is emit a subrange type die. */
18617 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
18618 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
18619 type = TREE_TYPE (type), code = TREE_CODE (type);
18621 if (code == ERROR_MARK
18622 /* Handle a special case. For functions whose return type is void, we
18623 generate *no* type attribute. (Note that no object may have type
18624 `void', so this only applies to function return types). */
18625 || code == VOID_TYPE)
18628 type_die = modified_type_die (type,
18629 decl_const || TYPE_READONLY (type),
18630 decl_volatile || TYPE_VOLATILE (type),
18633 if (type_die != NULL)
18634 add_AT_die_ref (object_die, DW_AT_type, type_die);
18637 /* Given an object die, add the calling convention attribute for the
18638 function call type. */
18640 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
18642 enum dwarf_calling_convention value = DW_CC_normal;
18644 value = ((enum dwarf_calling_convention)
18645 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
18648 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
18650 /* DWARF 2 doesn't provide a way to identify a program's source-level
18651 entry point. DW_AT_calling_convention attributes are only meant
18652 to describe functions' calling conventions. However, lacking a
18653 better way to signal the Fortran main program, we used this for
18654 a long time, following existing custom. Now, DWARF 4 has
18655 DW_AT_main_subprogram, which we add below, but some tools still
18656 rely on the old way, which we thus keep. */
18657 value = DW_CC_program;
18659 if (dwarf_version >= 4 || !dwarf_strict)
18660 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
18663 /* Only add the attribute if the backend requests it, and
18664 is not DW_CC_normal. */
18665 if (value && (value != DW_CC_normal))
18666 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18669 /* Given a tree pointer to a struct, class, union, or enum type node, return
18670 a pointer to the (string) tag name for the given type, or zero if the type
18671 was declared without a tag. */
18673 static const char *
18674 type_tag (const_tree type)
18676 const char *name = 0;
18678 if (TYPE_NAME (type) != 0)
18682 /* Find the IDENTIFIER_NODE for the type name. */
18683 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18684 && !TYPE_NAMELESS (type))
18685 t = TYPE_NAME (type);
18687 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18688 a TYPE_DECL node, regardless of whether or not a `typedef' was
18690 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18691 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18693 /* We want to be extra verbose. Don't call dwarf_name if
18694 DECL_NAME isn't set. The default hook for decl_printable_name
18695 doesn't like that, and in this context it's correct to return
18696 0, instead of "<anonymous>" or the like. */
18697 if (DECL_NAME (TYPE_NAME (type))
18698 && !DECL_NAMELESS (TYPE_NAME (type)))
18699 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18702 /* Now get the name as a string, or invent one. */
18703 if (!name && t != 0)
18704 name = IDENTIFIER_POINTER (t);
18707 return (name == 0 || *name == '\0') ? 0 : name;
18710 /* Return the type associated with a data member, make a special check
18711 for bit field types. */
18714 member_declared_type (const_tree member)
18716 return (DECL_BIT_FIELD_TYPE (member)
18717 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18720 /* Get the decl's label, as described by its RTL. This may be different
18721 from the DECL_NAME name used in the source file. */
18724 static const char *
18725 decl_start_label (tree decl)
18728 const char *fnname;
18730 x = DECL_RTL (decl);
18731 gcc_assert (MEM_P (x));
18734 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18736 fnname = XSTR (x, 0);
18741 /* These routines generate the internal representation of the DIE's for
18742 the compilation unit. Debugging information is collected by walking
18743 the declaration trees passed in from dwarf2out_decl(). */
18746 gen_array_type_die (tree type, dw_die_ref context_die)
18748 dw_die_ref scope_die = scope_die_for (type, context_die);
18749 dw_die_ref array_die;
18751 /* GNU compilers represent multidimensional array types as sequences of one
18752 dimensional array types whose element types are themselves array types.
18753 We sometimes squish that down to a single array_type DIE with multiple
18754 subscripts in the Dwarf debugging info. The draft Dwarf specification
18755 say that we are allowed to do this kind of compression in C, because
18756 there is no difference between an array of arrays and a multidimensional
18757 array. We don't do this for Ada to remain as close as possible to the
18758 actual representation, which is especially important against the language
18759 flexibilty wrt arrays of variable size. */
18761 bool collapse_nested_arrays = !is_ada ();
18764 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18765 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18766 if (TYPE_STRING_FLAG (type)
18767 && TREE_CODE (type) == ARRAY_TYPE
18769 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18771 HOST_WIDE_INT size;
18773 array_die = new_die (DW_TAG_string_type, scope_die, type);
18774 add_name_attribute (array_die, type_tag (type));
18775 equate_type_number_to_die (type, array_die);
18776 size = int_size_in_bytes (type);
18778 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18779 else if (TYPE_DOMAIN (type) != NULL_TREE
18780 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18781 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18783 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18784 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18786 size = int_size_in_bytes (TREE_TYPE (szdecl));
18787 if (loc && size > 0)
18789 add_AT_location_description (array_die, DW_AT_string_length, loc);
18790 if (size != DWARF2_ADDR_SIZE)
18791 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18797 /* ??? The SGI dwarf reader fails for array of array of enum types
18798 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18799 array type comes before the outer array type. We thus call gen_type_die
18800 before we new_die and must prevent nested array types collapsing for this
18803 #ifdef MIPS_DEBUGGING_INFO
18804 gen_type_die (TREE_TYPE (type), context_die);
18805 collapse_nested_arrays = false;
18808 array_die = new_die (DW_TAG_array_type, scope_die, type);
18809 add_name_attribute (array_die, type_tag (type));
18810 add_gnat_descriptive_type_attribute (array_die, type, context_die);
18811 equate_type_number_to_die (type, array_die);
18813 if (TREE_CODE (type) == VECTOR_TYPE)
18814 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18816 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18818 && TREE_CODE (type) == ARRAY_TYPE
18819 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18820 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18821 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18824 /* We default the array ordering. SDB will probably do
18825 the right things even if DW_AT_ordering is not present. It's not even
18826 an issue until we start to get into multidimensional arrays anyway. If
18827 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18828 then we'll have to put the DW_AT_ordering attribute back in. (But if
18829 and when we find out that we need to put these in, we will only do so
18830 for multidimensional arrays. */
18831 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18834 #ifdef MIPS_DEBUGGING_INFO
18835 /* The SGI compilers handle arrays of unknown bound by setting
18836 AT_declaration and not emitting any subrange DIEs. */
18837 if (TREE_CODE (type) == ARRAY_TYPE
18838 && ! TYPE_DOMAIN (type))
18839 add_AT_flag (array_die, DW_AT_declaration, 1);
18842 if (TREE_CODE (type) == VECTOR_TYPE)
18844 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18845 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18846 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18847 add_bound_info (subrange_die, DW_AT_upper_bound,
18848 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18851 add_subscript_info (array_die, type, collapse_nested_arrays);
18853 /* Add representation of the type of the elements of this array type and
18854 emit the corresponding DIE if we haven't done it already. */
18855 element_type = TREE_TYPE (type);
18856 if (collapse_nested_arrays)
18857 while (TREE_CODE (element_type) == ARRAY_TYPE)
18859 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18861 element_type = TREE_TYPE (element_type);
18864 #ifndef MIPS_DEBUGGING_INFO
18865 gen_type_die (element_type, context_die);
18868 add_type_attribute (array_die, element_type, 0, 0, context_die);
18870 if (get_AT (array_die, DW_AT_name))
18871 add_pubtype (type, array_die);
18874 static dw_loc_descr_ref
18875 descr_info_loc (tree val, tree base_decl)
18877 HOST_WIDE_INT size;
18878 dw_loc_descr_ref loc, loc2;
18879 enum dwarf_location_atom op;
18881 if (val == base_decl)
18882 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18884 switch (TREE_CODE (val))
18887 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18889 return loc_descriptor_from_tree (val, 0);
18891 if (host_integerp (val, 0))
18892 return int_loc_descriptor (tree_low_cst (val, 0));
18895 size = int_size_in_bytes (TREE_TYPE (val));
18898 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18901 if (size == DWARF2_ADDR_SIZE)
18902 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18904 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18906 case POINTER_PLUS_EXPR:
18908 if (host_integerp (TREE_OPERAND (val, 1), 1)
18909 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18912 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18915 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18921 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18924 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18927 add_loc_descr (&loc, loc2);
18928 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18950 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18951 tree val, tree base_decl)
18953 dw_loc_descr_ref loc;
18955 if (host_integerp (val, 0))
18957 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18961 loc = descr_info_loc (val, base_decl);
18965 add_AT_loc (die, attr, loc);
18968 /* This routine generates DIE for array with hidden descriptor, details
18969 are filled into *info by a langhook. */
18972 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18973 dw_die_ref context_die)
18975 dw_die_ref scope_die = scope_die_for (type, context_die);
18976 dw_die_ref array_die;
18979 array_die = new_die (DW_TAG_array_type, scope_die, type);
18980 add_name_attribute (array_die, type_tag (type));
18981 equate_type_number_to_die (type, array_die);
18983 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18985 && info->ndimensions >= 2)
18986 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18988 if (info->data_location)
18989 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18991 if (info->associated)
18992 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18994 if (info->allocated)
18995 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18998 for (dim = 0; dim < info->ndimensions; dim++)
19000 dw_die_ref subrange_die
19001 = new_die (DW_TAG_subrange_type, array_die, NULL);
19003 if (info->dimen[dim].lower_bound)
19005 /* If it is the default value, omit it. */
19008 if (host_integerp (info->dimen[dim].lower_bound, 0)
19009 && (dflt = lower_bound_default ()) != -1
19010 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
19013 add_descr_info_field (subrange_die, DW_AT_lower_bound,
19014 info->dimen[dim].lower_bound,
19017 if (info->dimen[dim].upper_bound)
19018 add_descr_info_field (subrange_die, DW_AT_upper_bound,
19019 info->dimen[dim].upper_bound,
19021 if (info->dimen[dim].stride)
19022 add_descr_info_field (subrange_die, DW_AT_byte_stride,
19023 info->dimen[dim].stride,
19027 gen_type_die (info->element_type, context_die);
19028 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
19030 if (get_AT (array_die, DW_AT_name))
19031 add_pubtype (type, array_die);
19036 gen_entry_point_die (tree decl, dw_die_ref context_die)
19038 tree origin = decl_ultimate_origin (decl);
19039 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
19041 if (origin != NULL)
19042 add_abstract_origin_attribute (decl_die, origin);
19045 add_name_and_src_coords_attributes (decl_die, decl);
19046 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
19047 0, 0, context_die);
19050 if (DECL_ABSTRACT (decl))
19051 equate_decl_number_to_die (decl, decl_die);
19053 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
19057 /* Walk through the list of incomplete types again, trying once more to
19058 emit full debugging info for them. */
19061 retry_incomplete_types (void)
19065 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
19066 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
19067 DINFO_USAGE_DIR_USE))
19068 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
19071 /* Determine what tag to use for a record type. */
19073 static enum dwarf_tag
19074 record_type_tag (tree type)
19076 if (! lang_hooks.types.classify_record)
19077 return DW_TAG_structure_type;
19079 switch (lang_hooks.types.classify_record (type))
19081 case RECORD_IS_STRUCT:
19082 return DW_TAG_structure_type;
19084 case RECORD_IS_CLASS:
19085 return DW_TAG_class_type;
19087 case RECORD_IS_INTERFACE:
19088 if (dwarf_version >= 3 || !dwarf_strict)
19089 return DW_TAG_interface_type;
19090 return DW_TAG_structure_type;
19093 gcc_unreachable ();
19097 /* Generate a DIE to represent an enumeration type. Note that these DIEs
19098 include all of the information about the enumeration values also. Each
19099 enumerated type name/value is listed as a child of the enumerated type
19103 gen_enumeration_type_die (tree type, dw_die_ref context_die)
19105 dw_die_ref type_die = lookup_type_die (type);
19107 if (type_die == NULL)
19109 type_die = new_die (DW_TAG_enumeration_type,
19110 scope_die_for (type, context_die), type);
19111 equate_type_number_to_die (type, type_die);
19112 add_name_attribute (type_die, type_tag (type));
19113 add_gnat_descriptive_type_attribute (type_die, type, context_die);
19114 if (dwarf_version >= 4 || !dwarf_strict)
19116 if (ENUM_IS_SCOPED (type))
19117 add_AT_flag (type_die, DW_AT_enum_class, 1);
19118 if (ENUM_IS_OPAQUE (type))
19119 add_AT_flag (type_die, DW_AT_declaration, 1);
19122 else if (! TYPE_SIZE (type))
19125 remove_AT (type_die, DW_AT_declaration);
19127 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
19128 given enum type is incomplete, do not generate the DW_AT_byte_size
19129 attribute or the DW_AT_element_list attribute. */
19130 if (TYPE_SIZE (type))
19134 TREE_ASM_WRITTEN (type) = 1;
19135 add_byte_size_attribute (type_die, type);
19136 if (TYPE_STUB_DECL (type) != NULL_TREE)
19138 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
19139 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
19142 /* If the first reference to this type was as the return type of an
19143 inline function, then it may not have a parent. Fix this now. */
19144 if (type_die->die_parent == NULL)
19145 add_child_die (scope_die_for (type, context_die), type_die);
19147 for (link = TYPE_VALUES (type);
19148 link != NULL; link = TREE_CHAIN (link))
19150 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
19151 tree value = TREE_VALUE (link);
19153 add_name_attribute (enum_die,
19154 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
19156 if (TREE_CODE (value) == CONST_DECL)
19157 value = DECL_INITIAL (value);
19159 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
19160 /* DWARF2 does not provide a way of indicating whether or
19161 not enumeration constants are signed or unsigned. GDB
19162 always assumes the values are signed, so we output all
19163 values as if they were signed. That means that
19164 enumeration constants with very large unsigned values
19165 will appear to have negative values in the debugger. */
19166 add_AT_int (enum_die, DW_AT_const_value,
19167 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
19171 add_AT_flag (type_die, DW_AT_declaration, 1);
19173 if (get_AT (type_die, DW_AT_name))
19174 add_pubtype (type, type_die);
19179 /* Generate a DIE to represent either a real live formal parameter decl or to
19180 represent just the type of some formal parameter position in some function
19183 Note that this routine is a bit unusual because its argument may be a
19184 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
19185 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
19186 node. If it's the former then this function is being called to output a
19187 DIE to represent a formal parameter object (or some inlining thereof). If
19188 it's the latter, then this function is only being called to output a
19189 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
19190 argument type of some subprogram type.
19191 If EMIT_NAME_P is true, name and source coordinate attributes
19195 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
19196 dw_die_ref context_die)
19198 tree node_or_origin = node ? node : origin;
19199 tree ultimate_origin;
19200 dw_die_ref parm_die
19201 = new_die (DW_TAG_formal_parameter, context_die, node);
19203 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
19205 case tcc_declaration:
19206 ultimate_origin = decl_ultimate_origin (node_or_origin);
19207 if (node || ultimate_origin)
19208 origin = ultimate_origin;
19209 if (origin != NULL)
19210 add_abstract_origin_attribute (parm_die, origin);
19211 else if (emit_name_p)
19212 add_name_and_src_coords_attributes (parm_die, node);
19214 || (! DECL_ABSTRACT (node_or_origin)
19215 && variably_modified_type_p (TREE_TYPE (node_or_origin),
19216 decl_function_context
19217 (node_or_origin))))
19219 tree type = TREE_TYPE (node_or_origin);
19220 if (decl_by_reference_p (node_or_origin))
19221 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
19224 add_type_attribute (parm_die, type,
19225 TREE_READONLY (node_or_origin),
19226 TREE_THIS_VOLATILE (node_or_origin),
19229 if (origin == NULL && DECL_ARTIFICIAL (node))
19230 add_AT_flag (parm_die, DW_AT_artificial, 1);
19232 if (node && node != origin)
19233 equate_decl_number_to_die (node, parm_die);
19234 if (! DECL_ABSTRACT (node_or_origin))
19235 add_location_or_const_value_attribute (parm_die, node_or_origin,
19236 node == NULL, DW_AT_location);
19241 /* We were called with some kind of a ..._TYPE node. */
19242 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
19246 gcc_unreachable ();
19252 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
19253 children DW_TAG_formal_parameter DIEs representing the arguments of the
19256 PARM_PACK must be a function parameter pack.
19257 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
19258 must point to the subsequent arguments of the function PACK_ARG belongs to.
19259 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
19260 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
19261 following the last one for which a DIE was generated. */
19264 gen_formal_parameter_pack_die (tree parm_pack,
19266 dw_die_ref subr_die,
19270 dw_die_ref parm_pack_die;
19272 gcc_assert (parm_pack
19273 && lang_hooks.function_parameter_pack_p (parm_pack)
19276 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
19277 add_src_coords_attributes (parm_pack_die, parm_pack);
19279 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
19281 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
19284 gen_formal_parameter_die (arg, NULL,
19285 false /* Don't emit name attribute. */,
19290 return parm_pack_die;
19293 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
19294 at the end of an (ANSI prototyped) formal parameters list. */
19297 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
19299 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
19302 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
19303 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
19304 parameters as specified in some function type specification (except for
19305 those which appear as part of a function *definition*). */
19308 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
19311 tree formal_type = NULL;
19312 tree first_parm_type;
19315 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
19317 arg = DECL_ARGUMENTS (function_or_method_type);
19318 function_or_method_type = TREE_TYPE (function_or_method_type);
19323 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
19325 /* Make our first pass over the list of formal parameter types and output a
19326 DW_TAG_formal_parameter DIE for each one. */
19327 for (link = first_parm_type; link; )
19329 dw_die_ref parm_die;
19331 formal_type = TREE_VALUE (link);
19332 if (formal_type == void_type_node)
19335 /* Output a (nameless) DIE to represent the formal parameter itself. */
19336 parm_die = gen_formal_parameter_die (formal_type, NULL,
19337 true /* Emit name attribute. */,
19339 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
19340 && link == first_parm_type)
19342 add_AT_flag (parm_die, DW_AT_artificial, 1);
19343 if (dwarf_version >= 3 || !dwarf_strict)
19344 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
19346 else if (arg && DECL_ARTIFICIAL (arg))
19347 add_AT_flag (parm_die, DW_AT_artificial, 1);
19349 link = TREE_CHAIN (link);
19351 arg = DECL_CHAIN (arg);
19354 /* If this function type has an ellipsis, add a
19355 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
19356 if (formal_type != void_type_node)
19357 gen_unspecified_parameters_die (function_or_method_type, context_die);
19359 /* Make our second (and final) pass over the list of formal parameter types
19360 and output DIEs to represent those types (as necessary). */
19361 for (link = TYPE_ARG_TYPES (function_or_method_type);
19362 link && TREE_VALUE (link);
19363 link = TREE_CHAIN (link))
19364 gen_type_die (TREE_VALUE (link), context_die);
19367 /* We want to generate the DIE for TYPE so that we can generate the
19368 die for MEMBER, which has been defined; we will need to refer back
19369 to the member declaration nested within TYPE. If we're trying to
19370 generate minimal debug info for TYPE, processing TYPE won't do the
19371 trick; we need to attach the member declaration by hand. */
19374 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
19376 gen_type_die (type, context_die);
19378 /* If we're trying to avoid duplicate debug info, we may not have
19379 emitted the member decl for this function. Emit it now. */
19380 if (TYPE_STUB_DECL (type)
19381 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
19382 && ! lookup_decl_die (member))
19384 dw_die_ref type_die;
19385 gcc_assert (!decl_ultimate_origin (member));
19387 push_decl_scope (type);
19388 type_die = lookup_type_die_strip_naming_typedef (type);
19389 if (TREE_CODE (member) == FUNCTION_DECL)
19390 gen_subprogram_die (member, type_die);
19391 else if (TREE_CODE (member) == FIELD_DECL)
19393 /* Ignore the nameless fields that are used to skip bits but handle
19394 C++ anonymous unions and structs. */
19395 if (DECL_NAME (member) != NULL_TREE
19396 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
19397 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
19399 gen_type_die (member_declared_type (member), type_die);
19400 gen_field_die (member, type_die);
19404 gen_variable_die (member, NULL_TREE, type_die);
19410 /* Generate the DWARF2 info for the "abstract" instance of a function which we
19411 may later generate inlined and/or out-of-line instances of. */
19414 dwarf2out_abstract_function (tree decl)
19416 dw_die_ref old_die;
19420 htab_t old_decl_loc_table;
19421 htab_t old_cached_dw_loc_list_table;
19422 int old_call_site_count, old_tail_call_site_count;
19423 struct call_arg_loc_node *old_call_arg_locations;
19425 /* Make sure we have the actual abstract inline, not a clone. */
19426 decl = DECL_ORIGIN (decl);
19428 old_die = lookup_decl_die (decl);
19429 if (old_die && get_AT (old_die, DW_AT_inline))
19430 /* We've already generated the abstract instance. */
19433 /* We can be called while recursively when seeing block defining inlined subroutine
19434 DIE. Be sure to not clobber the outer location table nor use it or we would
19435 get locations in abstract instantces. */
19436 old_decl_loc_table = decl_loc_table;
19437 decl_loc_table = NULL;
19438 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
19439 cached_dw_loc_list_table = NULL;
19440 old_call_arg_locations = call_arg_locations;
19441 call_arg_locations = NULL;
19442 old_call_site_count = call_site_count;
19443 call_site_count = -1;
19444 old_tail_call_site_count = tail_call_site_count;
19445 tail_call_site_count = -1;
19447 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
19448 we don't get confused by DECL_ABSTRACT. */
19449 if (debug_info_level > DINFO_LEVEL_TERSE)
19451 context = decl_class_context (decl);
19453 gen_type_die_for_member
19454 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
19457 /* Pretend we've just finished compiling this function. */
19458 save_fn = current_function_decl;
19459 current_function_decl = decl;
19460 push_cfun (DECL_STRUCT_FUNCTION (decl));
19462 was_abstract = DECL_ABSTRACT (decl);
19463 set_decl_abstract_flags (decl, 1);
19464 dwarf2out_decl (decl);
19465 if (! was_abstract)
19466 set_decl_abstract_flags (decl, 0);
19468 current_function_decl = save_fn;
19469 decl_loc_table = old_decl_loc_table;
19470 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
19471 call_arg_locations = old_call_arg_locations;
19472 call_site_count = old_call_site_count;
19473 tail_call_site_count = old_tail_call_site_count;
19477 /* Helper function of premark_used_types() which gets called through
19480 Marks the DIE of a given type in *SLOT as perennial, so it never gets
19481 marked as unused by prune_unused_types. */
19484 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
19489 type = (tree) *slot;
19490 die = lookup_type_die (type);
19492 die->die_perennial_p = 1;
19496 /* Helper function of premark_types_used_by_global_vars which gets called
19497 through htab_traverse.
19499 Marks the DIE of a given type in *SLOT as perennial, so it never gets
19500 marked as unused by prune_unused_types. The DIE of the type is marked
19501 only if the global variable using the type will actually be emitted. */
19504 premark_types_used_by_global_vars_helper (void **slot,
19505 void *data ATTRIBUTE_UNUSED)
19507 struct types_used_by_vars_entry *entry;
19510 entry = (struct types_used_by_vars_entry *) *slot;
19511 gcc_assert (entry->type != NULL
19512 && entry->var_decl != NULL);
19513 die = lookup_type_die (entry->type);
19516 /* Ask cgraph if the global variable really is to be emitted.
19517 If yes, then we'll keep the DIE of ENTRY->TYPE. */
19518 struct varpool_node *node = varpool_get_node (entry->var_decl);
19519 if (node && node->needed)
19521 die->die_perennial_p = 1;
19522 /* Keep the parent DIEs as well. */
19523 while ((die = die->die_parent) && die->die_perennial_p == 0)
19524 die->die_perennial_p = 1;
19530 /* Mark all members of used_types_hash as perennial. */
19533 premark_used_types (void)
19535 if (cfun && cfun->used_types_hash)
19536 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
19539 /* Mark all members of types_used_by_vars_entry as perennial. */
19542 premark_types_used_by_global_vars (void)
19544 if (types_used_by_vars_hash)
19545 htab_traverse (types_used_by_vars_hash,
19546 premark_types_used_by_global_vars_helper, NULL);
19549 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
19550 for CA_LOC call arg loc node. */
19553 gen_call_site_die (tree decl, dw_die_ref subr_die,
19554 struct call_arg_loc_node *ca_loc)
19556 dw_die_ref stmt_die = NULL, die;
19557 tree block = ca_loc->block;
19560 && block != DECL_INITIAL (decl)
19561 && TREE_CODE (block) == BLOCK)
19563 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
19564 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
19567 block = BLOCK_SUPERCONTEXT (block);
19569 if (stmt_die == NULL)
19570 stmt_die = subr_die;
19571 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
19572 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
19573 if (ca_loc->tail_call_p)
19574 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
19575 if (ca_loc->symbol_ref)
19577 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
19579 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
19581 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
19586 /* Generate a DIE to represent a declared function (either file-scope or
19590 gen_subprogram_die (tree decl, dw_die_ref context_die)
19592 tree origin = decl_ultimate_origin (decl);
19593 dw_die_ref subr_die;
19595 dw_die_ref old_die = lookup_decl_die (decl);
19596 int declaration = (current_function_decl != decl
19597 || class_or_namespace_scope_p (context_die));
19599 premark_used_types ();
19601 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
19602 started to generate the abstract instance of an inline, decided to output
19603 its containing class, and proceeded to emit the declaration of the inline
19604 from the member list for the class. If so, DECLARATION takes priority;
19605 we'll get back to the abstract instance when done with the class. */
19607 /* The class-scope declaration DIE must be the primary DIE. */
19608 if (origin && declaration && class_or_namespace_scope_p (context_die))
19611 gcc_assert (!old_die);
19614 /* Now that the C++ front end lazily declares artificial member fns, we
19615 might need to retrofit the declaration into its class. */
19616 if (!declaration && !origin && !old_die
19617 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
19618 && !class_or_namespace_scope_p (context_die)
19619 && debug_info_level > DINFO_LEVEL_TERSE)
19620 old_die = force_decl_die (decl);
19622 if (origin != NULL)
19624 gcc_assert (!declaration || local_scope_p (context_die));
19626 /* Fixup die_parent for the abstract instance of a nested
19627 inline function. */
19628 if (old_die && old_die->die_parent == NULL)
19629 add_child_die (context_die, old_die);
19631 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19632 add_abstract_origin_attribute (subr_die, origin);
19636 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19637 struct dwarf_file_data * file_index = lookup_filename (s.file);
19639 if (!get_AT_flag (old_die, DW_AT_declaration)
19640 /* We can have a normal definition following an inline one in the
19641 case of redefinition of GNU C extern inlines.
19642 It seems reasonable to use AT_specification in this case. */
19643 && !get_AT (old_die, DW_AT_inline))
19645 /* Detect and ignore this case, where we are trying to output
19646 something we have already output. */
19650 /* If the definition comes from the same place as the declaration,
19651 maybe use the old DIE. We always want the DIE for this function
19652 that has the *_pc attributes to be under comp_unit_die so the
19653 debugger can find it. We also need to do this for abstract
19654 instances of inlines, since the spec requires the out-of-line copy
19655 to have the same parent. For local class methods, this doesn't
19656 apply; we just use the old DIE. */
19657 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
19658 && (DECL_ARTIFICIAL (decl)
19659 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
19660 && (get_AT_unsigned (old_die, DW_AT_decl_line)
19661 == (unsigned) s.line))))
19663 subr_die = old_die;
19665 /* Clear out the declaration attribute and the formal parameters.
19666 Do not remove all children, because it is possible that this
19667 declaration die was forced using force_decl_die(). In such
19668 cases die that forced declaration die (e.g. TAG_imported_module)
19669 is one of the children that we do not want to remove. */
19670 remove_AT (subr_die, DW_AT_declaration);
19671 remove_AT (subr_die, DW_AT_object_pointer);
19672 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
19676 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19677 add_AT_specification (subr_die, old_die);
19678 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19679 add_AT_file (subr_die, DW_AT_decl_file, file_index);
19680 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19681 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
19686 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19688 if (TREE_PUBLIC (decl))
19689 add_AT_flag (subr_die, DW_AT_external, 1);
19691 add_name_and_src_coords_attributes (subr_die, decl);
19692 if (debug_info_level > DINFO_LEVEL_TERSE)
19694 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
19695 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
19696 0, 0, context_die);
19699 add_pure_or_virtual_attribute (subr_die, decl);
19700 if (DECL_ARTIFICIAL (decl))
19701 add_AT_flag (subr_die, DW_AT_artificial, 1);
19703 add_accessibility_attribute (subr_die, decl);
19708 if (!old_die || !get_AT (old_die, DW_AT_inline))
19710 add_AT_flag (subr_die, DW_AT_declaration, 1);
19712 /* If this is an explicit function declaration then generate
19713 a DW_AT_explicit attribute. */
19714 if (lang_hooks.decls.function_decl_explicit_p (decl)
19715 && (dwarf_version >= 3 || !dwarf_strict))
19716 add_AT_flag (subr_die, DW_AT_explicit, 1);
19718 /* The first time we see a member function, it is in the context of
19719 the class to which it belongs. We make sure of this by emitting
19720 the class first. The next time is the definition, which is
19721 handled above. The two may come from the same source text.
19723 Note that force_decl_die() forces function declaration die. It is
19724 later reused to represent definition. */
19725 equate_decl_number_to_die (decl, subr_die);
19728 else if (DECL_ABSTRACT (decl))
19730 if (DECL_DECLARED_INLINE_P (decl))
19732 if (cgraph_function_possibly_inlined_p (decl))
19733 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19735 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19739 if (cgraph_function_possibly_inlined_p (decl))
19740 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19742 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19745 if (DECL_DECLARED_INLINE_P (decl)
19746 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19747 add_AT_flag (subr_die, DW_AT_artificial, 1);
19749 equate_decl_number_to_die (decl, subr_die);
19751 else if (!DECL_EXTERNAL (decl))
19753 HOST_WIDE_INT cfa_fb_offset;
19755 if (!old_die || !get_AT (old_die, DW_AT_inline))
19756 equate_decl_number_to_die (decl, subr_die);
19758 if (!flag_reorder_blocks_and_partition)
19760 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19761 if (fde->dw_fde_begin)
19763 /* We have already generated the labels. */
19764 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19765 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19769 /* Create start/end labels and add the range. */
19770 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
19771 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19772 current_function_funcdef_no);
19773 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19774 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19775 current_function_funcdef_no);
19776 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19779 #if VMS_DEBUGGING_INFO
19780 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19781 Section 2.3 Prologue and Epilogue Attributes:
19782 When a breakpoint is set on entry to a function, it is generally
19783 desirable for execution to be suspended, not on the very first
19784 instruction of the function, but rather at a point after the
19785 function's frame has been set up, after any language defined local
19786 declaration processing has been completed, and before execution of
19787 the first statement of the function begins. Debuggers generally
19788 cannot properly determine where this point is. Similarly for a
19789 breakpoint set on exit from a function. The prologue and epilogue
19790 attributes allow a compiler to communicate the location(s) to use. */
19793 if (fde->dw_fde_vms_end_prologue)
19794 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19795 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19797 if (fde->dw_fde_vms_begin_epilogue)
19798 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19799 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19803 add_pubname (decl, subr_die);
19806 { /* Generate pubnames entries for the split function code
19808 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19810 if (fde->dw_fde_second_begin)
19812 if (dwarf_version >= 3 || !dwarf_strict)
19814 /* We should use ranges for non-contiguous code section
19815 addresses. Use the actual code range for the initial
19816 section, since the HOT/COLD labels might precede an
19817 alignment offset. */
19818 bool range_list_added = false;
19819 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
19820 fde->dw_fde_end, &range_list_added);
19821 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
19822 fde->dw_fde_second_end,
19823 &range_list_added);
19824 add_pubname (decl, subr_die);
19825 if (range_list_added)
19830 /* There is no real support in DW2 for this .. so we make
19831 a work-around. First, emit the pub name for the segment
19832 containing the function label. Then make and emit a
19833 simplified subprogram DIE for the second segment with the
19834 name pre-fixed by __hot/cold_sect_of_. We use the same
19835 linkage name for the second die so that gdb will find both
19836 sections when given "b foo". */
19837 const char *name = NULL;
19838 tree decl_name = DECL_NAME (decl);
19839 dw_die_ref seg_die;
19841 /* Do the 'primary' section. */
19842 add_AT_lbl_id (subr_die, DW_AT_low_pc,
19843 fde->dw_fde_begin);
19844 add_AT_lbl_id (subr_die, DW_AT_high_pc,
19847 add_pubname (decl, subr_die);
19849 /* Build a minimal DIE for the secondary section. */
19850 seg_die = new_die (DW_TAG_subprogram,
19851 subr_die->die_parent, decl);
19853 if (TREE_PUBLIC (decl))
19854 add_AT_flag (seg_die, DW_AT_external, 1);
19856 if (decl_name != NULL
19857 && IDENTIFIER_POINTER (decl_name) != NULL)
19859 name = dwarf2_name (decl, 1);
19860 if (! DECL_ARTIFICIAL (decl))
19861 add_src_coords_attributes (seg_die, decl);
19863 add_linkage_name (seg_die, decl);
19865 gcc_assert (name != NULL);
19866 add_pure_or_virtual_attribute (seg_die, decl);
19867 if (DECL_ARTIFICIAL (decl))
19868 add_AT_flag (seg_die, DW_AT_artificial, 1);
19870 name = concat ("__second_sect_of_", name, NULL);
19871 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19872 fde->dw_fde_second_begin);
19873 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19874 fde->dw_fde_second_end);
19875 add_name_attribute (seg_die, name);
19876 add_pubname_string (name, seg_die);
19881 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19882 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19883 add_pubname (decl, subr_die);
19887 #ifdef MIPS_DEBUGGING_INFO
19888 /* Add a reference to the FDE for this routine. */
19889 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19892 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19894 /* We define the "frame base" as the function's CFA. This is more
19895 convenient for several reasons: (1) It's stable across the prologue
19896 and epilogue, which makes it better than just a frame pointer,
19897 (2) With dwarf3, there exists a one-byte encoding that allows us
19898 to reference the .debug_frame data by proxy, but failing that,
19899 (3) We can at least reuse the code inspection and interpretation
19900 code that determines the CFA position at various points in the
19902 if (dwarf_version >= 3)
19904 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19905 add_AT_loc (subr_die, DW_AT_frame_base, op);
19909 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19910 if (list->dw_loc_next)
19911 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19913 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19916 /* Compute a displacement from the "steady-state frame pointer" to
19917 the CFA. The former is what all stack slots and argument slots
19918 will reference in the rtl; the later is what we've told the
19919 debugger about. We'll need to adjust all frame_base references
19920 by this displacement. */
19921 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19923 if (cfun->static_chain_decl)
19924 add_AT_location_description (subr_die, DW_AT_static_link,
19925 loc_list_from_tree (cfun->static_chain_decl, 2));
19928 /* Generate child dies for template paramaters. */
19929 if (debug_info_level > DINFO_LEVEL_TERSE)
19930 gen_generic_params_dies (decl);
19932 /* Now output descriptions of the arguments for this function. This gets
19933 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19934 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19935 `...' at the end of the formal parameter list. In order to find out if
19936 there was a trailing ellipsis or not, we must instead look at the type
19937 associated with the FUNCTION_DECL. This will be a node of type
19938 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19939 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19940 an ellipsis at the end. */
19942 /* In the case where we are describing a mere function declaration, all we
19943 need to do here (and all we *can* do here) is to describe the *types* of
19944 its formal parameters. */
19945 if (debug_info_level <= DINFO_LEVEL_TERSE)
19947 else if (declaration)
19948 gen_formal_types_die (decl, subr_die);
19951 /* Generate DIEs to represent all known formal parameters. */
19952 tree parm = DECL_ARGUMENTS (decl);
19953 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19954 tree generic_decl_parm = generic_decl
19955 ? DECL_ARGUMENTS (generic_decl)
19958 /* Now we want to walk the list of parameters of the function and
19959 emit their relevant DIEs.
19961 We consider the case of DECL being an instance of a generic function
19962 as well as it being a normal function.
19964 If DECL is an instance of a generic function we walk the
19965 parameters of the generic function declaration _and_ the parameters of
19966 DECL itself. This is useful because we want to emit specific DIEs for
19967 function parameter packs and those are declared as part of the
19968 generic function declaration. In that particular case,
19969 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19970 That DIE has children DIEs representing the set of arguments
19971 of the pack. Note that the set of pack arguments can be empty.
19972 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19975 Otherwise, we just consider the parameters of DECL. */
19976 while (generic_decl_parm || parm)
19978 if (generic_decl_parm
19979 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19980 gen_formal_parameter_pack_die (generic_decl_parm,
19985 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19987 if (parm == DECL_ARGUMENTS (decl)
19988 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19990 && (dwarf_version >= 3 || !dwarf_strict))
19991 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19993 parm = DECL_CHAIN (parm);
19996 if (generic_decl_parm)
19997 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
20000 /* Decide whether we need an unspecified_parameters DIE at the end.
20001 There are 2 more cases to do this for: 1) the ansi ... declaration -
20002 this is detectable when the end of the arg list is not a
20003 void_type_node 2) an unprototyped function declaration (not a
20004 definition). This just means that we have no info about the
20005 parameters at all. */
20006 if (prototype_p (TREE_TYPE (decl)))
20008 /* This is the prototyped case, check for.... */
20009 if (stdarg_p (TREE_TYPE (decl)))
20010 gen_unspecified_parameters_die (decl, subr_die);
20012 else if (DECL_INITIAL (decl) == NULL_TREE)
20013 gen_unspecified_parameters_die (decl, subr_die);
20016 /* Output Dwarf info for all of the stuff within the body of the function
20017 (if it has one - it may be just a declaration). */
20018 outer_scope = DECL_INITIAL (decl);
20020 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
20021 a function. This BLOCK actually represents the outermost binding contour
20022 for the function, i.e. the contour in which the function's formal
20023 parameters and labels get declared. Curiously, it appears that the front
20024 end doesn't actually put the PARM_DECL nodes for the current function onto
20025 the BLOCK_VARS list for this outer scope, but are strung off of the
20026 DECL_ARGUMENTS list for the function instead.
20028 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
20029 the LABEL_DECL nodes for the function however, and we output DWARF info
20030 for those in decls_for_scope. Just within the `outer_scope' there will be
20031 a BLOCK node representing the function's outermost pair of curly braces,
20032 and any blocks used for the base and member initializers of a C++
20033 constructor function. */
20034 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
20036 int call_site_note_count = 0;
20037 int tail_call_site_note_count = 0;
20039 /* Emit a DW_TAG_variable DIE for a named return value. */
20040 if (DECL_NAME (DECL_RESULT (decl)))
20041 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
20043 current_function_has_inlines = 0;
20044 decls_for_scope (outer_scope, subr_die, 0);
20046 if (call_arg_locations && !dwarf_strict)
20048 struct call_arg_loc_node *ca_loc;
20049 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
20051 dw_die_ref die = NULL;
20052 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
20055 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
20056 arg; arg = next_arg)
20058 dw_loc_descr_ref reg, val;
20059 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
20062 next_arg = XEXP (arg, 1);
20063 if (REG_P (XEXP (XEXP (arg, 0), 0))
20065 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
20066 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
20067 && REGNO (XEXP (XEXP (arg, 0), 0))
20068 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
20069 next_arg = XEXP (next_arg, 1);
20070 if (mode == VOIDmode)
20072 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
20073 if (mode == VOIDmode)
20074 mode = GET_MODE (XEXP (arg, 0));
20076 if (mode == VOIDmode || mode == BLKmode)
20078 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
20080 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
20081 tloc = XEXP (XEXP (arg, 0), 1);
20084 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
20085 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
20087 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
20088 tlocc = XEXP (XEXP (arg, 0), 1);
20091 if (REG_P (XEXP (XEXP (arg, 0), 0)))
20092 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
20093 VAR_INIT_STATUS_INITIALIZED);
20094 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
20096 rtx mem = XEXP (XEXP (arg, 0), 0);
20097 reg = mem_loc_descriptor (XEXP (mem, 0),
20098 get_address_mode (mem),
20100 VAR_INIT_STATUS_INITIALIZED);
20106 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
20108 VAR_INIT_STATUS_INITIALIZED);
20112 die = gen_call_site_die (decl, subr_die, ca_loc);
20113 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
20115 add_AT_loc (cdie, DW_AT_location, reg);
20116 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
20117 if (next_arg != XEXP (arg, 1))
20119 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
20120 if (mode == VOIDmode)
20121 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
20122 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
20125 VAR_INIT_STATUS_INITIALIZED);
20127 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
20131 && (ca_loc->symbol_ref || tloc))
20132 die = gen_call_site_die (decl, subr_die, ca_loc);
20133 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
20135 dw_loc_descr_ref tval = NULL;
20137 if (tloc != NULL_RTX)
20138 tval = mem_loc_descriptor (tloc,
20139 GET_MODE (tloc) == VOIDmode
20140 ? Pmode : GET_MODE (tloc),
20142 VAR_INIT_STATUS_INITIALIZED);
20144 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
20145 else if (tlocc != NULL_RTX)
20147 tval = mem_loc_descriptor (tlocc,
20148 GET_MODE (tlocc) == VOIDmode
20149 ? Pmode : GET_MODE (tlocc),
20151 VAR_INIT_STATUS_INITIALIZED);
20153 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
20159 call_site_note_count++;
20160 if (ca_loc->tail_call_p)
20161 tail_call_site_note_count++;
20165 call_arg_locations = NULL;
20166 call_arg_loc_last = NULL;
20167 if (tail_call_site_count >= 0
20168 && tail_call_site_count == tail_call_site_note_count
20171 if (call_site_count >= 0
20172 && call_site_count == call_site_note_count)
20173 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
20175 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
20177 call_site_count = -1;
20178 tail_call_site_count = -1;
20180 /* Add the calling convention attribute if requested. */
20181 add_calling_convention_attribute (subr_die, decl);
20185 /* Returns a hash value for X (which really is a die_struct). */
20188 common_block_die_table_hash (const void *x)
20190 const_dw_die_ref d = (const_dw_die_ref) x;
20191 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
20194 /* Return nonzero if decl_id and die_parent of die_struct X is the same
20195 as decl_id and die_parent of die_struct Y. */
20198 common_block_die_table_eq (const void *x, const void *y)
20200 const_dw_die_ref d = (const_dw_die_ref) x;
20201 const_dw_die_ref e = (const_dw_die_ref) y;
20202 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
20205 /* Generate a DIE to represent a declared data object.
20206 Either DECL or ORIGIN must be non-null. */
20209 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
20213 tree decl_or_origin = decl ? decl : origin;
20214 tree ultimate_origin;
20215 dw_die_ref var_die;
20216 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
20217 dw_die_ref origin_die;
20218 bool declaration = (DECL_EXTERNAL (decl_or_origin)
20219 || class_or_namespace_scope_p (context_die));
20220 bool specialization_p = false;
20222 ultimate_origin = decl_ultimate_origin (decl_or_origin);
20223 if (decl || ultimate_origin)
20224 origin = ultimate_origin;
20225 com_decl = fortran_common (decl_or_origin, &off);
20227 /* Symbol in common gets emitted as a child of the common block, in the form
20228 of a data member. */
20231 dw_die_ref com_die;
20232 dw_loc_list_ref loc;
20233 die_node com_die_arg;
20235 var_die = lookup_decl_die (decl_or_origin);
20238 if (get_AT (var_die, DW_AT_location) == NULL)
20240 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
20245 /* Optimize the common case. */
20246 if (single_element_loc_list_p (loc)
20247 && loc->expr->dw_loc_opc == DW_OP_addr
20248 && loc->expr->dw_loc_next == NULL
20249 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
20251 loc->expr->dw_loc_oprnd1.v.val_addr
20252 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
20254 loc_list_plus_const (loc, off);
20256 add_AT_location_description (var_die, DW_AT_location, loc);
20257 remove_AT (var_die, DW_AT_declaration);
20263 if (common_block_die_table == NULL)
20264 common_block_die_table
20265 = htab_create_ggc (10, common_block_die_table_hash,
20266 common_block_die_table_eq, NULL);
20268 com_die_arg.decl_id = DECL_UID (com_decl);
20269 com_die_arg.die_parent = context_die;
20270 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
20271 loc = loc_list_from_tree (com_decl, 2);
20272 if (com_die == NULL)
20275 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
20278 com_die = new_die (DW_TAG_common_block, context_die, decl);
20279 add_name_and_src_coords_attributes (com_die, com_decl);
20282 add_AT_location_description (com_die, DW_AT_location, loc);
20283 /* Avoid sharing the same loc descriptor between
20284 DW_TAG_common_block and DW_TAG_variable. */
20285 loc = loc_list_from_tree (com_decl, 2);
20287 else if (DECL_EXTERNAL (decl))
20288 add_AT_flag (com_die, DW_AT_declaration, 1);
20289 add_pubname_string (cnam, com_die); /* ??? needed? */
20290 com_die->decl_id = DECL_UID (com_decl);
20291 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
20292 *slot = (void *) com_die;
20294 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
20296 add_AT_location_description (com_die, DW_AT_location, loc);
20297 loc = loc_list_from_tree (com_decl, 2);
20298 remove_AT (com_die, DW_AT_declaration);
20300 var_die = new_die (DW_TAG_variable, com_die, decl);
20301 add_name_and_src_coords_attributes (var_die, decl);
20302 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
20303 TREE_THIS_VOLATILE (decl), context_die);
20304 add_AT_flag (var_die, DW_AT_external, 1);
20309 /* Optimize the common case. */
20310 if (single_element_loc_list_p (loc)
20311 && loc->expr->dw_loc_opc == DW_OP_addr
20312 && loc->expr->dw_loc_next == NULL
20313 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
20314 loc->expr->dw_loc_oprnd1.v.val_addr
20315 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
20317 loc_list_plus_const (loc, off);
20319 add_AT_location_description (var_die, DW_AT_location, loc);
20321 else if (DECL_EXTERNAL (decl))
20322 add_AT_flag (var_die, DW_AT_declaration, 1);
20323 equate_decl_number_to_die (decl, var_die);
20327 /* If the compiler emitted a definition for the DECL declaration
20328 and if we already emitted a DIE for it, don't emit a second
20329 DIE for it again. Allow re-declarations of DECLs that are
20330 inside functions, though. */
20331 if (old_die && declaration && !local_scope_p (context_die))
20334 /* For static data members, the declaration in the class is supposed
20335 to have DW_TAG_member tag; the specification should still be
20336 DW_TAG_variable referencing the DW_TAG_member DIE. */
20337 if (declaration && class_scope_p (context_die))
20338 var_die = new_die (DW_TAG_member, context_die, decl);
20340 var_die = new_die (DW_TAG_variable, context_die, decl);
20343 if (origin != NULL)
20344 origin_die = add_abstract_origin_attribute (var_die, origin);
20346 /* Loop unrolling can create multiple blocks that refer to the same
20347 static variable, so we must test for the DW_AT_declaration flag.
20349 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
20350 copy decls and set the DECL_ABSTRACT flag on them instead of
20353 ??? Duplicated blocks have been rewritten to use .debug_ranges.
20355 ??? The declare_in_namespace support causes us to get two DIEs for one
20356 variable, both of which are declarations. We want to avoid considering
20357 one to be a specification, so we must test that this DIE is not a
20359 else if (old_die && TREE_STATIC (decl) && ! declaration
20360 && get_AT_flag (old_die, DW_AT_declaration) == 1)
20362 /* This is a definition of a C++ class level static. */
20363 add_AT_specification (var_die, old_die);
20364 specialization_p = true;
20365 if (DECL_NAME (decl))
20367 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
20368 struct dwarf_file_data * file_index = lookup_filename (s.file);
20370 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
20371 add_AT_file (var_die, DW_AT_decl_file, file_index);
20373 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
20374 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
20376 if (old_die->die_tag == DW_TAG_member)
20377 add_linkage_name (var_die, decl);
20381 add_name_and_src_coords_attributes (var_die, decl);
20383 if ((origin == NULL && !specialization_p)
20385 && !DECL_ABSTRACT (decl_or_origin)
20386 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
20387 decl_function_context
20388 (decl_or_origin))))
20390 tree type = TREE_TYPE (decl_or_origin);
20392 if (decl_by_reference_p (decl_or_origin))
20393 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
20395 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
20396 TREE_THIS_VOLATILE (decl_or_origin), context_die);
20399 if (origin == NULL && !specialization_p)
20401 if (TREE_PUBLIC (decl))
20402 add_AT_flag (var_die, DW_AT_external, 1);
20404 if (DECL_ARTIFICIAL (decl))
20405 add_AT_flag (var_die, DW_AT_artificial, 1);
20407 add_accessibility_attribute (var_die, decl);
20411 add_AT_flag (var_die, DW_AT_declaration, 1);
20413 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
20414 equate_decl_number_to_die (decl, var_die);
20417 && (! DECL_ABSTRACT (decl_or_origin)
20418 /* Local static vars are shared between all clones/inlines,
20419 so emit DW_AT_location on the abstract DIE if DECL_RTL is
20421 || (TREE_CODE (decl_or_origin) == VAR_DECL
20422 && TREE_STATIC (decl_or_origin)
20423 && DECL_RTL_SET_P (decl_or_origin)))
20424 /* When abstract origin already has DW_AT_location attribute, no need
20425 to add it again. */
20426 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
20428 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
20429 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
20430 defer_location (decl_or_origin, var_die);
20432 add_location_or_const_value_attribute (var_die, decl_or_origin,
20433 decl == NULL, DW_AT_location);
20434 add_pubname (decl_or_origin, var_die);
20437 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
20440 /* Generate a DIE to represent a named constant. */
20443 gen_const_die (tree decl, dw_die_ref context_die)
20445 dw_die_ref const_die;
20446 tree type = TREE_TYPE (decl);
20448 const_die = new_die (DW_TAG_constant, context_die, decl);
20449 add_name_and_src_coords_attributes (const_die, decl);
20450 add_type_attribute (const_die, type, 1, 0, context_die);
20451 if (TREE_PUBLIC (decl))
20452 add_AT_flag (const_die, DW_AT_external, 1);
20453 if (DECL_ARTIFICIAL (decl))
20454 add_AT_flag (const_die, DW_AT_artificial, 1);
20455 tree_add_const_value_attribute_for_decl (const_die, decl);
20458 /* Generate a DIE to represent a label identifier. */
20461 gen_label_die (tree decl, dw_die_ref context_die)
20463 tree origin = decl_ultimate_origin (decl);
20464 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
20466 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20468 if (origin != NULL)
20469 add_abstract_origin_attribute (lbl_die, origin);
20471 add_name_and_src_coords_attributes (lbl_die, decl);
20473 if (DECL_ABSTRACT (decl))
20474 equate_decl_number_to_die (decl, lbl_die);
20477 insn = DECL_RTL_IF_SET (decl);
20479 /* Deleted labels are programmer specified labels which have been
20480 eliminated because of various optimizations. We still emit them
20481 here so that it is possible to put breakpoints on them. */
20485 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
20487 /* When optimization is enabled (via -O) some parts of the compiler
20488 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
20489 represent source-level labels which were explicitly declared by
20490 the user. This really shouldn't be happening though, so catch
20491 it if it ever does happen. */
20492 gcc_assert (!INSN_DELETED_P (insn));
20494 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
20495 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
20500 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
20501 attributes to the DIE for a block STMT, to describe where the inlined
20502 function was called from. This is similar to add_src_coords_attributes. */
20505 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
20507 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
20509 if (dwarf_version >= 3 || !dwarf_strict)
20511 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
20512 add_AT_unsigned (die, DW_AT_call_line, s.line);
20517 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
20518 Add low_pc and high_pc attributes to the DIE for a block STMT. */
20521 add_high_low_attributes (tree stmt, dw_die_ref die)
20523 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20525 if (BLOCK_FRAGMENT_CHAIN (stmt)
20526 && (dwarf_version >= 3 || !dwarf_strict))
20530 if (inlined_function_outer_scope_p (stmt))
20532 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
20533 BLOCK_NUMBER (stmt));
20534 add_AT_lbl_id (die, DW_AT_entry_pc, label);
20537 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
20539 chain = BLOCK_FRAGMENT_CHAIN (stmt);
20542 add_ranges (chain);
20543 chain = BLOCK_FRAGMENT_CHAIN (chain);
20550 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
20551 BLOCK_NUMBER (stmt));
20552 add_AT_lbl_id (die, DW_AT_low_pc, label);
20553 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
20554 BLOCK_NUMBER (stmt));
20555 add_AT_lbl_id (die, DW_AT_high_pc, label);
20559 /* Generate a DIE for a lexical block. */
20562 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
20564 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
20566 if (call_arg_locations)
20568 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
20569 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
20570 BLOCK_NUMBER (stmt) + 1);
20571 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
20574 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
20575 add_high_low_attributes (stmt, stmt_die);
20577 decls_for_scope (stmt, stmt_die, depth);
20580 /* Generate a DIE for an inlined subprogram. */
20583 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
20587 /* The instance of function that is effectively being inlined shall not
20589 gcc_assert (! BLOCK_ABSTRACT (stmt));
20591 decl = block_ultimate_origin (stmt);
20593 /* Emit info for the abstract instance first, if we haven't yet. We
20594 must emit this even if the block is abstract, otherwise when we
20595 emit the block below (or elsewhere), we may end up trying to emit
20596 a die whose origin die hasn't been emitted, and crashing. */
20597 dwarf2out_abstract_function (decl);
20599 if (! BLOCK_ABSTRACT (stmt))
20601 dw_die_ref subr_die
20602 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
20604 if (call_arg_locations)
20606 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
20607 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
20608 BLOCK_NUMBER (stmt) + 1);
20609 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
20611 add_abstract_origin_attribute (subr_die, decl);
20612 if (TREE_ASM_WRITTEN (stmt))
20613 add_high_low_attributes (stmt, subr_die);
20614 add_call_src_coords_attributes (stmt, subr_die);
20616 decls_for_scope (stmt, subr_die, depth);
20617 current_function_has_inlines = 1;
20621 /* Generate a DIE for a field in a record, or structure. */
20624 gen_field_die (tree decl, dw_die_ref context_die)
20626 dw_die_ref decl_die;
20628 if (TREE_TYPE (decl) == error_mark_node)
20631 decl_die = new_die (DW_TAG_member, context_die, decl);
20632 add_name_and_src_coords_attributes (decl_die, decl);
20633 add_type_attribute (decl_die, member_declared_type (decl),
20634 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
20637 if (DECL_BIT_FIELD_TYPE (decl))
20639 add_byte_size_attribute (decl_die, decl);
20640 add_bit_size_attribute (decl_die, decl);
20641 add_bit_offset_attribute (decl_die, decl);
20644 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
20645 add_data_member_location_attribute (decl_die, decl);
20647 if (DECL_ARTIFICIAL (decl))
20648 add_AT_flag (decl_die, DW_AT_artificial, 1);
20650 add_accessibility_attribute (decl_die, decl);
20652 /* Equate decl number to die, so that we can look up this decl later on. */
20653 equate_decl_number_to_die (decl, decl_die);
20657 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20658 Use modified_type_die instead.
20659 We keep this code here just in case these types of DIEs may be needed to
20660 represent certain things in other languages (e.g. Pascal) someday. */
20663 gen_pointer_type_die (tree type, dw_die_ref context_die)
20666 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20668 equate_type_number_to_die (type, ptr_die);
20669 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20670 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20673 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20674 Use modified_type_die instead.
20675 We keep this code here just in case these types of DIEs may be needed to
20676 represent certain things in other languages (e.g. Pascal) someday. */
20679 gen_reference_type_die (tree type, dw_die_ref context_die)
20681 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20683 if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
20684 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20686 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20688 equate_type_number_to_die (type, ref_die);
20689 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
20690 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20694 /* Generate a DIE for a pointer to a member type. */
20697 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20700 = new_die (DW_TAG_ptr_to_member_type,
20701 scope_die_for (type, context_die), type);
20703 equate_type_number_to_die (type, ptr_die);
20704 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20705 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20706 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20709 /* Generate the DIE for the compilation unit. */
20712 gen_compile_unit_die (const char *filename)
20715 char producer[250];
20716 const char *language_string = lang_hooks.name;
20719 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20723 add_name_attribute (die, filename);
20724 /* Don't add cwd for <built-in>. */
20725 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20726 add_comp_dir_attribute (die);
20729 sprintf (producer, "%s %s", language_string, version_string);
20731 #ifdef MIPS_DEBUGGING_INFO
20732 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20733 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20734 not appear in the producer string, the debugger reaches the conclusion
20735 that the object file is stripped and has no debugging information.
20736 To get the MIPS/SGI debugger to believe that there is debugging
20737 information in the object file, we add a -g to the producer string. */
20738 if (debug_info_level > DINFO_LEVEL_TERSE)
20739 strcat (producer, " -g");
20742 add_AT_string (die, DW_AT_producer, producer);
20744 /* If our producer is LTO try to figure out a common language to use
20745 from the global list of translation units. */
20746 if (strcmp (language_string, "GNU GIMPLE") == 0)
20750 const char *common_lang = NULL;
20752 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
20754 if (!TRANSLATION_UNIT_LANGUAGE (t))
20757 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20758 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20760 else if (strncmp (common_lang, "GNU C", 5) == 0
20761 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20762 /* Mixing C and C++ is ok, use C++ in that case. */
20763 common_lang = "GNU C++";
20766 /* Fall back to C. */
20767 common_lang = NULL;
20773 language_string = common_lang;
20776 language = DW_LANG_C89;
20777 if (strcmp (language_string, "GNU C++") == 0)
20778 language = DW_LANG_C_plus_plus;
20779 else if (strcmp (language_string, "GNU F77") == 0)
20780 language = DW_LANG_Fortran77;
20781 else if (strcmp (language_string, "GNU Pascal") == 0)
20782 language = DW_LANG_Pascal83;
20783 else if (dwarf_version >= 3 || !dwarf_strict)
20785 if (strcmp (language_string, "GNU Ada") == 0)
20786 language = DW_LANG_Ada95;
20787 else if (strcmp (language_string, "GNU Fortran") == 0)
20788 language = DW_LANG_Fortran95;
20789 else if (strcmp (language_string, "GNU Java") == 0)
20790 language = DW_LANG_Java;
20791 else if (strcmp (language_string, "GNU Objective-C") == 0)
20792 language = DW_LANG_ObjC;
20793 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20794 language = DW_LANG_ObjC_plus_plus;
20797 add_AT_unsigned (die, DW_AT_language, language);
20801 case DW_LANG_Fortran77:
20802 case DW_LANG_Fortran90:
20803 case DW_LANG_Fortran95:
20804 /* Fortran has case insensitive identifiers and the front-end
20805 lowercases everything. */
20806 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20809 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20815 /* Generate the DIE for a base class. */
20818 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20820 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20822 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
20823 add_data_member_location_attribute (die, binfo);
20825 if (BINFO_VIRTUAL_P (binfo))
20826 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20828 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20829 children, otherwise the default is DW_ACCESS_public. In DWARF2
20830 the default has always been DW_ACCESS_private. */
20831 if (access == access_public_node)
20833 if (dwarf_version == 2
20834 || context_die->die_tag == DW_TAG_class_type)
20835 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20837 else if (access == access_protected_node)
20838 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20839 else if (dwarf_version > 2
20840 && context_die->die_tag != DW_TAG_class_type)
20841 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20844 /* Generate a DIE for a class member. */
20847 gen_member_die (tree type, dw_die_ref context_die)
20850 tree binfo = TYPE_BINFO (type);
20853 /* If this is not an incomplete type, output descriptions of each of its
20854 members. Note that as we output the DIEs necessary to represent the
20855 members of this record or union type, we will also be trying to output
20856 DIEs to represent the *types* of those members. However the `type'
20857 function (above) will specifically avoid generating type DIEs for member
20858 types *within* the list of member DIEs for this (containing) type except
20859 for those types (of members) which are explicitly marked as also being
20860 members of this (containing) type themselves. The g++ front- end can
20861 force any given type to be treated as a member of some other (containing)
20862 type by setting the TYPE_CONTEXT of the given (member) type to point to
20863 the TREE node representing the appropriate (containing) type. */
20865 /* First output info about the base classes. */
20868 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
20872 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20873 gen_inheritance_die (base,
20874 (accesses ? VEC_index (tree, accesses, i)
20875 : access_public_node), context_die);
20878 /* Now output info about the data members and type members. */
20879 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20881 /* If we thought we were generating minimal debug info for TYPE
20882 and then changed our minds, some of the member declarations
20883 may have already been defined. Don't define them again, but
20884 do put them in the right order. */
20886 child = lookup_decl_die (member);
20888 splice_child_die (context_die, child);
20890 gen_decl_die (member, NULL, context_die);
20893 /* Now output info about the function members (if any). */
20894 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20896 /* Don't include clones in the member list. */
20897 if (DECL_ABSTRACT_ORIGIN (member))
20900 child = lookup_decl_die (member);
20902 splice_child_die (context_die, child);
20904 gen_decl_die (member, NULL, context_die);
20908 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20909 is set, we pretend that the type was never defined, so we only get the
20910 member DIEs needed by later specification DIEs. */
20913 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20914 enum debug_info_usage usage)
20916 dw_die_ref type_die = lookup_type_die (type);
20917 dw_die_ref scope_die = 0;
20919 int complete = (TYPE_SIZE (type)
20920 && (! TYPE_STUB_DECL (type)
20921 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20922 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20923 complete = complete && should_emit_struct_debug (type, usage);
20925 if (type_die && ! complete)
20928 if (TYPE_CONTEXT (type) != NULL_TREE
20929 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20930 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20933 scope_die = scope_die_for (type, context_die);
20935 if (! type_die || (nested && is_cu_die (scope_die)))
20936 /* First occurrence of type or toplevel definition of nested class. */
20938 dw_die_ref old_die = type_die;
20940 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20941 ? record_type_tag (type) : DW_TAG_union_type,
20943 equate_type_number_to_die (type, type_die);
20945 add_AT_specification (type_die, old_die);
20948 add_name_attribute (type_die, type_tag (type));
20949 add_gnat_descriptive_type_attribute (type_die, type, context_die);
20953 remove_AT (type_die, DW_AT_declaration);
20955 /* Generate child dies for template paramaters. */
20956 if (debug_info_level > DINFO_LEVEL_TERSE
20957 && COMPLETE_TYPE_P (type))
20958 schedule_generic_params_dies_gen (type);
20960 /* If this type has been completed, then give it a byte_size attribute and
20961 then give a list of members. */
20962 if (complete && !ns_decl)
20964 /* Prevent infinite recursion in cases where the type of some member of
20965 this type is expressed in terms of this type itself. */
20966 TREE_ASM_WRITTEN (type) = 1;
20967 add_byte_size_attribute (type_die, type);
20968 if (TYPE_STUB_DECL (type) != NULL_TREE)
20970 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20971 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20974 /* If the first reference to this type was as the return type of an
20975 inline function, then it may not have a parent. Fix this now. */
20976 if (type_die->die_parent == NULL)
20977 add_child_die (scope_die, type_die);
20979 push_decl_scope (type);
20980 gen_member_die (type, type_die);
20983 /* GNU extension: Record what type our vtable lives in. */
20984 if (TYPE_VFIELD (type))
20986 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20988 gen_type_die (vtype, context_die);
20989 add_AT_die_ref (type_die, DW_AT_containing_type,
20990 lookup_type_die (vtype));
20995 add_AT_flag (type_die, DW_AT_declaration, 1);
20997 /* We don't need to do this for function-local types. */
20998 if (TYPE_STUB_DECL (type)
20999 && ! decl_function_context (TYPE_STUB_DECL (type)))
21000 VEC_safe_push (tree, gc, incomplete_types, type);
21003 if (get_AT (type_die, DW_AT_name))
21004 add_pubtype (type, type_die);
21007 /* Generate a DIE for a subroutine _type_. */
21010 gen_subroutine_type_die (tree type, dw_die_ref context_die)
21012 tree return_type = TREE_TYPE (type);
21013 dw_die_ref subr_die
21014 = new_die (DW_TAG_subroutine_type,
21015 scope_die_for (type, context_die), type);
21017 equate_type_number_to_die (type, subr_die);
21018 add_prototyped_attribute (subr_die, type);
21019 add_type_attribute (subr_die, return_type, 0, 0, context_die);
21020 gen_formal_types_die (type, subr_die);
21022 if (get_AT (subr_die, DW_AT_name))
21023 add_pubtype (type, subr_die);
21026 /* Generate a DIE for a type definition. */
21029 gen_typedef_die (tree decl, dw_die_ref context_die)
21031 dw_die_ref type_die;
21034 if (TREE_ASM_WRITTEN (decl))
21037 TREE_ASM_WRITTEN (decl) = 1;
21038 type_die = new_die (DW_TAG_typedef, context_die, decl);
21039 origin = decl_ultimate_origin (decl);
21040 if (origin != NULL)
21041 add_abstract_origin_attribute (type_die, origin);
21046 add_name_and_src_coords_attributes (type_die, decl);
21047 if (DECL_ORIGINAL_TYPE (decl))
21049 type = DECL_ORIGINAL_TYPE (decl);
21051 gcc_assert (type != TREE_TYPE (decl));
21052 equate_type_number_to_die (TREE_TYPE (decl), type_die);
21056 type = TREE_TYPE (decl);
21058 if (is_naming_typedef_decl (TYPE_NAME (type)))
21060 /* Here, we are in the case of decl being a typedef naming
21061 an anonymous type, e.g:
21062 typedef struct {...} foo;
21063 In that case TREE_TYPE (decl) is not a typedef variant
21064 type and TYPE_NAME of the anonymous type is set to the
21065 TYPE_DECL of the typedef. This construct is emitted by
21068 TYPE is the anonymous struct named by the typedef
21069 DECL. As we need the DW_AT_type attribute of the
21070 DW_TAG_typedef to point to the DIE of TYPE, let's
21071 generate that DIE right away. add_type_attribute
21072 called below will then pick (via lookup_type_die) that
21073 anonymous struct DIE. */
21074 if (!TREE_ASM_WRITTEN (type))
21075 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
21077 /* This is a GNU Extension. We are adding a
21078 DW_AT_linkage_name attribute to the DIE of the
21079 anonymous struct TYPE. The value of that attribute
21080 is the name of the typedef decl naming the anonymous
21081 struct. This greatly eases the work of consumers of
21082 this debug info. */
21083 add_linkage_attr (lookup_type_die (type), decl);
21087 add_type_attribute (type_die, type, TREE_READONLY (decl),
21088 TREE_THIS_VOLATILE (decl), context_die);
21090 if (is_naming_typedef_decl (decl))
21091 /* We want that all subsequent calls to lookup_type_die with
21092 TYPE in argument yield the DW_TAG_typedef we have just
21094 equate_type_number_to_die (type, type_die);
21096 add_accessibility_attribute (type_die, decl);
21099 if (DECL_ABSTRACT (decl))
21100 equate_decl_number_to_die (decl, type_die);
21102 if (get_AT (type_die, DW_AT_name))
21103 add_pubtype (decl, type_die);
21106 /* Generate a DIE for a struct, class, enum or union type. */
21109 gen_tagged_type_die (tree type,
21110 dw_die_ref context_die,
21111 enum debug_info_usage usage)
21115 if (type == NULL_TREE
21116 || !is_tagged_type (type))
21119 /* If this is a nested type whose containing class hasn't been written
21120 out yet, writing it out will cover this one, too. This does not apply
21121 to instantiations of member class templates; they need to be added to
21122 the containing class as they are generated. FIXME: This hurts the
21123 idea of combining type decls from multiple TUs, since we can't predict
21124 what set of template instantiations we'll get. */
21125 if (TYPE_CONTEXT (type)
21126 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
21127 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
21129 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
21131 if (TREE_ASM_WRITTEN (type))
21134 /* If that failed, attach ourselves to the stub. */
21135 push_decl_scope (TYPE_CONTEXT (type));
21136 context_die = lookup_type_die (TYPE_CONTEXT (type));
21139 else if (TYPE_CONTEXT (type) != NULL_TREE
21140 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
21142 /* If this type is local to a function that hasn't been written
21143 out yet, use a NULL context for now; it will be fixed up in
21144 decls_for_scope. */
21145 context_die = lookup_decl_die (TYPE_CONTEXT (type));
21146 /* A declaration DIE doesn't count; nested types need to go in the
21148 if (context_die && is_declaration_die (context_die))
21149 context_die = NULL;
21154 context_die = declare_in_namespace (type, context_die);
21158 if (TREE_CODE (type) == ENUMERAL_TYPE)
21160 /* This might have been written out by the call to
21161 declare_in_namespace. */
21162 if (!TREE_ASM_WRITTEN (type))
21163 gen_enumeration_type_die (type, context_die);
21166 gen_struct_or_union_type_die (type, context_die, usage);
21171 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
21172 it up if it is ever completed. gen_*_type_die will set it for us
21173 when appropriate. */
21176 /* Generate a type description DIE. */
21179 gen_type_die_with_usage (tree type, dw_die_ref context_die,
21180 enum debug_info_usage usage)
21182 struct array_descr_info info;
21184 if (type == NULL_TREE || type == error_mark_node)
21187 if (TYPE_NAME (type) != NULL_TREE
21188 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
21189 && is_redundant_typedef (TYPE_NAME (type))
21190 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
21191 /* The DECL of this type is a typedef we don't want to emit debug
21192 info for but we want debug info for its underlying typedef.
21193 This can happen for e.g, the injected-class-name of a C++
21195 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
21197 /* If TYPE is a typedef type variant, let's generate debug info
21198 for the parent typedef which TYPE is a type of. */
21199 if (typedef_variant_p (type))
21201 if (TREE_ASM_WRITTEN (type))
21204 /* Prevent broken recursion; we can't hand off to the same type. */
21205 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
21207 /* Use the DIE of the containing namespace as the parent DIE of
21208 the type description DIE we want to generate. */
21209 if (DECL_CONTEXT (TYPE_NAME (type))
21210 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
21211 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
21213 TREE_ASM_WRITTEN (type) = 1;
21215 gen_decl_die (TYPE_NAME (type), NULL, context_die);
21219 /* If type is an anonymous tagged type named by a typedef, let's
21220 generate debug info for the typedef. */
21221 if (is_naming_typedef_decl (TYPE_NAME (type)))
21223 /* Use the DIE of the containing namespace as the parent DIE of
21224 the type description DIE we want to generate. */
21225 if (DECL_CONTEXT (TYPE_NAME (type))
21226 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
21227 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
21229 gen_decl_die (TYPE_NAME (type), NULL, context_die);
21233 /* If this is an array type with hidden descriptor, handle it first. */
21234 if (!TREE_ASM_WRITTEN (type)
21235 && lang_hooks.types.get_array_descr_info
21236 && lang_hooks.types.get_array_descr_info (type, &info)
21237 && (dwarf_version >= 3 || !dwarf_strict))
21239 gen_descr_array_type_die (type, &info, context_die);
21240 TREE_ASM_WRITTEN (type) = 1;
21244 /* We are going to output a DIE to represent the unqualified version
21245 of this type (i.e. without any const or volatile qualifiers) so
21246 get the main variant (i.e. the unqualified version) of this type
21247 now. (Vectors are special because the debugging info is in the
21248 cloned type itself). */
21249 if (TREE_CODE (type) != VECTOR_TYPE)
21250 type = type_main_variant (type);
21252 if (TREE_ASM_WRITTEN (type))
21255 switch (TREE_CODE (type))
21261 case REFERENCE_TYPE:
21262 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
21263 ensures that the gen_type_die recursion will terminate even if the
21264 type is recursive. Recursive types are possible in Ada. */
21265 /* ??? We could perhaps do this for all types before the switch
21267 TREE_ASM_WRITTEN (type) = 1;
21269 /* For these types, all that is required is that we output a DIE (or a
21270 set of DIEs) to represent the "basis" type. */
21271 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21272 DINFO_USAGE_IND_USE);
21276 /* This code is used for C++ pointer-to-data-member types.
21277 Output a description of the relevant class type. */
21278 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
21279 DINFO_USAGE_IND_USE);
21281 /* Output a description of the type of the object pointed to. */
21282 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21283 DINFO_USAGE_IND_USE);
21285 /* Now output a DIE to represent this pointer-to-data-member type
21287 gen_ptr_to_mbr_type_die (type, context_die);
21290 case FUNCTION_TYPE:
21291 /* Force out return type (in case it wasn't forced out already). */
21292 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21293 DINFO_USAGE_DIR_USE);
21294 gen_subroutine_type_die (type, context_die);
21298 /* Force out return type (in case it wasn't forced out already). */
21299 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21300 DINFO_USAGE_DIR_USE);
21301 gen_subroutine_type_die (type, context_die);
21305 gen_array_type_die (type, context_die);
21309 gen_array_type_die (type, context_die);
21312 case ENUMERAL_TYPE:
21315 case QUAL_UNION_TYPE:
21316 gen_tagged_type_die (type, context_die, usage);
21322 case FIXED_POINT_TYPE:
21325 /* No DIEs needed for fundamental types. */
21330 /* Just use DW_TAG_unspecified_type. */
21332 dw_die_ref type_die = lookup_type_die (type);
21333 if (type_die == NULL)
21335 tree name = TYPE_NAME (type);
21336 if (TREE_CODE (name) == TYPE_DECL)
21337 name = DECL_NAME (name);
21338 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
21339 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
21340 equate_type_number_to_die (type, type_die);
21346 gcc_unreachable ();
21349 TREE_ASM_WRITTEN (type) = 1;
21353 gen_type_die (tree type, dw_die_ref context_die)
21355 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
21358 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
21359 things which are local to the given block. */
21362 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
21364 int must_output_die = 0;
21367 /* Ignore blocks that are NULL. */
21368 if (stmt == NULL_TREE)
21371 inlined_func = inlined_function_outer_scope_p (stmt);
21373 /* If the block is one fragment of a non-contiguous block, do not
21374 process the variables, since they will have been done by the
21375 origin block. Do process subblocks. */
21376 if (BLOCK_FRAGMENT_ORIGIN (stmt))
21380 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
21381 gen_block_die (sub, context_die, depth + 1);
21386 /* Determine if we need to output any Dwarf DIEs at all to represent this
21389 /* The outer scopes for inlinings *must* always be represented. We
21390 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
21391 must_output_die = 1;
21394 /* Determine if this block directly contains any "significant"
21395 local declarations which we will need to output DIEs for. */
21396 if (debug_info_level > DINFO_LEVEL_TERSE)
21397 /* We are not in terse mode so *any* local declaration counts
21398 as being a "significant" one. */
21399 must_output_die = ((BLOCK_VARS (stmt) != NULL
21400 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
21401 && (TREE_USED (stmt)
21402 || TREE_ASM_WRITTEN (stmt)
21403 || BLOCK_ABSTRACT (stmt)));
21404 else if ((TREE_USED (stmt)
21405 || TREE_ASM_WRITTEN (stmt)
21406 || BLOCK_ABSTRACT (stmt))
21407 && !dwarf2out_ignore_block (stmt))
21408 must_output_die = 1;
21411 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
21412 DIE for any block which contains no significant local declarations at
21413 all. Rather, in such cases we just call `decls_for_scope' so that any
21414 needed Dwarf info for any sub-blocks will get properly generated. Note
21415 that in terse mode, our definition of what constitutes a "significant"
21416 local declaration gets restricted to include only inlined function
21417 instances and local (nested) function definitions. */
21418 if (must_output_die)
21422 /* If STMT block is abstract, that means we have been called
21423 indirectly from dwarf2out_abstract_function.
21424 That function rightfully marks the descendent blocks (of
21425 the abstract function it is dealing with) as being abstract,
21426 precisely to prevent us from emitting any
21427 DW_TAG_inlined_subroutine DIE as a descendent
21428 of an abstract function instance. So in that case, we should
21429 not call gen_inlined_subroutine_die.
21431 Later though, when cgraph asks dwarf2out to emit info
21432 for the concrete instance of the function decl into which
21433 the concrete instance of STMT got inlined, the later will lead
21434 to the generation of a DW_TAG_inlined_subroutine DIE. */
21435 if (! BLOCK_ABSTRACT (stmt))
21436 gen_inlined_subroutine_die (stmt, context_die, depth);
21439 gen_lexical_block_die (stmt, context_die, depth);
21442 decls_for_scope (stmt, context_die, depth);
21445 /* Process variable DECL (or variable with origin ORIGIN) within
21446 block STMT and add it to CONTEXT_DIE. */
21448 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
21451 tree decl_or_origin = decl ? decl : origin;
21453 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
21454 die = lookup_decl_die (decl_or_origin);
21455 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
21456 && TYPE_DECL_IS_STUB (decl_or_origin))
21457 die = lookup_type_die (TREE_TYPE (decl_or_origin));
21461 if (die != NULL && die->die_parent == NULL)
21462 add_child_die (context_die, die);
21463 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
21464 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
21465 stmt, context_die);
21467 gen_decl_die (decl, origin, context_die);
21470 /* Generate all of the decls declared within a given scope and (recursively)
21471 all of its sub-blocks. */
21474 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
21480 /* Ignore NULL blocks. */
21481 if (stmt == NULL_TREE)
21484 /* Output the DIEs to represent all of the data objects and typedefs
21485 declared directly within this block but not within any nested
21486 sub-blocks. Also, nested function and tag DIEs have been
21487 generated with a parent of NULL; fix that up now. */
21488 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
21489 process_scope_var (stmt, decl, NULL_TREE, context_die);
21490 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
21491 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
21494 /* If we're at -g1, we're not interested in subblocks. */
21495 if (debug_info_level <= DINFO_LEVEL_TERSE)
21498 /* Output the DIEs to represent all sub-blocks (and the items declared
21499 therein) of this block. */
21500 for (subblocks = BLOCK_SUBBLOCKS (stmt);
21502 subblocks = BLOCK_CHAIN (subblocks))
21503 gen_block_die (subblocks, context_die, depth + 1);
21506 /* Is this a typedef we can avoid emitting? */
21509 is_redundant_typedef (const_tree decl)
21511 if (TYPE_DECL_IS_STUB (decl))
21514 if (DECL_ARTIFICIAL (decl)
21515 && DECL_CONTEXT (decl)
21516 && is_tagged_type (DECL_CONTEXT (decl))
21517 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
21518 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
21519 /* Also ignore the artificial member typedef for the class name. */
21525 /* Return TRUE if TYPE is a typedef that names a type for linkage
21526 purposes. This kind of typedefs is produced by the C++ FE for
21529 typedef struct {...} foo;
21531 In that case, there is no typedef variant type produced for foo.
21532 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
21536 is_naming_typedef_decl (const_tree decl)
21538 if (decl == NULL_TREE
21539 || TREE_CODE (decl) != TYPE_DECL
21540 || !is_tagged_type (TREE_TYPE (decl))
21541 || DECL_IS_BUILTIN (decl)
21542 || is_redundant_typedef (decl)
21543 /* It looks like Ada produces TYPE_DECLs that are very similar
21544 to C++ naming typedefs but that have different
21545 semantics. Let's be specific to c++ for now. */
21549 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
21550 && TYPE_NAME (TREE_TYPE (decl)) == decl
21551 && (TYPE_STUB_DECL (TREE_TYPE (decl))
21552 != TYPE_NAME (TREE_TYPE (decl))));
21555 /* Returns the DIE for a context. */
21557 static inline dw_die_ref
21558 get_context_die (tree context)
21562 /* Find die that represents this context. */
21563 if (TYPE_P (context))
21565 context = TYPE_MAIN_VARIANT (context);
21566 return strip_naming_typedef (context, force_type_die (context));
21569 return force_decl_die (context);
21571 return comp_unit_die ();
21574 /* Returns the DIE for decl. A DIE will always be returned. */
21577 force_decl_die (tree decl)
21579 dw_die_ref decl_die;
21580 unsigned saved_external_flag;
21581 tree save_fn = NULL_TREE;
21582 decl_die = lookup_decl_die (decl);
21585 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
21587 decl_die = lookup_decl_die (decl);
21591 switch (TREE_CODE (decl))
21593 case FUNCTION_DECL:
21594 /* Clear current_function_decl, so that gen_subprogram_die thinks
21595 that this is a declaration. At this point, we just want to force
21596 declaration die. */
21597 save_fn = current_function_decl;
21598 current_function_decl = NULL_TREE;
21599 gen_subprogram_die (decl, context_die);
21600 current_function_decl = save_fn;
21604 /* Set external flag to force declaration die. Restore it after
21605 gen_decl_die() call. */
21606 saved_external_flag = DECL_EXTERNAL (decl);
21607 DECL_EXTERNAL (decl) = 1;
21608 gen_decl_die (decl, NULL, context_die);
21609 DECL_EXTERNAL (decl) = saved_external_flag;
21612 case NAMESPACE_DECL:
21613 if (dwarf_version >= 3 || !dwarf_strict)
21614 dwarf2out_decl (decl);
21616 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21617 decl_die = comp_unit_die ();
21620 case TRANSLATION_UNIT_DECL:
21621 decl_die = comp_unit_die ();
21625 gcc_unreachable ();
21628 /* We should be able to find the DIE now. */
21630 decl_die = lookup_decl_die (decl);
21631 gcc_assert (decl_die);
21637 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21638 always returned. */
21641 force_type_die (tree type)
21643 dw_die_ref type_die;
21645 type_die = lookup_type_die (type);
21648 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21650 type_die = modified_type_die (type, TYPE_READONLY (type),
21651 TYPE_VOLATILE (type), context_die);
21652 gcc_assert (type_die);
21657 /* Force out any required namespaces to be able to output DECL,
21658 and return the new context_die for it, if it's changed. */
21661 setup_namespace_context (tree thing, dw_die_ref context_die)
21663 tree context = (DECL_P (thing)
21664 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21665 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21666 /* Force out the namespace. */
21667 context_die = force_decl_die (context);
21669 return context_die;
21672 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21673 type) within its namespace, if appropriate.
21675 For compatibility with older debuggers, namespace DIEs only contain
21676 declarations; all definitions are emitted at CU scope. */
21679 declare_in_namespace (tree thing, dw_die_ref context_die)
21681 dw_die_ref ns_context;
21683 if (debug_info_level <= DINFO_LEVEL_TERSE)
21684 return context_die;
21686 /* If this decl is from an inlined function, then don't try to emit it in its
21687 namespace, as we will get confused. It would have already been emitted
21688 when the abstract instance of the inline function was emitted anyways. */
21689 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21690 return context_die;
21692 ns_context = setup_namespace_context (thing, context_die);
21694 if (ns_context != context_die)
21698 if (DECL_P (thing))
21699 gen_decl_die (thing, NULL, ns_context);
21701 gen_type_die (thing, ns_context);
21703 return context_die;
21706 /* Generate a DIE for a namespace or namespace alias. */
21709 gen_namespace_die (tree decl, dw_die_ref context_die)
21711 dw_die_ref namespace_die;
21713 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21714 they are an alias of. */
21715 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21717 /* Output a real namespace or module. */
21718 context_die = setup_namespace_context (decl, comp_unit_die ());
21719 namespace_die = new_die (is_fortran ()
21720 ? DW_TAG_module : DW_TAG_namespace,
21721 context_die, decl);
21722 /* For Fortran modules defined in different CU don't add src coords. */
21723 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21725 const char *name = dwarf2_name (decl, 0);
21727 add_name_attribute (namespace_die, name);
21730 add_name_and_src_coords_attributes (namespace_die, decl);
21731 if (DECL_EXTERNAL (decl))
21732 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21733 equate_decl_number_to_die (decl, namespace_die);
21737 /* Output a namespace alias. */
21739 /* Force out the namespace we are an alias of, if necessary. */
21740 dw_die_ref origin_die
21741 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21743 if (DECL_FILE_SCOPE_P (decl)
21744 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21745 context_die = setup_namespace_context (decl, comp_unit_die ());
21746 /* Now create the namespace alias DIE. */
21747 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21748 add_name_and_src_coords_attributes (namespace_die, decl);
21749 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21750 equate_decl_number_to_die (decl, namespace_die);
21754 /* Generate Dwarf debug information for a decl described by DECL.
21755 The return value is currently only meaningful for PARM_DECLs,
21756 for all other decls it returns NULL. */
21759 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21761 tree decl_or_origin = decl ? decl : origin;
21762 tree class_origin = NULL, ultimate_origin;
21764 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21767 switch (TREE_CODE (decl_or_origin))
21773 if (!is_fortran () && !is_ada ())
21775 /* The individual enumerators of an enum type get output when we output
21776 the Dwarf representation of the relevant enum type itself. */
21780 /* Emit its type. */
21781 gen_type_die (TREE_TYPE (decl), context_die);
21783 /* And its containing namespace. */
21784 context_die = declare_in_namespace (decl, context_die);
21786 gen_const_die (decl, context_die);
21789 case FUNCTION_DECL:
21790 /* Don't output any DIEs to represent mere function declarations,
21791 unless they are class members or explicit block externs. */
21792 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21793 && DECL_FILE_SCOPE_P (decl_or_origin)
21794 && (current_function_decl == NULL_TREE
21795 || DECL_ARTIFICIAL (decl_or_origin)))
21800 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21801 on local redeclarations of global functions. That seems broken. */
21802 if (current_function_decl != decl)
21803 /* This is only a declaration. */;
21806 /* If we're emitting a clone, emit info for the abstract instance. */
21807 if (origin || DECL_ORIGIN (decl) != decl)
21808 dwarf2out_abstract_function (origin
21809 ? DECL_ORIGIN (origin)
21810 : DECL_ABSTRACT_ORIGIN (decl));
21812 /* If we're emitting an out-of-line copy of an inline function,
21813 emit info for the abstract instance and set up to refer to it. */
21814 else if (cgraph_function_possibly_inlined_p (decl)
21815 && ! DECL_ABSTRACT (decl)
21816 && ! class_or_namespace_scope_p (context_die)
21817 /* dwarf2out_abstract_function won't emit a die if this is just
21818 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21819 that case, because that works only if we have a die. */
21820 && DECL_INITIAL (decl) != NULL_TREE)
21822 dwarf2out_abstract_function (decl);
21823 set_decl_origin_self (decl);
21826 /* Otherwise we're emitting the primary DIE for this decl. */
21827 else if (debug_info_level > DINFO_LEVEL_TERSE)
21829 /* Before we describe the FUNCTION_DECL itself, make sure that we
21830 have its containing type. */
21832 origin = decl_class_context (decl);
21833 if (origin != NULL_TREE)
21834 gen_type_die (origin, context_die);
21836 /* And its return type. */
21837 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21839 /* And its virtual context. */
21840 if (DECL_VINDEX (decl) != NULL_TREE)
21841 gen_type_die (DECL_CONTEXT (decl), context_die);
21843 /* Make sure we have a member DIE for decl. */
21844 if (origin != NULL_TREE)
21845 gen_type_die_for_member (origin, decl, context_die);
21847 /* And its containing namespace. */
21848 context_die = declare_in_namespace (decl, context_die);
21851 /* Now output a DIE to represent the function itself. */
21853 gen_subprogram_die (decl, context_die);
21857 /* If we are in terse mode, don't generate any DIEs to represent any
21858 actual typedefs. */
21859 if (debug_info_level <= DINFO_LEVEL_TERSE)
21862 /* In the special case of a TYPE_DECL node representing the declaration
21863 of some type tag, if the given TYPE_DECL is marked as having been
21864 instantiated from some other (original) TYPE_DECL node (e.g. one which
21865 was generated within the original definition of an inline function) we
21866 used to generate a special (abbreviated) DW_TAG_structure_type,
21867 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21868 should be actually referencing those DIEs, as variable DIEs with that
21869 type would be emitted already in the abstract origin, so it was always
21870 removed during unused type prunning. Don't add anything in this
21872 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21875 if (is_redundant_typedef (decl))
21876 gen_type_die (TREE_TYPE (decl), context_die);
21878 /* Output a DIE to represent the typedef itself. */
21879 gen_typedef_die (decl, context_die);
21883 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21884 gen_label_die (decl, context_die);
21889 /* If we are in terse mode, don't generate any DIEs to represent any
21890 variable declarations or definitions. */
21891 if (debug_info_level <= DINFO_LEVEL_TERSE)
21894 /* Output any DIEs that are needed to specify the type of this data
21896 if (decl_by_reference_p (decl_or_origin))
21897 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21899 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21901 /* And its containing type. */
21902 class_origin = decl_class_context (decl_or_origin);
21903 if (class_origin != NULL_TREE)
21904 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21906 /* And its containing namespace. */
21907 context_die = declare_in_namespace (decl_or_origin, context_die);
21909 /* Now output the DIE to represent the data object itself. This gets
21910 complicated because of the possibility that the VAR_DECL really
21911 represents an inlined instance of a formal parameter for an inline
21913 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21914 if (ultimate_origin != NULL_TREE
21915 && TREE_CODE (ultimate_origin) == PARM_DECL)
21916 gen_formal_parameter_die (decl, origin,
21917 true /* Emit name attribute. */,
21920 gen_variable_die (decl, origin, context_die);
21924 /* Ignore the nameless fields that are used to skip bits but handle C++
21925 anonymous unions and structs. */
21926 if (DECL_NAME (decl) != NULL_TREE
21927 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21928 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21930 gen_type_die (member_declared_type (decl), context_die);
21931 gen_field_die (decl, context_die);
21936 if (DECL_BY_REFERENCE (decl_or_origin))
21937 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21939 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21940 return gen_formal_parameter_die (decl, origin,
21941 true /* Emit name attribute. */,
21944 case NAMESPACE_DECL:
21945 case IMPORTED_DECL:
21946 if (dwarf_version >= 3 || !dwarf_strict)
21947 gen_namespace_die (decl, context_die);
21951 /* Probably some frontend-internal decl. Assume we don't care. */
21952 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21959 /* Output debug information for global decl DECL. Called from toplev.c after
21960 compilation proper has finished. */
21963 dwarf2out_global_decl (tree decl)
21965 /* Output DWARF2 information for file-scope tentative data object
21966 declarations, file-scope (extern) function declarations (which
21967 had no corresponding body) and file-scope tagged type declarations
21968 and definitions which have not yet been forced out. */
21969 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
21970 dwarf2out_decl (decl);
21973 /* Output debug information for type decl DECL. Called from toplev.c
21974 and from language front ends (to record built-in types). */
21976 dwarf2out_type_decl (tree decl, int local)
21979 dwarf2out_decl (decl);
21982 /* Output debug information for imported module or decl DECL.
21983 NAME is non-NULL name in the lexical block if the decl has been renamed.
21984 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21985 that DECL belongs to.
21986 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21988 dwarf2out_imported_module_or_decl_1 (tree decl,
21990 tree lexical_block,
21991 dw_die_ref lexical_block_die)
21993 expanded_location xloc;
21994 dw_die_ref imported_die = NULL;
21995 dw_die_ref at_import_die;
21997 if (TREE_CODE (decl) == IMPORTED_DECL)
21999 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
22000 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
22004 xloc = expand_location (input_location);
22006 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
22008 at_import_die = force_type_die (TREE_TYPE (decl));
22009 /* For namespace N { typedef void T; } using N::T; base_type_die
22010 returns NULL, but DW_TAG_imported_declaration requires
22011 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
22012 if (!at_import_die)
22014 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
22015 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
22016 at_import_die = lookup_type_die (TREE_TYPE (decl));
22017 gcc_assert (at_import_die);
22022 at_import_die = lookup_decl_die (decl);
22023 if (!at_import_die)
22025 /* If we're trying to avoid duplicate debug info, we may not have
22026 emitted the member decl for this field. Emit it now. */
22027 if (TREE_CODE (decl) == FIELD_DECL)
22029 tree type = DECL_CONTEXT (decl);
22031 if (TYPE_CONTEXT (type)
22032 && TYPE_P (TYPE_CONTEXT (type))
22033 && !should_emit_struct_debug (TYPE_CONTEXT (type),
22034 DINFO_USAGE_DIR_USE))
22036 gen_type_die_for_member (type, decl,
22037 get_context_die (TYPE_CONTEXT (type)));
22039 at_import_die = force_decl_die (decl);
22043 if (TREE_CODE (decl) == NAMESPACE_DECL)
22045 if (dwarf_version >= 3 || !dwarf_strict)
22046 imported_die = new_die (DW_TAG_imported_module,
22053 imported_die = new_die (DW_TAG_imported_declaration,
22057 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
22058 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
22060 add_AT_string (imported_die, DW_AT_name,
22061 IDENTIFIER_POINTER (name));
22062 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
22065 /* Output debug information for imported module or decl DECL.
22066 NAME is non-NULL name in context if the decl has been renamed.
22067 CHILD is true if decl is one of the renamed decls as part of
22068 importing whole module. */
22071 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
22074 /* dw_die_ref at_import_die; */
22075 dw_die_ref scope_die;
22077 if (debug_info_level <= DINFO_LEVEL_TERSE)
22082 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
22083 We need decl DIE for reference and scope die. First, get DIE for the decl
22086 /* Get the scope die for decl context. Use comp_unit_die for global module
22087 or decl. If die is not found for non globals, force new die. */
22089 && TYPE_P (context)
22090 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
22093 if (!(dwarf_version >= 3 || !dwarf_strict))
22096 scope_die = get_context_die (context);
22100 gcc_assert (scope_die->die_child);
22101 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
22102 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
22103 scope_die = scope_die->die_child;
22106 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
22107 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
22111 /* Write the debugging output for DECL. */
22114 dwarf2out_decl (tree decl)
22116 dw_die_ref context_die = comp_unit_die ();
22118 switch (TREE_CODE (decl))
22123 case FUNCTION_DECL:
22124 /* What we would really like to do here is to filter out all mere
22125 file-scope declarations of file-scope functions which are never
22126 referenced later within this translation unit (and keep all of ones
22127 that *are* referenced later on) but we aren't clairvoyant, so we have
22128 no idea which functions will be referenced in the future (i.e. later
22129 on within the current translation unit). So here we just ignore all
22130 file-scope function declarations which are not also definitions. If
22131 and when the debugger needs to know something about these functions,
22132 it will have to hunt around and find the DWARF information associated
22133 with the definition of the function.
22135 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
22136 nodes represent definitions and which ones represent mere
22137 declarations. We have to check DECL_INITIAL instead. That's because
22138 the C front-end supports some weird semantics for "extern inline"
22139 function definitions. These can get inlined within the current
22140 translation unit (and thus, we need to generate Dwarf info for their
22141 abstract instances so that the Dwarf info for the concrete inlined
22142 instances can have something to refer to) but the compiler never
22143 generates any out-of-lines instances of such things (despite the fact
22144 that they *are* definitions).
22146 The important point is that the C front-end marks these "extern
22147 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
22148 them anyway. Note that the C++ front-end also plays some similar games
22149 for inline function definitions appearing within include files which
22150 also contain `#pragma interface' pragmas. */
22151 if (DECL_INITIAL (decl) == NULL_TREE)
22154 /* If we're a nested function, initially use a parent of NULL; if we're
22155 a plain function, this will be fixed up in decls_for_scope. If
22156 we're a method, it will be ignored, since we already have a DIE. */
22157 if (decl_function_context (decl)
22158 /* But if we're in terse mode, we don't care about scope. */
22159 && debug_info_level > DINFO_LEVEL_TERSE)
22160 context_die = NULL;
22164 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
22165 declaration and if the declaration was never even referenced from
22166 within this entire compilation unit. We suppress these DIEs in
22167 order to save space in the .debug section (by eliminating entries
22168 which are probably useless). Note that we must not suppress
22169 block-local extern declarations (whether used or not) because that
22170 would screw-up the debugger's name lookup mechanism and cause it to
22171 miss things which really ought to be in scope at a given point. */
22172 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
22175 /* For local statics lookup proper context die. */
22176 if (TREE_STATIC (decl) && decl_function_context (decl))
22177 context_die = lookup_decl_die (DECL_CONTEXT (decl));
22179 /* If we are in terse mode, don't generate any DIEs to represent any
22180 variable declarations or definitions. */
22181 if (debug_info_level <= DINFO_LEVEL_TERSE)
22186 if (debug_info_level <= DINFO_LEVEL_TERSE)
22188 if (!is_fortran () && !is_ada ())
22190 if (TREE_STATIC (decl) && decl_function_context (decl))
22191 context_die = lookup_decl_die (DECL_CONTEXT (decl));
22194 case NAMESPACE_DECL:
22195 case IMPORTED_DECL:
22196 if (debug_info_level <= DINFO_LEVEL_TERSE)
22198 if (lookup_decl_die (decl) != NULL)
22203 /* Don't emit stubs for types unless they are needed by other DIEs. */
22204 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
22207 /* Don't bother trying to generate any DIEs to represent any of the
22208 normal built-in types for the language we are compiling. */
22209 if (DECL_IS_BUILTIN (decl))
22212 /* If we are in terse mode, don't generate any DIEs for types. */
22213 if (debug_info_level <= DINFO_LEVEL_TERSE)
22216 /* If we're a function-scope tag, initially use a parent of NULL;
22217 this will be fixed up in decls_for_scope. */
22218 if (decl_function_context (decl))
22219 context_die = NULL;
22227 gen_decl_die (decl, NULL, context_die);
22230 /* Write the debugging output for DECL. */
22233 dwarf2out_function_decl (tree decl)
22235 dwarf2out_decl (decl);
22236 call_arg_locations = NULL;
22237 call_arg_loc_last = NULL;
22238 call_site_count = -1;
22239 tail_call_site_count = -1;
22240 VEC_free (dw_die_ref, heap, block_map);
22241 htab_empty (decl_loc_table);
22242 htab_empty (cached_dw_loc_list_table);
22245 /* Output a marker (i.e. a label) for the beginning of the generated code for
22246 a lexical block. */
22249 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
22250 unsigned int blocknum)
22252 switch_to_section (current_function_section ());
22253 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
22256 /* Output a marker (i.e. a label) for the end of the generated code for a
22260 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
22262 switch_to_section (current_function_section ());
22263 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
22266 /* Returns nonzero if it is appropriate not to emit any debugging
22267 information for BLOCK, because it doesn't contain any instructions.
22269 Don't allow this for blocks with nested functions or local classes
22270 as we would end up with orphans, and in the presence of scheduling
22271 we may end up calling them anyway. */
22274 dwarf2out_ignore_block (const_tree block)
22279 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
22280 if (TREE_CODE (decl) == FUNCTION_DECL
22281 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22283 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
22285 decl = BLOCK_NONLOCALIZED_VAR (block, i);
22286 if (TREE_CODE (decl) == FUNCTION_DECL
22287 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22294 /* Hash table routines for file_hash. */
22297 file_table_eq (const void *p1_p, const void *p2_p)
22299 const struct dwarf_file_data *const p1 =
22300 (const struct dwarf_file_data *) p1_p;
22301 const char *const p2 = (const char *) p2_p;
22302 return filename_cmp (p1->filename, p2) == 0;
22306 file_table_hash (const void *p_p)
22308 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
22309 return htab_hash_string (p->filename);
22312 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22313 dwarf2out.c) and return its "index". The index of each (known) filename is
22314 just a unique number which is associated with only that one filename. We
22315 need such numbers for the sake of generating labels (in the .debug_sfnames
22316 section) and references to those files numbers (in the .debug_srcinfo
22317 and.debug_macinfo sections). If the filename given as an argument is not
22318 found in our current list, add it to the list and assign it the next
22319 available unique index number. In order to speed up searches, we remember
22320 the index of the filename was looked up last. This handles the majority of
22323 static struct dwarf_file_data *
22324 lookup_filename (const char *file_name)
22327 struct dwarf_file_data * created;
22329 /* Check to see if the file name that was searched on the previous
22330 call matches this file name. If so, return the index. */
22331 if (file_table_last_lookup
22332 && (file_name == file_table_last_lookup->filename
22333 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
22334 return file_table_last_lookup;
22336 /* Didn't match the previous lookup, search the table. */
22337 slot = htab_find_slot_with_hash (file_table, file_name,
22338 htab_hash_string (file_name), INSERT);
22340 return (struct dwarf_file_data *) *slot;
22342 created = ggc_alloc_dwarf_file_data ();
22343 created->filename = file_name;
22344 created->emitted_number = 0;
22349 /* If the assembler will construct the file table, then translate the compiler
22350 internal file table number into the assembler file table number, and emit
22351 a .file directive if we haven't already emitted one yet. The file table
22352 numbers are different because we prune debug info for unused variables and
22353 types, which may include filenames. */
22356 maybe_emit_file (struct dwarf_file_data * fd)
22358 if (! fd->emitted_number)
22360 if (last_emitted_file)
22361 fd->emitted_number = last_emitted_file->emitted_number + 1;
22363 fd->emitted_number = 1;
22364 last_emitted_file = fd;
22366 if (DWARF2_ASM_LINE_DEBUG_INFO)
22368 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
22369 output_quoted_string (asm_out_file,
22370 remap_debug_filename (fd->filename));
22371 fputc ('\n', asm_out_file);
22375 return fd->emitted_number;
22378 /* Schedule generation of a DW_AT_const_value attribute to DIE.
22379 That generation should happen after function debug info has been
22380 generated. The value of the attribute is the constant value of ARG. */
22383 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
22385 die_arg_entry entry;
22390 if (!tmpl_value_parm_die_table)
22391 tmpl_value_parm_die_table
22392 = VEC_alloc (die_arg_entry, gc, 32);
22396 VEC_safe_push (die_arg_entry, gc,
22397 tmpl_value_parm_die_table,
22401 /* Return TRUE if T is an instance of generic type, FALSE
22405 generic_type_p (tree t)
22407 if (t == NULL_TREE || !TYPE_P (t))
22409 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
22412 /* Schedule the generation of the generic parameter dies for the
22413 instance of generic type T. The proper generation itself is later
22414 done by gen_scheduled_generic_parms_dies. */
22417 schedule_generic_params_dies_gen (tree t)
22419 if (!generic_type_p (t))
22422 if (generic_type_instances == NULL)
22423 generic_type_instances = VEC_alloc (tree, gc, 256);
22425 VEC_safe_push (tree, gc, generic_type_instances, t);
22428 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
22429 by append_entry_to_tmpl_value_parm_die_table. This function must
22430 be called after function DIEs have been generated. */
22433 gen_remaining_tmpl_value_param_die_attribute (void)
22435 if (tmpl_value_parm_die_table)
22440 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
22441 tree_add_const_value_attribute (e->die, e->arg);
22445 /* Generate generic parameters DIEs for instances of generic types
22446 that have been previously scheduled by
22447 schedule_generic_params_dies_gen. This function must be called
22448 after all the types of the CU have been laid out. */
22451 gen_scheduled_generic_parms_dies (void)
22456 if (generic_type_instances == NULL)
22459 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
22460 gen_generic_params_dies (t);
22464 /* Replace DW_AT_name for the decl with name. */
22467 dwarf2out_set_name (tree decl, tree name)
22473 die = TYPE_SYMTAB_DIE (decl);
22477 dname = dwarf2_name (name, 0);
22481 attr = get_AT (die, DW_AT_name);
22484 struct indirect_string_node *node;
22486 node = find_AT_string (dname);
22487 /* replace the string. */
22488 attr->dw_attr_val.v.val_str = node;
22492 add_name_attribute (die, dname);
22495 /* Called by the final INSN scan whenever we see a var location. We
22496 use it to drop labels in the right places, and throw the location in
22497 our lookup table. */
22500 dwarf2out_var_location (rtx loc_note)
22502 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
22503 struct var_loc_node *newloc;
22505 static const char *last_label;
22506 static const char *last_postcall_label;
22507 static bool last_in_cold_section_p;
22511 if (!NOTE_P (loc_note))
22513 if (CALL_P (loc_note))
22516 if (SIBLING_CALL_P (loc_note))
22517 tail_call_site_count++;
22522 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
22523 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
22526 next_real = next_real_insn (loc_note);
22528 /* If there are no instructions which would be affected by this note,
22529 don't do anything. */
22531 && next_real == NULL_RTX
22532 && !NOTE_DURING_CALL_P (loc_note))
22535 if (next_real == NULL_RTX)
22536 next_real = get_last_insn ();
22538 /* If there were any real insns between note we processed last time
22539 and this note (or if it is the first note), clear
22540 last_{,postcall_}label so that they are not reused this time. */
22541 if (last_var_location_insn == NULL_RTX
22542 || last_var_location_insn != next_real
22543 || last_in_cold_section_p != in_cold_section_p)
22546 last_postcall_label = NULL;
22551 decl = NOTE_VAR_LOCATION_DECL (loc_note);
22552 newloc = add_var_loc_to_decl (decl, loc_note,
22553 NOTE_DURING_CALL_P (loc_note)
22554 ? last_postcall_label : last_label);
22555 if (newloc == NULL)
22564 /* If there were no real insns between note we processed last time
22565 and this note, use the label we emitted last time. Otherwise
22566 create a new label and emit it. */
22567 if (last_label == NULL)
22569 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
22570 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
22572 last_label = ggc_strdup (loclabel);
22577 struct call_arg_loc_node *ca_loc
22578 = ggc_alloc_cleared_call_arg_loc_node ();
22579 rtx prev = prev_real_insn (loc_note), x;
22580 ca_loc->call_arg_loc_note = loc_note;
22581 ca_loc->next = NULL;
22582 ca_loc->label = last_label;
22585 || (NONJUMP_INSN_P (prev)
22586 && GET_CODE (PATTERN (prev)) == SEQUENCE
22587 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
22588 if (!CALL_P (prev))
22589 prev = XVECEXP (PATTERN (prev), 0, 0);
22590 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
22591 x = PATTERN (prev);
22592 if (GET_CODE (x) == PARALLEL)
22593 x = XVECEXP (x, 0, 0);
22594 if (GET_CODE (x) == SET)
22596 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
22598 x = XEXP (XEXP (x, 0), 0);
22599 if (GET_CODE (x) == SYMBOL_REF
22600 && SYMBOL_REF_DECL (x)
22601 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
22602 ca_loc->symbol_ref = x;
22604 ca_loc->block = insn_scope (prev);
22605 if (call_arg_locations)
22606 call_arg_loc_last->next = ca_loc;
22608 call_arg_locations = ca_loc;
22609 call_arg_loc_last = ca_loc;
22611 else if (!NOTE_DURING_CALL_P (loc_note))
22612 newloc->label = last_label;
22615 if (!last_postcall_label)
22617 sprintf (loclabel, "%s-1", last_label);
22618 last_postcall_label = ggc_strdup (loclabel);
22620 newloc->label = last_postcall_label;
22623 last_var_location_insn = next_real;
22624 last_in_cold_section_p = in_cold_section_p;
22627 /* Note in one location list that text section has changed. */
22630 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
22632 var_loc_list *list = (var_loc_list *) *slot;
22634 list->last_before_switch
22635 = list->last->next ? list->last->next : list->last;
22639 /* Note in all location lists that text section has changed. */
22642 var_location_switch_text_section (void)
22644 if (decl_loc_table == NULL)
22647 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
22650 /* Create a new line number table. */
22652 static dw_line_info_table *
22653 new_line_info_table (void)
22655 dw_line_info_table *table;
22657 table = ggc_alloc_cleared_dw_line_info_table_struct ();
22658 table->file_num = 1;
22659 table->line_num = 1;
22660 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
22665 /* Lookup the "current" table into which we emit line info, so
22666 that we don't have to do it for every source line. */
22669 set_cur_line_info_table (section *sec)
22671 dw_line_info_table *table;
22673 if (sec == text_section)
22674 table = text_section_line_info;
22675 else if (sec == cold_text_section)
22677 table = cold_text_section_line_info;
22680 cold_text_section_line_info = table = new_line_info_table ();
22681 table->end_label = cold_end_label;
22686 const char *end_label;
22688 if (flag_reorder_blocks_and_partition)
22690 if (in_cold_section_p)
22691 end_label = crtl->subsections.cold_section_end_label;
22693 end_label = crtl->subsections.hot_section_end_label;
22697 char label[MAX_ARTIFICIAL_LABEL_BYTES];
22698 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
22699 current_function_funcdef_no);
22700 end_label = ggc_strdup (label);
22703 table = new_line_info_table ();
22704 table->end_label = end_label;
22706 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
22709 cur_line_info_table = table;
22713 /* We need to reset the locations at the beginning of each
22714 function. We can't do this in the end_function hook, because the
22715 declarations that use the locations won't have been output when
22716 that hook is called. Also compute have_multiple_function_sections here. */
22719 dwarf2out_begin_function (tree fun)
22721 section *sec = function_section (fun);
22723 if (sec != text_section)
22724 have_multiple_function_sections = true;
22726 if (flag_reorder_blocks_and_partition && !cold_text_section)
22728 gcc_assert (current_function_decl == fun);
22729 cold_text_section = unlikely_text_section ();
22730 switch_to_section (cold_text_section);
22731 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22732 switch_to_section (sec);
22735 dwarf2out_note_section_used ();
22736 call_site_count = 0;
22737 tail_call_site_count = 0;
22739 set_cur_line_info_table (sec);
22742 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22745 push_dw_line_info_entry (dw_line_info_table *table,
22746 enum dw_line_info_opcode opcode, unsigned int val)
22748 dw_line_info_entry e;
22751 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
22754 /* Output a label to mark the beginning of a source code line entry
22755 and record information relating to this source line, in
22756 'line_info_table' for later output of the .debug_line section. */
22757 /* ??? The discriminator parameter ought to be unsigned. */
22760 dwarf2out_source_line (unsigned int line, const char *filename,
22761 int discriminator, bool is_stmt)
22763 unsigned int file_num;
22764 dw_line_info_table *table;
22766 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
22769 /* The discriminator column was added in dwarf4. Simplify the below
22770 by simply removing it if we're not supposed to output it. */
22771 if (dwarf_version < 4 && dwarf_strict)
22774 table = cur_line_info_table;
22775 file_num = maybe_emit_file (lookup_filename (filename));
22777 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22778 the debugger has used the second (possibly duplicate) line number
22779 at the beginning of the function to mark the end of the prologue.
22780 We could eliminate any other duplicates within the function. For
22781 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22782 that second line number entry. */
22783 /* Recall that this end-of-prologue indication is *not* the same thing
22784 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22785 to which the hook corresponds, follows the last insn that was
22786 emitted by gen_prologue. What we need is to preceed the first insn
22787 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22788 insn that corresponds to something the user wrote. These may be
22789 very different locations once scheduling is enabled. */
22791 if (0 && file_num == table->file_num
22792 && line == table->line_num
22793 && discriminator == table->discrim_num
22794 && is_stmt == table->is_stmt)
22797 switch_to_section (current_function_section ());
22799 /* If requested, emit something human-readable. */
22800 if (flag_debug_asm)
22801 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
22803 if (DWARF2_ASM_LINE_DEBUG_INFO)
22805 /* Emit the .loc directive understood by GNU as. */
22806 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
22807 if (is_stmt != table->is_stmt)
22808 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
22809 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
22810 fprintf (asm_out_file, " discriminator %d", discriminator);
22811 fputc ('\n', asm_out_file);
22815 unsigned int label_num = ++line_info_label_num;
22817 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
22819 push_dw_line_info_entry (table, LI_set_address, label_num);
22820 if (file_num != table->file_num)
22821 push_dw_line_info_entry (table, LI_set_file, file_num);
22822 if (discriminator != table->discrim_num)
22823 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
22824 if (is_stmt != table->is_stmt)
22825 push_dw_line_info_entry (table, LI_negate_stmt, 0);
22826 push_dw_line_info_entry (table, LI_set_line, line);
22829 table->file_num = file_num;
22830 table->line_num = line;
22831 table->discrim_num = discriminator;
22832 table->is_stmt = is_stmt;
22833 table->in_use = true;
22836 /* Record the beginning of a new source file. */
22839 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22841 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22843 /* Record the beginning of the file for break_out_includes. */
22844 dw_die_ref bincl_die;
22846 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22847 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22850 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22853 e.code = DW_MACINFO_start_file;
22855 e.info = xstrdup (filename);
22856 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22860 /* Record the end of a source file. */
22863 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22865 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22866 /* Record the end of the file for break_out_includes. */
22867 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22869 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22872 e.code = DW_MACINFO_end_file;
22875 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22879 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22880 the tail part of the directive line, i.e. the part which is past the
22881 initial whitespace, #, whitespace, directive-name, whitespace part. */
22884 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22885 const char *buffer ATTRIBUTE_UNUSED)
22887 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22890 e.code = DW_MACINFO_define;
22892 e.info = xstrdup (buffer);;
22893 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22897 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22898 the tail part of the directive line, i.e. the part which is past the
22899 initial whitespace, #, whitespace, directive-name, whitespace part. */
22902 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22903 const char *buffer ATTRIBUTE_UNUSED)
22905 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22908 e.code = DW_MACINFO_undef;
22910 e.info = xstrdup (buffer);;
22911 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22916 output_macinfo (void)
22919 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
22920 macinfo_entry *ref;
22925 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
22929 case DW_MACINFO_start_file:
22931 int file_num = maybe_emit_file (lookup_filename (ref->info));
22932 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22933 dw2_asm_output_data_uleb128
22934 (ref->lineno, "Included from line number %lu",
22935 (unsigned long)ref->lineno);
22936 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22939 case DW_MACINFO_end_file:
22940 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22942 case DW_MACINFO_define:
22943 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
22944 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22945 (unsigned long)ref->lineno);
22946 dw2_asm_output_nstring (ref->info, -1, "The macro");
22948 case DW_MACINFO_undef:
22949 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
22950 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22951 (unsigned long)ref->lineno);
22952 dw2_asm_output_nstring (ref->info, -1, "The macro");
22955 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22956 ASM_COMMENT_START, (unsigned long)ref->code);
22962 /* Set up for Dwarf output at the start of compilation. */
22965 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
22967 /* Allocate the file_table. */
22968 file_table = htab_create_ggc (50, file_table_hash,
22969 file_table_eq, NULL);
22971 /* Allocate the decl_die_table. */
22972 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
22973 decl_die_table_eq, NULL);
22975 /* Allocate the decl_loc_table. */
22976 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
22977 decl_loc_table_eq, NULL);
22979 /* Allocate the cached_dw_loc_list_table. */
22980 cached_dw_loc_list_table
22981 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
22982 cached_dw_loc_list_table_eq, NULL);
22984 /* Allocate the initial hunk of the decl_scope_table. */
22985 decl_scope_table = VEC_alloc (tree, gc, 256);
22987 /* Allocate the initial hunk of the abbrev_die_table. */
22988 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
22989 (ABBREV_DIE_TABLE_INCREMENT);
22990 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
22991 /* Zero-th entry is allocated, but unused. */
22992 abbrev_die_table_in_use = 1;
22994 /* Allocate the pubtypes and pubnames vectors. */
22995 pubname_table = VEC_alloc (pubname_entry, gc, 32);
22996 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
22998 incomplete_types = VEC_alloc (tree, gc, 64);
23000 used_rtx_array = VEC_alloc (rtx, gc, 32);
23002 debug_info_section = get_section (DEBUG_INFO_SECTION,
23003 SECTION_DEBUG, NULL);
23004 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
23005 SECTION_DEBUG, NULL);
23006 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
23007 SECTION_DEBUG, NULL);
23008 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
23009 SECTION_DEBUG, NULL);
23010 debug_line_section = get_section (DEBUG_LINE_SECTION,
23011 SECTION_DEBUG, NULL);
23012 debug_loc_section = get_section (DEBUG_LOC_SECTION,
23013 SECTION_DEBUG, NULL);
23014 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
23015 SECTION_DEBUG, NULL);
23016 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
23017 SECTION_DEBUG, NULL);
23018 debug_str_section = get_section (DEBUG_STR_SECTION,
23019 DEBUG_STR_SECTION_FLAGS, NULL);
23020 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
23021 SECTION_DEBUG, NULL);
23022 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
23023 SECTION_DEBUG, NULL);
23025 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
23026 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
23027 DEBUG_ABBREV_SECTION_LABEL, 0);
23028 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
23029 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
23030 COLD_TEXT_SECTION_LABEL, 0);
23031 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
23033 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
23034 DEBUG_INFO_SECTION_LABEL, 0);
23035 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
23036 DEBUG_LINE_SECTION_LABEL, 0);
23037 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
23038 DEBUG_RANGES_SECTION_LABEL, 0);
23039 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
23040 DEBUG_MACINFO_SECTION_LABEL, 0);
23042 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23043 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
23045 switch_to_section (text_section);
23046 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
23048 /* Make sure the line number table for .text always exists. */
23049 text_section_line_info = new_line_info_table ();
23050 text_section_line_info->end_label = text_end_label;
23053 /* Called before cgraph_optimize starts outputtting functions, variables
23054 and toplevel asms into assembly. */
23057 dwarf2out_assembly_start (void)
23059 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23060 && dwarf2out_do_cfi_asm ()
23061 && (!(flag_unwind_tables || flag_exceptions)
23062 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
23063 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
23066 /* A helper function for dwarf2out_finish called through
23067 htab_traverse. Emit one queued .debug_str string. */
23070 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
23072 struct indirect_string_node *node = (struct indirect_string_node *) *h;
23074 if (node->form == DW_FORM_strp)
23076 switch_to_section (debug_str_section);
23077 ASM_OUTPUT_LABEL (asm_out_file, node->label);
23078 assemble_string (node->str, strlen (node->str) + 1);
23084 #if ENABLE_ASSERT_CHECKING
23085 /* Verify that all marks are clear. */
23088 verify_marks_clear (dw_die_ref die)
23092 gcc_assert (! die->die_mark);
23093 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
23095 #endif /* ENABLE_ASSERT_CHECKING */
23097 /* Clear the marks for a die and its children.
23098 Be cool if the mark isn't set. */
23101 prune_unmark_dies (dw_die_ref die)
23107 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
23110 /* Given DIE that we're marking as used, find any other dies
23111 it references as attributes and mark them as used. */
23114 prune_unused_types_walk_attribs (dw_die_ref die)
23119 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23121 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
23123 /* A reference to another DIE.
23124 Make sure that it will get emitted.
23125 If it was broken out into a comdat group, don't follow it. */
23126 if (! use_debug_types
23127 || a->dw_attr == DW_AT_specification
23128 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
23129 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
23131 /* Set the string's refcount to 0 so that prune_unused_types_mark
23132 accounts properly for it. */
23133 if (AT_class (a) == dw_val_class_str)
23134 a->dw_attr_val.v.val_str->refcount = 0;
23138 /* Mark the generic parameters and arguments children DIEs of DIE. */
23141 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
23145 if (die == NULL || die->die_child == NULL)
23147 c = die->die_child;
23150 switch (c->die_tag)
23152 case DW_TAG_template_type_param:
23153 case DW_TAG_template_value_param:
23154 case DW_TAG_GNU_template_template_param:
23155 case DW_TAG_GNU_template_parameter_pack:
23156 prune_unused_types_mark (c, 1);
23162 } while (c && c != die->die_child);
23165 /* Mark DIE as being used. If DOKIDS is true, then walk down
23166 to DIE's children. */
23169 prune_unused_types_mark (dw_die_ref die, int dokids)
23173 if (die->die_mark == 0)
23175 /* We haven't done this node yet. Mark it as used. */
23177 /* If this is the DIE of a generic type instantiation,
23178 mark the children DIEs that describe its generic parms and
23180 prune_unused_types_mark_generic_parms_dies (die);
23182 /* We also have to mark its parents as used.
23183 (But we don't want to mark our parents' kids due to this.) */
23184 if (die->die_parent)
23185 prune_unused_types_mark (die->die_parent, 0);
23187 /* Mark any referenced nodes. */
23188 prune_unused_types_walk_attribs (die);
23190 /* If this node is a specification,
23191 also mark the definition, if it exists. */
23192 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
23193 prune_unused_types_mark (die->die_definition, 1);
23196 if (dokids && die->die_mark != 2)
23198 /* We need to walk the children, but haven't done so yet.
23199 Remember that we've walked the kids. */
23202 /* If this is an array type, we need to make sure our
23203 kids get marked, even if they're types. If we're
23204 breaking out types into comdat sections, do this
23205 for all type definitions. */
23206 if (die->die_tag == DW_TAG_array_type
23207 || (use_debug_types
23208 && is_type_die (die) && ! is_declaration_die (die)))
23209 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
23211 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23215 /* For local classes, look if any static member functions were emitted
23216 and if so, mark them. */
23219 prune_unused_types_walk_local_classes (dw_die_ref die)
23223 if (die->die_mark == 2)
23226 switch (die->die_tag)
23228 case DW_TAG_structure_type:
23229 case DW_TAG_union_type:
23230 case DW_TAG_class_type:
23233 case DW_TAG_subprogram:
23234 if (!get_AT_flag (die, DW_AT_declaration)
23235 || die->die_definition != NULL)
23236 prune_unused_types_mark (die, 1);
23243 /* Mark children. */
23244 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
23247 /* Walk the tree DIE and mark types that we actually use. */
23250 prune_unused_types_walk (dw_die_ref die)
23254 /* Don't do anything if this node is already marked and
23255 children have been marked as well. */
23256 if (die->die_mark == 2)
23259 switch (die->die_tag)
23261 case DW_TAG_structure_type:
23262 case DW_TAG_union_type:
23263 case DW_TAG_class_type:
23264 if (die->die_perennial_p)
23267 for (c = die->die_parent; c; c = c->die_parent)
23268 if (c->die_tag == DW_TAG_subprogram)
23271 /* Finding used static member functions inside of classes
23272 is needed just for local classes, because for other classes
23273 static member function DIEs with DW_AT_specification
23274 are emitted outside of the DW_TAG_*_type. If we ever change
23275 it, we'd need to call this even for non-local classes. */
23277 prune_unused_types_walk_local_classes (die);
23279 /* It's a type node --- don't mark it. */
23282 case DW_TAG_const_type:
23283 case DW_TAG_packed_type:
23284 case DW_TAG_pointer_type:
23285 case DW_TAG_reference_type:
23286 case DW_TAG_rvalue_reference_type:
23287 case DW_TAG_volatile_type:
23288 case DW_TAG_typedef:
23289 case DW_TAG_array_type:
23290 case DW_TAG_interface_type:
23291 case DW_TAG_friend:
23292 case DW_TAG_variant_part:
23293 case DW_TAG_enumeration_type:
23294 case DW_TAG_subroutine_type:
23295 case DW_TAG_string_type:
23296 case DW_TAG_set_type:
23297 case DW_TAG_subrange_type:
23298 case DW_TAG_ptr_to_member_type:
23299 case DW_TAG_file_type:
23300 if (die->die_perennial_p)
23303 /* It's a type node --- don't mark it. */
23307 /* Mark everything else. */
23311 if (die->die_mark == 0)
23315 /* Now, mark any dies referenced from here. */
23316 prune_unused_types_walk_attribs (die);
23321 /* Mark children. */
23322 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23325 /* Increment the string counts on strings referred to from DIE's
23329 prune_unused_types_update_strings (dw_die_ref die)
23334 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23335 if (AT_class (a) == dw_val_class_str)
23337 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
23339 /* Avoid unnecessarily putting strings that are used less than
23340 twice in the hash table. */
23342 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
23345 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
23346 htab_hash_string (s->str),
23348 gcc_assert (*slot == NULL);
23354 /* Remove from the tree DIE any dies that aren't marked. */
23357 prune_unused_types_prune (dw_die_ref die)
23361 gcc_assert (die->die_mark);
23362 prune_unused_types_update_strings (die);
23364 if (! die->die_child)
23367 c = die->die_child;
23369 dw_die_ref prev = c;
23370 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
23371 if (c == die->die_child)
23373 /* No marked children between 'prev' and the end of the list. */
23375 /* No marked children at all. */
23376 die->die_child = NULL;
23379 prev->die_sib = c->die_sib;
23380 die->die_child = prev;
23385 if (c != prev->die_sib)
23387 prune_unused_types_prune (c);
23388 } while (c != die->die_child);
23391 /* Remove dies representing declarations that we never use. */
23394 prune_unused_types (void)
23397 limbo_die_node *node;
23398 comdat_type_node *ctnode;
23400 dw_die_ref base_type;
23402 #if ENABLE_ASSERT_CHECKING
23403 /* All the marks should already be clear. */
23404 verify_marks_clear (comp_unit_die ());
23405 for (node = limbo_die_list; node; node = node->next)
23406 verify_marks_clear (node->die);
23407 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23408 verify_marks_clear (ctnode->root_die);
23409 #endif /* ENABLE_ASSERT_CHECKING */
23411 /* Mark types that are used in global variables. */
23412 premark_types_used_by_global_vars ();
23414 /* Set the mark on nodes that are actually used. */
23415 prune_unused_types_walk (comp_unit_die ());
23416 for (node = limbo_die_list; node; node = node->next)
23417 prune_unused_types_walk (node->die);
23418 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23420 prune_unused_types_walk (ctnode->root_die);
23421 prune_unused_types_mark (ctnode->type_die, 1);
23424 /* Also set the mark on nodes referenced from the
23426 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
23427 prune_unused_types_mark (pub->die, 1);
23428 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
23429 prune_unused_types_mark (base_type, 1);
23431 if (debug_str_hash)
23432 htab_empty (debug_str_hash);
23433 prune_unused_types_prune (comp_unit_die ());
23434 for (node = limbo_die_list; node; node = node->next)
23435 prune_unused_types_prune (node->die);
23436 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23437 prune_unused_types_prune (ctnode->root_die);
23439 /* Leave the marks clear. */
23440 prune_unmark_dies (comp_unit_die ());
23441 for (node = limbo_die_list; node; node = node->next)
23442 prune_unmark_dies (node->die);
23443 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23444 prune_unmark_dies (ctnode->root_die);
23447 /* Set the parameter to true if there are any relative pathnames in
23450 file_table_relative_p (void ** slot, void *param)
23452 bool *p = (bool *) param;
23453 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
23454 if (!IS_ABSOLUTE_PATH (d->filename))
23462 /* Routines to manipulate hash table of comdat type units. */
23465 htab_ct_hash (const void *of)
23468 const comdat_type_node *const type_node = (const comdat_type_node *) of;
23470 memcpy (&h, type_node->signature, sizeof (h));
23475 htab_ct_eq (const void *of1, const void *of2)
23477 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
23478 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
23480 return (! memcmp (type_node_1->signature, type_node_2->signature,
23481 DWARF_TYPE_SIGNATURE_SIZE));
23484 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23485 to the location it would have been added, should we know its
23486 DECL_ASSEMBLER_NAME when we added other attributes. This will
23487 probably improve compactness of debug info, removing equivalent
23488 abbrevs, and hide any differences caused by deferring the
23489 computation of the assembler name, triggered by e.g. PCH. */
23492 move_linkage_attr (dw_die_ref die)
23494 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
23495 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
23497 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
23498 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
23502 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
23504 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
23508 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
23510 VEC_pop (dw_attr_node, die->die_attr);
23511 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
23515 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
23516 referenced from typed stack ops and count how often they are used. */
23519 mark_base_types (dw_loc_descr_ref loc)
23521 dw_die_ref base_type = NULL;
23523 for (; loc; loc = loc->dw_loc_next)
23525 switch (loc->dw_loc_opc)
23527 case DW_OP_GNU_regval_type:
23528 case DW_OP_GNU_deref_type:
23529 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
23531 case DW_OP_GNU_const_type:
23532 case DW_OP_GNU_convert:
23533 case DW_OP_GNU_reinterpret:
23534 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
23536 case DW_OP_GNU_entry_value:
23537 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
23542 gcc_assert (base_type->die_parent == comp_unit_die ());
23543 if (base_type->die_mark)
23544 base_type->die_mark++;
23547 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
23548 base_type->die_mark = 1;
23553 /* Comparison function for sorting marked base types. */
23556 base_type_cmp (const void *x, const void *y)
23558 dw_die_ref dx = *(const dw_die_ref *) x;
23559 dw_die_ref dy = *(const dw_die_ref *) y;
23560 unsigned int byte_size1, byte_size2;
23561 unsigned int encoding1, encoding2;
23562 if (dx->die_mark > dy->die_mark)
23564 if (dx->die_mark < dy->die_mark)
23566 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
23567 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
23568 if (byte_size1 < byte_size2)
23570 if (byte_size1 > byte_size2)
23572 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
23573 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
23574 if (encoding1 < encoding2)
23576 if (encoding1 > encoding2)
23581 /* Move base types marked by mark_base_types as early as possible
23582 in the CU, sorted by decreasing usage count both to make the
23583 uleb128 references as small as possible and to make sure they
23584 will have die_offset already computed by calc_die_sizes when
23585 sizes of typed stack loc ops is computed. */
23588 move_marked_base_types (void)
23591 dw_die_ref base_type, die, c;
23593 if (VEC_empty (dw_die_ref, base_types))
23596 /* Sort by decreasing usage count, they will be added again in that
23598 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
23599 die = comp_unit_die ();
23600 c = die->die_child;
23603 dw_die_ref prev = c;
23605 while (c->die_mark)
23607 remove_child_with_prev (c, prev);
23608 /* As base types got marked, there must be at least
23609 one node other than DW_TAG_base_type. */
23610 gcc_assert (c != c->die_sib);
23614 while (c != die->die_child);
23615 gcc_assert (die->die_child);
23616 c = die->die_child;
23617 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
23619 base_type->die_mark = 0;
23620 base_type->die_sib = c->die_sib;
23621 c->die_sib = base_type;
23626 /* Helper function for resolve_addr, attempt to resolve
23627 one CONST_STRING, return non-zero if not successful. Similarly verify that
23628 SYMBOL_REFs refer to variables emitted in the current CU. */
23631 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
23635 if (GET_CODE (rtl) == CONST_STRING)
23637 size_t len = strlen (XSTR (rtl, 0)) + 1;
23638 tree t = build_string (len, XSTR (rtl, 0));
23639 tree tlen = size_int (len - 1);
23641 = build_array_type (char_type_node, build_index_type (tlen));
23642 rtl = lookup_constant_def (t);
23643 if (!rtl || !MEM_P (rtl))
23645 rtl = XEXP (rtl, 0);
23646 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
23651 if (GET_CODE (rtl) == SYMBOL_REF
23652 && SYMBOL_REF_DECL (rtl))
23654 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
23656 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
23659 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
23663 if (GET_CODE (rtl) == CONST
23664 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
23670 /* Helper function for resolve_addr, handle one location
23671 expression, return false if at least one CONST_STRING or SYMBOL_REF in
23672 the location list couldn't be resolved. */
23675 resolve_addr_in_expr (dw_loc_descr_ref loc)
23677 for (; loc; loc = loc->dw_loc_next)
23678 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
23679 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
23680 || (loc->dw_loc_opc == DW_OP_implicit_value
23681 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
23682 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
23684 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
23685 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
23688 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
23691 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
23692 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
23693 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
23698 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23699 an address in .rodata section if the string literal is emitted there,
23700 or remove the containing location list or replace DW_AT_const_value
23701 with DW_AT_location and empty location expression, if it isn't found
23702 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23703 to something that has been emitted in the current CU. */
23706 resolve_addr (dw_die_ref die)
23710 dw_loc_list_ref *curr, *start, loc;
23713 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23714 switch (AT_class (a))
23716 case dw_val_class_loc_list:
23717 start = curr = AT_loc_list_ptr (a);
23720 /* The same list can be referenced more than once. See if we have
23721 already recorded the result from a previous pass. */
23723 *curr = loc->dw_loc_next;
23724 else if (!loc->resolved_addr)
23726 /* As things stand, we do not expect or allow one die to
23727 reference a suffix of another die's location list chain.
23728 References must be identical or completely separate.
23729 There is therefore no need to cache the result of this
23730 pass on any list other than the first; doing so
23731 would lead to unnecessary writes. */
23734 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
23735 if (!resolve_addr_in_expr ((*curr)->expr))
23737 dw_loc_list_ref next = (*curr)->dw_loc_next;
23738 if (next && (*curr)->ll_symbol)
23740 gcc_assert (!next->ll_symbol);
23741 next->ll_symbol = (*curr)->ll_symbol;
23747 mark_base_types ((*curr)->expr);
23748 curr = &(*curr)->dw_loc_next;
23752 loc->resolved_addr = 1;
23756 loc->dw_loc_next = *start;
23761 remove_AT (die, a->dw_attr);
23765 case dw_val_class_loc:
23766 if (!resolve_addr_in_expr (AT_loc (a)))
23768 remove_AT (die, a->dw_attr);
23772 mark_base_types (AT_loc (a));
23774 case dw_val_class_addr:
23775 if (a->dw_attr == DW_AT_const_value
23776 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
23778 remove_AT (die, a->dw_attr);
23781 if (die->die_tag == DW_TAG_GNU_call_site
23782 && a->dw_attr == DW_AT_abstract_origin)
23784 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
23785 dw_die_ref tdie = lookup_decl_die (tdecl);
23787 && DECL_EXTERNAL (tdecl)
23788 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
23790 force_decl_die (tdecl);
23791 tdie = lookup_decl_die (tdecl);
23795 a->dw_attr_val.val_class = dw_val_class_die_ref;
23796 a->dw_attr_val.v.val_die_ref.die = tdie;
23797 a->dw_attr_val.v.val_die_ref.external = 0;
23801 remove_AT (die, a->dw_attr);
23810 FOR_EACH_CHILD (die, c, resolve_addr (c));
23813 /* Helper routines for optimize_location_lists.
23814 This pass tries to share identical local lists in .debug_loc
23817 /* Iteratively hash operands of LOC opcode. */
23819 static inline hashval_t
23820 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
23822 dw_val_ref val1 = &loc->dw_loc_oprnd1;
23823 dw_val_ref val2 = &loc->dw_loc_oprnd2;
23825 switch (loc->dw_loc_opc)
23827 case DW_OP_const4u:
23828 case DW_OP_const8u:
23832 case DW_OP_const1u:
23833 case DW_OP_const1s:
23834 case DW_OP_const2u:
23835 case DW_OP_const2s:
23836 case DW_OP_const4s:
23837 case DW_OP_const8s:
23841 case DW_OP_plus_uconst:
23877 case DW_OP_deref_size:
23878 case DW_OP_xderef_size:
23879 hash = iterative_hash_object (val1->v.val_int, hash);
23886 gcc_assert (val1->val_class == dw_val_class_loc);
23887 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
23888 hash = iterative_hash_object (offset, hash);
23891 case DW_OP_implicit_value:
23892 hash = iterative_hash_object (val1->v.val_unsigned, hash);
23893 switch (val2->val_class)
23895 case dw_val_class_const:
23896 hash = iterative_hash_object (val2->v.val_int, hash);
23898 case dw_val_class_vec:
23900 unsigned int elt_size = val2->v.val_vec.elt_size;
23901 unsigned int len = val2->v.val_vec.length;
23903 hash = iterative_hash_object (elt_size, hash);
23904 hash = iterative_hash_object (len, hash);
23905 hash = iterative_hash (val2->v.val_vec.array,
23906 len * elt_size, hash);
23909 case dw_val_class_const_double:
23910 hash = iterative_hash_object (val2->v.val_double.low, hash);
23911 hash = iterative_hash_object (val2->v.val_double.high, hash);
23913 case dw_val_class_addr:
23914 hash = iterative_hash_rtx (val2->v.val_addr, hash);
23917 gcc_unreachable ();
23921 case DW_OP_bit_piece:
23922 hash = iterative_hash_object (val1->v.val_int, hash);
23923 hash = iterative_hash_object (val2->v.val_int, hash);
23929 unsigned char dtprel = 0xd1;
23930 hash = iterative_hash_object (dtprel, hash);
23932 hash = iterative_hash_rtx (val1->v.val_addr, hash);
23934 case DW_OP_GNU_implicit_pointer:
23935 hash = iterative_hash_object (val2->v.val_int, hash);
23937 case DW_OP_GNU_entry_value:
23938 hash = hash_loc_operands (val1->v.val_loc, hash);
23940 case DW_OP_GNU_regval_type:
23941 case DW_OP_GNU_deref_type:
23943 unsigned int byte_size
23944 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
23945 unsigned int encoding
23946 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
23947 hash = iterative_hash_object (val1->v.val_int, hash);
23948 hash = iterative_hash_object (byte_size, hash);
23949 hash = iterative_hash_object (encoding, hash);
23952 case DW_OP_GNU_convert:
23953 case DW_OP_GNU_reinterpret:
23954 case DW_OP_GNU_const_type:
23956 unsigned int byte_size
23957 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
23958 unsigned int encoding
23959 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
23960 hash = iterative_hash_object (byte_size, hash);
23961 hash = iterative_hash_object (encoding, hash);
23962 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
23964 hash = iterative_hash_object (val2->val_class, hash);
23965 switch (val2->val_class)
23967 case dw_val_class_const:
23968 hash = iterative_hash_object (val2->v.val_int, hash);
23970 case dw_val_class_vec:
23972 unsigned int elt_size = val2->v.val_vec.elt_size;
23973 unsigned int len = val2->v.val_vec.length;
23975 hash = iterative_hash_object (elt_size, hash);
23976 hash = iterative_hash_object (len, hash);
23977 hash = iterative_hash (val2->v.val_vec.array,
23978 len * elt_size, hash);
23981 case dw_val_class_const_double:
23982 hash = iterative_hash_object (val2->v.val_double.low, hash);
23983 hash = iterative_hash_object (val2->v.val_double.high, hash);
23986 gcc_unreachable ();
23992 /* Other codes have no operands. */
23998 /* Iteratively hash the whole DWARF location expression LOC. */
24000 static inline hashval_t
24001 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
24003 dw_loc_descr_ref l;
24004 bool sizes_computed = false;
24005 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24006 size_of_locs (loc);
24008 for (l = loc; l != NULL; l = l->dw_loc_next)
24010 enum dwarf_location_atom opc = l->dw_loc_opc;
24011 hash = iterative_hash_object (opc, hash);
24012 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
24014 size_of_locs (loc);
24015 sizes_computed = true;
24017 hash = hash_loc_operands (l, hash);
24022 /* Compute hash of the whole location list LIST_HEAD. */
24025 hash_loc_list (dw_loc_list_ref list_head)
24027 dw_loc_list_ref curr = list_head;
24028 hashval_t hash = 0;
24030 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
24032 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
24033 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
24035 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
24037 hash = hash_locs (curr->expr, hash);
24039 list_head->hash = hash;
24042 /* Return true if X and Y opcodes have the same operands. */
24045 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
24047 dw_val_ref valx1 = &x->dw_loc_oprnd1;
24048 dw_val_ref valx2 = &x->dw_loc_oprnd2;
24049 dw_val_ref valy1 = &y->dw_loc_oprnd1;
24050 dw_val_ref valy2 = &y->dw_loc_oprnd2;
24052 switch (x->dw_loc_opc)
24054 case DW_OP_const4u:
24055 case DW_OP_const8u:
24059 case DW_OP_const1u:
24060 case DW_OP_const1s:
24061 case DW_OP_const2u:
24062 case DW_OP_const2s:
24063 case DW_OP_const4s:
24064 case DW_OP_const8s:
24068 case DW_OP_plus_uconst:
24104 case DW_OP_deref_size:
24105 case DW_OP_xderef_size:
24106 return valx1->v.val_int == valy1->v.val_int;
24109 gcc_assert (valx1->val_class == dw_val_class_loc
24110 && valy1->val_class == dw_val_class_loc
24111 && x->dw_loc_addr == y->dw_loc_addr);
24112 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
24113 case DW_OP_implicit_value:
24114 if (valx1->v.val_unsigned != valy1->v.val_unsigned
24115 || valx2->val_class != valy2->val_class)
24117 switch (valx2->val_class)
24119 case dw_val_class_const:
24120 return valx2->v.val_int == valy2->v.val_int;
24121 case dw_val_class_vec:
24122 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24123 && valx2->v.val_vec.length == valy2->v.val_vec.length
24124 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24125 valx2->v.val_vec.elt_size
24126 * valx2->v.val_vec.length) == 0;
24127 case dw_val_class_const_double:
24128 return valx2->v.val_double.low == valy2->v.val_double.low
24129 && valx2->v.val_double.high == valy2->v.val_double.high;
24130 case dw_val_class_addr:
24131 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
24133 gcc_unreachable ();
24136 case DW_OP_bit_piece:
24137 return valx1->v.val_int == valy1->v.val_int
24138 && valx2->v.val_int == valy2->v.val_int;
24141 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
24142 case DW_OP_GNU_implicit_pointer:
24143 return valx1->val_class == dw_val_class_die_ref
24144 && valx1->val_class == valy1->val_class
24145 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
24146 && valx2->v.val_int == valy2->v.val_int;
24147 case DW_OP_GNU_entry_value:
24148 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
24149 case DW_OP_GNU_const_type:
24150 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
24151 || valx2->val_class != valy2->val_class)
24153 switch (valx2->val_class)
24155 case dw_val_class_const:
24156 return valx2->v.val_int == valy2->v.val_int;
24157 case dw_val_class_vec:
24158 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24159 && valx2->v.val_vec.length == valy2->v.val_vec.length
24160 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24161 valx2->v.val_vec.elt_size
24162 * valx2->v.val_vec.length) == 0;
24163 case dw_val_class_const_double:
24164 return valx2->v.val_double.low == valy2->v.val_double.low
24165 && valx2->v.val_double.high == valy2->v.val_double.high;
24167 gcc_unreachable ();
24169 case DW_OP_GNU_regval_type:
24170 case DW_OP_GNU_deref_type:
24171 return valx1->v.val_int == valy1->v.val_int
24172 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
24173 case DW_OP_GNU_convert:
24174 case DW_OP_GNU_reinterpret:
24175 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
24177 /* Other codes have no operands. */
24182 /* Return true if DWARF location expressions X and Y are the same. */
24185 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
24187 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
24188 if (x->dw_loc_opc != y->dw_loc_opc
24189 || x->dtprel != y->dtprel
24190 || !compare_loc_operands (x, y))
24192 return x == NULL && y == NULL;
24195 /* Return precomputed hash of location list X. */
24198 loc_list_hash (const void *x)
24200 return ((const struct dw_loc_list_struct *) x)->hash;
24203 /* Return 1 if location lists X and Y are the same. */
24206 loc_list_eq (const void *x, const void *y)
24208 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
24209 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
24212 if (a->hash != b->hash)
24214 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
24215 if (strcmp (a->begin, b->begin) != 0
24216 || strcmp (a->end, b->end) != 0
24217 || (a->section == NULL) != (b->section == NULL)
24218 || (a->section && strcmp (a->section, b->section) != 0)
24219 || !compare_locs (a->expr, b->expr))
24221 return a == NULL && b == NULL;
24224 /* Recursively optimize location lists referenced from DIE
24225 children and share them whenever possible. */
24228 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
24235 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
24236 if (AT_class (a) == dw_val_class_loc_list)
24238 dw_loc_list_ref list = AT_loc_list (a);
24239 /* TODO: perform some optimizations here, before hashing
24240 it and storing into the hash table. */
24241 hash_loc_list (list);
24242 slot = htab_find_slot_with_hash (htab, list, list->hash,
24245 *slot = (void *) list;
24247 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
24250 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
24253 /* Optimize location lists referenced from DIE
24254 children and share them whenever possible. */
24257 optimize_location_lists (dw_die_ref die)
24259 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
24260 optimize_location_lists_1 (die, htab);
24261 htab_delete (htab);
24264 /* Output stuff that dwarf requires at the end of every file,
24265 and generate the DWARF-2 debugging info. */
24268 dwarf2out_finish (const char *filename)
24270 limbo_die_node *node, *next_node;
24271 comdat_type_node *ctnode;
24272 htab_t comdat_type_table;
24275 gen_scheduled_generic_parms_dies ();
24276 gen_remaining_tmpl_value_param_die_attribute ();
24278 /* Add the name for the main input file now. We delayed this from
24279 dwarf2out_init to avoid complications with PCH. */
24280 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
24281 if (!IS_ABSOLUTE_PATH (filename))
24282 add_comp_dir_attribute (comp_unit_die ());
24283 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
24286 htab_traverse (file_table, file_table_relative_p, &p);
24288 add_comp_dir_attribute (comp_unit_die ());
24291 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
24293 add_location_or_const_value_attribute (
24294 VEC_index (deferred_locations, deferred_locations_list, i)->die,
24295 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
24300 /* Traverse the limbo die list, and add parent/child links. The only
24301 dies without parents that should be here are concrete instances of
24302 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
24303 For concrete instances, we can get the parent die from the abstract
24305 for (node = limbo_die_list; node; node = next_node)
24307 dw_die_ref die = node->die;
24308 next_node = node->next;
24310 if (die->die_parent == NULL)
24312 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
24315 add_child_die (origin->die_parent, die);
24316 else if (is_cu_die (die))
24318 else if (seen_error ())
24319 /* It's OK to be confused by errors in the input. */
24320 add_child_die (comp_unit_die (), die);
24323 /* In certain situations, the lexical block containing a
24324 nested function can be optimized away, which results
24325 in the nested function die being orphaned. Likewise
24326 with the return type of that nested function. Force
24327 this to be a child of the containing function.
24329 It may happen that even the containing function got fully
24330 inlined and optimized out. In that case we are lost and
24331 assign the empty child. This should not be big issue as
24332 the function is likely unreachable too. */
24333 tree context = NULL_TREE;
24335 gcc_assert (node->created_for);
24337 if (DECL_P (node->created_for))
24338 context = DECL_CONTEXT (node->created_for);
24339 else if (TYPE_P (node->created_for))
24340 context = TYPE_CONTEXT (node->created_for);
24342 gcc_assert (context
24343 && (TREE_CODE (context) == FUNCTION_DECL
24344 || TREE_CODE (context) == NAMESPACE_DECL));
24346 origin = lookup_decl_die (context);
24348 add_child_die (origin, die);
24350 add_child_die (comp_unit_die (), die);
24355 limbo_die_list = NULL;
24357 #if ENABLE_ASSERT_CHECKING
24359 dw_die_ref die = comp_unit_die (), c;
24360 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
24363 resolve_addr (comp_unit_die ());
24364 move_marked_base_types ();
24366 for (node = deferred_asm_name; node; node = node->next)
24368 tree decl = node->created_for;
24369 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
24371 add_linkage_attr (node->die, decl);
24372 move_linkage_attr (node->die);
24376 deferred_asm_name = NULL;
24378 /* Walk through the list of incomplete types again, trying once more to
24379 emit full debugging info for them. */
24380 retry_incomplete_types ();
24382 if (flag_eliminate_unused_debug_types)
24383 prune_unused_types ();
24385 /* Generate separate CUs for each of the include files we've seen.
24386 They will go into limbo_die_list. */
24387 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
24388 break_out_includes (comp_unit_die ());
24390 /* Generate separate COMDAT sections for type DIEs. */
24391 if (use_debug_types)
24393 break_out_comdat_types (comp_unit_die ());
24395 /* Each new type_unit DIE was added to the limbo die list when created.
24396 Since these have all been added to comdat_type_list, clear the
24398 limbo_die_list = NULL;
24400 /* For each new comdat type unit, copy declarations for incomplete
24401 types to make the new unit self-contained (i.e., no direct
24402 references to the main compile unit). */
24403 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
24404 copy_decls_for_unworthy_types (ctnode->root_die);
24405 copy_decls_for_unworthy_types (comp_unit_die ());
24407 /* In the process of copying declarations from one unit to another,
24408 we may have left some declarations behind that are no longer
24409 referenced. Prune them. */
24410 prune_unused_types ();
24413 /* Traverse the DIE's and add add sibling attributes to those DIE's
24414 that have children. */
24415 add_sibling_attributes (comp_unit_die ());
24416 for (node = limbo_die_list; node; node = node->next)
24417 add_sibling_attributes (node->die);
24418 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
24419 add_sibling_attributes (ctnode->root_die);
24421 /* Output a terminator label for the .text section. */
24422 switch_to_section (text_section);
24423 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
24424 if (cold_text_section)
24426 switch_to_section (cold_text_section);
24427 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
24430 /* We can only use the low/high_pc attributes if all of the code was
24432 if (!have_multiple_function_sections
24433 || (dwarf_version < 3 && dwarf_strict))
24435 /* Don't add if the CU has no associated code. */
24436 if (text_section_used)
24438 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
24439 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
24444 unsigned fde_idx = 0;
24445 bool range_list_added = false;
24447 if (text_section_used)
24448 add_ranges_by_labels (comp_unit_die (), text_section_label,
24449 text_end_label, &range_list_added);
24450 if (cold_text_section_used)
24451 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
24452 cold_end_label, &range_list_added);
24454 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
24456 dw_fde_ref fde = &fde_table[fde_idx];
24458 if (!fde->in_std_section)
24459 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
24460 fde->dw_fde_end, &range_list_added);
24461 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
24462 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
24463 fde->dw_fde_second_end, &range_list_added);
24466 if (range_list_added)
24468 /* We need to give .debug_loc and .debug_ranges an appropriate
24469 "base address". Use zero so that these addresses become
24470 absolute. Historically, we've emitted the unexpected
24471 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
24472 Emit both to give time for other tools to adapt. */
24473 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
24474 if (! dwarf_strict && dwarf_version < 4)
24475 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
24481 if (debug_info_level >= DINFO_LEVEL_NORMAL)
24482 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
24483 debug_line_section_label);
24485 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
24486 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
24488 if (have_location_lists)
24489 optimize_location_lists (comp_unit_die ());
24491 /* Output all of the compilation units. We put the main one last so that
24492 the offsets are available to output_pubnames. */
24493 for (node = limbo_die_list; node; node = node->next)
24494 output_comp_unit (node->die, 0);
24496 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
24497 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
24499 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
24501 /* Don't output duplicate types. */
24502 if (*slot != HTAB_EMPTY_ENTRY)
24505 /* Add a pointer to the line table for the main compilation unit
24506 so that the debugger can make sense of DW_AT_decl_file
24508 if (debug_info_level >= DINFO_LEVEL_NORMAL)
24509 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
24510 debug_line_section_label);
24512 output_comdat_type_unit (ctnode);
24515 htab_delete (comdat_type_table);
24517 /* Output the main compilation unit if non-empty or if .debug_macinfo
24518 will be emitted. */
24519 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
24521 /* Output the abbreviation table. */
24522 switch_to_section (debug_abbrev_section);
24523 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
24524 output_abbrev_section ();
24526 /* Output location list section if necessary. */
24527 if (have_location_lists)
24529 /* Output the location lists info. */
24530 switch_to_section (debug_loc_section);
24531 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
24532 DEBUG_LOC_SECTION_LABEL, 0);
24533 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
24534 output_location_lists (comp_unit_die ());
24537 /* Output public names table if necessary. */
24538 if (!VEC_empty (pubname_entry, pubname_table))
24540 gcc_assert (info_section_emitted);
24541 switch_to_section (debug_pubnames_section);
24542 output_pubnames (pubname_table);
24545 /* Output public types table if necessary. */
24546 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
24547 It shouldn't hurt to emit it always, since pure DWARF2 consumers
24548 simply won't look for the section. */
24549 if (!VEC_empty (pubname_entry, pubtype_table))
24551 bool empty = false;
24553 if (flag_eliminate_unused_debug_types)
24555 /* The pubtypes table might be emptied by pruning unused items. */
24559 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
24560 if (p->die->die_offset != 0)
24568 gcc_assert (info_section_emitted);
24569 switch_to_section (debug_pubtypes_section);
24570 output_pubnames (pubtype_table);
24574 /* Output the address range information if a CU (.debug_info section)
24575 was emitted. We output an empty table even if we had no functions
24576 to put in it. This because the consumer has no way to tell the
24577 difference between an empty table that we omitted and failure to
24578 generate a table that would have contained data. */
24579 if (info_section_emitted)
24581 unsigned long aranges_length = size_of_aranges ();
24583 switch_to_section (debug_aranges_section);
24584 output_aranges (aranges_length);
24587 /* Output ranges section if necessary. */
24588 if (ranges_table_in_use)
24590 switch_to_section (debug_ranges_section);
24591 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
24595 /* Output the source line correspondence table. We must do this
24596 even if there is no line information. Otherwise, on an empty
24597 translation unit, we will generate a present, but empty,
24598 .debug_info section. IRIX 6.5 `nm' will then complain when
24599 examining the file. This is done late so that any filenames
24600 used by the debug_info section are marked as 'used'. */
24601 switch_to_section (debug_line_section);
24602 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
24603 if (! DWARF2_ASM_LINE_DEBUG_INFO)
24604 output_line_info ();
24606 /* Have to end the macro section. */
24607 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
24609 switch_to_section (debug_macinfo_section);
24610 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
24611 if (!VEC_empty (macinfo_entry, macinfo_table))
24613 dw2_asm_output_data (1, 0, "End compilation unit");
24616 /* If we emitted any DW_FORM_strp form attribute, output the string
24618 if (debug_str_hash)
24619 htab_traverse (debug_str_hash, output_indirect_string, NULL);
24622 #include "gt-dwarf2out.h"