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 "common/common-target.h"
89 #include "langhooks.h"
94 #include "tree-pass.h"
95 #include "tree-flow.h"
96 #include "cfglayout.h"
98 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
99 static rtx last_var_location_insn;
101 #ifdef VMS_DEBUGGING_INFO
102 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
104 /* Define this macro to be a nonzero value if the directory specifications
105 which are output in the debug info should end with a separator. */
106 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
107 /* Define this macro to evaluate to a nonzero value if GCC should refrain
108 from generating indirect strings in DWARF2 debug information, for instance
109 if your target is stuck with an old version of GDB that is unable to
110 process them properly or uses VMS Debug. */
111 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
113 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
114 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
117 /* ??? Poison these here until it can be done generically. They've been
118 totally replaced in this file; make sure it stays that way. */
119 #undef DWARF2_UNWIND_INFO
120 #undef DWARF2_FRAME_INFO
121 #if (GCC_VERSION >= 3000)
122 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
125 #ifndef INCOMING_RETURN_ADDR_RTX
126 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
129 /* Map register numbers held in the call frame info that gcc has
130 collected using DWARF_FRAME_REGNUM to those that should be output in
131 .debug_frame and .eh_frame. */
132 #ifndef DWARF2_FRAME_REG_OUT
133 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
136 /* Save the result of dwarf2out_do_frame across PCH. */
137 static GTY(()) bool saved_do_cfi_asm = 0;
139 /* Decide whether we want to emit frame unwind information for the current
143 dwarf2out_do_frame (void)
145 /* We want to emit correct CFA location expressions or lists, so we
146 have to return true if we're going to output debug info, even if
147 we're not going to output frame or unwind info. */
148 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
151 if (saved_do_cfi_asm)
154 if (targetm.debug_unwind_info () == UI_DWARF2)
157 if ((flag_unwind_tables || flag_exceptions)
158 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
164 /* Decide whether to emit frame unwind via assembler directives. */
167 dwarf2out_do_cfi_asm (void)
171 #ifdef MIPS_DEBUGGING_INFO
174 if (saved_do_cfi_asm)
176 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
178 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
181 /* Make sure the personality encoding is one the assembler can support.
182 In particular, aligned addresses can't be handled. */
183 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
184 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
186 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
187 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
190 /* If we can't get the assembler to emit only .debug_frame, and we don't need
191 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
192 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
193 && !flag_unwind_tables && !flag_exceptions
194 && targetm_common.except_unwind_info (&global_options) != UI_DWARF2)
197 saved_do_cfi_asm = true;
201 /* The size of the target's pointer type. */
203 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
206 /* Array of RTXes referenced by the debugging information, which therefore
207 must be kept around forever. */
208 static GTY(()) VEC(rtx,gc) *used_rtx_array;
210 /* A pointer to the base of a list of incomplete types which might be
211 completed at some later time. incomplete_types_list needs to be a
212 VEC(tree,gc) because we want to tell the garbage collector about
214 static GTY(()) VEC(tree,gc) *incomplete_types;
216 /* A pointer to the base of a table of references to declaration
217 scopes. This table is a display which tracks the nesting
218 of declaration scopes at the current scope and containing
219 scopes. This table is used to find the proper place to
220 define type declaration DIE's. */
221 static GTY(()) VEC(tree,gc) *decl_scope_table;
223 /* Pointers to various DWARF2 sections. */
224 static GTY(()) section *debug_info_section;
225 static GTY(()) section *debug_abbrev_section;
226 static GTY(()) section *debug_aranges_section;
227 static GTY(()) section *debug_macinfo_section;
228 static GTY(()) section *debug_line_section;
229 static GTY(()) section *debug_loc_section;
230 static GTY(()) section *debug_pubnames_section;
231 static GTY(()) section *debug_pubtypes_section;
232 static GTY(()) section *debug_str_section;
233 static GTY(()) section *debug_ranges_section;
234 static GTY(()) section *debug_frame_section;
236 /* Personality decl of current unit. Used only when assembler does not support
238 static GTY(()) rtx current_unit_personality;
240 /* How to start an assembler comment. */
241 #ifndef ASM_COMMENT_START
242 #define ASM_COMMENT_START ";#"
245 typedef struct dw_cfi_struct *dw_cfi_ref;
246 typedef struct dw_fde_struct *dw_fde_ref;
247 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
249 /* Call frames are described using a sequence of Call Frame
250 Information instructions. The register number, offset
251 and address fields are provided as possible operands;
252 their use is selected by the opcode field. */
254 enum dw_cfi_oprnd_type {
256 dw_cfi_oprnd_reg_num,
262 typedef union GTY(()) dw_cfi_oprnd_struct {
263 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
264 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
265 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
266 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
270 typedef struct GTY(()) dw_cfi_struct {
271 enum dwarf_call_frame_info dw_cfi_opc;
272 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
274 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
279 DEF_VEC_P (dw_cfi_ref);
280 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
281 DEF_VEC_ALLOC_P (dw_cfi_ref, gc);
283 typedef VEC(dw_cfi_ref, gc) *cfi_vec;
285 /* This is how we define the location of the CFA. We use to handle it
286 as REG + OFFSET all the time, but now it can be more complex.
287 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
288 Instead of passing around REG and OFFSET, we pass a copy
289 of this structure. */
290 typedef struct cfa_loc {
291 HOST_WIDE_INT offset;
292 HOST_WIDE_INT base_offset;
294 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
295 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
298 /* All call frame descriptions (FDE's) in the GCC generated DWARF
299 refer to a single Common Information Entry (CIE), defined at
300 the beginning of the .debug_frame section. This use of a single
301 CIE obviates the need to keep track of multiple CIE's
302 in the DWARF generation routines below. */
304 typedef struct GTY(()) dw_fde_struct {
306 const char *dw_fde_begin;
307 const char *dw_fde_current_label;
308 const char *dw_fde_end;
309 const char *dw_fde_vms_end_prologue;
310 const char *dw_fde_vms_begin_epilogue;
311 const char *dw_fde_second_begin;
312 const char *dw_fde_second_end;
314 int dw_fde_switch_cfi_index; /* Last CFI before switching sections. */
315 HOST_WIDE_INT stack_realignment;
316 unsigned funcdef_number;
317 /* Dynamic realign argument pointer register. */
318 unsigned int drap_reg;
319 /* Virtual dynamic realign argument pointer register. */
320 unsigned int vdrap_reg;
321 /* These 3 flags are copied from rtl_data in function.h. */
322 unsigned all_throwers_are_sibcalls : 1;
323 unsigned uses_eh_lsda : 1;
324 unsigned nothrow : 1;
325 /* Whether we did stack realign in this call frame. */
326 unsigned stack_realign : 1;
327 /* Whether dynamic realign argument pointer register has been saved. */
328 unsigned drap_reg_saved: 1;
329 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
330 unsigned in_std_section : 1;
331 /* True iff dw_fde_second_begin label is in text_section or
332 cold_text_section. */
333 unsigned second_in_std_section : 1;
337 /* Maximum size (in bytes) of an artificially generated label. */
338 #define MAX_ARTIFICIAL_LABEL_BYTES 30
340 /* The size of addresses as they appear in the Dwarf 2 data.
341 Some architectures use word addresses to refer to code locations,
342 but Dwarf 2 info always uses byte addresses. On such machines,
343 Dwarf 2 addresses need to be larger than the architecture's
345 #ifndef DWARF2_ADDR_SIZE
346 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
349 /* The size in bytes of a DWARF field indicating an offset or length
350 relative to a debug info section, specified to be 4 bytes in the
351 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
354 #ifndef DWARF_OFFSET_SIZE
355 #define DWARF_OFFSET_SIZE 4
358 /* The size in bytes of a DWARF 4 type signature. */
360 #ifndef DWARF_TYPE_SIGNATURE_SIZE
361 #define DWARF_TYPE_SIGNATURE_SIZE 8
364 /* According to the (draft) DWARF 3 specification, the initial length
365 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
366 bytes are 0xffffffff, followed by the length stored in the next 8
369 However, the SGI/MIPS ABI uses an initial length which is equal to
370 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
372 #ifndef DWARF_INITIAL_LENGTH_SIZE
373 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
376 /* Round SIZE up to the nearest BOUNDARY. */
377 #define DWARF_ROUND(SIZE,BOUNDARY) \
378 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
380 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
381 #ifndef DWARF_CIE_DATA_ALIGNMENT
382 #ifdef STACK_GROWS_DOWNWARD
383 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
385 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
389 /* CIE identifier. */
390 #if HOST_BITS_PER_WIDE_INT >= 64
391 #define DWARF_CIE_ID \
392 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
394 #define DWARF_CIE_ID DW_CIE_ID
397 /* A pointer to the base of a table that contains frame description
398 information for each routine. */
399 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
401 /* Number of elements currently allocated for fde_table. */
402 static GTY(()) unsigned fde_table_allocated;
404 /* Number of elements in fde_table currently in use. */
405 static GTY(()) unsigned fde_table_in_use;
407 /* Size (in elements) of increments by which we may expand the
409 #define FDE_TABLE_INCREMENT 256
411 /* Get the current fde_table entry we should use. */
413 static inline dw_fde_ref
416 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
419 /* A vector of call frame insns for the CIE. */
420 static GTY(()) cfi_vec cie_cfi_vec;
422 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
423 attribute that accelerates the lookup of the FDE associated
424 with the subprogram. This variable holds the table index of the FDE
425 associated with the current function (body) definition. */
426 static unsigned current_funcdef_fde;
428 struct GTY(()) indirect_string_node {
430 unsigned int refcount;
431 enum dwarf_form form;
435 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
437 static GTY(()) int dw2_string_counter;
438 static GTY(()) unsigned long dwarf2out_cfi_label_num;
440 /* True if the compilation unit places functions in more than one section. */
441 static GTY(()) bool have_multiple_function_sections = false;
443 /* Whether the default text and cold text sections have been used at all. */
445 static GTY(()) bool text_section_used = false;
446 static GTY(()) bool cold_text_section_used = false;
448 /* The default cold text section. */
449 static GTY(()) section *cold_text_section;
451 /* Forward declarations for functions defined in this file. */
453 static char *stripattributes (const char *);
454 static const char *dwarf_cfi_name (unsigned);
455 static dw_cfi_ref new_cfi (void);
456 static void add_cfi (cfi_vec *, dw_cfi_ref);
457 static void add_fde_cfi (const char *, dw_cfi_ref);
458 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
459 static void lookup_cfa (dw_cfa_location *);
460 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
461 static void initial_return_save (rtx);
462 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
464 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
465 static void output_cfi_directive (dw_cfi_ref);
466 static void output_call_frame_info (int);
467 static void dwarf2out_note_section_used (void);
468 static bool clobbers_queued_reg_save (const_rtx);
469 static void dwarf2out_frame_debug_expr (rtx, const char *);
471 /* Support for complex CFA locations. */
472 static void output_cfa_loc (dw_cfi_ref, int);
473 static void output_cfa_loc_raw (dw_cfi_ref);
474 static void get_cfa_from_loc_descr (dw_cfa_location *,
475 struct dw_loc_descr_struct *);
476 static struct dw_loc_descr_struct *build_cfa_loc
477 (dw_cfa_location *, HOST_WIDE_INT);
478 static struct dw_loc_descr_struct *build_cfa_aligned_loc
479 (HOST_WIDE_INT, HOST_WIDE_INT);
480 static void def_cfa_1 (const char *, dw_cfa_location *);
481 static struct dw_loc_descr_struct *mem_loc_descriptor
482 (rtx, enum machine_mode mode, enum machine_mode mem_mode,
483 enum var_init_status);
485 /* How to start an assembler comment. */
486 #ifndef ASM_COMMENT_START
487 #define ASM_COMMENT_START ";#"
490 /* Data and reference forms for relocatable data. */
491 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
492 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
494 #ifndef DEBUG_FRAME_SECTION
495 #define DEBUG_FRAME_SECTION ".debug_frame"
498 #ifndef FUNC_BEGIN_LABEL
499 #define FUNC_BEGIN_LABEL "LFB"
502 #ifndef FUNC_END_LABEL
503 #define FUNC_END_LABEL "LFE"
506 #ifndef PROLOGUE_END_LABEL
507 #define PROLOGUE_END_LABEL "LPE"
510 #ifndef EPILOGUE_BEGIN_LABEL
511 #define EPILOGUE_BEGIN_LABEL "LEB"
514 #ifndef FRAME_BEGIN_LABEL
515 #define FRAME_BEGIN_LABEL "Lframe"
517 #define CIE_AFTER_SIZE_LABEL "LSCIE"
518 #define CIE_END_LABEL "LECIE"
519 #define FDE_LABEL "LSFDE"
520 #define FDE_AFTER_SIZE_LABEL "LASFDE"
521 #define FDE_END_LABEL "LEFDE"
522 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
523 #define LINE_NUMBER_END_LABEL "LELT"
524 #define LN_PROLOG_AS_LABEL "LASLTP"
525 #define LN_PROLOG_END_LABEL "LELTP"
526 #define DIE_LABEL_PREFIX "DW"
528 /* The DWARF 2 CFA column which tracks the return address. Normally this
529 is the column for PC, or the first column after all of the hard
531 #ifndef DWARF_FRAME_RETURN_COLUMN
533 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
535 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
539 /* The mapping from gcc register number to DWARF 2 CFA column number. By
540 default, we just provide columns for all registers. */
541 #ifndef DWARF_FRAME_REGNUM
542 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
545 /* Match the base name of a file to the base name of a compilation unit. */
548 matches_main_base (const char *path)
550 /* Cache the last query. */
551 static const char *last_path = NULL;
552 static int last_match = 0;
553 if (path != last_path)
556 int length = base_of_path (path, &base);
558 last_match = (length == main_input_baselength
559 && memcmp (base, main_input_basename, length) == 0);
564 #ifdef DEBUG_DEBUG_STRUCT
567 dump_struct_debug (tree type, enum debug_info_usage usage,
568 enum debug_struct_file criterion, int generic,
569 int matches, int result)
571 /* Find the type name. */
572 tree type_decl = TYPE_STUB_DECL (type);
574 const char *name = 0;
575 if (TREE_CODE (t) == TYPE_DECL)
578 name = IDENTIFIER_POINTER (t);
580 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
582 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
583 matches ? "bas" : "hdr",
584 generic ? "gen" : "ord",
585 usage == DINFO_USAGE_DFN ? ";" :
586 usage == DINFO_USAGE_DIR_USE ? "." : "*",
588 (void*) type_decl, name);
591 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
592 dump_struct_debug (type, usage, criterion, generic, matches, result)
596 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
602 should_emit_struct_debug (tree type, enum debug_info_usage usage)
604 enum debug_struct_file criterion;
606 bool generic = lang_hooks.types.generic_p (type);
609 criterion = debug_struct_generic[usage];
611 criterion = debug_struct_ordinary[usage];
613 if (criterion == DINFO_STRUCT_FILE_NONE)
614 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
615 if (criterion == DINFO_STRUCT_FILE_ANY)
616 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
618 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
620 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
621 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
623 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
624 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
625 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
628 /* Hook used by __throw. */
631 expand_builtin_dwarf_sp_column (void)
633 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
634 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
637 /* Return a pointer to a copy of the section string name S with all
638 attributes stripped off, and an asterisk prepended (for assemble_name). */
641 stripattributes (const char *s)
643 char *stripped = XNEWVEC (char, strlen (s) + 2);
648 while (*s && *s != ',')
655 /* MEM is a memory reference for the register size table, each element of
656 which has mode MODE. Initialize column C as a return address column. */
659 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
661 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
662 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
663 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
666 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
668 static inline HOST_WIDE_INT
669 div_data_align (HOST_WIDE_INT off)
671 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
672 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
676 /* Return true if we need a signed version of a given opcode
677 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
680 need_data_align_sf_opcode (HOST_WIDE_INT off)
682 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
685 /* Generate code to initialize the register size table. */
688 expand_builtin_init_dwarf_reg_sizes (tree address)
691 enum machine_mode mode = TYPE_MODE (char_type_node);
692 rtx addr = expand_normal (address);
693 rtx mem = gen_rtx_MEM (BLKmode, addr);
694 bool wrote_return_column = false;
696 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
698 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
700 if (rnum < DWARF_FRAME_REGISTERS)
702 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
703 enum machine_mode save_mode = reg_raw_mode[i];
706 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
707 save_mode = choose_hard_reg_mode (i, 1, true);
708 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
710 if (save_mode == VOIDmode)
712 wrote_return_column = true;
714 size = GET_MODE_SIZE (save_mode);
718 emit_move_insn (adjust_address (mem, mode, offset),
719 gen_int_mode (size, mode));
723 if (!wrote_return_column)
724 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
726 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
727 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
730 targetm.init_dwarf_reg_sizes_extra (address);
733 /* Convert a DWARF call frame info. operation to its string name */
736 dwarf_cfi_name (unsigned int cfi_opc)
740 case DW_CFA_advance_loc:
741 return "DW_CFA_advance_loc";
743 return "DW_CFA_offset";
745 return "DW_CFA_restore";
749 return "DW_CFA_set_loc";
750 case DW_CFA_advance_loc1:
751 return "DW_CFA_advance_loc1";
752 case DW_CFA_advance_loc2:
753 return "DW_CFA_advance_loc2";
754 case DW_CFA_advance_loc4:
755 return "DW_CFA_advance_loc4";
756 case DW_CFA_offset_extended:
757 return "DW_CFA_offset_extended";
758 case DW_CFA_restore_extended:
759 return "DW_CFA_restore_extended";
760 case DW_CFA_undefined:
761 return "DW_CFA_undefined";
762 case DW_CFA_same_value:
763 return "DW_CFA_same_value";
764 case DW_CFA_register:
765 return "DW_CFA_register";
766 case DW_CFA_remember_state:
767 return "DW_CFA_remember_state";
768 case DW_CFA_restore_state:
769 return "DW_CFA_restore_state";
771 return "DW_CFA_def_cfa";
772 case DW_CFA_def_cfa_register:
773 return "DW_CFA_def_cfa_register";
774 case DW_CFA_def_cfa_offset:
775 return "DW_CFA_def_cfa_offset";
778 case DW_CFA_def_cfa_expression:
779 return "DW_CFA_def_cfa_expression";
780 case DW_CFA_expression:
781 return "DW_CFA_expression";
782 case DW_CFA_offset_extended_sf:
783 return "DW_CFA_offset_extended_sf";
784 case DW_CFA_def_cfa_sf:
785 return "DW_CFA_def_cfa_sf";
786 case DW_CFA_def_cfa_offset_sf:
787 return "DW_CFA_def_cfa_offset_sf";
789 /* SGI/MIPS specific */
790 case DW_CFA_MIPS_advance_loc8:
791 return "DW_CFA_MIPS_advance_loc8";
794 case DW_CFA_GNU_window_save:
795 return "DW_CFA_GNU_window_save";
796 case DW_CFA_GNU_args_size:
797 return "DW_CFA_GNU_args_size";
798 case DW_CFA_GNU_negative_offset_extended:
799 return "DW_CFA_GNU_negative_offset_extended";
802 return "DW_CFA_<unknown>";
806 /* Return a pointer to a newly allocated Call Frame Instruction. */
808 static inline dw_cfi_ref
811 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
813 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
814 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
819 /* Add a Call Frame Instruction to list of instructions. */
822 add_cfi (cfi_vec *vec, dw_cfi_ref cfi)
824 dw_fde_ref fde = current_fde ();
826 /* When DRAP is used, CFA is defined with an expression. Redefine
827 CFA may lead to a different CFA value. */
828 /* ??? Of course, this heuristic fails when we're annotating epilogues,
829 because of course we'll always want to redefine the CFA back to the
830 stack pointer on the way out. Where should we move this check? */
831 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
832 switch (cfi->dw_cfi_opc)
834 case DW_CFA_def_cfa_register:
835 case DW_CFA_def_cfa_offset:
836 case DW_CFA_def_cfa_offset_sf:
838 case DW_CFA_def_cfa_sf:
845 VEC_safe_push (dw_cfi_ref, gc, *vec, cfi);
848 /* Generate a new label for the CFI info to refer to. FORCE is true
849 if a label needs to be output even when using .cfi_* directives. */
852 dwarf2out_cfi_label (bool force)
854 static char label[20];
856 if (!force && dwarf2out_do_cfi_asm ())
858 /* In this case, we will be emitting the asm directive instead of
859 the label, so just return a placeholder to keep the rest of the
861 strcpy (label, "<do not output>");
865 int num = dwarf2out_cfi_label_num++;
866 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
867 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
873 /* True if remember_state should be emitted before following CFI directive. */
874 static bool emit_cfa_remember;
876 /* True if any CFI directives were emitted at the current insn. */
877 static bool any_cfis_emitted;
879 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
880 or to the CIE if LABEL is NULL. */
883 add_fde_cfi (const char *label, dw_cfi_ref cfi)
887 if (cie_cfi_vec == NULL)
888 cie_cfi_vec = VEC_alloc (dw_cfi_ref, gc, 20);
892 if (emit_cfa_remember)
894 dw_cfi_ref cfi_remember;
896 /* Emit the state save. */
897 emit_cfa_remember = false;
898 cfi_remember = new_cfi ();
899 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
900 add_fde_cfi (label, cfi_remember);
903 if (dwarf2out_do_cfi_asm ())
907 dw_fde_ref fde = current_fde ();
909 gcc_assert (fde != NULL);
911 /* We still have to add the cfi to the list so that lookup_cfa
912 works later on. When -g2 and above we even need to force
913 emitting of CFI labels and add to list a DW_CFA_set_loc for
914 convert_cfa_to_fb_loc_list purposes. If we're generating
915 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
916 convert_cfa_to_fb_loc_list. */
917 if (dwarf_version == 2
918 && debug_info_level > DINFO_LEVEL_TERSE
919 && (write_symbols == DWARF2_DEBUG
920 || write_symbols == VMS_AND_DWARF2_DEBUG))
922 switch (cfi->dw_cfi_opc)
924 case DW_CFA_def_cfa_offset:
925 case DW_CFA_def_cfa_offset_sf:
926 case DW_CFA_def_cfa_register:
928 case DW_CFA_def_cfa_sf:
929 case DW_CFA_def_cfa_expression:
930 case DW_CFA_restore_state:
931 if (*label == 0 || strcmp (label, "<do not output>") == 0)
932 label = dwarf2out_cfi_label (true);
934 if (fde->dw_fde_current_label == NULL
935 || strcmp (label, fde->dw_fde_current_label) != 0)
939 label = xstrdup (label);
941 /* Set the location counter to the new label. */
943 /* It doesn't metter whether DW_CFA_set_loc
944 or DW_CFA_advance_loc4 is added here, those aren't
945 emitted into assembly, only looked up by
946 convert_cfa_to_fb_loc_list. */
947 xcfi->dw_cfi_opc = DW_CFA_set_loc;
948 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
949 add_cfi (&fde->dw_fde_cfi, xcfi);
950 fde->dw_fde_current_label = label;
958 output_cfi_directive (cfi);
960 vec = &fde->dw_fde_cfi;
961 any_cfis_emitted = true;
963 /* ??? If this is a CFI for the CIE, we don't emit. This
964 assumes that the standard CIE contents that the assembler
965 uses matches the standard CIE contents that the compiler
966 uses. This is probably a bad assumption. I'm not quite
967 sure how to address this for now. */
971 dw_fde_ref fde = current_fde ();
973 gcc_assert (fde != NULL);
976 label = dwarf2out_cfi_label (false);
978 if (fde->dw_fde_current_label == NULL
979 || strcmp (label, fde->dw_fde_current_label) != 0)
983 label = xstrdup (label);
985 /* Set the location counter to the new label. */
987 /* If we have a current label, advance from there, otherwise
988 set the location directly using set_loc. */
989 xcfi->dw_cfi_opc = fde->dw_fde_current_label
990 ? DW_CFA_advance_loc4
992 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
993 add_cfi (&fde->dw_fde_cfi, xcfi);
995 fde->dw_fde_current_label = label;
998 vec = &fde->dw_fde_cfi;
999 any_cfis_emitted = true;
1005 /* Subroutine of lookup_cfa. */
1008 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
1010 switch (cfi->dw_cfi_opc)
1012 case DW_CFA_def_cfa_offset:
1013 case DW_CFA_def_cfa_offset_sf:
1014 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
1016 case DW_CFA_def_cfa_register:
1017 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1019 case DW_CFA_def_cfa:
1020 case DW_CFA_def_cfa_sf:
1021 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1022 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
1024 case DW_CFA_def_cfa_expression:
1025 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
1028 case DW_CFA_remember_state:
1029 gcc_assert (!remember->in_use);
1031 remember->in_use = 1;
1033 case DW_CFA_restore_state:
1034 gcc_assert (remember->in_use);
1036 remember->in_use = 0;
1044 /* Find the previous value for the CFA. */
1047 lookup_cfa (dw_cfa_location *loc)
1052 dw_cfa_location remember;
1054 memset (loc, 0, sizeof (*loc));
1055 loc->reg = INVALID_REGNUM;
1058 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
1059 lookup_cfa_1 (cfi, loc, &remember);
1061 fde = current_fde ();
1063 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
1064 lookup_cfa_1 (cfi, loc, &remember);
1067 /* The current rule for calculating the DWARF2 canonical frame address. */
1068 static dw_cfa_location cfa;
1070 /* The register used for saving registers to the stack, and its offset
1072 static dw_cfa_location cfa_store;
1074 /* The current save location around an epilogue. */
1075 static dw_cfa_location cfa_remember;
1077 /* The running total of the size of arguments pushed onto the stack. */
1078 static HOST_WIDE_INT args_size;
1080 /* The last args_size we actually output. */
1081 static HOST_WIDE_INT old_args_size;
1083 /* Entry point to update the canonical frame address (CFA).
1084 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1085 calculated from REG+OFFSET. */
1088 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1090 dw_cfa_location loc;
1092 loc.base_offset = 0;
1094 loc.offset = offset;
1095 def_cfa_1 (label, &loc);
1098 /* Determine if two dw_cfa_location structures define the same data. */
1101 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1103 return (loc1->reg == loc2->reg
1104 && loc1->offset == loc2->offset
1105 && loc1->indirect == loc2->indirect
1106 && (loc1->indirect == 0
1107 || loc1->base_offset == loc2->base_offset));
1110 /* This routine does the actual work. The CFA is now calculated from
1111 the dw_cfa_location structure. */
1114 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1117 dw_cfa_location old_cfa, loc;
1122 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1123 cfa_store.offset = loc.offset;
1125 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1126 lookup_cfa (&old_cfa);
1128 /* If nothing changed, no need to issue any call frame instructions. */
1129 if (cfa_equal_p (&loc, &old_cfa))
1134 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1136 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1137 the CFA register did not change but the offset did. The data
1138 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1139 in the assembler via the .cfi_def_cfa_offset directive. */
1141 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1143 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1144 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1147 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1148 else if (loc.offset == old_cfa.offset
1149 && old_cfa.reg != INVALID_REGNUM
1151 && !old_cfa.indirect)
1153 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1154 indicating the CFA register has changed to <register> but the
1155 offset has not changed. */
1156 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1157 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1161 else if (loc.indirect == 0)
1163 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1164 indicating the CFA register has changed to <register> with
1165 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1166 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1169 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1171 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1172 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1173 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1177 /* Construct a DW_CFA_def_cfa_expression instruction to
1178 calculate the CFA using a full location expression since no
1179 register-offset pair is available. */
1180 struct dw_loc_descr_struct *loc_list;
1182 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1183 loc_list = build_cfa_loc (&loc, 0);
1184 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1187 add_fde_cfi (label, cfi);
1190 /* Add the CFI for saving a register. REG is the CFA column number.
1191 LABEL is passed to add_fde_cfi.
1192 If SREG is -1, the register is saved at OFFSET from the CFA;
1193 otherwise it is saved in SREG. */
1196 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1198 dw_cfi_ref cfi = new_cfi ();
1199 dw_fde_ref fde = current_fde ();
1201 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1203 /* When stack is aligned, store REG using DW_CFA_expression with
1206 && fde->stack_realign
1207 && sreg == INVALID_REGNUM)
1209 cfi->dw_cfi_opc = DW_CFA_expression;
1210 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1211 cfi->dw_cfi_oprnd2.dw_cfi_loc
1212 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1214 else if (sreg == INVALID_REGNUM)
1216 if (need_data_align_sf_opcode (offset))
1217 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1218 else if (reg & ~0x3f)
1219 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1221 cfi->dw_cfi_opc = DW_CFA_offset;
1222 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1224 else if (sreg == reg)
1225 cfi->dw_cfi_opc = DW_CFA_same_value;
1228 cfi->dw_cfi_opc = DW_CFA_register;
1229 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1232 add_fde_cfi (label, cfi);
1235 /* Entry point for saving a register to the stack. REG is the GCC register
1236 number. LABEL and OFFSET are passed to reg_save. */
1239 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1241 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1244 /* Entry point for saving the return address in the stack.
1245 LABEL and OFFSET are passed to reg_save. */
1248 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1250 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1253 /* Entry point for saving the return address in a register.
1254 LABEL and SREG are passed to reg_save. */
1257 dwarf2out_return_reg (const char *label, unsigned int sreg)
1259 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1262 /* Record the initial position of the return address. RTL is
1263 INCOMING_RETURN_ADDR_RTX. */
1266 initial_return_save (rtx rtl)
1268 unsigned int reg = INVALID_REGNUM;
1269 HOST_WIDE_INT offset = 0;
1271 switch (GET_CODE (rtl))
1274 /* RA is in a register. */
1275 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1279 /* RA is on the stack. */
1280 rtl = XEXP (rtl, 0);
1281 switch (GET_CODE (rtl))
1284 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1289 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1290 offset = INTVAL (XEXP (rtl, 1));
1294 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1295 offset = -INTVAL (XEXP (rtl, 1));
1305 /* The return address is at some offset from any value we can
1306 actually load. For instance, on the SPARC it is in %i7+8. Just
1307 ignore the offset for now; it doesn't matter for unwinding frames. */
1308 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1309 initial_return_save (XEXP (rtl, 0));
1316 if (reg != DWARF_FRAME_RETURN_COLUMN)
1317 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1320 /* Given a SET, calculate the amount of stack adjustment it
1323 static HOST_WIDE_INT
1324 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1325 HOST_WIDE_INT cur_offset)
1327 const_rtx src = SET_SRC (pattern);
1328 const_rtx dest = SET_DEST (pattern);
1329 HOST_WIDE_INT offset = 0;
1332 if (dest == stack_pointer_rtx)
1334 code = GET_CODE (src);
1336 /* Assume (set (reg sp) (reg whatever)) sets args_size
1338 if (code == REG && src != stack_pointer_rtx)
1340 offset = -cur_args_size;
1341 #ifndef STACK_GROWS_DOWNWARD
1344 return offset - cur_offset;
1347 if (! (code == PLUS || code == MINUS)
1348 || XEXP (src, 0) != stack_pointer_rtx
1349 || !CONST_INT_P (XEXP (src, 1)))
1352 /* (set (reg sp) (plus (reg sp) (const_int))) */
1353 offset = INTVAL (XEXP (src, 1));
1359 if (MEM_P (src) && !MEM_P (dest))
1363 /* (set (mem (pre_dec (reg sp))) (foo)) */
1364 src = XEXP (dest, 0);
1365 code = GET_CODE (src);
1371 if (XEXP (src, 0) == stack_pointer_rtx)
1373 rtx val = XEXP (XEXP (src, 1), 1);
1374 /* We handle only adjustments by constant amount. */
1375 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1376 && CONST_INT_P (val));
1377 offset = -INTVAL (val);
1384 if (XEXP (src, 0) == stack_pointer_rtx)
1386 offset = GET_MODE_SIZE (GET_MODE (dest));
1393 if (XEXP (src, 0) == stack_pointer_rtx)
1395 offset = -GET_MODE_SIZE (GET_MODE (dest));
1410 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1411 indexed by INSN_UID. */
1413 static HOST_WIDE_INT *barrier_args_size;
1415 /* Helper function for compute_barrier_args_size. Handle one insn. */
1417 static HOST_WIDE_INT
1418 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1419 VEC (rtx, heap) **next)
1421 HOST_WIDE_INT offset = 0;
1424 if (! RTX_FRAME_RELATED_P (insn))
1426 if (prologue_epilogue_contains (insn))
1428 else if (GET_CODE (PATTERN (insn)) == SET)
1429 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1430 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1431 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1433 /* There may be stack adjustments inside compound insns. Search
1435 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1436 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1437 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1438 cur_args_size, offset);
1443 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1447 expr = XEXP (expr, 0);
1448 if (GET_CODE (expr) == PARALLEL
1449 || GET_CODE (expr) == SEQUENCE)
1450 for (i = 1; i < XVECLEN (expr, 0); i++)
1452 rtx elem = XVECEXP (expr, 0, i);
1454 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1455 offset += stack_adjust_offset (elem, cur_args_size, offset);
1460 #ifndef STACK_GROWS_DOWNWARD
1464 cur_args_size += offset;
1465 if (cur_args_size < 0)
1470 rtx dest = JUMP_LABEL (insn);
1474 if (barrier_args_size [INSN_UID (dest)] < 0)
1476 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1477 VEC_safe_push (rtx, heap, *next, dest);
1482 return cur_args_size;
1485 /* Walk the whole function and compute args_size on BARRIERs. */
1488 compute_barrier_args_size (void)
1490 int max_uid = get_max_uid (), i;
1492 VEC (rtx, heap) *worklist, *next, *tmp;
1494 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1495 for (i = 0; i < max_uid; i++)
1496 barrier_args_size[i] = -1;
1498 worklist = VEC_alloc (rtx, heap, 20);
1499 next = VEC_alloc (rtx, heap, 20);
1500 insn = get_insns ();
1501 barrier_args_size[INSN_UID (insn)] = 0;
1502 VEC_quick_push (rtx, worklist, insn);
1505 while (!VEC_empty (rtx, worklist))
1507 rtx prev, body, first_insn;
1508 HOST_WIDE_INT cur_args_size;
1510 first_insn = insn = VEC_pop (rtx, worklist);
1511 cur_args_size = barrier_args_size[INSN_UID (insn)];
1512 prev = prev_nonnote_insn (insn);
1513 if (prev && BARRIER_P (prev))
1514 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1516 for (; insn; insn = NEXT_INSN (insn))
1518 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1520 if (BARRIER_P (insn))
1525 if (insn == first_insn)
1527 else if (barrier_args_size[INSN_UID (insn)] < 0)
1529 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1534 /* The insns starting with this label have been
1535 already scanned or are in the worklist. */
1540 body = PATTERN (insn);
1541 if (GET_CODE (body) == SEQUENCE)
1543 HOST_WIDE_INT dest_args_size = cur_args_size;
1544 for (i = 1; i < XVECLEN (body, 0); i++)
1545 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1546 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1548 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1549 dest_args_size, &next);
1552 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1553 cur_args_size, &next);
1555 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1556 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1557 dest_args_size, &next);
1560 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1561 cur_args_size, &next);
1565 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1569 if (VEC_empty (rtx, next))
1572 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1576 VEC_truncate (rtx, next, 0);
1579 VEC_free (rtx, heap, worklist);
1580 VEC_free (rtx, heap, next);
1583 /* Add a CFI to update the running total of the size of arguments
1584 pushed onto the stack. */
1587 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1591 if (size == old_args_size)
1594 old_args_size = size;
1597 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1598 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1599 add_fde_cfi (label, cfi);
1602 /* Record a stack adjustment of OFFSET bytes. */
1605 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1607 if (cfa.reg == STACK_POINTER_REGNUM)
1608 cfa.offset += offset;
1610 if (cfa_store.reg == STACK_POINTER_REGNUM)
1611 cfa_store.offset += offset;
1613 if (ACCUMULATE_OUTGOING_ARGS)
1616 #ifndef STACK_GROWS_DOWNWARD
1620 args_size += offset;
1624 def_cfa_1 (label, &cfa);
1625 if (flag_asynchronous_unwind_tables)
1626 dwarf2out_args_size (label, args_size);
1629 /* Check INSN to see if it looks like a push or a stack adjustment, and
1630 make a note of it if it does. EH uses this information to find out
1631 how much extra space it needs to pop off the stack. */
1634 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1636 HOST_WIDE_INT offset;
1640 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1641 with this function. Proper support would require all frame-related
1642 insns to be marked, and to be able to handle saving state around
1643 epilogues textually in the middle of the function. */
1644 if (prologue_epilogue_contains (insn))
1647 /* If INSN is an instruction from target of an annulled branch, the
1648 effects are for the target only and so current argument size
1649 shouldn't change at all. */
1651 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1652 && INSN_FROM_TARGET_P (insn))
1655 /* If only calls can throw, and we have a frame pointer,
1656 save up adjustments until we see the CALL_INSN. */
1657 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1659 if (CALL_P (insn) && !after_p)
1661 /* Extract the size of the args from the CALL rtx itself. */
1662 insn = PATTERN (insn);
1663 if (GET_CODE (insn) == PARALLEL)
1664 insn = XVECEXP (insn, 0, 0);
1665 if (GET_CODE (insn) == SET)
1666 insn = SET_SRC (insn);
1667 gcc_assert (GET_CODE (insn) == CALL);
1668 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1673 if (CALL_P (insn) && !after_p)
1675 if (!flag_asynchronous_unwind_tables)
1676 dwarf2out_args_size ("", args_size);
1679 else if (BARRIER_P (insn))
1681 /* Don't call compute_barrier_args_size () if the only
1682 BARRIER is at the end of function. */
1683 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1684 compute_barrier_args_size ();
1685 if (barrier_args_size == NULL)
1689 offset = barrier_args_size[INSN_UID (insn)];
1694 offset -= args_size;
1695 #ifndef STACK_GROWS_DOWNWARD
1699 else if (GET_CODE (PATTERN (insn)) == SET)
1700 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1701 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1702 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1704 /* There may be stack adjustments inside compound insns. Search
1706 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1707 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1708 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1717 label = dwarf2out_cfi_label (false);
1718 dwarf2out_stack_adjust (offset, label);
1721 /* We delay emitting a register save until either (a) we reach the end
1722 of the prologue or (b) the register is clobbered. This clusters
1723 register saves so that there are fewer pc advances. */
1725 struct GTY(()) queued_reg_save {
1726 struct queued_reg_save *next;
1728 HOST_WIDE_INT cfa_offset;
1732 static GTY(()) struct queued_reg_save *queued_reg_saves;
1734 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1735 struct GTY(()) reg_saved_in_data {
1740 /* A list of registers saved in other registers.
1741 The list intentionally has a small maximum capacity of 4; if your
1742 port needs more than that, you might consider implementing a
1743 more efficient data structure. */
1744 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1745 static GTY(()) size_t num_regs_saved_in_regs;
1747 static const char *last_reg_save_label;
1749 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1750 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1753 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1755 struct queued_reg_save *q;
1757 /* Duplicates waste space, but it's also necessary to remove them
1758 for correctness, since the queue gets output in reverse
1760 for (q = queued_reg_saves; q != NULL; q = q->next)
1761 if (REGNO (q->reg) == REGNO (reg))
1766 q = ggc_alloc_queued_reg_save ();
1767 q->next = queued_reg_saves;
1768 queued_reg_saves = q;
1772 q->cfa_offset = offset;
1773 q->saved_reg = sreg;
1775 last_reg_save_label = label;
1778 /* Output all the entries in QUEUED_REG_SAVES. */
1781 dwarf2out_flush_queued_reg_saves (void)
1783 struct queued_reg_save *q;
1785 for (q = queued_reg_saves; q; q = q->next)
1788 unsigned int reg, sreg;
1790 for (i = 0; i < num_regs_saved_in_regs; i++)
1791 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1793 if (q->saved_reg && i == num_regs_saved_in_regs)
1795 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1796 num_regs_saved_in_regs++;
1798 if (i != num_regs_saved_in_regs)
1800 regs_saved_in_regs[i].orig_reg = q->reg;
1801 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1804 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1806 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1808 sreg = INVALID_REGNUM;
1809 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1812 queued_reg_saves = NULL;
1813 last_reg_save_label = NULL;
1816 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1817 location for? Or, does it clobber a register which we've previously
1818 said that some other register is saved in, and for which we now
1819 have a new location for? */
1822 clobbers_queued_reg_save (const_rtx insn)
1824 struct queued_reg_save *q;
1826 for (q = queued_reg_saves; q; q = q->next)
1829 if (modified_in_p (q->reg, insn))
1831 for (i = 0; i < num_regs_saved_in_regs; i++)
1832 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1833 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1840 /* Entry point for saving the first register into the second. */
1843 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1846 unsigned int regno, sregno;
1848 for (i = 0; i < num_regs_saved_in_regs; i++)
1849 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1851 if (i == num_regs_saved_in_regs)
1853 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1854 num_regs_saved_in_regs++;
1856 regs_saved_in_regs[i].orig_reg = reg;
1857 regs_saved_in_regs[i].saved_in_reg = sreg;
1859 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1860 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1861 reg_save (label, regno, sregno, 0);
1864 /* What register, if any, is currently saved in REG? */
1867 reg_saved_in (rtx reg)
1869 unsigned int regn = REGNO (reg);
1871 struct queued_reg_save *q;
1873 for (q = queued_reg_saves; q; q = q->next)
1874 if (q->saved_reg && regn == REGNO (q->saved_reg))
1877 for (i = 0; i < num_regs_saved_in_regs; i++)
1878 if (regs_saved_in_regs[i].saved_in_reg
1879 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1880 return regs_saved_in_regs[i].orig_reg;
1886 /* A temporary register holding an integral value used in adjusting SP
1887 or setting up the store_reg. The "offset" field holds the integer
1888 value, not an offset. */
1889 static dw_cfa_location cfa_temp;
1891 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1894 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1896 memset (&cfa, 0, sizeof (cfa));
1898 switch (GET_CODE (pat))
1901 cfa.reg = REGNO (XEXP (pat, 0));
1902 cfa.offset = INTVAL (XEXP (pat, 1));
1906 cfa.reg = REGNO (pat);
1911 pat = XEXP (pat, 0);
1912 if (GET_CODE (pat) == PLUS)
1914 cfa.base_offset = INTVAL (XEXP (pat, 1));
1915 pat = XEXP (pat, 0);
1917 cfa.reg = REGNO (pat);
1921 /* Recurse and define an expression. */
1925 def_cfa_1 (label, &cfa);
1928 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1931 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1935 gcc_assert (GET_CODE (pat) == SET);
1936 dest = XEXP (pat, 0);
1937 src = XEXP (pat, 1);
1939 switch (GET_CODE (src))
1942 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1943 cfa.offset -= INTVAL (XEXP (src, 1));
1953 cfa.reg = REGNO (dest);
1954 gcc_assert (cfa.indirect == 0);
1956 def_cfa_1 (label, &cfa);
1959 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1962 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1964 HOST_WIDE_INT offset;
1965 rtx src, addr, span;
1967 src = XEXP (set, 1);
1968 addr = XEXP (set, 0);
1969 gcc_assert (MEM_P (addr));
1970 addr = XEXP (addr, 0);
1972 /* As documented, only consider extremely simple addresses. */
1973 switch (GET_CODE (addr))
1976 gcc_assert (REGNO (addr) == cfa.reg);
1977 offset = -cfa.offset;
1980 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1981 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1987 span = targetm.dwarf_register_span (src);
1989 /* ??? We'd like to use queue_reg_save, but we need to come up with
1990 a different flushing heuristic for epilogues. */
1992 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1995 /* We have a PARALLEL describing where the contents of SRC live.
1996 Queue register saves for each piece of the PARALLEL. */
1999 HOST_WIDE_INT span_offset = offset;
2001 gcc_assert (GET_CODE (span) == PARALLEL);
2003 limit = XVECLEN (span, 0);
2004 for (par_index = 0; par_index < limit; par_index++)
2006 rtx elem = XVECEXP (span, 0, par_index);
2008 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2009 INVALID_REGNUM, span_offset);
2010 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2015 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2018 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2021 unsigned sregno, dregno;
2023 src = XEXP (set, 1);
2024 dest = XEXP (set, 0);
2027 sregno = DWARF_FRAME_RETURN_COLUMN;
2029 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2031 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2033 /* ??? We'd like to use queue_reg_save, but we need to come up with
2034 a different flushing heuristic for epilogues. */
2035 reg_save (label, sregno, dregno, 0);
2038 /* Helper function to get mode of MEM's address. */
2040 static inline enum machine_mode
2041 get_address_mode (rtx mem)
2043 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
2044 if (mode != VOIDmode)
2046 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
2049 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2052 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2054 rtx src, dest, span;
2055 dw_cfi_ref cfi = new_cfi ();
2057 dest = SET_DEST (set);
2058 src = SET_SRC (set);
2060 gcc_assert (REG_P (src));
2061 gcc_assert (MEM_P (dest));
2063 span = targetm.dwarf_register_span (src);
2066 cfi->dw_cfi_opc = DW_CFA_expression;
2067 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2068 cfi->dw_cfi_oprnd2.dw_cfi_loc
2069 = mem_loc_descriptor (XEXP (dest, 0), get_address_mode (dest),
2070 GET_MODE (dest), VAR_INIT_STATUS_INITIALIZED);
2072 /* ??? We'd like to use queue_reg_save, were the interface different,
2073 and, as above, we could manage flushing for epilogues. */
2074 add_fde_cfi (label, cfi);
2077 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2080 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2082 dw_cfi_ref cfi = new_cfi ();
2083 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2085 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2086 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2088 add_fde_cfi (label, cfi);
2091 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE.
2092 ??? Perhaps we should note in the CIE where windows are saved (instead of
2093 assuming 0(cfa)) and what registers are in the window. */
2096 dwarf2out_frame_debug_cfa_window_save (const char *label)
2098 dw_cfi_ref cfi = new_cfi ();
2100 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
2101 add_fde_cfi (label, cfi);
2104 /* Record call frame debugging information for an expression EXPR,
2105 which either sets SP or FP (adjusting how we calculate the frame
2106 address) or saves a register to the stack or another register.
2107 LABEL indicates the address of EXPR.
2109 This function encodes a state machine mapping rtxes to actions on
2110 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2111 users need not read the source code.
2113 The High-Level Picture
2115 Changes in the register we use to calculate the CFA: Currently we
2116 assume that if you copy the CFA register into another register, we
2117 should take the other one as the new CFA register; this seems to
2118 work pretty well. If it's wrong for some target, it's simple
2119 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2121 Changes in the register we use for saving registers to the stack:
2122 This is usually SP, but not always. Again, we deduce that if you
2123 copy SP into another register (and SP is not the CFA register),
2124 then the new register is the one we will be using for register
2125 saves. This also seems to work.
2127 Register saves: There's not much guesswork about this one; if
2128 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2129 register save, and the register used to calculate the destination
2130 had better be the one we think we're using for this purpose.
2131 It's also assumed that a copy from a call-saved register to another
2132 register is saving that register if RTX_FRAME_RELATED_P is set on
2133 that instruction. If the copy is from a call-saved register to
2134 the *same* register, that means that the register is now the same
2135 value as in the caller.
2137 Except: If the register being saved is the CFA register, and the
2138 offset is nonzero, we are saving the CFA, so we assume we have to
2139 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2140 the intent is to save the value of SP from the previous frame.
2142 In addition, if a register has previously been saved to a different
2145 Invariants / Summaries of Rules
2147 cfa current rule for calculating the CFA. It usually
2148 consists of a register and an offset.
2149 cfa_store register used by prologue code to save things to the stack
2150 cfa_store.offset is the offset from the value of
2151 cfa_store.reg to the actual CFA
2152 cfa_temp register holding an integral value. cfa_temp.offset
2153 stores the value, which will be used to adjust the
2154 stack pointer. cfa_temp is also used like cfa_store,
2155 to track stores to the stack via fp or a temp reg.
2157 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2158 with cfa.reg as the first operand changes the cfa.reg and its
2159 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2162 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2163 expression yielding a constant. This sets cfa_temp.reg
2164 and cfa_temp.offset.
2166 Rule 5: Create a new register cfa_store used to save items to the
2169 Rules 10-14: Save a register to the stack. Define offset as the
2170 difference of the original location and cfa_store's
2171 location (or cfa_temp's location if cfa_temp is used).
2173 Rules 16-20: If AND operation happens on sp in prologue, we assume
2174 stack is realigned. We will use a group of DW_OP_XXX
2175 expressions to represent the location of the stored
2176 register instead of CFA+offset.
2180 "{a,b}" indicates a choice of a xor b.
2181 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2184 (set <reg1> <reg2>:cfa.reg)
2185 effects: cfa.reg = <reg1>
2186 cfa.offset unchanged
2187 cfa_temp.reg = <reg1>
2188 cfa_temp.offset = cfa.offset
2191 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2192 {<const_int>,<reg>:cfa_temp.reg}))
2193 effects: cfa.reg = sp if fp used
2194 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2195 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2196 if cfa_store.reg==sp
2199 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2200 effects: cfa.reg = fp
2201 cfa_offset += +/- <const_int>
2204 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2205 constraints: <reg1> != fp
2207 effects: cfa.reg = <reg1>
2208 cfa_temp.reg = <reg1>
2209 cfa_temp.offset = cfa.offset
2212 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2213 constraints: <reg1> != fp
2215 effects: cfa_store.reg = <reg1>
2216 cfa_store.offset = cfa.offset - cfa_temp.offset
2219 (set <reg> <const_int>)
2220 effects: cfa_temp.reg = <reg>
2221 cfa_temp.offset = <const_int>
2224 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2225 effects: cfa_temp.reg = <reg1>
2226 cfa_temp.offset |= <const_int>
2229 (set <reg> (high <exp>))
2233 (set <reg> (lo_sum <exp> <const_int>))
2234 effects: cfa_temp.reg = <reg>
2235 cfa_temp.offset = <const_int>
2238 (set (mem ({pre,post}_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2239 effects: cfa_store.offset -= <const_int>
2240 cfa.offset = cfa_store.offset if cfa.reg == sp
2242 cfa.base_offset = -cfa_store.offset
2245 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2246 effects: cfa_store.offset += -/+ mode_size(mem)
2247 cfa.offset = cfa_store.offset if cfa.reg == sp
2249 cfa.base_offset = -cfa_store.offset
2252 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2255 effects: cfa.reg = <reg1>
2256 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2259 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2260 effects: cfa.reg = <reg1>
2261 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2264 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2265 effects: cfa.reg = <reg1>
2266 cfa.base_offset = -cfa_temp.offset
2267 cfa_temp.offset -= mode_size(mem)
2270 (set <reg> {unspec, unspec_volatile})
2271 effects: target-dependent
2274 (set sp (and: sp <const_int>))
2275 constraints: cfa_store.reg == sp
2276 effects: current_fde.stack_realign = 1
2277 cfa_store.offset = 0
2278 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2281 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2282 effects: cfa_store.offset += -/+ mode_size(mem)
2285 (set (mem ({pre_inc, pre_dec} sp)) fp)
2286 constraints: fde->stack_realign == 1
2287 effects: cfa_store.offset = 0
2288 cfa.reg != HARD_FRAME_POINTER_REGNUM
2291 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2292 constraints: fde->stack_realign == 1
2294 && cfa.indirect == 0
2295 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2296 effects: Use DW_CFA_def_cfa_expression to define cfa
2297 cfa.reg == fde->drap_reg */
2300 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2302 rtx src, dest, span;
2303 HOST_WIDE_INT offset;
2306 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2307 the PARALLEL independently. The first element is always processed if
2308 it is a SET. This is for backward compatibility. Other elements
2309 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2310 flag is set in them. */
2311 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2314 int limit = XVECLEN (expr, 0);
2317 /* PARALLELs have strict read-modify-write semantics, so we
2318 ought to evaluate every rvalue before changing any lvalue.
2319 It's cumbersome to do that in general, but there's an
2320 easy approximation that is enough for all current users:
2321 handle register saves before register assignments. */
2322 if (GET_CODE (expr) == PARALLEL)
2323 for (par_index = 0; par_index < limit; par_index++)
2325 elem = XVECEXP (expr, 0, par_index);
2326 if (GET_CODE (elem) == SET
2327 && MEM_P (SET_DEST (elem))
2328 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2329 dwarf2out_frame_debug_expr (elem, label);
2332 for (par_index = 0; par_index < limit; par_index++)
2334 elem = XVECEXP (expr, 0, par_index);
2335 if (GET_CODE (elem) == SET
2336 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2337 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2338 dwarf2out_frame_debug_expr (elem, label);
2339 else if (GET_CODE (elem) == SET
2341 && !RTX_FRAME_RELATED_P (elem))
2343 /* Stack adjustment combining might combine some post-prologue
2344 stack adjustment into a prologue stack adjustment. */
2345 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2348 dwarf2out_stack_adjust (offset, label);
2354 gcc_assert (GET_CODE (expr) == SET);
2356 src = SET_SRC (expr);
2357 dest = SET_DEST (expr);
2361 rtx rsi = reg_saved_in (src);
2366 fde = current_fde ();
2368 switch (GET_CODE (dest))
2371 switch (GET_CODE (src))
2373 /* Setting FP from SP. */
2375 if (cfa.reg == (unsigned) REGNO (src))
2378 /* Update the CFA rule wrt SP or FP. Make sure src is
2379 relative to the current CFA register.
2381 We used to require that dest be either SP or FP, but the
2382 ARM copies SP to a temporary register, and from there to
2383 FP. So we just rely on the backends to only set
2384 RTX_FRAME_RELATED_P on appropriate insns. */
2385 cfa.reg = REGNO (dest);
2386 cfa_temp.reg = cfa.reg;
2387 cfa_temp.offset = cfa.offset;
2391 /* Saving a register in a register. */
2392 gcc_assert (!fixed_regs [REGNO (dest)]
2393 /* For the SPARC and its register window. */
2394 || (DWARF_FRAME_REGNUM (REGNO (src))
2395 == DWARF_FRAME_RETURN_COLUMN));
2397 /* After stack is aligned, we can only save SP in FP
2398 if drap register is used. In this case, we have
2399 to restore stack pointer with the CFA value and we
2400 don't generate this DWARF information. */
2402 && fde->stack_realign
2403 && REGNO (src) == STACK_POINTER_REGNUM)
2404 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2405 && fde->drap_reg != INVALID_REGNUM
2406 && cfa.reg != REGNO (src));
2408 queue_reg_save (label, src, dest, 0);
2415 if (dest == stack_pointer_rtx)
2419 switch (GET_CODE (XEXP (src, 1)))
2422 offset = INTVAL (XEXP (src, 1));
2425 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2427 offset = cfa_temp.offset;
2433 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2435 /* Restoring SP from FP in the epilogue. */
2436 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2437 cfa.reg = STACK_POINTER_REGNUM;
2439 else if (GET_CODE (src) == LO_SUM)
2440 /* Assume we've set the source reg of the LO_SUM from sp. */
2443 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2445 if (GET_CODE (src) != MINUS)
2447 if (cfa.reg == STACK_POINTER_REGNUM)
2448 cfa.offset += offset;
2449 if (cfa_store.reg == STACK_POINTER_REGNUM)
2450 cfa_store.offset += offset;
2452 else if (dest == hard_frame_pointer_rtx)
2455 /* Either setting the FP from an offset of the SP,
2456 or adjusting the FP */
2457 gcc_assert (frame_pointer_needed);
2459 gcc_assert (REG_P (XEXP (src, 0))
2460 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2461 && CONST_INT_P (XEXP (src, 1)));
2462 offset = INTVAL (XEXP (src, 1));
2463 if (GET_CODE (src) != MINUS)
2465 cfa.offset += offset;
2466 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2470 gcc_assert (GET_CODE (src) != MINUS);
2473 if (REG_P (XEXP (src, 0))
2474 && REGNO (XEXP (src, 0)) == cfa.reg
2475 && CONST_INT_P (XEXP (src, 1)))
2477 /* Setting a temporary CFA register that will be copied
2478 into the FP later on. */
2479 offset = - INTVAL (XEXP (src, 1));
2480 cfa.offset += offset;
2481 cfa.reg = REGNO (dest);
2482 /* Or used to save regs to the stack. */
2483 cfa_temp.reg = cfa.reg;
2484 cfa_temp.offset = cfa.offset;
2488 else if (REG_P (XEXP (src, 0))
2489 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2490 && XEXP (src, 1) == stack_pointer_rtx)
2492 /* Setting a scratch register that we will use instead
2493 of SP for saving registers to the stack. */
2494 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2495 cfa_store.reg = REGNO (dest);
2496 cfa_store.offset = cfa.offset - cfa_temp.offset;
2500 else if (GET_CODE (src) == LO_SUM
2501 && CONST_INT_P (XEXP (src, 1)))
2503 cfa_temp.reg = REGNO (dest);
2504 cfa_temp.offset = INTVAL (XEXP (src, 1));
2513 cfa_temp.reg = REGNO (dest);
2514 cfa_temp.offset = INTVAL (src);
2519 gcc_assert (REG_P (XEXP (src, 0))
2520 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2521 && CONST_INT_P (XEXP (src, 1)));
2523 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2524 cfa_temp.reg = REGNO (dest);
2525 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2528 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2529 which will fill in all of the bits. */
2536 case UNSPEC_VOLATILE:
2537 gcc_assert (targetm.dwarf_handle_frame_unspec);
2538 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2543 /* If this AND operation happens on stack pointer in prologue,
2544 we assume the stack is realigned and we extract the
2546 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2548 /* We interpret reg_save differently with stack_realign set.
2549 Thus we must flush whatever we have queued first. */
2550 dwarf2out_flush_queued_reg_saves ();
2552 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2553 fde->stack_realign = 1;
2554 fde->stack_realignment = INTVAL (XEXP (src, 1));
2555 cfa_store.offset = 0;
2557 if (cfa.reg != STACK_POINTER_REGNUM
2558 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2559 fde->drap_reg = cfa.reg;
2567 def_cfa_1 (label, &cfa);
2572 /* Saving a register to the stack. Make sure dest is relative to the
2574 switch (GET_CODE (XEXP (dest, 0)))
2580 /* We can't handle variable size modifications. */
2581 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2583 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2585 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2586 && cfa_store.reg == STACK_POINTER_REGNUM);
2588 cfa_store.offset += offset;
2589 if (cfa.reg == STACK_POINTER_REGNUM)
2590 cfa.offset = cfa_store.offset;
2592 if (GET_CODE (XEXP (dest, 0)) == POST_MODIFY)
2593 offset -= cfa_store.offset;
2595 offset = -cfa_store.offset;
2602 offset = GET_MODE_SIZE (GET_MODE (dest));
2603 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2606 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2607 == STACK_POINTER_REGNUM)
2608 && cfa_store.reg == STACK_POINTER_REGNUM);
2610 cfa_store.offset += offset;
2612 /* Rule 18: If stack is aligned, we will use FP as a
2613 reference to represent the address of the stored
2616 && fde->stack_realign
2617 && src == hard_frame_pointer_rtx)
2619 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2620 cfa_store.offset = 0;
2623 if (cfa.reg == STACK_POINTER_REGNUM)
2624 cfa.offset = cfa_store.offset;
2626 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
2627 offset += -cfa_store.offset;
2629 offset = -cfa_store.offset;
2633 /* With an offset. */
2640 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2641 && REG_P (XEXP (XEXP (dest, 0), 0)));
2642 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2643 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2646 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2648 if (cfa.reg == (unsigned) regno)
2649 offset -= cfa.offset;
2650 else if (cfa_store.reg == (unsigned) regno)
2651 offset -= cfa_store.offset;
2654 gcc_assert (cfa_temp.reg == (unsigned) regno);
2655 offset -= cfa_temp.offset;
2661 /* Without an offset. */
2664 int regno = REGNO (XEXP (dest, 0));
2666 if (cfa.reg == (unsigned) regno)
2667 offset = -cfa.offset;
2668 else if (cfa_store.reg == (unsigned) regno)
2669 offset = -cfa_store.offset;
2672 gcc_assert (cfa_temp.reg == (unsigned) regno);
2673 offset = -cfa_temp.offset;
2680 gcc_assert (cfa_temp.reg
2681 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2682 offset = -cfa_temp.offset;
2683 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2691 /* If the source operand of this MEM operation is not a
2692 register, basically the source is return address. Here
2693 we only care how much stack grew and we don't save it. */
2697 if (REGNO (src) != STACK_POINTER_REGNUM
2698 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2699 && (unsigned) REGNO (src) == cfa.reg)
2701 /* We're storing the current CFA reg into the stack. */
2703 if (cfa.offset == 0)
2706 /* If stack is aligned, putting CFA reg into stack means
2707 we can no longer use reg + offset to represent CFA.
2708 Here we use DW_CFA_def_cfa_expression instead. The
2709 result of this expression equals to the original CFA
2712 && fde->stack_realign
2713 && cfa.indirect == 0
2714 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2716 dw_cfa_location cfa_exp;
2718 gcc_assert (fde->drap_reg == cfa.reg);
2720 cfa_exp.indirect = 1;
2721 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2722 cfa_exp.base_offset = offset;
2725 fde->drap_reg_saved = 1;
2727 def_cfa_1 (label, &cfa_exp);
2731 /* If the source register is exactly the CFA, assume
2732 we're saving SP like any other register; this happens
2734 def_cfa_1 (label, &cfa);
2735 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2740 /* Otherwise, we'll need to look in the stack to
2741 calculate the CFA. */
2742 rtx x = XEXP (dest, 0);
2746 gcc_assert (REG_P (x));
2748 cfa.reg = REGNO (x);
2749 cfa.base_offset = offset;
2751 def_cfa_1 (label, &cfa);
2756 def_cfa_1 (label, &cfa);
2758 span = targetm.dwarf_register_span (src);
2761 queue_reg_save (label, src, NULL_RTX, offset);
2764 /* We have a PARALLEL describing where the contents of SRC
2765 live. Queue register saves for each piece of the
2769 HOST_WIDE_INT span_offset = offset;
2771 gcc_assert (GET_CODE (span) == PARALLEL);
2773 limit = XVECLEN (span, 0);
2774 for (par_index = 0; par_index < limit; par_index++)
2776 rtx elem = XVECEXP (span, 0, par_index);
2778 queue_reg_save (label, elem, NULL_RTX, span_offset);
2779 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2790 /* Record call frame debugging information for INSN, which either
2791 sets SP or FP (adjusting how we calculate the frame address) or saves a
2792 register to the stack. If INSN is NULL_RTX, initialize our state.
2794 If AFTER_P is false, we're being called before the insn is emitted,
2795 otherwise after. Call instructions get invoked twice. */
2798 dwarf2out_frame_debug (rtx insn, bool after_p)
2802 bool handled_one = false;
2804 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2805 dwarf2out_flush_queued_reg_saves ();
2807 if (!RTX_FRAME_RELATED_P (insn))
2809 /* ??? This should be done unconditionally since stack adjustments
2810 matter if the stack pointer is not the CFA register anymore but
2811 is still used to save registers. */
2812 if (!ACCUMULATE_OUTGOING_ARGS)
2813 dwarf2out_notice_stack_adjust (insn, after_p);
2817 label = dwarf2out_cfi_label (false);
2818 any_cfis_emitted = false;
2820 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2821 switch (REG_NOTE_KIND (note))
2823 case REG_FRAME_RELATED_EXPR:
2824 insn = XEXP (note, 0);
2827 case REG_CFA_DEF_CFA:
2828 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2832 case REG_CFA_ADJUST_CFA:
2837 if (GET_CODE (n) == PARALLEL)
2838 n = XVECEXP (n, 0, 0);
2840 dwarf2out_frame_debug_adjust_cfa (n, label);
2844 case REG_CFA_OFFSET:
2847 n = single_set (insn);
2848 dwarf2out_frame_debug_cfa_offset (n, label);
2852 case REG_CFA_REGISTER:
2857 if (GET_CODE (n) == PARALLEL)
2858 n = XVECEXP (n, 0, 0);
2860 dwarf2out_frame_debug_cfa_register (n, label);
2864 case REG_CFA_EXPRESSION:
2867 n = single_set (insn);
2868 dwarf2out_frame_debug_cfa_expression (n, label);
2872 case REG_CFA_RESTORE:
2877 if (GET_CODE (n) == PARALLEL)
2878 n = XVECEXP (n, 0, 0);
2881 dwarf2out_frame_debug_cfa_restore (n, label);
2885 case REG_CFA_SET_VDRAP:
2889 dw_fde_ref fde = current_fde ();
2892 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2894 fde->vdrap_reg = REGNO (n);
2900 case REG_CFA_WINDOW_SAVE:
2901 dwarf2out_frame_debug_cfa_window_save (label);
2910 if (any_cfis_emitted)
2911 dwarf2out_flush_queued_reg_saves ();
2915 insn = PATTERN (insn);
2917 dwarf2out_frame_debug_expr (insn, label);
2919 /* Check again. A parallel can save and update the same register.
2920 We could probably check just once, here, but this is safer than
2921 removing the check above. */
2922 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2923 dwarf2out_flush_queued_reg_saves ();
2926 /* Called once at the start of final to initialize some data for the
2927 current function. */
2929 dwarf2out_frame_debug_init (void)
2933 /* Flush any queued register saves. */
2934 dwarf2out_flush_queued_reg_saves ();
2936 /* Set up state for generating call frame debug info. */
2939 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2941 cfa.reg = STACK_POINTER_REGNUM;
2944 cfa_temp.offset = 0;
2946 for (i = 0; i < num_regs_saved_in_regs; i++)
2948 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2949 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2951 num_regs_saved_in_regs = 0;
2953 if (barrier_args_size)
2955 XDELETEVEC (barrier_args_size);
2956 barrier_args_size = NULL;
2960 /* Determine if we need to save and restore CFI information around this
2961 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2962 we do need to save/restore, then emit the save now, and insert a
2963 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2966 dwarf2out_cfi_begin_epilogue (rtx insn)
2968 bool saw_frp = false;
2971 /* Scan forward to the return insn, noticing if there are possible
2972 frame related insns. */
2973 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2978 /* Look for both regular and sibcalls to end the block. */
2979 if (returnjump_p (i))
2981 if (CALL_P (i) && SIBLING_CALL_P (i))
2984 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2987 rtx seq = PATTERN (i);
2989 if (returnjump_p (XVECEXP (seq, 0, 0)))
2991 if (CALL_P (XVECEXP (seq, 0, 0))
2992 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2995 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2996 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
3000 if (RTX_FRAME_RELATED_P (i))
3004 /* If the port doesn't emit epilogue unwind info, we don't need a
3005 save/restore pair. */
3009 /* Otherwise, search forward to see if the return insn was the last
3010 basic block of the function. If so, we don't need save/restore. */
3011 gcc_assert (i != NULL);
3012 i = next_real_insn (i);
3016 /* Insert the restore before that next real insn in the stream, and before
3017 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3018 properly nested. This should be after any label or alignment. This
3019 will be pushed into the CFI stream by the function below. */
3022 rtx p = PREV_INSN (i);
3025 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3029 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3031 emit_cfa_remember = true;
3033 /* And emulate the state save. */
3034 gcc_assert (!cfa_remember.in_use);
3036 cfa_remember.in_use = 1;
3039 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3043 dwarf2out_frame_debug_restore_state (void)
3045 dw_cfi_ref cfi = new_cfi ();
3046 const char *label = dwarf2out_cfi_label (false);
3048 cfi->dw_cfi_opc = DW_CFA_restore_state;
3049 add_fde_cfi (label, cfi);
3051 gcc_assert (cfa_remember.in_use);
3053 cfa_remember.in_use = 0;
3056 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3057 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3058 (enum dwarf_call_frame_info cfi);
3060 static enum dw_cfi_oprnd_type
3061 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3066 case DW_CFA_GNU_window_save:
3067 case DW_CFA_remember_state:
3068 case DW_CFA_restore_state:
3069 return dw_cfi_oprnd_unused;
3071 case DW_CFA_set_loc:
3072 case DW_CFA_advance_loc1:
3073 case DW_CFA_advance_loc2:
3074 case DW_CFA_advance_loc4:
3075 case DW_CFA_MIPS_advance_loc8:
3076 return dw_cfi_oprnd_addr;
3079 case DW_CFA_offset_extended:
3080 case DW_CFA_def_cfa:
3081 case DW_CFA_offset_extended_sf:
3082 case DW_CFA_def_cfa_sf:
3083 case DW_CFA_restore:
3084 case DW_CFA_restore_extended:
3085 case DW_CFA_undefined:
3086 case DW_CFA_same_value:
3087 case DW_CFA_def_cfa_register:
3088 case DW_CFA_register:
3089 case DW_CFA_expression:
3090 return dw_cfi_oprnd_reg_num;
3092 case DW_CFA_def_cfa_offset:
3093 case DW_CFA_GNU_args_size:
3094 case DW_CFA_def_cfa_offset_sf:
3095 return dw_cfi_oprnd_offset;
3097 case DW_CFA_def_cfa_expression:
3098 return dw_cfi_oprnd_loc;
3105 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3106 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3107 (enum dwarf_call_frame_info cfi);
3109 static enum dw_cfi_oprnd_type
3110 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3114 case DW_CFA_def_cfa:
3115 case DW_CFA_def_cfa_sf:
3117 case DW_CFA_offset_extended_sf:
3118 case DW_CFA_offset_extended:
3119 return dw_cfi_oprnd_offset;
3121 case DW_CFA_register:
3122 return dw_cfi_oprnd_reg_num;
3124 case DW_CFA_expression:
3125 return dw_cfi_oprnd_loc;
3128 return dw_cfi_oprnd_unused;
3132 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3133 switch to the data section instead, and write out a synthetic start label
3134 for collect2 the first time around. */
3137 switch_to_eh_frame_section (bool back)
3141 #ifdef EH_FRAME_SECTION_NAME
3142 if (eh_frame_section == 0)
3146 if (EH_TABLES_CAN_BE_READ_ONLY)
3152 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3154 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3156 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3158 flags = ((! flag_pic
3159 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3160 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3161 && (per_encoding & 0x70) != DW_EH_PE_absptr
3162 && (per_encoding & 0x70) != DW_EH_PE_aligned
3163 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3164 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3165 ? 0 : SECTION_WRITE);
3168 flags = SECTION_WRITE;
3169 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3171 #endif /* EH_FRAME_SECTION_NAME */
3173 if (eh_frame_section)
3174 switch_to_section (eh_frame_section);
3177 /* We have no special eh_frame section. Put the information in
3178 the data section and emit special labels to guide collect2. */
3179 switch_to_section (data_section);
3183 label = get_file_function_name ("F");
3184 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3185 targetm.asm_out.globalize_label (asm_out_file,
3186 IDENTIFIER_POINTER (label));
3187 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3192 /* Switch [BACK] to the eh or debug frame table section, depending on
3196 switch_to_frame_table_section (int for_eh, bool back)
3199 switch_to_eh_frame_section (back);
3202 if (!debug_frame_section)
3203 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3204 SECTION_DEBUG, NULL);
3205 switch_to_section (debug_frame_section);
3209 /* Output a Call Frame Information opcode and its operand(s). */
3212 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3217 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3218 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3219 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3220 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3221 ((unsigned HOST_WIDE_INT)
3222 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3223 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3225 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3226 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3227 "DW_CFA_offset, column %#lx", r);
3228 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3229 dw2_asm_output_data_uleb128 (off, NULL);
3231 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3233 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3234 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3235 "DW_CFA_restore, column %#lx", r);
3239 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3240 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3242 switch (cfi->dw_cfi_opc)
3244 case DW_CFA_set_loc:
3246 dw2_asm_output_encoded_addr_rtx (
3247 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3248 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3251 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3252 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3253 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3256 case DW_CFA_advance_loc1:
3257 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3258 fde->dw_fde_current_label, NULL);
3259 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3262 case DW_CFA_advance_loc2:
3263 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3264 fde->dw_fde_current_label, NULL);
3265 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3268 case DW_CFA_advance_loc4:
3269 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3270 fde->dw_fde_current_label, NULL);
3271 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3274 case DW_CFA_MIPS_advance_loc8:
3275 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3276 fde->dw_fde_current_label, NULL);
3277 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3280 case DW_CFA_offset_extended:
3281 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3282 dw2_asm_output_data_uleb128 (r, NULL);
3283 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3284 dw2_asm_output_data_uleb128 (off, NULL);
3287 case DW_CFA_def_cfa:
3288 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3289 dw2_asm_output_data_uleb128 (r, NULL);
3290 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3293 case DW_CFA_offset_extended_sf:
3294 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3295 dw2_asm_output_data_uleb128 (r, NULL);
3296 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3297 dw2_asm_output_data_sleb128 (off, NULL);
3300 case DW_CFA_def_cfa_sf:
3301 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3302 dw2_asm_output_data_uleb128 (r, NULL);
3303 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3304 dw2_asm_output_data_sleb128 (off, NULL);
3307 case DW_CFA_restore_extended:
3308 case DW_CFA_undefined:
3309 case DW_CFA_same_value:
3310 case DW_CFA_def_cfa_register:
3311 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3312 dw2_asm_output_data_uleb128 (r, NULL);
3315 case DW_CFA_register:
3316 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3317 dw2_asm_output_data_uleb128 (r, NULL);
3318 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3319 dw2_asm_output_data_uleb128 (r, NULL);
3322 case DW_CFA_def_cfa_offset:
3323 case DW_CFA_GNU_args_size:
3324 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3327 case DW_CFA_def_cfa_offset_sf:
3328 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3329 dw2_asm_output_data_sleb128 (off, NULL);
3332 case DW_CFA_GNU_window_save:
3335 case DW_CFA_def_cfa_expression:
3336 case DW_CFA_expression:
3337 output_cfa_loc (cfi, for_eh);
3340 case DW_CFA_GNU_negative_offset_extended:
3341 /* Obsoleted by DW_CFA_offset_extended_sf. */
3350 /* Similar, but do it via assembler directives instead. */
3353 output_cfi_directive (dw_cfi_ref cfi)
3355 unsigned long r, r2;
3357 switch (cfi->dw_cfi_opc)
3359 case DW_CFA_advance_loc:
3360 case DW_CFA_advance_loc1:
3361 case DW_CFA_advance_loc2:
3362 case DW_CFA_advance_loc4:
3363 case DW_CFA_MIPS_advance_loc8:
3364 case DW_CFA_set_loc:
3365 /* Should only be created by add_fde_cfi in a code path not
3366 followed when emitting via directives. The assembler is
3367 going to take care of this for us. */
3371 case DW_CFA_offset_extended:
3372 case DW_CFA_offset_extended_sf:
3373 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3374 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3375 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3378 case DW_CFA_restore:
3379 case DW_CFA_restore_extended:
3380 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3381 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3384 case DW_CFA_undefined:
3385 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3386 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3389 case DW_CFA_same_value:
3390 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3391 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3394 case DW_CFA_def_cfa:
3395 case DW_CFA_def_cfa_sf:
3396 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3397 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3398 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3401 case DW_CFA_def_cfa_register:
3402 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3403 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3406 case DW_CFA_register:
3407 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3408 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3409 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3412 case DW_CFA_def_cfa_offset:
3413 case DW_CFA_def_cfa_offset_sf:
3414 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3415 HOST_WIDE_INT_PRINT_DEC"\n",
3416 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3419 case DW_CFA_remember_state:
3420 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3422 case DW_CFA_restore_state:
3423 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3426 case DW_CFA_GNU_args_size:
3427 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3428 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3430 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3431 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3432 fputc ('\n', asm_out_file);
3435 case DW_CFA_GNU_window_save:
3436 fprintf (asm_out_file, "\t.cfi_window_save\n");
3439 case DW_CFA_def_cfa_expression:
3440 case DW_CFA_expression:
3441 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3442 output_cfa_loc_raw (cfi);
3443 fputc ('\n', asm_out_file);
3451 /* Output CFIs from VEC, up to index UPTO, to bring current FDE to the
3452 same state as after executing CFIs in CFI chain. DO_CFI_ASM is
3453 true if .cfi_* directives shall be emitted, false otherwise. If it
3454 is false, FDE and FOR_EH are the other arguments to pass to
3458 output_cfis (cfi_vec vec, int upto, bool do_cfi_asm,
3459 dw_fde_ref fde, bool for_eh)
3462 struct dw_cfi_struct cfi_buf;
3464 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3465 VEC(dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3466 unsigned int len, idx;
3468 for (ix = 0; ix < upto + 1; ix++)
3470 dw_cfi_ref cfi = ix < upto ? VEC_index (dw_cfi_ref, vec, ix) : NULL;
3471 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3473 case DW_CFA_advance_loc:
3474 case DW_CFA_advance_loc1:
3475 case DW_CFA_advance_loc2:
3476 case DW_CFA_advance_loc4:
3477 case DW_CFA_MIPS_advance_loc8:
3478 case DW_CFA_set_loc:
3479 /* All advances should be ignored. */
3481 case DW_CFA_remember_state:
3483 dw_cfi_ref args_size = cfi_args_size;
3485 /* Skip everything between .cfi_remember_state and
3486 .cfi_restore_state. */
3491 for (; ix < upto; ix++)
3493 cfi2 = VEC_index (dw_cfi_ref, vec, ix);
3494 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3496 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3499 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3502 cfi_args_size = args_size;
3505 case DW_CFA_GNU_args_size:
3506 cfi_args_size = cfi;
3508 case DW_CFA_GNU_window_save:
3511 case DW_CFA_offset_extended:
3512 case DW_CFA_offset_extended_sf:
3513 case DW_CFA_restore:
3514 case DW_CFA_restore_extended:
3515 case DW_CFA_undefined:
3516 case DW_CFA_same_value:
3517 case DW_CFA_register:
3518 case DW_CFA_val_offset:
3519 case DW_CFA_val_offset_sf:
3520 case DW_CFA_expression:
3521 case DW_CFA_val_expression:
3522 case DW_CFA_GNU_negative_offset_extended:
3523 if (VEC_length (dw_cfi_ref, regs)
3524 <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3525 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3526 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3527 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
3530 case DW_CFA_def_cfa:
3531 case DW_CFA_def_cfa_sf:
3532 case DW_CFA_def_cfa_expression:
3534 cfi_cfa_offset = cfi;
3536 case DW_CFA_def_cfa_register:
3539 case DW_CFA_def_cfa_offset:
3540 case DW_CFA_def_cfa_offset_sf:
3541 cfi_cfa_offset = cfi;
3544 gcc_assert (cfi == NULL);
3546 len = VEC_length (dw_cfi_ref, regs);
3547 for (idx = 0; idx < len; idx++)
3549 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3551 && cfi2->dw_cfi_opc != DW_CFA_restore
3552 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3555 output_cfi_directive (cfi2);
3557 output_cfi (cfi2, fde, for_eh);
3560 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3562 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3564 switch (cfi_cfa_offset->dw_cfi_opc)
3566 case DW_CFA_def_cfa_offset:
3567 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3568 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3570 case DW_CFA_def_cfa_offset_sf:
3571 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3572 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3574 case DW_CFA_def_cfa:
3575 case DW_CFA_def_cfa_sf:
3576 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3577 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3584 else if (cfi_cfa_offset)
3585 cfi_cfa = cfi_cfa_offset;
3589 output_cfi_directive (cfi_cfa);
3591 output_cfi (cfi_cfa, fde, for_eh);
3594 cfi_cfa_offset = NULL;
3596 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3599 output_cfi_directive (cfi_args_size);
3601 output_cfi (cfi_args_size, fde, for_eh);
3603 cfi_args_size = NULL;
3606 VEC_free (dw_cfi_ref, heap, regs);
3609 else if (do_cfi_asm)
3610 output_cfi_directive (cfi);
3612 output_cfi (cfi, fde, for_eh);
3620 /* Like output_cfis, but emit all CFIs in the vector. */
3622 output_all_cfis (cfi_vec vec, bool do_cfi_asm,
3623 dw_fde_ref fde, bool for_eh)
3625 output_cfis (vec, VEC_length (dw_cfi_ref, vec), do_cfi_asm, fde, for_eh);
3628 /* Output one FDE. */
3631 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3632 char *section_start_label, int fde_encoding, char *augmentation,
3633 bool any_lsda_needed, int lsda_encoding)
3636 const char *begin, *end;
3637 static unsigned int j;
3638 char l1[20], l2[20];
3641 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3643 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3645 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3646 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3647 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3648 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3649 " indicating 64-bit DWARF extension");
3650 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3652 ASM_OUTPUT_LABEL (asm_out_file, l1);
3655 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3657 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3658 debug_frame_section, "FDE CIE offset");
3660 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
3661 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
3665 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3666 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3667 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3668 "FDE initial location");
3669 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3670 end, begin, "FDE address range");
3674 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3675 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3678 if (augmentation[0])
3680 if (any_lsda_needed)
3682 int size = size_of_encoded_value (lsda_encoding);
3684 if (lsda_encoding == DW_EH_PE_aligned)
3686 int offset = ( 4 /* Length */
3687 + 4 /* CIE offset */
3688 + 2 * size_of_encoded_value (fde_encoding)
3689 + 1 /* Augmentation size */ );
3690 int pad = -offset & (PTR_SIZE - 1);
3693 gcc_assert (size_of_uleb128 (size) == 1);
3696 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3698 if (fde->uses_eh_lsda)
3700 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3701 fde->funcdef_number);
3702 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3703 gen_rtx_SYMBOL_REF (Pmode, l1),
3705 "Language Specific Data Area");
3709 if (lsda_encoding == DW_EH_PE_aligned)
3710 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3711 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3712 "Language Specific Data Area (none)");
3716 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3719 /* Loop through the Call Frame Instructions associated with
3721 fde->dw_fde_current_label = begin;
3722 if (fde->dw_fde_second_begin == NULL)
3723 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
3724 output_cfi (cfi, fde, for_eh);
3727 if (fde->dw_fde_switch_cfi_index > 0)
3728 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
3730 if (ix == fde->dw_fde_switch_cfi_index)
3732 output_cfi (cfi, fde, for_eh);
3738 int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
3740 if (fde->dw_fde_switch_cfi_index > 0)
3742 from = fde->dw_fde_switch_cfi_index;
3743 output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh);
3745 for (i = from; i < until; i++)
3746 output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i),
3750 /* If we are to emit a ref/link from function bodies to their frame tables,
3751 do it now. This is typically performed to make sure that tables
3752 associated with functions are dragged with them and not discarded in
3753 garbage collecting links. We need to do this on a per function basis to
3754 cope with -ffunction-sections. */
3756 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3757 /* Switch to the function section, emit the ref to the tables, and
3758 switch *back* into the table section. */
3759 switch_to_section (function_section (fde->decl));
3760 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3761 switch_to_frame_table_section (for_eh, true);
3764 /* Pad the FDE out to an address sized boundary. */
3765 ASM_OUTPUT_ALIGN (asm_out_file,
3766 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3767 ASM_OUTPUT_LABEL (asm_out_file, l2);
3772 /* Return true if frame description entry FDE is needed for EH. */
3775 fde_needed_for_eh_p (dw_fde_ref fde)
3777 if (flag_asynchronous_unwind_tables)
3780 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3783 if (fde->uses_eh_lsda)
3786 /* If exceptions are enabled, we have collected nothrow info. */
3787 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3793 /* Output the call frame information used to record information
3794 that relates to calculating the frame pointer, and records the
3795 location of saved registers. */
3798 output_call_frame_info (int for_eh)
3803 char l1[20], l2[20], section_start_label[20];
3804 bool any_lsda_needed = false;
3805 char augmentation[6];
3806 int augmentation_size;
3807 int fde_encoding = DW_EH_PE_absptr;
3808 int per_encoding = DW_EH_PE_absptr;
3809 int lsda_encoding = DW_EH_PE_absptr;
3811 rtx personality = NULL;
3814 /* Don't emit a CIE if there won't be any FDEs. */
3815 if (fde_table_in_use == 0)
3818 /* Nothing to do if the assembler's doing it all. */
3819 if (dwarf2out_do_cfi_asm ())
3822 /* If we don't have any functions we'll want to unwind out of, don't emit
3823 any EH unwind information. If we make FDEs linkonce, we may have to
3824 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3825 want to avoid having an FDE kept around when the function it refers to
3826 is discarded. Example where this matters: a primary function template
3827 in C++ requires EH information, an explicit specialization doesn't. */
3830 bool any_eh_needed = false;
3832 for (i = 0; i < fde_table_in_use; i++)
3833 if (fde_table[i].uses_eh_lsda)
3834 any_eh_needed = any_lsda_needed = true;
3835 else if (fde_needed_for_eh_p (&fde_table[i]))
3836 any_eh_needed = true;
3837 else if (TARGET_USES_WEAK_UNWIND_INFO)
3838 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3845 /* We're going to be generating comments, so turn on app. */
3849 /* Switch to the proper frame section, first time. */
3850 switch_to_frame_table_section (for_eh, false);
3852 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3853 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3855 /* Output the CIE. */
3856 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3857 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3858 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3859 dw2_asm_output_data (4, 0xffffffff,
3860 "Initial length escape value indicating 64-bit DWARF extension");
3861 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3862 "Length of Common Information Entry");
3863 ASM_OUTPUT_LABEL (asm_out_file, l1);
3865 /* Now that the CIE pointer is PC-relative for EH,
3866 use 0 to identify the CIE. */
3867 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3868 (for_eh ? 0 : DWARF_CIE_ID),
3869 "CIE Identifier Tag");
3871 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3872 use CIE version 1, unless that would produce incorrect results
3873 due to overflowing the return register column. */
3874 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3876 if (return_reg >= 256 || dwarf_version > 2)
3878 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3880 augmentation[0] = 0;
3881 augmentation_size = 0;
3883 personality = current_unit_personality;
3889 z Indicates that a uleb128 is present to size the
3890 augmentation section.
3891 L Indicates the encoding (and thus presence) of
3892 an LSDA pointer in the FDE augmentation.
3893 R Indicates a non-default pointer encoding for
3895 P Indicates the presence of an encoding + language
3896 personality routine in the CIE augmentation. */
3898 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3899 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3900 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3902 p = augmentation + 1;
3906 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3907 assemble_external_libcall (personality);
3909 if (any_lsda_needed)
3912 augmentation_size += 1;
3914 if (fde_encoding != DW_EH_PE_absptr)
3917 augmentation_size += 1;
3919 if (p > augmentation + 1)
3921 augmentation[0] = 'z';
3925 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3926 if (personality && per_encoding == DW_EH_PE_aligned)
3928 int offset = ( 4 /* Length */
3930 + 1 /* CIE version */
3931 + strlen (augmentation) + 1 /* Augmentation */
3932 + size_of_uleb128 (1) /* Code alignment */
3933 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3935 + 1 /* Augmentation size */
3936 + 1 /* Personality encoding */ );
3937 int pad = -offset & (PTR_SIZE - 1);
3939 augmentation_size += pad;
3941 /* Augmentations should be small, so there's scarce need to
3942 iterate for a solution. Die if we exceed one uleb128 byte. */
3943 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3947 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3948 if (dw_cie_version >= 4)
3950 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3951 dw2_asm_output_data (1, 0, "CIE Segment Size");
3953 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3954 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3955 "CIE Data Alignment Factor");
3957 if (dw_cie_version == 1)
3958 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3960 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3962 if (augmentation[0])
3964 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3967 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3968 eh_data_format_name (per_encoding));
3969 dw2_asm_output_encoded_addr_rtx (per_encoding,
3974 if (any_lsda_needed)
3975 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3976 eh_data_format_name (lsda_encoding));
3978 if (fde_encoding != DW_EH_PE_absptr)
3979 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3980 eh_data_format_name (fde_encoding));
3983 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
3984 output_cfi (cfi, NULL, for_eh);
3986 /* Pad the CIE out to an address sized boundary. */
3987 ASM_OUTPUT_ALIGN (asm_out_file,
3988 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3989 ASM_OUTPUT_LABEL (asm_out_file, l2);
3991 /* Loop through all of the FDE's. */
3992 for (i = 0; i < fde_table_in_use; i++)
3995 fde = &fde_table[i];
3997 /* Don't emit EH unwind info for leaf functions that don't need it. */
3998 if (for_eh && !fde_needed_for_eh_p (fde))
4001 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
4002 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
4003 augmentation, any_lsda_needed, lsda_encoding);
4006 if (for_eh && targetm.terminate_dw2_eh_frame_info)
4007 dw2_asm_output_data (4, 0, "End of Table");
4008 #ifdef MIPS_DEBUGGING_INFO
4009 /* Work around Irix 6 assembler bug whereby labels at the end of a section
4010 get a value of 0. Putting .align 0 after the label fixes it. */
4011 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4014 /* Turn off app to make assembly quicker. */
4019 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4022 dwarf2out_do_cfi_startproc (bool second)
4026 rtx personality = get_personality_function (current_function_decl);
4028 fprintf (asm_out_file, "\t.cfi_startproc\n");
4032 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4035 /* ??? The GAS support isn't entirely consistent. We have to
4036 handle indirect support ourselves, but PC-relative is done
4037 in the assembler. Further, the assembler can't handle any
4038 of the weirder relocation types. */
4039 if (enc & DW_EH_PE_indirect)
4040 ref = dw2_force_const_mem (ref, true);
4042 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4043 output_addr_const (asm_out_file, ref);
4044 fputc ('\n', asm_out_file);
4047 if (crtl->uses_eh_lsda)
4051 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4052 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4053 current_function_funcdef_no);
4054 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4055 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4057 if (enc & DW_EH_PE_indirect)
4058 ref = dw2_force_const_mem (ref, true);
4060 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4061 output_addr_const (asm_out_file, ref);
4062 fputc ('\n', asm_out_file);
4066 /* Output a marker (i.e. a label) for the beginning of a function, before
4070 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4071 const char *file ATTRIBUTE_UNUSED)
4073 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4079 current_function_func_begin_label = NULL;
4081 do_frame = dwarf2out_do_frame ();
4083 /* ??? current_function_func_begin_label is also used by except.c for
4084 call-site information. We must emit this label if it might be used. */
4086 && (!flag_exceptions
4087 || targetm_common.except_unwind_info (&global_options) != UI_TARGET))
4090 fnsec = function_section (current_function_decl);
4091 switch_to_section (fnsec);
4092 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4093 current_function_funcdef_no);
4094 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4095 current_function_funcdef_no);
4096 dup_label = xstrdup (label);
4097 current_function_func_begin_label = dup_label;
4099 /* We can elide the fde allocation if we're not emitting debug info. */
4103 /* Expand the fde table if necessary. */
4104 if (fde_table_in_use == fde_table_allocated)
4106 fde_table_allocated += FDE_TABLE_INCREMENT;
4107 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4108 memset (fde_table + fde_table_in_use, 0,
4109 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4112 /* Record the FDE associated with this function. */
4113 current_funcdef_fde = fde_table_in_use;
4115 /* Add the new FDE at the end of the fde_table. */
4116 fde = &fde_table[fde_table_in_use++];
4117 fde->decl = current_function_decl;
4118 fde->dw_fde_begin = dup_label;
4119 fde->dw_fde_end = NULL;
4120 fde->dw_fde_current_label = dup_label;
4121 fde->dw_fde_second_begin = NULL;
4122 fde->dw_fde_second_end = NULL;
4123 fde->dw_fde_vms_end_prologue = NULL;
4124 fde->dw_fde_vms_begin_epilogue = NULL;
4125 fde->dw_fde_cfi = VEC_alloc (dw_cfi_ref, gc, 20);
4126 fde->dw_fde_switch_cfi_index = 0;
4127 fde->funcdef_number = current_function_funcdef_no;
4128 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4129 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4130 fde->nothrow = crtl->nothrow;
4131 fde->drap_reg = INVALID_REGNUM;
4132 fde->vdrap_reg = INVALID_REGNUM;
4133 fde->in_std_section = (fnsec == text_section
4134 || (cold_text_section && fnsec == cold_text_section));
4135 fde->second_in_std_section = 0;
4137 args_size = old_args_size = 0;
4139 /* We only want to output line number information for the genuine dwarf2
4140 prologue case, not the eh frame case. */
4141 #ifdef DWARF2_DEBUGGING_INFO
4143 dwarf2out_source_line (line, file, 0, true);
4146 if (dwarf2out_do_cfi_asm ())
4147 dwarf2out_do_cfi_startproc (false);
4150 rtx personality = get_personality_function (current_function_decl);
4151 if (!current_unit_personality)
4152 current_unit_personality = personality;
4154 /* We cannot keep a current personality per function as without CFI
4155 asm, at the point where we emit the CFI data, there is no current
4156 function anymore. */
4157 if (personality && current_unit_personality != personality)
4158 sorry ("multiple EH personalities are supported only with assemblers "
4159 "supporting .cfi_personality directive");
4163 /* Output a marker (i.e. a label) for the end of the generated code
4164 for a function prologue. This gets called *after* the prologue code has
4168 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4169 const char *file ATTRIBUTE_UNUSED)
4172 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4174 /* Output a label to mark the endpoint of the code generated for this
4176 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4177 current_function_funcdef_no);
4178 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4179 current_function_funcdef_no);
4180 fde = &fde_table[fde_table_in_use - 1];
4181 fde->dw_fde_vms_end_prologue = xstrdup (label);
4184 /* Output a marker (i.e. a label) for the beginning of the generated code
4185 for a function epilogue. This gets called *before* the prologue code has
4189 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4190 const char *file ATTRIBUTE_UNUSED)
4193 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4195 fde = &fde_table[fde_table_in_use - 1];
4196 if (fde->dw_fde_vms_begin_epilogue)
4199 /* Output a label to mark the endpoint of the code generated for this
4201 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4202 current_function_funcdef_no);
4203 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4204 current_function_funcdef_no);
4205 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4208 /* Output a marker (i.e. a label) for the absolute end of the generated code
4209 for a function definition. This gets called *after* the epilogue code has
4213 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4214 const char *file ATTRIBUTE_UNUSED)
4217 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4219 last_var_location_insn = NULL_RTX;
4221 if (dwarf2out_do_cfi_asm ())
4222 fprintf (asm_out_file, "\t.cfi_endproc\n");
4224 /* Output a label to mark the endpoint of the code generated for this
4226 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4227 current_function_funcdef_no);
4228 ASM_OUTPUT_LABEL (asm_out_file, label);
4229 fde = current_fde ();
4230 gcc_assert (fde != NULL);
4231 if (fde->dw_fde_second_begin == NULL)
4232 fde->dw_fde_end = xstrdup (label);
4236 dwarf2out_frame_init (void)
4238 /* Allocate the initial hunk of the fde_table. */
4239 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4240 fde_table_allocated = FDE_TABLE_INCREMENT;
4241 fde_table_in_use = 0;
4243 /* Generate the CFA instructions common to all FDE's. Do it now for the
4244 sake of lookup_cfa. */
4246 /* On entry, the Canonical Frame Address is at SP. */
4247 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4249 if (targetm.debug_unwind_info () == UI_DWARF2
4250 || targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
4251 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4255 dwarf2out_frame_finish (void)
4257 /* Output call frame information. */
4258 if (targetm.debug_unwind_info () == UI_DWARF2)
4259 output_call_frame_info (0);
4261 /* Output another copy for the unwinder. */
4262 if ((flag_unwind_tables || flag_exceptions)
4263 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
4264 output_call_frame_info (1);
4267 /* Note that the current function section is being used for code. */
4270 dwarf2out_note_section_used (void)
4272 section *sec = current_function_section ();
4273 if (sec == text_section)
4274 text_section_used = true;
4275 else if (sec == cold_text_section)
4276 cold_text_section_used = true;
4279 static void var_location_switch_text_section (void);
4280 static void set_cur_line_info_table (section *);
4283 dwarf2out_switch_text_section (void)
4286 dw_fde_ref fde = current_fde ();
4288 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
4290 if (!in_cold_section_p)
4292 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
4293 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
4294 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
4298 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
4299 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
4300 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
4302 have_multiple_function_sections = true;
4304 /* Reset the current label on switching text sections, so that we
4305 don't attempt to advance_loc4 between labels in different sections. */
4306 fde->dw_fde_current_label = NULL;
4308 /* There is no need to mark used sections when not debugging. */
4309 if (cold_text_section != NULL)
4310 dwarf2out_note_section_used ();
4312 if (dwarf2out_do_cfi_asm ())
4313 fprintf (asm_out_file, "\t.cfi_endproc\n");
4315 /* Now do the real section switch. */
4316 sect = current_function_section ();
4317 switch_to_section (sect);
4319 fde->second_in_std_section
4320 = (sect == text_section
4321 || (cold_text_section && sect == cold_text_section));
4323 if (dwarf2out_do_cfi_asm ())
4325 dwarf2out_do_cfi_startproc (true);
4326 /* As this is a different FDE, insert all current CFI instructions
4328 output_all_cfis (fde->dw_fde_cfi, true, fde, true);
4330 fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
4331 var_location_switch_text_section ();
4333 set_cur_line_info_table (sect);
4336 /* And now, the subset of the debugging information support code necessary
4337 for emitting location expressions. */
4339 /* Data about a single source file. */
4340 struct GTY(()) dwarf_file_data {
4341 const char * filename;
4345 typedef struct dw_val_struct *dw_val_ref;
4346 typedef struct die_struct *dw_die_ref;
4347 typedef const struct die_struct *const_dw_die_ref;
4348 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4349 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4351 typedef struct GTY(()) deferred_locations_struct
4355 } deferred_locations;
4357 DEF_VEC_O(deferred_locations);
4358 DEF_VEC_ALLOC_O(deferred_locations,gc);
4360 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4362 DEF_VEC_P(dw_die_ref);
4363 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4365 /* Each DIE may have a series of attribute/value pairs. Values
4366 can take on several forms. The forms that are used in this
4367 implementation are listed below. */
4372 dw_val_class_offset,
4374 dw_val_class_loc_list,
4375 dw_val_class_range_list,
4377 dw_val_class_unsigned_const,
4378 dw_val_class_const_double,
4381 dw_val_class_die_ref,
4382 dw_val_class_fde_ref,
4383 dw_val_class_lbl_id,
4384 dw_val_class_lineptr,
4386 dw_val_class_macptr,
4389 dw_val_class_decl_ref,
4390 dw_val_class_vms_delta
4393 /* Describe a floating point constant value, or a vector constant value. */
4395 typedef struct GTY(()) dw_vec_struct {
4396 unsigned char * GTY((length ("%h.length"))) array;
4402 /* The dw_val_node describes an attribute's value, as it is
4403 represented internally. */
4405 typedef struct GTY(()) dw_val_struct {
4406 enum dw_val_class val_class;
4407 union dw_val_struct_union
4409 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4410 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4411 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4412 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4413 HOST_WIDE_INT GTY ((default)) val_int;
4414 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4415 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4416 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4417 struct dw_val_die_union
4421 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4422 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4423 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4424 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4425 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4426 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4427 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4428 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4429 struct dw_val_vms_delta_union
4433 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4435 GTY ((desc ("%1.val_class"))) v;
4439 /* Locations in memory are described using a sequence of stack machine
4442 typedef struct GTY(()) dw_loc_descr_struct {
4443 dw_loc_descr_ref dw_loc_next;
4444 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4445 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4446 from DW_OP_addr with a dtp-relative symbol relocation. */
4447 unsigned int dtprel : 1;
4449 dw_val_node dw_loc_oprnd1;
4450 dw_val_node dw_loc_oprnd2;
4454 /* Location lists are ranges + location descriptions for that range,
4455 so you can track variables that are in different places over
4456 their entire life. */
4457 typedef struct GTY(()) dw_loc_list_struct {
4458 dw_loc_list_ref dw_loc_next;
4459 const char *begin; /* Label for begin address of range */
4460 const char *end; /* Label for end address of range */
4461 char *ll_symbol; /* Label for beginning of location list.
4462 Only on head of list */
4463 const char *section; /* Section this loclist is relative to */
4464 dw_loc_descr_ref expr;
4466 /* True if all addresses in this and subsequent lists are known to be
4469 /* True if this list has been replaced by dw_loc_next. */
4472 /* True if the range should be emitted even if begin and end
4477 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4479 /* Convert a DWARF stack opcode into its string name. */
4482 dwarf_stack_op_name (unsigned int op)
4487 return "DW_OP_addr";
4489 return "DW_OP_deref";
4491 return "DW_OP_const1u";
4493 return "DW_OP_const1s";
4495 return "DW_OP_const2u";
4497 return "DW_OP_const2s";
4499 return "DW_OP_const4u";
4501 return "DW_OP_const4s";
4503 return "DW_OP_const8u";
4505 return "DW_OP_const8s";
4507 return "DW_OP_constu";
4509 return "DW_OP_consts";
4513 return "DW_OP_drop";
4515 return "DW_OP_over";
4517 return "DW_OP_pick";
4519 return "DW_OP_swap";
4523 return "DW_OP_xderef";
4531 return "DW_OP_minus";
4543 return "DW_OP_plus";
4544 case DW_OP_plus_uconst:
4545 return "DW_OP_plus_uconst";
4551 return "DW_OP_shra";
4569 return "DW_OP_skip";
4571 return "DW_OP_lit0";
4573 return "DW_OP_lit1";
4575 return "DW_OP_lit2";
4577 return "DW_OP_lit3";
4579 return "DW_OP_lit4";
4581 return "DW_OP_lit5";
4583 return "DW_OP_lit6";
4585 return "DW_OP_lit7";
4587 return "DW_OP_lit8";
4589 return "DW_OP_lit9";
4591 return "DW_OP_lit10";
4593 return "DW_OP_lit11";
4595 return "DW_OP_lit12";
4597 return "DW_OP_lit13";
4599 return "DW_OP_lit14";
4601 return "DW_OP_lit15";
4603 return "DW_OP_lit16";
4605 return "DW_OP_lit17";
4607 return "DW_OP_lit18";
4609 return "DW_OP_lit19";
4611 return "DW_OP_lit20";
4613 return "DW_OP_lit21";
4615 return "DW_OP_lit22";
4617 return "DW_OP_lit23";
4619 return "DW_OP_lit24";
4621 return "DW_OP_lit25";
4623 return "DW_OP_lit26";
4625 return "DW_OP_lit27";
4627 return "DW_OP_lit28";
4629 return "DW_OP_lit29";
4631 return "DW_OP_lit30";
4633 return "DW_OP_lit31";
4635 return "DW_OP_reg0";
4637 return "DW_OP_reg1";
4639 return "DW_OP_reg2";
4641 return "DW_OP_reg3";
4643 return "DW_OP_reg4";
4645 return "DW_OP_reg5";
4647 return "DW_OP_reg6";
4649 return "DW_OP_reg7";
4651 return "DW_OP_reg8";
4653 return "DW_OP_reg9";
4655 return "DW_OP_reg10";
4657 return "DW_OP_reg11";
4659 return "DW_OP_reg12";
4661 return "DW_OP_reg13";
4663 return "DW_OP_reg14";
4665 return "DW_OP_reg15";
4667 return "DW_OP_reg16";
4669 return "DW_OP_reg17";
4671 return "DW_OP_reg18";
4673 return "DW_OP_reg19";
4675 return "DW_OP_reg20";
4677 return "DW_OP_reg21";
4679 return "DW_OP_reg22";
4681 return "DW_OP_reg23";
4683 return "DW_OP_reg24";
4685 return "DW_OP_reg25";
4687 return "DW_OP_reg26";
4689 return "DW_OP_reg27";
4691 return "DW_OP_reg28";
4693 return "DW_OP_reg29";
4695 return "DW_OP_reg30";
4697 return "DW_OP_reg31";
4699 return "DW_OP_breg0";
4701 return "DW_OP_breg1";
4703 return "DW_OP_breg2";
4705 return "DW_OP_breg3";
4707 return "DW_OP_breg4";
4709 return "DW_OP_breg5";
4711 return "DW_OP_breg6";
4713 return "DW_OP_breg7";
4715 return "DW_OP_breg8";
4717 return "DW_OP_breg9";
4719 return "DW_OP_breg10";
4721 return "DW_OP_breg11";
4723 return "DW_OP_breg12";
4725 return "DW_OP_breg13";
4727 return "DW_OP_breg14";
4729 return "DW_OP_breg15";
4731 return "DW_OP_breg16";
4733 return "DW_OP_breg17";
4735 return "DW_OP_breg18";
4737 return "DW_OP_breg19";
4739 return "DW_OP_breg20";
4741 return "DW_OP_breg21";
4743 return "DW_OP_breg22";
4745 return "DW_OP_breg23";
4747 return "DW_OP_breg24";
4749 return "DW_OP_breg25";
4751 return "DW_OP_breg26";
4753 return "DW_OP_breg27";
4755 return "DW_OP_breg28";
4757 return "DW_OP_breg29";
4759 return "DW_OP_breg30";
4761 return "DW_OP_breg31";
4763 return "DW_OP_regx";
4765 return "DW_OP_fbreg";
4767 return "DW_OP_bregx";
4769 return "DW_OP_piece";
4770 case DW_OP_deref_size:
4771 return "DW_OP_deref_size";
4772 case DW_OP_xderef_size:
4773 return "DW_OP_xderef_size";
4777 case DW_OP_push_object_address:
4778 return "DW_OP_push_object_address";
4780 return "DW_OP_call2";
4782 return "DW_OP_call4";
4783 case DW_OP_call_ref:
4784 return "DW_OP_call_ref";
4785 case DW_OP_implicit_value:
4786 return "DW_OP_implicit_value";
4787 case DW_OP_stack_value:
4788 return "DW_OP_stack_value";
4789 case DW_OP_form_tls_address:
4790 return "DW_OP_form_tls_address";
4791 case DW_OP_call_frame_cfa:
4792 return "DW_OP_call_frame_cfa";
4793 case DW_OP_bit_piece:
4794 return "DW_OP_bit_piece";
4796 case DW_OP_GNU_push_tls_address:
4797 return "DW_OP_GNU_push_tls_address";
4798 case DW_OP_GNU_uninit:
4799 return "DW_OP_GNU_uninit";
4800 case DW_OP_GNU_encoded_addr:
4801 return "DW_OP_GNU_encoded_addr";
4802 case DW_OP_GNU_implicit_pointer:
4803 return "DW_OP_GNU_implicit_pointer";
4804 case DW_OP_GNU_entry_value:
4805 return "DW_OP_GNU_entry_value";
4806 case DW_OP_GNU_const_type:
4807 return "DW_OP_GNU_const_type";
4808 case DW_OP_GNU_regval_type:
4809 return "DW_OP_GNU_regval_type";
4810 case DW_OP_GNU_deref_type:
4811 return "DW_OP_GNU_deref_type";
4812 case DW_OP_GNU_convert:
4813 return "DW_OP_GNU_convert";
4814 case DW_OP_GNU_reinterpret:
4815 return "DW_OP_GNU_reinterpret";
4816 case DW_OP_GNU_parameter_ref:
4817 return "DW_OP_GNU_parameter_ref";
4820 return "OP_<unknown>";
4824 /* Return a pointer to a newly allocated location description. Location
4825 descriptions are simple expression terms that can be strung
4826 together to form more complicated location (address) descriptions. */
4828 static inline dw_loc_descr_ref
4829 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4830 unsigned HOST_WIDE_INT oprnd2)
4832 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4834 descr->dw_loc_opc = op;
4835 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4836 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4837 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4838 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4843 /* Return a pointer to a newly allocated location description for
4846 static inline dw_loc_descr_ref
4847 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4850 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4853 return new_loc_descr (DW_OP_bregx, reg, offset);
4856 /* Add a location description term to a location description expression. */
4859 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4861 dw_loc_descr_ref *d;
4863 /* Find the end of the chain. */
4864 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4870 /* Add a constant OFFSET to a location expression. */
4873 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4875 dw_loc_descr_ref loc;
4878 gcc_assert (*list_head != NULL);
4883 /* Find the end of the chain. */
4884 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4888 if (loc->dw_loc_opc == DW_OP_fbreg
4889 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4890 p = &loc->dw_loc_oprnd1.v.val_int;
4891 else if (loc->dw_loc_opc == DW_OP_bregx)
4892 p = &loc->dw_loc_oprnd2.v.val_int;
4894 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4895 offset. Don't optimize if an signed integer overflow would happen. */
4897 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4898 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4901 else if (offset > 0)
4902 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4906 loc->dw_loc_next = int_loc_descriptor (-offset);
4907 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4911 /* Add a constant OFFSET to a location list. */
4914 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4917 for (d = list_head; d != NULL; d = d->dw_loc_next)
4918 loc_descr_plus_const (&d->expr, offset);
4921 #define DWARF_REF_SIZE \
4922 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4924 static unsigned long size_of_locs (dw_loc_descr_ref);
4925 static unsigned long int get_base_type_offset (dw_die_ref);
4927 /* Return the size of a location descriptor. */
4929 static unsigned long
4930 size_of_loc_descr (dw_loc_descr_ref loc)
4932 unsigned long size = 1;
4934 switch (loc->dw_loc_opc)
4937 size += DWARF2_ADDR_SIZE;
4956 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4959 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4964 case DW_OP_plus_uconst:
4965 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5003 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
5006 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5009 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
5012 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5013 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5016 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5018 case DW_OP_bit_piece:
5019 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5020 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
5022 case DW_OP_deref_size:
5023 case DW_OP_xderef_size:
5032 case DW_OP_call_ref:
5033 size += DWARF_REF_SIZE;
5035 case DW_OP_implicit_value:
5036 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5037 + loc->dw_loc_oprnd1.v.val_unsigned;
5039 case DW_OP_GNU_implicit_pointer:
5040 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5042 case DW_OP_GNU_entry_value:
5044 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
5045 size += size_of_uleb128 (op_size) + op_size;
5048 case DW_OP_GNU_const_type:
5051 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
5052 size += size_of_uleb128 (o) + 1;
5053 switch (loc->dw_loc_oprnd2.val_class)
5055 case dw_val_class_vec:
5056 size += loc->dw_loc_oprnd2.v.val_vec.length
5057 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
5059 case dw_val_class_const:
5060 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
5062 case dw_val_class_const_double:
5063 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
5070 case DW_OP_GNU_regval_type:
5073 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
5074 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5075 + size_of_uleb128 (o);
5078 case DW_OP_GNU_deref_type:
5081 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
5082 size += 1 + size_of_uleb128 (o);
5085 case DW_OP_GNU_convert:
5086 case DW_OP_GNU_reinterpret:
5087 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
5088 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5092 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
5093 size += size_of_uleb128 (o);
5096 case DW_OP_GNU_parameter_ref:
5106 /* Return the size of a series of location descriptors. */
5108 static unsigned long
5109 size_of_locs (dw_loc_descr_ref loc)
5114 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5115 field, to avoid writing to a PCH file. */
5116 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5118 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5120 size += size_of_loc_descr (l);
5125 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5127 l->dw_loc_addr = size;
5128 size += size_of_loc_descr (l);
5134 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5135 static void get_ref_die_offset_label (char *, dw_die_ref);
5136 static unsigned long int get_ref_die_offset (dw_die_ref);
5137 static void output_loc_sequence (dw_loc_descr_ref, int);
5139 /* Output location description stack opcode's operands (if any).
5140 The for_eh_or_skip parameter controls whether register numbers are
5141 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5142 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5143 info). This should be suppressed for the cases that have not been converted
5144 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5147 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5149 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5150 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5152 switch (loc->dw_loc_opc)
5154 #ifdef DWARF2_DEBUGGING_INFO
5157 dw2_asm_output_data (2, val1->v.val_int, NULL);
5162 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5163 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5165 fputc ('\n', asm_out_file);
5170 dw2_asm_output_data (4, val1->v.val_int, NULL);
5175 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5176 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5178 fputc ('\n', asm_out_file);
5183 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5184 dw2_asm_output_data (8, val1->v.val_int, NULL);
5191 gcc_assert (val1->val_class == dw_val_class_loc);
5192 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5194 dw2_asm_output_data (2, offset, NULL);
5197 case DW_OP_implicit_value:
5198 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5199 switch (val2->val_class)
5201 case dw_val_class_const:
5202 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5204 case dw_val_class_vec:
5206 unsigned int elt_size = val2->v.val_vec.elt_size;
5207 unsigned int len = val2->v.val_vec.length;
5211 if (elt_size > sizeof (HOST_WIDE_INT))
5216 for (i = 0, p = val2->v.val_vec.array;
5219 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5220 "fp or vector constant word %u", i);
5223 case dw_val_class_const_double:
5225 unsigned HOST_WIDE_INT first, second;
5227 if (WORDS_BIG_ENDIAN)
5229 first = val2->v.val_double.high;
5230 second = val2->v.val_double.low;
5234 first = val2->v.val_double.low;
5235 second = val2->v.val_double.high;
5237 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5239 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5243 case dw_val_class_addr:
5244 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5245 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5260 case DW_OP_implicit_value:
5261 /* We currently don't make any attempt to make sure these are
5262 aligned properly like we do for the main unwind info, so
5263 don't support emitting things larger than a byte if we're
5264 only doing unwinding. */
5269 dw2_asm_output_data (1, val1->v.val_int, NULL);
5272 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5275 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5278 dw2_asm_output_data (1, val1->v.val_int, NULL);
5280 case DW_OP_plus_uconst:
5281 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5315 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5319 unsigned r = val1->v.val_unsigned;
5320 if (for_eh_or_skip >= 0)
5321 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5322 gcc_assert (size_of_uleb128 (r)
5323 == size_of_uleb128 (val1->v.val_unsigned));
5324 dw2_asm_output_data_uleb128 (r, NULL);
5328 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5332 unsigned r = val1->v.val_unsigned;
5333 if (for_eh_or_skip >= 0)
5334 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5335 gcc_assert (size_of_uleb128 (r)
5336 == size_of_uleb128 (val1->v.val_unsigned));
5337 dw2_asm_output_data_uleb128 (r, NULL);
5338 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5342 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5344 case DW_OP_bit_piece:
5345 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5346 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5348 case DW_OP_deref_size:
5349 case DW_OP_xderef_size:
5350 dw2_asm_output_data (1, val1->v.val_int, NULL);
5356 if (targetm.asm_out.output_dwarf_dtprel)
5358 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5361 fputc ('\n', asm_out_file);
5368 #ifdef DWARF2_DEBUGGING_INFO
5369 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5376 case DW_OP_GNU_implicit_pointer:
5378 char label[MAX_ARTIFICIAL_LABEL_BYTES
5379 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5380 gcc_assert (val1->val_class == dw_val_class_die_ref);
5381 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5382 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5383 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5387 case DW_OP_GNU_entry_value:
5388 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5389 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5392 case DW_OP_GNU_const_type:
5394 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
5396 dw2_asm_output_data_uleb128 (o, NULL);
5397 switch (val2->val_class)
5399 case dw_val_class_const:
5400 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5401 dw2_asm_output_data (1, l, NULL);
5402 dw2_asm_output_data (l, val2->v.val_int, NULL);
5404 case dw_val_class_vec:
5406 unsigned int elt_size = val2->v.val_vec.elt_size;
5407 unsigned int len = val2->v.val_vec.length;
5412 dw2_asm_output_data (1, l, NULL);
5413 if (elt_size > sizeof (HOST_WIDE_INT))
5418 for (i = 0, p = val2->v.val_vec.array;
5421 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5422 "fp or vector constant word %u", i);
5425 case dw_val_class_const_double:
5427 unsigned HOST_WIDE_INT first, second;
5428 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5430 dw2_asm_output_data (1, 2 * l, NULL);
5431 if (WORDS_BIG_ENDIAN)
5433 first = val2->v.val_double.high;
5434 second = val2->v.val_double.low;
5438 first = val2->v.val_double.low;
5439 second = val2->v.val_double.high;
5441 dw2_asm_output_data (l, first, NULL);
5442 dw2_asm_output_data (l, second, NULL);
5450 case DW_OP_GNU_regval_type:
5452 unsigned r = val1->v.val_unsigned;
5453 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
5455 if (for_eh_or_skip >= 0)
5457 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5458 gcc_assert (size_of_uleb128 (r)
5459 == size_of_uleb128 (val1->v.val_unsigned));
5461 dw2_asm_output_data_uleb128 (r, NULL);
5462 dw2_asm_output_data_uleb128 (o, NULL);
5465 case DW_OP_GNU_deref_type:
5467 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
5469 dw2_asm_output_data (1, val1->v.val_int, NULL);
5470 dw2_asm_output_data_uleb128 (o, NULL);
5473 case DW_OP_GNU_convert:
5474 case DW_OP_GNU_reinterpret:
5475 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
5476 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5479 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
5481 dw2_asm_output_data_uleb128 (o, NULL);
5485 case DW_OP_GNU_parameter_ref:
5488 gcc_assert (val1->val_class == dw_val_class_die_ref);
5489 o = get_ref_die_offset (val1->v.val_die_ref.die);
5490 dw2_asm_output_data (4, o, NULL);
5495 /* Other codes have no operands. */
5500 /* Output a sequence of location operations.
5501 The for_eh_or_skip parameter controls whether register numbers are
5502 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5503 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5504 info). This should be suppressed for the cases that have not been converted
5505 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5508 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5510 for (; loc != NULL; loc = loc->dw_loc_next)
5512 enum dwarf_location_atom opc = loc->dw_loc_opc;
5513 /* Output the opcode. */
5514 if (for_eh_or_skip >= 0
5515 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5517 unsigned r = (opc - DW_OP_breg0);
5518 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5519 gcc_assert (r <= 31);
5520 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5522 else if (for_eh_or_skip >= 0
5523 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5525 unsigned r = (opc - DW_OP_reg0);
5526 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5527 gcc_assert (r <= 31);
5528 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5531 dw2_asm_output_data (1, opc,
5532 "%s", dwarf_stack_op_name (opc));
5534 /* Output the operand(s) (if any). */
5535 output_loc_operands (loc, for_eh_or_skip);
5539 /* Output location description stack opcode's operands (if any).
5540 The output is single bytes on a line, suitable for .cfi_escape. */
5543 output_loc_operands_raw (dw_loc_descr_ref loc)
5545 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5546 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5548 switch (loc->dw_loc_opc)
5551 case DW_OP_implicit_value:
5552 /* We cannot output addresses in .cfi_escape, only bytes. */
5558 case DW_OP_deref_size:
5559 case DW_OP_xderef_size:
5560 fputc (',', asm_out_file);
5561 dw2_asm_output_data_raw (1, val1->v.val_int);
5566 fputc (',', asm_out_file);
5567 dw2_asm_output_data_raw (2, val1->v.val_int);
5572 fputc (',', asm_out_file);
5573 dw2_asm_output_data_raw (4, val1->v.val_int);
5578 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5579 fputc (',', asm_out_file);
5580 dw2_asm_output_data_raw (8, val1->v.val_int);
5588 gcc_assert (val1->val_class == dw_val_class_loc);
5589 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5591 fputc (',', asm_out_file);
5592 dw2_asm_output_data_raw (2, offset);
5598 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5599 gcc_assert (size_of_uleb128 (r)
5600 == size_of_uleb128 (val1->v.val_unsigned));
5601 fputc (',', asm_out_file);
5602 dw2_asm_output_data_uleb128_raw (r);
5607 case DW_OP_plus_uconst:
5609 fputc (',', asm_out_file);
5610 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5613 case DW_OP_bit_piece:
5614 fputc (',', asm_out_file);
5615 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5616 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5653 fputc (',', asm_out_file);
5654 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5659 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5660 gcc_assert (size_of_uleb128 (r)
5661 == size_of_uleb128 (val1->v.val_unsigned));
5662 fputc (',', asm_out_file);
5663 dw2_asm_output_data_uleb128_raw (r);
5664 fputc (',', asm_out_file);
5665 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5669 case DW_OP_GNU_implicit_pointer:
5670 case DW_OP_GNU_entry_value:
5671 case DW_OP_GNU_const_type:
5672 case DW_OP_GNU_regval_type:
5673 case DW_OP_GNU_deref_type:
5674 case DW_OP_GNU_convert:
5675 case DW_OP_GNU_reinterpret:
5676 case DW_OP_GNU_parameter_ref:
5681 /* Other codes have no operands. */
5687 output_loc_sequence_raw (dw_loc_descr_ref loc)
5691 enum dwarf_location_atom opc = loc->dw_loc_opc;
5692 /* Output the opcode. */
5693 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5695 unsigned r = (opc - DW_OP_breg0);
5696 r = DWARF2_FRAME_REG_OUT (r, 1);
5697 gcc_assert (r <= 31);
5698 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5700 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5702 unsigned r = (opc - DW_OP_reg0);
5703 r = DWARF2_FRAME_REG_OUT (r, 1);
5704 gcc_assert (r <= 31);
5705 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5707 /* Output the opcode. */
5708 fprintf (asm_out_file, "%#x", opc);
5709 output_loc_operands_raw (loc);
5711 if (!loc->dw_loc_next)
5713 loc = loc->dw_loc_next;
5715 fputc (',', asm_out_file);
5719 /* This routine will generate the correct assembly data for a location
5720 description based on a cfi entry with a complex address. */
5723 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5725 dw_loc_descr_ref loc;
5728 if (cfi->dw_cfi_opc == DW_CFA_expression)
5731 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5732 dw2_asm_output_data (1, r, NULL);
5733 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5736 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5738 /* Output the size of the block. */
5739 size = size_of_locs (loc);
5740 dw2_asm_output_data_uleb128 (size, NULL);
5742 /* Now output the operations themselves. */
5743 output_loc_sequence (loc, for_eh);
5746 /* Similar, but used for .cfi_escape. */
5749 output_cfa_loc_raw (dw_cfi_ref cfi)
5751 dw_loc_descr_ref loc;
5754 if (cfi->dw_cfi_opc == DW_CFA_expression)
5757 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5758 fprintf (asm_out_file, "%#x,", r);
5759 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5762 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5764 /* Output the size of the block. */
5765 size = size_of_locs (loc);
5766 dw2_asm_output_data_uleb128_raw (size);
5767 fputc (',', asm_out_file);
5769 /* Now output the operations themselves. */
5770 output_loc_sequence_raw (loc);
5773 /* This function builds a dwarf location descriptor sequence from a
5774 dw_cfa_location, adding the given OFFSET to the result of the
5777 static struct dw_loc_descr_struct *
5778 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5780 struct dw_loc_descr_struct *head, *tmp;
5782 offset += cfa->offset;
5786 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5787 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5788 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5789 add_loc_descr (&head, tmp);
5792 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5793 add_loc_descr (&head, tmp);
5797 head = new_reg_loc_descr (cfa->reg, offset);
5802 /* This function builds a dwarf location descriptor sequence for
5803 the address at OFFSET from the CFA when stack is aligned to
5806 static struct dw_loc_descr_struct *
5807 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5809 struct dw_loc_descr_struct *head;
5810 unsigned int dwarf_fp
5811 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5813 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5814 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5816 head = new_reg_loc_descr (dwarf_fp, 0);
5817 add_loc_descr (&head, int_loc_descriptor (alignment));
5818 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5819 loc_descr_plus_const (&head, offset);
5822 head = new_reg_loc_descr (dwarf_fp, offset);
5826 /* This function fills in aa dw_cfa_location structure from a dwarf location
5827 descriptor sequence. */
5830 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5832 struct dw_loc_descr_struct *ptr;
5834 cfa->base_offset = 0;
5838 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5840 enum dwarf_location_atom op = ptr->dw_loc_opc;
5876 cfa->reg = op - DW_OP_reg0;
5879 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5913 cfa->reg = op - DW_OP_breg0;
5914 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5917 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5918 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5923 case DW_OP_plus_uconst:
5924 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5927 internal_error ("DW_LOC_OP %s not implemented",
5928 dwarf_stack_op_name (ptr->dw_loc_opc));
5933 /* And now, the support for symbolic debugging information. */
5935 /* .debug_str support. */
5936 static int output_indirect_string (void **, void *);
5938 static void dwarf2out_init (const char *);
5939 static void dwarf2out_finish (const char *);
5940 static void dwarf2out_assembly_start (void);
5941 static void dwarf2out_define (unsigned int, const char *);
5942 static void dwarf2out_undef (unsigned int, const char *);
5943 static void dwarf2out_start_source_file (unsigned, const char *);
5944 static void dwarf2out_end_source_file (unsigned);
5945 static void dwarf2out_function_decl (tree);
5946 static void dwarf2out_begin_block (unsigned, unsigned);
5947 static void dwarf2out_end_block (unsigned, unsigned);
5948 static bool dwarf2out_ignore_block (const_tree);
5949 static void dwarf2out_global_decl (tree);
5950 static void dwarf2out_type_decl (tree, int);
5951 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5952 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5954 static void dwarf2out_abstract_function (tree);
5955 static void dwarf2out_var_location (rtx);
5956 static void dwarf2out_begin_function (tree);
5957 static void dwarf2out_set_name (tree, tree);
5959 /* The debug hooks structure. */
5961 const struct gcc_debug_hooks dwarf2_debug_hooks =
5965 dwarf2out_assembly_start,
5968 dwarf2out_start_source_file,
5969 dwarf2out_end_source_file,
5970 dwarf2out_begin_block,
5971 dwarf2out_end_block,
5972 dwarf2out_ignore_block,
5973 dwarf2out_source_line,
5974 dwarf2out_begin_prologue,
5975 #if VMS_DEBUGGING_INFO
5976 dwarf2out_vms_end_prologue,
5977 dwarf2out_vms_begin_epilogue,
5979 debug_nothing_int_charstar,
5980 debug_nothing_int_charstar,
5982 dwarf2out_end_epilogue,
5983 dwarf2out_begin_function,
5984 debug_nothing_int, /* end_function */
5985 dwarf2out_function_decl, /* function_decl */
5986 dwarf2out_global_decl,
5987 dwarf2out_type_decl, /* type_decl */
5988 dwarf2out_imported_module_or_decl,
5989 debug_nothing_tree, /* deferred_inline_function */
5990 /* The DWARF 2 backend tries to reduce debugging bloat by not
5991 emitting the abstract description of inline functions until
5992 something tries to reference them. */
5993 dwarf2out_abstract_function, /* outlining_inline_function */
5994 debug_nothing_rtx, /* label */
5995 debug_nothing_int, /* handle_pch */
5996 dwarf2out_var_location,
5997 dwarf2out_switch_text_section,
5999 1, /* start_end_main_source_file */
6000 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
6003 /* NOTE: In the comments in this file, many references are made to
6004 "Debugging Information Entries". This term is abbreviated as `DIE'
6005 throughout the remainder of this file. */
6007 /* An internal representation of the DWARF output is built, and then
6008 walked to generate the DWARF debugging info. The walk of the internal
6009 representation is done after the entire program has been compiled.
6010 The types below are used to describe the internal representation. */
6012 /* Whether to put type DIEs into their own section .debug_types instead
6013 of making them part of the .debug_info section. Only supported for
6014 Dwarf V4 or higher and the user didn't disable them through
6015 -fno-debug-types-section. It is more efficient to put them in a
6016 separate comdat sections since the linker will then be able to
6017 remove duplicates. But not all tools support .debug_types sections
6020 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
6022 /* Various DIE's use offsets relative to the beginning of the
6023 .debug_info section to refer to each other. */
6025 typedef long int dw_offset;
6027 /* Define typedefs here to avoid circular dependencies. */
6029 typedef struct dw_attr_struct *dw_attr_ref;
6030 typedef struct dw_line_info_struct *dw_line_info_ref;
6031 typedef struct pubname_struct *pubname_ref;
6032 typedef struct dw_ranges_struct *dw_ranges_ref;
6033 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
6034 typedef struct comdat_type_struct *comdat_type_node_ref;
6036 /* The entries in the line_info table more-or-less mirror the opcodes
6037 that are used in the real dwarf line table. Arrays of these entries
6038 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
6041 enum dw_line_info_opcode {
6042 /* Emit DW_LNE_set_address; the operand is the label index. */
6045 /* Emit a row to the matrix with the given line. This may be done
6046 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
6050 /* Emit a DW_LNS_set_file. */
6053 /* Emit a DW_LNS_set_column. */
6056 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
6059 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
6060 LI_set_prologue_end,
6061 LI_set_epilogue_begin,
6063 /* Emit a DW_LNE_set_discriminator. */
6064 LI_set_discriminator
6067 typedef struct GTY(()) dw_line_info_struct {
6068 enum dw_line_info_opcode opcode;
6070 } dw_line_info_entry;
6072 DEF_VEC_O(dw_line_info_entry);
6073 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
6075 typedef struct GTY(()) dw_line_info_table_struct {
6076 /* The label that marks the end of this section. */
6077 const char *end_label;
6079 /* The values for the last row of the matrix, as collected in the table.
6080 These are used to minimize the changes to the next row. */
6081 unsigned int file_num;
6082 unsigned int line_num;
6083 unsigned int column_num;
6088 VEC(dw_line_info_entry, gc) *entries;
6089 } dw_line_info_table;
6091 typedef dw_line_info_table *dw_line_info_table_p;
6093 DEF_VEC_P(dw_line_info_table_p);
6094 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
6096 /* Each DIE attribute has a field specifying the attribute kind,
6097 a link to the next attribute in the chain, and an attribute value.
6098 Attributes are typically linked below the DIE they modify. */
6100 typedef struct GTY(()) dw_attr_struct {
6101 enum dwarf_attribute dw_attr;
6102 dw_val_node dw_attr_val;
6106 DEF_VEC_O(dw_attr_node);
6107 DEF_VEC_ALLOC_O(dw_attr_node,gc);
6109 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
6110 The children of each node form a circular list linked by
6111 die_sib. die_child points to the node *before* the "first" child node. */
6113 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
6114 union die_symbol_or_type_node
6116 char * GTY ((tag ("0"))) die_symbol;
6117 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
6119 GTY ((desc ("use_debug_types"))) die_id;
6120 VEC(dw_attr_node,gc) * die_attr;
6121 dw_die_ref die_parent;
6122 dw_die_ref die_child;
6124 dw_die_ref die_definition; /* ref from a specification to its definition */
6125 dw_offset die_offset;
6126 unsigned long die_abbrev;
6128 /* Die is used and must not be pruned as unused. */
6129 int die_perennial_p;
6130 unsigned int decl_id;
6131 enum dwarf_tag die_tag;
6135 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
6136 #define FOR_EACH_CHILD(die, c, expr) do { \
6137 c = die->die_child; \
6141 } while (c != die->die_child); \
6144 /* The pubname structure */
6146 typedef struct GTY(()) pubname_struct {
6152 DEF_VEC_O(pubname_entry);
6153 DEF_VEC_ALLOC_O(pubname_entry, gc);
6155 struct GTY(()) dw_ranges_struct {
6156 /* If this is positive, it's a block number, otherwise it's a
6157 bitwise-negated index into dw_ranges_by_label. */
6161 /* A structure to hold a macinfo entry. */
6163 typedef struct GTY(()) macinfo_struct {
6164 unsigned HOST_WIDE_INT code;
6165 unsigned HOST_WIDE_INT lineno;
6170 DEF_VEC_O(macinfo_entry);
6171 DEF_VEC_ALLOC_O(macinfo_entry, gc);
6173 struct GTY(()) dw_ranges_by_label_struct {
6178 /* The comdat type node structure. */
6179 typedef struct GTY(()) comdat_type_struct
6181 dw_die_ref root_die;
6182 dw_die_ref type_die;
6183 char signature[DWARF_TYPE_SIGNATURE_SIZE];
6184 struct comdat_type_struct *next;
6188 /* The limbo die list structure. */
6189 typedef struct GTY(()) limbo_die_struct {
6192 struct limbo_die_struct *next;
6196 typedef struct skeleton_chain_struct
6200 struct skeleton_chain_struct *parent;
6202 skeleton_chain_node;
6204 /* How to start an assembler comment. */
6205 #ifndef ASM_COMMENT_START
6206 #define ASM_COMMENT_START ";#"
6209 /* Define a macro which returns nonzero for a TYPE_DECL which was
6210 implicitly generated for a tagged type.
6212 Note that unlike the gcc front end (which generates a NULL named
6213 TYPE_DECL node for each complete tagged type, each array type, and
6214 each function type node created) the g++ front end generates a
6215 _named_ TYPE_DECL node for each tagged type node created.
6216 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
6217 generate a DW_TAG_typedef DIE for them. */
6219 #define TYPE_DECL_IS_STUB(decl) \
6220 (DECL_NAME (decl) == NULL_TREE \
6221 || (DECL_ARTIFICIAL (decl) \
6222 && is_tagged_type (TREE_TYPE (decl)) \
6223 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
6224 /* This is necessary for stub decls that \
6225 appear in nested inline functions. */ \
6226 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6227 && (decl_ultimate_origin (decl) \
6228 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6230 /* Information concerning the compilation unit's programming
6231 language, and compiler version. */
6233 /* Fixed size portion of the DWARF compilation unit header. */
6234 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6235 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6237 /* Fixed size portion of the DWARF comdat type unit header. */
6238 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6239 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6240 + DWARF_OFFSET_SIZE)
6242 /* Fixed size portion of public names info. */
6243 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6245 /* Fixed size portion of the address range info. */
6246 #define DWARF_ARANGES_HEADER_SIZE \
6247 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6248 DWARF2_ADDR_SIZE * 2) \
6249 - DWARF_INITIAL_LENGTH_SIZE)
6251 /* Size of padding portion in the address range info. It must be
6252 aligned to twice the pointer size. */
6253 #define DWARF_ARANGES_PAD_SIZE \
6254 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6255 DWARF2_ADDR_SIZE * 2) \
6256 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6258 /* Use assembler line directives if available. */
6259 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6260 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6261 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6263 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6267 /* Minimum line offset in a special line info. opcode.
6268 This value was chosen to give a reasonable range of values. */
6269 #define DWARF_LINE_BASE -10
6271 /* First special line opcode - leave room for the standard opcodes. */
6272 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
6274 /* Range of line offsets in a special line info. opcode. */
6275 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6277 /* Flag that indicates the initial value of the is_stmt_start flag.
6278 In the present implementation, we do not mark any lines as
6279 the beginning of a source statement, because that information
6280 is not made available by the GCC front-end. */
6281 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6283 /* Maximum number of operations per instruction bundle. */
6284 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6285 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6288 /* This location is used by calc_die_sizes() to keep track
6289 the offset of each DIE within the .debug_info section. */
6290 static unsigned long next_die_offset;
6292 /* Record the root of the DIE's built for the current compilation unit. */
6293 static GTY(()) dw_die_ref single_comp_unit_die;
6295 /* A list of type DIEs that have been separated into comdat sections. */
6296 static GTY(()) comdat_type_node *comdat_type_list;
6298 /* A list of DIEs with a NULL parent waiting to be relocated. */
6299 static GTY(()) limbo_die_node *limbo_die_list;
6301 /* A list of DIEs for which we may have to generate
6302 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6303 static GTY(()) limbo_die_node *deferred_asm_name;
6305 /* Filenames referenced by this compilation unit. */
6306 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6308 /* A hash table of references to DIE's that describe declarations.
6309 The key is a DECL_UID() which is a unique number identifying each decl. */
6310 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6312 /* A hash table of references to DIE's that describe COMMON blocks.
6313 The key is DECL_UID() ^ die_parent. */
6314 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6316 typedef struct GTY(()) die_arg_entry_struct {
6321 DEF_VEC_O(die_arg_entry);
6322 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6324 /* Node of the variable location list. */
6325 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6326 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6327 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6328 in mode of the EXPR_LIST node and first EXPR_LIST operand
6329 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6330 location or NULL for padding. For larger bitsizes,
6331 mode is 0 and first operand is a CONCAT with bitsize
6332 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6333 NULL as second operand. */
6335 const char * GTY (()) label;
6336 struct var_loc_node * GTY (()) next;
6339 /* Variable location list. */
6340 struct GTY (()) var_loc_list_def {
6341 struct var_loc_node * GTY (()) first;
6343 /* Pointer to the last but one or last element of the
6344 chained list. If the list is empty, both first and
6345 last are NULL, if the list contains just one node
6346 or the last node certainly is not redundant, it points
6347 to the last node, otherwise points to the last but one.
6348 Do not mark it for GC because it is marked through the chain. */
6349 struct var_loc_node * GTY ((skip ("%h"))) last;
6351 /* Pointer to the last element before section switch,
6352 if NULL, either sections weren't switched or first
6353 is after section switch. */
6354 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
6356 /* DECL_UID of the variable decl. */
6357 unsigned int decl_id;
6359 typedef struct var_loc_list_def var_loc_list;
6361 /* Call argument location list. */
6362 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6363 rtx GTY (()) call_arg_loc_note;
6364 const char * GTY (()) label;
6365 tree GTY (()) block;
6367 rtx GTY (()) symbol_ref;
6368 struct call_arg_loc_node * GTY (()) next;
6372 /* Table of decl location linked lists. */
6373 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6375 /* Head and tail of call_arg_loc chain. */
6376 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6377 static struct call_arg_loc_node *call_arg_loc_last;
6379 /* Number of call sites in the current function. */
6380 static int call_site_count = -1;
6381 /* Number of tail call sites in the current function. */
6382 static int tail_call_site_count = -1;
6384 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6386 static VEC (dw_die_ref, heap) *block_map;
6388 /* A cached location list. */
6389 struct GTY (()) cached_dw_loc_list_def {
6390 /* The DECL_UID of the decl that this entry describes. */
6391 unsigned int decl_id;
6393 /* The cached location list. */
6394 dw_loc_list_ref loc_list;
6396 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
6398 /* Table of cached location lists. */
6399 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
6401 /* A pointer to the base of a list of references to DIE's that
6402 are uniquely identified by their tag, presence/absence of
6403 children DIE's, and list of attribute/value pairs. */
6404 static GTY((length ("abbrev_die_table_allocated")))
6405 dw_die_ref *abbrev_die_table;
6407 /* Number of elements currently allocated for abbrev_die_table. */
6408 static GTY(()) unsigned abbrev_die_table_allocated;
6410 /* Number of elements in type_die_table currently in use. */
6411 static GTY(()) unsigned abbrev_die_table_in_use;
6413 /* Size (in elements) of increments by which we may expand the
6414 abbrev_die_table. */
6415 #define ABBREV_DIE_TABLE_INCREMENT 256
6417 /* A global counter for generating labels for line number data. */
6418 static unsigned int line_info_label_num;
6420 /* The current table to which we should emit line number information
6421 for the current function. This will be set up at the beginning of
6422 assembly for the function. */
6423 static dw_line_info_table *cur_line_info_table;
6425 /* The two default tables of line number info. */
6426 static GTY(()) dw_line_info_table *text_section_line_info;
6427 static GTY(()) dw_line_info_table *cold_text_section_line_info;
6429 /* The set of all non-default tables of line number info. */
6430 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
6432 /* A flag to tell pubnames/types export if there is an info section to
6434 static bool info_section_emitted;
6436 /* A pointer to the base of a table that contains a list of publicly
6437 accessible names. */
6438 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6440 /* A pointer to the base of a table that contains a list of publicly
6441 accessible types. */
6442 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6444 /* A pointer to the base of a table that contains a list of macro
6445 defines/undefines (and file start/end markers). */
6446 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6448 /* Array of dies for which we should generate .debug_ranges info. */
6449 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6451 /* Number of elements currently allocated for ranges_table. */
6452 static GTY(()) unsigned ranges_table_allocated;
6454 /* Number of elements in ranges_table currently in use. */
6455 static GTY(()) unsigned ranges_table_in_use;
6457 /* Array of pairs of labels referenced in ranges_table. */
6458 static GTY ((length ("ranges_by_label_allocated")))
6459 dw_ranges_by_label_ref ranges_by_label;
6461 /* Number of elements currently allocated for ranges_by_label. */
6462 static GTY(()) unsigned ranges_by_label_allocated;
6464 /* Number of elements in ranges_by_label currently in use. */
6465 static GTY(()) unsigned ranges_by_label_in_use;
6467 /* Size (in elements) of increments by which we may expand the
6469 #define RANGES_TABLE_INCREMENT 64
6471 /* Whether we have location lists that need outputting */
6472 static GTY(()) bool have_location_lists;
6474 /* Unique label counter. */
6475 static GTY(()) unsigned int loclabel_num;
6477 /* Unique label counter for point-of-call tables. */
6478 static GTY(()) unsigned int poc_label_num;
6480 /* Record whether the function being analyzed contains inlined functions. */
6481 static int current_function_has_inlines;
6483 /* The last file entry emitted by maybe_emit_file(). */
6484 static GTY(()) struct dwarf_file_data * last_emitted_file;
6486 /* Number of internal labels generated by gen_internal_sym(). */
6487 static GTY(()) int label_num;
6489 /* Cached result of previous call to lookup_filename. */
6490 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6492 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6494 /* Instances of generic types for which we need to generate debug
6495 info that describe their generic parameters and arguments. That
6496 generation needs to happen once all types are properly laid out so
6497 we do it at the end of compilation. */
6498 static GTY(()) VEC(tree,gc) *generic_type_instances;
6500 /* Offset from the "steady-state frame pointer" to the frame base,
6501 within the current function. */
6502 static HOST_WIDE_INT frame_pointer_fb_offset;
6503 static bool frame_pointer_fb_offset_valid;
6505 static VEC (dw_die_ref, heap) *base_types;
6507 /* Forward declarations for functions defined in this file. */
6509 static int is_pseudo_reg (const_rtx);
6510 static tree type_main_variant (tree);
6511 static int is_tagged_type (const_tree);
6512 static const char *dwarf_tag_name (unsigned);
6513 static const char *dwarf_attr_name (unsigned);
6514 static const char *dwarf_form_name (unsigned);
6515 static tree decl_ultimate_origin (const_tree);
6516 static tree decl_class_context (tree);
6517 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6518 static inline enum dw_val_class AT_class (dw_attr_ref);
6519 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6520 static inline unsigned AT_flag (dw_attr_ref);
6521 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6522 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6523 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6524 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6525 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6526 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6527 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6528 unsigned int, unsigned char *);
6529 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6530 static hashval_t debug_str_do_hash (const void *);
6531 static int debug_str_eq (const void *, const void *);
6532 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6533 static inline const char *AT_string (dw_attr_ref);
6534 static enum dwarf_form AT_string_form (dw_attr_ref);
6535 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6536 static void add_AT_specification (dw_die_ref, dw_die_ref);
6537 static inline dw_die_ref AT_ref (dw_attr_ref);
6538 static inline int AT_ref_external (dw_attr_ref);
6539 static inline void set_AT_ref_external (dw_attr_ref, int);
6540 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6541 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6542 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6543 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6545 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6546 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6547 static inline rtx AT_addr (dw_attr_ref);
6548 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6549 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6550 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6551 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6552 unsigned HOST_WIDE_INT);
6553 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6555 static inline const char *AT_lbl (dw_attr_ref);
6556 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6557 static const char *get_AT_low_pc (dw_die_ref);
6558 static const char *get_AT_hi_pc (dw_die_ref);
6559 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6560 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6561 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6562 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6563 static bool is_cxx (void);
6564 static bool is_fortran (void);
6565 static bool is_ada (void);
6566 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6567 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6568 static void add_child_die (dw_die_ref, dw_die_ref);
6569 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6570 static dw_die_ref lookup_type_die (tree);
6571 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6572 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6573 static void equate_type_number_to_die (tree, dw_die_ref);
6574 static hashval_t decl_die_table_hash (const void *);
6575 static int decl_die_table_eq (const void *, const void *);
6576 static dw_die_ref lookup_decl_die (tree);
6577 static hashval_t common_block_die_table_hash (const void *);
6578 static int common_block_die_table_eq (const void *, const void *);
6579 static hashval_t decl_loc_table_hash (const void *);
6580 static int decl_loc_table_eq (const void *, const void *);
6581 static var_loc_list *lookup_decl_loc (const_tree);
6582 static void equate_decl_number_to_die (tree, dw_die_ref);
6583 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6584 static void print_spaces (FILE *);
6585 static void print_die (dw_die_ref, FILE *);
6586 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6587 static dw_die_ref pop_compile_unit (dw_die_ref);
6588 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6589 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6590 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6591 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6592 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6593 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6594 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6595 struct md5_ctx *, int *);
6596 struct checksum_attributes;
6597 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6598 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6599 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6600 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6601 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6602 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6603 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6604 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6605 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6606 static void compute_section_prefix (dw_die_ref);
6607 static int is_type_die (dw_die_ref);
6608 static int is_comdat_die (dw_die_ref);
6609 static int is_symbol_die (dw_die_ref);
6610 static void assign_symbol_names (dw_die_ref);
6611 static void break_out_includes (dw_die_ref);
6612 static int is_declaration_die (dw_die_ref);
6613 static int should_move_die_to_comdat (dw_die_ref);
6614 static dw_die_ref clone_as_declaration (dw_die_ref);
6615 static dw_die_ref clone_die (dw_die_ref);
6616 static dw_die_ref clone_tree (dw_die_ref);
6617 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6618 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6619 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6620 static dw_die_ref generate_skeleton (dw_die_ref);
6621 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6623 static void break_out_comdat_types (dw_die_ref);
6624 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6625 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6626 static void copy_decls_for_unworthy_types (dw_die_ref);
6628 static hashval_t htab_cu_hash (const void *);
6629 static int htab_cu_eq (const void *, const void *);
6630 static void htab_cu_del (void *);
6631 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6632 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6633 static void add_sibling_attributes (dw_die_ref);
6634 static void build_abbrev_table (dw_die_ref);
6635 static void output_location_lists (dw_die_ref);
6636 static int constant_size (unsigned HOST_WIDE_INT);
6637 static unsigned long size_of_die (dw_die_ref);
6638 static void calc_die_sizes (dw_die_ref);
6639 static void calc_base_type_die_sizes (void);
6640 static void mark_dies (dw_die_ref);
6641 static void unmark_dies (dw_die_ref);
6642 static void unmark_all_dies (dw_die_ref);
6643 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6644 static unsigned long size_of_aranges (void);
6645 static enum dwarf_form value_format (dw_attr_ref);
6646 static void output_value_format (dw_attr_ref);
6647 static void output_abbrev_section (void);
6648 static void output_die_symbol (dw_die_ref);
6649 static void output_die (dw_die_ref);
6650 static void output_compilation_unit_header (void);
6651 static void output_comp_unit (dw_die_ref, int);
6652 static void output_comdat_type_unit (comdat_type_node *);
6653 static const char *dwarf2_name (tree, int);
6654 static void add_pubname (tree, dw_die_ref);
6655 static void add_pubname_string (const char *, dw_die_ref);
6656 static void add_pubtype (tree, dw_die_ref);
6657 static void output_pubnames (VEC (pubname_entry,gc) *);
6658 static void output_aranges (unsigned long);
6659 static unsigned int add_ranges_num (int);
6660 static unsigned int add_ranges (const_tree);
6661 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6663 static void output_ranges (void);
6664 static dw_line_info_table *new_line_info_table (void);
6665 static void output_line_info (void);
6666 static void output_file_names (void);
6667 static dw_die_ref base_type_die (tree);
6668 static int is_base_type (tree);
6669 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6670 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6671 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6672 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6673 static int type_is_enum (const_tree);
6674 static unsigned int dbx_reg_number (const_rtx);
6675 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6676 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6677 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6678 enum var_init_status);
6679 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6680 enum var_init_status);
6681 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6682 enum var_init_status);
6683 static int is_based_loc (const_rtx);
6684 static int resolve_one_addr (rtx *, void *);
6685 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6686 enum var_init_status);
6687 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6688 enum var_init_status);
6689 static dw_loc_list_ref loc_list_from_tree (tree, int);
6690 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6691 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6692 static tree field_type (const_tree);
6693 static unsigned int simple_type_align_in_bits (const_tree);
6694 static unsigned int simple_decl_align_in_bits (const_tree);
6695 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6696 static HOST_WIDE_INT field_byte_offset (const_tree);
6697 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6699 static void add_data_member_location_attribute (dw_die_ref, tree);
6700 static bool add_const_value_attribute (dw_die_ref, rtx);
6701 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6702 static void insert_double (double_int, unsigned char *);
6703 static void insert_float (const_rtx, unsigned char *);
6704 static rtx rtl_for_decl_location (tree);
6705 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
6706 enum dwarf_attribute);
6707 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6708 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6709 static void add_name_attribute (dw_die_ref, const char *);
6710 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
6711 static void add_comp_dir_attribute (dw_die_ref);
6712 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6713 static void add_subscript_info (dw_die_ref, tree, bool);
6714 static void add_byte_size_attribute (dw_die_ref, tree);
6715 static void add_bit_offset_attribute (dw_die_ref, tree);
6716 static void add_bit_size_attribute (dw_die_ref, tree);
6717 static void add_prototyped_attribute (dw_die_ref, tree);
6718 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6719 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6720 static void add_src_coords_attributes (dw_die_ref, tree);
6721 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6722 static void push_decl_scope (tree);
6723 static void pop_decl_scope (void);
6724 static dw_die_ref scope_die_for (tree, dw_die_ref);
6725 static inline int local_scope_p (dw_die_ref);
6726 static inline int class_scope_p (dw_die_ref);
6727 static inline int class_or_namespace_scope_p (dw_die_ref);
6728 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6729 static void add_calling_convention_attribute (dw_die_ref, tree);
6730 static const char *type_tag (const_tree);
6731 static tree member_declared_type (const_tree);
6733 static const char *decl_start_label (tree);
6735 static void gen_array_type_die (tree, dw_die_ref);
6736 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6738 static void gen_entry_point_die (tree, dw_die_ref);
6740 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6741 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6742 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6743 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6744 static void gen_formal_types_die (tree, dw_die_ref);
6745 static void gen_subprogram_die (tree, dw_die_ref);
6746 static void gen_variable_die (tree, tree, dw_die_ref);
6747 static void gen_const_die (tree, dw_die_ref);
6748 static void gen_label_die (tree, dw_die_ref);
6749 static void gen_lexical_block_die (tree, dw_die_ref, int);
6750 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6751 static void gen_field_die (tree, dw_die_ref);
6752 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6753 static dw_die_ref gen_compile_unit_die (const char *);
6754 static void gen_inheritance_die (tree, tree, dw_die_ref);
6755 static void gen_member_die (tree, dw_die_ref);
6756 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6757 enum debug_info_usage);
6758 static void gen_subroutine_type_die (tree, dw_die_ref);
6759 static void gen_typedef_die (tree, dw_die_ref);
6760 static void gen_type_die (tree, dw_die_ref);
6761 static void gen_block_die (tree, dw_die_ref, int);
6762 static void decls_for_scope (tree, dw_die_ref, int);
6763 static inline int is_redundant_typedef (const_tree);
6764 static bool is_naming_typedef_decl (const_tree);
6765 static inline dw_die_ref get_context_die (tree);
6766 static void gen_namespace_die (tree, dw_die_ref);
6767 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6768 static dw_die_ref force_decl_die (tree);
6769 static dw_die_ref force_type_die (tree);
6770 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6771 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6772 static struct dwarf_file_data * lookup_filename (const char *);
6773 static void retry_incomplete_types (void);
6774 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6775 static void gen_generic_params_dies (tree);
6776 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6777 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6778 static void splice_child_die (dw_die_ref, dw_die_ref);
6779 static int file_info_cmp (const void *, const void *);
6780 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6781 const char *, const char *);
6782 static void output_loc_list (dw_loc_list_ref);
6783 static char *gen_internal_sym (const char *);
6785 static void prune_unmark_dies (dw_die_ref);
6786 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6787 static void prune_unused_types_mark (dw_die_ref, int);
6788 static void prune_unused_types_walk (dw_die_ref);
6789 static void prune_unused_types_walk_attribs (dw_die_ref);
6790 static void prune_unused_types_prune (dw_die_ref);
6791 static void prune_unused_types (void);
6792 static int maybe_emit_file (struct dwarf_file_data *fd);
6793 static inline const char *AT_vms_delta1 (dw_attr_ref);
6794 static inline const char *AT_vms_delta2 (dw_attr_ref);
6795 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6796 const char *, const char *);
6797 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6798 static void gen_remaining_tmpl_value_param_die_attribute (void);
6799 static bool generic_type_p (tree);
6800 static void schedule_generic_params_dies_gen (tree t);
6801 static void gen_scheduled_generic_parms_dies (void);
6803 /* Section names used to hold DWARF debugging information. */
6804 #ifndef DEBUG_INFO_SECTION
6805 #define DEBUG_INFO_SECTION ".debug_info"
6807 #ifndef DEBUG_ABBREV_SECTION
6808 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6810 #ifndef DEBUG_ARANGES_SECTION
6811 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6813 #ifndef DEBUG_MACINFO_SECTION
6814 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6816 #ifndef DEBUG_LINE_SECTION
6817 #define DEBUG_LINE_SECTION ".debug_line"
6819 #ifndef DEBUG_LOC_SECTION
6820 #define DEBUG_LOC_SECTION ".debug_loc"
6822 #ifndef DEBUG_PUBNAMES_SECTION
6823 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6825 #ifndef DEBUG_PUBTYPES_SECTION
6826 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6828 #ifndef DEBUG_STR_SECTION
6829 #define DEBUG_STR_SECTION ".debug_str"
6831 #ifndef DEBUG_RANGES_SECTION
6832 #define DEBUG_RANGES_SECTION ".debug_ranges"
6835 /* Standard ELF section names for compiled code and data. */
6836 #ifndef TEXT_SECTION_NAME
6837 #define TEXT_SECTION_NAME ".text"
6840 /* Section flags for .debug_str section. */
6841 #define DEBUG_STR_SECTION_FLAGS \
6842 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6843 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6846 /* Labels we insert at beginning sections we can reference instead of
6847 the section names themselves. */
6849 #ifndef TEXT_SECTION_LABEL
6850 #define TEXT_SECTION_LABEL "Ltext"
6852 #ifndef COLD_TEXT_SECTION_LABEL
6853 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6855 #ifndef DEBUG_LINE_SECTION_LABEL
6856 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6858 #ifndef DEBUG_INFO_SECTION_LABEL
6859 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6861 #ifndef DEBUG_ABBREV_SECTION_LABEL
6862 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6864 #ifndef DEBUG_LOC_SECTION_LABEL
6865 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6867 #ifndef DEBUG_RANGES_SECTION_LABEL
6868 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6870 #ifndef DEBUG_MACINFO_SECTION_LABEL
6871 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6875 /* Definitions of defaults for formats and names of various special
6876 (artificial) labels which may be generated within this file (when the -g
6877 options is used and DWARF2_DEBUGGING_INFO is in effect.
6878 If necessary, these may be overridden from within the tm.h file, but
6879 typically, overriding these defaults is unnecessary. */
6881 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6882 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6883 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6884 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6885 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6886 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6887 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6888 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6889 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6890 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6892 #ifndef TEXT_END_LABEL
6893 #define TEXT_END_LABEL "Letext"
6895 #ifndef COLD_END_LABEL
6896 #define COLD_END_LABEL "Letext_cold"
6898 #ifndef BLOCK_BEGIN_LABEL
6899 #define BLOCK_BEGIN_LABEL "LBB"
6901 #ifndef BLOCK_END_LABEL
6902 #define BLOCK_END_LABEL "LBE"
6904 #ifndef LINE_CODE_LABEL
6905 #define LINE_CODE_LABEL "LM"
6909 /* Return the root of the DIE's built for the current compilation unit. */
6911 comp_unit_die (void)
6913 if (!single_comp_unit_die)
6914 single_comp_unit_die = gen_compile_unit_die (NULL);
6915 return single_comp_unit_die;
6918 /* We allow a language front-end to designate a function that is to be
6919 called to "demangle" any name before it is put into a DIE. */
6921 static const char *(*demangle_name_func) (const char *);
6924 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6926 demangle_name_func = func;
6929 /* Test if rtl node points to a pseudo register. */
6932 is_pseudo_reg (const_rtx rtl)
6934 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6935 || (GET_CODE (rtl) == SUBREG
6936 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6939 /* Return a reference to a type, with its const and volatile qualifiers
6943 type_main_variant (tree type)
6945 type = TYPE_MAIN_VARIANT (type);
6947 /* ??? There really should be only one main variant among any group of
6948 variants of a given type (and all of the MAIN_VARIANT values for all
6949 members of the group should point to that one type) but sometimes the C
6950 front-end messes this up for array types, so we work around that bug
6952 if (TREE_CODE (type) == ARRAY_TYPE)
6953 while (type != TYPE_MAIN_VARIANT (type))
6954 type = TYPE_MAIN_VARIANT (type);
6959 /* Return nonzero if the given type node represents a tagged type. */
6962 is_tagged_type (const_tree type)
6964 enum tree_code code = TREE_CODE (type);
6966 return (code == RECORD_TYPE || code == UNION_TYPE
6967 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6970 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6973 get_ref_die_offset_label (char *label, dw_die_ref ref)
6975 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6978 /* Return die_offset of a DIE reference to a base type. */
6980 static unsigned long int
6981 get_base_type_offset (dw_die_ref ref)
6983 if (ref->die_offset)
6984 return ref->die_offset;
6985 if (comp_unit_die ()->die_abbrev)
6987 calc_base_type_die_sizes ();
6988 gcc_assert (ref->die_offset);
6990 return ref->die_offset;
6993 /* Return die_offset of a DIE reference other than base type. */
6995 static unsigned long int
6996 get_ref_die_offset (dw_die_ref ref)
6998 gcc_assert (ref->die_offset);
6999 return ref->die_offset;
7002 /* Convert a DIE tag into its string name. */
7005 dwarf_tag_name (unsigned int tag)
7009 case DW_TAG_padding:
7010 return "DW_TAG_padding";
7011 case DW_TAG_array_type:
7012 return "DW_TAG_array_type";
7013 case DW_TAG_class_type:
7014 return "DW_TAG_class_type";
7015 case DW_TAG_entry_point:
7016 return "DW_TAG_entry_point";
7017 case DW_TAG_enumeration_type:
7018 return "DW_TAG_enumeration_type";
7019 case DW_TAG_formal_parameter:
7020 return "DW_TAG_formal_parameter";
7021 case DW_TAG_imported_declaration:
7022 return "DW_TAG_imported_declaration";
7024 return "DW_TAG_label";
7025 case DW_TAG_lexical_block:
7026 return "DW_TAG_lexical_block";
7028 return "DW_TAG_member";
7029 case DW_TAG_pointer_type:
7030 return "DW_TAG_pointer_type";
7031 case DW_TAG_reference_type:
7032 return "DW_TAG_reference_type";
7033 case DW_TAG_compile_unit:
7034 return "DW_TAG_compile_unit";
7035 case DW_TAG_string_type:
7036 return "DW_TAG_string_type";
7037 case DW_TAG_structure_type:
7038 return "DW_TAG_structure_type";
7039 case DW_TAG_subroutine_type:
7040 return "DW_TAG_subroutine_type";
7041 case DW_TAG_typedef:
7042 return "DW_TAG_typedef";
7043 case DW_TAG_union_type:
7044 return "DW_TAG_union_type";
7045 case DW_TAG_unspecified_parameters:
7046 return "DW_TAG_unspecified_parameters";
7047 case DW_TAG_variant:
7048 return "DW_TAG_variant";
7049 case DW_TAG_common_block:
7050 return "DW_TAG_common_block";
7051 case DW_TAG_common_inclusion:
7052 return "DW_TAG_common_inclusion";
7053 case DW_TAG_inheritance:
7054 return "DW_TAG_inheritance";
7055 case DW_TAG_inlined_subroutine:
7056 return "DW_TAG_inlined_subroutine";
7058 return "DW_TAG_module";
7059 case DW_TAG_ptr_to_member_type:
7060 return "DW_TAG_ptr_to_member_type";
7061 case DW_TAG_set_type:
7062 return "DW_TAG_set_type";
7063 case DW_TAG_subrange_type:
7064 return "DW_TAG_subrange_type";
7065 case DW_TAG_with_stmt:
7066 return "DW_TAG_with_stmt";
7067 case DW_TAG_access_declaration:
7068 return "DW_TAG_access_declaration";
7069 case DW_TAG_base_type:
7070 return "DW_TAG_base_type";
7071 case DW_TAG_catch_block:
7072 return "DW_TAG_catch_block";
7073 case DW_TAG_const_type:
7074 return "DW_TAG_const_type";
7075 case DW_TAG_constant:
7076 return "DW_TAG_constant";
7077 case DW_TAG_enumerator:
7078 return "DW_TAG_enumerator";
7079 case DW_TAG_file_type:
7080 return "DW_TAG_file_type";
7082 return "DW_TAG_friend";
7083 case DW_TAG_namelist:
7084 return "DW_TAG_namelist";
7085 case DW_TAG_namelist_item:
7086 return "DW_TAG_namelist_item";
7087 case DW_TAG_packed_type:
7088 return "DW_TAG_packed_type";
7089 case DW_TAG_subprogram:
7090 return "DW_TAG_subprogram";
7091 case DW_TAG_template_type_param:
7092 return "DW_TAG_template_type_param";
7093 case DW_TAG_template_value_param:
7094 return "DW_TAG_template_value_param";
7095 case DW_TAG_thrown_type:
7096 return "DW_TAG_thrown_type";
7097 case DW_TAG_try_block:
7098 return "DW_TAG_try_block";
7099 case DW_TAG_variant_part:
7100 return "DW_TAG_variant_part";
7101 case DW_TAG_variable:
7102 return "DW_TAG_variable";
7103 case DW_TAG_volatile_type:
7104 return "DW_TAG_volatile_type";
7105 case DW_TAG_dwarf_procedure:
7106 return "DW_TAG_dwarf_procedure";
7107 case DW_TAG_restrict_type:
7108 return "DW_TAG_restrict_type";
7109 case DW_TAG_interface_type:
7110 return "DW_TAG_interface_type";
7111 case DW_TAG_namespace:
7112 return "DW_TAG_namespace";
7113 case DW_TAG_imported_module:
7114 return "DW_TAG_imported_module";
7115 case DW_TAG_unspecified_type:
7116 return "DW_TAG_unspecified_type";
7117 case DW_TAG_partial_unit:
7118 return "DW_TAG_partial_unit";
7119 case DW_TAG_imported_unit:
7120 return "DW_TAG_imported_unit";
7121 case DW_TAG_condition:
7122 return "DW_TAG_condition";
7123 case DW_TAG_shared_type:
7124 return "DW_TAG_shared_type";
7125 case DW_TAG_type_unit:
7126 return "DW_TAG_type_unit";
7127 case DW_TAG_rvalue_reference_type:
7128 return "DW_TAG_rvalue_reference_type";
7129 case DW_TAG_template_alias:
7130 return "DW_TAG_template_alias";
7131 case DW_TAG_GNU_template_parameter_pack:
7132 return "DW_TAG_GNU_template_parameter_pack";
7133 case DW_TAG_GNU_formal_parameter_pack:
7134 return "DW_TAG_GNU_formal_parameter_pack";
7135 case DW_TAG_MIPS_loop:
7136 return "DW_TAG_MIPS_loop";
7137 case DW_TAG_format_label:
7138 return "DW_TAG_format_label";
7139 case DW_TAG_function_template:
7140 return "DW_TAG_function_template";
7141 case DW_TAG_class_template:
7142 return "DW_TAG_class_template";
7143 case DW_TAG_GNU_BINCL:
7144 return "DW_TAG_GNU_BINCL";
7145 case DW_TAG_GNU_EINCL:
7146 return "DW_TAG_GNU_EINCL";
7147 case DW_TAG_GNU_template_template_param:
7148 return "DW_TAG_GNU_template_template_param";
7149 case DW_TAG_GNU_call_site:
7150 return "DW_TAG_GNU_call_site";
7151 case DW_TAG_GNU_call_site_parameter:
7152 return "DW_TAG_GNU_call_site_parameter";
7154 return "DW_TAG_<unknown>";
7158 /* Convert a DWARF attribute code into its string name. */
7161 dwarf_attr_name (unsigned int attr)
7166 return "DW_AT_sibling";
7167 case DW_AT_location:
7168 return "DW_AT_location";
7170 return "DW_AT_name";
7171 case DW_AT_ordering:
7172 return "DW_AT_ordering";
7173 case DW_AT_subscr_data:
7174 return "DW_AT_subscr_data";
7175 case DW_AT_byte_size:
7176 return "DW_AT_byte_size";
7177 case DW_AT_bit_offset:
7178 return "DW_AT_bit_offset";
7179 case DW_AT_bit_size:
7180 return "DW_AT_bit_size";
7181 case DW_AT_element_list:
7182 return "DW_AT_element_list";
7183 case DW_AT_stmt_list:
7184 return "DW_AT_stmt_list";
7186 return "DW_AT_low_pc";
7188 return "DW_AT_high_pc";
7189 case DW_AT_language:
7190 return "DW_AT_language";
7192 return "DW_AT_member";
7194 return "DW_AT_discr";
7195 case DW_AT_discr_value:
7196 return "DW_AT_discr_value";
7197 case DW_AT_visibility:
7198 return "DW_AT_visibility";
7200 return "DW_AT_import";
7201 case DW_AT_string_length:
7202 return "DW_AT_string_length";
7203 case DW_AT_common_reference:
7204 return "DW_AT_common_reference";
7205 case DW_AT_comp_dir:
7206 return "DW_AT_comp_dir";
7207 case DW_AT_const_value:
7208 return "DW_AT_const_value";
7209 case DW_AT_containing_type:
7210 return "DW_AT_containing_type";
7211 case DW_AT_default_value:
7212 return "DW_AT_default_value";
7214 return "DW_AT_inline";
7215 case DW_AT_is_optional:
7216 return "DW_AT_is_optional";
7217 case DW_AT_lower_bound:
7218 return "DW_AT_lower_bound";
7219 case DW_AT_producer:
7220 return "DW_AT_producer";
7221 case DW_AT_prototyped:
7222 return "DW_AT_prototyped";
7223 case DW_AT_return_addr:
7224 return "DW_AT_return_addr";
7225 case DW_AT_start_scope:
7226 return "DW_AT_start_scope";
7227 case DW_AT_bit_stride:
7228 return "DW_AT_bit_stride";
7229 case DW_AT_upper_bound:
7230 return "DW_AT_upper_bound";
7231 case DW_AT_abstract_origin:
7232 return "DW_AT_abstract_origin";
7233 case DW_AT_accessibility:
7234 return "DW_AT_accessibility";
7235 case DW_AT_address_class:
7236 return "DW_AT_address_class";
7237 case DW_AT_artificial:
7238 return "DW_AT_artificial";
7239 case DW_AT_base_types:
7240 return "DW_AT_base_types";
7241 case DW_AT_calling_convention:
7242 return "DW_AT_calling_convention";
7244 return "DW_AT_count";
7245 case DW_AT_data_member_location:
7246 return "DW_AT_data_member_location";
7247 case DW_AT_decl_column:
7248 return "DW_AT_decl_column";
7249 case DW_AT_decl_file:
7250 return "DW_AT_decl_file";
7251 case DW_AT_decl_line:
7252 return "DW_AT_decl_line";
7253 case DW_AT_declaration:
7254 return "DW_AT_declaration";
7255 case DW_AT_discr_list:
7256 return "DW_AT_discr_list";
7257 case DW_AT_encoding:
7258 return "DW_AT_encoding";
7259 case DW_AT_external:
7260 return "DW_AT_external";
7261 case DW_AT_explicit:
7262 return "DW_AT_explicit";
7263 case DW_AT_frame_base:
7264 return "DW_AT_frame_base";
7266 return "DW_AT_friend";
7267 case DW_AT_identifier_case:
7268 return "DW_AT_identifier_case";
7269 case DW_AT_macro_info:
7270 return "DW_AT_macro_info";
7271 case DW_AT_namelist_items:
7272 return "DW_AT_namelist_items";
7273 case DW_AT_priority:
7274 return "DW_AT_priority";
7276 return "DW_AT_segment";
7277 case DW_AT_specification:
7278 return "DW_AT_specification";
7279 case DW_AT_static_link:
7280 return "DW_AT_static_link";
7282 return "DW_AT_type";
7283 case DW_AT_use_location:
7284 return "DW_AT_use_location";
7285 case DW_AT_variable_parameter:
7286 return "DW_AT_variable_parameter";
7287 case DW_AT_virtuality:
7288 return "DW_AT_virtuality";
7289 case DW_AT_vtable_elem_location:
7290 return "DW_AT_vtable_elem_location";
7292 case DW_AT_allocated:
7293 return "DW_AT_allocated";
7294 case DW_AT_associated:
7295 return "DW_AT_associated";
7296 case DW_AT_data_location:
7297 return "DW_AT_data_location";
7298 case DW_AT_byte_stride:
7299 return "DW_AT_byte_stride";
7300 case DW_AT_entry_pc:
7301 return "DW_AT_entry_pc";
7302 case DW_AT_use_UTF8:
7303 return "DW_AT_use_UTF8";
7304 case DW_AT_extension:
7305 return "DW_AT_extension";
7307 return "DW_AT_ranges";
7308 case DW_AT_trampoline:
7309 return "DW_AT_trampoline";
7310 case DW_AT_call_column:
7311 return "DW_AT_call_column";
7312 case DW_AT_call_file:
7313 return "DW_AT_call_file";
7314 case DW_AT_call_line:
7315 return "DW_AT_call_line";
7316 case DW_AT_object_pointer:
7317 return "DW_AT_object_pointer";
7319 case DW_AT_signature:
7320 return "DW_AT_signature";
7321 case DW_AT_main_subprogram:
7322 return "DW_AT_main_subprogram";
7323 case DW_AT_data_bit_offset:
7324 return "DW_AT_data_bit_offset";
7325 case DW_AT_const_expr:
7326 return "DW_AT_const_expr";
7327 case DW_AT_enum_class:
7328 return "DW_AT_enum_class";
7329 case DW_AT_linkage_name:
7330 return "DW_AT_linkage_name";
7332 case DW_AT_MIPS_fde:
7333 return "DW_AT_MIPS_fde";
7334 case DW_AT_MIPS_loop_begin:
7335 return "DW_AT_MIPS_loop_begin";
7336 case DW_AT_MIPS_tail_loop_begin:
7337 return "DW_AT_MIPS_tail_loop_begin";
7338 case DW_AT_MIPS_epilog_begin:
7339 return "DW_AT_MIPS_epilog_begin";
7340 #if VMS_DEBUGGING_INFO
7341 case DW_AT_HP_prologue:
7342 return "DW_AT_HP_prologue";
7344 case DW_AT_MIPS_loop_unroll_factor:
7345 return "DW_AT_MIPS_loop_unroll_factor";
7347 case DW_AT_MIPS_software_pipeline_depth:
7348 return "DW_AT_MIPS_software_pipeline_depth";
7349 case DW_AT_MIPS_linkage_name:
7350 return "DW_AT_MIPS_linkage_name";
7351 #if VMS_DEBUGGING_INFO
7352 case DW_AT_HP_epilogue:
7353 return "DW_AT_HP_epilogue";
7355 case DW_AT_MIPS_stride:
7356 return "DW_AT_MIPS_stride";
7358 case DW_AT_MIPS_abstract_name:
7359 return "DW_AT_MIPS_abstract_name";
7360 case DW_AT_MIPS_clone_origin:
7361 return "DW_AT_MIPS_clone_origin";
7362 case DW_AT_MIPS_has_inlines:
7363 return "DW_AT_MIPS_has_inlines";
7365 case DW_AT_sf_names:
7366 return "DW_AT_sf_names";
7367 case DW_AT_src_info:
7368 return "DW_AT_src_info";
7369 case DW_AT_mac_info:
7370 return "DW_AT_mac_info";
7371 case DW_AT_src_coords:
7372 return "DW_AT_src_coords";
7373 case DW_AT_body_begin:
7374 return "DW_AT_body_begin";
7375 case DW_AT_body_end:
7376 return "DW_AT_body_end";
7378 case DW_AT_GNU_vector:
7379 return "DW_AT_GNU_vector";
7380 case DW_AT_GNU_guarded_by:
7381 return "DW_AT_GNU_guarded_by";
7382 case DW_AT_GNU_pt_guarded_by:
7383 return "DW_AT_GNU_pt_guarded_by";
7384 case DW_AT_GNU_guarded:
7385 return "DW_AT_GNU_guarded";
7386 case DW_AT_GNU_pt_guarded:
7387 return "DW_AT_GNU_pt_guarded";
7388 case DW_AT_GNU_locks_excluded:
7389 return "DW_AT_GNU_locks_excluded";
7390 case DW_AT_GNU_exclusive_locks_required:
7391 return "DW_AT_GNU_exclusive_locks_required";
7392 case DW_AT_GNU_shared_locks_required:
7393 return "DW_AT_GNU_shared_locks_required";
7394 case DW_AT_GNU_odr_signature:
7395 return "DW_AT_GNU_odr_signature";
7396 case DW_AT_GNU_template_name:
7397 return "DW_AT_GNU_template_name";
7398 case DW_AT_GNU_call_site_value:
7399 return "DW_AT_GNU_call_site_value";
7400 case DW_AT_GNU_call_site_data_value:
7401 return "DW_AT_GNU_call_site_data_value";
7402 case DW_AT_GNU_call_site_target:
7403 return "DW_AT_GNU_call_site_target";
7404 case DW_AT_GNU_call_site_target_clobbered:
7405 return "DW_AT_GNU_call_site_target_clobbered";
7406 case DW_AT_GNU_tail_call:
7407 return "DW_AT_GNU_tail_call";
7408 case DW_AT_GNU_all_tail_call_sites:
7409 return "DW_AT_GNU_all_tail_call_sites";
7410 case DW_AT_GNU_all_call_sites:
7411 return "DW_AT_GNU_all_call_sites";
7412 case DW_AT_GNU_all_source_call_sites:
7413 return "DW_AT_GNU_all_source_call_sites";
7415 case DW_AT_GNAT_descriptive_type:
7416 return "DW_AT_GNAT_descriptive_type";
7418 case DW_AT_VMS_rtnbeg_pd_address:
7419 return "DW_AT_VMS_rtnbeg_pd_address";
7422 return "DW_AT_<unknown>";
7426 /* Convert a DWARF value form code into its string name. */
7429 dwarf_form_name (unsigned int form)
7434 return "DW_FORM_addr";
7435 case DW_FORM_block2:
7436 return "DW_FORM_block2";
7437 case DW_FORM_block4:
7438 return "DW_FORM_block4";
7440 return "DW_FORM_data2";
7442 return "DW_FORM_data4";
7444 return "DW_FORM_data8";
7445 case DW_FORM_string:
7446 return "DW_FORM_string";
7448 return "DW_FORM_block";
7449 case DW_FORM_block1:
7450 return "DW_FORM_block1";
7452 return "DW_FORM_data1";
7454 return "DW_FORM_flag";
7456 return "DW_FORM_sdata";
7458 return "DW_FORM_strp";
7460 return "DW_FORM_udata";
7461 case DW_FORM_ref_addr:
7462 return "DW_FORM_ref_addr";
7464 return "DW_FORM_ref1";
7466 return "DW_FORM_ref2";
7468 return "DW_FORM_ref4";
7470 return "DW_FORM_ref8";
7471 case DW_FORM_ref_udata:
7472 return "DW_FORM_ref_udata";
7473 case DW_FORM_indirect:
7474 return "DW_FORM_indirect";
7475 case DW_FORM_sec_offset:
7476 return "DW_FORM_sec_offset";
7477 case DW_FORM_exprloc:
7478 return "DW_FORM_exprloc";
7479 case DW_FORM_flag_present:
7480 return "DW_FORM_flag_present";
7481 case DW_FORM_ref_sig8:
7482 return "DW_FORM_ref_sig8";
7484 return "DW_FORM_<unknown>";
7488 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7489 instance of an inlined instance of a decl which is local to an inline
7490 function, so we have to trace all of the way back through the origin chain
7491 to find out what sort of node actually served as the original seed for the
7495 decl_ultimate_origin (const_tree decl)
7497 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7500 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7501 nodes in the function to point to themselves; ignore that if
7502 we're trying to output the abstract instance of this function. */
7503 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7506 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7507 most distant ancestor, this should never happen. */
7508 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7510 return DECL_ABSTRACT_ORIGIN (decl);
7513 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7514 of a virtual function may refer to a base class, so we check the 'this'
7518 decl_class_context (tree decl)
7520 tree context = NULL_TREE;
7522 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7523 context = DECL_CONTEXT (decl);
7525 context = TYPE_MAIN_VARIANT
7526 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7528 if (context && !TYPE_P (context))
7529 context = NULL_TREE;
7534 /* Add an attribute/value pair to a DIE. */
7537 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7539 /* Maybe this should be an assert? */
7543 if (die->die_attr == NULL)
7544 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7545 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7548 static inline enum dw_val_class
7549 AT_class (dw_attr_ref a)
7551 return a->dw_attr_val.val_class;
7554 /* Add a flag value attribute to a DIE. */
7557 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7561 attr.dw_attr = attr_kind;
7562 attr.dw_attr_val.val_class = dw_val_class_flag;
7563 attr.dw_attr_val.v.val_flag = flag;
7564 add_dwarf_attr (die, &attr);
7567 static inline unsigned
7568 AT_flag (dw_attr_ref a)
7570 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7571 return a->dw_attr_val.v.val_flag;
7574 /* Add a signed integer attribute value to a DIE. */
7577 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7581 attr.dw_attr = attr_kind;
7582 attr.dw_attr_val.val_class = dw_val_class_const;
7583 attr.dw_attr_val.v.val_int = int_val;
7584 add_dwarf_attr (die, &attr);
7587 static inline HOST_WIDE_INT
7588 AT_int (dw_attr_ref a)
7590 gcc_assert (a && AT_class (a) == dw_val_class_const);
7591 return a->dw_attr_val.v.val_int;
7594 /* Add an unsigned integer attribute value to a DIE. */
7597 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7598 unsigned HOST_WIDE_INT unsigned_val)
7602 attr.dw_attr = attr_kind;
7603 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7604 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7605 add_dwarf_attr (die, &attr);
7608 static inline unsigned HOST_WIDE_INT
7609 AT_unsigned (dw_attr_ref a)
7611 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7612 return a->dw_attr_val.v.val_unsigned;
7615 /* Add an unsigned double integer attribute value to a DIE. */
7618 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7619 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7623 attr.dw_attr = attr_kind;
7624 attr.dw_attr_val.val_class = dw_val_class_const_double;
7625 attr.dw_attr_val.v.val_double.high = high;
7626 attr.dw_attr_val.v.val_double.low = low;
7627 add_dwarf_attr (die, &attr);
7630 /* Add a floating point attribute value to a DIE and return it. */
7633 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7634 unsigned int length, unsigned int elt_size, unsigned char *array)
7638 attr.dw_attr = attr_kind;
7639 attr.dw_attr_val.val_class = dw_val_class_vec;
7640 attr.dw_attr_val.v.val_vec.length = length;
7641 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7642 attr.dw_attr_val.v.val_vec.array = array;
7643 add_dwarf_attr (die, &attr);
7646 /* Add an 8-byte data attribute value to a DIE. */
7649 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7650 unsigned char data8[8])
7654 attr.dw_attr = attr_kind;
7655 attr.dw_attr_val.val_class = dw_val_class_data8;
7656 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7657 add_dwarf_attr (die, &attr);
7660 /* Hash and equality functions for debug_str_hash. */
7663 debug_str_do_hash (const void *x)
7665 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7669 debug_str_eq (const void *x1, const void *x2)
7671 return strcmp ((((const struct indirect_string_node *)x1)->str),
7672 (const char *)x2) == 0;
7675 /* Add STR to the indirect string hash table. */
7677 static struct indirect_string_node *
7678 find_AT_string (const char *str)
7680 struct indirect_string_node *node;
7683 if (! debug_str_hash)
7684 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7685 debug_str_eq, NULL);
7687 slot = htab_find_slot_with_hash (debug_str_hash, str,
7688 htab_hash_string (str), INSERT);
7691 node = ggc_alloc_cleared_indirect_string_node ();
7692 node->str = ggc_strdup (str);
7696 node = (struct indirect_string_node *) *slot;
7702 /* Add a string attribute value to a DIE. */
7705 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7708 struct indirect_string_node *node;
7710 node = find_AT_string (str);
7712 attr.dw_attr = attr_kind;
7713 attr.dw_attr_val.val_class = dw_val_class_str;
7714 attr.dw_attr_val.v.val_str = node;
7715 add_dwarf_attr (die, &attr);
7718 static inline const char *
7719 AT_string (dw_attr_ref a)
7721 gcc_assert (a && AT_class (a) == dw_val_class_str);
7722 return a->dw_attr_val.v.val_str->str;
7725 /* Find out whether a string should be output inline in DIE
7726 or out-of-line in .debug_str section. */
7728 static enum dwarf_form
7729 AT_string_form (dw_attr_ref a)
7731 struct indirect_string_node *node;
7735 gcc_assert (a && AT_class (a) == dw_val_class_str);
7737 node = a->dw_attr_val.v.val_str;
7741 len = strlen (node->str) + 1;
7743 /* If the string is shorter or equal to the size of the reference, it is
7744 always better to put it inline. */
7745 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7746 return node->form = DW_FORM_string;
7748 /* If we cannot expect the linker to merge strings in .debug_str
7749 section, only put it into .debug_str if it is worth even in this
7751 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7752 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7753 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7754 return node->form = DW_FORM_string;
7756 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7757 ++dw2_string_counter;
7758 node->label = xstrdup (label);
7760 return node->form = DW_FORM_strp;
7763 /* Add a DIE reference attribute value to a DIE. */
7766 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7770 #ifdef ENABLE_CHECKING
7771 gcc_assert (targ_die != NULL);
7773 /* With LTO we can end up trying to reference something we didn't create
7774 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7775 if (targ_die == NULL)
7779 attr.dw_attr = attr_kind;
7780 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7781 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7782 attr.dw_attr_val.v.val_die_ref.external = 0;
7783 add_dwarf_attr (die, &attr);
7786 /* Add an AT_specification attribute to a DIE, and also make the back
7787 pointer from the specification to the definition. */
7790 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7792 add_AT_die_ref (die, DW_AT_specification, targ_die);
7793 gcc_assert (!targ_die->die_definition);
7794 targ_die->die_definition = die;
7797 static inline dw_die_ref
7798 AT_ref (dw_attr_ref a)
7800 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7801 return a->dw_attr_val.v.val_die_ref.die;
7805 AT_ref_external (dw_attr_ref a)
7807 if (a && AT_class (a) == dw_val_class_die_ref)
7808 return a->dw_attr_val.v.val_die_ref.external;
7814 set_AT_ref_external (dw_attr_ref a, int i)
7816 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7817 a->dw_attr_val.v.val_die_ref.external = i;
7820 /* Add an FDE reference attribute value to a DIE. */
7823 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7827 attr.dw_attr = attr_kind;
7828 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7829 attr.dw_attr_val.v.val_fde_index = targ_fde;
7830 add_dwarf_attr (die, &attr);
7833 /* Add a location description attribute value to a DIE. */
7836 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7840 attr.dw_attr = attr_kind;
7841 attr.dw_attr_val.val_class = dw_val_class_loc;
7842 attr.dw_attr_val.v.val_loc = loc;
7843 add_dwarf_attr (die, &attr);
7846 static inline dw_loc_descr_ref
7847 AT_loc (dw_attr_ref a)
7849 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7850 return a->dw_attr_val.v.val_loc;
7854 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7858 attr.dw_attr = attr_kind;
7859 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7860 attr.dw_attr_val.v.val_loc_list = loc_list;
7861 add_dwarf_attr (die, &attr);
7862 have_location_lists = true;
7865 static inline dw_loc_list_ref
7866 AT_loc_list (dw_attr_ref a)
7868 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7869 return a->dw_attr_val.v.val_loc_list;
7872 static inline dw_loc_list_ref *
7873 AT_loc_list_ptr (dw_attr_ref a)
7875 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7876 return &a->dw_attr_val.v.val_loc_list;
7879 /* Add an address constant attribute value to a DIE. */
7882 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7886 attr.dw_attr = attr_kind;
7887 attr.dw_attr_val.val_class = dw_val_class_addr;
7888 attr.dw_attr_val.v.val_addr = addr;
7889 add_dwarf_attr (die, &attr);
7892 /* Get the RTX from to an address DIE attribute. */
7895 AT_addr (dw_attr_ref a)
7897 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7898 return a->dw_attr_val.v.val_addr;
7901 /* Add a file attribute value to a DIE. */
7904 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7905 struct dwarf_file_data *fd)
7909 attr.dw_attr = attr_kind;
7910 attr.dw_attr_val.val_class = dw_val_class_file;
7911 attr.dw_attr_val.v.val_file = fd;
7912 add_dwarf_attr (die, &attr);
7915 /* Get the dwarf_file_data from a file DIE attribute. */
7917 static inline struct dwarf_file_data *
7918 AT_file (dw_attr_ref a)
7920 gcc_assert (a && AT_class (a) == dw_val_class_file);
7921 return a->dw_attr_val.v.val_file;
7924 /* Add a vms delta attribute value to a DIE. */
7927 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7928 const char *lbl1, const char *lbl2)
7932 attr.dw_attr = attr_kind;
7933 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7934 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7935 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7936 add_dwarf_attr (die, &attr);
7939 /* Add a label identifier attribute value to a DIE. */
7942 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7946 attr.dw_attr = attr_kind;
7947 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7948 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7949 add_dwarf_attr (die, &attr);
7952 /* Add a section offset attribute value to a DIE, an offset into the
7953 debug_line section. */
7956 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7961 attr.dw_attr = attr_kind;
7962 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7963 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7964 add_dwarf_attr (die, &attr);
7967 /* Add a section offset attribute value to a DIE, an offset into the
7968 debug_macinfo section. */
7971 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7976 attr.dw_attr = attr_kind;
7977 attr.dw_attr_val.val_class = dw_val_class_macptr;
7978 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7979 add_dwarf_attr (die, &attr);
7982 /* Add an offset attribute value to a DIE. */
7985 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7986 unsigned HOST_WIDE_INT offset)
7990 attr.dw_attr = attr_kind;
7991 attr.dw_attr_val.val_class = dw_val_class_offset;
7992 attr.dw_attr_val.v.val_offset = offset;
7993 add_dwarf_attr (die, &attr);
7996 /* Add an range_list attribute value to a DIE. */
7999 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
8000 long unsigned int offset)
8004 attr.dw_attr = attr_kind;
8005 attr.dw_attr_val.val_class = dw_val_class_range_list;
8006 attr.dw_attr_val.v.val_offset = offset;
8007 add_dwarf_attr (die, &attr);
8010 /* Return the start label of a delta attribute. */
8012 static inline const char *
8013 AT_vms_delta1 (dw_attr_ref a)
8015 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
8016 return a->dw_attr_val.v.val_vms_delta.lbl1;
8019 /* Return the end label of a delta attribute. */
8021 static inline const char *
8022 AT_vms_delta2 (dw_attr_ref a)
8024 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
8025 return a->dw_attr_val.v.val_vms_delta.lbl2;
8028 static inline const char *
8029 AT_lbl (dw_attr_ref a)
8031 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
8032 || AT_class (a) == dw_val_class_lineptr
8033 || AT_class (a) == dw_val_class_macptr));
8034 return a->dw_attr_val.v.val_lbl_id;
8037 /* Get the attribute of type attr_kind. */
8040 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
8044 dw_die_ref spec = NULL;
8049 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8050 if (a->dw_attr == attr_kind)
8052 else if (a->dw_attr == DW_AT_specification
8053 || a->dw_attr == DW_AT_abstract_origin)
8057 return get_AT (spec, attr_kind);
8062 /* Return the "low pc" attribute value, typically associated with a subprogram
8063 DIE. Return null if the "low pc" attribute is either not present, or if it
8064 cannot be represented as an assembler label identifier. */
8066 static inline const char *
8067 get_AT_low_pc (dw_die_ref die)
8069 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
8071 return a ? AT_lbl (a) : NULL;
8074 /* Return the "high pc" attribute value, typically associated with a subprogram
8075 DIE. Return null if the "high pc" attribute is either not present, or if it
8076 cannot be represented as an assembler label identifier. */
8078 static inline const char *
8079 get_AT_hi_pc (dw_die_ref die)
8081 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
8083 return a ? AT_lbl (a) : NULL;
8086 /* Return the value of the string attribute designated by ATTR_KIND, or
8087 NULL if it is not present. */
8089 static inline const char *
8090 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
8092 dw_attr_ref a = get_AT (die, attr_kind);
8094 return a ? AT_string (a) : NULL;
8097 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
8098 if it is not present. */
8101 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
8103 dw_attr_ref a = get_AT (die, attr_kind);
8105 return a ? AT_flag (a) : 0;
8108 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
8109 if it is not present. */
8111 static inline unsigned
8112 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
8114 dw_attr_ref a = get_AT (die, attr_kind);
8116 return a ? AT_unsigned (a) : 0;
8119 static inline dw_die_ref
8120 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
8122 dw_attr_ref a = get_AT (die, attr_kind);
8124 return a ? AT_ref (a) : NULL;
8127 static inline struct dwarf_file_data *
8128 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
8130 dw_attr_ref a = get_AT (die, attr_kind);
8132 return a ? AT_file (a) : NULL;
8135 /* Return TRUE if the language is C++. */
8140 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8142 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
8145 /* Return TRUE if the language is Fortran. */
8150 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8152 return (lang == DW_LANG_Fortran77
8153 || lang == DW_LANG_Fortran90
8154 || lang == DW_LANG_Fortran95);
8157 /* Return TRUE if the language is Ada. */
8162 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8164 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
8167 /* Remove the specified attribute if present. */
8170 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
8178 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8179 if (a->dw_attr == attr_kind)
8181 if (AT_class (a) == dw_val_class_str)
8182 if (a->dw_attr_val.v.val_str->refcount)
8183 a->dw_attr_val.v.val_str->refcount--;
8185 /* VEC_ordered_remove should help reduce the number of abbrevs
8187 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
8192 /* Remove CHILD from its parent. PREV must have the property that
8193 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
8196 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
8198 gcc_assert (child->die_parent == prev->die_parent);
8199 gcc_assert (prev->die_sib == child);
8202 gcc_assert (child->die_parent->die_child == child);
8206 prev->die_sib = child->die_sib;
8207 if (child->die_parent->die_child == child)
8208 child->die_parent->die_child = prev;
8211 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
8212 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
8215 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
8217 dw_die_ref parent = old_child->die_parent;
8219 gcc_assert (parent == prev->die_parent);
8220 gcc_assert (prev->die_sib == old_child);
8222 new_child->die_parent = parent;
8223 if (prev == old_child)
8225 gcc_assert (parent->die_child == old_child);
8226 new_child->die_sib = new_child;
8230 prev->die_sib = new_child;
8231 new_child->die_sib = old_child->die_sib;
8233 if (old_child->die_parent->die_child == old_child)
8234 old_child->die_parent->die_child = new_child;
8237 /* Move all children from OLD_PARENT to NEW_PARENT. */
8240 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
8243 new_parent->die_child = old_parent->die_child;
8244 old_parent->die_child = NULL;
8245 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
8248 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8252 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8258 dw_die_ref prev = c;
8260 while (c->die_tag == tag)
8262 remove_child_with_prev (c, prev);
8263 /* Might have removed every child. */
8264 if (c == c->die_sib)
8268 } while (c != die->die_child);
8271 /* Add a CHILD_DIE as the last child of DIE. */
8274 add_child_die (dw_die_ref die, dw_die_ref child_die)
8276 /* FIXME this should probably be an assert. */
8277 if (! die || ! child_die)
8279 gcc_assert (die != child_die);
8281 child_die->die_parent = die;
8284 child_die->die_sib = die->die_child->die_sib;
8285 die->die_child->die_sib = child_die;
8288 child_die->die_sib = child_die;
8289 die->die_child = child_die;
8292 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8293 is the specification, to the end of PARENT's list of children.
8294 This is done by removing and re-adding it. */
8297 splice_child_die (dw_die_ref parent, dw_die_ref child)
8301 /* We want the declaration DIE from inside the class, not the
8302 specification DIE at toplevel. */
8303 if (child->die_parent != parent)
8305 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8311 gcc_assert (child->die_parent == parent
8312 || (child->die_parent
8313 == get_AT_ref (parent, DW_AT_specification)));
8315 for (p = child->die_parent->die_child; ; p = p->die_sib)
8316 if (p->die_sib == child)
8318 remove_child_with_prev (child, p);
8322 add_child_die (parent, child);
8325 /* Return a pointer to a newly created DIE node. */
8327 static inline dw_die_ref
8328 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8330 dw_die_ref die = ggc_alloc_cleared_die_node ();
8332 die->die_tag = tag_value;
8334 if (parent_die != NULL)
8335 add_child_die (parent_die, die);
8338 limbo_die_node *limbo_node;
8340 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8341 limbo_node->die = die;
8342 limbo_node->created_for = t;
8343 limbo_node->next = limbo_die_list;
8344 limbo_die_list = limbo_node;
8350 /* Return the DIE associated with the given type specifier. */
8352 static inline dw_die_ref
8353 lookup_type_die (tree type)
8355 return TYPE_SYMTAB_DIE (type);
8358 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8359 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8360 anonymous type instead the one of the naming typedef. */
8362 static inline dw_die_ref
8363 strip_naming_typedef (tree type, dw_die_ref type_die)
8366 && TREE_CODE (type) == RECORD_TYPE
8368 && type_die->die_tag == DW_TAG_typedef
8369 && is_naming_typedef_decl (TYPE_NAME (type)))
8370 type_die = get_AT_ref (type_die, DW_AT_type);
8374 /* Like lookup_type_die, but if type is an anonymous type named by a
8375 typedef[1], return the DIE of the anonymous type instead the one of
8376 the naming typedef. This is because in gen_typedef_die, we did
8377 equate the anonymous struct named by the typedef with the DIE of
8378 the naming typedef. So by default, lookup_type_die on an anonymous
8379 struct yields the DIE of the naming typedef.
8381 [1]: Read the comment of is_naming_typedef_decl to learn about what
8382 a naming typedef is. */
8384 static inline dw_die_ref
8385 lookup_type_die_strip_naming_typedef (tree type)
8387 dw_die_ref die = lookup_type_die (type);
8388 return strip_naming_typedef (type, die);
8391 /* Equate a DIE to a given type specifier. */
8394 equate_type_number_to_die (tree type, dw_die_ref type_die)
8396 TYPE_SYMTAB_DIE (type) = type_die;
8399 /* Returns a hash value for X (which really is a die_struct). */
8402 decl_die_table_hash (const void *x)
8404 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8407 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8410 decl_die_table_eq (const void *x, const void *y)
8412 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8415 /* Return the DIE associated with a given declaration. */
8417 static inline dw_die_ref
8418 lookup_decl_die (tree decl)
8420 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8423 /* Returns a hash value for X (which really is a var_loc_list). */
8426 decl_loc_table_hash (const void *x)
8428 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8431 /* Return nonzero if decl_id of var_loc_list X is the same as
8435 decl_loc_table_eq (const void *x, const void *y)
8437 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8440 /* Return the var_loc list associated with a given declaration. */
8442 static inline var_loc_list *
8443 lookup_decl_loc (const_tree decl)
8445 if (!decl_loc_table)
8447 return (var_loc_list *)
8448 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8451 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
8454 cached_dw_loc_list_table_hash (const void *x)
8456 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
8459 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
8463 cached_dw_loc_list_table_eq (const void *x, const void *y)
8465 return (((const cached_dw_loc_list *) x)->decl_id
8466 == DECL_UID ((const_tree) y));
8469 /* Equate a DIE to a particular declaration. */
8472 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8474 unsigned int decl_id = DECL_UID (decl);
8477 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8479 decl_die->decl_id = decl_id;
8482 /* Return how many bits covers PIECE EXPR_LIST. */
8485 decl_piece_bitsize (rtx piece)
8487 int ret = (int) GET_MODE (piece);
8490 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8491 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8492 return INTVAL (XEXP (XEXP (piece, 0), 0));
8495 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8498 decl_piece_varloc_ptr (rtx piece)
8500 if ((int) GET_MODE (piece))
8501 return &XEXP (piece, 0);
8503 return &XEXP (XEXP (piece, 0), 1);
8506 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8507 Next is the chain of following piece nodes. */
8510 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8512 if (bitsize <= (int) MAX_MACHINE_MODE)
8513 return alloc_EXPR_LIST (bitsize, loc_note, next);
8515 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8520 /* Return rtx that should be stored into loc field for
8521 LOC_NOTE and BITPOS/BITSIZE. */
8524 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8525 HOST_WIDE_INT bitsize)
8529 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8531 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8536 /* This function either modifies location piece list *DEST in
8537 place (if SRC and INNER is NULL), or copies location piece list
8538 *SRC to *DEST while modifying it. Location BITPOS is modified
8539 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8540 not copied and if needed some padding around it is added.
8541 When modifying in place, DEST should point to EXPR_LIST where
8542 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8543 to the start of the whole list and INNER points to the EXPR_LIST
8544 where earlier pieces cover PIECE_BITPOS bits. */
8547 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8548 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8549 HOST_WIDE_INT bitsize, rtx loc_note)
8552 bool copy = inner != NULL;
8556 /* First copy all nodes preceeding the current bitpos. */
8557 while (src != inner)
8559 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8560 decl_piece_bitsize (*src), NULL_RTX);
8561 dest = &XEXP (*dest, 1);
8562 src = &XEXP (*src, 1);
8565 /* Add padding if needed. */
8566 if (bitpos != piece_bitpos)
8568 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8569 copy ? NULL_RTX : *dest);
8570 dest = &XEXP (*dest, 1);
8572 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8575 /* A piece with correct bitpos and bitsize already exist,
8576 just update the location for it and return. */
8577 *decl_piece_varloc_ptr (*dest) = loc_note;
8580 /* Add the piece that changed. */
8581 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8582 dest = &XEXP (*dest, 1);
8583 /* Skip over pieces that overlap it. */
8584 diff = bitpos - piece_bitpos + bitsize;
8587 while (diff > 0 && *src)
8590 diff -= decl_piece_bitsize (piece);
8592 src = &XEXP (piece, 1);
8595 *src = XEXP (piece, 1);
8596 free_EXPR_LIST_node (piece);
8599 /* Add padding if needed. */
8600 if (diff < 0 && *src)
8604 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8605 dest = &XEXP (*dest, 1);
8609 /* Finally copy all nodes following it. */
8612 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8613 decl_piece_bitsize (*src), NULL_RTX);
8614 dest = &XEXP (*dest, 1);
8615 src = &XEXP (*src, 1);
8619 /* Add a variable location node to the linked list for DECL. */
8621 static struct var_loc_node *
8622 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8624 unsigned int decl_id;
8627 struct var_loc_node *loc = NULL;
8628 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8630 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8632 tree realdecl = DECL_DEBUG_EXPR (decl);
8633 if (realdecl && handled_component_p (realdecl))
8635 HOST_WIDE_INT maxsize;
8638 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8639 if (!DECL_P (innerdecl)
8640 || DECL_IGNORED_P (innerdecl)
8641 || TREE_STATIC (innerdecl)
8643 || bitpos + bitsize > 256
8644 || bitsize != maxsize)
8650 decl_id = DECL_UID (decl);
8651 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8654 temp = ggc_alloc_cleared_var_loc_list ();
8655 temp->decl_id = decl_id;
8659 temp = (var_loc_list *) *slot;
8661 /* For PARM_DECLs try to keep around the original incoming value,
8662 even if that means we'll emit a zero-range .debug_loc entry. */
8664 && temp->first == temp->last
8665 && TREE_CODE (decl) == PARM_DECL
8666 && GET_CODE (temp->first->loc) == NOTE
8667 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
8668 && DECL_INCOMING_RTL (decl)
8669 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
8670 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
8671 == GET_CODE (DECL_INCOMING_RTL (decl))
8672 && prev_real_insn (temp->first->loc) == NULL_RTX
8674 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
8675 NOTE_VAR_LOCATION_LOC (loc_note))
8676 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
8677 != NOTE_VAR_LOCATION_STATUS (loc_note))))
8679 loc = ggc_alloc_cleared_var_loc_node ();
8680 temp->first->next = loc;
8682 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8684 else if (temp->last)
8686 struct var_loc_node *last = temp->last, *unused = NULL;
8687 rtx *piece_loc = NULL, last_loc_note;
8688 int piece_bitpos = 0;
8692 gcc_assert (last->next == NULL);
8694 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8696 piece_loc = &last->loc;
8699 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8700 if (piece_bitpos + cur_bitsize > bitpos)
8702 piece_bitpos += cur_bitsize;
8703 piece_loc = &XEXP (*piece_loc, 1);
8707 /* TEMP->LAST here is either pointer to the last but one or
8708 last element in the chained list, LAST is pointer to the
8710 if (label && strcmp (last->label, label) == 0)
8712 /* For SRA optimized variables if there weren't any real
8713 insns since last note, just modify the last node. */
8714 if (piece_loc != NULL)
8716 adjust_piece_list (piece_loc, NULL, NULL,
8717 bitpos, piece_bitpos, bitsize, loc_note);
8720 /* If the last note doesn't cover any instructions, remove it. */
8721 if (temp->last != last)
8723 temp->last->next = NULL;
8726 gcc_assert (strcmp (last->label, label) != 0);
8730 gcc_assert (temp->first == temp->last
8731 || (temp->first->next == temp->last
8732 && TREE_CODE (decl) == PARM_DECL));
8733 memset (temp->last, '\0', sizeof (*temp->last));
8734 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8738 if (bitsize == -1 && NOTE_P (last->loc))
8739 last_loc_note = last->loc;
8740 else if (piece_loc != NULL
8741 && *piece_loc != NULL_RTX
8742 && piece_bitpos == bitpos
8743 && decl_piece_bitsize (*piece_loc) == bitsize)
8744 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8746 last_loc_note = NULL_RTX;
8747 /* If the current location is the same as the end of the list,
8748 and either both or neither of the locations is uninitialized,
8749 we have nothing to do. */
8750 if (last_loc_note == NULL_RTX
8751 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8752 NOTE_VAR_LOCATION_LOC (loc_note)))
8753 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8754 != NOTE_VAR_LOCATION_STATUS (loc_note))
8755 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8756 == VAR_INIT_STATUS_UNINITIALIZED)
8757 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8758 == VAR_INIT_STATUS_UNINITIALIZED))))
8760 /* Add LOC to the end of list and update LAST. If the last
8761 element of the list has been removed above, reuse its
8762 memory for the new node, otherwise allocate a new one. */
8766 memset (loc, '\0', sizeof (*loc));
8769 loc = ggc_alloc_cleared_var_loc_node ();
8770 if (bitsize == -1 || piece_loc == NULL)
8771 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8773 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8774 bitpos, piece_bitpos, bitsize, loc_note);
8776 /* Ensure TEMP->LAST will point either to the new last but one
8777 element of the chain, or to the last element in it. */
8778 if (last != temp->last)
8786 loc = ggc_alloc_cleared_var_loc_node ();
8789 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8794 /* Keep track of the number of spaces used to indent the
8795 output of the debugging routines that print the structure of
8796 the DIE internal representation. */
8797 static int print_indent;
8799 /* Indent the line the number of spaces given by print_indent. */
8802 print_spaces (FILE *outfile)
8804 fprintf (outfile, "%*s", print_indent, "");
8807 /* Print a type signature in hex. */
8810 print_signature (FILE *outfile, char *sig)
8814 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8815 fprintf (outfile, "%02x", sig[i] & 0xff);
8818 /* Print the information associated with a given DIE, and its children.
8819 This routine is a debugging aid only. */
8822 print_die (dw_die_ref die, FILE *outfile)
8828 print_spaces (outfile);
8829 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8830 die->die_offset, dwarf_tag_name (die->die_tag),
8832 print_spaces (outfile);
8833 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8834 fprintf (outfile, " offset: %ld", die->die_offset);
8835 fprintf (outfile, " mark: %d\n", die->die_mark);
8837 if (use_debug_types && die->die_id.die_type_node)
8839 print_spaces (outfile);
8840 fprintf (outfile, " signature: ");
8841 print_signature (outfile, die->die_id.die_type_node->signature);
8842 fprintf (outfile, "\n");
8845 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8847 print_spaces (outfile);
8848 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8850 switch (AT_class (a))
8852 case dw_val_class_addr:
8853 fprintf (outfile, "address");
8855 case dw_val_class_offset:
8856 fprintf (outfile, "offset");
8858 case dw_val_class_loc:
8859 fprintf (outfile, "location descriptor");
8861 case dw_val_class_loc_list:
8862 fprintf (outfile, "location list -> label:%s",
8863 AT_loc_list (a)->ll_symbol);
8865 case dw_val_class_range_list:
8866 fprintf (outfile, "range list");
8868 case dw_val_class_const:
8869 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8871 case dw_val_class_unsigned_const:
8872 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8874 case dw_val_class_const_double:
8875 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8876 HOST_WIDE_INT_PRINT_UNSIGNED")",
8877 a->dw_attr_val.v.val_double.high,
8878 a->dw_attr_val.v.val_double.low);
8880 case dw_val_class_vec:
8881 fprintf (outfile, "floating-point or vector constant");
8883 case dw_val_class_flag:
8884 fprintf (outfile, "%u", AT_flag (a));
8886 case dw_val_class_die_ref:
8887 if (AT_ref (a) != NULL)
8889 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
8891 fprintf (outfile, "die -> signature: ");
8892 print_signature (outfile,
8893 AT_ref (a)->die_id.die_type_node->signature);
8895 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
8896 fprintf (outfile, "die -> label: %s",
8897 AT_ref (a)->die_id.die_symbol);
8899 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8900 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8903 fprintf (outfile, "die -> <null>");
8905 case dw_val_class_vms_delta:
8906 fprintf (outfile, "delta: @slotcount(%s-%s)",
8907 AT_vms_delta2 (a), AT_vms_delta1 (a));
8909 case dw_val_class_lbl_id:
8910 case dw_val_class_lineptr:
8911 case dw_val_class_macptr:
8912 fprintf (outfile, "label: %s", AT_lbl (a));
8914 case dw_val_class_str:
8915 if (AT_string (a) != NULL)
8916 fprintf (outfile, "\"%s\"", AT_string (a));
8918 fprintf (outfile, "<null>");
8920 case dw_val_class_file:
8921 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8922 AT_file (a)->emitted_number);
8924 case dw_val_class_data8:
8928 for (i = 0; i < 8; i++)
8929 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8936 fprintf (outfile, "\n");
8939 if (die->die_child != NULL)
8942 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8945 if (print_indent == 0)
8946 fprintf (outfile, "\n");
8949 /* Print the information collected for a given DIE. */
8952 debug_dwarf_die (dw_die_ref die)
8954 print_die (die, stderr);
8957 /* Print all DWARF information collected for the compilation unit.
8958 This routine is a debugging aid only. */
8964 print_die (comp_unit_die (), stderr);
8967 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8968 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8969 DIE that marks the start of the DIEs for this include file. */
8972 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8974 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8975 dw_die_ref new_unit = gen_compile_unit_die (filename);
8977 new_unit->die_sib = old_unit;
8981 /* Close an include-file CU and reopen the enclosing one. */
8984 pop_compile_unit (dw_die_ref old_unit)
8986 dw_die_ref new_unit = old_unit->die_sib;
8988 old_unit->die_sib = NULL;
8992 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8993 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8995 /* Calculate the checksum of a location expression. */
8998 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
9002 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
9004 CHECKSUM (loc->dw_loc_oprnd1);
9005 CHECKSUM (loc->dw_loc_oprnd2);
9008 /* Calculate the checksum of an attribute. */
9011 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
9013 dw_loc_descr_ref loc;
9016 CHECKSUM (at->dw_attr);
9018 /* We don't care that this was compiled with a different compiler
9019 snapshot; if the output is the same, that's what matters. */
9020 if (at->dw_attr == DW_AT_producer)
9023 switch (AT_class (at))
9025 case dw_val_class_const:
9026 CHECKSUM (at->dw_attr_val.v.val_int);
9028 case dw_val_class_unsigned_const:
9029 CHECKSUM (at->dw_attr_val.v.val_unsigned);
9031 case dw_val_class_const_double:
9032 CHECKSUM (at->dw_attr_val.v.val_double);
9034 case dw_val_class_vec:
9035 CHECKSUM (at->dw_attr_val.v.val_vec);
9037 case dw_val_class_flag:
9038 CHECKSUM (at->dw_attr_val.v.val_flag);
9040 case dw_val_class_str:
9041 CHECKSUM_STRING (AT_string (at));
9044 case dw_val_class_addr:
9046 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9047 CHECKSUM_STRING (XSTR (r, 0));
9050 case dw_val_class_offset:
9051 CHECKSUM (at->dw_attr_val.v.val_offset);
9054 case dw_val_class_loc:
9055 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9056 loc_checksum (loc, ctx);
9059 case dw_val_class_die_ref:
9060 die_checksum (AT_ref (at), ctx, mark);
9063 case dw_val_class_fde_ref:
9064 case dw_val_class_vms_delta:
9065 case dw_val_class_lbl_id:
9066 case dw_val_class_lineptr:
9067 case dw_val_class_macptr:
9070 case dw_val_class_file:
9071 CHECKSUM_STRING (AT_file (at)->filename);
9074 case dw_val_class_data8:
9075 CHECKSUM (at->dw_attr_val.v.val_data8);
9083 /* Calculate the checksum of a DIE. */
9086 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9092 /* To avoid infinite recursion. */
9095 CHECKSUM (die->die_mark);
9098 die->die_mark = ++(*mark);
9100 CHECKSUM (die->die_tag);
9102 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9103 attr_checksum (a, ctx, mark);
9105 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
9109 #undef CHECKSUM_STRING
9111 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
9112 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
9113 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
9114 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
9115 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
9116 #define CHECKSUM_ATTR(FOO) \
9117 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
9119 /* Calculate the checksum of a number in signed LEB128 format. */
9122 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
9129 byte = (value & 0x7f);
9131 more = !((value == 0 && (byte & 0x40) == 0)
9132 || (value == -1 && (byte & 0x40) != 0));
9141 /* Calculate the checksum of a number in unsigned LEB128 format. */
9144 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
9148 unsigned char byte = (value & 0x7f);
9151 /* More bytes to follow. */
9159 /* Checksum the context of the DIE. This adds the names of any
9160 surrounding namespaces or structures to the checksum. */
9163 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
9167 int tag = die->die_tag;
9169 if (tag != DW_TAG_namespace
9170 && tag != DW_TAG_structure_type
9171 && tag != DW_TAG_class_type)
9174 name = get_AT_string (die, DW_AT_name);
9176 spec = get_AT_ref (die, DW_AT_specification);
9180 if (die->die_parent != NULL)
9181 checksum_die_context (die->die_parent, ctx);
9183 CHECKSUM_ULEB128 ('C');
9184 CHECKSUM_ULEB128 (tag);
9186 CHECKSUM_STRING (name);
9189 /* Calculate the checksum of a location expression. */
9192 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
9194 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
9195 were emitted as a DW_FORM_sdata instead of a location expression. */
9196 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
9198 CHECKSUM_ULEB128 (DW_FORM_sdata);
9199 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
9203 /* Otherwise, just checksum the raw location expression. */
9206 CHECKSUM_ULEB128 (loc->dw_loc_opc);
9207 CHECKSUM (loc->dw_loc_oprnd1);
9208 CHECKSUM (loc->dw_loc_oprnd2);
9209 loc = loc->dw_loc_next;
9213 /* Calculate the checksum of an attribute. */
9216 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
9217 struct md5_ctx *ctx, int *mark)
9219 dw_loc_descr_ref loc;
9222 if (AT_class (at) == dw_val_class_die_ref)
9224 dw_die_ref target_die = AT_ref (at);
9226 /* For pointer and reference types, we checksum only the (qualified)
9227 name of the target type (if there is a name). For friend entries,
9228 we checksum only the (qualified) name of the target type or function.
9229 This allows the checksum to remain the same whether the target type
9230 is complete or not. */
9231 if ((at->dw_attr == DW_AT_type
9232 && (tag == DW_TAG_pointer_type
9233 || tag == DW_TAG_reference_type
9234 || tag == DW_TAG_rvalue_reference_type
9235 || tag == DW_TAG_ptr_to_member_type))
9236 || (at->dw_attr == DW_AT_friend
9237 && tag == DW_TAG_friend))
9239 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
9241 if (name_attr != NULL)
9243 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9247 CHECKSUM_ULEB128 ('N');
9248 CHECKSUM_ULEB128 (at->dw_attr);
9249 if (decl->die_parent != NULL)
9250 checksum_die_context (decl->die_parent, ctx);
9251 CHECKSUM_ULEB128 ('E');
9252 CHECKSUM_STRING (AT_string (name_attr));
9257 /* For all other references to another DIE, we check to see if the
9258 target DIE has already been visited. If it has, we emit a
9259 backward reference; if not, we descend recursively. */
9260 if (target_die->die_mark > 0)
9262 CHECKSUM_ULEB128 ('R');
9263 CHECKSUM_ULEB128 (at->dw_attr);
9264 CHECKSUM_ULEB128 (target_die->die_mark);
9268 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9272 target_die->die_mark = ++(*mark);
9273 CHECKSUM_ULEB128 ('T');
9274 CHECKSUM_ULEB128 (at->dw_attr);
9275 if (decl->die_parent != NULL)
9276 checksum_die_context (decl->die_parent, ctx);
9277 die_checksum_ordered (target_die, ctx, mark);
9282 CHECKSUM_ULEB128 ('A');
9283 CHECKSUM_ULEB128 (at->dw_attr);
9285 switch (AT_class (at))
9287 case dw_val_class_const:
9288 CHECKSUM_ULEB128 (DW_FORM_sdata);
9289 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9292 case dw_val_class_unsigned_const:
9293 CHECKSUM_ULEB128 (DW_FORM_sdata);
9294 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9297 case dw_val_class_const_double:
9298 CHECKSUM_ULEB128 (DW_FORM_block);
9299 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9300 CHECKSUM (at->dw_attr_val.v.val_double);
9303 case dw_val_class_vec:
9304 CHECKSUM_ULEB128 (DW_FORM_block);
9305 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9306 CHECKSUM (at->dw_attr_val.v.val_vec);
9309 case dw_val_class_flag:
9310 CHECKSUM_ULEB128 (DW_FORM_flag);
9311 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9314 case dw_val_class_str:
9315 CHECKSUM_ULEB128 (DW_FORM_string);
9316 CHECKSUM_STRING (AT_string (at));
9319 case dw_val_class_addr:
9321 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9322 CHECKSUM_ULEB128 (DW_FORM_string);
9323 CHECKSUM_STRING (XSTR (r, 0));
9326 case dw_val_class_offset:
9327 CHECKSUM_ULEB128 (DW_FORM_sdata);
9328 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9331 case dw_val_class_loc:
9332 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9333 loc_checksum_ordered (loc, ctx);
9336 case dw_val_class_fde_ref:
9337 case dw_val_class_lbl_id:
9338 case dw_val_class_lineptr:
9339 case dw_val_class_macptr:
9342 case dw_val_class_file:
9343 CHECKSUM_ULEB128 (DW_FORM_string);
9344 CHECKSUM_STRING (AT_file (at)->filename);
9347 case dw_val_class_data8:
9348 CHECKSUM (at->dw_attr_val.v.val_data8);
9356 struct checksum_attributes
9358 dw_attr_ref at_name;
9359 dw_attr_ref at_type;
9360 dw_attr_ref at_friend;
9361 dw_attr_ref at_accessibility;
9362 dw_attr_ref at_address_class;
9363 dw_attr_ref at_allocated;
9364 dw_attr_ref at_artificial;
9365 dw_attr_ref at_associated;
9366 dw_attr_ref at_binary_scale;
9367 dw_attr_ref at_bit_offset;
9368 dw_attr_ref at_bit_size;
9369 dw_attr_ref at_bit_stride;
9370 dw_attr_ref at_byte_size;
9371 dw_attr_ref at_byte_stride;
9372 dw_attr_ref at_const_value;
9373 dw_attr_ref at_containing_type;
9374 dw_attr_ref at_count;
9375 dw_attr_ref at_data_location;
9376 dw_attr_ref at_data_member_location;
9377 dw_attr_ref at_decimal_scale;
9378 dw_attr_ref at_decimal_sign;
9379 dw_attr_ref at_default_value;
9380 dw_attr_ref at_digit_count;
9381 dw_attr_ref at_discr;
9382 dw_attr_ref at_discr_list;
9383 dw_attr_ref at_discr_value;
9384 dw_attr_ref at_encoding;
9385 dw_attr_ref at_endianity;
9386 dw_attr_ref at_explicit;
9387 dw_attr_ref at_is_optional;
9388 dw_attr_ref at_location;
9389 dw_attr_ref at_lower_bound;
9390 dw_attr_ref at_mutable;
9391 dw_attr_ref at_ordering;
9392 dw_attr_ref at_picture_string;
9393 dw_attr_ref at_prototyped;
9394 dw_attr_ref at_small;
9395 dw_attr_ref at_segment;
9396 dw_attr_ref at_string_length;
9397 dw_attr_ref at_threads_scaled;
9398 dw_attr_ref at_upper_bound;
9399 dw_attr_ref at_use_location;
9400 dw_attr_ref at_use_UTF8;
9401 dw_attr_ref at_variable_parameter;
9402 dw_attr_ref at_virtuality;
9403 dw_attr_ref at_visibility;
9404 dw_attr_ref at_vtable_elem_location;
9407 /* Collect the attributes that we will want to use for the checksum. */
9410 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9415 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9426 attrs->at_friend = a;
9428 case DW_AT_accessibility:
9429 attrs->at_accessibility = a;
9431 case DW_AT_address_class:
9432 attrs->at_address_class = a;
9434 case DW_AT_allocated:
9435 attrs->at_allocated = a;
9437 case DW_AT_artificial:
9438 attrs->at_artificial = a;
9440 case DW_AT_associated:
9441 attrs->at_associated = a;
9443 case DW_AT_binary_scale:
9444 attrs->at_binary_scale = a;
9446 case DW_AT_bit_offset:
9447 attrs->at_bit_offset = a;
9449 case DW_AT_bit_size:
9450 attrs->at_bit_size = a;
9452 case DW_AT_bit_stride:
9453 attrs->at_bit_stride = a;
9455 case DW_AT_byte_size:
9456 attrs->at_byte_size = a;
9458 case DW_AT_byte_stride:
9459 attrs->at_byte_stride = a;
9461 case DW_AT_const_value:
9462 attrs->at_const_value = a;
9464 case DW_AT_containing_type:
9465 attrs->at_containing_type = a;
9468 attrs->at_count = a;
9470 case DW_AT_data_location:
9471 attrs->at_data_location = a;
9473 case DW_AT_data_member_location:
9474 attrs->at_data_member_location = a;
9476 case DW_AT_decimal_scale:
9477 attrs->at_decimal_scale = a;
9479 case DW_AT_decimal_sign:
9480 attrs->at_decimal_sign = a;
9482 case DW_AT_default_value:
9483 attrs->at_default_value = a;
9485 case DW_AT_digit_count:
9486 attrs->at_digit_count = a;
9489 attrs->at_discr = a;
9491 case DW_AT_discr_list:
9492 attrs->at_discr_list = a;
9494 case DW_AT_discr_value:
9495 attrs->at_discr_value = a;
9497 case DW_AT_encoding:
9498 attrs->at_encoding = a;
9500 case DW_AT_endianity:
9501 attrs->at_endianity = a;
9503 case DW_AT_explicit:
9504 attrs->at_explicit = a;
9506 case DW_AT_is_optional:
9507 attrs->at_is_optional = a;
9509 case DW_AT_location:
9510 attrs->at_location = a;
9512 case DW_AT_lower_bound:
9513 attrs->at_lower_bound = a;
9516 attrs->at_mutable = a;
9518 case DW_AT_ordering:
9519 attrs->at_ordering = a;
9521 case DW_AT_picture_string:
9522 attrs->at_picture_string = a;
9524 case DW_AT_prototyped:
9525 attrs->at_prototyped = a;
9528 attrs->at_small = a;
9531 attrs->at_segment = a;
9533 case DW_AT_string_length:
9534 attrs->at_string_length = a;
9536 case DW_AT_threads_scaled:
9537 attrs->at_threads_scaled = a;
9539 case DW_AT_upper_bound:
9540 attrs->at_upper_bound = a;
9542 case DW_AT_use_location:
9543 attrs->at_use_location = a;
9545 case DW_AT_use_UTF8:
9546 attrs->at_use_UTF8 = a;
9548 case DW_AT_variable_parameter:
9549 attrs->at_variable_parameter = a;
9551 case DW_AT_virtuality:
9552 attrs->at_virtuality = a;
9554 case DW_AT_visibility:
9555 attrs->at_visibility = a;
9557 case DW_AT_vtable_elem_location:
9558 attrs->at_vtable_elem_location = a;
9566 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9569 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9573 struct checksum_attributes attrs;
9575 CHECKSUM_ULEB128 ('D');
9576 CHECKSUM_ULEB128 (die->die_tag);
9578 memset (&attrs, 0, sizeof (attrs));
9580 decl = get_AT_ref (die, DW_AT_specification);
9582 collect_checksum_attributes (&attrs, decl);
9583 collect_checksum_attributes (&attrs, die);
9585 CHECKSUM_ATTR (attrs.at_name);
9586 CHECKSUM_ATTR (attrs.at_accessibility);
9587 CHECKSUM_ATTR (attrs.at_address_class);
9588 CHECKSUM_ATTR (attrs.at_allocated);
9589 CHECKSUM_ATTR (attrs.at_artificial);
9590 CHECKSUM_ATTR (attrs.at_associated);
9591 CHECKSUM_ATTR (attrs.at_binary_scale);
9592 CHECKSUM_ATTR (attrs.at_bit_offset);
9593 CHECKSUM_ATTR (attrs.at_bit_size);
9594 CHECKSUM_ATTR (attrs.at_bit_stride);
9595 CHECKSUM_ATTR (attrs.at_byte_size);
9596 CHECKSUM_ATTR (attrs.at_byte_stride);
9597 CHECKSUM_ATTR (attrs.at_const_value);
9598 CHECKSUM_ATTR (attrs.at_containing_type);
9599 CHECKSUM_ATTR (attrs.at_count);
9600 CHECKSUM_ATTR (attrs.at_data_location);
9601 CHECKSUM_ATTR (attrs.at_data_member_location);
9602 CHECKSUM_ATTR (attrs.at_decimal_scale);
9603 CHECKSUM_ATTR (attrs.at_decimal_sign);
9604 CHECKSUM_ATTR (attrs.at_default_value);
9605 CHECKSUM_ATTR (attrs.at_digit_count);
9606 CHECKSUM_ATTR (attrs.at_discr);
9607 CHECKSUM_ATTR (attrs.at_discr_list);
9608 CHECKSUM_ATTR (attrs.at_discr_value);
9609 CHECKSUM_ATTR (attrs.at_encoding);
9610 CHECKSUM_ATTR (attrs.at_endianity);
9611 CHECKSUM_ATTR (attrs.at_explicit);
9612 CHECKSUM_ATTR (attrs.at_is_optional);
9613 CHECKSUM_ATTR (attrs.at_location);
9614 CHECKSUM_ATTR (attrs.at_lower_bound);
9615 CHECKSUM_ATTR (attrs.at_mutable);
9616 CHECKSUM_ATTR (attrs.at_ordering);
9617 CHECKSUM_ATTR (attrs.at_picture_string);
9618 CHECKSUM_ATTR (attrs.at_prototyped);
9619 CHECKSUM_ATTR (attrs.at_small);
9620 CHECKSUM_ATTR (attrs.at_segment);
9621 CHECKSUM_ATTR (attrs.at_string_length);
9622 CHECKSUM_ATTR (attrs.at_threads_scaled);
9623 CHECKSUM_ATTR (attrs.at_upper_bound);
9624 CHECKSUM_ATTR (attrs.at_use_location);
9625 CHECKSUM_ATTR (attrs.at_use_UTF8);
9626 CHECKSUM_ATTR (attrs.at_variable_parameter);
9627 CHECKSUM_ATTR (attrs.at_virtuality);
9628 CHECKSUM_ATTR (attrs.at_visibility);
9629 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9630 CHECKSUM_ATTR (attrs.at_type);
9631 CHECKSUM_ATTR (attrs.at_friend);
9633 /* Checksum the child DIEs, except for nested types and member functions. */
9636 dw_attr_ref name_attr;
9639 name_attr = get_AT (c, DW_AT_name);
9640 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9641 && name_attr != NULL)
9643 CHECKSUM_ULEB128 ('S');
9644 CHECKSUM_ULEB128 (c->die_tag);
9645 CHECKSUM_STRING (AT_string (name_attr));
9649 /* Mark this DIE so it gets processed when unmarking. */
9650 if (c->die_mark == 0)
9652 die_checksum_ordered (c, ctx, mark);
9654 } while (c != die->die_child);
9656 CHECKSUM_ULEB128 (0);
9660 #undef CHECKSUM_STRING
9661 #undef CHECKSUM_ATTR
9662 #undef CHECKSUM_LEB128
9663 #undef CHECKSUM_ULEB128
9665 /* Generate the type signature for DIE. This is computed by generating an
9666 MD5 checksum over the DIE's tag, its relevant attributes, and its
9667 children. Attributes that are references to other DIEs are processed
9668 by recursion, using the MARK field to prevent infinite recursion.
9669 If the DIE is nested inside a namespace or another type, we also
9670 need to include that context in the signature. The lower 64 bits
9671 of the resulting MD5 checksum comprise the signature. */
9674 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9678 unsigned char checksum[16];
9682 name = get_AT_string (die, DW_AT_name);
9683 decl = get_AT_ref (die, DW_AT_specification);
9685 /* First, compute a signature for just the type name (and its surrounding
9686 context, if any. This is stored in the type unit DIE for link-time
9687 ODR (one-definition rule) checking. */
9689 if (is_cxx() && name != NULL)
9691 md5_init_ctx (&ctx);
9693 /* Checksum the names of surrounding namespaces and structures. */
9694 if (decl != NULL && decl->die_parent != NULL)
9695 checksum_die_context (decl->die_parent, &ctx);
9697 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9698 md5_process_bytes (name, strlen (name) + 1, &ctx);
9699 md5_finish_ctx (&ctx, checksum);
9701 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9704 /* Next, compute the complete type signature. */
9706 md5_init_ctx (&ctx);
9708 die->die_mark = mark;
9710 /* Checksum the names of surrounding namespaces and structures. */
9711 if (decl != NULL && decl->die_parent != NULL)
9712 checksum_die_context (decl->die_parent, &ctx);
9714 /* Checksum the DIE and its children. */
9715 die_checksum_ordered (die, &ctx, &mark);
9716 unmark_all_dies (die);
9717 md5_finish_ctx (&ctx, checksum);
9719 /* Store the signature in the type node and link the type DIE and the
9720 type node together. */
9721 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9722 DWARF_TYPE_SIGNATURE_SIZE);
9723 die->die_id.die_type_node = type_node;
9724 type_node->type_die = die;
9726 /* If the DIE is a specification, link its declaration to the type node
9729 decl->die_id.die_type_node = type_node;
9732 /* Do the location expressions look same? */
9734 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9736 return loc1->dw_loc_opc == loc2->dw_loc_opc
9737 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9738 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9741 /* Do the values look the same? */
9743 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9745 dw_loc_descr_ref loc1, loc2;
9748 if (v1->val_class != v2->val_class)
9751 switch (v1->val_class)
9753 case dw_val_class_const:
9754 return v1->v.val_int == v2->v.val_int;
9755 case dw_val_class_unsigned_const:
9756 return v1->v.val_unsigned == v2->v.val_unsigned;
9757 case dw_val_class_const_double:
9758 return v1->v.val_double.high == v2->v.val_double.high
9759 && v1->v.val_double.low == v2->v.val_double.low;
9760 case dw_val_class_vec:
9761 if (v1->v.val_vec.length != v2->v.val_vec.length
9762 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9764 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9765 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9768 case dw_val_class_flag:
9769 return v1->v.val_flag == v2->v.val_flag;
9770 case dw_val_class_str:
9771 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9773 case dw_val_class_addr:
9774 r1 = v1->v.val_addr;
9775 r2 = v2->v.val_addr;
9776 if (GET_CODE (r1) != GET_CODE (r2))
9778 return !rtx_equal_p (r1, r2);
9780 case dw_val_class_offset:
9781 return v1->v.val_offset == v2->v.val_offset;
9783 case dw_val_class_loc:
9784 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9786 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9787 if (!same_loc_p (loc1, loc2, mark))
9789 return !loc1 && !loc2;
9791 case dw_val_class_die_ref:
9792 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9794 case dw_val_class_fde_ref:
9795 case dw_val_class_vms_delta:
9796 case dw_val_class_lbl_id:
9797 case dw_val_class_lineptr:
9798 case dw_val_class_macptr:
9801 case dw_val_class_file:
9802 return v1->v.val_file == v2->v.val_file;
9804 case dw_val_class_data8:
9805 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9812 /* Do the attributes look the same? */
9815 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9817 if (at1->dw_attr != at2->dw_attr)
9820 /* We don't care that this was compiled with a different compiler
9821 snapshot; if the output is the same, that's what matters. */
9822 if (at1->dw_attr == DW_AT_producer)
9825 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9828 /* Do the dies look the same? */
9831 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9837 /* To avoid infinite recursion. */
9839 return die1->die_mark == die2->die_mark;
9840 die1->die_mark = die2->die_mark = ++(*mark);
9842 if (die1->die_tag != die2->die_tag)
9845 if (VEC_length (dw_attr_node, die1->die_attr)
9846 != VEC_length (dw_attr_node, die2->die_attr))
9849 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9850 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9853 c1 = die1->die_child;
9854 c2 = die2->die_child;
9863 if (!same_die_p (c1, c2, mark))
9867 if (c1 == die1->die_child)
9869 if (c2 == die2->die_child)
9879 /* Do the dies look the same? Wrapper around same_die_p. */
9882 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9885 int ret = same_die_p (die1, die2, &mark);
9887 unmark_all_dies (die1);
9888 unmark_all_dies (die2);
9893 /* The prefix to attach to symbols on DIEs in the current comdat debug
9895 static char *comdat_symbol_id;
9897 /* The index of the current symbol within the current comdat CU. */
9898 static unsigned int comdat_symbol_number;
9900 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9901 children, and set comdat_symbol_id accordingly. */
9904 compute_section_prefix (dw_die_ref unit_die)
9906 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9907 const char *base = die_name ? lbasename (die_name) : "anonymous";
9908 char *name = XALLOCAVEC (char, strlen (base) + 64);
9911 unsigned char checksum[16];
9914 /* Compute the checksum of the DIE, then append part of it as hex digits to
9915 the name filename of the unit. */
9917 md5_init_ctx (&ctx);
9919 die_checksum (unit_die, &ctx, &mark);
9920 unmark_all_dies (unit_die);
9921 md5_finish_ctx (&ctx, checksum);
9923 sprintf (name, "%s.", base);
9924 clean_symbol_name (name);
9926 p = name + strlen (name);
9927 for (i = 0; i < 4; i++)
9929 sprintf (p, "%.2x", checksum[i]);
9933 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9934 comdat_symbol_number = 0;
9937 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9940 is_type_die (dw_die_ref die)
9942 switch (die->die_tag)
9944 case DW_TAG_array_type:
9945 case DW_TAG_class_type:
9946 case DW_TAG_interface_type:
9947 case DW_TAG_enumeration_type:
9948 case DW_TAG_pointer_type:
9949 case DW_TAG_reference_type:
9950 case DW_TAG_rvalue_reference_type:
9951 case DW_TAG_string_type:
9952 case DW_TAG_structure_type:
9953 case DW_TAG_subroutine_type:
9954 case DW_TAG_union_type:
9955 case DW_TAG_ptr_to_member_type:
9956 case DW_TAG_set_type:
9957 case DW_TAG_subrange_type:
9958 case DW_TAG_base_type:
9959 case DW_TAG_const_type:
9960 case DW_TAG_file_type:
9961 case DW_TAG_packed_type:
9962 case DW_TAG_volatile_type:
9963 case DW_TAG_typedef:
9970 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9971 Basically, we want to choose the bits that are likely to be shared between
9972 compilations (types) and leave out the bits that are specific to individual
9973 compilations (functions). */
9976 is_comdat_die (dw_die_ref c)
9978 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9979 we do for stabs. The advantage is a greater likelihood of sharing between
9980 objects that don't include headers in the same order (and therefore would
9981 put the base types in a different comdat). jason 8/28/00 */
9983 if (c->die_tag == DW_TAG_base_type)
9986 if (c->die_tag == DW_TAG_pointer_type
9987 || c->die_tag == DW_TAG_reference_type
9988 || c->die_tag == DW_TAG_rvalue_reference_type
9989 || c->die_tag == DW_TAG_const_type
9990 || c->die_tag == DW_TAG_volatile_type)
9992 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9994 return t ? is_comdat_die (t) : 0;
9997 return is_type_die (c);
10000 /* Returns 1 iff C is the sort of DIE that might be referred to from another
10001 compilation unit. */
10004 is_symbol_die (dw_die_ref c)
10006 return (is_type_die (c)
10007 || is_declaration_die (c)
10008 || c->die_tag == DW_TAG_namespace
10009 || c->die_tag == DW_TAG_module);
10012 /* Returns true iff C is a compile-unit DIE. */
10015 is_cu_die (dw_die_ref c)
10017 return c && c->die_tag == DW_TAG_compile_unit;
10021 gen_internal_sym (const char *prefix)
10025 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
10026 return xstrdup (buf);
10029 /* Assign symbols to all worthy DIEs under DIE. */
10032 assign_symbol_names (dw_die_ref die)
10036 if (is_symbol_die (die))
10038 if (comdat_symbol_id)
10040 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
10042 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
10043 comdat_symbol_id, comdat_symbol_number++);
10044 die->die_id.die_symbol = xstrdup (p);
10047 die->die_id.die_symbol = gen_internal_sym ("LDIE");
10050 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
10053 struct cu_hash_table_entry
10056 unsigned min_comdat_num, max_comdat_num;
10057 struct cu_hash_table_entry *next;
10060 /* Routines to manipulate hash table of CUs. */
10062 htab_cu_hash (const void *of)
10064 const struct cu_hash_table_entry *const entry =
10065 (const struct cu_hash_table_entry *) of;
10067 return htab_hash_string (entry->cu->die_id.die_symbol);
10071 htab_cu_eq (const void *of1, const void *of2)
10073 const struct cu_hash_table_entry *const entry1 =
10074 (const struct cu_hash_table_entry *) of1;
10075 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10077 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
10081 htab_cu_del (void *what)
10083 struct cu_hash_table_entry *next,
10084 *entry = (struct cu_hash_table_entry *) what;
10088 next = entry->next;
10094 /* Check whether we have already seen this CU and set up SYM_NUM
10097 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
10099 struct cu_hash_table_entry dummy;
10100 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
10102 dummy.max_comdat_num = 0;
10104 slot = (struct cu_hash_table_entry **)
10105 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
10109 for (; entry; last = entry, entry = entry->next)
10111 if (same_die_p_wrap (cu, entry->cu))
10117 *sym_num = entry->min_comdat_num;
10121 entry = XCNEW (struct cu_hash_table_entry);
10123 entry->min_comdat_num = *sym_num = last->max_comdat_num;
10124 entry->next = *slot;
10130 /* Record SYM_NUM to record of CU in HTABLE. */
10132 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
10134 struct cu_hash_table_entry **slot, *entry;
10136 slot = (struct cu_hash_table_entry **)
10137 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
10141 entry->max_comdat_num = sym_num;
10144 /* Traverse the DIE (which is always comp_unit_die), and set up
10145 additional compilation units for each of the include files we see
10146 bracketed by BINCL/EINCL. */
10149 break_out_includes (dw_die_ref die)
10152 dw_die_ref unit = NULL;
10153 limbo_die_node *node, **pnode;
10154 htab_t cu_hash_table;
10156 c = die->die_child;
10158 dw_die_ref prev = c;
10160 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
10161 || (unit && is_comdat_die (c)))
10163 dw_die_ref next = c->die_sib;
10165 /* This DIE is for a secondary CU; remove it from the main one. */
10166 remove_child_with_prev (c, prev);
10168 if (c->die_tag == DW_TAG_GNU_BINCL)
10169 unit = push_new_compile_unit (unit, c);
10170 else if (c->die_tag == DW_TAG_GNU_EINCL)
10171 unit = pop_compile_unit (unit);
10173 add_child_die (unit, c);
10175 if (c == die->die_child)
10178 } while (c != die->die_child);
10181 /* We can only use this in debugging, since the frontend doesn't check
10182 to make sure that we leave every include file we enter. */
10183 gcc_assert (!unit);
10186 assign_symbol_names (die);
10187 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
10188 for (node = limbo_die_list, pnode = &limbo_die_list;
10194 compute_section_prefix (node->die);
10195 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
10196 &comdat_symbol_number);
10197 assign_symbol_names (node->die);
10199 *pnode = node->next;
10202 pnode = &node->next;
10203 record_comdat_symbol_number (node->die, cu_hash_table,
10204 comdat_symbol_number);
10207 htab_delete (cu_hash_table);
10210 /* Return non-zero if this DIE is a declaration. */
10213 is_declaration_die (dw_die_ref die)
10218 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10219 if (a->dw_attr == DW_AT_declaration)
10225 /* Return non-zero if this DIE is nested inside a subprogram. */
10228 is_nested_in_subprogram (dw_die_ref die)
10230 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
10234 return local_scope_p (decl);
10237 /* Return non-zero if this DIE contains a defining declaration of a
10241 contains_subprogram_definition (dw_die_ref die)
10245 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
10247 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
10251 /* Return non-zero if this is a type DIE that should be moved to a
10252 COMDAT .debug_types section. */
10255 should_move_die_to_comdat (dw_die_ref die)
10257 switch (die->die_tag)
10259 case DW_TAG_class_type:
10260 case DW_TAG_structure_type:
10261 case DW_TAG_enumeration_type:
10262 case DW_TAG_union_type:
10263 /* Don't move declarations, inlined instances, or types nested in a
10265 if (is_declaration_die (die)
10266 || get_AT (die, DW_AT_abstract_origin)
10267 || is_nested_in_subprogram (die))
10269 /* A type definition should never contain a subprogram definition. */
10270 gcc_assert (!contains_subprogram_definition (die));
10272 case DW_TAG_array_type:
10273 case DW_TAG_interface_type:
10274 case DW_TAG_pointer_type:
10275 case DW_TAG_reference_type:
10276 case DW_TAG_rvalue_reference_type:
10277 case DW_TAG_string_type:
10278 case DW_TAG_subroutine_type:
10279 case DW_TAG_ptr_to_member_type:
10280 case DW_TAG_set_type:
10281 case DW_TAG_subrange_type:
10282 case DW_TAG_base_type:
10283 case DW_TAG_const_type:
10284 case DW_TAG_file_type:
10285 case DW_TAG_packed_type:
10286 case DW_TAG_volatile_type:
10287 case DW_TAG_typedef:
10293 /* Make a clone of DIE. */
10296 clone_die (dw_die_ref die)
10302 clone = ggc_alloc_cleared_die_node ();
10303 clone->die_tag = die->die_tag;
10305 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10306 add_dwarf_attr (clone, a);
10311 /* Make a clone of the tree rooted at DIE. */
10314 clone_tree (dw_die_ref die)
10317 dw_die_ref clone = clone_die (die);
10319 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10324 /* Make a clone of DIE as a declaration. */
10327 clone_as_declaration (dw_die_ref die)
10334 /* If the DIE is already a declaration, just clone it. */
10335 if (is_declaration_die (die))
10336 return clone_die (die);
10338 /* If the DIE is a specification, just clone its declaration DIE. */
10339 decl = get_AT_ref (die, DW_AT_specification);
10341 return clone_die (decl);
10343 clone = ggc_alloc_cleared_die_node ();
10344 clone->die_tag = die->die_tag;
10346 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10348 /* We don't want to copy over all attributes.
10349 For example we don't want DW_AT_byte_size because otherwise we will no
10350 longer have a declaration and GDB will treat it as a definition. */
10352 switch (a->dw_attr)
10354 case DW_AT_artificial:
10355 case DW_AT_containing_type:
10356 case DW_AT_external:
10359 case DW_AT_virtuality:
10360 case DW_AT_linkage_name:
10361 case DW_AT_MIPS_linkage_name:
10362 add_dwarf_attr (clone, a);
10364 case DW_AT_byte_size:
10370 if (die->die_id.die_type_node)
10371 add_AT_die_ref (clone, DW_AT_signature, die);
10373 add_AT_flag (clone, DW_AT_declaration, 1);
10377 /* Copy the declaration context to the new compile unit DIE. This includes
10378 any surrounding namespace or type declarations. If the DIE has an
10379 AT_specification attribute, it also includes attributes and children
10380 attached to the specification. */
10383 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10386 dw_die_ref new_decl;
10388 decl = get_AT_ref (die, DW_AT_specification);
10397 /* Copy the type node pointer from the new DIE to the original
10398 declaration DIE so we can forward references later. */
10399 decl->die_id.die_type_node = die->die_id.die_type_node;
10401 remove_AT (die, DW_AT_specification);
10403 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10405 if (a->dw_attr != DW_AT_name
10406 && a->dw_attr != DW_AT_declaration
10407 && a->dw_attr != DW_AT_external)
10408 add_dwarf_attr (die, a);
10411 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10414 if (decl->die_parent != NULL
10415 && decl->die_parent->die_tag != DW_TAG_compile_unit
10416 && decl->die_parent->die_tag != DW_TAG_type_unit)
10418 new_decl = copy_ancestor_tree (unit, decl, NULL);
10419 if (new_decl != NULL)
10421 remove_AT (new_decl, DW_AT_signature);
10422 add_AT_specification (die, new_decl);
10427 /* Generate the skeleton ancestor tree for the given NODE, then clone
10428 the DIE and add the clone into the tree. */
10431 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10433 if (node->new_die != NULL)
10436 node->new_die = clone_as_declaration (node->old_die);
10438 if (node->parent != NULL)
10440 generate_skeleton_ancestor_tree (node->parent);
10441 add_child_die (node->parent->new_die, node->new_die);
10445 /* Generate a skeleton tree of DIEs containing any declarations that are
10446 found in the original tree. We traverse the tree looking for declaration
10447 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10450 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10452 skeleton_chain_node node;
10455 dw_die_ref prev = NULL;
10456 dw_die_ref next = NULL;
10458 node.parent = parent;
10460 first = c = parent->old_die->die_child;
10464 if (prev == NULL || prev->die_sib == c)
10467 next = (c == first ? NULL : c->die_sib);
10469 node.new_die = NULL;
10470 if (is_declaration_die (c))
10472 /* Clone the existing DIE, move the original to the skeleton
10473 tree (which is in the main CU), and put the clone, with
10474 all the original's children, where the original came from. */
10475 dw_die_ref clone = clone_die (c);
10476 move_all_children (c, clone);
10478 replace_child (c, clone, prev);
10479 generate_skeleton_ancestor_tree (parent);
10480 add_child_die (parent->new_die, c);
10484 generate_skeleton_bottom_up (&node);
10485 } while (next != NULL);
10488 /* Wrapper function for generate_skeleton_bottom_up. */
10491 generate_skeleton (dw_die_ref die)
10493 skeleton_chain_node node;
10495 node.old_die = die;
10496 node.new_die = NULL;
10497 node.parent = NULL;
10499 /* If this type definition is nested inside another type,
10500 always leave at least a declaration in its place. */
10501 if (die->die_parent != NULL && is_type_die (die->die_parent))
10502 node.new_die = clone_as_declaration (die);
10504 generate_skeleton_bottom_up (&node);
10505 return node.new_die;
10508 /* Remove the DIE from its parent, possibly replacing it with a cloned
10509 declaration. The original DIE will be moved to a new compile unit
10510 so that existing references to it follow it to the new location. If
10511 any of the original DIE's descendants is a declaration, we need to
10512 replace the original DIE with a skeleton tree and move the
10513 declarations back into the skeleton tree. */
10516 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10518 dw_die_ref skeleton;
10520 skeleton = generate_skeleton (child);
10521 if (skeleton == NULL)
10522 remove_child_with_prev (child, prev);
10525 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10526 replace_child (child, skeleton, prev);
10532 /* Traverse the DIE and set up additional .debug_types sections for each
10533 type worthy of being placed in a COMDAT section. */
10536 break_out_comdat_types (dw_die_ref die)
10540 dw_die_ref prev = NULL;
10541 dw_die_ref next = NULL;
10542 dw_die_ref unit = NULL;
10544 first = c = die->die_child;
10548 if (prev == NULL || prev->die_sib == c)
10551 next = (c == first ? NULL : c->die_sib);
10552 if (should_move_die_to_comdat (c))
10554 dw_die_ref replacement;
10555 comdat_type_node_ref type_node;
10557 /* Create a new type unit DIE as the root for the new tree, and
10558 add it to the list of comdat types. */
10559 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10560 add_AT_unsigned (unit, DW_AT_language,
10561 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10562 type_node = ggc_alloc_cleared_comdat_type_node ();
10563 type_node->root_die = unit;
10564 type_node->next = comdat_type_list;
10565 comdat_type_list = type_node;
10567 /* Generate the type signature. */
10568 generate_type_signature (c, type_node);
10570 /* Copy the declaration context, attributes, and children of the
10571 declaration into the new compile unit DIE. */
10572 copy_declaration_context (unit, c);
10574 /* Remove this DIE from the main CU. */
10575 replacement = remove_child_or_replace_with_skeleton (c, prev);
10577 /* Break out nested types into their own type units. */
10578 break_out_comdat_types (c);
10580 /* Add the DIE to the new compunit. */
10581 add_child_die (unit, c);
10583 if (replacement != NULL)
10586 else if (c->die_tag == DW_TAG_namespace
10587 || c->die_tag == DW_TAG_class_type
10588 || c->die_tag == DW_TAG_structure_type
10589 || c->die_tag == DW_TAG_union_type)
10591 /* Look for nested types that can be broken out. */
10592 break_out_comdat_types (c);
10594 } while (next != NULL);
10597 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10599 struct decl_table_entry
10605 /* Routines to manipulate hash table of copied declarations. */
10608 htab_decl_hash (const void *of)
10610 const struct decl_table_entry *const entry =
10611 (const struct decl_table_entry *) of;
10613 return htab_hash_pointer (entry->orig);
10617 htab_decl_eq (const void *of1, const void *of2)
10619 const struct decl_table_entry *const entry1 =
10620 (const struct decl_table_entry *) of1;
10621 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10623 return entry1->orig == entry2;
10627 htab_decl_del (void *what)
10629 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10634 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10635 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10636 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10637 to check if the ancestor has already been copied into UNIT. */
10640 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10642 dw_die_ref parent = die->die_parent;
10643 dw_die_ref new_parent = unit;
10645 void **slot = NULL;
10646 struct decl_table_entry *entry = NULL;
10650 /* Check if the entry has already been copied to UNIT. */
10651 slot = htab_find_slot_with_hash (decl_table, die,
10652 htab_hash_pointer (die), INSERT);
10653 if (*slot != HTAB_EMPTY_ENTRY)
10655 entry = (struct decl_table_entry *) *slot;
10656 return entry->copy;
10659 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10660 entry = XCNEW (struct decl_table_entry);
10662 entry->copy = NULL;
10666 if (parent != NULL)
10668 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10671 if (parent->die_tag != DW_TAG_compile_unit
10672 && parent->die_tag != DW_TAG_type_unit)
10673 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10676 copy = clone_as_declaration (die);
10677 add_child_die (new_parent, copy);
10679 if (decl_table != NULL)
10681 /* Record the pointer to the copy. */
10682 entry->copy = copy;
10688 /* Walk the DIE and its children, looking for references to incomplete
10689 or trivial types that are unmarked (i.e., that are not in the current
10693 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10699 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10701 if (AT_class (a) == dw_val_class_die_ref)
10703 dw_die_ref targ = AT_ref (a);
10704 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10706 struct decl_table_entry *entry;
10708 if (targ->die_mark != 0 || type_node != NULL)
10711 slot = htab_find_slot_with_hash (decl_table, targ,
10712 htab_hash_pointer (targ), INSERT);
10714 if (*slot != HTAB_EMPTY_ENTRY)
10716 /* TARG has already been copied, so we just need to
10717 modify the reference to point to the copy. */
10718 entry = (struct decl_table_entry *) *slot;
10719 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10723 dw_die_ref parent = unit;
10724 dw_die_ref copy = clone_tree (targ);
10726 /* Make sure the cloned tree is marked as part of the
10730 /* Record in DECL_TABLE that TARG has been copied.
10731 Need to do this now, before the recursive call,
10732 because DECL_TABLE may be expanded and SLOT
10733 would no longer be a valid pointer. */
10734 entry = XCNEW (struct decl_table_entry);
10735 entry->orig = targ;
10736 entry->copy = copy;
10739 /* If TARG has surrounding context, copy its ancestor tree
10740 into the new type unit. */
10741 if (targ->die_parent != NULL
10742 && targ->die_parent->die_tag != DW_TAG_compile_unit
10743 && targ->die_parent->die_tag != DW_TAG_type_unit)
10744 parent = copy_ancestor_tree (unit, targ->die_parent,
10747 add_child_die (parent, copy);
10748 a->dw_attr_val.v.val_die_ref.die = copy;
10750 /* Make sure the newly-copied DIE is walked. If it was
10751 installed in a previously-added context, it won't
10752 get visited otherwise. */
10753 if (parent != unit)
10755 /* Find the highest point of the newly-added tree,
10756 mark each node along the way, and walk from there. */
10757 parent->die_mark = 1;
10758 while (parent->die_parent
10759 && parent->die_parent->die_mark == 0)
10761 parent = parent->die_parent;
10762 parent->die_mark = 1;
10764 copy_decls_walk (unit, parent, decl_table);
10770 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10773 /* Copy declarations for "unworthy" types into the new comdat section.
10774 Incomplete types, modified types, and certain other types aren't broken
10775 out into comdat sections of their own, so they don't have a signature,
10776 and we need to copy the declaration into the same section so that we
10777 don't have an external reference. */
10780 copy_decls_for_unworthy_types (dw_die_ref unit)
10785 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10786 copy_decls_walk (unit, unit, decl_table);
10787 htab_delete (decl_table);
10788 unmark_dies (unit);
10791 /* Traverse the DIE and add a sibling attribute if it may have the
10792 effect of speeding up access to siblings. To save some space,
10793 avoid generating sibling attributes for DIE's without children. */
10796 add_sibling_attributes (dw_die_ref die)
10800 if (! die->die_child)
10803 if (die->die_parent && die != die->die_parent->die_child)
10804 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10806 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10809 /* Output all location lists for the DIE and its children. */
10812 output_location_lists (dw_die_ref die)
10818 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10819 if (AT_class (a) == dw_val_class_loc_list)
10820 output_loc_list (AT_loc_list (a));
10822 FOR_EACH_CHILD (die, c, output_location_lists (c));
10825 /* The format of each DIE (and its attribute value pairs) is encoded in an
10826 abbreviation table. This routine builds the abbreviation table and assigns
10827 a unique abbreviation id for each abbreviation entry. The children of each
10828 die are visited recursively. */
10831 build_abbrev_table (dw_die_ref die)
10833 unsigned long abbrev_id;
10834 unsigned int n_alloc;
10839 /* Scan the DIE references, and mark as external any that refer to
10840 DIEs from other CUs (i.e. those which are not marked). */
10841 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10842 if (AT_class (a) == dw_val_class_die_ref
10843 && AT_ref (a)->die_mark == 0)
10845 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
10846 set_AT_ref_external (a, 1);
10849 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10851 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10852 dw_attr_ref die_a, abbrev_a;
10856 if (abbrev->die_tag != die->die_tag)
10858 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10861 if (VEC_length (dw_attr_node, abbrev->die_attr)
10862 != VEC_length (dw_attr_node, die->die_attr))
10865 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10867 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10868 if ((abbrev_a->dw_attr != die_a->dw_attr)
10869 || (value_format (abbrev_a) != value_format (die_a)))
10879 if (abbrev_id >= abbrev_die_table_in_use)
10881 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10883 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10884 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10887 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10888 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10889 abbrev_die_table_allocated = n_alloc;
10892 ++abbrev_die_table_in_use;
10893 abbrev_die_table[abbrev_id] = die;
10896 die->die_abbrev = abbrev_id;
10897 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10900 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10903 constant_size (unsigned HOST_WIDE_INT value)
10910 log = floor_log2 (value);
10913 log = 1 << (floor_log2 (log) + 1);
10918 /* Return the size of a DIE as it is represented in the
10919 .debug_info section. */
10921 static unsigned long
10922 size_of_die (dw_die_ref die)
10924 unsigned long size = 0;
10928 size += size_of_uleb128 (die->die_abbrev);
10929 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10931 switch (AT_class (a))
10933 case dw_val_class_addr:
10934 size += DWARF2_ADDR_SIZE;
10936 case dw_val_class_offset:
10937 size += DWARF_OFFSET_SIZE;
10939 case dw_val_class_loc:
10941 unsigned long lsize = size_of_locs (AT_loc (a));
10943 /* Block length. */
10944 if (dwarf_version >= 4)
10945 size += size_of_uleb128 (lsize);
10947 size += constant_size (lsize);
10951 case dw_val_class_loc_list:
10952 size += DWARF_OFFSET_SIZE;
10954 case dw_val_class_range_list:
10955 size += DWARF_OFFSET_SIZE;
10957 case dw_val_class_const:
10958 size += size_of_sleb128 (AT_int (a));
10960 case dw_val_class_unsigned_const:
10961 size += constant_size (AT_unsigned (a));
10963 case dw_val_class_const_double:
10964 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10965 if (HOST_BITS_PER_WIDE_INT >= 64)
10966 size++; /* block */
10968 case dw_val_class_vec:
10969 size += constant_size (a->dw_attr_val.v.val_vec.length
10970 * a->dw_attr_val.v.val_vec.elt_size)
10971 + a->dw_attr_val.v.val_vec.length
10972 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10974 case dw_val_class_flag:
10975 if (dwarf_version >= 4)
10976 /* Currently all add_AT_flag calls pass in 1 as last argument,
10977 so DW_FORM_flag_present can be used. If that ever changes,
10978 we'll need to use DW_FORM_flag and have some optimization
10979 in build_abbrev_table that will change those to
10980 DW_FORM_flag_present if it is set to 1 in all DIEs using
10981 the same abbrev entry. */
10982 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10986 case dw_val_class_die_ref:
10987 if (AT_ref_external (a))
10989 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
10990 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10991 is sized by target address length, whereas in DWARF3
10992 it's always sized as an offset. */
10993 if (use_debug_types)
10994 size += DWARF_TYPE_SIGNATURE_SIZE;
10995 else if (dwarf_version == 2)
10996 size += DWARF2_ADDR_SIZE;
10998 size += DWARF_OFFSET_SIZE;
11001 size += DWARF_OFFSET_SIZE;
11003 case dw_val_class_fde_ref:
11004 size += DWARF_OFFSET_SIZE;
11006 case dw_val_class_lbl_id:
11007 size += DWARF2_ADDR_SIZE;
11009 case dw_val_class_lineptr:
11010 case dw_val_class_macptr:
11011 size += DWARF_OFFSET_SIZE;
11013 case dw_val_class_str:
11014 if (AT_string_form (a) == DW_FORM_strp)
11015 size += DWARF_OFFSET_SIZE;
11017 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
11019 case dw_val_class_file:
11020 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
11022 case dw_val_class_data8:
11025 case dw_val_class_vms_delta:
11026 size += DWARF_OFFSET_SIZE;
11029 gcc_unreachable ();
11036 /* Size the debugging information associated with a given DIE. Visits the
11037 DIE's children recursively. Updates the global variable next_die_offset, on
11038 each time through. Uses the current value of next_die_offset to update the
11039 die_offset field in each DIE. */
11042 calc_die_sizes (dw_die_ref die)
11046 gcc_assert (die->die_offset == 0
11047 || (unsigned long int) die->die_offset == next_die_offset);
11048 die->die_offset = next_die_offset;
11049 next_die_offset += size_of_die (die);
11051 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
11053 if (die->die_child != NULL)
11054 /* Count the null byte used to terminate sibling lists. */
11055 next_die_offset += 1;
11058 /* Size just the base type children at the start of the CU.
11059 This is needed because build_abbrev needs to size locs
11060 and sizing of type based stack ops needs to know die_offset
11061 values for the base types. */
11064 calc_base_type_die_sizes (void)
11066 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11068 dw_die_ref base_type;
11069 #if ENABLE_ASSERT_CHECKING
11070 dw_die_ref prev = comp_unit_die ()->die_child;
11073 die_offset += size_of_die (comp_unit_die ());
11074 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
11076 #if ENABLE_ASSERT_CHECKING
11077 gcc_assert (base_type->die_offset == 0
11078 && prev->die_sib == base_type
11079 && base_type->die_child == NULL
11080 && base_type->die_abbrev);
11083 base_type->die_offset = die_offset;
11084 die_offset += size_of_die (base_type);
11088 /* Set the marks for a die and its children. We do this so
11089 that we know whether or not a reference needs to use FORM_ref_addr; only
11090 DIEs in the same CU will be marked. We used to clear out the offset
11091 and use that as the flag, but ran into ordering problems. */
11094 mark_dies (dw_die_ref die)
11098 gcc_assert (!die->die_mark);
11101 FOR_EACH_CHILD (die, c, mark_dies (c));
11104 /* Clear the marks for a die and its children. */
11107 unmark_dies (dw_die_ref die)
11111 if (! use_debug_types)
11112 gcc_assert (die->die_mark);
11115 FOR_EACH_CHILD (die, c, unmark_dies (c));
11118 /* Clear the marks for a die, its children and referred dies. */
11121 unmark_all_dies (dw_die_ref die)
11127 if (!die->die_mark)
11131 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
11133 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11134 if (AT_class (a) == dw_val_class_die_ref)
11135 unmark_all_dies (AT_ref (a));
11138 /* Return the size of the .debug_pubnames or .debug_pubtypes table
11139 generated for the compilation unit. */
11141 static unsigned long
11142 size_of_pubnames (VEC (pubname_entry, gc) * names)
11144 unsigned long size;
11148 size = DWARF_PUBNAMES_HEADER_SIZE;
11149 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
11150 if (names != pubtype_table
11151 || p->die->die_offset != 0
11152 || !flag_eliminate_unused_debug_types)
11153 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
11155 size += DWARF_OFFSET_SIZE;
11159 /* Return the size of the information in the .debug_aranges section. */
11161 static unsigned long
11162 size_of_aranges (void)
11164 unsigned long size;
11166 size = DWARF_ARANGES_HEADER_SIZE;
11168 /* Count the address/length pair for this compilation unit. */
11169 if (text_section_used)
11170 size += 2 * DWARF2_ADDR_SIZE;
11171 if (cold_text_section_used)
11172 size += 2 * DWARF2_ADDR_SIZE;
11173 if (have_multiple_function_sections)
11175 unsigned fde_idx = 0;
11177 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
11179 dw_fde_ref fde = &fde_table[fde_idx];
11181 if (!fde->in_std_section)
11182 size += 2 * DWARF2_ADDR_SIZE;
11183 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11184 size += 2 * DWARF2_ADDR_SIZE;
11188 /* Count the two zero words used to terminated the address range table. */
11189 size += 2 * DWARF2_ADDR_SIZE;
11193 /* Select the encoding of an attribute value. */
11195 static enum dwarf_form
11196 value_format (dw_attr_ref a)
11198 switch (a->dw_attr_val.val_class)
11200 case dw_val_class_addr:
11201 /* Only very few attributes allow DW_FORM_addr. */
11202 switch (a->dw_attr)
11205 case DW_AT_high_pc:
11206 case DW_AT_entry_pc:
11207 case DW_AT_trampoline:
11208 return DW_FORM_addr;
11212 switch (DWARF2_ADDR_SIZE)
11215 return DW_FORM_data1;
11217 return DW_FORM_data2;
11219 return DW_FORM_data4;
11221 return DW_FORM_data8;
11223 gcc_unreachable ();
11225 case dw_val_class_range_list:
11226 case dw_val_class_loc_list:
11227 if (dwarf_version >= 4)
11228 return DW_FORM_sec_offset;
11230 case dw_val_class_vms_delta:
11231 case dw_val_class_offset:
11232 switch (DWARF_OFFSET_SIZE)
11235 return DW_FORM_data4;
11237 return DW_FORM_data8;
11239 gcc_unreachable ();
11241 case dw_val_class_loc:
11242 if (dwarf_version >= 4)
11243 return DW_FORM_exprloc;
11244 switch (constant_size (size_of_locs (AT_loc (a))))
11247 return DW_FORM_block1;
11249 return DW_FORM_block2;
11251 gcc_unreachable ();
11253 case dw_val_class_const:
11254 return DW_FORM_sdata;
11255 case dw_val_class_unsigned_const:
11256 switch (constant_size (AT_unsigned (a)))
11259 return DW_FORM_data1;
11261 return DW_FORM_data2;
11263 return DW_FORM_data4;
11265 return DW_FORM_data8;
11267 gcc_unreachable ();
11269 case dw_val_class_const_double:
11270 switch (HOST_BITS_PER_WIDE_INT)
11273 return DW_FORM_data2;
11275 return DW_FORM_data4;
11277 return DW_FORM_data8;
11280 return DW_FORM_block1;
11282 case dw_val_class_vec:
11283 switch (constant_size (a->dw_attr_val.v.val_vec.length
11284 * a->dw_attr_val.v.val_vec.elt_size))
11287 return DW_FORM_block1;
11289 return DW_FORM_block2;
11291 return DW_FORM_block4;
11293 gcc_unreachable ();
11295 case dw_val_class_flag:
11296 if (dwarf_version >= 4)
11298 /* Currently all add_AT_flag calls pass in 1 as last argument,
11299 so DW_FORM_flag_present can be used. If that ever changes,
11300 we'll need to use DW_FORM_flag and have some optimization
11301 in build_abbrev_table that will change those to
11302 DW_FORM_flag_present if it is set to 1 in all DIEs using
11303 the same abbrev entry. */
11304 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11305 return DW_FORM_flag_present;
11307 return DW_FORM_flag;
11308 case dw_val_class_die_ref:
11309 if (AT_ref_external (a))
11310 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
11312 return DW_FORM_ref;
11313 case dw_val_class_fde_ref:
11314 return DW_FORM_data;
11315 case dw_val_class_lbl_id:
11316 return DW_FORM_addr;
11317 case dw_val_class_lineptr:
11318 case dw_val_class_macptr:
11319 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11320 case dw_val_class_str:
11321 return AT_string_form (a);
11322 case dw_val_class_file:
11323 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11326 return DW_FORM_data1;
11328 return DW_FORM_data2;
11330 return DW_FORM_data4;
11332 gcc_unreachable ();
11335 case dw_val_class_data8:
11336 return DW_FORM_data8;
11339 gcc_unreachable ();
11343 /* Output the encoding of an attribute value. */
11346 output_value_format (dw_attr_ref a)
11348 enum dwarf_form form = value_format (a);
11350 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11353 /* Output the .debug_abbrev section which defines the DIE abbreviation
11357 output_abbrev_section (void)
11359 unsigned long abbrev_id;
11361 if (abbrev_die_table_in_use == 1)
11364 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11366 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11368 dw_attr_ref a_attr;
11370 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11371 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11372 dwarf_tag_name (abbrev->die_tag));
11374 if (abbrev->die_child != NULL)
11375 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11377 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11379 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11382 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11383 dwarf_attr_name (a_attr->dw_attr));
11384 output_value_format (a_attr);
11387 dw2_asm_output_data (1, 0, NULL);
11388 dw2_asm_output_data (1, 0, NULL);
11391 /* Terminate the table. */
11392 dw2_asm_output_data (1, 0, NULL);
11395 /* Output a symbol we can use to refer to this DIE from another CU. */
11398 output_die_symbol (dw_die_ref die)
11400 char *sym = die->die_id.die_symbol;
11405 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11406 /* We make these global, not weak; if the target doesn't support
11407 .linkonce, it doesn't support combining the sections, so debugging
11409 targetm.asm_out.globalize_label (asm_out_file, sym);
11411 ASM_OUTPUT_LABEL (asm_out_file, sym);
11414 /* Return a new location list, given the begin and end range, and the
11417 static inline dw_loc_list_ref
11418 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11419 const char *section)
11421 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11423 retlist->begin = begin;
11424 retlist->end = end;
11425 retlist->expr = expr;
11426 retlist->section = section;
11431 /* Generate a new internal symbol for this location list node, if it
11432 hasn't got one yet. */
11435 gen_llsym (dw_loc_list_ref list)
11437 gcc_assert (!list->ll_symbol);
11438 list->ll_symbol = gen_internal_sym ("LLST");
11441 /* Output the location list given to us. */
11444 output_loc_list (dw_loc_list_ref list_head)
11446 dw_loc_list_ref curr = list_head;
11448 if (list_head->emitted)
11450 list_head->emitted = true;
11452 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11454 /* Walk the location list, and output each range + expression. */
11455 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11457 unsigned long size;
11458 /* Don't output an entry that starts and ends at the same address. */
11459 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
11461 if (!have_multiple_function_sections)
11463 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11464 "Location list begin address (%s)",
11465 list_head->ll_symbol);
11466 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11467 "Location list end address (%s)",
11468 list_head->ll_symbol);
11472 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11473 "Location list begin address (%s)",
11474 list_head->ll_symbol);
11475 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11476 "Location list end address (%s)",
11477 list_head->ll_symbol);
11479 size = size_of_locs (curr->expr);
11481 /* Output the block length for this list of location operations. */
11482 gcc_assert (size <= 0xffff);
11483 dw2_asm_output_data (2, size, "%s", "Location expression size");
11485 output_loc_sequence (curr->expr, -1);
11488 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11489 "Location list terminator begin (%s)",
11490 list_head->ll_symbol);
11491 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11492 "Location list terminator end (%s)",
11493 list_head->ll_symbol);
11496 /* Output a type signature. */
11499 output_signature (const char *sig, const char *name)
11503 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11504 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11507 /* Output the DIE and its attributes. Called recursively to generate
11508 the definitions of each child DIE. */
11511 output_die (dw_die_ref die)
11515 unsigned long size;
11518 /* If someone in another CU might refer to us, set up a symbol for
11519 them to point to. */
11520 if (! use_debug_types && die->die_id.die_symbol)
11521 output_die_symbol (die);
11523 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11524 (unsigned long)die->die_offset,
11525 dwarf_tag_name (die->die_tag));
11527 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11529 const char *name = dwarf_attr_name (a->dw_attr);
11531 switch (AT_class (a))
11533 case dw_val_class_addr:
11534 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11537 case dw_val_class_offset:
11538 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11542 case dw_val_class_range_list:
11544 char *p = strchr (ranges_section_label, '\0');
11546 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11547 a->dw_attr_val.v.val_offset);
11548 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11549 debug_ranges_section, "%s", name);
11554 case dw_val_class_loc:
11555 size = size_of_locs (AT_loc (a));
11557 /* Output the block length for this list of location operations. */
11558 if (dwarf_version >= 4)
11559 dw2_asm_output_data_uleb128 (size, "%s", name);
11561 dw2_asm_output_data (constant_size (size), size, "%s", name);
11563 output_loc_sequence (AT_loc (a), -1);
11566 case dw_val_class_const:
11567 /* ??? It would be slightly more efficient to use a scheme like is
11568 used for unsigned constants below, but gdb 4.x does not sign
11569 extend. Gdb 5.x does sign extend. */
11570 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11573 case dw_val_class_unsigned_const:
11574 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11575 AT_unsigned (a), "%s", name);
11578 case dw_val_class_const_double:
11580 unsigned HOST_WIDE_INT first, second;
11582 if (HOST_BITS_PER_WIDE_INT >= 64)
11583 dw2_asm_output_data (1,
11584 2 * HOST_BITS_PER_WIDE_INT
11585 / HOST_BITS_PER_CHAR,
11588 if (WORDS_BIG_ENDIAN)
11590 first = a->dw_attr_val.v.val_double.high;
11591 second = a->dw_attr_val.v.val_double.low;
11595 first = a->dw_attr_val.v.val_double.low;
11596 second = a->dw_attr_val.v.val_double.high;
11599 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11601 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11606 case dw_val_class_vec:
11608 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11609 unsigned int len = a->dw_attr_val.v.val_vec.length;
11613 dw2_asm_output_data (constant_size (len * elt_size),
11614 len * elt_size, "%s", name);
11615 if (elt_size > sizeof (HOST_WIDE_INT))
11620 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11622 i++, p += elt_size)
11623 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11624 "fp or vector constant word %u", i);
11628 case dw_val_class_flag:
11629 if (dwarf_version >= 4)
11631 /* Currently all add_AT_flag calls pass in 1 as last argument,
11632 so DW_FORM_flag_present can be used. If that ever changes,
11633 we'll need to use DW_FORM_flag and have some optimization
11634 in build_abbrev_table that will change those to
11635 DW_FORM_flag_present if it is set to 1 in all DIEs using
11636 the same abbrev entry. */
11637 gcc_assert (AT_flag (a) == 1);
11638 if (flag_debug_asm)
11639 fprintf (asm_out_file, "\t\t\t%s %s\n",
11640 ASM_COMMENT_START, name);
11643 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11646 case dw_val_class_loc_list:
11648 char *sym = AT_loc_list (a)->ll_symbol;
11651 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11656 case dw_val_class_die_ref:
11657 if (AT_ref_external (a))
11659 if (use_debug_types)
11661 comdat_type_node_ref type_node =
11662 AT_ref (a)->die_id.die_type_node;
11664 gcc_assert (type_node);
11665 output_signature (type_node->signature, name);
11669 char *sym = AT_ref (a)->die_id.die_symbol;
11673 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11674 length, whereas in DWARF3 it's always sized as an
11676 if (dwarf_version == 2)
11677 size = DWARF2_ADDR_SIZE;
11679 size = DWARF_OFFSET_SIZE;
11680 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11686 gcc_assert (AT_ref (a)->die_offset);
11687 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11692 case dw_val_class_fde_ref:
11696 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11697 a->dw_attr_val.v.val_fde_index * 2);
11698 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11703 case dw_val_class_vms_delta:
11704 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11705 AT_vms_delta2 (a), AT_vms_delta1 (a),
11709 case dw_val_class_lbl_id:
11710 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11713 case dw_val_class_lineptr:
11714 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11715 debug_line_section, "%s", name);
11718 case dw_val_class_macptr:
11719 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11720 debug_macinfo_section, "%s", name);
11723 case dw_val_class_str:
11724 if (AT_string_form (a) == DW_FORM_strp)
11725 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11726 a->dw_attr_val.v.val_str->label,
11728 "%s: \"%s\"", name, AT_string (a));
11730 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11733 case dw_val_class_file:
11735 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11737 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11738 a->dw_attr_val.v.val_file->filename);
11742 case dw_val_class_data8:
11746 for (i = 0; i < 8; i++)
11747 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11748 i == 0 ? "%s" : NULL, name);
11753 gcc_unreachable ();
11757 FOR_EACH_CHILD (die, c, output_die (c));
11759 /* Add null byte to terminate sibling list. */
11760 if (die->die_child != NULL)
11761 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11762 (unsigned long) die->die_offset);
11765 /* Output the compilation unit that appears at the beginning of the
11766 .debug_info section, and precedes the DIE descriptions. */
11769 output_compilation_unit_header (void)
11771 int ver = dwarf_version;
11773 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11774 dw2_asm_output_data (4, 0xffffffff,
11775 "Initial length escape value indicating 64-bit DWARF extension");
11776 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11777 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11778 "Length of Compilation Unit Info");
11779 dw2_asm_output_data (2, ver, "DWARF version number");
11780 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11781 debug_abbrev_section,
11782 "Offset Into Abbrev. Section");
11783 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11786 /* Output the compilation unit DIE and its children. */
11789 output_comp_unit (dw_die_ref die, int output_if_empty)
11791 const char *secname;
11792 char *oldsym, *tmp;
11794 /* Unless we are outputting main CU, we may throw away empty ones. */
11795 if (!output_if_empty && die->die_child == NULL)
11798 /* Even if there are no children of this DIE, we must output the information
11799 about the compilation unit. Otherwise, on an empty translation unit, we
11800 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11801 will then complain when examining the file. First mark all the DIEs in
11802 this CU so we know which get local refs. */
11805 build_abbrev_table (die);
11807 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11808 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11809 calc_die_sizes (die);
11811 oldsym = die->die_id.die_symbol;
11814 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11816 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11818 die->die_id.die_symbol = NULL;
11819 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11823 switch_to_section (debug_info_section);
11824 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11825 info_section_emitted = true;
11828 /* Output debugging information. */
11829 output_compilation_unit_header ();
11832 /* Leave the marks on the main CU, so we can check them in
11833 output_pubnames. */
11837 die->die_id.die_symbol = oldsym;
11841 /* Output a comdat type unit DIE and its children. */
11844 output_comdat_type_unit (comdat_type_node *node)
11846 const char *secname;
11849 #if defined (OBJECT_FORMAT_ELF)
11853 /* First mark all the DIEs in this CU so we know which get local refs. */
11854 mark_dies (node->root_die);
11856 build_abbrev_table (node->root_die);
11858 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11859 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11860 calc_die_sizes (node->root_die);
11862 #if defined (OBJECT_FORMAT_ELF)
11863 secname = ".debug_types";
11864 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11865 sprintf (tmp, "wt.");
11866 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11867 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11868 comdat_key = get_identifier (tmp);
11869 targetm.asm_out.named_section (secname,
11870 SECTION_DEBUG | SECTION_LINKONCE,
11873 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11874 sprintf (tmp, ".gnu.linkonce.wt.");
11875 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11876 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11878 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11881 /* Output debugging information. */
11882 output_compilation_unit_header ();
11883 output_signature (node->signature, "Type Signature");
11884 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11885 "Offset to Type DIE");
11886 output_die (node->root_die);
11888 unmark_dies (node->root_die);
11891 /* Return the DWARF2/3 pubname associated with a decl. */
11893 static const char *
11894 dwarf2_name (tree decl, int scope)
11896 if (DECL_NAMELESS (decl))
11898 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11901 /* Add a new entry to .debug_pubnames if appropriate. */
11904 add_pubname_string (const char *str, dw_die_ref die)
11906 if (targetm.want_debug_pub_sections)
11911 e.name = xstrdup (str);
11912 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11917 add_pubname (tree decl, dw_die_ref die)
11919 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11921 const char *name = dwarf2_name (decl, 1);
11923 add_pubname_string (name, die);
11927 /* Add a new entry to .debug_pubtypes if appropriate. */
11930 add_pubtype (tree decl, dw_die_ref die)
11934 if (!targetm.want_debug_pub_sections)
11938 if ((TREE_PUBLIC (decl)
11939 || is_cu_die (die->die_parent))
11940 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11945 if (TYPE_NAME (decl))
11947 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11948 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11949 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11950 && DECL_NAME (TYPE_NAME (decl)))
11951 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11953 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11958 e.name = dwarf2_name (decl, 1);
11960 e.name = xstrdup (e.name);
11963 /* If we don't have a name for the type, there's no point in adding
11964 it to the table. */
11965 if (e.name && e.name[0] != '\0')
11966 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11970 /* Output the public names table used to speed up access to externally
11971 visible names; or the public types table used to find type definitions. */
11974 output_pubnames (VEC (pubname_entry, gc) * names)
11977 unsigned long pubnames_length = size_of_pubnames (names);
11980 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11981 dw2_asm_output_data (4, 0xffffffff,
11982 "Initial length escape value indicating 64-bit DWARF extension");
11983 if (names == pubname_table)
11984 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11985 "Length of Public Names Info");
11987 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11988 "Length of Public Type Names Info");
11989 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11990 dw2_asm_output_data (2, 2, "DWARF Version");
11991 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11992 debug_info_section,
11993 "Offset of Compilation Unit Info");
11994 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11995 "Compilation Unit Length");
11997 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11999 /* We shouldn't see pubnames for DIEs outside of the main CU. */
12000 if (names == pubname_table)
12001 gcc_assert (pub->die->die_mark);
12003 if (names != pubtype_table
12004 || pub->die->die_offset != 0
12005 || !flag_eliminate_unused_debug_types)
12007 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
12010 dw2_asm_output_nstring (pub->name, -1, "external name");
12014 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
12017 /* Output the information that goes into the .debug_aranges table.
12018 Namely, define the beginning and ending address range of the
12019 text section generated for this compilation unit. */
12022 output_aranges (unsigned long aranges_length)
12026 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12027 dw2_asm_output_data (4, 0xffffffff,
12028 "Initial length escape value indicating 64-bit DWARF extension");
12029 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
12030 "Length of Address Ranges Info");
12031 /* Version number for aranges is still 2, even in DWARF3. */
12032 dw2_asm_output_data (2, 2, "DWARF Version");
12033 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12034 debug_info_section,
12035 "Offset of Compilation Unit Info");
12036 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
12037 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
12039 /* We need to align to twice the pointer size here. */
12040 if (DWARF_ARANGES_PAD_SIZE)
12042 /* Pad using a 2 byte words so that padding is correct for any
12044 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
12045 2 * DWARF2_ADDR_SIZE);
12046 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
12047 dw2_asm_output_data (2, 0, NULL);
12050 /* It is necessary not to output these entries if the sections were
12051 not used; if the sections were not used, the length will be 0 and
12052 the address may end up as 0 if the section is discarded by ld
12053 --gc-sections, leaving an invalid (0, 0) entry that can be
12054 confused with the terminator. */
12055 if (text_section_used)
12057 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
12058 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
12059 text_section_label, "Length");
12061 if (cold_text_section_used)
12063 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
12065 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
12066 cold_text_section_label, "Length");
12069 if (have_multiple_function_sections)
12071 unsigned fde_idx = 0;
12073 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
12075 dw_fde_ref fde = &fde_table[fde_idx];
12077 if (!fde->in_std_section)
12079 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
12081 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
12082 fde->dw_fde_begin, "Length");
12084 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
12086 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
12088 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
12089 fde->dw_fde_second_begin, "Length");
12094 /* Output the terminator words. */
12095 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12096 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12099 /* Add a new entry to .debug_ranges. Return the offset at which it
12102 static unsigned int
12103 add_ranges_num (int num)
12105 unsigned int in_use = ranges_table_in_use;
12107 if (in_use == ranges_table_allocated)
12109 ranges_table_allocated += RANGES_TABLE_INCREMENT;
12110 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
12111 ranges_table_allocated);
12112 memset (ranges_table + ranges_table_in_use, 0,
12113 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
12116 ranges_table[in_use].num = num;
12117 ranges_table_in_use = in_use + 1;
12119 return in_use * 2 * DWARF2_ADDR_SIZE;
12122 /* Add a new entry to .debug_ranges corresponding to a block, or a
12123 range terminator if BLOCK is NULL. */
12125 static unsigned int
12126 add_ranges (const_tree block)
12128 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
12131 /* Add a new entry to .debug_ranges corresponding to a pair of
12135 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
12138 unsigned int in_use = ranges_by_label_in_use;
12139 unsigned int offset;
12141 if (in_use == ranges_by_label_allocated)
12143 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
12144 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
12146 ranges_by_label_allocated);
12147 memset (ranges_by_label + ranges_by_label_in_use, 0,
12148 RANGES_TABLE_INCREMENT
12149 * sizeof (struct dw_ranges_by_label_struct));
12152 ranges_by_label[in_use].begin = begin;
12153 ranges_by_label[in_use].end = end;
12154 ranges_by_label_in_use = in_use + 1;
12156 offset = add_ranges_num (-(int)in_use - 1);
12159 add_AT_range_list (die, DW_AT_ranges, offset);
12165 output_ranges (void)
12168 static const char *const start_fmt = "Offset %#x";
12169 const char *fmt = start_fmt;
12171 for (i = 0; i < ranges_table_in_use; i++)
12173 int block_num = ranges_table[i].num;
12177 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12178 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12180 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12181 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12183 /* If all code is in the text section, then the compilation
12184 unit base address defaults to DW_AT_low_pc, which is the
12185 base of the text section. */
12186 if (!have_multiple_function_sections)
12188 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
12189 text_section_label,
12190 fmt, i * 2 * DWARF2_ADDR_SIZE);
12191 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
12192 text_section_label, NULL);
12195 /* Otherwise, the compilation unit base address is zero,
12196 which allows us to use absolute addresses, and not worry
12197 about whether the target supports cross-section
12201 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12202 fmt, i * 2 * DWARF2_ADDR_SIZE);
12203 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
12209 /* Negative block_num stands for an index into ranges_by_label. */
12210 else if (block_num < 0)
12212 int lab_idx = - block_num - 1;
12214 if (!have_multiple_function_sections)
12216 gcc_unreachable ();
12218 /* If we ever use add_ranges_by_labels () for a single
12219 function section, all we have to do is to take out
12220 the #if 0 above. */
12221 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12222 ranges_by_label[lab_idx].begin,
12223 text_section_label,
12224 fmt, i * 2 * DWARF2_ADDR_SIZE);
12225 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12226 ranges_by_label[lab_idx].end,
12227 text_section_label, NULL);
12232 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12233 ranges_by_label[lab_idx].begin,
12234 fmt, i * 2 * DWARF2_ADDR_SIZE);
12235 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12236 ranges_by_label[lab_idx].end,
12242 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12243 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12249 /* Data structure containing information about input files. */
12252 const char *path; /* Complete file name. */
12253 const char *fname; /* File name part. */
12254 int length; /* Length of entire string. */
12255 struct dwarf_file_data * file_idx; /* Index in input file table. */
12256 int dir_idx; /* Index in directory table. */
12259 /* Data structure containing information about directories with source
12263 const char *path; /* Path including directory name. */
12264 int length; /* Path length. */
12265 int prefix; /* Index of directory entry which is a prefix. */
12266 int count; /* Number of files in this directory. */
12267 int dir_idx; /* Index of directory used as base. */
12270 /* Callback function for file_info comparison. We sort by looking at
12271 the directories in the path. */
12274 file_info_cmp (const void *p1, const void *p2)
12276 const struct file_info *const s1 = (const struct file_info *) p1;
12277 const struct file_info *const s2 = (const struct file_info *) p2;
12278 const unsigned char *cp1;
12279 const unsigned char *cp2;
12281 /* Take care of file names without directories. We need to make sure that
12282 we return consistent values to qsort since some will get confused if
12283 we return the same value when identical operands are passed in opposite
12284 orders. So if neither has a directory, return 0 and otherwise return
12285 1 or -1 depending on which one has the directory. */
12286 if ((s1->path == s1->fname || s2->path == s2->fname))
12287 return (s2->path == s2->fname) - (s1->path == s1->fname);
12289 cp1 = (const unsigned char *) s1->path;
12290 cp2 = (const unsigned char *) s2->path;
12296 /* Reached the end of the first path? If so, handle like above. */
12297 if ((cp1 == (const unsigned char *) s1->fname)
12298 || (cp2 == (const unsigned char *) s2->fname))
12299 return ((cp2 == (const unsigned char *) s2->fname)
12300 - (cp1 == (const unsigned char *) s1->fname));
12302 /* Character of current path component the same? */
12303 else if (*cp1 != *cp2)
12304 return *cp1 - *cp2;
12308 struct file_name_acquire_data
12310 struct file_info *files;
12315 /* Traversal function for the hash table. */
12318 file_name_acquire (void ** slot, void *data)
12320 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12321 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12322 struct file_info *fi;
12325 gcc_assert (fnad->max_files >= d->emitted_number);
12327 if (! d->emitted_number)
12330 gcc_assert (fnad->max_files != fnad->used_files);
12332 fi = fnad->files + fnad->used_files++;
12334 /* Skip all leading "./". */
12336 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12339 /* Create a new array entry. */
12341 fi->length = strlen (f);
12344 /* Search for the file name part. */
12345 f = strrchr (f, DIR_SEPARATOR);
12346 #if defined (DIR_SEPARATOR_2)
12348 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12352 if (f == NULL || f < g)
12358 fi->fname = f == NULL ? fi->path : f + 1;
12362 /* Output the directory table and the file name table. We try to minimize
12363 the total amount of memory needed. A heuristic is used to avoid large
12364 slowdowns with many input files. */
12367 output_file_names (void)
12369 struct file_name_acquire_data fnad;
12371 struct file_info *files;
12372 struct dir_info *dirs;
12380 if (!last_emitted_file)
12382 dw2_asm_output_data (1, 0, "End directory table");
12383 dw2_asm_output_data (1, 0, "End file name table");
12387 numfiles = last_emitted_file->emitted_number;
12389 /* Allocate the various arrays we need. */
12390 files = XALLOCAVEC (struct file_info, numfiles);
12391 dirs = XALLOCAVEC (struct dir_info, numfiles);
12393 fnad.files = files;
12394 fnad.used_files = 0;
12395 fnad.max_files = numfiles;
12396 htab_traverse (file_table, file_name_acquire, &fnad);
12397 gcc_assert (fnad.used_files == fnad.max_files);
12399 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12401 /* Find all the different directories used. */
12402 dirs[0].path = files[0].path;
12403 dirs[0].length = files[0].fname - files[0].path;
12404 dirs[0].prefix = -1;
12406 dirs[0].dir_idx = 0;
12407 files[0].dir_idx = 0;
12410 for (i = 1; i < numfiles; i++)
12411 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12412 && memcmp (dirs[ndirs - 1].path, files[i].path,
12413 dirs[ndirs - 1].length) == 0)
12415 /* Same directory as last entry. */
12416 files[i].dir_idx = ndirs - 1;
12417 ++dirs[ndirs - 1].count;
12423 /* This is a new directory. */
12424 dirs[ndirs].path = files[i].path;
12425 dirs[ndirs].length = files[i].fname - files[i].path;
12426 dirs[ndirs].count = 1;
12427 dirs[ndirs].dir_idx = ndirs;
12428 files[i].dir_idx = ndirs;
12430 /* Search for a prefix. */
12431 dirs[ndirs].prefix = -1;
12432 for (j = 0; j < ndirs; j++)
12433 if (dirs[j].length < dirs[ndirs].length
12434 && dirs[j].length > 1
12435 && (dirs[ndirs].prefix == -1
12436 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12437 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12438 dirs[ndirs].prefix = j;
12443 /* Now to the actual work. We have to find a subset of the directories which
12444 allow expressing the file name using references to the directory table
12445 with the least amount of characters. We do not do an exhaustive search
12446 where we would have to check out every combination of every single
12447 possible prefix. Instead we use a heuristic which provides nearly optimal
12448 results in most cases and never is much off. */
12449 saved = XALLOCAVEC (int, ndirs);
12450 savehere = XALLOCAVEC (int, ndirs);
12452 memset (saved, '\0', ndirs * sizeof (saved[0]));
12453 for (i = 0; i < ndirs; i++)
12458 /* We can always save some space for the current directory. But this
12459 does not mean it will be enough to justify adding the directory. */
12460 savehere[i] = dirs[i].length;
12461 total = (savehere[i] - saved[i]) * dirs[i].count;
12463 for (j = i + 1; j < ndirs; j++)
12466 if (saved[j] < dirs[i].length)
12468 /* Determine whether the dirs[i] path is a prefix of the
12472 k = dirs[j].prefix;
12473 while (k != -1 && k != (int) i)
12474 k = dirs[k].prefix;
12478 /* Yes it is. We can possibly save some memory by
12479 writing the filenames in dirs[j] relative to
12481 savehere[j] = dirs[i].length;
12482 total += (savehere[j] - saved[j]) * dirs[j].count;
12487 /* Check whether we can save enough to justify adding the dirs[i]
12489 if (total > dirs[i].length + 1)
12491 /* It's worthwhile adding. */
12492 for (j = i; j < ndirs; j++)
12493 if (savehere[j] > 0)
12495 /* Remember how much we saved for this directory so far. */
12496 saved[j] = savehere[j];
12498 /* Remember the prefix directory. */
12499 dirs[j].dir_idx = i;
12504 /* Emit the directory name table. */
12505 idx_offset = dirs[0].length > 0 ? 1 : 0;
12506 for (i = 1 - idx_offset; i < ndirs; i++)
12507 dw2_asm_output_nstring (dirs[i].path,
12509 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12510 "Directory Entry: %#x", i + idx_offset);
12512 dw2_asm_output_data (1, 0, "End directory table");
12514 /* We have to emit them in the order of emitted_number since that's
12515 used in the debug info generation. To do this efficiently we
12516 generate a back-mapping of the indices first. */
12517 backmap = XALLOCAVEC (int, numfiles);
12518 for (i = 0; i < numfiles; i++)
12519 backmap[files[i].file_idx->emitted_number - 1] = i;
12521 /* Now write all the file names. */
12522 for (i = 0; i < numfiles; i++)
12524 int file_idx = backmap[i];
12525 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12527 #ifdef VMS_DEBUGGING_INFO
12528 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12530 /* Setting these fields can lead to debugger miscomparisons,
12531 but VMS Debug requires them to be set correctly. */
12536 int maxfilelen = strlen (files[file_idx].path)
12537 + dirs[dir_idx].length
12538 + MAX_VMS_VERSION_LEN + 1;
12539 char *filebuf = XALLOCAVEC (char, maxfilelen);
12541 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12542 snprintf (filebuf, maxfilelen, "%s;%d",
12543 files[file_idx].path + dirs[dir_idx].length, ver);
12545 dw2_asm_output_nstring
12546 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12548 /* Include directory index. */
12549 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12551 /* Modification time. */
12552 dw2_asm_output_data_uleb128
12553 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12557 /* File length in bytes. */
12558 dw2_asm_output_data_uleb128
12559 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12563 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12564 "File Entry: %#x", (unsigned) i + 1);
12566 /* Include directory index. */
12567 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12569 /* Modification time. */
12570 dw2_asm_output_data_uleb128 (0, NULL);
12572 /* File length in bytes. */
12573 dw2_asm_output_data_uleb128 (0, NULL);
12574 #endif /* VMS_DEBUGGING_INFO */
12577 dw2_asm_output_data (1, 0, "End file name table");
12581 /* Output one line number table into the .debug_line section. */
12584 output_one_line_info_table (dw_line_info_table *table)
12586 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12587 unsigned int current_line = 1;
12588 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
12589 dw_line_info_entry *ent;
12592 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
12594 switch (ent->opcode)
12596 case LI_set_address:
12597 /* ??? Unfortunately, we have little choice here currently, and
12598 must always use the most general form. GCC does not know the
12599 address delta itself, so we can't use DW_LNS_advance_pc. Many
12600 ports do have length attributes which will give an upper bound
12601 on the address range. We could perhaps use length attributes
12602 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12603 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
12605 /* This can handle any delta. This takes
12606 4+DWARF2_ADDR_SIZE bytes. */
12607 dw2_asm_output_data (1, 0, "set address %s", line_label);
12608 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12609 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12610 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12614 if (ent->val == current_line)
12616 /* We still need to start a new row, so output a copy insn. */
12617 dw2_asm_output_data (1, DW_LNS_copy,
12618 "copy line %u", current_line);
12622 int line_offset = ent->val - current_line;
12623 int line_delta = line_offset - DWARF_LINE_BASE;
12625 current_line = ent->val;
12626 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12628 /* This can handle deltas from -10 to 234, using the current
12629 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
12630 This takes 1 byte. */
12631 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12632 "line %u", current_line);
12636 /* This can handle any delta. This takes at least 4 bytes,
12637 depending on the value being encoded. */
12638 dw2_asm_output_data (1, DW_LNS_advance_line,
12639 "advance to line %u", current_line);
12640 dw2_asm_output_data_sleb128 (line_offset, NULL);
12641 dw2_asm_output_data (1, DW_LNS_copy, NULL);
12647 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
12648 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12651 case LI_set_column:
12652 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
12653 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12656 case LI_negate_stmt:
12657 current_is_stmt = !current_is_stmt;
12658 dw2_asm_output_data (1, DW_LNS_negate_stmt,
12659 "is_stmt %d", current_is_stmt);
12662 case LI_set_prologue_end:
12663 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
12664 "set prologue end");
12667 case LI_set_epilogue_begin:
12668 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
12669 "set epilogue begin");
12672 case LI_set_discriminator:
12673 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
12674 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
12675 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
12676 dw2_asm_output_data_uleb128 (ent->val, NULL);
12681 /* Emit debug info for the address of the end of the table. */
12682 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
12683 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12684 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12685 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
12687 dw2_asm_output_data (1, 0, "end sequence");
12688 dw2_asm_output_data_uleb128 (1, NULL);
12689 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12692 /* Output the source line number correspondence information. This
12693 information goes into the .debug_line section. */
12696 output_line_info (void)
12698 char l1[20], l2[20], p1[20], p2[20];
12699 int ver = dwarf_version;
12700 bool saw_one = false;
12703 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12704 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12705 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12706 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12708 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12709 dw2_asm_output_data (4, 0xffffffff,
12710 "Initial length escape value indicating 64-bit DWARF extension");
12711 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12712 "Length of Source Line Info");
12713 ASM_OUTPUT_LABEL (asm_out_file, l1);
12715 dw2_asm_output_data (2, ver, "DWARF Version");
12716 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12717 ASM_OUTPUT_LABEL (asm_out_file, p1);
12719 /* Define the architecture-dependent minimum instruction length (in bytes).
12720 In this implementation of DWARF, this field is used for information
12721 purposes only. Since GCC generates assembly language, we have no
12722 a priori knowledge of how many instruction bytes are generated for each
12723 source line, and therefore can use only the DW_LNE_set_address and
12724 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12725 this as '1', which is "correct enough" for all architectures,
12726 and don't let the target override. */
12727 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12730 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12731 "Maximum Operations Per Instruction");
12732 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12733 "Default is_stmt_start flag");
12734 dw2_asm_output_data (1, DWARF_LINE_BASE,
12735 "Line Base Value (Special Opcodes)");
12736 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12737 "Line Range Value (Special Opcodes)");
12738 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12739 "Special Opcode Base");
12741 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12746 case DW_LNS_advance_pc:
12747 case DW_LNS_advance_line:
12748 case DW_LNS_set_file:
12749 case DW_LNS_set_column:
12750 case DW_LNS_fixed_advance_pc:
12751 case DW_LNS_set_isa:
12759 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12763 /* Write out the information about the files we use. */
12764 output_file_names ();
12765 ASM_OUTPUT_LABEL (asm_out_file, p2);
12767 if (separate_line_info)
12769 dw_line_info_table *table;
12772 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
12775 output_one_line_info_table (table);
12779 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
12781 output_one_line_info_table (cold_text_section_line_info);
12785 /* ??? Some Darwin linkers crash on a .debug_line section with no
12786 sequences. Further, merely a DW_LNE_end_sequence entry is not
12787 sufficient -- the address column must also be initialized.
12788 Make sure to output at least one set_address/end_sequence pair,
12789 choosing .text since that section is always present. */
12790 if (text_section_line_info->in_use || !saw_one)
12791 output_one_line_info_table (text_section_line_info);
12793 /* Output the marker for the end of the line number info. */
12794 ASM_OUTPUT_LABEL (asm_out_file, l2);
12797 /* Given a pointer to a tree node for some base type, return a pointer to
12798 a DIE that describes the given type.
12800 This routine must only be called for GCC type nodes that correspond to
12801 Dwarf base (fundamental) types. */
12804 base_type_die (tree type)
12806 dw_die_ref base_type_result;
12807 enum dwarf_type encoding;
12809 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12812 /* If this is a subtype that should not be emitted as a subrange type,
12813 use the base type. See subrange_type_for_debug_p. */
12814 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12815 type = TREE_TYPE (type);
12817 switch (TREE_CODE (type))
12820 if ((dwarf_version >= 4 || !dwarf_strict)
12821 && TYPE_NAME (type)
12822 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12823 && DECL_IS_BUILTIN (TYPE_NAME (type))
12824 && DECL_NAME (TYPE_NAME (type)))
12826 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12827 if (strcmp (name, "char16_t") == 0
12828 || strcmp (name, "char32_t") == 0)
12830 encoding = DW_ATE_UTF;
12834 if (TYPE_STRING_FLAG (type))
12836 if (TYPE_UNSIGNED (type))
12837 encoding = DW_ATE_unsigned_char;
12839 encoding = DW_ATE_signed_char;
12841 else if (TYPE_UNSIGNED (type))
12842 encoding = DW_ATE_unsigned;
12844 encoding = DW_ATE_signed;
12848 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12850 if (dwarf_version >= 3 || !dwarf_strict)
12851 encoding = DW_ATE_decimal_float;
12853 encoding = DW_ATE_lo_user;
12856 encoding = DW_ATE_float;
12859 case FIXED_POINT_TYPE:
12860 if (!(dwarf_version >= 3 || !dwarf_strict))
12861 encoding = DW_ATE_lo_user;
12862 else if (TYPE_UNSIGNED (type))
12863 encoding = DW_ATE_unsigned_fixed;
12865 encoding = DW_ATE_signed_fixed;
12868 /* Dwarf2 doesn't know anything about complex ints, so use
12869 a user defined type for it. */
12871 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12872 encoding = DW_ATE_complex_float;
12874 encoding = DW_ATE_lo_user;
12878 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12879 encoding = DW_ATE_boolean;
12883 /* No other TREE_CODEs are Dwarf fundamental types. */
12884 gcc_unreachable ();
12887 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12889 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12890 int_size_in_bytes (type));
12891 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12893 return base_type_result;
12896 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12897 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12900 is_base_type (tree type)
12902 switch (TREE_CODE (type))
12908 case FIXED_POINT_TYPE:
12916 case QUAL_UNION_TYPE:
12917 case ENUMERAL_TYPE:
12918 case FUNCTION_TYPE:
12921 case REFERENCE_TYPE:
12929 gcc_unreachable ();
12935 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12936 node, return the size in bits for the type if it is a constant, or else
12937 return the alignment for the type if the type's size is not constant, or
12938 else return BITS_PER_WORD if the type actually turns out to be an
12939 ERROR_MARK node. */
12941 static inline unsigned HOST_WIDE_INT
12942 simple_type_size_in_bits (const_tree type)
12944 if (TREE_CODE (type) == ERROR_MARK)
12945 return BITS_PER_WORD;
12946 else if (TYPE_SIZE (type) == NULL_TREE)
12948 else if (host_integerp (TYPE_SIZE (type), 1))
12949 return tree_low_cst (TYPE_SIZE (type), 1);
12951 return TYPE_ALIGN (type);
12954 /* Similarly, but return a double_int instead of UHWI. */
12956 static inline double_int
12957 double_int_type_size_in_bits (const_tree type)
12959 if (TREE_CODE (type) == ERROR_MARK)
12960 return uhwi_to_double_int (BITS_PER_WORD);
12961 else if (TYPE_SIZE (type) == NULL_TREE)
12962 return double_int_zero;
12963 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12964 return tree_to_double_int (TYPE_SIZE (type));
12966 return uhwi_to_double_int (TYPE_ALIGN (type));
12969 /* Given a pointer to a tree node for a subrange type, return a pointer
12970 to a DIE that describes the given type. */
12973 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12975 dw_die_ref subrange_die;
12976 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12978 if (context_die == NULL)
12979 context_die = comp_unit_die ();
12981 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12983 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12985 /* The size of the subrange type and its base type do not match,
12986 so we need to generate a size attribute for the subrange type. */
12987 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12991 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12993 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12995 return subrange_die;
12998 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12999 entry that chains various modifiers in front of the given type. */
13002 modified_type_die (tree type, int is_const_type, int is_volatile_type,
13003 dw_die_ref context_die)
13005 enum tree_code code = TREE_CODE (type);
13006 dw_die_ref mod_type_die;
13007 dw_die_ref sub_die = NULL;
13008 tree item_type = NULL;
13009 tree qualified_type;
13010 tree name, low, high;
13012 if (code == ERROR_MARK)
13015 /* See if we already have the appropriately qualified variant of
13018 = get_qualified_type (type,
13019 ((is_const_type ? TYPE_QUAL_CONST : 0)
13020 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
13022 if (qualified_type == sizetype
13023 && TYPE_NAME (qualified_type)
13024 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
13026 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
13028 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
13029 && TYPE_PRECISION (t)
13030 == TYPE_PRECISION (qualified_type)
13031 && TYPE_UNSIGNED (t)
13032 == TYPE_UNSIGNED (qualified_type));
13033 qualified_type = t;
13036 /* If we do, then we can just use its DIE, if it exists. */
13037 if (qualified_type)
13039 mod_type_die = lookup_type_die (qualified_type);
13041 return mod_type_die;
13044 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
13046 /* Handle C typedef types. */
13047 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
13048 && !DECL_ARTIFICIAL (name))
13050 tree dtype = TREE_TYPE (name);
13052 if (qualified_type == dtype)
13054 /* For a named type, use the typedef. */
13055 gen_type_die (qualified_type, context_die);
13056 return lookup_type_die (qualified_type);
13058 else if (is_const_type < TYPE_READONLY (dtype)
13059 || is_volatile_type < TYPE_VOLATILE (dtype)
13060 || (is_const_type <= TYPE_READONLY (dtype)
13061 && is_volatile_type <= TYPE_VOLATILE (dtype)
13062 && DECL_ORIGINAL_TYPE (name) != type))
13063 /* cv-unqualified version of named type. Just use the unnamed
13064 type to which it refers. */
13065 return modified_type_die (DECL_ORIGINAL_TYPE (name),
13066 is_const_type, is_volatile_type,
13068 /* Else cv-qualified version of named type; fall through. */
13072 /* If both is_const_type and is_volatile_type, prefer the path
13073 which leads to a qualified type. */
13074 && (!is_volatile_type
13075 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
13076 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
13078 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
13079 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
13081 else if (is_volatile_type)
13083 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
13084 sub_die = modified_type_die (type, is_const_type, 0, context_die);
13086 else if (code == POINTER_TYPE)
13088 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
13089 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13090 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13091 item_type = TREE_TYPE (type);
13092 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13093 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13094 TYPE_ADDR_SPACE (item_type));
13096 else if (code == REFERENCE_TYPE)
13098 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
13099 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
13102 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
13103 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13104 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13105 item_type = TREE_TYPE (type);
13106 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13107 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13108 TYPE_ADDR_SPACE (item_type));
13110 else if (code == INTEGER_TYPE
13111 && TREE_TYPE (type) != NULL_TREE
13112 && subrange_type_for_debug_p (type, &low, &high))
13114 mod_type_die = subrange_type_die (type, low, high, context_die);
13115 item_type = TREE_TYPE (type);
13117 else if (is_base_type (type))
13118 mod_type_die = base_type_die (type);
13121 gen_type_die (type, context_die);
13123 /* We have to get the type_main_variant here (and pass that to the
13124 `lookup_type_die' routine) because the ..._TYPE node we have
13125 might simply be a *copy* of some original type node (where the
13126 copy was created to help us keep track of typedef names) and
13127 that copy might have a different TYPE_UID from the original
13129 if (TREE_CODE (type) != VECTOR_TYPE)
13130 return lookup_type_die (type_main_variant (type));
13132 /* Vectors have the debugging information in the type,
13133 not the main variant. */
13134 return lookup_type_die (type);
13137 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
13138 don't output a DW_TAG_typedef, since there isn't one in the
13139 user's program; just attach a DW_AT_name to the type.
13140 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
13141 if the base type already has the same name. */
13143 && ((TREE_CODE (name) != TYPE_DECL
13144 && (qualified_type == TYPE_MAIN_VARIANT (type)
13145 || (!is_const_type && !is_volatile_type)))
13146 || (TREE_CODE (name) == TYPE_DECL
13147 && TREE_TYPE (name) == qualified_type
13148 && DECL_NAME (name))))
13150 if (TREE_CODE (name) == TYPE_DECL)
13151 /* Could just call add_name_and_src_coords_attributes here,
13152 but since this is a builtin type it doesn't have any
13153 useful source coordinates anyway. */
13154 name = DECL_NAME (name);
13155 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
13156 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
13158 /* This probably indicates a bug. */
13159 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
13160 add_name_attribute (mod_type_die, "__unknown__");
13162 if (qualified_type)
13163 equate_type_number_to_die (qualified_type, mod_type_die);
13166 /* We must do this after the equate_type_number_to_die call, in case
13167 this is a recursive type. This ensures that the modified_type_die
13168 recursion will terminate even if the type is recursive. Recursive
13169 types are possible in Ada. */
13170 sub_die = modified_type_die (item_type,
13171 TYPE_READONLY (item_type),
13172 TYPE_VOLATILE (item_type),
13175 if (sub_die != NULL)
13176 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
13178 return mod_type_die;
13181 /* Generate DIEs for the generic parameters of T.
13182 T must be either a generic type or a generic function.
13183 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13186 gen_generic_params_dies (tree t)
13190 dw_die_ref die = NULL;
13192 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13196 die = lookup_type_die (t);
13197 else if (DECL_P (t))
13198 die = lookup_decl_die (t);
13202 parms = lang_hooks.get_innermost_generic_parms (t);
13204 /* T has no generic parameter. It means T is neither a generic type
13205 or function. End of story. */
13208 parms_num = TREE_VEC_LENGTH (parms);
13209 args = lang_hooks.get_innermost_generic_args (t);
13210 for (i = 0; i < parms_num; i++)
13212 tree parm, arg, arg_pack_elems;
13214 parm = TREE_VEC_ELT (parms, i);
13215 arg = TREE_VEC_ELT (args, i);
13216 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13217 gcc_assert (parm && TREE_VALUE (parm) && arg);
13219 if (parm && TREE_VALUE (parm) && arg)
13221 /* If PARM represents a template parameter pack,
13222 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13223 by DW_TAG_template_*_parameter DIEs for the argument
13224 pack elements of ARG. Note that ARG would then be
13225 an argument pack. */
13226 if (arg_pack_elems)
13227 template_parameter_pack_die (TREE_VALUE (parm),
13231 generic_parameter_die (TREE_VALUE (parm), arg,
13232 true /* Emit DW_AT_name */, die);
13237 /* Create and return a DIE for PARM which should be
13238 the representation of a generic type parameter.
13239 For instance, in the C++ front end, PARM would be a template parameter.
13240 ARG is the argument to PARM.
13241 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13243 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13244 as a child node. */
13247 generic_parameter_die (tree parm, tree arg,
13249 dw_die_ref parent_die)
13251 dw_die_ref tmpl_die = NULL;
13252 const char *name = NULL;
13254 if (!parm || !DECL_NAME (parm) || !arg)
13257 /* We support non-type generic parameters and arguments,
13258 type generic parameters and arguments, as well as
13259 generic generic parameters (a.k.a. template template parameters in C++)
13261 if (TREE_CODE (parm) == PARM_DECL)
13262 /* PARM is a nontype generic parameter */
13263 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13264 else if (TREE_CODE (parm) == TYPE_DECL)
13265 /* PARM is a type generic parameter. */
13266 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13267 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13268 /* PARM is a generic generic parameter.
13269 Its DIE is a GNU extension. It shall have a
13270 DW_AT_name attribute to represent the name of the template template
13271 parameter, and a DW_AT_GNU_template_name attribute to represent the
13272 name of the template template argument. */
13273 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13276 gcc_unreachable ();
13282 /* If PARM is a generic parameter pack, it means we are
13283 emitting debug info for a template argument pack element.
13284 In other terms, ARG is a template argument pack element.
13285 In that case, we don't emit any DW_AT_name attribute for
13289 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13291 add_AT_string (tmpl_die, DW_AT_name, name);
13294 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13296 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13297 TMPL_DIE should have a child DW_AT_type attribute that is set
13298 to the type of the argument to PARM, which is ARG.
13299 If PARM is a type generic parameter, TMPL_DIE should have a
13300 child DW_AT_type that is set to ARG. */
13301 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13302 add_type_attribute (tmpl_die, tmpl_type, 0,
13303 TREE_THIS_VOLATILE (tmpl_type),
13308 /* So TMPL_DIE is a DIE representing a
13309 a generic generic template parameter, a.k.a template template
13310 parameter in C++ and arg is a template. */
13312 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13313 to the name of the argument. */
13314 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13316 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13319 if (TREE_CODE (parm) == PARM_DECL)
13320 /* So PARM is a non-type generic parameter.
13321 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13322 attribute of TMPL_DIE which value represents the value
13324 We must be careful here:
13325 The value of ARG might reference some function decls.
13326 We might currently be emitting debug info for a generic
13327 type and types are emitted before function decls, we don't
13328 know if the function decls referenced by ARG will actually be
13329 emitted after cgraph computations.
13330 So must defer the generation of the DW_AT_const_value to
13331 after cgraph is ready. */
13332 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13338 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13339 PARM_PACK must be a template parameter pack. The returned DIE
13340 will be child DIE of PARENT_DIE. */
13343 template_parameter_pack_die (tree parm_pack,
13344 tree parm_pack_args,
13345 dw_die_ref parent_die)
13350 gcc_assert (parent_die && parm_pack);
13352 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13353 add_name_and_src_coords_attributes (die, parm_pack);
13354 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13355 generic_parameter_die (parm_pack,
13356 TREE_VEC_ELT (parm_pack_args, j),
13357 false /* Don't emit DW_AT_name */,
13362 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13363 an enumerated type. */
13366 type_is_enum (const_tree type)
13368 return TREE_CODE (type) == ENUMERAL_TYPE;
13371 /* Return the DBX register number described by a given RTL node. */
13373 static unsigned int
13374 dbx_reg_number (const_rtx rtl)
13376 unsigned regno = REGNO (rtl);
13378 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13380 #ifdef LEAF_REG_REMAP
13381 if (current_function_uses_only_leaf_regs)
13383 int leaf_reg = LEAF_REG_REMAP (regno);
13384 if (leaf_reg != -1)
13385 regno = (unsigned) leaf_reg;
13389 return DBX_REGISTER_NUMBER (regno);
13392 /* Optionally add a DW_OP_piece term to a location description expression.
13393 DW_OP_piece is only added if the location description expression already
13394 doesn't end with DW_OP_piece. */
13397 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13399 dw_loc_descr_ref loc;
13401 if (*list_head != NULL)
13403 /* Find the end of the chain. */
13404 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13407 if (loc->dw_loc_opc != DW_OP_piece)
13408 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13412 /* Return a location descriptor that designates a machine register or
13413 zero if there is none. */
13415 static dw_loc_descr_ref
13416 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13420 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13423 /* We only use "frame base" when we're sure we're talking about the
13424 post-prologue local stack frame. We do this by *not* running
13425 register elimination until this point, and recognizing the special
13426 argument pointer and soft frame pointer rtx's.
13427 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13428 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13429 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13431 dw_loc_descr_ref result = NULL;
13433 if (dwarf_version >= 4 || !dwarf_strict)
13435 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
13438 add_loc_descr (&result,
13439 new_loc_descr (DW_OP_stack_value, 0, 0));
13444 regs = targetm.dwarf_register_span (rtl);
13446 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13447 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13449 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13452 /* Return a location descriptor that designates a machine register for
13453 a given hard register number. */
13455 static dw_loc_descr_ref
13456 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13458 dw_loc_descr_ref reg_loc_descr;
13462 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13464 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13466 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13467 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13469 return reg_loc_descr;
13472 /* Given an RTL of a register, return a location descriptor that
13473 designates a value that spans more than one register. */
13475 static dw_loc_descr_ref
13476 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13477 enum var_init_status initialized)
13479 int nregs, size, i;
13481 dw_loc_descr_ref loc_result = NULL;
13484 #ifdef LEAF_REG_REMAP
13485 if (current_function_uses_only_leaf_regs)
13487 int leaf_reg = LEAF_REG_REMAP (reg);
13488 if (leaf_reg != -1)
13489 reg = (unsigned) leaf_reg;
13492 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13493 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13495 /* Simple, contiguous registers. */
13496 if (regs == NULL_RTX)
13498 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13503 dw_loc_descr_ref t;
13505 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13506 VAR_INIT_STATUS_INITIALIZED);
13507 add_loc_descr (&loc_result, t);
13508 add_loc_descr_op_piece (&loc_result, size);
13514 /* Now onto stupid register sets in non contiguous locations. */
13516 gcc_assert (GET_CODE (regs) == PARALLEL);
13518 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13521 for (i = 0; i < XVECLEN (regs, 0); ++i)
13523 dw_loc_descr_ref t;
13525 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13526 VAR_INIT_STATUS_INITIALIZED);
13527 add_loc_descr (&loc_result, t);
13528 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13529 add_loc_descr_op_piece (&loc_result, size);
13532 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13533 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13537 /* Return a location descriptor that designates a constant. */
13539 static dw_loc_descr_ref
13540 int_loc_descriptor (HOST_WIDE_INT i)
13542 enum dwarf_location_atom op;
13544 /* Pick the smallest representation of a constant, rather than just
13545 defaulting to the LEB encoding. */
13549 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13550 else if (i <= 0xff)
13551 op = DW_OP_const1u;
13552 else if (i <= 0xffff)
13553 op = DW_OP_const2u;
13554 else if (HOST_BITS_PER_WIDE_INT == 32
13555 || i <= 0xffffffff)
13556 op = DW_OP_const4u;
13563 op = DW_OP_const1s;
13564 else if (i >= -0x8000)
13565 op = DW_OP_const2s;
13566 else if (HOST_BITS_PER_WIDE_INT == 32
13567 || i >= -0x80000000)
13568 op = DW_OP_const4s;
13573 return new_loc_descr (op, i, 0);
13576 /* Return loc description representing "address" of integer value.
13577 This can appear only as toplevel expression. */
13579 static dw_loc_descr_ref
13580 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13583 dw_loc_descr_ref loc_result = NULL;
13585 if (!(dwarf_version >= 4 || !dwarf_strict))
13592 else if (i <= 0xff)
13594 else if (i <= 0xffff)
13596 else if (HOST_BITS_PER_WIDE_INT == 32
13597 || i <= 0xffffffff)
13600 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13606 else if (i >= -0x8000)
13608 else if (HOST_BITS_PER_WIDE_INT == 32
13609 || i >= -0x80000000)
13612 litsize = 1 + size_of_sleb128 (i);
13614 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13615 is more compact. For DW_OP_stack_value we need:
13616 litsize + 1 (DW_OP_stack_value)
13617 and for DW_OP_implicit_value:
13618 1 (DW_OP_implicit_value) + 1 (length) + size. */
13619 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13621 loc_result = int_loc_descriptor (i);
13622 add_loc_descr (&loc_result,
13623 new_loc_descr (DW_OP_stack_value, 0, 0));
13627 loc_result = new_loc_descr (DW_OP_implicit_value,
13629 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13630 loc_result->dw_loc_oprnd2.v.val_int = i;
13634 /* Return a location descriptor that designates a base+offset location. */
13636 static dw_loc_descr_ref
13637 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13638 enum var_init_status initialized)
13640 unsigned int regno;
13641 dw_loc_descr_ref result;
13642 dw_fde_ref fde = current_fde ();
13644 /* We only use "frame base" when we're sure we're talking about the
13645 post-prologue local stack frame. We do this by *not* running
13646 register elimination until this point, and recognizing the special
13647 argument pointer and soft frame pointer rtx's. */
13648 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13650 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13654 if (GET_CODE (elim) == PLUS)
13656 offset += INTVAL (XEXP (elim, 1));
13657 elim = XEXP (elim, 0);
13659 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13660 && (elim == hard_frame_pointer_rtx
13661 || elim == stack_pointer_rtx))
13662 || elim == (frame_pointer_needed
13663 ? hard_frame_pointer_rtx
13664 : stack_pointer_rtx));
13666 /* If drap register is used to align stack, use frame
13667 pointer + offset to access stack variables. If stack
13668 is aligned without drap, use stack pointer + offset to
13669 access stack variables. */
13670 if (crtl->stack_realign_tried
13671 && reg == frame_pointer_rtx)
13674 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13675 ? HARD_FRAME_POINTER_REGNUM
13677 return new_reg_loc_descr (base_reg, offset);
13680 gcc_assert (frame_pointer_fb_offset_valid);
13681 offset += frame_pointer_fb_offset;
13682 return new_loc_descr (DW_OP_fbreg, offset, 0);
13687 && (fde->drap_reg == REGNO (reg)
13688 || fde->vdrap_reg == REGNO (reg)))
13690 /* Use cfa+offset to represent the location of arguments passed
13691 on the stack when drap is used to align stack.
13692 Only do this when not optimizing, for optimized code var-tracking
13693 is supposed to track where the arguments live and the register
13694 used as vdrap or drap in some spot might be used for something
13695 else in other part of the routine. */
13696 return new_loc_descr (DW_OP_fbreg, offset, 0);
13699 regno = dbx_reg_number (reg);
13701 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13704 result = new_loc_descr (DW_OP_bregx, regno, offset);
13706 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13707 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13712 /* Return true if this RTL expression describes a base+offset calculation. */
13715 is_based_loc (const_rtx rtl)
13717 return (GET_CODE (rtl) == PLUS
13718 && ((REG_P (XEXP (rtl, 0))
13719 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13720 && CONST_INT_P (XEXP (rtl, 1)))));
13723 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13726 static dw_loc_descr_ref
13727 tls_mem_loc_descriptor (rtx mem)
13730 dw_loc_descr_ref loc_result;
13732 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13735 base = get_base_address (MEM_EXPR (mem));
13737 || TREE_CODE (base) != VAR_DECL
13738 || !DECL_THREAD_LOCAL_P (base))
13741 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13742 if (loc_result == NULL)
13745 if (INTVAL (MEM_OFFSET (mem)))
13746 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13751 /* Output debug info about reason why we failed to expand expression as dwarf
13755 expansion_failed (tree expr, rtx rtl, char const *reason)
13757 if (dump_file && (dump_flags & TDF_DETAILS))
13759 fprintf (dump_file, "Failed to expand as dwarf: ");
13761 print_generic_expr (dump_file, expr, dump_flags);
13764 fprintf (dump_file, "\n");
13765 print_rtl (dump_file, rtl);
13767 fprintf (dump_file, "\nReason: %s\n", reason);
13771 /* Helper function for const_ok_for_output, called either directly
13772 or via for_each_rtx. */
13775 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13779 if (GET_CODE (rtl) == UNSPEC)
13781 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13782 we can't express it in the debug info. */
13783 #ifdef ENABLE_CHECKING
13784 /* Don't complain about TLS UNSPECs, those are just too hard to
13786 if (XVECLEN (rtl, 0) != 1
13787 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13788 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13789 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13790 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13791 inform (current_function_decl
13792 ? DECL_SOURCE_LOCATION (current_function_decl)
13793 : UNKNOWN_LOCATION,
13794 #if NUM_UNSPEC_VALUES > 0
13795 "non-delegitimized UNSPEC %s (%d) found in variable location",
13796 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
13797 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
13800 "non-delegitimized UNSPEC %d found in variable location",
13804 expansion_failed (NULL_TREE, rtl,
13805 "UNSPEC hasn't been delegitimized.\n");
13809 if (GET_CODE (rtl) != SYMBOL_REF)
13812 if (CONSTANT_POOL_ADDRESS_P (rtl))
13815 get_pool_constant_mark (rtl, &marked);
13816 /* If all references to this pool constant were optimized away,
13817 it was not output and thus we can't represent it. */
13820 expansion_failed (NULL_TREE, rtl,
13821 "Constant was removed from constant pool.\n");
13826 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13829 /* Avoid references to external symbols in debug info, on several targets
13830 the linker might even refuse to link when linking a shared library,
13831 and in many other cases the relocations for .debug_info/.debug_loc are
13832 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13833 to be defined within the same shared library or executable are fine. */
13834 if (SYMBOL_REF_EXTERNAL_P (rtl))
13836 tree decl = SYMBOL_REF_DECL (rtl);
13838 if (decl == NULL || !targetm.binds_local_p (decl))
13840 expansion_failed (NULL_TREE, rtl,
13841 "Symbol not defined in current TU.\n");
13849 /* Return true if constant RTL can be emitted in DW_OP_addr or
13850 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13851 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13854 const_ok_for_output (rtx rtl)
13856 if (GET_CODE (rtl) == SYMBOL_REF)
13857 return const_ok_for_output_1 (&rtl, NULL) == 0;
13859 if (GET_CODE (rtl) == CONST)
13860 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13865 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13866 if possible, NULL otherwise. */
13869 base_type_for_mode (enum machine_mode mode, bool unsignedp)
13871 dw_die_ref type_die;
13872 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
13876 switch (TREE_CODE (type))
13884 type_die = lookup_type_die (type);
13886 type_die = modified_type_die (type, false, false, comp_unit_die ());
13887 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
13892 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
13893 type matching MODE, or, if MODE is narrower than or as wide as
13894 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
13897 static dw_loc_descr_ref
13898 convert_descriptor_to_mode (enum machine_mode mode, dw_loc_descr_ref op)
13900 enum machine_mode outer_mode = mode;
13901 dw_die_ref type_die;
13902 dw_loc_descr_ref cvt;
13904 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
13906 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
13909 type_die = base_type_for_mode (outer_mode, 1);
13910 if (type_die == NULL)
13912 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13913 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13914 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13915 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13916 add_loc_descr (&op, cvt);
13920 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13922 static dw_loc_descr_ref
13923 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
13924 dw_loc_descr_ref op1)
13926 dw_loc_descr_ref ret = op0;
13927 add_loc_descr (&ret, op1);
13928 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
13929 if (STORE_FLAG_VALUE != 1)
13931 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
13932 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
13937 /* Return location descriptor for signed comparison OP RTL. */
13939 static dw_loc_descr_ref
13940 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
13941 enum machine_mode mem_mode)
13943 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13944 dw_loc_descr_ref op0, op1;
13947 if (op_mode == VOIDmode)
13948 op_mode = GET_MODE (XEXP (rtl, 1));
13949 if (op_mode == VOIDmode)
13953 && (GET_MODE_CLASS (op_mode) != MODE_INT
13954 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
13957 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
13958 VAR_INIT_STATUS_INITIALIZED);
13959 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
13960 VAR_INIT_STATUS_INITIALIZED);
13962 if (op0 == NULL || op1 == NULL)
13965 if (GET_MODE_CLASS (op_mode) != MODE_INT
13966 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
13967 return compare_loc_descriptor (op, op0, op1);
13969 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
13971 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
13972 dw_loc_descr_ref cvt;
13974 if (type_die == NULL)
13976 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13977 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13978 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13979 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13980 add_loc_descr (&op0, cvt);
13981 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13982 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13983 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13984 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13985 add_loc_descr (&op1, cvt);
13986 return compare_loc_descriptor (op, op0, op1);
13989 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
13990 /* For eq/ne, if the operands are known to be zero-extended,
13991 there is no need to do the fancy shifting up. */
13992 if (op == DW_OP_eq || op == DW_OP_ne)
13994 dw_loc_descr_ref last0, last1;
13995 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
13997 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
13999 /* deref_size zero extends, and for constants we can check
14000 whether they are zero extended or not. */
14001 if (((last0->dw_loc_opc == DW_OP_deref_size
14002 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
14003 || (CONST_INT_P (XEXP (rtl, 0))
14004 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14005 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
14006 && ((last1->dw_loc_opc == DW_OP_deref_size
14007 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
14008 || (CONST_INT_P (XEXP (rtl, 1))
14009 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
14010 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
14011 return compare_loc_descriptor (op, op0, op1);
14013 add_loc_descr (&op0, int_loc_descriptor (shift));
14014 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14015 if (CONST_INT_P (XEXP (rtl, 1)))
14016 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14019 add_loc_descr (&op1, int_loc_descriptor (shift));
14020 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14022 return compare_loc_descriptor (op, op0, op1);
14025 /* Return location descriptor for unsigned comparison OP RTL. */
14027 static dw_loc_descr_ref
14028 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
14029 enum machine_mode mem_mode)
14031 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14032 dw_loc_descr_ref op0, op1;
14034 if (op_mode == VOIDmode)
14035 op_mode = GET_MODE (XEXP (rtl, 1));
14036 if (op_mode == VOIDmode)
14038 if (GET_MODE_CLASS (op_mode) != MODE_INT)
14041 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
14044 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
14045 VAR_INIT_STATUS_INITIALIZED);
14046 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
14047 VAR_INIT_STATUS_INITIALIZED);
14049 if (op0 == NULL || op1 == NULL)
14052 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14054 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14055 dw_loc_descr_ref last0, last1;
14056 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
14058 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
14060 if (CONST_INT_P (XEXP (rtl, 0)))
14061 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14062 /* deref_size zero extends, so no need to mask it again. */
14063 else if (last0->dw_loc_opc != DW_OP_deref_size
14064 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
14066 add_loc_descr (&op0, int_loc_descriptor (mask));
14067 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14069 if (CONST_INT_P (XEXP (rtl, 1)))
14070 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14071 /* deref_size zero extends, so no need to mask it again. */
14072 else if (last1->dw_loc_opc != DW_OP_deref_size
14073 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
14075 add_loc_descr (&op1, int_loc_descriptor (mask));
14076 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14079 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
14081 HOST_WIDE_INT bias = 1;
14082 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14083 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14084 if (CONST_INT_P (XEXP (rtl, 1)))
14085 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14086 + INTVAL (XEXP (rtl, 1)));
14088 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14091 return compare_loc_descriptor (op, op0, op1);
14094 /* Return location descriptor for {U,S}{MIN,MAX}. */
14096 static dw_loc_descr_ref
14097 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
14098 enum machine_mode mem_mode)
14100 enum dwarf_location_atom op;
14101 dw_loc_descr_ref op0, op1, ret;
14102 dw_loc_descr_ref bra_node, drop_node;
14105 && (GET_MODE_CLASS (mode) != MODE_INT
14106 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
14109 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14110 VAR_INIT_STATUS_INITIALIZED);
14111 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14112 VAR_INIT_STATUS_INITIALIZED);
14114 if (op0 == NULL || op1 == NULL)
14117 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14118 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14119 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14120 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14122 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14124 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
14125 add_loc_descr (&op0, int_loc_descriptor (mask));
14126 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14127 add_loc_descr (&op1, int_loc_descriptor (mask));
14128 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14130 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
14132 HOST_WIDE_INT bias = 1;
14133 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14134 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14135 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14138 else if (GET_MODE_CLASS (mode) == MODE_INT
14139 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14141 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
14142 add_loc_descr (&op0, int_loc_descriptor (shift));
14143 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14144 add_loc_descr (&op1, int_loc_descriptor (shift));
14145 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14147 else if (GET_MODE_CLASS (mode) == MODE_INT
14148 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
14150 dw_die_ref type_die = base_type_for_mode (mode, 0);
14151 dw_loc_descr_ref cvt;
14152 if (type_die == NULL)
14154 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14155 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14156 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14157 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14158 add_loc_descr (&op0, cvt);
14159 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14160 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14161 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14162 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14163 add_loc_descr (&op1, cvt);
14166 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14171 add_loc_descr (&ret, op1);
14172 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
14173 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14174 add_loc_descr (&ret, bra_node);
14175 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14176 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14177 add_loc_descr (&ret, drop_node);
14178 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14179 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14180 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
14181 && GET_MODE_CLASS (mode) == MODE_INT
14182 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
14183 ret = convert_descriptor_to_mode (mode, ret);
14187 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14188 but after converting arguments to type_die, afterwards
14189 convert back to unsigned. */
14191 static dw_loc_descr_ref
14192 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
14193 enum machine_mode mode, enum machine_mode mem_mode)
14195 dw_loc_descr_ref cvt, op0, op1;
14197 if (type_die == NULL)
14199 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14200 VAR_INIT_STATUS_INITIALIZED);
14201 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14202 VAR_INIT_STATUS_INITIALIZED);
14203 if (op0 == NULL || op1 == NULL)
14205 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14206 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14207 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14208 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14209 add_loc_descr (&op0, cvt);
14210 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14211 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14212 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14213 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14214 add_loc_descr (&op1, cvt);
14215 add_loc_descr (&op0, op1);
14216 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
14217 return convert_descriptor_to_mode (mode, op0);
14220 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14221 const0 is DW_OP_lit0 or corresponding typed constant,
14222 const1 is DW_OP_lit1 or corresponding typed constant
14223 and constMSB is constant with just the MSB bit set
14225 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14226 L1: const0 DW_OP_swap
14227 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14228 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14233 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14234 L1: const0 DW_OP_swap
14235 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14236 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14241 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14242 L1: const1 DW_OP_swap
14243 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14244 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14248 static dw_loc_descr_ref
14249 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
14250 enum machine_mode mem_mode)
14252 dw_loc_descr_ref op0, ret, tmp;
14253 HOST_WIDE_INT valv;
14254 dw_loc_descr_ref l1jump, l1label;
14255 dw_loc_descr_ref l2jump, l2label;
14256 dw_loc_descr_ref l3jump, l3label;
14257 dw_loc_descr_ref l4jump, l4label;
14260 if (GET_MODE_CLASS (mode) != MODE_INT
14261 || GET_MODE (XEXP (rtl, 0)) != mode
14262 || (GET_CODE (rtl) == CLZ
14263 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
14266 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14267 VAR_INIT_STATUS_INITIALIZED);
14271 if (GET_CODE (rtl) == CLZ)
14273 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
14274 valv = GET_MODE_BITSIZE (mode);
14276 else if (GET_CODE (rtl) == FFS)
14278 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
14279 valv = GET_MODE_BITSIZE (mode);
14280 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
14281 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
14282 add_loc_descr (&ret, l1jump);
14283 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
14284 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
14285 VAR_INIT_STATUS_INITIALIZED);
14288 add_loc_descr (&ret, tmp);
14289 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
14290 add_loc_descr (&ret, l4jump);
14291 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
14292 ? const1_rtx : const0_rtx,
14294 VAR_INIT_STATUS_INITIALIZED);
14295 if (l1label == NULL)
14297 add_loc_descr (&ret, l1label);
14298 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14299 l2label = new_loc_descr (DW_OP_dup, 0, 0);
14300 add_loc_descr (&ret, l2label);
14301 if (GET_CODE (rtl) != CLZ)
14303 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
14304 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
14305 << (GET_MODE_BITSIZE (mode) - 1));
14307 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
14308 << (GET_MODE_BITSIZE (mode)
14309 - HOST_BITS_PER_WIDE_INT - 1), mode);
14310 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
14311 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
14312 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
14313 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
14315 tmp = mem_loc_descriptor (msb, mode, mem_mode,
14316 VAR_INIT_STATUS_INITIALIZED);
14319 add_loc_descr (&ret, tmp);
14320 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
14321 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
14322 add_loc_descr (&ret, l3jump);
14323 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
14324 VAR_INIT_STATUS_INITIALIZED);
14327 add_loc_descr (&ret, tmp);
14328 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
14329 ? DW_OP_shl : DW_OP_shr, 0, 0));
14330 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14331 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
14332 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14333 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
14334 add_loc_descr (&ret, l2jump);
14335 l3label = new_loc_descr (DW_OP_drop, 0, 0);
14336 add_loc_descr (&ret, l3label);
14337 l4label = new_loc_descr (DW_OP_nop, 0, 0);
14338 add_loc_descr (&ret, l4label);
14339 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14340 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
14341 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14342 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
14343 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14344 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
14345 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14346 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
14350 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14351 const1 is DW_OP_lit1 or corresponding typed constant):
14353 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14354 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14358 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14359 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14362 static dw_loc_descr_ref
14363 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
14364 enum machine_mode mem_mode)
14366 dw_loc_descr_ref op0, ret, tmp;
14367 dw_loc_descr_ref l1jump, l1label;
14368 dw_loc_descr_ref l2jump, l2label;
14370 if (GET_MODE_CLASS (mode) != MODE_INT
14371 || GET_MODE (XEXP (rtl, 0)) != mode)
14374 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14375 VAR_INIT_STATUS_INITIALIZED);
14379 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
14380 VAR_INIT_STATUS_INITIALIZED);
14383 add_loc_descr (&ret, tmp);
14384 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14385 l1label = new_loc_descr (DW_OP_dup, 0, 0);
14386 add_loc_descr (&ret, l1label);
14387 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
14388 add_loc_descr (&ret, l2jump);
14389 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
14390 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
14391 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
14392 VAR_INIT_STATUS_INITIALIZED);
14395 add_loc_descr (&ret, tmp);
14396 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
14397 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
14398 ? DW_OP_plus : DW_OP_xor, 0, 0));
14399 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14400 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
14401 VAR_INIT_STATUS_INITIALIZED);
14402 add_loc_descr (&ret, tmp);
14403 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14404 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
14405 add_loc_descr (&ret, l1jump);
14406 l2label = new_loc_descr (DW_OP_drop, 0, 0);
14407 add_loc_descr (&ret, l2label);
14408 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14409 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
14410 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14411 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
14415 /* BSWAP (constS is initial shift count, either 56 or 24):
14417 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14418 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14419 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14420 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14421 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14423 static dw_loc_descr_ref
14424 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
14425 enum machine_mode mem_mode)
14427 dw_loc_descr_ref op0, ret, tmp;
14428 dw_loc_descr_ref l1jump, l1label;
14429 dw_loc_descr_ref l2jump, l2label;
14431 if (GET_MODE_CLASS (mode) != MODE_INT
14432 || BITS_PER_UNIT != 8
14433 || (GET_MODE_BITSIZE (mode) != 32
14434 && GET_MODE_BITSIZE (mode) != 64))
14437 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14438 VAR_INIT_STATUS_INITIALIZED);
14443 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
14445 VAR_INIT_STATUS_INITIALIZED);
14448 add_loc_descr (&ret, tmp);
14449 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
14450 VAR_INIT_STATUS_INITIALIZED);
14453 add_loc_descr (&ret, tmp);
14454 l1label = new_loc_descr (DW_OP_pick, 2, 0);
14455 add_loc_descr (&ret, l1label);
14456 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
14458 VAR_INIT_STATUS_INITIALIZED);
14459 add_loc_descr (&ret, tmp);
14460 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
14461 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
14462 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14463 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
14464 VAR_INIT_STATUS_INITIALIZED);
14467 add_loc_descr (&ret, tmp);
14468 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
14469 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
14470 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
14471 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
14472 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14473 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
14474 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
14475 VAR_INIT_STATUS_INITIALIZED);
14476 add_loc_descr (&ret, tmp);
14477 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
14478 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
14479 add_loc_descr (&ret, l2jump);
14480 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
14481 VAR_INIT_STATUS_INITIALIZED);
14482 add_loc_descr (&ret, tmp);
14483 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
14484 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14485 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
14486 add_loc_descr (&ret, l1jump);
14487 l2label = new_loc_descr (DW_OP_drop, 0, 0);
14488 add_loc_descr (&ret, l2label);
14489 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14490 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
14491 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14492 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
14493 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14494 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
14498 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14499 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14500 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14501 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14503 ROTATERT is similar:
14504 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14505 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14506 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14508 static dw_loc_descr_ref
14509 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
14510 enum machine_mode mem_mode)
14512 rtx rtlop1 = XEXP (rtl, 1);
14513 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
14516 if (GET_MODE_CLASS (mode) != MODE_INT)
14519 if (GET_MODE (rtlop1) != VOIDmode
14520 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
14521 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
14522 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14523 VAR_INIT_STATUS_INITIALIZED);
14524 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
14525 VAR_INIT_STATUS_INITIALIZED);
14526 if (op0 == NULL || op1 == NULL)
14528 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14529 for (i = 0; i < 2; i++)
14531 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
14532 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
14534 VAR_INIT_STATUS_INITIALIZED);
14535 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
14536 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
14538 : HOST_BITS_PER_WIDE_INT == 64
14539 ? DW_OP_const8u : DW_OP_constu,
14540 GET_MODE_MASK (mode), 0);
14543 if (mask[i] == NULL)
14545 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
14548 add_loc_descr (&ret, op1);
14549 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
14550 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
14551 if (GET_CODE (rtl) == ROTATERT)
14553 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14554 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
14555 GET_MODE_BITSIZE (mode), 0));
14557 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
14558 if (mask[0] != NULL)
14559 add_loc_descr (&ret, mask[0]);
14560 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
14561 if (mask[1] != NULL)
14563 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14564 add_loc_descr (&ret, mask[1]);
14565 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14567 if (GET_CODE (rtl) == ROTATE)
14569 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14570 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
14571 GET_MODE_BITSIZE (mode), 0));
14573 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14574 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
14578 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
14579 for DEBUG_PARAMETER_REF RTL. */
14581 static dw_loc_descr_ref
14582 parameter_ref_descriptor (rtx rtl)
14584 dw_loc_descr_ref ret;
14589 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
14590 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
14591 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
14594 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14595 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14596 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14600 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14601 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
14606 /* The following routine converts the RTL for a variable or parameter
14607 (resident in memory) into an equivalent Dwarf representation of a
14608 mechanism for getting the address of that same variable onto the top of a
14609 hypothetical "address evaluation" stack.
14611 When creating memory location descriptors, we are effectively transforming
14612 the RTL for a memory-resident object into its Dwarf postfix expression
14613 equivalent. This routine recursively descends an RTL tree, turning
14614 it into Dwarf postfix code as it goes.
14616 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14618 MEM_MODE is the mode of the memory reference, needed to handle some
14619 autoincrement addressing modes.
14621 Return 0 if we can't represent the location. */
14623 static dw_loc_descr_ref
14624 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
14625 enum machine_mode mem_mode,
14626 enum var_init_status initialized)
14628 dw_loc_descr_ref mem_loc_result = NULL;
14629 enum dwarf_location_atom op;
14630 dw_loc_descr_ref op0, op1;
14632 if (mode == VOIDmode)
14633 mode = GET_MODE (rtl);
14635 /* Note that for a dynamically sized array, the location we will generate a
14636 description of here will be the lowest numbered location which is
14637 actually within the array. That's *not* necessarily the same as the
14638 zeroth element of the array. */
14640 rtl = targetm.delegitimize_address (rtl);
14642 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
14645 switch (GET_CODE (rtl))
14650 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
14653 /* The case of a subreg may arise when we have a local (register)
14654 variable or a formal (register) parameter which doesn't quite fill
14655 up an entire register. For now, just assume that it is
14656 legitimate to make the Dwarf info refer to the whole register which
14657 contains the given subreg. */
14658 if (!subreg_lowpart_p (rtl))
14660 if (GET_MODE_CLASS (mode) == MODE_INT
14661 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
14662 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14663 #ifdef POINTERS_EXTEND_UNSIGNED
14664 || (mode == Pmode && mem_mode != VOIDmode)
14667 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
14669 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
14670 GET_MODE (SUBREG_REG (rtl)),
14671 mem_mode, initialized);
14676 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
14678 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
14679 && (GET_MODE_CLASS (mode) != MODE_INT
14680 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
14684 dw_die_ref type_die;
14685 dw_loc_descr_ref cvt;
14687 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
14688 GET_MODE (SUBREG_REG (rtl)),
14689 mem_mode, initialized);
14690 if (mem_loc_result == NULL)
14692 type_die = base_type_for_mode (mode,
14693 GET_MODE_CLASS (mode) == MODE_INT);
14694 if (type_die == NULL)
14696 mem_loc_result = NULL;
14699 if (GET_MODE_SIZE (mode)
14700 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
14701 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14703 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
14704 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14705 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14706 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14707 add_loc_descr (&mem_loc_result, cvt);
14712 if (GET_MODE_CLASS (mode) != MODE_INT
14713 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14714 #ifdef POINTERS_EXTEND_UNSIGNED
14715 && (mode != Pmode || mem_mode == VOIDmode)
14719 dw_die_ref type_die;
14723 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
14725 type_die = base_type_for_mode (mode,
14726 GET_MODE_CLASS (mode) == MODE_INT);
14727 if (type_die == NULL)
14729 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
14730 dbx_reg_number (rtl), 0);
14731 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
14732 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
14733 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
14736 /* Whenever a register number forms a part of the description of the
14737 method for calculating the (dynamic) address of a memory resident
14738 object, DWARF rules require the register number be referred to as
14739 a "base register". This distinction is not based in any way upon
14740 what category of register the hardware believes the given register
14741 belongs to. This is strictly DWARF terminology we're dealing with
14742 here. Note that in cases where the location of a memory-resident
14743 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14744 OP_CONST (0)) the actual DWARF location descriptor that we generate
14745 may just be OP_BASEREG (basereg). This may look deceptively like
14746 the object in question was allocated to a register (rather than in
14747 memory) so DWARF consumers need to be aware of the subtle
14748 distinction between OP_REG and OP_BASEREG. */
14749 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
14750 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
14751 else if (stack_realign_drap
14753 && crtl->args.internal_arg_pointer == rtl
14754 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
14756 /* If RTL is internal_arg_pointer, which has been optimized
14757 out, use DRAP instead. */
14758 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
14759 VAR_INIT_STATUS_INITIALIZED);
14765 gcc_assert (GET_MODE_CLASS (mode) == MODE_INT);
14766 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
14767 mem_mode, VAR_INIT_STATUS_INITIALIZED);
14770 else if (GET_CODE (rtl) == ZERO_EXTEND
14771 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14772 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14773 < HOST_BITS_PER_WIDE_INT
14774 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14775 to expand zero extend as two shifts instead of
14777 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
14779 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
14780 mem_loc_result = op0;
14781 add_loc_descr (&mem_loc_result,
14782 int_loc_descriptor (GET_MODE_MASK (imode)));
14783 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
14785 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
14787 int shift = DWARF2_ADDR_SIZE
14788 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14789 shift *= BITS_PER_UNIT;
14790 if (GET_CODE (rtl) == SIGN_EXTEND)
14794 mem_loc_result = op0;
14795 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
14796 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14797 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
14798 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14800 else if (!dwarf_strict)
14802 dw_die_ref type_die1, type_die2;
14803 dw_loc_descr_ref cvt;
14805 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
14806 GET_CODE (rtl) == ZERO_EXTEND);
14807 if (type_die1 == NULL)
14809 type_die2 = base_type_for_mode (mode, 1);
14810 if (type_die2 == NULL)
14812 mem_loc_result = op0;
14813 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14814 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14815 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
14816 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14817 add_loc_descr (&mem_loc_result, cvt);
14818 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14819 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14820 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
14821 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14822 add_loc_descr (&mem_loc_result, cvt);
14827 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
14828 get_address_mode (rtl), mode,
14829 VAR_INIT_STATUS_INITIALIZED);
14830 if (mem_loc_result == NULL)
14831 mem_loc_result = tls_mem_loc_descriptor (rtl);
14832 if (mem_loc_result != 0)
14834 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14835 || GET_MODE_CLASS (mode) != MODE_INT)
14837 dw_die_ref type_die;
14838 dw_loc_descr_ref deref;
14843 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
14844 if (type_die == NULL)
14846 deref = new_loc_descr (DW_OP_GNU_deref_type,
14847 GET_MODE_SIZE (mode), 0);
14848 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
14849 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
14850 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
14851 add_loc_descr (&mem_loc_result, deref);
14853 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
14854 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
14856 add_loc_descr (&mem_loc_result,
14857 new_loc_descr (DW_OP_deref_size,
14858 GET_MODE_SIZE (mode), 0));
14862 rtx new_rtl = avoid_constant_pool_reference (rtl);
14863 if (new_rtl != rtl)
14864 return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
14869 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
14872 /* Some ports can transform a symbol ref into a label ref, because
14873 the symbol ref is too far away and has to be dumped into a constant
14877 if (GET_MODE_CLASS (mode) != MODE_INT
14878 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14879 #ifdef POINTERS_EXTEND_UNSIGNED
14880 && (mode != Pmode || mem_mode == VOIDmode)
14884 if (GET_CODE (rtl) == SYMBOL_REF
14885 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
14887 dw_loc_descr_ref temp;
14889 /* If this is not defined, we have no way to emit the data. */
14890 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
14893 /* We used to emit DW_OP_addr here, but that's wrong, since
14894 DW_OP_addr should be relocated by the debug info consumer,
14895 while DW_OP_GNU_push_tls_address operand should not. */
14896 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
14897 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
14898 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
14899 temp->dw_loc_oprnd1.v.val_addr = rtl;
14900 temp->dtprel = true;
14902 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
14903 add_loc_descr (&mem_loc_result, temp);
14908 if (!const_ok_for_output (rtl))
14912 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14913 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14914 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14915 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14921 case DEBUG_IMPLICIT_PTR:
14922 expansion_failed (NULL_TREE, rtl,
14923 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14929 if (REG_P (ENTRY_VALUE_EXP (rtl)))
14931 if (GET_MODE_CLASS (mode) != MODE_INT
14932 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
14933 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
14934 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14937 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
14938 VAR_INIT_STATUS_INITIALIZED);
14940 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
14941 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
14943 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
14944 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14945 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
14949 gcc_unreachable ();
14952 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
14953 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
14954 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
14957 case DEBUG_PARAMETER_REF:
14958 mem_loc_result = parameter_ref_descriptor (rtl);
14962 /* Extract the PLUS expression nested inside and fall into
14963 PLUS code below. */
14964 rtl = XEXP (rtl, 1);
14969 /* Turn these into a PLUS expression and fall into the PLUS code
14971 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
14972 GEN_INT (GET_CODE (rtl) == PRE_INC
14973 ? GET_MODE_UNIT_SIZE (mem_mode)
14974 : -GET_MODE_UNIT_SIZE (mem_mode)));
14976 /* ... fall through ... */
14980 if (is_based_loc (rtl)
14981 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14982 && GET_MODE_CLASS (mode) == MODE_INT)
14983 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
14984 INTVAL (XEXP (rtl, 1)),
14985 VAR_INIT_STATUS_INITIALIZED);
14988 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14989 VAR_INIT_STATUS_INITIALIZED);
14990 if (mem_loc_result == 0)
14993 if (CONST_INT_P (XEXP (rtl, 1))
14994 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
14995 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
14998 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14999 VAR_INIT_STATUS_INITIALIZED);
15002 add_loc_descr (&mem_loc_result, op1);
15003 add_loc_descr (&mem_loc_result,
15004 new_loc_descr (DW_OP_plus, 0, 0));
15009 /* If a pseudo-reg is optimized away, it is possible for it to
15010 be replaced with a MEM containing a multiply or shift. */
15021 && GET_MODE_CLASS (mode) == MODE_INT
15022 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
15024 mem_loc_result = typed_binop (DW_OP_div, rtl,
15025 base_type_for_mode (mode, 0),
15049 if (GET_MODE_CLASS (mode) != MODE_INT)
15051 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15052 VAR_INIT_STATUS_INITIALIZED);
15054 rtx rtlop1 = XEXP (rtl, 1);
15055 if (GET_MODE (rtlop1) != VOIDmode
15056 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
15057 < GET_MODE_BITSIZE (mode))
15058 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
15059 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
15060 VAR_INIT_STATUS_INITIALIZED);
15063 if (op0 == 0 || op1 == 0)
15066 mem_loc_result = op0;
15067 add_loc_descr (&mem_loc_result, op1);
15068 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15084 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15085 VAR_INIT_STATUS_INITIALIZED);
15086 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15087 VAR_INIT_STATUS_INITIALIZED);
15089 if (op0 == 0 || op1 == 0)
15092 mem_loc_result = op0;
15093 add_loc_descr (&mem_loc_result, op1);
15094 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15098 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
15100 mem_loc_result = typed_binop (DW_OP_mod, rtl,
15101 base_type_for_mode (mode, 0),
15106 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15107 VAR_INIT_STATUS_INITIALIZED);
15108 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15109 VAR_INIT_STATUS_INITIALIZED);
15111 if (op0 == 0 || op1 == 0)
15114 mem_loc_result = op0;
15115 add_loc_descr (&mem_loc_result, op1);
15116 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
15117 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
15118 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
15119 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
15120 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
15124 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
15126 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
15131 mem_loc_result = typed_binop (DW_OP_div, rtl,
15132 base_type_for_mode (mode, 1),
15150 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15151 VAR_INIT_STATUS_INITIALIZED);
15156 mem_loc_result = op0;
15157 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15161 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
15162 #ifdef POINTERS_EXTEND_UNSIGNED
15164 && mem_mode != VOIDmode
15165 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
15169 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
15173 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
15174 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
15176 dw_die_ref type_die = base_type_for_mode (mode, 1);
15177 if (type_die == NULL)
15179 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
15181 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15182 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15183 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
15184 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
15185 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
15188 mem_loc_result->dw_loc_oprnd2.val_class
15189 = dw_val_class_const_double;
15190 mem_loc_result->dw_loc_oprnd2.v.val_double
15191 = shwi_to_double_int (INTVAL (rtl));
15199 dw_die_ref type_die;
15201 /* Note that a CONST_DOUBLE rtx could represent either an integer
15202 or a floating-point constant. A CONST_DOUBLE is used whenever
15203 the constant requires more than one word in order to be
15204 adequately represented. We output CONST_DOUBLEs as blocks. */
15205 if (mode == VOIDmode
15206 || (GET_MODE (rtl) == VOIDmode
15207 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
15209 type_die = base_type_for_mode (mode,
15210 GET_MODE_CLASS (mode) == MODE_INT);
15211 if (type_die == NULL)
15213 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
15214 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15215 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15216 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
15217 if (SCALAR_FLOAT_MODE_P (mode))
15219 unsigned int length = GET_MODE_SIZE (mode);
15220 unsigned char *array
15221 = (unsigned char*) ggc_alloc_atomic (length);
15223 insert_float (rtl, array);
15224 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15225 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
15226 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
15227 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15231 mem_loc_result->dw_loc_oprnd2.val_class
15232 = dw_val_class_const_double;
15233 mem_loc_result->dw_loc_oprnd2.v.val_double
15234 = rtx_to_double_int (rtl);
15240 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
15244 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
15248 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
15252 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
15256 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
15260 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
15264 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
15268 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
15272 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
15276 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
15281 if (GET_MODE_CLASS (mode) != MODE_INT)
15286 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
15291 if (CONST_INT_P (XEXP (rtl, 1))
15292 && CONST_INT_P (XEXP (rtl, 2))
15293 && ((unsigned) INTVAL (XEXP (rtl, 1))
15294 + (unsigned) INTVAL (XEXP (rtl, 2))
15295 <= GET_MODE_BITSIZE (mode))
15296 && GET_MODE_CLASS (mode) == MODE_INT
15297 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
15298 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
15301 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
15302 mem_mode, VAR_INIT_STATUS_INITIALIZED);
15305 if (GET_CODE (rtl) == SIGN_EXTRACT)
15309 mem_loc_result = op0;
15310 size = INTVAL (XEXP (rtl, 1));
15311 shift = INTVAL (XEXP (rtl, 2));
15312 if (BITS_BIG_ENDIAN)
15313 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
15315 if (shift + size != (int) DWARF2_ADDR_SIZE)
15317 add_loc_descr (&mem_loc_result,
15318 int_loc_descriptor (DWARF2_ADDR_SIZE
15320 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
15322 if (size != (int) DWARF2_ADDR_SIZE)
15324 add_loc_descr (&mem_loc_result,
15325 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
15326 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15333 dw_loc_descr_ref op2, bra_node, drop_node;
15334 op0 = mem_loc_descriptor (XEXP (rtl, 0),
15335 GET_MODE (XEXP (rtl, 0)) == VOIDmode
15336 ? word_mode : GET_MODE (XEXP (rtl, 0)),
15337 mem_mode, VAR_INIT_STATUS_INITIALIZED);
15338 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15339 VAR_INIT_STATUS_INITIALIZED);
15340 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
15341 VAR_INIT_STATUS_INITIALIZED);
15342 if (op0 == NULL || op1 == NULL || op2 == NULL)
15345 mem_loc_result = op1;
15346 add_loc_descr (&mem_loc_result, op2);
15347 add_loc_descr (&mem_loc_result, op0);
15348 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15349 add_loc_descr (&mem_loc_result, bra_node);
15350 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
15351 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
15352 add_loc_descr (&mem_loc_result, drop_node);
15353 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15354 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
15359 case FLOAT_TRUNCATE:
15361 case UNSIGNED_FLOAT:
15366 dw_die_ref type_die;
15367 dw_loc_descr_ref cvt;
15369 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
15370 mem_mode, VAR_INIT_STATUS_INITIALIZED);
15373 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
15374 && (GET_CODE (rtl) == FLOAT
15375 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
15376 <= DWARF2_ADDR_SIZE))
15378 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
15379 GET_CODE (rtl) == UNSIGNED_FLOAT);
15380 if (type_die == NULL)
15382 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
15383 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15384 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15385 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15386 add_loc_descr (&op0, cvt);
15388 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
15389 if (type_die == NULL)
15391 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
15392 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15393 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15394 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15395 add_loc_descr (&op0, cvt);
15396 if (GET_MODE_CLASS (mode) == MODE_INT
15397 && (GET_CODE (rtl) == FIX
15398 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
15400 op0 = convert_descriptor_to_mode (mode, op0);
15404 mem_loc_result = op0;
15411 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
15416 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
15420 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
15425 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
15430 /* In theory, we could implement the above. */
15431 /* DWARF cannot represent the unsigned compare operations
15456 case FRACT_CONVERT:
15457 case UNSIGNED_FRACT_CONVERT:
15459 case UNSIGNED_SAT_FRACT:
15465 case VEC_DUPLICATE:
15469 case STRICT_LOW_PART:
15473 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15474 can't express it in the debug info. This can happen e.g. with some
15479 resolve_one_addr (&rtl, NULL);
15483 #ifdef ENABLE_CHECKING
15484 print_rtl (stderr, rtl);
15485 gcc_unreachable ();
15491 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
15492 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15494 return mem_loc_result;
15497 /* Return a descriptor that describes the concatenation of two locations.
15498 This is typically a complex variable. */
15500 static dw_loc_descr_ref
15501 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
15503 dw_loc_descr_ref cc_loc_result = NULL;
15504 dw_loc_descr_ref x0_ref
15505 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
15506 dw_loc_descr_ref x1_ref
15507 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
15509 if (x0_ref == 0 || x1_ref == 0)
15512 cc_loc_result = x0_ref;
15513 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
15515 add_loc_descr (&cc_loc_result, x1_ref);
15516 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
15518 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
15519 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15521 return cc_loc_result;
15524 /* Return a descriptor that describes the concatenation of N
15527 static dw_loc_descr_ref
15528 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
15531 dw_loc_descr_ref cc_loc_result = NULL;
15532 unsigned int n = XVECLEN (concatn, 0);
15534 for (i = 0; i < n; ++i)
15536 dw_loc_descr_ref ref;
15537 rtx x = XVECEXP (concatn, 0, i);
15539 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
15543 add_loc_descr (&cc_loc_result, ref);
15544 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
15547 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
15548 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15550 return cc_loc_result;
15553 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
15554 for DEBUG_IMPLICIT_PTR RTL. */
15556 static dw_loc_descr_ref
15557 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
15559 dw_loc_descr_ref ret;
15564 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
15565 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
15566 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
15567 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
15568 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
15569 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
15572 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15573 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
15574 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
15578 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
15579 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
15584 /* Output a proper Dwarf location descriptor for a variable or parameter
15585 which is either allocated in a register or in a memory location. For a
15586 register, we just generate an OP_REG and the register number. For a
15587 memory location we provide a Dwarf postfix expression describing how to
15588 generate the (dynamic) address of the object onto the address stack.
15590 MODE is mode of the decl if this loc_descriptor is going to be used in
15591 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15592 allowed, VOIDmode otherwise.
15594 If we don't know how to describe it, return 0. */
15596 static dw_loc_descr_ref
15597 loc_descriptor (rtx rtl, enum machine_mode mode,
15598 enum var_init_status initialized)
15600 dw_loc_descr_ref loc_result = NULL;
15602 switch (GET_CODE (rtl))
15605 /* The case of a subreg may arise when we have a local (register)
15606 variable or a formal (register) parameter which doesn't quite fill
15607 up an entire register. For now, just assume that it is
15608 legitimate to make the Dwarf info refer to the whole register which
15609 contains the given subreg. */
15610 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
15611 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
15617 loc_result = reg_loc_descriptor (rtl, initialized);
15621 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
15622 GET_MODE (rtl), initialized);
15623 if (loc_result == NULL)
15624 loc_result = tls_mem_loc_descriptor (rtl);
15625 if (loc_result == NULL)
15627 rtx new_rtl = avoid_constant_pool_reference (rtl);
15628 if (new_rtl != rtl)
15629 loc_result = loc_descriptor (new_rtl, mode, initialized);
15634 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
15639 loc_result = concatn_loc_descriptor (rtl, initialized);
15644 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
15646 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
15647 if (GET_CODE (loc) == EXPR_LIST)
15648 loc = XEXP (loc, 0);
15649 loc_result = loc_descriptor (loc, mode, initialized);
15653 rtl = XEXP (rtl, 1);
15658 rtvec par_elems = XVEC (rtl, 0);
15659 int num_elem = GET_NUM_ELEM (par_elems);
15660 enum machine_mode mode;
15663 /* Create the first one, so we have something to add to. */
15664 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
15665 VOIDmode, initialized);
15666 if (loc_result == NULL)
15668 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
15669 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
15670 for (i = 1; i < num_elem; i++)
15672 dw_loc_descr_ref temp;
15674 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
15675 VOIDmode, initialized);
15678 add_loc_descr (&loc_result, temp);
15679 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
15680 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
15686 if (mode != VOIDmode && mode != BLKmode)
15687 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
15692 if (mode == VOIDmode)
15693 mode = GET_MODE (rtl);
15695 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
15697 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
15699 /* Note that a CONST_DOUBLE rtx could represent either an integer
15700 or a floating-point constant. A CONST_DOUBLE is used whenever
15701 the constant requires more than one word in order to be
15702 adequately represented. We output CONST_DOUBLEs as blocks. */
15703 loc_result = new_loc_descr (DW_OP_implicit_value,
15704 GET_MODE_SIZE (mode), 0);
15705 if (SCALAR_FLOAT_MODE_P (mode))
15707 unsigned int length = GET_MODE_SIZE (mode);
15708 unsigned char *array
15709 = (unsigned char*) ggc_alloc_atomic (length);
15711 insert_float (rtl, array);
15712 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15713 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
15714 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
15715 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15719 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
15720 loc_result->dw_loc_oprnd2.v.val_double
15721 = rtx_to_double_int (rtl);
15727 if (mode == VOIDmode)
15728 mode = GET_MODE (rtl);
15730 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
15732 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
15733 unsigned int length = CONST_VECTOR_NUNITS (rtl);
15734 unsigned char *array = (unsigned char *)
15735 ggc_alloc_atomic (length * elt_size);
15739 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
15740 switch (GET_MODE_CLASS (mode))
15742 case MODE_VECTOR_INT:
15743 for (i = 0, p = array; i < length; i++, p += elt_size)
15745 rtx elt = CONST_VECTOR_ELT (rtl, i);
15746 double_int val = rtx_to_double_int (elt);
15748 if (elt_size <= sizeof (HOST_WIDE_INT))
15749 insert_int (double_int_to_shwi (val), elt_size, p);
15752 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
15753 insert_double (val, p);
15758 case MODE_VECTOR_FLOAT:
15759 for (i = 0, p = array; i < length; i++, p += elt_size)
15761 rtx elt = CONST_VECTOR_ELT (rtl, i);
15762 insert_float (elt, p);
15767 gcc_unreachable ();
15770 loc_result = new_loc_descr (DW_OP_implicit_value,
15771 length * elt_size, 0);
15772 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15773 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
15774 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
15775 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15780 if (mode == VOIDmode
15781 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
15782 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
15783 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
15785 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
15790 if (!const_ok_for_output (rtl))
15793 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
15794 && (dwarf_version >= 4 || !dwarf_strict))
15796 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
15797 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
15798 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
15799 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
15800 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
15804 case DEBUG_IMPLICIT_PTR:
15805 loc_result = implicit_ptr_descriptor (rtl, 0);
15809 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
15810 && CONST_INT_P (XEXP (rtl, 1)))
15813 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
15819 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
15820 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
15821 && dwarf_version >= 4)
15822 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
15824 /* Value expression. */
15825 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
15827 add_loc_descr (&loc_result,
15828 new_loc_descr (DW_OP_stack_value, 0, 0));
15836 /* We need to figure out what section we should use as the base for the
15837 address ranges where a given location is valid.
15838 1. If this particular DECL has a section associated with it, use that.
15839 2. If this function has a section associated with it, use that.
15840 3. Otherwise, use the text section.
15841 XXX: If you split a variable across multiple sections, we won't notice. */
15843 static const char *
15844 secname_for_decl (const_tree decl)
15846 const char *secname;
15848 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
15850 tree sectree = DECL_SECTION_NAME (decl);
15851 secname = TREE_STRING_POINTER (sectree);
15853 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
15855 tree sectree = DECL_SECTION_NAME (current_function_decl);
15856 secname = TREE_STRING_POINTER (sectree);
15858 else if (cfun && in_cold_section_p)
15859 secname = crtl->subsections.cold_section_label;
15861 secname = text_section_label;
15866 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
15869 decl_by_reference_p (tree decl)
15871 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
15872 || TREE_CODE (decl) == VAR_DECL)
15873 && DECL_BY_REFERENCE (decl));
15876 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15879 static dw_loc_descr_ref
15880 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
15881 enum var_init_status initialized)
15883 int have_address = 0;
15884 dw_loc_descr_ref descr;
15885 enum machine_mode mode;
15887 if (want_address != 2)
15889 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
15891 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15893 varloc = PAT_VAR_LOCATION_LOC (varloc);
15894 if (GET_CODE (varloc) == EXPR_LIST)
15895 varloc = XEXP (varloc, 0);
15896 mode = GET_MODE (varloc);
15897 if (MEM_P (varloc))
15899 rtx addr = XEXP (varloc, 0);
15900 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
15901 mode, initialized);
15906 rtx x = avoid_constant_pool_reference (varloc);
15908 descr = mem_loc_descriptor (x, mode, VOIDmode,
15913 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
15920 if (GET_CODE (varloc) == VAR_LOCATION)
15921 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
15923 mode = DECL_MODE (loc);
15924 descr = loc_descriptor (varloc, mode, initialized);
15931 if (want_address == 2 && !have_address
15932 && (dwarf_version >= 4 || !dwarf_strict))
15934 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15936 expansion_failed (loc, NULL_RTX,
15937 "DWARF address size mismatch");
15940 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
15943 /* Show if we can't fill the request for an address. */
15944 if (want_address && !have_address)
15946 expansion_failed (loc, NULL_RTX,
15947 "Want address and only have value");
15951 /* If we've got an address and don't want one, dereference. */
15952 if (!want_address && have_address)
15954 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15955 enum dwarf_location_atom op;
15957 if (size > DWARF2_ADDR_SIZE || size == -1)
15959 expansion_failed (loc, NULL_RTX,
15960 "DWARF address size mismatch");
15963 else if (size == DWARF2_ADDR_SIZE)
15966 op = DW_OP_deref_size;
15968 add_loc_descr (&descr, new_loc_descr (op, size, 0));
15974 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
15975 if it is not possible. */
15977 static dw_loc_descr_ref
15978 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
15980 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
15981 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
15982 else if (dwarf_version >= 3 || !dwarf_strict)
15983 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
15988 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15989 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
15991 static dw_loc_descr_ref
15992 dw_sra_loc_expr (tree decl, rtx loc)
15995 unsigned int padsize = 0;
15996 dw_loc_descr_ref descr, *descr_tail;
15997 unsigned HOST_WIDE_INT decl_size;
15999 enum var_init_status initialized;
16001 if (DECL_SIZE (decl) == NULL
16002 || !host_integerp (DECL_SIZE (decl), 1))
16005 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
16007 descr_tail = &descr;
16009 for (p = loc; p; p = XEXP (p, 1))
16011 unsigned int bitsize = decl_piece_bitsize (p);
16012 rtx loc_note = *decl_piece_varloc_ptr (p);
16013 dw_loc_descr_ref cur_descr;
16014 dw_loc_descr_ref *tail, last = NULL;
16015 unsigned int opsize = 0;
16017 if (loc_note == NULL_RTX
16018 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
16020 padsize += bitsize;
16023 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
16024 varloc = NOTE_VAR_LOCATION (loc_note);
16025 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
16026 if (cur_descr == NULL)
16028 padsize += bitsize;
16032 /* Check that cur_descr either doesn't use
16033 DW_OP_*piece operations, or their sum is equal
16034 to bitsize. Otherwise we can't embed it. */
16035 for (tail = &cur_descr; *tail != NULL;
16036 tail = &(*tail)->dw_loc_next)
16037 if ((*tail)->dw_loc_opc == DW_OP_piece)
16039 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
16043 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
16045 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
16049 if (last != NULL && opsize != bitsize)
16051 padsize += bitsize;
16055 /* If there is a hole, add DW_OP_*piece after empty DWARF
16056 expression, which means that those bits are optimized out. */
16059 if (padsize > decl_size)
16061 decl_size -= padsize;
16062 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
16063 if (*descr_tail == NULL)
16065 descr_tail = &(*descr_tail)->dw_loc_next;
16068 *descr_tail = cur_descr;
16070 if (bitsize > decl_size)
16072 decl_size -= bitsize;
16075 HOST_WIDE_INT offset = 0;
16076 if (GET_CODE (varloc) == VAR_LOCATION
16077 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
16079 varloc = PAT_VAR_LOCATION_LOC (varloc);
16080 if (GET_CODE (varloc) == EXPR_LIST)
16081 varloc = XEXP (varloc, 0);
16085 if (GET_CODE (varloc) == CONST
16086 || GET_CODE (varloc) == SIGN_EXTEND
16087 || GET_CODE (varloc) == ZERO_EXTEND)
16088 varloc = XEXP (varloc, 0);
16089 else if (GET_CODE (varloc) == SUBREG)
16090 varloc = SUBREG_REG (varloc);
16095 /* DW_OP_bit_size offset should be zero for register
16096 or implicit location descriptions and empty location
16097 descriptions, but for memory addresses needs big endian
16099 if (MEM_P (varloc))
16101 unsigned HOST_WIDE_INT memsize
16102 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
16103 if (memsize != bitsize)
16105 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
16106 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
16108 if (memsize < bitsize)
16110 if (BITS_BIG_ENDIAN)
16111 offset = memsize - bitsize;
16115 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
16116 if (*descr_tail == NULL)
16118 descr_tail = &(*descr_tail)->dw_loc_next;
16122 /* If there were any non-empty expressions, add padding till the end of
16124 if (descr != NULL && decl_size != 0)
16126 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
16127 if (*descr_tail == NULL)
16133 /* Return the dwarf representation of the location list LOC_LIST of
16134 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16137 static dw_loc_list_ref
16138 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
16140 const char *endname, *secname;
16142 enum var_init_status initialized;
16143 struct var_loc_node *node;
16144 dw_loc_descr_ref descr;
16145 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
16146 dw_loc_list_ref list = NULL;
16147 dw_loc_list_ref *listp = &list;
16149 /* Now that we know what section we are using for a base,
16150 actually construct the list of locations.
16151 The first location information is what is passed to the
16152 function that creates the location list, and the remaining
16153 locations just get added on to that list.
16154 Note that we only know the start address for a location
16155 (IE location changes), so to build the range, we use
16156 the range [current location start, next location start].
16157 This means we have to special case the last node, and generate
16158 a range of [last location start, end of function label]. */
16160 secname = secname_for_decl (decl);
16162 for (node = loc_list->first; node; node = node->next)
16163 if (GET_CODE (node->loc) == EXPR_LIST
16164 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
16166 if (GET_CODE (node->loc) == EXPR_LIST)
16168 /* This requires DW_OP_{,bit_}piece, which is not usable
16169 inside DWARF expressions. */
16170 if (want_address != 2)
16172 descr = dw_sra_loc_expr (decl, node->loc);
16178 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
16179 varloc = NOTE_VAR_LOCATION (node->loc);
16180 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
16184 bool range_across_switch = false;
16185 /* If section switch happens in between node->label
16186 and node->next->label (or end of function) and
16187 we can't emit it as a single entry list,
16188 emit two ranges, first one ending at the end
16189 of first partition and second one starting at the
16190 beginning of second partition. */
16191 if (node == loc_list->last_before_switch
16192 && (node != loc_list->first || loc_list->first->next)
16193 && current_function_decl)
16195 endname = current_fde ()->dw_fde_end;
16196 range_across_switch = true;
16198 /* The variable has a location between NODE->LABEL and
16199 NODE->NEXT->LABEL. */
16200 else if (node->next)
16201 endname = node->next->label;
16202 /* If the variable has a location at the last label
16203 it keeps its location until the end of function. */
16204 else if (!current_function_decl)
16205 endname = text_end_label;
16208 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
16209 current_function_funcdef_no);
16210 endname = ggc_strdup (label_id);
16213 *listp = new_loc_list (descr, node->label, endname, secname);
16214 if (TREE_CODE (decl) == PARM_DECL
16215 && node == loc_list->first
16216 && GET_CODE (node->loc) == NOTE
16217 && strcmp (node->label, endname) == 0)
16218 (*listp)->force = true;
16219 listp = &(*listp)->dw_loc_next;
16221 if (range_across_switch)
16223 if (GET_CODE (node->loc) == EXPR_LIST)
16224 descr = dw_sra_loc_expr (decl, node->loc);
16227 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
16228 varloc = NOTE_VAR_LOCATION (node->loc);
16229 descr = dw_loc_list_1 (decl, varloc, want_address,
16232 gcc_assert (descr);
16233 /* The variable has a location between NODE->LABEL and
16234 NODE->NEXT->LABEL. */
16236 endname = node->next->label;
16238 endname = current_fde ()->dw_fde_second_end;
16239 *listp = new_loc_list (descr,
16240 current_fde ()->dw_fde_second_begin,
16242 listp = &(*listp)->dw_loc_next;
16247 /* Try to avoid the overhead of a location list emitting a location
16248 expression instead, but only if we didn't have more than one
16249 location entry in the first place. If some entries were not
16250 representable, we don't want to pretend a single entry that was
16251 applies to the entire scope in which the variable is
16253 if (list && loc_list->first->next)
16259 /* Return if the loc_list has only single element and thus can be represented
16260 as location description. */
16263 single_element_loc_list_p (dw_loc_list_ref list)
16265 gcc_assert (!list->dw_loc_next || list->ll_symbol);
16266 return !list->ll_symbol;
16269 /* To each location in list LIST add loc descr REF. */
16272 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
16274 dw_loc_descr_ref copy;
16275 add_loc_descr (&list->expr, ref);
16276 list = list->dw_loc_next;
16279 copy = ggc_alloc_dw_loc_descr_node ();
16280 memcpy (copy, ref, sizeof (dw_loc_descr_node));
16281 add_loc_descr (&list->expr, copy);
16282 while (copy->dw_loc_next)
16284 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
16285 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
16286 copy->dw_loc_next = new_copy;
16289 list = list->dw_loc_next;
16293 /* Given two lists RET and LIST
16294 produce location list that is result of adding expression in LIST
16295 to expression in RET on each possition in program.
16296 Might be destructive on both RET and LIST.
16298 TODO: We handle only simple cases of RET or LIST having at most one
16299 element. General case would inolve sorting the lists in program order
16300 and merging them that will need some additional work.
16301 Adding that will improve quality of debug info especially for SRA-ed
16305 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
16314 if (!list->dw_loc_next)
16316 add_loc_descr_to_each (*ret, list->expr);
16319 if (!(*ret)->dw_loc_next)
16321 add_loc_descr_to_each (list, (*ret)->expr);
16325 expansion_failed (NULL_TREE, NULL_RTX,
16326 "Don't know how to merge two non-trivial"
16327 " location lists.\n");
16332 /* LOC is constant expression. Try a luck, look it up in constant
16333 pool and return its loc_descr of its address. */
16335 static dw_loc_descr_ref
16336 cst_pool_loc_descr (tree loc)
16338 /* Get an RTL for this, if something has been emitted. */
16339 rtx rtl = lookup_constant_def (loc);
16341 if (!rtl || !MEM_P (rtl))
16346 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
16348 /* TODO: We might get more coverage if we was actually delaying expansion
16349 of all expressions till end of compilation when constant pools are fully
16351 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
16353 expansion_failed (loc, NULL_RTX,
16354 "CST value in contant pool but not marked.");
16357 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
16358 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
16361 /* Return dw_loc_list representing address of addr_expr LOC
16362 by looking for innder INDIRECT_REF expression and turing it
16363 into simple arithmetics. */
16365 static dw_loc_list_ref
16366 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
16369 HOST_WIDE_INT bitsize, bitpos, bytepos;
16370 enum machine_mode mode;
16372 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
16373 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
16375 obj = get_inner_reference (TREE_OPERAND (loc, 0),
16376 &bitsize, &bitpos, &offset, &mode,
16377 &unsignedp, &volatilep, false);
16379 if (bitpos % BITS_PER_UNIT)
16381 expansion_failed (loc, NULL_RTX, "bitfield access");
16384 if (!INDIRECT_REF_P (obj))
16386 expansion_failed (obj,
16387 NULL_RTX, "no indirect ref in inner refrence");
16390 if (!offset && !bitpos)
16391 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
16393 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
16394 && (dwarf_version >= 4 || !dwarf_strict))
16396 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
16401 /* Variable offset. */
16402 list_ret1 = loc_list_from_tree (offset, 0);
16403 if (list_ret1 == 0)
16405 add_loc_list (&list_ret, list_ret1);
16408 add_loc_descr_to_each (list_ret,
16409 new_loc_descr (DW_OP_plus, 0, 0));
16411 bytepos = bitpos / BITS_PER_UNIT;
16413 add_loc_descr_to_each (list_ret,
16414 new_loc_descr (DW_OP_plus_uconst,
16416 else if (bytepos < 0)
16417 loc_list_plus_const (list_ret, bytepos);
16418 add_loc_descr_to_each (list_ret,
16419 new_loc_descr (DW_OP_stack_value, 0, 0));
16425 /* Generate Dwarf location list representing LOC.
16426 If WANT_ADDRESS is false, expression computing LOC will be computed
16427 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
16428 if WANT_ADDRESS is 2, expression computing address useable in location
16429 will be returned (i.e. DW_OP_reg can be used
16430 to refer to register values). */
16432 static dw_loc_list_ref
16433 loc_list_from_tree (tree loc, int want_address)
16435 dw_loc_descr_ref ret = NULL, ret1 = NULL;
16436 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
16437 int have_address = 0;
16438 enum dwarf_location_atom op;
16440 /* ??? Most of the time we do not take proper care for sign/zero
16441 extending the values properly. Hopefully this won't be a real
16444 switch (TREE_CODE (loc))
16447 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
16450 case PLACEHOLDER_EXPR:
16451 /* This case involves extracting fields from an object to determine the
16452 position of other fields. We don't try to encode this here. The
16453 only user of this is Ada, which encodes the needed information using
16454 the names of types. */
16455 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
16459 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
16460 /* There are no opcodes for these operations. */
16463 case PREINCREMENT_EXPR:
16464 case PREDECREMENT_EXPR:
16465 case POSTINCREMENT_EXPR:
16466 case POSTDECREMENT_EXPR:
16467 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
16468 /* There are no opcodes for these operations. */
16472 /* If we already want an address, see if there is INDIRECT_REF inside
16473 e.g. for &this->field. */
16476 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
16477 (loc, want_address == 2);
16480 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
16481 && (ret = cst_pool_loc_descr (loc)))
16484 /* Otherwise, process the argument and look for the address. */
16485 if (!list_ret && !ret)
16486 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
16490 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
16496 if (DECL_THREAD_LOCAL_P (loc))
16499 enum dwarf_location_atom first_op;
16500 enum dwarf_location_atom second_op;
16501 bool dtprel = false;
16503 if (targetm.have_tls)
16505 /* If this is not defined, we have no way to emit the
16507 if (!targetm.asm_out.output_dwarf_dtprel)
16510 /* The way DW_OP_GNU_push_tls_address is specified, we
16511 can only look up addresses of objects in the current
16512 module. We used DW_OP_addr as first op, but that's
16513 wrong, because DW_OP_addr is relocated by the debug
16514 info consumer, while DW_OP_GNU_push_tls_address
16515 operand shouldn't be. */
16516 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
16518 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
16520 second_op = DW_OP_GNU_push_tls_address;
16524 if (!targetm.emutls.debug_form_tls_address
16525 || !(dwarf_version >= 3 || !dwarf_strict))
16527 /* We stuffed the control variable into the DECL_VALUE_EXPR
16528 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
16529 no longer appear in gimple code. We used the control
16530 variable in specific so that we could pick it up here. */
16531 loc = DECL_VALUE_EXPR (loc);
16532 first_op = DW_OP_addr;
16533 second_op = DW_OP_form_tls_address;
16536 rtl = rtl_for_decl_location (loc);
16537 if (rtl == NULL_RTX)
16542 rtl = XEXP (rtl, 0);
16543 if (! CONSTANT_P (rtl))
16546 ret = new_loc_descr (first_op, 0, 0);
16547 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
16548 ret->dw_loc_oprnd1.v.val_addr = rtl;
16549 ret->dtprel = dtprel;
16551 ret1 = new_loc_descr (second_op, 0, 0);
16552 add_loc_descr (&ret, ret1);
16561 if (DECL_HAS_VALUE_EXPR_P (loc))
16562 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
16566 case FUNCTION_DECL:
16569 var_loc_list *loc_list = lookup_decl_loc (loc);
16571 if (loc_list && loc_list->first)
16573 list_ret = dw_loc_list (loc_list, loc, want_address);
16574 have_address = want_address != 0;
16577 rtl = rtl_for_decl_location (loc);
16578 if (rtl == NULL_RTX)
16580 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
16583 else if (CONST_INT_P (rtl))
16585 HOST_WIDE_INT val = INTVAL (rtl);
16586 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16587 val &= GET_MODE_MASK (DECL_MODE (loc));
16588 ret = int_loc_descriptor (val);
16590 else if (GET_CODE (rtl) == CONST_STRING)
16592 expansion_failed (loc, NULL_RTX, "CONST_STRING");
16595 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
16597 ret = new_loc_descr (DW_OP_addr, 0, 0);
16598 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
16599 ret->dw_loc_oprnd1.v.val_addr = rtl;
16603 enum machine_mode mode, mem_mode;
16605 /* Certain constructs can only be represented at top-level. */
16606 if (want_address == 2)
16608 ret = loc_descriptor (rtl, VOIDmode,
16609 VAR_INIT_STATUS_INITIALIZED);
16614 mode = GET_MODE (rtl);
16615 mem_mode = VOIDmode;
16619 mode = get_address_mode (rtl);
16620 rtl = XEXP (rtl, 0);
16623 ret = mem_loc_descriptor (rtl, mode, mem_mode,
16624 VAR_INIT_STATUS_INITIALIZED);
16627 expansion_failed (loc, rtl,
16628 "failed to produce loc descriptor for rtl");
16635 if (!integer_zerop (TREE_OPERAND (loc, 1)))
16639 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16643 case COMPOUND_EXPR:
16644 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
16647 case VIEW_CONVERT_EXPR:
16650 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
16652 case COMPONENT_REF:
16653 case BIT_FIELD_REF:
16655 case ARRAY_RANGE_REF:
16656 case REALPART_EXPR:
16657 case IMAGPART_EXPR:
16660 HOST_WIDE_INT bitsize, bitpos, bytepos;
16661 enum machine_mode mode;
16663 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
16665 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
16666 &unsignedp, &volatilep, false);
16668 gcc_assert (obj != loc);
16670 list_ret = loc_list_from_tree (obj,
16672 && !bitpos && !offset ? 2 : 1);
16673 /* TODO: We can extract value of the small expression via shifting even
16674 for nonzero bitpos. */
16677 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
16679 expansion_failed (loc, NULL_RTX,
16680 "bitfield access");
16684 if (offset != NULL_TREE)
16686 /* Variable offset. */
16687 list_ret1 = loc_list_from_tree (offset, 0);
16688 if (list_ret1 == 0)
16690 add_loc_list (&list_ret, list_ret1);
16693 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
16696 bytepos = bitpos / BITS_PER_UNIT;
16698 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
16699 else if (bytepos < 0)
16700 loc_list_plus_const (list_ret, bytepos);
16707 if ((want_address || !host_integerp (loc, 0))
16708 && (ret = cst_pool_loc_descr (loc)))
16710 else if (want_address == 2
16711 && host_integerp (loc, 0)
16712 && (ret = address_of_int_loc_descriptor
16713 (int_size_in_bytes (TREE_TYPE (loc)),
16714 tree_low_cst (loc, 0))))
16716 else if (host_integerp (loc, 0))
16717 ret = int_loc_descriptor (tree_low_cst (loc, 0));
16720 expansion_failed (loc, NULL_RTX,
16721 "Integer operand is not host integer");
16730 if ((ret = cst_pool_loc_descr (loc)))
16733 /* We can construct small constants here using int_loc_descriptor. */
16734 expansion_failed (loc, NULL_RTX,
16735 "constructor or constant not in constant pool");
16738 case TRUTH_AND_EXPR:
16739 case TRUTH_ANDIF_EXPR:
16744 case TRUTH_XOR_EXPR:
16749 case TRUTH_OR_EXPR:
16750 case TRUTH_ORIF_EXPR:
16755 case FLOOR_DIV_EXPR:
16756 case CEIL_DIV_EXPR:
16757 case ROUND_DIV_EXPR:
16758 case TRUNC_DIV_EXPR:
16759 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16768 case FLOOR_MOD_EXPR:
16769 case CEIL_MOD_EXPR:
16770 case ROUND_MOD_EXPR:
16771 case TRUNC_MOD_EXPR:
16772 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16777 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16778 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
16779 if (list_ret == 0 || list_ret1 == 0)
16782 add_loc_list (&list_ret, list_ret1);
16785 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16786 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16787 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
16788 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
16789 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
16801 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
16804 case POINTER_PLUS_EXPR:
16806 if (host_integerp (TREE_OPERAND (loc, 1), 0))
16808 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16812 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
16820 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16827 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16834 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16841 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16856 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16857 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
16858 if (list_ret == 0 || list_ret1 == 0)
16861 add_loc_list (&list_ret, list_ret1);
16864 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16867 case TRUTH_NOT_EXPR:
16881 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16885 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16891 const enum tree_code code =
16892 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
16894 loc = build3 (COND_EXPR, TREE_TYPE (loc),
16895 build2 (code, integer_type_node,
16896 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
16897 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
16900 /* ... fall through ... */
16904 dw_loc_descr_ref lhs
16905 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
16906 dw_loc_list_ref rhs
16907 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
16908 dw_loc_descr_ref bra_node, jump_node, tmp;
16910 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16911 if (list_ret == 0 || lhs == 0 || rhs == 0)
16914 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
16915 add_loc_descr_to_each (list_ret, bra_node);
16917 add_loc_list (&list_ret, rhs);
16918 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
16919 add_loc_descr_to_each (list_ret, jump_node);
16921 add_loc_descr_to_each (list_ret, lhs);
16922 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16923 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
16925 /* ??? Need a node to point the skip at. Use a nop. */
16926 tmp = new_loc_descr (DW_OP_nop, 0, 0);
16927 add_loc_descr_to_each (list_ret, tmp);
16928 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16929 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
16933 case FIX_TRUNC_EXPR:
16937 /* Leave front-end specific codes as simply unknown. This comes
16938 up, for instance, with the C STMT_EXPR. */
16939 if ((unsigned int) TREE_CODE (loc)
16940 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
16942 expansion_failed (loc, NULL_RTX,
16943 "language specific tree node");
16947 #ifdef ENABLE_CHECKING
16948 /* Otherwise this is a generic code; we should just lists all of
16949 these explicitly. We forgot one. */
16950 gcc_unreachable ();
16952 /* In a release build, we want to degrade gracefully: better to
16953 generate incomplete debugging information than to crash. */
16958 if (!ret && !list_ret)
16961 if (want_address == 2 && !have_address
16962 && (dwarf_version >= 4 || !dwarf_strict))
16964 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
16966 expansion_failed (loc, NULL_RTX,
16967 "DWARF address size mismatch");
16971 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
16973 add_loc_descr_to_each (list_ret,
16974 new_loc_descr (DW_OP_stack_value, 0, 0));
16977 /* Show if we can't fill the request for an address. */
16978 if (want_address && !have_address)
16980 expansion_failed (loc, NULL_RTX,
16981 "Want address and only have value");
16985 gcc_assert (!ret || !list_ret);
16987 /* If we've got an address and don't want one, dereference. */
16988 if (!want_address && have_address)
16990 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
16992 if (size > DWARF2_ADDR_SIZE || size == -1)
16994 expansion_failed (loc, NULL_RTX,
16995 "DWARF address size mismatch");
16998 else if (size == DWARF2_ADDR_SIZE)
17001 op = DW_OP_deref_size;
17004 add_loc_descr (&ret, new_loc_descr (op, size, 0));
17006 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
17009 list_ret = new_loc_list (ret, NULL, NULL, NULL);
17014 /* Same as above but return only single location expression. */
17015 static dw_loc_descr_ref
17016 loc_descriptor_from_tree (tree loc, int want_address)
17018 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
17021 if (ret->dw_loc_next)
17023 expansion_failed (loc, NULL_RTX,
17024 "Location list where only loc descriptor needed");
17030 /* Given a value, round it up to the lowest multiple of `boundary'
17031 which is not less than the value itself. */
17033 static inline HOST_WIDE_INT
17034 ceiling (HOST_WIDE_INT value, unsigned int boundary)
17036 return (((value + boundary - 1) / boundary) * boundary);
17039 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
17040 pointer to the declared type for the relevant field variable, or return
17041 `integer_type_node' if the given node turns out to be an
17042 ERROR_MARK node. */
17045 field_type (const_tree decl)
17049 if (TREE_CODE (decl) == ERROR_MARK)
17050 return integer_type_node;
17052 type = DECL_BIT_FIELD_TYPE (decl);
17053 if (type == NULL_TREE)
17054 type = TREE_TYPE (decl);
17059 /* Given a pointer to a tree node, return the alignment in bits for
17060 it, or else return BITS_PER_WORD if the node actually turns out to
17061 be an ERROR_MARK node. */
17063 static inline unsigned
17064 simple_type_align_in_bits (const_tree type)
17066 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
17069 static inline unsigned
17070 simple_decl_align_in_bits (const_tree decl)
17072 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
17075 /* Return the result of rounding T up to ALIGN. */
17077 static inline double_int
17078 round_up_to_align (double_int t, unsigned int align)
17080 double_int alignd = uhwi_to_double_int (align);
17081 t = double_int_add (t, alignd);
17082 t = double_int_add (t, double_int_minus_one);
17083 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
17084 t = double_int_mul (t, alignd);
17088 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
17089 lowest addressed byte of the "containing object" for the given FIELD_DECL,
17090 or return 0 if we are unable to determine what that offset is, either
17091 because the argument turns out to be a pointer to an ERROR_MARK node, or
17092 because the offset is actually variable. (We can't handle the latter case
17095 static HOST_WIDE_INT
17096 field_byte_offset (const_tree decl)
17098 double_int object_offset_in_bits;
17099 double_int object_offset_in_bytes;
17100 double_int bitpos_int;
17102 if (TREE_CODE (decl) == ERROR_MARK)
17105 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
17107 /* We cannot yet cope with fields whose positions are variable, so
17108 for now, when we see such things, we simply return 0. Someday, we may
17109 be able to handle such cases, but it will be damn difficult. */
17110 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
17113 bitpos_int = tree_to_double_int (bit_position (decl));
17115 #ifdef PCC_BITFIELD_TYPE_MATTERS
17116 if (PCC_BITFIELD_TYPE_MATTERS)
17119 tree field_size_tree;
17120 double_int deepest_bitpos;
17121 double_int field_size_in_bits;
17122 unsigned int type_align_in_bits;
17123 unsigned int decl_align_in_bits;
17124 double_int type_size_in_bits;
17126 type = field_type (decl);
17127 type_size_in_bits = double_int_type_size_in_bits (type);
17128 type_align_in_bits = simple_type_align_in_bits (type);
17130 field_size_tree = DECL_SIZE (decl);
17132 /* The size could be unspecified if there was an error, or for
17133 a flexible array member. */
17134 if (!field_size_tree)
17135 field_size_tree = bitsize_zero_node;
17137 /* If the size of the field is not constant, use the type size. */
17138 if (TREE_CODE (field_size_tree) == INTEGER_CST)
17139 field_size_in_bits = tree_to_double_int (field_size_tree);
17141 field_size_in_bits = type_size_in_bits;
17143 decl_align_in_bits = simple_decl_align_in_bits (decl);
17145 /* The GCC front-end doesn't make any attempt to keep track of the
17146 starting bit offset (relative to the start of the containing
17147 structure type) of the hypothetical "containing object" for a
17148 bit-field. Thus, when computing the byte offset value for the
17149 start of the "containing object" of a bit-field, we must deduce
17150 this information on our own. This can be rather tricky to do in
17151 some cases. For example, handling the following structure type
17152 definition when compiling for an i386/i486 target (which only
17153 aligns long long's to 32-bit boundaries) can be very tricky:
17155 struct S { int field1; long long field2:31; };
17157 Fortunately, there is a simple rule-of-thumb which can be used
17158 in such cases. When compiling for an i386/i486, GCC will
17159 allocate 8 bytes for the structure shown above. It decides to
17160 do this based upon one simple rule for bit-field allocation.
17161 GCC allocates each "containing object" for each bit-field at
17162 the first (i.e. lowest addressed) legitimate alignment boundary
17163 (based upon the required minimum alignment for the declared
17164 type of the field) which it can possibly use, subject to the
17165 condition that there is still enough available space remaining
17166 in the containing object (when allocated at the selected point)
17167 to fully accommodate all of the bits of the bit-field itself.
17169 This simple rule makes it obvious why GCC allocates 8 bytes for
17170 each object of the structure type shown above. When looking
17171 for a place to allocate the "containing object" for `field2',
17172 the compiler simply tries to allocate a 64-bit "containing
17173 object" at each successive 32-bit boundary (starting at zero)
17174 until it finds a place to allocate that 64- bit field such that
17175 at least 31 contiguous (and previously unallocated) bits remain
17176 within that selected 64 bit field. (As it turns out, for the
17177 example above, the compiler finds it is OK to allocate the
17178 "containing object" 64-bit field at bit-offset zero within the
17181 Here we attempt to work backwards from the limited set of facts
17182 we're given, and we try to deduce from those facts, where GCC
17183 must have believed that the containing object started (within
17184 the structure type). The value we deduce is then used (by the
17185 callers of this routine) to generate DW_AT_location and
17186 DW_AT_bit_offset attributes for fields (both bit-fields and, in
17187 the case of DW_AT_location, regular fields as well). */
17189 /* Figure out the bit-distance from the start of the structure to
17190 the "deepest" bit of the bit-field. */
17191 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
17193 /* This is the tricky part. Use some fancy footwork to deduce
17194 where the lowest addressed bit of the containing object must
17196 object_offset_in_bits
17197 = double_int_sub (deepest_bitpos, type_size_in_bits);
17199 /* Round up to type_align by default. This works best for
17201 object_offset_in_bits
17202 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
17204 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
17206 object_offset_in_bits
17207 = double_int_sub (deepest_bitpos, type_size_in_bits);
17209 /* Round up to decl_align instead. */
17210 object_offset_in_bits
17211 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
17215 #endif /* PCC_BITFIELD_TYPE_MATTERS */
17216 object_offset_in_bits = bitpos_int;
17218 object_offset_in_bytes
17219 = double_int_div (object_offset_in_bits,
17220 uhwi_to_double_int (BITS_PER_UNIT), true,
17222 return double_int_to_shwi (object_offset_in_bytes);
17225 /* The following routines define various Dwarf attributes and any data
17226 associated with them. */
17228 /* Add a location description attribute value to a DIE.
17230 This emits location attributes suitable for whole variables and
17231 whole parameters. Note that the location attributes for struct fields are
17232 generated by the routine `data_member_location_attribute' below. */
17235 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
17236 dw_loc_list_ref descr)
17240 if (single_element_loc_list_p (descr))
17241 add_AT_loc (die, attr_kind, descr->expr);
17243 add_AT_loc_list (die, attr_kind, descr);
17246 /* Add DW_AT_accessibility attribute to DIE if needed. */
17249 add_accessibility_attribute (dw_die_ref die, tree decl)
17251 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
17252 children, otherwise the default is DW_ACCESS_public. In DWARF2
17253 the default has always been DW_ACCESS_public. */
17254 if (TREE_PROTECTED (decl))
17255 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
17256 else if (TREE_PRIVATE (decl))
17258 if (dwarf_version == 2
17259 || die->die_parent == NULL
17260 || die->die_parent->die_tag != DW_TAG_class_type)
17261 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
17263 else if (dwarf_version > 2
17265 && die->die_parent->die_tag == DW_TAG_class_type)
17266 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
17269 /* Attach the specialized form of location attribute used for data members of
17270 struct and union types. In the special case of a FIELD_DECL node which
17271 represents a bit-field, the "offset" part of this special location
17272 descriptor must indicate the distance in bytes from the lowest-addressed
17273 byte of the containing struct or union type to the lowest-addressed byte of
17274 the "containing object" for the bit-field. (See the `field_byte_offset'
17277 For any given bit-field, the "containing object" is a hypothetical object
17278 (of some integral or enum type) within which the given bit-field lives. The
17279 type of this hypothetical "containing object" is always the same as the
17280 declared type of the individual bit-field itself (for GCC anyway... the
17281 DWARF spec doesn't actually mandate this). Note that it is the size (in
17282 bytes) of the hypothetical "containing object" which will be given in the
17283 DW_AT_byte_size attribute for this bit-field. (See the
17284 `byte_size_attribute' function below.) It is also used when calculating the
17285 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
17286 function below.) */
17289 add_data_member_location_attribute (dw_die_ref die, tree decl)
17291 HOST_WIDE_INT offset;
17292 dw_loc_descr_ref loc_descr = 0;
17294 if (TREE_CODE (decl) == TREE_BINFO)
17296 /* We're working on the TAG_inheritance for a base class. */
17297 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
17299 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
17300 aren't at a fixed offset from all (sub)objects of the same
17301 type. We need to extract the appropriate offset from our
17302 vtable. The following dwarf expression means
17304 BaseAddr = ObAddr + *((*ObAddr) - Offset)
17306 This is specific to the V3 ABI, of course. */
17308 dw_loc_descr_ref tmp;
17310 /* Make a copy of the object address. */
17311 tmp = new_loc_descr (DW_OP_dup, 0, 0);
17312 add_loc_descr (&loc_descr, tmp);
17314 /* Extract the vtable address. */
17315 tmp = new_loc_descr (DW_OP_deref, 0, 0);
17316 add_loc_descr (&loc_descr, tmp);
17318 /* Calculate the address of the offset. */
17319 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
17320 gcc_assert (offset < 0);
17322 tmp = int_loc_descriptor (-offset);
17323 add_loc_descr (&loc_descr, tmp);
17324 tmp = new_loc_descr (DW_OP_minus, 0, 0);
17325 add_loc_descr (&loc_descr, tmp);
17327 /* Extract the offset. */
17328 tmp = new_loc_descr (DW_OP_deref, 0, 0);
17329 add_loc_descr (&loc_descr, tmp);
17331 /* Add it to the object address. */
17332 tmp = new_loc_descr (DW_OP_plus, 0, 0);
17333 add_loc_descr (&loc_descr, tmp);
17336 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
17339 offset = field_byte_offset (decl);
17343 if (dwarf_version > 2)
17345 /* Don't need to output a location expression, just the constant. */
17347 add_AT_int (die, DW_AT_data_member_location, offset);
17349 add_AT_unsigned (die, DW_AT_data_member_location, offset);
17354 enum dwarf_location_atom op;
17356 /* The DWARF2 standard says that we should assume that the structure
17357 address is already on the stack, so we can specify a structure
17358 field address by using DW_OP_plus_uconst. */
17360 #ifdef MIPS_DEBUGGING_INFO
17361 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
17362 operator correctly. It works only if we leave the offset on the
17366 op = DW_OP_plus_uconst;
17369 loc_descr = new_loc_descr (op, offset, 0);
17373 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
17376 /* Writes integer values to dw_vec_const array. */
17379 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
17383 *dest++ = val & 0xff;
17389 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
17391 static HOST_WIDE_INT
17392 extract_int (const unsigned char *src, unsigned int size)
17394 HOST_WIDE_INT val = 0;
17400 val |= *--src & 0xff;
17406 /* Writes double_int values to dw_vec_const array. */
17409 insert_double (double_int val, unsigned char *dest)
17411 unsigned char *p0 = dest;
17412 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
17414 if (WORDS_BIG_ENDIAN)
17420 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
17421 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
17424 /* Writes floating point values to dw_vec_const array. */
17427 insert_float (const_rtx rtl, unsigned char *array)
17429 REAL_VALUE_TYPE rv;
17433 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
17434 real_to_target (val, &rv, GET_MODE (rtl));
17436 /* real_to_target puts 32-bit pieces in each long. Pack them. */
17437 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
17439 insert_int (val[i], 4, array);
17444 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
17445 does not have a "location" either in memory or in a register. These
17446 things can arise in GNU C when a constant is passed as an actual parameter
17447 to an inlined function. They can also arise in C++ where declared
17448 constants do not necessarily get memory "homes". */
17451 add_const_value_attribute (dw_die_ref die, rtx rtl)
17453 switch (GET_CODE (rtl))
17457 HOST_WIDE_INT val = INTVAL (rtl);
17460 add_AT_int (die, DW_AT_const_value, val);
17462 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
17467 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
17468 floating-point constant. A CONST_DOUBLE is used whenever the
17469 constant requires more than one word in order to be adequately
17472 enum machine_mode mode = GET_MODE (rtl);
17474 if (SCALAR_FLOAT_MODE_P (mode))
17476 unsigned int length = GET_MODE_SIZE (mode);
17477 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
17479 insert_float (rtl, array);
17480 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
17483 add_AT_double (die, DW_AT_const_value,
17484 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
17490 enum machine_mode mode = GET_MODE (rtl);
17491 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
17492 unsigned int length = CONST_VECTOR_NUNITS (rtl);
17493 unsigned char *array = (unsigned char *) ggc_alloc_atomic
17494 (length * elt_size);
17498 switch (GET_MODE_CLASS (mode))
17500 case MODE_VECTOR_INT:
17501 for (i = 0, p = array; i < length; i++, p += elt_size)
17503 rtx elt = CONST_VECTOR_ELT (rtl, i);
17504 double_int val = rtx_to_double_int (elt);
17506 if (elt_size <= sizeof (HOST_WIDE_INT))
17507 insert_int (double_int_to_shwi (val), elt_size, p);
17510 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
17511 insert_double (val, p);
17516 case MODE_VECTOR_FLOAT:
17517 for (i = 0, p = array; i < length; i++, p += elt_size)
17519 rtx elt = CONST_VECTOR_ELT (rtl, i);
17520 insert_float (elt, p);
17525 gcc_unreachable ();
17528 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
17533 if (dwarf_version >= 4 || !dwarf_strict)
17535 dw_loc_descr_ref loc_result;
17536 resolve_one_addr (&rtl, NULL);
17538 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
17539 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
17540 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
17541 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
17542 add_AT_loc (die, DW_AT_location, loc_result);
17543 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
17549 if (CONSTANT_P (XEXP (rtl, 0)))
17550 return add_const_value_attribute (die, XEXP (rtl, 0));
17553 if (!const_ok_for_output (rtl))
17556 if (dwarf_version >= 4 || !dwarf_strict)
17561 /* In cases where an inlined instance of an inline function is passed
17562 the address of an `auto' variable (which is local to the caller) we
17563 can get a situation where the DECL_RTL of the artificial local
17564 variable (for the inlining) which acts as a stand-in for the
17565 corresponding formal parameter (of the inline function) will look
17566 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
17567 exactly a compile-time constant expression, but it isn't the address
17568 of the (artificial) local variable either. Rather, it represents the
17569 *value* which the artificial local variable always has during its
17570 lifetime. We currently have no way to represent such quasi-constant
17571 values in Dwarf, so for now we just punt and generate nothing. */
17579 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
17580 && MEM_READONLY_P (rtl)
17581 && GET_MODE (rtl) == BLKmode)
17583 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
17589 /* No other kinds of rtx should be possible here. */
17590 gcc_unreachable ();
17595 /* Determine whether the evaluation of EXPR references any variables
17596 or functions which aren't otherwise used (and therefore may not be
17599 reference_to_unused (tree * tp, int * walk_subtrees,
17600 void * data ATTRIBUTE_UNUSED)
17602 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
17603 *walk_subtrees = 0;
17605 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
17606 && ! TREE_ASM_WRITTEN (*tp))
17608 /* ??? The C++ FE emits debug information for using decls, so
17609 putting gcc_unreachable here falls over. See PR31899. For now
17610 be conservative. */
17611 else if (!cgraph_global_info_ready
17612 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
17614 else if (TREE_CODE (*tp) == VAR_DECL)
17616 struct varpool_node *node = varpool_get_node (*tp);
17617 if (!node || !node->needed)
17620 else if (TREE_CODE (*tp) == FUNCTION_DECL
17621 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
17623 /* The call graph machinery must have finished analyzing,
17624 optimizing and gimplifying the CU by now.
17625 So if *TP has no call graph node associated
17626 to it, it means *TP will not be emitted. */
17627 if (!cgraph_get_node (*tp))
17630 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
17636 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
17637 for use in a later add_const_value_attribute call. */
17640 rtl_for_decl_init (tree init, tree type)
17642 rtx rtl = NULL_RTX;
17646 /* If a variable is initialized with a string constant without embedded
17647 zeros, build CONST_STRING. */
17648 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
17650 tree enttype = TREE_TYPE (type);
17651 tree domain = TYPE_DOMAIN (type);
17652 enum machine_mode mode = TYPE_MODE (enttype);
17654 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
17656 && integer_zerop (TYPE_MIN_VALUE (domain))
17657 && compare_tree_int (TYPE_MAX_VALUE (domain),
17658 TREE_STRING_LENGTH (init) - 1) == 0
17659 && ((size_t) TREE_STRING_LENGTH (init)
17660 == strlen (TREE_STRING_POINTER (init)) + 1))
17662 rtl = gen_rtx_CONST_STRING (VOIDmode,
17663 ggc_strdup (TREE_STRING_POINTER (init)));
17664 rtl = gen_rtx_MEM (BLKmode, rtl);
17665 MEM_READONLY_P (rtl) = 1;
17668 /* Other aggregates, and complex values, could be represented using
17670 else if (AGGREGATE_TYPE_P (type)
17671 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
17672 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
17673 || TREE_CODE (type) == COMPLEX_TYPE)
17675 /* Vectors only work if their mode is supported by the target.
17676 FIXME: generic vectors ought to work too. */
17677 else if (TREE_CODE (type) == VECTOR_TYPE
17678 && !VECTOR_MODE_P (TYPE_MODE (type)))
17680 /* If the initializer is something that we know will expand into an
17681 immediate RTL constant, expand it now. We must be careful not to
17682 reference variables which won't be output. */
17683 else if (initializer_constant_valid_p (init, type)
17684 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
17686 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
17688 if (TREE_CODE (type) == VECTOR_TYPE)
17689 switch (TREE_CODE (init))
17694 if (TREE_CONSTANT (init))
17696 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
17697 bool constant_p = true;
17699 unsigned HOST_WIDE_INT ix;
17701 /* Even when ctor is constant, it might contain non-*_CST
17702 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
17703 belong into VECTOR_CST nodes. */
17704 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
17705 if (!CONSTANT_CLASS_P (value))
17707 constant_p = false;
17713 init = build_vector_from_ctor (type, elts);
17723 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
17725 /* If expand_expr returns a MEM, it wasn't immediate. */
17726 gcc_assert (!rtl || !MEM_P (rtl));
17732 /* Generate RTL for the variable DECL to represent its location. */
17735 rtl_for_decl_location (tree decl)
17739 /* Here we have to decide where we are going to say the parameter "lives"
17740 (as far as the debugger is concerned). We only have a couple of
17741 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
17743 DECL_RTL normally indicates where the parameter lives during most of the
17744 activation of the function. If optimization is enabled however, this
17745 could be either NULL or else a pseudo-reg. Both of those cases indicate
17746 that the parameter doesn't really live anywhere (as far as the code
17747 generation parts of GCC are concerned) during most of the function's
17748 activation. That will happen (for example) if the parameter is never
17749 referenced within the function.
17751 We could just generate a location descriptor here for all non-NULL
17752 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
17753 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
17754 where DECL_RTL is NULL or is a pseudo-reg.
17756 Note however that we can only get away with using DECL_INCOMING_RTL as
17757 a backup substitute for DECL_RTL in certain limited cases. In cases
17758 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
17759 we can be sure that the parameter was passed using the same type as it is
17760 declared to have within the function, and that its DECL_INCOMING_RTL
17761 points us to a place where a value of that type is passed.
17763 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
17764 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
17765 because in these cases DECL_INCOMING_RTL points us to a value of some
17766 type which is *different* from the type of the parameter itself. Thus,
17767 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
17768 such cases, the debugger would end up (for example) trying to fetch a
17769 `float' from a place which actually contains the first part of a
17770 `double'. That would lead to really incorrect and confusing
17771 output at debug-time.
17773 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
17774 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
17775 are a couple of exceptions however. On little-endian machines we can
17776 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
17777 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
17778 an integral type that is smaller than TREE_TYPE (decl). These cases arise
17779 when (on a little-endian machine) a non-prototyped function has a
17780 parameter declared to be of type `short' or `char'. In such cases,
17781 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
17782 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
17783 passed `int' value. If the debugger then uses that address to fetch
17784 a `short' or a `char' (on a little-endian machine) the result will be
17785 the correct data, so we allow for such exceptional cases below.
17787 Note that our goal here is to describe the place where the given formal
17788 parameter lives during most of the function's activation (i.e. between the
17789 end of the prologue and the start of the epilogue). We'll do that as best
17790 as we can. Note however that if the given formal parameter is modified
17791 sometime during the execution of the function, then a stack backtrace (at
17792 debug-time) will show the function as having been called with the *new*
17793 value rather than the value which was originally passed in. This happens
17794 rarely enough that it is not a major problem, but it *is* a problem, and
17795 I'd like to fix it.
17797 A future version of dwarf2out.c may generate two additional attributes for
17798 any given DW_TAG_formal_parameter DIE which will describe the "passed
17799 type" and the "passed location" for the given formal parameter in addition
17800 to the attributes we now generate to indicate the "declared type" and the
17801 "active location" for each parameter. This additional set of attributes
17802 could be used by debuggers for stack backtraces. Separately, note that
17803 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
17804 This happens (for example) for inlined-instances of inline function formal
17805 parameters which are never referenced. This really shouldn't be
17806 happening. All PARM_DECL nodes should get valid non-NULL
17807 DECL_INCOMING_RTL values. FIXME. */
17809 /* Use DECL_RTL as the "location" unless we find something better. */
17810 rtl = DECL_RTL_IF_SET (decl);
17812 /* When generating abstract instances, ignore everything except
17813 constants, symbols living in memory, and symbols living in
17814 fixed registers. */
17815 if (! reload_completed)
17818 && (CONSTANT_P (rtl)
17820 && CONSTANT_P (XEXP (rtl, 0)))
17822 && TREE_CODE (decl) == VAR_DECL
17823 && TREE_STATIC (decl))))
17825 rtl = targetm.delegitimize_address (rtl);
17830 else if (TREE_CODE (decl) == PARM_DECL)
17832 if (rtl == NULL_RTX
17833 || is_pseudo_reg (rtl)
17835 && is_pseudo_reg (XEXP (rtl, 0))
17836 && DECL_INCOMING_RTL (decl)
17837 && MEM_P (DECL_INCOMING_RTL (decl))
17838 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
17840 tree declared_type = TREE_TYPE (decl);
17841 tree passed_type = DECL_ARG_TYPE (decl);
17842 enum machine_mode dmode = TYPE_MODE (declared_type);
17843 enum machine_mode pmode = TYPE_MODE (passed_type);
17845 /* This decl represents a formal parameter which was optimized out.
17846 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
17847 all cases where (rtl == NULL_RTX) just below. */
17848 if (dmode == pmode)
17849 rtl = DECL_INCOMING_RTL (decl);
17850 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
17851 && SCALAR_INT_MODE_P (dmode)
17852 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
17853 && DECL_INCOMING_RTL (decl))
17855 rtx inc = DECL_INCOMING_RTL (decl);
17858 else if (MEM_P (inc))
17860 if (BYTES_BIG_ENDIAN)
17861 rtl = adjust_address_nv (inc, dmode,
17862 GET_MODE_SIZE (pmode)
17863 - GET_MODE_SIZE (dmode));
17870 /* If the parm was passed in registers, but lives on the stack, then
17871 make a big endian correction if the mode of the type of the
17872 parameter is not the same as the mode of the rtl. */
17873 /* ??? This is the same series of checks that are made in dbxout.c before
17874 we reach the big endian correction code there. It isn't clear if all
17875 of these checks are necessary here, but keeping them all is the safe
17877 else if (MEM_P (rtl)
17878 && XEXP (rtl, 0) != const0_rtx
17879 && ! CONSTANT_P (XEXP (rtl, 0))
17880 /* Not passed in memory. */
17881 && !MEM_P (DECL_INCOMING_RTL (decl))
17882 /* Not passed by invisible reference. */
17883 && (!REG_P (XEXP (rtl, 0))
17884 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
17885 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
17886 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
17887 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
17890 /* Big endian correction check. */
17891 && BYTES_BIG_ENDIAN
17892 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
17893 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
17896 int offset = (UNITS_PER_WORD
17897 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
17899 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17900 plus_constant (XEXP (rtl, 0), offset));
17903 else if (TREE_CODE (decl) == VAR_DECL
17906 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
17907 && BYTES_BIG_ENDIAN)
17909 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
17910 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
17912 /* If a variable is declared "register" yet is smaller than
17913 a register, then if we store the variable to memory, it
17914 looks like we're storing a register-sized value, when in
17915 fact we are not. We need to adjust the offset of the
17916 storage location to reflect the actual value's bytes,
17917 else gdb will not be able to display it. */
17919 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17920 plus_constant (XEXP (rtl, 0), rsize-dsize));
17923 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
17924 and will have been substituted directly into all expressions that use it.
17925 C does not have such a concept, but C++ and other languages do. */
17926 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
17927 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
17930 rtl = targetm.delegitimize_address (rtl);
17932 /* If we don't look past the constant pool, we risk emitting a
17933 reference to a constant pool entry that isn't referenced from
17934 code, and thus is not emitted. */
17936 rtl = avoid_constant_pool_reference (rtl);
17938 /* Try harder to get a rtl. If this symbol ends up not being emitted
17939 in the current CU, resolve_addr will remove the expression referencing
17941 if (rtl == NULL_RTX
17942 && TREE_CODE (decl) == VAR_DECL
17943 && !DECL_EXTERNAL (decl)
17944 && TREE_STATIC (decl)
17945 && DECL_NAME (decl)
17946 && !DECL_HARD_REGISTER (decl)
17947 && DECL_MODE (decl) != VOIDmode)
17949 rtl = make_decl_rtl_for_debug (decl);
17951 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
17952 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
17959 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17960 returned. If so, the decl for the COMMON block is returned, and the
17961 value is the offset into the common block for the symbol. */
17964 fortran_common (tree decl, HOST_WIDE_INT *value)
17966 tree val_expr, cvar;
17967 enum machine_mode mode;
17968 HOST_WIDE_INT bitsize, bitpos;
17970 int volatilep = 0, unsignedp = 0;
17972 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
17973 it does not have a value (the offset into the common area), or if it
17974 is thread local (as opposed to global) then it isn't common, and shouldn't
17975 be handled as such. */
17976 if (TREE_CODE (decl) != VAR_DECL
17977 || !TREE_STATIC (decl)
17978 || !DECL_HAS_VALUE_EXPR_P (decl)
17982 val_expr = DECL_VALUE_EXPR (decl);
17983 if (TREE_CODE (val_expr) != COMPONENT_REF)
17986 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
17987 &mode, &unsignedp, &volatilep, true);
17989 if (cvar == NULL_TREE
17990 || TREE_CODE (cvar) != VAR_DECL
17991 || DECL_ARTIFICIAL (cvar)
17992 || !TREE_PUBLIC (cvar))
17996 if (offset != NULL)
17998 if (!host_integerp (offset, 0))
18000 *value = tree_low_cst (offset, 0);
18003 *value += bitpos / BITS_PER_UNIT;
18008 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
18009 data attribute for a variable or a parameter. We generate the
18010 DW_AT_const_value attribute only in those cases where the given variable
18011 or parameter does not have a true "location" either in memory or in a
18012 register. This can happen (for example) when a constant is passed as an
18013 actual argument in a call to an inline function. (It's possible that
18014 these things can crop up in other ways also.) Note that one type of
18015 constant value which can be passed into an inlined function is a constant
18016 pointer. This can happen for example if an actual argument in an inlined
18017 function call evaluates to a compile-time constant address.
18019 CACHE_P is true if it is worth caching the location list for DECL,
18020 so that future calls can reuse it rather than regenerate it from scratch.
18021 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
18022 since we will need to refer to them each time the function is inlined. */
18025 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
18026 enum dwarf_attribute attr)
18029 dw_loc_list_ref list;
18030 var_loc_list *loc_list;
18031 cached_dw_loc_list *cache;
18034 if (TREE_CODE (decl) == ERROR_MARK)
18037 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
18038 || TREE_CODE (decl) == RESULT_DECL);
18040 /* Try to get some constant RTL for this decl, and use that as the value of
18043 rtl = rtl_for_decl_location (decl);
18044 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
18045 && add_const_value_attribute (die, rtl))
18048 /* See if we have single element location list that is equivalent to
18049 a constant value. That way we are better to use add_const_value_attribute
18050 rather than expanding constant value equivalent. */
18051 loc_list = lookup_decl_loc (decl);
18054 && loc_list->first->next == NULL
18055 && NOTE_P (loc_list->first->loc)
18056 && NOTE_VAR_LOCATION (loc_list->first->loc)
18057 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
18059 struct var_loc_node *node;
18061 node = loc_list->first;
18062 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
18063 if (GET_CODE (rtl) == EXPR_LIST)
18064 rtl = XEXP (rtl, 0);
18065 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
18066 && add_const_value_attribute (die, rtl))
18069 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
18070 list several times. See if we've already cached the contents. */
18072 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
18076 cache = (cached_dw_loc_list *)
18077 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
18079 list = cache->loc_list;
18083 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
18084 /* It is usually worth caching this result if the decl is from
18085 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
18086 if (cache_p && list && list->dw_loc_next)
18088 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
18089 DECL_UID (decl), INSERT);
18090 cache = ggc_alloc_cleared_cached_dw_loc_list ();
18091 cache->decl_id = DECL_UID (decl);
18092 cache->loc_list = list;
18098 add_AT_location_description (die, attr, list);
18101 /* None of that worked, so it must not really have a location;
18102 try adding a constant value attribute from the DECL_INITIAL. */
18103 return tree_add_const_value_attribute_for_decl (die, decl);
18106 /* Add VARIABLE and DIE into deferred locations list. */
18109 defer_location (tree variable, dw_die_ref die)
18111 deferred_locations entry;
18112 entry.variable = variable;
18114 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
18117 /* Helper function for tree_add_const_value_attribute. Natively encode
18118 initializer INIT into an array. Return true if successful. */
18121 native_encode_initializer (tree init, unsigned char *array, int size)
18125 if (init == NULL_TREE)
18129 switch (TREE_CODE (init))
18132 type = TREE_TYPE (init);
18133 if (TREE_CODE (type) == ARRAY_TYPE)
18135 tree enttype = TREE_TYPE (type);
18136 enum machine_mode mode = TYPE_MODE (enttype);
18138 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
18140 if (int_size_in_bytes (type) != size)
18142 if (size > TREE_STRING_LENGTH (init))
18144 memcpy (array, TREE_STRING_POINTER (init),
18145 TREE_STRING_LENGTH (init));
18146 memset (array + TREE_STRING_LENGTH (init),
18147 '\0', size - TREE_STRING_LENGTH (init));
18150 memcpy (array, TREE_STRING_POINTER (init), size);
18155 type = TREE_TYPE (init);
18156 if (int_size_in_bytes (type) != size)
18158 if (TREE_CODE (type) == ARRAY_TYPE)
18160 HOST_WIDE_INT min_index;
18161 unsigned HOST_WIDE_INT cnt;
18162 int curpos = 0, fieldsize;
18163 constructor_elt *ce;
18165 if (TYPE_DOMAIN (type) == NULL_TREE
18166 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
18169 fieldsize = int_size_in_bytes (TREE_TYPE (type));
18170 if (fieldsize <= 0)
18173 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
18174 memset (array, '\0', size);
18175 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
18177 tree val = ce->value;
18178 tree index = ce->index;
18180 if (index && TREE_CODE (index) == RANGE_EXPR)
18181 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
18184 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
18189 if (!native_encode_initializer (val, array + pos, fieldsize))
18192 curpos = pos + fieldsize;
18193 if (index && TREE_CODE (index) == RANGE_EXPR)
18195 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
18196 - tree_low_cst (TREE_OPERAND (index, 0), 0);
18197 while (count-- > 0)
18200 memcpy (array + curpos, array + pos, fieldsize);
18201 curpos += fieldsize;
18204 gcc_assert (curpos <= size);
18208 else if (TREE_CODE (type) == RECORD_TYPE
18209 || TREE_CODE (type) == UNION_TYPE)
18211 tree field = NULL_TREE;
18212 unsigned HOST_WIDE_INT cnt;
18213 constructor_elt *ce;
18215 if (int_size_in_bytes (type) != size)
18218 if (TREE_CODE (type) == RECORD_TYPE)
18219 field = TYPE_FIELDS (type);
18221 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
18223 tree val = ce->value;
18224 int pos, fieldsize;
18226 if (ce->index != 0)
18232 if (field == NULL_TREE || DECL_BIT_FIELD (field))
18235 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
18236 && TYPE_DOMAIN (TREE_TYPE (field))
18237 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
18239 else if (DECL_SIZE_UNIT (field) == NULL_TREE
18240 || !host_integerp (DECL_SIZE_UNIT (field), 0))
18242 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
18243 pos = int_byte_position (field);
18244 gcc_assert (pos + fieldsize <= size);
18246 && !native_encode_initializer (val, array + pos, fieldsize))
18252 case VIEW_CONVERT_EXPR:
18253 case NON_LVALUE_EXPR:
18254 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
18256 return native_encode_expr (init, array, size) == size;
18260 /* Attach a DW_AT_const_value attribute to DIE. The value of the
18261 attribute is the const value T. */
18264 tree_add_const_value_attribute (dw_die_ref die, tree t)
18267 tree type = TREE_TYPE (t);
18270 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
18274 gcc_assert (!DECL_P (init));
18276 rtl = rtl_for_decl_init (init, type);
18278 return add_const_value_attribute (die, rtl);
18279 /* If the host and target are sane, try harder. */
18280 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
18281 && initializer_constant_valid_p (init, type))
18283 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
18284 if (size > 0 && (int) size == size)
18286 unsigned char *array = (unsigned char *)
18287 ggc_alloc_cleared_atomic (size);
18289 if (native_encode_initializer (init, array, size))
18291 add_AT_vec (die, DW_AT_const_value, size, 1, array);
18299 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
18300 attribute is the const value of T, where T is an integral constant
18301 variable with static storage duration
18302 (so it can't be a PARM_DECL or a RESULT_DECL). */
18305 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
18309 || (TREE_CODE (decl) != VAR_DECL
18310 && TREE_CODE (decl) != CONST_DECL)
18311 || (TREE_CODE (decl) == VAR_DECL
18312 && !TREE_STATIC (decl)))
18315 if (TREE_READONLY (decl)
18316 && ! TREE_THIS_VOLATILE (decl)
18317 && DECL_INITIAL (decl))
18322 /* Don't add DW_AT_const_value if abstract origin already has one. */
18323 if (get_AT (var_die, DW_AT_const_value))
18326 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
18329 /* Convert the CFI instructions for the current function into a
18330 location list. This is used for DW_AT_frame_base when we targeting
18331 a dwarf2 consumer that does not support the dwarf3
18332 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
18335 static dw_loc_list_ref
18336 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
18340 dw_loc_list_ref list, *list_tail;
18342 dw_cfa_location last_cfa, next_cfa;
18343 const char *start_label, *last_label, *section;
18344 dw_cfa_location remember;
18346 fde = current_fde ();
18347 gcc_assert (fde != NULL);
18349 section = secname_for_decl (current_function_decl);
18353 memset (&next_cfa, 0, sizeof (next_cfa));
18354 next_cfa.reg = INVALID_REGNUM;
18355 remember = next_cfa;
18357 start_label = fde->dw_fde_begin;
18359 /* ??? Bald assumption that the CIE opcode list does not contain
18360 advance opcodes. */
18361 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
18362 lookup_cfa_1 (cfi, &next_cfa, &remember);
18364 last_cfa = next_cfa;
18365 last_label = start_label;
18367 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
18369 /* If the first partition contained no CFI adjustments, the
18370 CIE opcodes apply to the whole first partition. */
18371 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18372 fde->dw_fde_begin, fde->dw_fde_end, section);
18373 list_tail =&(*list_tail)->dw_loc_next;
18374 start_label = last_label = fde->dw_fde_second_begin;
18377 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
18379 switch (cfi->dw_cfi_opc)
18381 case DW_CFA_set_loc:
18382 case DW_CFA_advance_loc1:
18383 case DW_CFA_advance_loc2:
18384 case DW_CFA_advance_loc4:
18385 if (!cfa_equal_p (&last_cfa, &next_cfa))
18387 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18388 start_label, last_label, section);
18390 list_tail = &(*list_tail)->dw_loc_next;
18391 last_cfa = next_cfa;
18392 start_label = last_label;
18394 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
18397 case DW_CFA_advance_loc:
18398 /* The encoding is complex enough that we should never emit this. */
18399 gcc_unreachable ();
18402 lookup_cfa_1 (cfi, &next_cfa, &remember);
18405 if (ix + 1 == fde->dw_fde_switch_cfi_index)
18407 if (!cfa_equal_p (&last_cfa, &next_cfa))
18409 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18410 start_label, last_label, section);
18412 list_tail = &(*list_tail)->dw_loc_next;
18413 last_cfa = next_cfa;
18414 start_label = last_label;
18416 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18417 start_label, fde->dw_fde_end, section);
18418 list_tail = &(*list_tail)->dw_loc_next;
18419 start_label = last_label = fde->dw_fde_second_begin;
18423 if (!cfa_equal_p (&last_cfa, &next_cfa))
18425 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18426 start_label, last_label, section);
18427 list_tail = &(*list_tail)->dw_loc_next;
18428 start_label = last_label;
18431 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
18433 fde->dw_fde_second_begin
18434 ? fde->dw_fde_second_end : fde->dw_fde_end,
18437 if (list && list->dw_loc_next)
18443 /* Compute a displacement from the "steady-state frame pointer" to the
18444 frame base (often the same as the CFA), and store it in
18445 frame_pointer_fb_offset. OFFSET is added to the displacement
18446 before the latter is negated. */
18449 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
18453 #ifdef FRAME_POINTER_CFA_OFFSET
18454 reg = frame_pointer_rtx;
18455 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
18457 reg = arg_pointer_rtx;
18458 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
18461 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
18462 if (GET_CODE (elim) == PLUS)
18464 offset += INTVAL (XEXP (elim, 1));
18465 elim = XEXP (elim, 0);
18468 frame_pointer_fb_offset = -offset;
18470 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
18471 in which to eliminate. This is because it's stack pointer isn't
18472 directly accessible as a register within the ISA. To work around
18473 this, assume that while we cannot provide a proper value for
18474 frame_pointer_fb_offset, we won't need one either. */
18475 frame_pointer_fb_offset_valid
18476 = ((SUPPORTS_STACK_ALIGNMENT
18477 && (elim == hard_frame_pointer_rtx
18478 || elim == stack_pointer_rtx))
18479 || elim == (frame_pointer_needed
18480 ? hard_frame_pointer_rtx
18481 : stack_pointer_rtx));
18484 /* Generate a DW_AT_name attribute given some string value to be included as
18485 the value of the attribute. */
18488 add_name_attribute (dw_die_ref die, const char *name_string)
18490 if (name_string != NULL && *name_string != 0)
18492 if (demangle_name_func)
18493 name_string = (*demangle_name_func) (name_string);
18495 add_AT_string (die, DW_AT_name, name_string);
18499 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
18500 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
18501 of TYPE accordingly.
18503 ??? This is a temporary measure until after we're able to generate
18504 regular DWARF for the complex Ada type system. */
18507 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
18508 dw_die_ref context_die)
18511 dw_die_ref dtype_die;
18513 if (!lang_hooks.types.descriptive_type)
18516 dtype = lang_hooks.types.descriptive_type (type);
18520 dtype_die = lookup_type_die (dtype);
18523 gen_type_die (dtype, context_die);
18524 dtype_die = lookup_type_die (dtype);
18525 gcc_assert (dtype_die);
18528 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
18531 /* Generate a DW_AT_comp_dir attribute for DIE. */
18534 add_comp_dir_attribute (dw_die_ref die)
18536 const char *wd = get_src_pwd ();
18542 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
18546 wdlen = strlen (wd);
18547 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
18549 wd1 [wdlen] = DIR_SEPARATOR;
18550 wd1 [wdlen + 1] = 0;
18554 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
18557 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
18561 lower_bound_default (void)
18563 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
18568 case DW_LANG_C_plus_plus:
18570 case DW_LANG_ObjC_plus_plus:
18573 case DW_LANG_Fortran77:
18574 case DW_LANG_Fortran90:
18575 case DW_LANG_Fortran95:
18579 case DW_LANG_Python:
18580 return dwarf_version >= 4 ? 0 : -1;
18581 case DW_LANG_Ada95:
18582 case DW_LANG_Ada83:
18583 case DW_LANG_Cobol74:
18584 case DW_LANG_Cobol85:
18585 case DW_LANG_Pascal83:
18586 case DW_LANG_Modula2:
18588 return dwarf_version >= 4 ? 1 : -1;
18594 /* Given a tree node describing an array bound (either lower or upper) output
18595 a representation for that bound. */
18598 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
18600 switch (TREE_CODE (bound))
18605 /* All fixed-bounds are represented by INTEGER_CST nodes. */
18608 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
18611 /* Use the default if possible. */
18612 if (bound_attr == DW_AT_lower_bound
18613 && host_integerp (bound, 0)
18614 && (dflt = lower_bound_default ()) != -1
18615 && tree_low_cst (bound, 0) == dflt)
18618 /* Otherwise represent the bound as an unsigned value with the
18619 precision of its type. The precision and signedness of the
18620 type will be necessary to re-interpret it unambiguously. */
18621 else if (prec < HOST_BITS_PER_WIDE_INT)
18623 unsigned HOST_WIDE_INT mask
18624 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
18625 add_AT_unsigned (subrange_die, bound_attr,
18626 TREE_INT_CST_LOW (bound) & mask);
18628 else if (prec == HOST_BITS_PER_WIDE_INT
18629 || TREE_INT_CST_HIGH (bound) == 0)
18630 add_AT_unsigned (subrange_die, bound_attr,
18631 TREE_INT_CST_LOW (bound));
18633 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
18634 TREE_INT_CST_LOW (bound));
18639 case VIEW_CONVERT_EXPR:
18640 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
18650 dw_die_ref decl_die = lookup_decl_die (bound);
18652 /* ??? Can this happen, or should the variable have been bound
18653 first? Probably it can, since I imagine that we try to create
18654 the types of parameters in the order in which they exist in
18655 the list, and won't have created a forward reference to a
18656 later parameter. */
18657 if (decl_die != NULL)
18659 add_AT_die_ref (subrange_die, bound_attr, decl_die);
18667 /* Otherwise try to create a stack operation procedure to
18668 evaluate the value of the array bound. */
18670 dw_die_ref ctx, decl_die;
18671 dw_loc_list_ref list;
18673 list = loc_list_from_tree (bound, 2);
18674 if (list == NULL || single_element_loc_list_p (list))
18676 /* If DW_AT_*bound is not a reference nor constant, it is
18677 a DWARF expression rather than location description.
18678 For that loc_list_from_tree (bound, 0) is needed.
18679 If that fails to give a single element list,
18680 fall back to outputting this as a reference anyway. */
18681 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
18682 if (list2 && single_element_loc_list_p (list2))
18684 add_AT_loc (subrange_die, bound_attr, list2->expr);
18691 if (current_function_decl == 0)
18692 ctx = comp_unit_die ();
18694 ctx = lookup_decl_die (current_function_decl);
18696 decl_die = new_die (DW_TAG_variable, ctx, bound);
18697 add_AT_flag (decl_die, DW_AT_artificial, 1);
18698 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
18699 add_AT_location_description (decl_die, DW_AT_location, list);
18700 add_AT_die_ref (subrange_die, bound_attr, decl_die);
18706 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
18707 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
18708 Note that the block of subscript information for an array type also
18709 includes information about the element type of the given array type. */
18712 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
18714 unsigned dimension_number;
18716 dw_die_ref subrange_die;
18718 for (dimension_number = 0;
18719 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
18720 type = TREE_TYPE (type), dimension_number++)
18722 tree domain = TYPE_DOMAIN (type);
18724 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
18727 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
18728 and (in GNU C only) variable bounds. Handle all three forms
18730 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
18733 /* We have an array type with specified bounds. */
18734 lower = TYPE_MIN_VALUE (domain);
18735 upper = TYPE_MAX_VALUE (domain);
18737 /* Define the index type. */
18738 if (TREE_TYPE (domain))
18740 /* ??? This is probably an Ada unnamed subrange type. Ignore the
18741 TREE_TYPE field. We can't emit debug info for this
18742 because it is an unnamed integral type. */
18743 if (TREE_CODE (domain) == INTEGER_TYPE
18744 && TYPE_NAME (domain) == NULL_TREE
18745 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
18746 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
18749 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
18753 /* ??? If upper is NULL, the array has unspecified length,
18754 but it does have a lower bound. This happens with Fortran
18756 Since the debugger is definitely going to need to know N
18757 to produce useful results, go ahead and output the lower
18758 bound solo, and hope the debugger can cope. */
18760 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
18762 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
18765 /* Otherwise we have an array type with an unspecified length. The
18766 DWARF-2 spec does not say how to handle this; let's just leave out the
18772 add_byte_size_attribute (dw_die_ref die, tree tree_node)
18776 switch (TREE_CODE (tree_node))
18781 case ENUMERAL_TYPE:
18784 case QUAL_UNION_TYPE:
18785 size = int_size_in_bytes (tree_node);
18788 /* For a data member of a struct or union, the DW_AT_byte_size is
18789 generally given as the number of bytes normally allocated for an
18790 object of the *declared* type of the member itself. This is true
18791 even for bit-fields. */
18792 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
18795 gcc_unreachable ();
18798 /* Note that `size' might be -1 when we get to this point. If it is, that
18799 indicates that the byte size of the entity in question is variable. We
18800 have no good way of expressing this fact in Dwarf at the present time,
18801 so just let the -1 pass on through. */
18802 add_AT_unsigned (die, DW_AT_byte_size, size);
18805 /* For a FIELD_DECL node which represents a bit-field, output an attribute
18806 which specifies the distance in bits from the highest order bit of the
18807 "containing object" for the bit-field to the highest order bit of the
18810 For any given bit-field, the "containing object" is a hypothetical object
18811 (of some integral or enum type) within which the given bit-field lives. The
18812 type of this hypothetical "containing object" is always the same as the
18813 declared type of the individual bit-field itself. The determination of the
18814 exact location of the "containing object" for a bit-field is rather
18815 complicated. It's handled by the `field_byte_offset' function (above).
18817 Note that it is the size (in bytes) of the hypothetical "containing object"
18818 which will be given in the DW_AT_byte_size attribute for this bit-field.
18819 (See `byte_size_attribute' above). */
18822 add_bit_offset_attribute (dw_die_ref die, tree decl)
18824 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
18825 tree type = DECL_BIT_FIELD_TYPE (decl);
18826 HOST_WIDE_INT bitpos_int;
18827 HOST_WIDE_INT highest_order_object_bit_offset;
18828 HOST_WIDE_INT highest_order_field_bit_offset;
18829 HOST_WIDE_INT bit_offset;
18831 /* Must be a field and a bit field. */
18832 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
18834 /* We can't yet handle bit-fields whose offsets are variable, so if we
18835 encounter such things, just return without generating any attribute
18836 whatsoever. Likewise for variable or too large size. */
18837 if (! host_integerp (bit_position (decl), 0)
18838 || ! host_integerp (DECL_SIZE (decl), 1))
18841 bitpos_int = int_bit_position (decl);
18843 /* Note that the bit offset is always the distance (in bits) from the
18844 highest-order bit of the "containing object" to the highest-order bit of
18845 the bit-field itself. Since the "high-order end" of any object or field
18846 is different on big-endian and little-endian machines, the computation
18847 below must take account of these differences. */
18848 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
18849 highest_order_field_bit_offset = bitpos_int;
18851 if (! BYTES_BIG_ENDIAN)
18853 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
18854 highest_order_object_bit_offset += simple_type_size_in_bits (type);
18858 = (! BYTES_BIG_ENDIAN
18859 ? highest_order_object_bit_offset - highest_order_field_bit_offset
18860 : highest_order_field_bit_offset - highest_order_object_bit_offset);
18862 if (bit_offset < 0)
18863 add_AT_int (die, DW_AT_bit_offset, bit_offset);
18865 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
18868 /* For a FIELD_DECL node which represents a bit field, output an attribute
18869 which specifies the length in bits of the given field. */
18872 add_bit_size_attribute (dw_die_ref die, tree decl)
18874 /* Must be a field and a bit field. */
18875 gcc_assert (TREE_CODE (decl) == FIELD_DECL
18876 && DECL_BIT_FIELD_TYPE (decl));
18878 if (host_integerp (DECL_SIZE (decl), 1))
18879 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
18882 /* If the compiled language is ANSI C, then add a 'prototyped'
18883 attribute, if arg types are given for the parameters of a function. */
18886 add_prototyped_attribute (dw_die_ref die, tree func_type)
18888 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
18889 && prototype_p (func_type))
18890 add_AT_flag (die, DW_AT_prototyped, 1);
18893 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
18894 by looking in either the type declaration or object declaration
18897 static inline dw_die_ref
18898 add_abstract_origin_attribute (dw_die_ref die, tree origin)
18900 dw_die_ref origin_die = NULL;
18902 if (TREE_CODE (origin) != FUNCTION_DECL)
18904 /* We may have gotten separated from the block for the inlined
18905 function, if we're in an exception handler or some such; make
18906 sure that the abstract function has been written out.
18908 Doing this for nested functions is wrong, however; functions are
18909 distinct units, and our context might not even be inline. */
18913 fn = TYPE_STUB_DECL (fn);
18915 fn = decl_function_context (fn);
18917 dwarf2out_abstract_function (fn);
18920 if (DECL_P (origin))
18921 origin_die = lookup_decl_die (origin);
18922 else if (TYPE_P (origin))
18923 origin_die = lookup_type_die (origin);
18925 /* XXX: Functions that are never lowered don't always have correct block
18926 trees (in the case of java, they simply have no block tree, in some other
18927 languages). For these functions, there is nothing we can really do to
18928 output correct debug info for inlined functions in all cases. Rather
18929 than die, we'll just produce deficient debug info now, in that we will
18930 have variables without a proper abstract origin. In the future, when all
18931 functions are lowered, we should re-add a gcc_assert (origin_die)
18935 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
18939 /* We do not currently support the pure_virtual attribute. */
18942 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
18944 if (DECL_VINDEX (func_decl))
18946 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18948 if (host_integerp (DECL_VINDEX (func_decl), 0))
18949 add_AT_loc (die, DW_AT_vtable_elem_location,
18950 new_loc_descr (DW_OP_constu,
18951 tree_low_cst (DECL_VINDEX (func_decl), 0),
18954 /* GNU extension: Record what type this method came from originally. */
18955 if (debug_info_level > DINFO_LEVEL_TERSE
18956 && DECL_CONTEXT (func_decl))
18957 add_AT_die_ref (die, DW_AT_containing_type,
18958 lookup_type_die (DECL_CONTEXT (func_decl)));
18962 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
18963 given decl. This used to be a vendor extension until after DWARF 4
18964 standardized it. */
18967 add_linkage_attr (dw_die_ref die, tree decl)
18969 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
18971 /* Mimic what assemble_name_raw does with a leading '*'. */
18972 if (name[0] == '*')
18975 if (dwarf_version >= 4)
18976 add_AT_string (die, DW_AT_linkage_name, name);
18978 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
18981 /* Add source coordinate attributes for the given decl. */
18984 add_src_coords_attributes (dw_die_ref die, tree decl)
18986 expanded_location s;
18988 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
18990 s = expand_location (DECL_SOURCE_LOCATION (decl));
18991 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
18992 add_AT_unsigned (die, DW_AT_decl_line, s.line);
18995 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
18998 add_linkage_name (dw_die_ref die, tree decl)
19000 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
19001 && TREE_PUBLIC (decl)
19002 && !DECL_ABSTRACT (decl)
19003 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
19004 && die->die_tag != DW_TAG_member)
19006 /* Defer until we have an assembler name set. */
19007 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
19009 limbo_die_node *asm_name;
19011 asm_name = ggc_alloc_cleared_limbo_die_node ();
19012 asm_name->die = die;
19013 asm_name->created_for = decl;
19014 asm_name->next = deferred_asm_name;
19015 deferred_asm_name = asm_name;
19017 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
19018 add_linkage_attr (die, decl);
19022 /* Add a DW_AT_name attribute and source coordinate attribute for the
19023 given decl, but only if it actually has a name. */
19026 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
19030 decl_name = DECL_NAME (decl);
19031 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
19033 const char *name = dwarf2_name (decl, 0);
19035 add_name_attribute (die, name);
19036 if (! DECL_ARTIFICIAL (decl))
19037 add_src_coords_attributes (die, decl);
19039 add_linkage_name (die, decl);
19042 #ifdef VMS_DEBUGGING_INFO
19043 /* Get the function's name, as described by its RTL. This may be different
19044 from the DECL_NAME name used in the source file. */
19045 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
19047 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
19048 XEXP (DECL_RTL (decl), 0));
19049 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
19051 #endif /* VMS_DEBUGGING_INFO */
19054 #ifdef VMS_DEBUGGING_INFO
19055 /* Output the debug main pointer die for VMS */
19058 dwarf2out_vms_debug_main_pointer (void)
19060 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19063 /* Allocate the VMS debug main subprogram die. */
19064 die = ggc_alloc_cleared_die_node ();
19065 die->die_tag = DW_TAG_subprogram;
19066 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
19067 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
19068 current_function_funcdef_no);
19069 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19071 /* Make it the first child of comp_unit_die (). */
19072 die->die_parent = comp_unit_die ();
19073 if (comp_unit_die ()->die_child)
19075 die->die_sib = comp_unit_die ()->die_child->die_sib;
19076 comp_unit_die ()->die_child->die_sib = die;
19080 die->die_sib = die;
19081 comp_unit_die ()->die_child = die;
19084 #endif /* VMS_DEBUGGING_INFO */
19086 /* Push a new declaration scope. */
19089 push_decl_scope (tree scope)
19091 VEC_safe_push (tree, gc, decl_scope_table, scope);
19094 /* Pop a declaration scope. */
19097 pop_decl_scope (void)
19099 VEC_pop (tree, decl_scope_table);
19102 /* Return the DIE for the scope that immediately contains this type.
19103 Non-named types get global scope. Named types nested in other
19104 types get their containing scope if it's open, or global scope
19105 otherwise. All other types (i.e. function-local named types) get
19106 the current active scope. */
19109 scope_die_for (tree t, dw_die_ref context_die)
19111 dw_die_ref scope_die = NULL;
19112 tree containing_scope;
19115 /* Non-types always go in the current scope. */
19116 gcc_assert (TYPE_P (t));
19118 containing_scope = TYPE_CONTEXT (t);
19120 /* Use the containing namespace if it was passed in (for a declaration). */
19121 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
19123 if (context_die == lookup_decl_die (containing_scope))
19126 containing_scope = NULL_TREE;
19129 /* Ignore function type "scopes" from the C frontend. They mean that
19130 a tagged type is local to a parmlist of a function declarator, but
19131 that isn't useful to DWARF. */
19132 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
19133 containing_scope = NULL_TREE;
19135 if (SCOPE_FILE_SCOPE_P (containing_scope))
19136 scope_die = comp_unit_die ();
19137 else if (TYPE_P (containing_scope))
19139 /* For types, we can just look up the appropriate DIE. But
19140 first we check to see if we're in the middle of emitting it
19141 so we know where the new DIE should go. */
19142 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
19143 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
19148 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
19149 || TREE_ASM_WRITTEN (containing_scope));
19150 /*We are not in the middle of emitting the type
19151 CONTAINING_SCOPE. Let's see if it's emitted already. */
19152 scope_die = lookup_type_die (containing_scope);
19154 /* If none of the current dies are suitable, we get file scope. */
19155 if (scope_die == NULL)
19156 scope_die = comp_unit_die ();
19159 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
19162 scope_die = context_die;
19167 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
19170 local_scope_p (dw_die_ref context_die)
19172 for (; context_die; context_die = context_die->die_parent)
19173 if (context_die->die_tag == DW_TAG_inlined_subroutine
19174 || context_die->die_tag == DW_TAG_subprogram)
19180 /* Returns nonzero if CONTEXT_DIE is a class. */
19183 class_scope_p (dw_die_ref context_die)
19185 return (context_die
19186 && (context_die->die_tag == DW_TAG_structure_type
19187 || context_die->die_tag == DW_TAG_class_type
19188 || context_die->die_tag == DW_TAG_interface_type
19189 || context_die->die_tag == DW_TAG_union_type));
19192 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
19193 whether or not to treat a DIE in this context as a declaration. */
19196 class_or_namespace_scope_p (dw_die_ref context_die)
19198 return (class_scope_p (context_die)
19199 || (context_die && context_die->die_tag == DW_TAG_namespace));
19202 /* Many forms of DIEs require a "type description" attribute. This
19203 routine locates the proper "type descriptor" die for the type given
19204 by 'type', and adds a DW_AT_type attribute below the given die. */
19207 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
19208 int decl_volatile, dw_die_ref context_die)
19210 enum tree_code code = TREE_CODE (type);
19211 dw_die_ref type_die = NULL;
19213 /* ??? If this type is an unnamed subrange type of an integral, floating-point
19214 or fixed-point type, use the inner type. This is because we have no
19215 support for unnamed types in base_type_die. This can happen if this is
19216 an Ada subrange type. Correct solution is emit a subrange type die. */
19217 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
19218 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
19219 type = TREE_TYPE (type), code = TREE_CODE (type);
19221 if (code == ERROR_MARK
19222 /* Handle a special case. For functions whose return type is void, we
19223 generate *no* type attribute. (Note that no object may have type
19224 `void', so this only applies to function return types). */
19225 || code == VOID_TYPE)
19228 type_die = modified_type_die (type,
19229 decl_const || TYPE_READONLY (type),
19230 decl_volatile || TYPE_VOLATILE (type),
19233 if (type_die != NULL)
19234 add_AT_die_ref (object_die, DW_AT_type, type_die);
19237 /* Given an object die, add the calling convention attribute for the
19238 function call type. */
19240 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
19242 enum dwarf_calling_convention value = DW_CC_normal;
19244 value = ((enum dwarf_calling_convention)
19245 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
19248 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
19250 /* DWARF 2 doesn't provide a way to identify a program's source-level
19251 entry point. DW_AT_calling_convention attributes are only meant
19252 to describe functions' calling conventions. However, lacking a
19253 better way to signal the Fortran main program, we used this for
19254 a long time, following existing custom. Now, DWARF 4 has
19255 DW_AT_main_subprogram, which we add below, but some tools still
19256 rely on the old way, which we thus keep. */
19257 value = DW_CC_program;
19259 if (dwarf_version >= 4 || !dwarf_strict)
19260 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
19263 /* Only add the attribute if the backend requests it, and
19264 is not DW_CC_normal. */
19265 if (value && (value != DW_CC_normal))
19266 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
19269 /* Given a tree pointer to a struct, class, union, or enum type node, return
19270 a pointer to the (string) tag name for the given type, or zero if the type
19271 was declared without a tag. */
19273 static const char *
19274 type_tag (const_tree type)
19276 const char *name = 0;
19278 if (TYPE_NAME (type) != 0)
19282 /* Find the IDENTIFIER_NODE for the type name. */
19283 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
19284 && !TYPE_NAMELESS (type))
19285 t = TYPE_NAME (type);
19287 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
19288 a TYPE_DECL node, regardless of whether or not a `typedef' was
19290 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
19291 && ! DECL_IGNORED_P (TYPE_NAME (type)))
19293 /* We want to be extra verbose. Don't call dwarf_name if
19294 DECL_NAME isn't set. The default hook for decl_printable_name
19295 doesn't like that, and in this context it's correct to return
19296 0, instead of "<anonymous>" or the like. */
19297 if (DECL_NAME (TYPE_NAME (type))
19298 && !DECL_NAMELESS (TYPE_NAME (type)))
19299 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
19302 /* Now get the name as a string, or invent one. */
19303 if (!name && t != 0)
19304 name = IDENTIFIER_POINTER (t);
19307 return (name == 0 || *name == '\0') ? 0 : name;
19310 /* Return the type associated with a data member, make a special check
19311 for bit field types. */
19314 member_declared_type (const_tree member)
19316 return (DECL_BIT_FIELD_TYPE (member)
19317 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
19320 /* Get the decl's label, as described by its RTL. This may be different
19321 from the DECL_NAME name used in the source file. */
19324 static const char *
19325 decl_start_label (tree decl)
19328 const char *fnname;
19330 x = DECL_RTL (decl);
19331 gcc_assert (MEM_P (x));
19334 gcc_assert (GET_CODE (x) == SYMBOL_REF);
19336 fnname = XSTR (x, 0);
19341 /* These routines generate the internal representation of the DIE's for
19342 the compilation unit. Debugging information is collected by walking
19343 the declaration trees passed in from dwarf2out_decl(). */
19346 gen_array_type_die (tree type, dw_die_ref context_die)
19348 dw_die_ref scope_die = scope_die_for (type, context_die);
19349 dw_die_ref array_die;
19351 /* GNU compilers represent multidimensional array types as sequences of one
19352 dimensional array types whose element types are themselves array types.
19353 We sometimes squish that down to a single array_type DIE with multiple
19354 subscripts in the Dwarf debugging info. The draft Dwarf specification
19355 say that we are allowed to do this kind of compression in C, because
19356 there is no difference between an array of arrays and a multidimensional
19357 array. We don't do this for Ada to remain as close as possible to the
19358 actual representation, which is especially important against the language
19359 flexibilty wrt arrays of variable size. */
19361 bool collapse_nested_arrays = !is_ada ();
19364 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
19365 DW_TAG_string_type doesn't have DW_AT_type attribute). */
19366 if (TYPE_STRING_FLAG (type)
19367 && TREE_CODE (type) == ARRAY_TYPE
19369 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
19371 HOST_WIDE_INT size;
19373 array_die = new_die (DW_TAG_string_type, scope_die, type);
19374 add_name_attribute (array_die, type_tag (type));
19375 equate_type_number_to_die (type, array_die);
19376 size = int_size_in_bytes (type);
19378 add_AT_unsigned (array_die, DW_AT_byte_size, size);
19379 else if (TYPE_DOMAIN (type) != NULL_TREE
19380 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
19381 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
19383 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
19384 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
19386 size = int_size_in_bytes (TREE_TYPE (szdecl));
19387 if (loc && size > 0)
19389 add_AT_location_description (array_die, DW_AT_string_length, loc);
19390 if (size != DWARF2_ADDR_SIZE)
19391 add_AT_unsigned (array_die, DW_AT_byte_size, size);
19397 /* ??? The SGI dwarf reader fails for array of array of enum types
19398 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
19399 array type comes before the outer array type. We thus call gen_type_die
19400 before we new_die and must prevent nested array types collapsing for this
19403 #ifdef MIPS_DEBUGGING_INFO
19404 gen_type_die (TREE_TYPE (type), context_die);
19405 collapse_nested_arrays = false;
19408 array_die = new_die (DW_TAG_array_type, scope_die, type);
19409 add_name_attribute (array_die, type_tag (type));
19410 add_gnat_descriptive_type_attribute (array_die, type, context_die);
19411 equate_type_number_to_die (type, array_die);
19413 if (TREE_CODE (type) == VECTOR_TYPE)
19414 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
19416 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19418 && TREE_CODE (type) == ARRAY_TYPE
19419 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
19420 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
19421 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
19424 /* We default the array ordering. SDB will probably do
19425 the right things even if DW_AT_ordering is not present. It's not even
19426 an issue until we start to get into multidimensional arrays anyway. If
19427 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
19428 then we'll have to put the DW_AT_ordering attribute back in. (But if
19429 and when we find out that we need to put these in, we will only do so
19430 for multidimensional arrays. */
19431 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
19434 #ifdef MIPS_DEBUGGING_INFO
19435 /* The SGI compilers handle arrays of unknown bound by setting
19436 AT_declaration and not emitting any subrange DIEs. */
19437 if (TREE_CODE (type) == ARRAY_TYPE
19438 && ! TYPE_DOMAIN (type))
19439 add_AT_flag (array_die, DW_AT_declaration, 1);
19442 if (TREE_CODE (type) == VECTOR_TYPE)
19444 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
19445 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
19446 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
19447 add_bound_info (subrange_die, DW_AT_upper_bound,
19448 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
19451 add_subscript_info (array_die, type, collapse_nested_arrays);
19453 /* Add representation of the type of the elements of this array type and
19454 emit the corresponding DIE if we haven't done it already. */
19455 element_type = TREE_TYPE (type);
19456 if (collapse_nested_arrays)
19457 while (TREE_CODE (element_type) == ARRAY_TYPE)
19459 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
19461 element_type = TREE_TYPE (element_type);
19464 #ifndef MIPS_DEBUGGING_INFO
19465 gen_type_die (element_type, context_die);
19468 add_type_attribute (array_die, element_type, 0, 0, context_die);
19470 if (get_AT (array_die, DW_AT_name))
19471 add_pubtype (type, array_die);
19474 static dw_loc_descr_ref
19475 descr_info_loc (tree val, tree base_decl)
19477 HOST_WIDE_INT size;
19478 dw_loc_descr_ref loc, loc2;
19479 enum dwarf_location_atom op;
19481 if (val == base_decl)
19482 return new_loc_descr (DW_OP_push_object_address, 0, 0);
19484 switch (TREE_CODE (val))
19487 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19489 return loc_descriptor_from_tree (val, 0);
19491 if (host_integerp (val, 0))
19492 return int_loc_descriptor (tree_low_cst (val, 0));
19495 size = int_size_in_bytes (TREE_TYPE (val));
19498 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19501 if (size == DWARF2_ADDR_SIZE)
19502 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
19504 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
19506 case POINTER_PLUS_EXPR:
19508 if (host_integerp (TREE_OPERAND (val, 1), 1)
19509 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
19512 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19515 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
19521 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19524 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
19527 add_loc_descr (&loc, loc2);
19528 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
19550 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
19551 tree val, tree base_decl)
19553 dw_loc_descr_ref loc;
19555 if (host_integerp (val, 0))
19557 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
19561 loc = descr_info_loc (val, base_decl);
19565 add_AT_loc (die, attr, loc);
19568 /* This routine generates DIE for array with hidden descriptor, details
19569 are filled into *info by a langhook. */
19572 gen_descr_array_type_die (tree type, struct array_descr_info *info,
19573 dw_die_ref context_die)
19575 dw_die_ref scope_die = scope_die_for (type, context_die);
19576 dw_die_ref array_die;
19579 array_die = new_die (DW_TAG_array_type, scope_die, type);
19580 add_name_attribute (array_die, type_tag (type));
19581 equate_type_number_to_die (type, array_die);
19583 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19585 && info->ndimensions >= 2)
19586 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
19588 if (info->data_location)
19589 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
19591 if (info->associated)
19592 add_descr_info_field (array_die, DW_AT_associated, info->associated,
19594 if (info->allocated)
19595 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
19598 for (dim = 0; dim < info->ndimensions; dim++)
19600 dw_die_ref subrange_die
19601 = new_die (DW_TAG_subrange_type, array_die, NULL);
19603 if (info->dimen[dim].lower_bound)
19605 /* If it is the default value, omit it. */
19608 if (host_integerp (info->dimen[dim].lower_bound, 0)
19609 && (dflt = lower_bound_default ()) != -1
19610 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
19613 add_descr_info_field (subrange_die, DW_AT_lower_bound,
19614 info->dimen[dim].lower_bound,
19617 if (info->dimen[dim].upper_bound)
19618 add_descr_info_field (subrange_die, DW_AT_upper_bound,
19619 info->dimen[dim].upper_bound,
19621 if (info->dimen[dim].stride)
19622 add_descr_info_field (subrange_die, DW_AT_byte_stride,
19623 info->dimen[dim].stride,
19627 gen_type_die (info->element_type, context_die);
19628 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
19630 if (get_AT (array_die, DW_AT_name))
19631 add_pubtype (type, array_die);
19636 gen_entry_point_die (tree decl, dw_die_ref context_die)
19638 tree origin = decl_ultimate_origin (decl);
19639 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
19641 if (origin != NULL)
19642 add_abstract_origin_attribute (decl_die, origin);
19645 add_name_and_src_coords_attributes (decl_die, decl);
19646 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
19647 0, 0, context_die);
19650 if (DECL_ABSTRACT (decl))
19651 equate_decl_number_to_die (decl, decl_die);
19653 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
19657 /* Walk through the list of incomplete types again, trying once more to
19658 emit full debugging info for them. */
19661 retry_incomplete_types (void)
19665 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
19666 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
19667 DINFO_USAGE_DIR_USE))
19668 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
19671 /* Determine what tag to use for a record type. */
19673 static enum dwarf_tag
19674 record_type_tag (tree type)
19676 if (! lang_hooks.types.classify_record)
19677 return DW_TAG_structure_type;
19679 switch (lang_hooks.types.classify_record (type))
19681 case RECORD_IS_STRUCT:
19682 return DW_TAG_structure_type;
19684 case RECORD_IS_CLASS:
19685 return DW_TAG_class_type;
19687 case RECORD_IS_INTERFACE:
19688 if (dwarf_version >= 3 || !dwarf_strict)
19689 return DW_TAG_interface_type;
19690 return DW_TAG_structure_type;
19693 gcc_unreachable ();
19697 /* Generate a DIE to represent an enumeration type. Note that these DIEs
19698 include all of the information about the enumeration values also. Each
19699 enumerated type name/value is listed as a child of the enumerated type
19703 gen_enumeration_type_die (tree type, dw_die_ref context_die)
19705 dw_die_ref type_die = lookup_type_die (type);
19707 if (type_die == NULL)
19709 type_die = new_die (DW_TAG_enumeration_type,
19710 scope_die_for (type, context_die), type);
19711 equate_type_number_to_die (type, type_die);
19712 add_name_attribute (type_die, type_tag (type));
19713 add_gnat_descriptive_type_attribute (type_die, type, context_die);
19714 if (dwarf_version >= 4 || !dwarf_strict)
19716 if (ENUM_IS_SCOPED (type))
19717 add_AT_flag (type_die, DW_AT_enum_class, 1);
19718 if (ENUM_IS_OPAQUE (type))
19719 add_AT_flag (type_die, DW_AT_declaration, 1);
19722 else if (! TYPE_SIZE (type))
19725 remove_AT (type_die, DW_AT_declaration);
19727 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
19728 given enum type is incomplete, do not generate the DW_AT_byte_size
19729 attribute or the DW_AT_element_list attribute. */
19730 if (TYPE_SIZE (type))
19734 TREE_ASM_WRITTEN (type) = 1;
19735 add_byte_size_attribute (type_die, type);
19736 if (TYPE_STUB_DECL (type) != NULL_TREE)
19738 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
19739 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
19742 /* If the first reference to this type was as the return type of an
19743 inline function, then it may not have a parent. Fix this now. */
19744 if (type_die->die_parent == NULL)
19745 add_child_die (scope_die_for (type, context_die), type_die);
19747 for (link = TYPE_VALUES (type);
19748 link != NULL; link = TREE_CHAIN (link))
19750 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
19751 tree value = TREE_VALUE (link);
19753 add_name_attribute (enum_die,
19754 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
19756 if (TREE_CODE (value) == CONST_DECL)
19757 value = DECL_INITIAL (value);
19759 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
19760 /* DWARF2 does not provide a way of indicating whether or
19761 not enumeration constants are signed or unsigned. GDB
19762 always assumes the values are signed, so we output all
19763 values as if they were signed. That means that
19764 enumeration constants with very large unsigned values
19765 will appear to have negative values in the debugger. */
19766 add_AT_int (enum_die, DW_AT_const_value,
19767 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
19771 add_AT_flag (type_die, DW_AT_declaration, 1);
19773 if (get_AT (type_die, DW_AT_name))
19774 add_pubtype (type, type_die);
19779 /* Generate a DIE to represent either a real live formal parameter decl or to
19780 represent just the type of some formal parameter position in some function
19783 Note that this routine is a bit unusual because its argument may be a
19784 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
19785 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
19786 node. If it's the former then this function is being called to output a
19787 DIE to represent a formal parameter object (or some inlining thereof). If
19788 it's the latter, then this function is only being called to output a
19789 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
19790 argument type of some subprogram type.
19791 If EMIT_NAME_P is true, name and source coordinate attributes
19795 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
19796 dw_die_ref context_die)
19798 tree node_or_origin = node ? node : origin;
19799 tree ultimate_origin;
19800 dw_die_ref parm_die
19801 = new_die (DW_TAG_formal_parameter, context_die, node);
19803 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
19805 case tcc_declaration:
19806 ultimate_origin = decl_ultimate_origin (node_or_origin);
19807 if (node || ultimate_origin)
19808 origin = ultimate_origin;
19809 if (origin != NULL)
19810 add_abstract_origin_attribute (parm_die, origin);
19811 else if (emit_name_p)
19812 add_name_and_src_coords_attributes (parm_die, node);
19814 || (! DECL_ABSTRACT (node_or_origin)
19815 && variably_modified_type_p (TREE_TYPE (node_or_origin),
19816 decl_function_context
19817 (node_or_origin))))
19819 tree type = TREE_TYPE (node_or_origin);
19820 if (decl_by_reference_p (node_or_origin))
19821 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
19824 add_type_attribute (parm_die, type,
19825 TREE_READONLY (node_or_origin),
19826 TREE_THIS_VOLATILE (node_or_origin),
19829 if (origin == NULL && DECL_ARTIFICIAL (node))
19830 add_AT_flag (parm_die, DW_AT_artificial, 1);
19832 if (node && node != origin)
19833 equate_decl_number_to_die (node, parm_die);
19834 if (! DECL_ABSTRACT (node_or_origin))
19835 add_location_or_const_value_attribute (parm_die, node_or_origin,
19836 node == NULL, DW_AT_location);
19841 /* We were called with some kind of a ..._TYPE node. */
19842 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
19846 gcc_unreachable ();
19852 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
19853 children DW_TAG_formal_parameter DIEs representing the arguments of the
19856 PARM_PACK must be a function parameter pack.
19857 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
19858 must point to the subsequent arguments of the function PACK_ARG belongs to.
19859 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
19860 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
19861 following the last one for which a DIE was generated. */
19864 gen_formal_parameter_pack_die (tree parm_pack,
19866 dw_die_ref subr_die,
19870 dw_die_ref parm_pack_die;
19872 gcc_assert (parm_pack
19873 && lang_hooks.function_parameter_pack_p (parm_pack)
19876 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
19877 add_src_coords_attributes (parm_pack_die, parm_pack);
19879 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
19881 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
19884 gen_formal_parameter_die (arg, NULL,
19885 false /* Don't emit name attribute. */,
19890 return parm_pack_die;
19893 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
19894 at the end of an (ANSI prototyped) formal parameters list. */
19897 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
19899 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
19902 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
19903 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
19904 parameters as specified in some function type specification (except for
19905 those which appear as part of a function *definition*). */
19908 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
19911 tree formal_type = NULL;
19912 tree first_parm_type;
19915 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
19917 arg = DECL_ARGUMENTS (function_or_method_type);
19918 function_or_method_type = TREE_TYPE (function_or_method_type);
19923 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
19925 /* Make our first pass over the list of formal parameter types and output a
19926 DW_TAG_formal_parameter DIE for each one. */
19927 for (link = first_parm_type; link; )
19929 dw_die_ref parm_die;
19931 formal_type = TREE_VALUE (link);
19932 if (formal_type == void_type_node)
19935 /* Output a (nameless) DIE to represent the formal parameter itself. */
19936 parm_die = gen_formal_parameter_die (formal_type, NULL,
19937 true /* Emit name attribute. */,
19939 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
19940 && link == first_parm_type)
19942 add_AT_flag (parm_die, DW_AT_artificial, 1);
19943 if (dwarf_version >= 3 || !dwarf_strict)
19944 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
19946 else if (arg && DECL_ARTIFICIAL (arg))
19947 add_AT_flag (parm_die, DW_AT_artificial, 1);
19949 link = TREE_CHAIN (link);
19951 arg = DECL_CHAIN (arg);
19954 /* If this function type has an ellipsis, add a
19955 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
19956 if (formal_type != void_type_node)
19957 gen_unspecified_parameters_die (function_or_method_type, context_die);
19959 /* Make our second (and final) pass over the list of formal parameter types
19960 and output DIEs to represent those types (as necessary). */
19961 for (link = TYPE_ARG_TYPES (function_or_method_type);
19962 link && TREE_VALUE (link);
19963 link = TREE_CHAIN (link))
19964 gen_type_die (TREE_VALUE (link), context_die);
19967 /* We want to generate the DIE for TYPE so that we can generate the
19968 die for MEMBER, which has been defined; we will need to refer back
19969 to the member declaration nested within TYPE. If we're trying to
19970 generate minimal debug info for TYPE, processing TYPE won't do the
19971 trick; we need to attach the member declaration by hand. */
19974 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
19976 gen_type_die (type, context_die);
19978 /* If we're trying to avoid duplicate debug info, we may not have
19979 emitted the member decl for this function. Emit it now. */
19980 if (TYPE_STUB_DECL (type)
19981 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
19982 && ! lookup_decl_die (member))
19984 dw_die_ref type_die;
19985 gcc_assert (!decl_ultimate_origin (member));
19987 push_decl_scope (type);
19988 type_die = lookup_type_die_strip_naming_typedef (type);
19989 if (TREE_CODE (member) == FUNCTION_DECL)
19990 gen_subprogram_die (member, type_die);
19991 else if (TREE_CODE (member) == FIELD_DECL)
19993 /* Ignore the nameless fields that are used to skip bits but handle
19994 C++ anonymous unions and structs. */
19995 if (DECL_NAME (member) != NULL_TREE
19996 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
19997 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
19999 gen_type_die (member_declared_type (member), type_die);
20000 gen_field_die (member, type_die);
20004 gen_variable_die (member, NULL_TREE, type_die);
20010 /* Generate the DWARF2 info for the "abstract" instance of a function which we
20011 may later generate inlined and/or out-of-line instances of. */
20014 dwarf2out_abstract_function (tree decl)
20016 dw_die_ref old_die;
20020 htab_t old_decl_loc_table;
20021 htab_t old_cached_dw_loc_list_table;
20022 int old_call_site_count, old_tail_call_site_count;
20023 struct call_arg_loc_node *old_call_arg_locations;
20025 /* Make sure we have the actual abstract inline, not a clone. */
20026 decl = DECL_ORIGIN (decl);
20028 old_die = lookup_decl_die (decl);
20029 if (old_die && get_AT (old_die, DW_AT_inline))
20030 /* We've already generated the abstract instance. */
20033 /* We can be called while recursively when seeing block defining inlined subroutine
20034 DIE. Be sure to not clobber the outer location table nor use it or we would
20035 get locations in abstract instantces. */
20036 old_decl_loc_table = decl_loc_table;
20037 decl_loc_table = NULL;
20038 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
20039 cached_dw_loc_list_table = NULL;
20040 old_call_arg_locations = call_arg_locations;
20041 call_arg_locations = NULL;
20042 old_call_site_count = call_site_count;
20043 call_site_count = -1;
20044 old_tail_call_site_count = tail_call_site_count;
20045 tail_call_site_count = -1;
20047 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
20048 we don't get confused by DECL_ABSTRACT. */
20049 if (debug_info_level > DINFO_LEVEL_TERSE)
20051 context = decl_class_context (decl);
20053 gen_type_die_for_member
20054 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
20057 /* Pretend we've just finished compiling this function. */
20058 save_fn = current_function_decl;
20059 current_function_decl = decl;
20060 push_cfun (DECL_STRUCT_FUNCTION (decl));
20062 was_abstract = DECL_ABSTRACT (decl);
20063 set_decl_abstract_flags (decl, 1);
20064 dwarf2out_decl (decl);
20065 if (! was_abstract)
20066 set_decl_abstract_flags (decl, 0);
20068 current_function_decl = save_fn;
20069 decl_loc_table = old_decl_loc_table;
20070 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
20071 call_arg_locations = old_call_arg_locations;
20072 call_site_count = old_call_site_count;
20073 tail_call_site_count = old_tail_call_site_count;
20077 /* Helper function of premark_used_types() which gets called through
20080 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20081 marked as unused by prune_unused_types. */
20084 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
20089 type = (tree) *slot;
20090 die = lookup_type_die (type);
20092 die->die_perennial_p = 1;
20096 /* Helper function of premark_types_used_by_global_vars which gets called
20097 through htab_traverse.
20099 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20100 marked as unused by prune_unused_types. The DIE of the type is marked
20101 only if the global variable using the type will actually be emitted. */
20104 premark_types_used_by_global_vars_helper (void **slot,
20105 void *data ATTRIBUTE_UNUSED)
20107 struct types_used_by_vars_entry *entry;
20110 entry = (struct types_used_by_vars_entry *) *slot;
20111 gcc_assert (entry->type != NULL
20112 && entry->var_decl != NULL);
20113 die = lookup_type_die (entry->type);
20116 /* Ask cgraph if the global variable really is to be emitted.
20117 If yes, then we'll keep the DIE of ENTRY->TYPE. */
20118 struct varpool_node *node = varpool_get_node (entry->var_decl);
20119 if (node && node->needed)
20121 die->die_perennial_p = 1;
20122 /* Keep the parent DIEs as well. */
20123 while ((die = die->die_parent) && die->die_perennial_p == 0)
20124 die->die_perennial_p = 1;
20130 /* Mark all members of used_types_hash as perennial. */
20133 premark_used_types (void)
20135 if (cfun && cfun->used_types_hash)
20136 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
20139 /* Mark all members of types_used_by_vars_entry as perennial. */
20142 premark_types_used_by_global_vars (void)
20144 if (types_used_by_vars_hash)
20145 htab_traverse (types_used_by_vars_hash,
20146 premark_types_used_by_global_vars_helper, NULL);
20149 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
20150 for CA_LOC call arg loc node. */
20153 gen_call_site_die (tree decl, dw_die_ref subr_die,
20154 struct call_arg_loc_node *ca_loc)
20156 dw_die_ref stmt_die = NULL, die;
20157 tree block = ca_loc->block;
20160 && block != DECL_INITIAL (decl)
20161 && TREE_CODE (block) == BLOCK)
20163 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
20164 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
20167 block = BLOCK_SUPERCONTEXT (block);
20169 if (stmt_die == NULL)
20170 stmt_die = subr_die;
20171 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
20172 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
20173 if (ca_loc->tail_call_p)
20174 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
20175 if (ca_loc->symbol_ref)
20177 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
20179 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
20181 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
20186 /* Generate a DIE to represent a declared function (either file-scope or
20190 gen_subprogram_die (tree decl, dw_die_ref context_die)
20192 tree origin = decl_ultimate_origin (decl);
20193 dw_die_ref subr_die;
20195 dw_die_ref old_die = lookup_decl_die (decl);
20196 int declaration = (current_function_decl != decl
20197 || class_or_namespace_scope_p (context_die));
20199 premark_used_types ();
20201 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
20202 started to generate the abstract instance of an inline, decided to output
20203 its containing class, and proceeded to emit the declaration of the inline
20204 from the member list for the class. If so, DECLARATION takes priority;
20205 we'll get back to the abstract instance when done with the class. */
20207 /* The class-scope declaration DIE must be the primary DIE. */
20208 if (origin && declaration && class_or_namespace_scope_p (context_die))
20211 gcc_assert (!old_die);
20214 /* Now that the C++ front end lazily declares artificial member fns, we
20215 might need to retrofit the declaration into its class. */
20216 if (!declaration && !origin && !old_die
20217 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
20218 && !class_or_namespace_scope_p (context_die)
20219 && debug_info_level > DINFO_LEVEL_TERSE)
20220 old_die = force_decl_die (decl);
20222 if (origin != NULL)
20224 gcc_assert (!declaration || local_scope_p (context_die));
20226 /* Fixup die_parent for the abstract instance of a nested
20227 inline function. */
20228 if (old_die && old_die->die_parent == NULL)
20229 add_child_die (context_die, old_die);
20231 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20232 add_abstract_origin_attribute (subr_die, origin);
20233 /* This is where the actual code for a cloned function is.
20234 Let's emit linkage name attribute for it. This helps
20235 debuggers to e.g, set breakpoints into
20236 constructors/destructors when the user asks "break
20238 add_linkage_name (subr_die, decl);
20242 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
20243 struct dwarf_file_data * file_index = lookup_filename (s.file);
20245 if (!get_AT_flag (old_die, DW_AT_declaration)
20246 /* We can have a normal definition following an inline one in the
20247 case of redefinition of GNU C extern inlines.
20248 It seems reasonable to use AT_specification in this case. */
20249 && !get_AT (old_die, DW_AT_inline))
20251 /* Detect and ignore this case, where we are trying to output
20252 something we have already output. */
20256 /* If the definition comes from the same place as the declaration,
20257 maybe use the old DIE. We always want the DIE for this function
20258 that has the *_pc attributes to be under comp_unit_die so the
20259 debugger can find it. We also need to do this for abstract
20260 instances of inlines, since the spec requires the out-of-line copy
20261 to have the same parent. For local class methods, this doesn't
20262 apply; we just use the old DIE. */
20263 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
20264 && (DECL_ARTIFICIAL (decl)
20265 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
20266 && (get_AT_unsigned (old_die, DW_AT_decl_line)
20267 == (unsigned) s.line))))
20269 subr_die = old_die;
20271 /* Clear out the declaration attribute and the formal parameters.
20272 Do not remove all children, because it is possible that this
20273 declaration die was forced using force_decl_die(). In such
20274 cases die that forced declaration die (e.g. TAG_imported_module)
20275 is one of the children that we do not want to remove. */
20276 remove_AT (subr_die, DW_AT_declaration);
20277 remove_AT (subr_die, DW_AT_object_pointer);
20278 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
20282 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20283 add_AT_specification (subr_die, old_die);
20284 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
20285 add_AT_file (subr_die, DW_AT_decl_file, file_index);
20286 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
20287 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
20292 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20294 if (TREE_PUBLIC (decl))
20295 add_AT_flag (subr_die, DW_AT_external, 1);
20297 add_name_and_src_coords_attributes (subr_die, decl);
20298 if (debug_info_level > DINFO_LEVEL_TERSE)
20300 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
20301 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
20302 0, 0, context_die);
20305 add_pure_or_virtual_attribute (subr_die, decl);
20306 if (DECL_ARTIFICIAL (decl))
20307 add_AT_flag (subr_die, DW_AT_artificial, 1);
20309 add_accessibility_attribute (subr_die, decl);
20314 if (!old_die || !get_AT (old_die, DW_AT_inline))
20316 add_AT_flag (subr_die, DW_AT_declaration, 1);
20318 /* If this is an explicit function declaration then generate
20319 a DW_AT_explicit attribute. */
20320 if (lang_hooks.decls.function_decl_explicit_p (decl)
20321 && (dwarf_version >= 3 || !dwarf_strict))
20322 add_AT_flag (subr_die, DW_AT_explicit, 1);
20324 /* The first time we see a member function, it is in the context of
20325 the class to which it belongs. We make sure of this by emitting
20326 the class first. The next time is the definition, which is
20327 handled above. The two may come from the same source text.
20329 Note that force_decl_die() forces function declaration die. It is
20330 later reused to represent definition. */
20331 equate_decl_number_to_die (decl, subr_die);
20334 else if (DECL_ABSTRACT (decl))
20336 if (DECL_DECLARED_INLINE_P (decl))
20338 if (cgraph_function_possibly_inlined_p (decl))
20339 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
20341 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
20345 if (cgraph_function_possibly_inlined_p (decl))
20346 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
20348 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
20351 if (DECL_DECLARED_INLINE_P (decl)
20352 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
20353 add_AT_flag (subr_die, DW_AT_artificial, 1);
20355 equate_decl_number_to_die (decl, subr_die);
20357 else if (!DECL_EXTERNAL (decl))
20359 HOST_WIDE_INT cfa_fb_offset;
20361 if (!old_die || !get_AT (old_die, DW_AT_inline))
20362 equate_decl_number_to_die (decl, subr_die);
20364 if (!flag_reorder_blocks_and_partition)
20366 dw_fde_ref fde = &fde_table[current_funcdef_fde];
20367 if (fde->dw_fde_begin)
20369 /* We have already generated the labels. */
20370 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
20371 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
20375 /* Create start/end labels and add the range. */
20376 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
20377 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
20378 current_function_funcdef_no);
20379 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
20380 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
20381 current_function_funcdef_no);
20382 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
20385 #if VMS_DEBUGGING_INFO
20386 /* HP OpenVMS Industry Standard 64: DWARF Extensions
20387 Section 2.3 Prologue and Epilogue Attributes:
20388 When a breakpoint is set on entry to a function, it is generally
20389 desirable for execution to be suspended, not on the very first
20390 instruction of the function, but rather at a point after the
20391 function's frame has been set up, after any language defined local
20392 declaration processing has been completed, and before execution of
20393 the first statement of the function begins. Debuggers generally
20394 cannot properly determine where this point is. Similarly for a
20395 breakpoint set on exit from a function. The prologue and epilogue
20396 attributes allow a compiler to communicate the location(s) to use. */
20399 if (fde->dw_fde_vms_end_prologue)
20400 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
20401 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
20403 if (fde->dw_fde_vms_begin_epilogue)
20404 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
20405 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
20409 add_pubname (decl, subr_die);
20412 { /* Generate pubnames entries for the split function code
20414 dw_fde_ref fde = &fde_table[current_funcdef_fde];
20416 if (fde->dw_fde_second_begin)
20418 if (dwarf_version >= 3 || !dwarf_strict)
20420 /* We should use ranges for non-contiguous code section
20421 addresses. Use the actual code range for the initial
20422 section, since the HOT/COLD labels might precede an
20423 alignment offset. */
20424 bool range_list_added = false;
20425 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
20426 fde->dw_fde_end, &range_list_added);
20427 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
20428 fde->dw_fde_second_end,
20429 &range_list_added);
20430 add_pubname (decl, subr_die);
20431 if (range_list_added)
20436 /* There is no real support in DW2 for this .. so we make
20437 a work-around. First, emit the pub name for the segment
20438 containing the function label. Then make and emit a
20439 simplified subprogram DIE for the second segment with the
20440 name pre-fixed by __hot/cold_sect_of_. We use the same
20441 linkage name for the second die so that gdb will find both
20442 sections when given "b foo". */
20443 const char *name = NULL;
20444 tree decl_name = DECL_NAME (decl);
20445 dw_die_ref seg_die;
20447 /* Do the 'primary' section. */
20448 add_AT_lbl_id (subr_die, DW_AT_low_pc,
20449 fde->dw_fde_begin);
20450 add_AT_lbl_id (subr_die, DW_AT_high_pc,
20453 add_pubname (decl, subr_die);
20455 /* Build a minimal DIE for the secondary section. */
20456 seg_die = new_die (DW_TAG_subprogram,
20457 subr_die->die_parent, decl);
20459 if (TREE_PUBLIC (decl))
20460 add_AT_flag (seg_die, DW_AT_external, 1);
20462 if (decl_name != NULL
20463 && IDENTIFIER_POINTER (decl_name) != NULL)
20465 name = dwarf2_name (decl, 1);
20466 if (! DECL_ARTIFICIAL (decl))
20467 add_src_coords_attributes (seg_die, decl);
20469 add_linkage_name (seg_die, decl);
20471 gcc_assert (name != NULL);
20472 add_pure_or_virtual_attribute (seg_die, decl);
20473 if (DECL_ARTIFICIAL (decl))
20474 add_AT_flag (seg_die, DW_AT_artificial, 1);
20476 name = concat ("__second_sect_of_", name, NULL);
20477 add_AT_lbl_id (seg_die, DW_AT_low_pc,
20478 fde->dw_fde_second_begin);
20479 add_AT_lbl_id (seg_die, DW_AT_high_pc,
20480 fde->dw_fde_second_end);
20481 add_name_attribute (seg_die, name);
20482 add_pubname_string (name, seg_die);
20487 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
20488 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
20489 add_pubname (decl, subr_die);
20493 #ifdef MIPS_DEBUGGING_INFO
20494 /* Add a reference to the FDE for this routine. */
20495 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
20498 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
20500 /* We define the "frame base" as the function's CFA. This is more
20501 convenient for several reasons: (1) It's stable across the prologue
20502 and epilogue, which makes it better than just a frame pointer,
20503 (2) With dwarf3, there exists a one-byte encoding that allows us
20504 to reference the .debug_frame data by proxy, but failing that,
20505 (3) We can at least reuse the code inspection and interpretation
20506 code that determines the CFA position at various points in the
20508 if (dwarf_version >= 3)
20510 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
20511 add_AT_loc (subr_die, DW_AT_frame_base, op);
20515 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
20516 if (list->dw_loc_next)
20517 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
20519 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
20522 /* Compute a displacement from the "steady-state frame pointer" to
20523 the CFA. The former is what all stack slots and argument slots
20524 will reference in the rtl; the later is what we've told the
20525 debugger about. We'll need to adjust all frame_base references
20526 by this displacement. */
20527 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
20529 if (cfun->static_chain_decl)
20530 add_AT_location_description (subr_die, DW_AT_static_link,
20531 loc_list_from_tree (cfun->static_chain_decl, 2));
20534 /* Generate child dies for template paramaters. */
20535 if (debug_info_level > DINFO_LEVEL_TERSE)
20536 gen_generic_params_dies (decl);
20538 /* Now output descriptions of the arguments for this function. This gets
20539 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
20540 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
20541 `...' at the end of the formal parameter list. In order to find out if
20542 there was a trailing ellipsis or not, we must instead look at the type
20543 associated with the FUNCTION_DECL. This will be a node of type
20544 FUNCTION_TYPE. If the chain of type nodes hanging off of this
20545 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
20546 an ellipsis at the end. */
20548 /* In the case where we are describing a mere function declaration, all we
20549 need to do here (and all we *can* do here) is to describe the *types* of
20550 its formal parameters. */
20551 if (debug_info_level <= DINFO_LEVEL_TERSE)
20553 else if (declaration)
20554 gen_formal_types_die (decl, subr_die);
20557 /* Generate DIEs to represent all known formal parameters. */
20558 tree parm = DECL_ARGUMENTS (decl);
20559 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
20560 tree generic_decl_parm = generic_decl
20561 ? DECL_ARGUMENTS (generic_decl)
20564 /* Now we want to walk the list of parameters of the function and
20565 emit their relevant DIEs.
20567 We consider the case of DECL being an instance of a generic function
20568 as well as it being a normal function.
20570 If DECL is an instance of a generic function we walk the
20571 parameters of the generic function declaration _and_ the parameters of
20572 DECL itself. This is useful because we want to emit specific DIEs for
20573 function parameter packs and those are declared as part of the
20574 generic function declaration. In that particular case,
20575 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
20576 That DIE has children DIEs representing the set of arguments
20577 of the pack. Note that the set of pack arguments can be empty.
20578 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
20581 Otherwise, we just consider the parameters of DECL. */
20582 while (generic_decl_parm || parm)
20584 if (generic_decl_parm
20585 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
20586 gen_formal_parameter_pack_die (generic_decl_parm,
20591 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
20593 if (parm == DECL_ARGUMENTS (decl)
20594 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
20596 && (dwarf_version >= 3 || !dwarf_strict))
20597 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
20599 parm = DECL_CHAIN (parm);
20602 if (generic_decl_parm)
20603 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
20606 /* Decide whether we need an unspecified_parameters DIE at the end.
20607 There are 2 more cases to do this for: 1) the ansi ... declaration -
20608 this is detectable when the end of the arg list is not a
20609 void_type_node 2) an unprototyped function declaration (not a
20610 definition). This just means that we have no info about the
20611 parameters at all. */
20612 if (prototype_p (TREE_TYPE (decl)))
20614 /* This is the prototyped case, check for.... */
20615 if (stdarg_p (TREE_TYPE (decl)))
20616 gen_unspecified_parameters_die (decl, subr_die);
20618 else if (DECL_INITIAL (decl) == NULL_TREE)
20619 gen_unspecified_parameters_die (decl, subr_die);
20622 /* Output Dwarf info for all of the stuff within the body of the function
20623 (if it has one - it may be just a declaration). */
20624 outer_scope = DECL_INITIAL (decl);
20626 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
20627 a function. This BLOCK actually represents the outermost binding contour
20628 for the function, i.e. the contour in which the function's formal
20629 parameters and labels get declared. Curiously, it appears that the front
20630 end doesn't actually put the PARM_DECL nodes for the current function onto
20631 the BLOCK_VARS list for this outer scope, but are strung off of the
20632 DECL_ARGUMENTS list for the function instead.
20634 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
20635 the LABEL_DECL nodes for the function however, and we output DWARF info
20636 for those in decls_for_scope. Just within the `outer_scope' there will be
20637 a BLOCK node representing the function's outermost pair of curly braces,
20638 and any blocks used for the base and member initializers of a C++
20639 constructor function. */
20640 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
20642 int call_site_note_count = 0;
20643 int tail_call_site_note_count = 0;
20645 /* Emit a DW_TAG_variable DIE for a named return value. */
20646 if (DECL_NAME (DECL_RESULT (decl)))
20647 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
20649 current_function_has_inlines = 0;
20650 decls_for_scope (outer_scope, subr_die, 0);
20652 if (call_arg_locations && !dwarf_strict)
20654 struct call_arg_loc_node *ca_loc;
20655 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
20657 dw_die_ref die = NULL;
20658 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
20661 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
20662 arg; arg = next_arg)
20664 dw_loc_descr_ref reg, val;
20665 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
20666 dw_die_ref cdie, tdie = NULL;
20668 next_arg = XEXP (arg, 1);
20669 if (REG_P (XEXP (XEXP (arg, 0), 0))
20671 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
20672 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
20673 && REGNO (XEXP (XEXP (arg, 0), 0))
20674 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
20675 next_arg = XEXP (next_arg, 1);
20676 if (mode == VOIDmode)
20678 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
20679 if (mode == VOIDmode)
20680 mode = GET_MODE (XEXP (arg, 0));
20682 if (mode == VOIDmode || mode == BLKmode)
20684 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
20686 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
20687 tloc = XEXP (XEXP (arg, 0), 1);
20690 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
20691 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
20693 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
20694 tlocc = XEXP (XEXP (arg, 0), 1);
20698 if (REG_P (XEXP (XEXP (arg, 0), 0)))
20699 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
20700 VAR_INIT_STATUS_INITIALIZED);
20701 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
20703 rtx mem = XEXP (XEXP (arg, 0), 0);
20704 reg = mem_loc_descriptor (XEXP (mem, 0),
20705 get_address_mode (mem),
20707 VAR_INIT_STATUS_INITIALIZED);
20709 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
20710 == DEBUG_PARAMETER_REF)
20713 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
20714 tdie = lookup_decl_die (tdecl);
20721 && GET_CODE (XEXP (XEXP (arg, 0), 0))
20722 != DEBUG_PARAMETER_REF)
20724 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
20726 VAR_INIT_STATUS_INITIALIZED);
20730 die = gen_call_site_die (decl, subr_die, ca_loc);
20731 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
20734 add_AT_loc (cdie, DW_AT_location, reg);
20735 else if (tdie != NULL)
20736 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
20737 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
20738 if (next_arg != XEXP (arg, 1))
20740 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
20741 if (mode == VOIDmode)
20742 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
20743 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
20746 VAR_INIT_STATUS_INITIALIZED);
20748 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
20752 && (ca_loc->symbol_ref || tloc))
20753 die = gen_call_site_die (decl, subr_die, ca_loc);
20754 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
20756 dw_loc_descr_ref tval = NULL;
20758 if (tloc != NULL_RTX)
20759 tval = mem_loc_descriptor (tloc,
20760 GET_MODE (tloc) == VOIDmode
20761 ? Pmode : GET_MODE (tloc),
20763 VAR_INIT_STATUS_INITIALIZED);
20765 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
20766 else if (tlocc != NULL_RTX)
20768 tval = mem_loc_descriptor (tlocc,
20769 GET_MODE (tlocc) == VOIDmode
20770 ? Pmode : GET_MODE (tlocc),
20772 VAR_INIT_STATUS_INITIALIZED);
20774 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
20780 call_site_note_count++;
20781 if (ca_loc->tail_call_p)
20782 tail_call_site_note_count++;
20786 call_arg_locations = NULL;
20787 call_arg_loc_last = NULL;
20788 if (tail_call_site_count >= 0
20789 && tail_call_site_count == tail_call_site_note_count
20792 if (call_site_count >= 0
20793 && call_site_count == call_site_note_count)
20794 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
20796 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
20798 call_site_count = -1;
20799 tail_call_site_count = -1;
20801 /* Add the calling convention attribute if requested. */
20802 add_calling_convention_attribute (subr_die, decl);
20806 /* Returns a hash value for X (which really is a die_struct). */
20809 common_block_die_table_hash (const void *x)
20811 const_dw_die_ref d = (const_dw_die_ref) x;
20812 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
20815 /* Return nonzero if decl_id and die_parent of die_struct X is the same
20816 as decl_id and die_parent of die_struct Y. */
20819 common_block_die_table_eq (const void *x, const void *y)
20821 const_dw_die_ref d = (const_dw_die_ref) x;
20822 const_dw_die_ref e = (const_dw_die_ref) y;
20823 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
20826 /* Generate a DIE to represent a declared data object.
20827 Either DECL or ORIGIN must be non-null. */
20830 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
20834 tree decl_or_origin = decl ? decl : origin;
20835 tree ultimate_origin;
20836 dw_die_ref var_die;
20837 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
20838 dw_die_ref origin_die;
20839 bool declaration = (DECL_EXTERNAL (decl_or_origin)
20840 || class_or_namespace_scope_p (context_die));
20841 bool specialization_p = false;
20843 ultimate_origin = decl_ultimate_origin (decl_or_origin);
20844 if (decl || ultimate_origin)
20845 origin = ultimate_origin;
20846 com_decl = fortran_common (decl_or_origin, &off);
20848 /* Symbol in common gets emitted as a child of the common block, in the form
20849 of a data member. */
20852 dw_die_ref com_die;
20853 dw_loc_list_ref loc;
20854 die_node com_die_arg;
20856 var_die = lookup_decl_die (decl_or_origin);
20859 if (get_AT (var_die, DW_AT_location) == NULL)
20861 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
20866 /* Optimize the common case. */
20867 if (single_element_loc_list_p (loc)
20868 && loc->expr->dw_loc_opc == DW_OP_addr
20869 && loc->expr->dw_loc_next == NULL
20870 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
20872 loc->expr->dw_loc_oprnd1.v.val_addr
20873 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
20875 loc_list_plus_const (loc, off);
20877 add_AT_location_description (var_die, DW_AT_location, loc);
20878 remove_AT (var_die, DW_AT_declaration);
20884 if (common_block_die_table == NULL)
20885 common_block_die_table
20886 = htab_create_ggc (10, common_block_die_table_hash,
20887 common_block_die_table_eq, NULL);
20889 com_die_arg.decl_id = DECL_UID (com_decl);
20890 com_die_arg.die_parent = context_die;
20891 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
20892 loc = loc_list_from_tree (com_decl, 2);
20893 if (com_die == NULL)
20896 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
20899 com_die = new_die (DW_TAG_common_block, context_die, decl);
20900 add_name_and_src_coords_attributes (com_die, com_decl);
20903 add_AT_location_description (com_die, DW_AT_location, loc);
20904 /* Avoid sharing the same loc descriptor between
20905 DW_TAG_common_block and DW_TAG_variable. */
20906 loc = loc_list_from_tree (com_decl, 2);
20908 else if (DECL_EXTERNAL (decl))
20909 add_AT_flag (com_die, DW_AT_declaration, 1);
20910 add_pubname_string (cnam, com_die); /* ??? needed? */
20911 com_die->decl_id = DECL_UID (com_decl);
20912 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
20913 *slot = (void *) com_die;
20915 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
20917 add_AT_location_description (com_die, DW_AT_location, loc);
20918 loc = loc_list_from_tree (com_decl, 2);
20919 remove_AT (com_die, DW_AT_declaration);
20921 var_die = new_die (DW_TAG_variable, com_die, decl);
20922 add_name_and_src_coords_attributes (var_die, decl);
20923 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
20924 TREE_THIS_VOLATILE (decl), context_die);
20925 add_AT_flag (var_die, DW_AT_external, 1);
20930 /* Optimize the common case. */
20931 if (single_element_loc_list_p (loc)
20932 && loc->expr->dw_loc_opc == DW_OP_addr
20933 && loc->expr->dw_loc_next == NULL
20934 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
20935 loc->expr->dw_loc_oprnd1.v.val_addr
20936 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
20938 loc_list_plus_const (loc, off);
20940 add_AT_location_description (var_die, DW_AT_location, loc);
20942 else if (DECL_EXTERNAL (decl))
20943 add_AT_flag (var_die, DW_AT_declaration, 1);
20944 equate_decl_number_to_die (decl, var_die);
20948 /* If the compiler emitted a definition for the DECL declaration
20949 and if we already emitted a DIE for it, don't emit a second
20950 DIE for it again. Allow re-declarations of DECLs that are
20951 inside functions, though. */
20952 if (old_die && declaration && !local_scope_p (context_die))
20955 /* For static data members, the declaration in the class is supposed
20956 to have DW_TAG_member tag; the specification should still be
20957 DW_TAG_variable referencing the DW_TAG_member DIE. */
20958 if (declaration && class_scope_p (context_die))
20959 var_die = new_die (DW_TAG_member, context_die, decl);
20961 var_die = new_die (DW_TAG_variable, context_die, decl);
20964 if (origin != NULL)
20965 origin_die = add_abstract_origin_attribute (var_die, origin);
20967 /* Loop unrolling can create multiple blocks that refer to the same
20968 static variable, so we must test for the DW_AT_declaration flag.
20970 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
20971 copy decls and set the DECL_ABSTRACT flag on them instead of
20974 ??? Duplicated blocks have been rewritten to use .debug_ranges.
20976 ??? The declare_in_namespace support causes us to get two DIEs for one
20977 variable, both of which are declarations. We want to avoid considering
20978 one to be a specification, so we must test that this DIE is not a
20980 else if (old_die && TREE_STATIC (decl) && ! declaration
20981 && get_AT_flag (old_die, DW_AT_declaration) == 1)
20983 /* This is a definition of a C++ class level static. */
20984 add_AT_specification (var_die, old_die);
20985 specialization_p = true;
20986 if (DECL_NAME (decl))
20988 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
20989 struct dwarf_file_data * file_index = lookup_filename (s.file);
20991 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
20992 add_AT_file (var_die, DW_AT_decl_file, file_index);
20994 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
20995 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
20997 if (old_die->die_tag == DW_TAG_member)
20998 add_linkage_name (var_die, decl);
21002 add_name_and_src_coords_attributes (var_die, decl);
21004 if ((origin == NULL && !specialization_p)
21006 && !DECL_ABSTRACT (decl_or_origin)
21007 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
21008 decl_function_context
21009 (decl_or_origin))))
21011 tree type = TREE_TYPE (decl_or_origin);
21013 if (decl_by_reference_p (decl_or_origin))
21014 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
21016 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
21017 TREE_THIS_VOLATILE (decl_or_origin), context_die);
21020 if (origin == NULL && !specialization_p)
21022 if (TREE_PUBLIC (decl))
21023 add_AT_flag (var_die, DW_AT_external, 1);
21025 if (DECL_ARTIFICIAL (decl))
21026 add_AT_flag (var_die, DW_AT_artificial, 1);
21028 add_accessibility_attribute (var_die, decl);
21032 add_AT_flag (var_die, DW_AT_declaration, 1);
21034 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
21035 equate_decl_number_to_die (decl, var_die);
21038 && (! DECL_ABSTRACT (decl_or_origin)
21039 /* Local static vars are shared between all clones/inlines,
21040 so emit DW_AT_location on the abstract DIE if DECL_RTL is
21042 || (TREE_CODE (decl_or_origin) == VAR_DECL
21043 && TREE_STATIC (decl_or_origin)
21044 && DECL_RTL_SET_P (decl_or_origin)))
21045 /* When abstract origin already has DW_AT_location attribute, no need
21046 to add it again. */
21047 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
21049 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
21050 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
21051 defer_location (decl_or_origin, var_die);
21053 add_location_or_const_value_attribute (var_die, decl_or_origin,
21054 decl == NULL, DW_AT_location);
21055 add_pubname (decl_or_origin, var_die);
21058 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
21061 /* Generate a DIE to represent a named constant. */
21064 gen_const_die (tree decl, dw_die_ref context_die)
21066 dw_die_ref const_die;
21067 tree type = TREE_TYPE (decl);
21069 const_die = new_die (DW_TAG_constant, context_die, decl);
21070 add_name_and_src_coords_attributes (const_die, decl);
21071 add_type_attribute (const_die, type, 1, 0, context_die);
21072 if (TREE_PUBLIC (decl))
21073 add_AT_flag (const_die, DW_AT_external, 1);
21074 if (DECL_ARTIFICIAL (decl))
21075 add_AT_flag (const_die, DW_AT_artificial, 1);
21076 tree_add_const_value_attribute_for_decl (const_die, decl);
21079 /* Generate a DIE to represent a label identifier. */
21082 gen_label_die (tree decl, dw_die_ref context_die)
21084 tree origin = decl_ultimate_origin (decl);
21085 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
21087 char label[MAX_ARTIFICIAL_LABEL_BYTES];
21089 if (origin != NULL)
21090 add_abstract_origin_attribute (lbl_die, origin);
21092 add_name_and_src_coords_attributes (lbl_die, decl);
21094 if (DECL_ABSTRACT (decl))
21095 equate_decl_number_to_die (decl, lbl_die);
21098 insn = DECL_RTL_IF_SET (decl);
21100 /* Deleted labels are programmer specified labels which have been
21101 eliminated because of various optimizations. We still emit them
21102 here so that it is possible to put breakpoints on them. */
21106 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
21108 /* When optimization is enabled (via -O) some parts of the compiler
21109 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
21110 represent source-level labels which were explicitly declared by
21111 the user. This really shouldn't be happening though, so catch
21112 it if it ever does happen. */
21113 gcc_assert (!INSN_DELETED_P (insn));
21115 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
21116 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
21121 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
21122 attributes to the DIE for a block STMT, to describe where the inlined
21123 function was called from. This is similar to add_src_coords_attributes. */
21126 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
21128 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
21130 if (dwarf_version >= 3 || !dwarf_strict)
21132 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
21133 add_AT_unsigned (die, DW_AT_call_line, s.line);
21138 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
21139 Add low_pc and high_pc attributes to the DIE for a block STMT. */
21142 add_high_low_attributes (tree stmt, dw_die_ref die)
21144 char label[MAX_ARTIFICIAL_LABEL_BYTES];
21146 if (BLOCK_FRAGMENT_CHAIN (stmt)
21147 && (dwarf_version >= 3 || !dwarf_strict))
21151 if (inlined_function_outer_scope_p (stmt))
21153 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
21154 BLOCK_NUMBER (stmt));
21155 add_AT_lbl_id (die, DW_AT_entry_pc, label);
21158 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
21160 chain = BLOCK_FRAGMENT_CHAIN (stmt);
21163 add_ranges (chain);
21164 chain = BLOCK_FRAGMENT_CHAIN (chain);
21171 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
21172 BLOCK_NUMBER (stmt));
21173 add_AT_lbl_id (die, DW_AT_low_pc, label);
21174 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
21175 BLOCK_NUMBER (stmt));
21176 add_AT_lbl_id (die, DW_AT_high_pc, label);
21180 /* Generate a DIE for a lexical block. */
21183 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
21185 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
21187 if (call_arg_locations)
21189 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
21190 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
21191 BLOCK_NUMBER (stmt) + 1);
21192 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
21195 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
21196 add_high_low_attributes (stmt, stmt_die);
21198 decls_for_scope (stmt, stmt_die, depth);
21201 /* Generate a DIE for an inlined subprogram. */
21204 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
21208 /* The instance of function that is effectively being inlined shall not
21210 gcc_assert (! BLOCK_ABSTRACT (stmt));
21212 decl = block_ultimate_origin (stmt);
21214 /* Emit info for the abstract instance first, if we haven't yet. We
21215 must emit this even if the block is abstract, otherwise when we
21216 emit the block below (or elsewhere), we may end up trying to emit
21217 a die whose origin die hasn't been emitted, and crashing. */
21218 dwarf2out_abstract_function (decl);
21220 if (! BLOCK_ABSTRACT (stmt))
21222 dw_die_ref subr_die
21223 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
21225 if (call_arg_locations)
21227 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
21228 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
21229 BLOCK_NUMBER (stmt) + 1);
21230 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
21232 add_abstract_origin_attribute (subr_die, decl);
21233 if (TREE_ASM_WRITTEN (stmt))
21234 add_high_low_attributes (stmt, subr_die);
21235 add_call_src_coords_attributes (stmt, subr_die);
21237 decls_for_scope (stmt, subr_die, depth);
21238 current_function_has_inlines = 1;
21242 /* Generate a DIE for a field in a record, or structure. */
21245 gen_field_die (tree decl, dw_die_ref context_die)
21247 dw_die_ref decl_die;
21249 if (TREE_TYPE (decl) == error_mark_node)
21252 decl_die = new_die (DW_TAG_member, context_die, decl);
21253 add_name_and_src_coords_attributes (decl_die, decl);
21254 add_type_attribute (decl_die, member_declared_type (decl),
21255 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
21258 if (DECL_BIT_FIELD_TYPE (decl))
21260 add_byte_size_attribute (decl_die, decl);
21261 add_bit_size_attribute (decl_die, decl);
21262 add_bit_offset_attribute (decl_die, decl);
21265 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
21266 add_data_member_location_attribute (decl_die, decl);
21268 if (DECL_ARTIFICIAL (decl))
21269 add_AT_flag (decl_die, DW_AT_artificial, 1);
21271 add_accessibility_attribute (decl_die, decl);
21273 /* Equate decl number to die, so that we can look up this decl later on. */
21274 equate_decl_number_to_die (decl, decl_die);
21278 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21279 Use modified_type_die instead.
21280 We keep this code here just in case these types of DIEs may be needed to
21281 represent certain things in other languages (e.g. Pascal) someday. */
21284 gen_pointer_type_die (tree type, dw_die_ref context_die)
21287 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
21289 equate_type_number_to_die (type, ptr_die);
21290 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
21291 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
21294 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21295 Use modified_type_die instead.
21296 We keep this code here just in case these types of DIEs may be needed to
21297 represent certain things in other languages (e.g. Pascal) someday. */
21300 gen_reference_type_die (tree type, dw_die_ref context_die)
21302 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
21304 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
21305 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
21307 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
21309 equate_type_number_to_die (type, ref_die);
21310 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
21311 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
21315 /* Generate a DIE for a pointer to a member type. */
21318 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
21321 = new_die (DW_TAG_ptr_to_member_type,
21322 scope_die_for (type, context_die), type);
21324 equate_type_number_to_die (type, ptr_die);
21325 add_AT_die_ref (ptr_die, DW_AT_containing_type,
21326 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
21327 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
21330 /* Generate the DIE for the compilation unit. */
21333 gen_compile_unit_die (const char *filename)
21336 char producer[250];
21337 const char *language_string = lang_hooks.name;
21340 die = new_die (DW_TAG_compile_unit, NULL, NULL);
21344 add_name_attribute (die, filename);
21345 /* Don't add cwd for <built-in>. */
21346 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
21347 add_comp_dir_attribute (die);
21350 sprintf (producer, "%s %s", language_string, version_string);
21352 #ifdef MIPS_DEBUGGING_INFO
21353 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
21354 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
21355 not appear in the producer string, the debugger reaches the conclusion
21356 that the object file is stripped and has no debugging information.
21357 To get the MIPS/SGI debugger to believe that there is debugging
21358 information in the object file, we add a -g to the producer string. */
21359 if (debug_info_level > DINFO_LEVEL_TERSE)
21360 strcat (producer, " -g");
21363 add_AT_string (die, DW_AT_producer, producer);
21365 /* If our producer is LTO try to figure out a common language to use
21366 from the global list of translation units. */
21367 if (strcmp (language_string, "GNU GIMPLE") == 0)
21371 const char *common_lang = NULL;
21373 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
21375 if (!TRANSLATION_UNIT_LANGUAGE (t))
21378 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
21379 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
21381 else if (strncmp (common_lang, "GNU C", 5) == 0
21382 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
21383 /* Mixing C and C++ is ok, use C++ in that case. */
21384 common_lang = "GNU C++";
21387 /* Fall back to C. */
21388 common_lang = NULL;
21394 language_string = common_lang;
21397 language = DW_LANG_C89;
21398 if (strcmp (language_string, "GNU C++") == 0)
21399 language = DW_LANG_C_plus_plus;
21400 else if (strcmp (language_string, "GNU F77") == 0)
21401 language = DW_LANG_Fortran77;
21402 else if (strcmp (language_string, "GNU Pascal") == 0)
21403 language = DW_LANG_Pascal83;
21404 else if (dwarf_version >= 3 || !dwarf_strict)
21406 if (strcmp (language_string, "GNU Ada") == 0)
21407 language = DW_LANG_Ada95;
21408 else if (strcmp (language_string, "GNU Fortran") == 0)
21409 language = DW_LANG_Fortran95;
21410 else if (strcmp (language_string, "GNU Java") == 0)
21411 language = DW_LANG_Java;
21412 else if (strcmp (language_string, "GNU Objective-C") == 0)
21413 language = DW_LANG_ObjC;
21414 else if (strcmp (language_string, "GNU Objective-C++") == 0)
21415 language = DW_LANG_ObjC_plus_plus;
21418 add_AT_unsigned (die, DW_AT_language, language);
21422 case DW_LANG_Fortran77:
21423 case DW_LANG_Fortran90:
21424 case DW_LANG_Fortran95:
21425 /* Fortran has case insensitive identifiers and the front-end
21426 lowercases everything. */
21427 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
21430 /* The default DW_ID_case_sensitive doesn't need to be specified. */
21436 /* Generate the DIE for a base class. */
21439 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
21441 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
21443 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
21444 add_data_member_location_attribute (die, binfo);
21446 if (BINFO_VIRTUAL_P (binfo))
21447 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
21449 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
21450 children, otherwise the default is DW_ACCESS_public. In DWARF2
21451 the default has always been DW_ACCESS_private. */
21452 if (access == access_public_node)
21454 if (dwarf_version == 2
21455 || context_die->die_tag == DW_TAG_class_type)
21456 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
21458 else if (access == access_protected_node)
21459 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
21460 else if (dwarf_version > 2
21461 && context_die->die_tag != DW_TAG_class_type)
21462 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
21465 /* Generate a DIE for a class member. */
21468 gen_member_die (tree type, dw_die_ref context_die)
21471 tree binfo = TYPE_BINFO (type);
21474 /* If this is not an incomplete type, output descriptions of each of its
21475 members. Note that as we output the DIEs necessary to represent the
21476 members of this record or union type, we will also be trying to output
21477 DIEs to represent the *types* of those members. However the `type'
21478 function (above) will specifically avoid generating type DIEs for member
21479 types *within* the list of member DIEs for this (containing) type except
21480 for those types (of members) which are explicitly marked as also being
21481 members of this (containing) type themselves. The g++ front- end can
21482 force any given type to be treated as a member of some other (containing)
21483 type by setting the TYPE_CONTEXT of the given (member) type to point to
21484 the TREE node representing the appropriate (containing) type. */
21486 /* First output info about the base classes. */
21489 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
21493 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
21494 gen_inheritance_die (base,
21495 (accesses ? VEC_index (tree, accesses, i)
21496 : access_public_node), context_die);
21499 /* Now output info about the data members and type members. */
21500 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
21502 /* If we thought we were generating minimal debug info for TYPE
21503 and then changed our minds, some of the member declarations
21504 may have already been defined. Don't define them again, but
21505 do put them in the right order. */
21507 child = lookup_decl_die (member);
21509 splice_child_die (context_die, child);
21511 gen_decl_die (member, NULL, context_die);
21514 /* Now output info about the function members (if any). */
21515 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
21517 /* Don't include clones in the member list. */
21518 if (DECL_ABSTRACT_ORIGIN (member))
21521 child = lookup_decl_die (member);
21523 splice_child_die (context_die, child);
21525 gen_decl_die (member, NULL, context_die);
21529 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
21530 is set, we pretend that the type was never defined, so we only get the
21531 member DIEs needed by later specification DIEs. */
21534 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
21535 enum debug_info_usage usage)
21537 dw_die_ref type_die = lookup_type_die (type);
21538 dw_die_ref scope_die = 0;
21540 int complete = (TYPE_SIZE (type)
21541 && (! TYPE_STUB_DECL (type)
21542 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
21543 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
21544 complete = complete && should_emit_struct_debug (type, usage);
21546 if (type_die && ! complete)
21549 if (TYPE_CONTEXT (type) != NULL_TREE
21550 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
21551 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
21554 scope_die = scope_die_for (type, context_die);
21556 if (! type_die || (nested && is_cu_die (scope_die)))
21557 /* First occurrence of type or toplevel definition of nested class. */
21559 dw_die_ref old_die = type_die;
21561 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
21562 ? record_type_tag (type) : DW_TAG_union_type,
21564 equate_type_number_to_die (type, type_die);
21566 add_AT_specification (type_die, old_die);
21569 add_name_attribute (type_die, type_tag (type));
21570 add_gnat_descriptive_type_attribute (type_die, type, context_die);
21574 remove_AT (type_die, DW_AT_declaration);
21576 /* Generate child dies for template paramaters. */
21577 if (debug_info_level > DINFO_LEVEL_TERSE
21578 && COMPLETE_TYPE_P (type))
21579 schedule_generic_params_dies_gen (type);
21581 /* If this type has been completed, then give it a byte_size attribute and
21582 then give a list of members. */
21583 if (complete && !ns_decl)
21585 /* Prevent infinite recursion in cases where the type of some member of
21586 this type is expressed in terms of this type itself. */
21587 TREE_ASM_WRITTEN (type) = 1;
21588 add_byte_size_attribute (type_die, type);
21589 if (TYPE_STUB_DECL (type) != NULL_TREE)
21591 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
21592 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
21595 /* If the first reference to this type was as the return type of an
21596 inline function, then it may not have a parent. Fix this now. */
21597 if (type_die->die_parent == NULL)
21598 add_child_die (scope_die, type_die);
21600 push_decl_scope (type);
21601 gen_member_die (type, type_die);
21604 /* GNU extension: Record what type our vtable lives in. */
21605 if (TYPE_VFIELD (type))
21607 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
21609 gen_type_die (vtype, context_die);
21610 add_AT_die_ref (type_die, DW_AT_containing_type,
21611 lookup_type_die (vtype));
21616 add_AT_flag (type_die, DW_AT_declaration, 1);
21618 /* We don't need to do this for function-local types. */
21619 if (TYPE_STUB_DECL (type)
21620 && ! decl_function_context (TYPE_STUB_DECL (type)))
21621 VEC_safe_push (tree, gc, incomplete_types, type);
21624 if (get_AT (type_die, DW_AT_name))
21625 add_pubtype (type, type_die);
21628 /* Generate a DIE for a subroutine _type_. */
21631 gen_subroutine_type_die (tree type, dw_die_ref context_die)
21633 tree return_type = TREE_TYPE (type);
21634 dw_die_ref subr_die
21635 = new_die (DW_TAG_subroutine_type,
21636 scope_die_for (type, context_die), type);
21638 equate_type_number_to_die (type, subr_die);
21639 add_prototyped_attribute (subr_die, type);
21640 add_type_attribute (subr_die, return_type, 0, 0, context_die);
21641 gen_formal_types_die (type, subr_die);
21643 if (get_AT (subr_die, DW_AT_name))
21644 add_pubtype (type, subr_die);
21647 /* Generate a DIE for a type definition. */
21650 gen_typedef_die (tree decl, dw_die_ref context_die)
21652 dw_die_ref type_die;
21655 if (TREE_ASM_WRITTEN (decl))
21658 TREE_ASM_WRITTEN (decl) = 1;
21659 type_die = new_die (DW_TAG_typedef, context_die, decl);
21660 origin = decl_ultimate_origin (decl);
21661 if (origin != NULL)
21662 add_abstract_origin_attribute (type_die, origin);
21667 add_name_and_src_coords_attributes (type_die, decl);
21668 if (DECL_ORIGINAL_TYPE (decl))
21670 type = DECL_ORIGINAL_TYPE (decl);
21672 gcc_assert (type != TREE_TYPE (decl));
21673 equate_type_number_to_die (TREE_TYPE (decl), type_die);
21677 type = TREE_TYPE (decl);
21679 if (is_naming_typedef_decl (TYPE_NAME (type)))
21681 /* Here, we are in the case of decl being a typedef naming
21682 an anonymous type, e.g:
21683 typedef struct {...} foo;
21684 In that case TREE_TYPE (decl) is not a typedef variant
21685 type and TYPE_NAME of the anonymous type is set to the
21686 TYPE_DECL of the typedef. This construct is emitted by
21689 TYPE is the anonymous struct named by the typedef
21690 DECL. As we need the DW_AT_type attribute of the
21691 DW_TAG_typedef to point to the DIE of TYPE, let's
21692 generate that DIE right away. add_type_attribute
21693 called below will then pick (via lookup_type_die) that
21694 anonymous struct DIE. */
21695 if (!TREE_ASM_WRITTEN (type))
21696 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
21698 /* This is a GNU Extension. We are adding a
21699 DW_AT_linkage_name attribute to the DIE of the
21700 anonymous struct TYPE. The value of that attribute
21701 is the name of the typedef decl naming the anonymous
21702 struct. This greatly eases the work of consumers of
21703 this debug info. */
21704 add_linkage_attr (lookup_type_die (type), decl);
21708 add_type_attribute (type_die, type, TREE_READONLY (decl),
21709 TREE_THIS_VOLATILE (decl), context_die);
21711 if (is_naming_typedef_decl (decl))
21712 /* We want that all subsequent calls to lookup_type_die with
21713 TYPE in argument yield the DW_TAG_typedef we have just
21715 equate_type_number_to_die (type, type_die);
21717 add_accessibility_attribute (type_die, decl);
21720 if (DECL_ABSTRACT (decl))
21721 equate_decl_number_to_die (decl, type_die);
21723 if (get_AT (type_die, DW_AT_name))
21724 add_pubtype (decl, type_die);
21727 /* Generate a DIE for a struct, class, enum or union type. */
21730 gen_tagged_type_die (tree type,
21731 dw_die_ref context_die,
21732 enum debug_info_usage usage)
21736 if (type == NULL_TREE
21737 || !is_tagged_type (type))
21740 /* If this is a nested type whose containing class hasn't been written
21741 out yet, writing it out will cover this one, too. This does not apply
21742 to instantiations of member class templates; they need to be added to
21743 the containing class as they are generated. FIXME: This hurts the
21744 idea of combining type decls from multiple TUs, since we can't predict
21745 what set of template instantiations we'll get. */
21746 if (TYPE_CONTEXT (type)
21747 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
21748 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
21750 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
21752 if (TREE_ASM_WRITTEN (type))
21755 /* If that failed, attach ourselves to the stub. */
21756 push_decl_scope (TYPE_CONTEXT (type));
21757 context_die = lookup_type_die (TYPE_CONTEXT (type));
21760 else if (TYPE_CONTEXT (type) != NULL_TREE
21761 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
21763 /* If this type is local to a function that hasn't been written
21764 out yet, use a NULL context for now; it will be fixed up in
21765 decls_for_scope. */
21766 context_die = lookup_decl_die (TYPE_CONTEXT (type));
21767 /* A declaration DIE doesn't count; nested types need to go in the
21769 if (context_die && is_declaration_die (context_die))
21770 context_die = NULL;
21775 context_die = declare_in_namespace (type, context_die);
21779 if (TREE_CODE (type) == ENUMERAL_TYPE)
21781 /* This might have been written out by the call to
21782 declare_in_namespace. */
21783 if (!TREE_ASM_WRITTEN (type))
21784 gen_enumeration_type_die (type, context_die);
21787 gen_struct_or_union_type_die (type, context_die, usage);
21792 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
21793 it up if it is ever completed. gen_*_type_die will set it for us
21794 when appropriate. */
21797 /* Generate a type description DIE. */
21800 gen_type_die_with_usage (tree type, dw_die_ref context_die,
21801 enum debug_info_usage usage)
21803 struct array_descr_info info;
21805 if (type == NULL_TREE || type == error_mark_node)
21808 if (TYPE_NAME (type) != NULL_TREE
21809 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
21810 && is_redundant_typedef (TYPE_NAME (type))
21811 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
21812 /* The DECL of this type is a typedef we don't want to emit debug
21813 info for but we want debug info for its underlying typedef.
21814 This can happen for e.g, the injected-class-name of a C++
21816 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
21818 /* If TYPE is a typedef type variant, let's generate debug info
21819 for the parent typedef which TYPE is a type of. */
21820 if (typedef_variant_p (type))
21822 if (TREE_ASM_WRITTEN (type))
21825 /* Prevent broken recursion; we can't hand off to the same type. */
21826 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
21828 /* Use the DIE of the containing namespace as the parent DIE of
21829 the type description DIE we want to generate. */
21830 if (DECL_CONTEXT (TYPE_NAME (type))
21831 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
21832 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
21834 TREE_ASM_WRITTEN (type) = 1;
21836 gen_decl_die (TYPE_NAME (type), NULL, context_die);
21840 /* If type is an anonymous tagged type named by a typedef, let's
21841 generate debug info for the typedef. */
21842 if (is_naming_typedef_decl (TYPE_NAME (type)))
21844 /* Use the DIE of the containing namespace as the parent DIE of
21845 the type description DIE we want to generate. */
21846 if (DECL_CONTEXT (TYPE_NAME (type))
21847 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
21848 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
21850 gen_decl_die (TYPE_NAME (type), NULL, context_die);
21854 /* If this is an array type with hidden descriptor, handle it first. */
21855 if (!TREE_ASM_WRITTEN (type)
21856 && lang_hooks.types.get_array_descr_info
21857 && lang_hooks.types.get_array_descr_info (type, &info)
21858 && (dwarf_version >= 3 || !dwarf_strict))
21860 gen_descr_array_type_die (type, &info, context_die);
21861 TREE_ASM_WRITTEN (type) = 1;
21865 /* We are going to output a DIE to represent the unqualified version
21866 of this type (i.e. without any const or volatile qualifiers) so
21867 get the main variant (i.e. the unqualified version) of this type
21868 now. (Vectors are special because the debugging info is in the
21869 cloned type itself). */
21870 if (TREE_CODE (type) != VECTOR_TYPE)
21871 type = type_main_variant (type);
21873 if (TREE_ASM_WRITTEN (type))
21876 switch (TREE_CODE (type))
21882 case REFERENCE_TYPE:
21883 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
21884 ensures that the gen_type_die recursion will terminate even if the
21885 type is recursive. Recursive types are possible in Ada. */
21886 /* ??? We could perhaps do this for all types before the switch
21888 TREE_ASM_WRITTEN (type) = 1;
21890 /* For these types, all that is required is that we output a DIE (or a
21891 set of DIEs) to represent the "basis" type. */
21892 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21893 DINFO_USAGE_IND_USE);
21897 /* This code is used for C++ pointer-to-data-member types.
21898 Output a description of the relevant class type. */
21899 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
21900 DINFO_USAGE_IND_USE);
21902 /* Output a description of the type of the object pointed to. */
21903 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21904 DINFO_USAGE_IND_USE);
21906 /* Now output a DIE to represent this pointer-to-data-member type
21908 gen_ptr_to_mbr_type_die (type, context_die);
21911 case FUNCTION_TYPE:
21912 /* Force out return type (in case it wasn't forced out already). */
21913 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21914 DINFO_USAGE_DIR_USE);
21915 gen_subroutine_type_die (type, context_die);
21919 /* Force out return type (in case it wasn't forced out already). */
21920 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21921 DINFO_USAGE_DIR_USE);
21922 gen_subroutine_type_die (type, context_die);
21926 gen_array_type_die (type, context_die);
21930 gen_array_type_die (type, context_die);
21933 case ENUMERAL_TYPE:
21936 case QUAL_UNION_TYPE:
21937 gen_tagged_type_die (type, context_die, usage);
21943 case FIXED_POINT_TYPE:
21946 /* No DIEs needed for fundamental types. */
21951 /* Just use DW_TAG_unspecified_type. */
21953 dw_die_ref type_die = lookup_type_die (type);
21954 if (type_die == NULL)
21956 tree name = TYPE_NAME (type);
21957 if (TREE_CODE (name) == TYPE_DECL)
21958 name = DECL_NAME (name);
21959 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
21960 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
21961 equate_type_number_to_die (type, type_die);
21967 gcc_unreachable ();
21970 TREE_ASM_WRITTEN (type) = 1;
21974 gen_type_die (tree type, dw_die_ref context_die)
21976 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
21979 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
21980 things which are local to the given block. */
21983 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
21985 int must_output_die = 0;
21988 /* Ignore blocks that are NULL. */
21989 if (stmt == NULL_TREE)
21992 inlined_func = inlined_function_outer_scope_p (stmt);
21994 /* If the block is one fragment of a non-contiguous block, do not
21995 process the variables, since they will have been done by the
21996 origin block. Do process subblocks. */
21997 if (BLOCK_FRAGMENT_ORIGIN (stmt))
22001 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
22002 gen_block_die (sub, context_die, depth + 1);
22007 /* Determine if we need to output any Dwarf DIEs at all to represent this
22010 /* The outer scopes for inlinings *must* always be represented. We
22011 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
22012 must_output_die = 1;
22015 /* Determine if this block directly contains any "significant"
22016 local declarations which we will need to output DIEs for. */
22017 if (debug_info_level > DINFO_LEVEL_TERSE)
22018 /* We are not in terse mode so *any* local declaration counts
22019 as being a "significant" one. */
22020 must_output_die = ((BLOCK_VARS (stmt) != NULL
22021 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
22022 && (TREE_USED (stmt)
22023 || TREE_ASM_WRITTEN (stmt)
22024 || BLOCK_ABSTRACT (stmt)));
22025 else if ((TREE_USED (stmt)
22026 || TREE_ASM_WRITTEN (stmt)
22027 || BLOCK_ABSTRACT (stmt))
22028 && !dwarf2out_ignore_block (stmt))
22029 must_output_die = 1;
22032 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
22033 DIE for any block which contains no significant local declarations at
22034 all. Rather, in such cases we just call `decls_for_scope' so that any
22035 needed Dwarf info for any sub-blocks will get properly generated. Note
22036 that in terse mode, our definition of what constitutes a "significant"
22037 local declaration gets restricted to include only inlined function
22038 instances and local (nested) function definitions. */
22039 if (must_output_die)
22043 /* If STMT block is abstract, that means we have been called
22044 indirectly from dwarf2out_abstract_function.
22045 That function rightfully marks the descendent blocks (of
22046 the abstract function it is dealing with) as being abstract,
22047 precisely to prevent us from emitting any
22048 DW_TAG_inlined_subroutine DIE as a descendent
22049 of an abstract function instance. So in that case, we should
22050 not call gen_inlined_subroutine_die.
22052 Later though, when cgraph asks dwarf2out to emit info
22053 for the concrete instance of the function decl into which
22054 the concrete instance of STMT got inlined, the later will lead
22055 to the generation of a DW_TAG_inlined_subroutine DIE. */
22056 if (! BLOCK_ABSTRACT (stmt))
22057 gen_inlined_subroutine_die (stmt, context_die, depth);
22060 gen_lexical_block_die (stmt, context_die, depth);
22063 decls_for_scope (stmt, context_die, depth);
22066 /* Process variable DECL (or variable with origin ORIGIN) within
22067 block STMT and add it to CONTEXT_DIE. */
22069 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
22072 tree decl_or_origin = decl ? decl : origin;
22074 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
22075 die = lookup_decl_die (decl_or_origin);
22076 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
22077 && TYPE_DECL_IS_STUB (decl_or_origin))
22078 die = lookup_type_die (TREE_TYPE (decl_or_origin));
22082 if (die != NULL && die->die_parent == NULL)
22083 add_child_die (context_die, die);
22084 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
22085 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
22086 stmt, context_die);
22088 gen_decl_die (decl, origin, context_die);
22091 /* Generate all of the decls declared within a given scope and (recursively)
22092 all of its sub-blocks. */
22095 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
22101 /* Ignore NULL blocks. */
22102 if (stmt == NULL_TREE)
22105 /* Output the DIEs to represent all of the data objects and typedefs
22106 declared directly within this block but not within any nested
22107 sub-blocks. Also, nested function and tag DIEs have been
22108 generated with a parent of NULL; fix that up now. */
22109 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
22110 process_scope_var (stmt, decl, NULL_TREE, context_die);
22111 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
22112 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
22115 /* If we're at -g1, we're not interested in subblocks. */
22116 if (debug_info_level <= DINFO_LEVEL_TERSE)
22119 /* Output the DIEs to represent all sub-blocks (and the items declared
22120 therein) of this block. */
22121 for (subblocks = BLOCK_SUBBLOCKS (stmt);
22123 subblocks = BLOCK_CHAIN (subblocks))
22124 gen_block_die (subblocks, context_die, depth + 1);
22127 /* Is this a typedef we can avoid emitting? */
22130 is_redundant_typedef (const_tree decl)
22132 if (TYPE_DECL_IS_STUB (decl))
22135 if (DECL_ARTIFICIAL (decl)
22136 && DECL_CONTEXT (decl)
22137 && is_tagged_type (DECL_CONTEXT (decl))
22138 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
22139 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
22140 /* Also ignore the artificial member typedef for the class name. */
22146 /* Return TRUE if TYPE is a typedef that names a type for linkage
22147 purposes. This kind of typedefs is produced by the C++ FE for
22150 typedef struct {...} foo;
22152 In that case, there is no typedef variant type produced for foo.
22153 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
22157 is_naming_typedef_decl (const_tree decl)
22159 if (decl == NULL_TREE
22160 || TREE_CODE (decl) != TYPE_DECL
22161 || !is_tagged_type (TREE_TYPE (decl))
22162 || DECL_IS_BUILTIN (decl)
22163 || is_redundant_typedef (decl)
22164 /* It looks like Ada produces TYPE_DECLs that are very similar
22165 to C++ naming typedefs but that have different
22166 semantics. Let's be specific to c++ for now. */
22170 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
22171 && TYPE_NAME (TREE_TYPE (decl)) == decl
22172 && (TYPE_STUB_DECL (TREE_TYPE (decl))
22173 != TYPE_NAME (TREE_TYPE (decl))));
22176 /* Returns the DIE for a context. */
22178 static inline dw_die_ref
22179 get_context_die (tree context)
22183 /* Find die that represents this context. */
22184 if (TYPE_P (context))
22186 context = TYPE_MAIN_VARIANT (context);
22187 return strip_naming_typedef (context, force_type_die (context));
22190 return force_decl_die (context);
22192 return comp_unit_die ();
22195 /* Returns the DIE for decl. A DIE will always be returned. */
22198 force_decl_die (tree decl)
22200 dw_die_ref decl_die;
22201 unsigned saved_external_flag;
22202 tree save_fn = NULL_TREE;
22203 decl_die = lookup_decl_die (decl);
22206 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
22208 decl_die = lookup_decl_die (decl);
22212 switch (TREE_CODE (decl))
22214 case FUNCTION_DECL:
22215 /* Clear current_function_decl, so that gen_subprogram_die thinks
22216 that this is a declaration. At this point, we just want to force
22217 declaration die. */
22218 save_fn = current_function_decl;
22219 current_function_decl = NULL_TREE;
22220 gen_subprogram_die (decl, context_die);
22221 current_function_decl = save_fn;
22225 /* Set external flag to force declaration die. Restore it after
22226 gen_decl_die() call. */
22227 saved_external_flag = DECL_EXTERNAL (decl);
22228 DECL_EXTERNAL (decl) = 1;
22229 gen_decl_die (decl, NULL, context_die);
22230 DECL_EXTERNAL (decl) = saved_external_flag;
22233 case NAMESPACE_DECL:
22234 if (dwarf_version >= 3 || !dwarf_strict)
22235 dwarf2out_decl (decl);
22237 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
22238 decl_die = comp_unit_die ();
22241 case TRANSLATION_UNIT_DECL:
22242 decl_die = comp_unit_die ();
22246 gcc_unreachable ();
22249 /* We should be able to find the DIE now. */
22251 decl_die = lookup_decl_die (decl);
22252 gcc_assert (decl_die);
22258 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
22259 always returned. */
22262 force_type_die (tree type)
22264 dw_die_ref type_die;
22266 type_die = lookup_type_die (type);
22269 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
22271 type_die = modified_type_die (type, TYPE_READONLY (type),
22272 TYPE_VOLATILE (type), context_die);
22273 gcc_assert (type_die);
22278 /* Force out any required namespaces to be able to output DECL,
22279 and return the new context_die for it, if it's changed. */
22282 setup_namespace_context (tree thing, dw_die_ref context_die)
22284 tree context = (DECL_P (thing)
22285 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
22286 if (context && TREE_CODE (context) == NAMESPACE_DECL)
22287 /* Force out the namespace. */
22288 context_die = force_decl_die (context);
22290 return context_die;
22293 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
22294 type) within its namespace, if appropriate.
22296 For compatibility with older debuggers, namespace DIEs only contain
22297 declarations; all definitions are emitted at CU scope. */
22300 declare_in_namespace (tree thing, dw_die_ref context_die)
22302 dw_die_ref ns_context;
22304 if (debug_info_level <= DINFO_LEVEL_TERSE)
22305 return context_die;
22307 /* If this decl is from an inlined function, then don't try to emit it in its
22308 namespace, as we will get confused. It would have already been emitted
22309 when the abstract instance of the inline function was emitted anyways. */
22310 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
22311 return context_die;
22313 ns_context = setup_namespace_context (thing, context_die);
22315 if (ns_context != context_die)
22319 if (DECL_P (thing))
22320 gen_decl_die (thing, NULL, ns_context);
22322 gen_type_die (thing, ns_context);
22324 return context_die;
22327 /* Generate a DIE for a namespace or namespace alias. */
22330 gen_namespace_die (tree decl, dw_die_ref context_die)
22332 dw_die_ref namespace_die;
22334 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
22335 they are an alias of. */
22336 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
22338 /* Output a real namespace or module. */
22339 context_die = setup_namespace_context (decl, comp_unit_die ());
22340 namespace_die = new_die (is_fortran ()
22341 ? DW_TAG_module : DW_TAG_namespace,
22342 context_die, decl);
22343 /* For Fortran modules defined in different CU don't add src coords. */
22344 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
22346 const char *name = dwarf2_name (decl, 0);
22348 add_name_attribute (namespace_die, name);
22351 add_name_and_src_coords_attributes (namespace_die, decl);
22352 if (DECL_EXTERNAL (decl))
22353 add_AT_flag (namespace_die, DW_AT_declaration, 1);
22354 equate_decl_number_to_die (decl, namespace_die);
22358 /* Output a namespace alias. */
22360 /* Force out the namespace we are an alias of, if necessary. */
22361 dw_die_ref origin_die
22362 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
22364 if (DECL_FILE_SCOPE_P (decl)
22365 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
22366 context_die = setup_namespace_context (decl, comp_unit_die ());
22367 /* Now create the namespace alias DIE. */
22368 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
22369 add_name_and_src_coords_attributes (namespace_die, decl);
22370 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
22371 equate_decl_number_to_die (decl, namespace_die);
22375 /* Generate Dwarf debug information for a decl described by DECL.
22376 The return value is currently only meaningful for PARM_DECLs,
22377 for all other decls it returns NULL. */
22380 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
22382 tree decl_or_origin = decl ? decl : origin;
22383 tree class_origin = NULL, ultimate_origin;
22385 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
22388 switch (TREE_CODE (decl_or_origin))
22394 if (!is_fortran () && !is_ada ())
22396 /* The individual enumerators of an enum type get output when we output
22397 the Dwarf representation of the relevant enum type itself. */
22401 /* Emit its type. */
22402 gen_type_die (TREE_TYPE (decl), context_die);
22404 /* And its containing namespace. */
22405 context_die = declare_in_namespace (decl, context_die);
22407 gen_const_die (decl, context_die);
22410 case FUNCTION_DECL:
22411 /* Don't output any DIEs to represent mere function declarations,
22412 unless they are class members or explicit block externs. */
22413 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
22414 && DECL_FILE_SCOPE_P (decl_or_origin)
22415 && (current_function_decl == NULL_TREE
22416 || DECL_ARTIFICIAL (decl_or_origin)))
22421 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
22422 on local redeclarations of global functions. That seems broken. */
22423 if (current_function_decl != decl)
22424 /* This is only a declaration. */;
22427 /* If we're emitting a clone, emit info for the abstract instance. */
22428 if (origin || DECL_ORIGIN (decl) != decl)
22429 dwarf2out_abstract_function (origin
22430 ? DECL_ORIGIN (origin)
22431 : DECL_ABSTRACT_ORIGIN (decl));
22433 /* If we're emitting an out-of-line copy of an inline function,
22434 emit info for the abstract instance and set up to refer to it. */
22435 else if (cgraph_function_possibly_inlined_p (decl)
22436 && ! DECL_ABSTRACT (decl)
22437 && ! class_or_namespace_scope_p (context_die)
22438 /* dwarf2out_abstract_function won't emit a die if this is just
22439 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
22440 that case, because that works only if we have a die. */
22441 && DECL_INITIAL (decl) != NULL_TREE)
22443 dwarf2out_abstract_function (decl);
22444 set_decl_origin_self (decl);
22447 /* Otherwise we're emitting the primary DIE for this decl. */
22448 else if (debug_info_level > DINFO_LEVEL_TERSE)
22450 /* Before we describe the FUNCTION_DECL itself, make sure that we
22451 have its containing type. */
22453 origin = decl_class_context (decl);
22454 if (origin != NULL_TREE)
22455 gen_type_die (origin, context_die);
22457 /* And its return type. */
22458 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
22460 /* And its virtual context. */
22461 if (DECL_VINDEX (decl) != NULL_TREE)
22462 gen_type_die (DECL_CONTEXT (decl), context_die);
22464 /* Make sure we have a member DIE for decl. */
22465 if (origin != NULL_TREE)
22466 gen_type_die_for_member (origin, decl, context_die);
22468 /* And its containing namespace. */
22469 context_die = declare_in_namespace (decl, context_die);
22472 /* Now output a DIE to represent the function itself. */
22474 gen_subprogram_die (decl, context_die);
22478 /* If we are in terse mode, don't generate any DIEs to represent any
22479 actual typedefs. */
22480 if (debug_info_level <= DINFO_LEVEL_TERSE)
22483 /* In the special case of a TYPE_DECL node representing the declaration
22484 of some type tag, if the given TYPE_DECL is marked as having been
22485 instantiated from some other (original) TYPE_DECL node (e.g. one which
22486 was generated within the original definition of an inline function) we
22487 used to generate a special (abbreviated) DW_TAG_structure_type,
22488 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
22489 should be actually referencing those DIEs, as variable DIEs with that
22490 type would be emitted already in the abstract origin, so it was always
22491 removed during unused type prunning. Don't add anything in this
22493 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
22496 if (is_redundant_typedef (decl))
22497 gen_type_die (TREE_TYPE (decl), context_die);
22499 /* Output a DIE to represent the typedef itself. */
22500 gen_typedef_die (decl, context_die);
22504 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22505 gen_label_die (decl, context_die);
22510 /* If we are in terse mode, don't generate any DIEs to represent any
22511 variable declarations or definitions. */
22512 if (debug_info_level <= DINFO_LEVEL_TERSE)
22515 /* Output any DIEs that are needed to specify the type of this data
22517 if (decl_by_reference_p (decl_or_origin))
22518 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
22520 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
22522 /* And its containing type. */
22523 class_origin = decl_class_context (decl_or_origin);
22524 if (class_origin != NULL_TREE)
22525 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
22527 /* And its containing namespace. */
22528 context_die = declare_in_namespace (decl_or_origin, context_die);
22530 /* Now output the DIE to represent the data object itself. This gets
22531 complicated because of the possibility that the VAR_DECL really
22532 represents an inlined instance of a formal parameter for an inline
22534 ultimate_origin = decl_ultimate_origin (decl_or_origin);
22535 if (ultimate_origin != NULL_TREE
22536 && TREE_CODE (ultimate_origin) == PARM_DECL)
22537 gen_formal_parameter_die (decl, origin,
22538 true /* Emit name attribute. */,
22541 gen_variable_die (decl, origin, context_die);
22545 /* Ignore the nameless fields that are used to skip bits but handle C++
22546 anonymous unions and structs. */
22547 if (DECL_NAME (decl) != NULL_TREE
22548 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
22549 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
22551 gen_type_die (member_declared_type (decl), context_die);
22552 gen_field_die (decl, context_die);
22557 if (DECL_BY_REFERENCE (decl_or_origin))
22558 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
22560 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
22561 return gen_formal_parameter_die (decl, origin,
22562 true /* Emit name attribute. */,
22565 case NAMESPACE_DECL:
22566 case IMPORTED_DECL:
22567 if (dwarf_version >= 3 || !dwarf_strict)
22568 gen_namespace_die (decl, context_die);
22572 /* Probably some frontend-internal decl. Assume we don't care. */
22573 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
22580 /* Output debug information for global decl DECL. Called from toplev.c after
22581 compilation proper has finished. */
22584 dwarf2out_global_decl (tree decl)
22586 /* Output DWARF2 information for file-scope tentative data object
22587 declarations, file-scope (extern) function declarations (which
22588 had no corresponding body) and file-scope tagged type declarations
22589 and definitions which have not yet been forced out. */
22590 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
22591 dwarf2out_decl (decl);
22594 /* Output debug information for type decl DECL. Called from toplev.c
22595 and from language front ends (to record built-in types). */
22597 dwarf2out_type_decl (tree decl, int local)
22600 dwarf2out_decl (decl);
22603 /* Output debug information for imported module or decl DECL.
22604 NAME is non-NULL name in the lexical block if the decl has been renamed.
22605 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
22606 that DECL belongs to.
22607 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
22609 dwarf2out_imported_module_or_decl_1 (tree decl,
22611 tree lexical_block,
22612 dw_die_ref lexical_block_die)
22614 expanded_location xloc;
22615 dw_die_ref imported_die = NULL;
22616 dw_die_ref at_import_die;
22618 if (TREE_CODE (decl) == IMPORTED_DECL)
22620 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
22621 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
22625 xloc = expand_location (input_location);
22627 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
22629 at_import_die = force_type_die (TREE_TYPE (decl));
22630 /* For namespace N { typedef void T; } using N::T; base_type_die
22631 returns NULL, but DW_TAG_imported_declaration requires
22632 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
22633 if (!at_import_die)
22635 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
22636 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
22637 at_import_die = lookup_type_die (TREE_TYPE (decl));
22638 gcc_assert (at_import_die);
22643 at_import_die = lookup_decl_die (decl);
22644 if (!at_import_die)
22646 /* If we're trying to avoid duplicate debug info, we may not have
22647 emitted the member decl for this field. Emit it now. */
22648 if (TREE_CODE (decl) == FIELD_DECL)
22650 tree type = DECL_CONTEXT (decl);
22652 if (TYPE_CONTEXT (type)
22653 && TYPE_P (TYPE_CONTEXT (type))
22654 && !should_emit_struct_debug (TYPE_CONTEXT (type),
22655 DINFO_USAGE_DIR_USE))
22657 gen_type_die_for_member (type, decl,
22658 get_context_die (TYPE_CONTEXT (type)));
22660 at_import_die = force_decl_die (decl);
22664 if (TREE_CODE (decl) == NAMESPACE_DECL)
22666 if (dwarf_version >= 3 || !dwarf_strict)
22667 imported_die = new_die (DW_TAG_imported_module,
22674 imported_die = new_die (DW_TAG_imported_declaration,
22678 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
22679 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
22681 add_AT_string (imported_die, DW_AT_name,
22682 IDENTIFIER_POINTER (name));
22683 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
22686 /* Output debug information for imported module or decl DECL.
22687 NAME is non-NULL name in context if the decl has been renamed.
22688 CHILD is true if decl is one of the renamed decls as part of
22689 importing whole module. */
22692 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
22695 /* dw_die_ref at_import_die; */
22696 dw_die_ref scope_die;
22698 if (debug_info_level <= DINFO_LEVEL_TERSE)
22703 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
22704 We need decl DIE for reference and scope die. First, get DIE for the decl
22707 /* Get the scope die for decl context. Use comp_unit_die for global module
22708 or decl. If die is not found for non globals, force new die. */
22710 && TYPE_P (context)
22711 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
22714 if (!(dwarf_version >= 3 || !dwarf_strict))
22717 scope_die = get_context_die (context);
22721 gcc_assert (scope_die->die_child);
22722 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
22723 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
22724 scope_die = scope_die->die_child;
22727 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
22728 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
22732 /* Write the debugging output for DECL. */
22735 dwarf2out_decl (tree decl)
22737 dw_die_ref context_die = comp_unit_die ();
22739 switch (TREE_CODE (decl))
22744 case FUNCTION_DECL:
22745 /* What we would really like to do here is to filter out all mere
22746 file-scope declarations of file-scope functions which are never
22747 referenced later within this translation unit (and keep all of ones
22748 that *are* referenced later on) but we aren't clairvoyant, so we have
22749 no idea which functions will be referenced in the future (i.e. later
22750 on within the current translation unit). So here we just ignore all
22751 file-scope function declarations which are not also definitions. If
22752 and when the debugger needs to know something about these functions,
22753 it will have to hunt around and find the DWARF information associated
22754 with the definition of the function.
22756 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
22757 nodes represent definitions and which ones represent mere
22758 declarations. We have to check DECL_INITIAL instead. That's because
22759 the C front-end supports some weird semantics for "extern inline"
22760 function definitions. These can get inlined within the current
22761 translation unit (and thus, we need to generate Dwarf info for their
22762 abstract instances so that the Dwarf info for the concrete inlined
22763 instances can have something to refer to) but the compiler never
22764 generates any out-of-lines instances of such things (despite the fact
22765 that they *are* definitions).
22767 The important point is that the C front-end marks these "extern
22768 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
22769 them anyway. Note that the C++ front-end also plays some similar games
22770 for inline function definitions appearing within include files which
22771 also contain `#pragma interface' pragmas. */
22772 if (DECL_INITIAL (decl) == NULL_TREE)
22775 /* If we're a nested function, initially use a parent of NULL; if we're
22776 a plain function, this will be fixed up in decls_for_scope. If
22777 we're a method, it will be ignored, since we already have a DIE. */
22778 if (decl_function_context (decl)
22779 /* But if we're in terse mode, we don't care about scope. */
22780 && debug_info_level > DINFO_LEVEL_TERSE)
22781 context_die = NULL;
22785 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
22786 declaration and if the declaration was never even referenced from
22787 within this entire compilation unit. We suppress these DIEs in
22788 order to save space in the .debug section (by eliminating entries
22789 which are probably useless). Note that we must not suppress
22790 block-local extern declarations (whether used or not) because that
22791 would screw-up the debugger's name lookup mechanism and cause it to
22792 miss things which really ought to be in scope at a given point. */
22793 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
22796 /* For local statics lookup proper context die. */
22797 if (TREE_STATIC (decl) && decl_function_context (decl))
22798 context_die = lookup_decl_die (DECL_CONTEXT (decl));
22800 /* If we are in terse mode, don't generate any DIEs to represent any
22801 variable declarations or definitions. */
22802 if (debug_info_level <= DINFO_LEVEL_TERSE)
22807 if (debug_info_level <= DINFO_LEVEL_TERSE)
22809 if (!is_fortran () && !is_ada ())
22811 if (TREE_STATIC (decl) && decl_function_context (decl))
22812 context_die = lookup_decl_die (DECL_CONTEXT (decl));
22815 case NAMESPACE_DECL:
22816 case IMPORTED_DECL:
22817 if (debug_info_level <= DINFO_LEVEL_TERSE)
22819 if (lookup_decl_die (decl) != NULL)
22824 /* Don't emit stubs for types unless they are needed by other DIEs. */
22825 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
22828 /* Don't bother trying to generate any DIEs to represent any of the
22829 normal built-in types for the language we are compiling. */
22830 if (DECL_IS_BUILTIN (decl))
22833 /* If we are in terse mode, don't generate any DIEs for types. */
22834 if (debug_info_level <= DINFO_LEVEL_TERSE)
22837 /* If we're a function-scope tag, initially use a parent of NULL;
22838 this will be fixed up in decls_for_scope. */
22839 if (decl_function_context (decl))
22840 context_die = NULL;
22848 gen_decl_die (decl, NULL, context_die);
22851 /* Write the debugging output for DECL. */
22854 dwarf2out_function_decl (tree decl)
22856 dwarf2out_decl (decl);
22857 call_arg_locations = NULL;
22858 call_arg_loc_last = NULL;
22859 call_site_count = -1;
22860 tail_call_site_count = -1;
22861 VEC_free (dw_die_ref, heap, block_map);
22862 htab_empty (decl_loc_table);
22863 htab_empty (cached_dw_loc_list_table);
22866 /* Output a marker (i.e. a label) for the beginning of the generated code for
22867 a lexical block. */
22870 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
22871 unsigned int blocknum)
22873 switch_to_section (current_function_section ());
22874 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
22877 /* Output a marker (i.e. a label) for the end of the generated code for a
22881 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
22883 switch_to_section (current_function_section ());
22884 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
22887 /* Returns nonzero if it is appropriate not to emit any debugging
22888 information for BLOCK, because it doesn't contain any instructions.
22890 Don't allow this for blocks with nested functions or local classes
22891 as we would end up with orphans, and in the presence of scheduling
22892 we may end up calling them anyway. */
22895 dwarf2out_ignore_block (const_tree block)
22900 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
22901 if (TREE_CODE (decl) == FUNCTION_DECL
22902 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22904 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
22906 decl = BLOCK_NONLOCALIZED_VAR (block, i);
22907 if (TREE_CODE (decl) == FUNCTION_DECL
22908 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22915 /* Hash table routines for file_hash. */
22918 file_table_eq (const void *p1_p, const void *p2_p)
22920 const struct dwarf_file_data *const p1 =
22921 (const struct dwarf_file_data *) p1_p;
22922 const char *const p2 = (const char *) p2_p;
22923 return filename_cmp (p1->filename, p2) == 0;
22927 file_table_hash (const void *p_p)
22929 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
22930 return htab_hash_string (p->filename);
22933 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22934 dwarf2out.c) and return its "index". The index of each (known) filename is
22935 just a unique number which is associated with only that one filename. We
22936 need such numbers for the sake of generating labels (in the .debug_sfnames
22937 section) and references to those files numbers (in the .debug_srcinfo
22938 and.debug_macinfo sections). If the filename given as an argument is not
22939 found in our current list, add it to the list and assign it the next
22940 available unique index number. In order to speed up searches, we remember
22941 the index of the filename was looked up last. This handles the majority of
22944 static struct dwarf_file_data *
22945 lookup_filename (const char *file_name)
22948 struct dwarf_file_data * created;
22950 /* Check to see if the file name that was searched on the previous
22951 call matches this file name. If so, return the index. */
22952 if (file_table_last_lookup
22953 && (file_name == file_table_last_lookup->filename
22954 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
22955 return file_table_last_lookup;
22957 /* Didn't match the previous lookup, search the table. */
22958 slot = htab_find_slot_with_hash (file_table, file_name,
22959 htab_hash_string (file_name), INSERT);
22961 return (struct dwarf_file_data *) *slot;
22963 created = ggc_alloc_dwarf_file_data ();
22964 created->filename = file_name;
22965 created->emitted_number = 0;
22970 /* If the assembler will construct the file table, then translate the compiler
22971 internal file table number into the assembler file table number, and emit
22972 a .file directive if we haven't already emitted one yet. The file table
22973 numbers are different because we prune debug info for unused variables and
22974 types, which may include filenames. */
22977 maybe_emit_file (struct dwarf_file_data * fd)
22979 if (! fd->emitted_number)
22981 if (last_emitted_file)
22982 fd->emitted_number = last_emitted_file->emitted_number + 1;
22984 fd->emitted_number = 1;
22985 last_emitted_file = fd;
22987 if (DWARF2_ASM_LINE_DEBUG_INFO)
22989 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
22990 output_quoted_string (asm_out_file,
22991 remap_debug_filename (fd->filename));
22992 fputc ('\n', asm_out_file);
22996 return fd->emitted_number;
22999 /* Schedule generation of a DW_AT_const_value attribute to DIE.
23000 That generation should happen after function debug info has been
23001 generated. The value of the attribute is the constant value of ARG. */
23004 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
23006 die_arg_entry entry;
23011 if (!tmpl_value_parm_die_table)
23012 tmpl_value_parm_die_table
23013 = VEC_alloc (die_arg_entry, gc, 32);
23017 VEC_safe_push (die_arg_entry, gc,
23018 tmpl_value_parm_die_table,
23022 /* Return TRUE if T is an instance of generic type, FALSE
23026 generic_type_p (tree t)
23028 if (t == NULL_TREE || !TYPE_P (t))
23030 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
23033 /* Schedule the generation of the generic parameter dies for the
23034 instance of generic type T. The proper generation itself is later
23035 done by gen_scheduled_generic_parms_dies. */
23038 schedule_generic_params_dies_gen (tree t)
23040 if (!generic_type_p (t))
23043 if (generic_type_instances == NULL)
23044 generic_type_instances = VEC_alloc (tree, gc, 256);
23046 VEC_safe_push (tree, gc, generic_type_instances, t);
23049 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
23050 by append_entry_to_tmpl_value_parm_die_table. This function must
23051 be called after function DIEs have been generated. */
23054 gen_remaining_tmpl_value_param_die_attribute (void)
23056 if (tmpl_value_parm_die_table)
23061 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
23062 tree_add_const_value_attribute (e->die, e->arg);
23066 /* Generate generic parameters DIEs for instances of generic types
23067 that have been previously scheduled by
23068 schedule_generic_params_dies_gen. This function must be called
23069 after all the types of the CU have been laid out. */
23072 gen_scheduled_generic_parms_dies (void)
23077 if (generic_type_instances == NULL)
23080 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
23081 gen_generic_params_dies (t);
23085 /* Replace DW_AT_name for the decl with name. */
23088 dwarf2out_set_name (tree decl, tree name)
23094 die = TYPE_SYMTAB_DIE (decl);
23098 dname = dwarf2_name (name, 0);
23102 attr = get_AT (die, DW_AT_name);
23105 struct indirect_string_node *node;
23107 node = find_AT_string (dname);
23108 /* replace the string. */
23109 attr->dw_attr_val.v.val_str = node;
23113 add_name_attribute (die, dname);
23116 /* Called by the final INSN scan whenever we see a var location. We
23117 use it to drop labels in the right places, and throw the location in
23118 our lookup table. */
23121 dwarf2out_var_location (rtx loc_note)
23123 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
23124 struct var_loc_node *newloc;
23126 static const char *last_label;
23127 static const char *last_postcall_label;
23128 static bool last_in_cold_section_p;
23132 if (!NOTE_P (loc_note))
23134 if (CALL_P (loc_note))
23137 if (SIBLING_CALL_P (loc_note))
23138 tail_call_site_count++;
23143 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
23144 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
23147 next_real = next_real_insn (loc_note);
23149 /* If there are no instructions which would be affected by this note,
23150 don't do anything. */
23152 && next_real == NULL_RTX
23153 && !NOTE_DURING_CALL_P (loc_note))
23156 if (next_real == NULL_RTX)
23157 next_real = get_last_insn ();
23159 /* If there were any real insns between note we processed last time
23160 and this note (or if it is the first note), clear
23161 last_{,postcall_}label so that they are not reused this time. */
23162 if (last_var_location_insn == NULL_RTX
23163 || last_var_location_insn != next_real
23164 || last_in_cold_section_p != in_cold_section_p)
23167 last_postcall_label = NULL;
23172 decl = NOTE_VAR_LOCATION_DECL (loc_note);
23173 newloc = add_var_loc_to_decl (decl, loc_note,
23174 NOTE_DURING_CALL_P (loc_note)
23175 ? last_postcall_label : last_label);
23176 if (newloc == NULL)
23185 /* If there were no real insns between note we processed last time
23186 and this note, use the label we emitted last time. Otherwise
23187 create a new label and emit it. */
23188 if (last_label == NULL)
23190 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
23191 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
23193 last_label = ggc_strdup (loclabel);
23198 struct call_arg_loc_node *ca_loc
23199 = ggc_alloc_cleared_call_arg_loc_node ();
23200 rtx prev = prev_real_insn (loc_note), x;
23201 ca_loc->call_arg_loc_note = loc_note;
23202 ca_loc->next = NULL;
23203 ca_loc->label = last_label;
23206 || (NONJUMP_INSN_P (prev)
23207 && GET_CODE (PATTERN (prev)) == SEQUENCE
23208 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
23209 if (!CALL_P (prev))
23210 prev = XVECEXP (PATTERN (prev), 0, 0);
23211 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
23212 x = PATTERN (prev);
23213 if (GET_CODE (x) == PARALLEL)
23214 x = XVECEXP (x, 0, 0);
23215 if (GET_CODE (x) == SET)
23217 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
23219 x = XEXP (XEXP (x, 0), 0);
23220 if (GET_CODE (x) == SYMBOL_REF
23221 && SYMBOL_REF_DECL (x)
23222 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
23223 ca_loc->symbol_ref = x;
23225 ca_loc->block = insn_scope (prev);
23226 if (call_arg_locations)
23227 call_arg_loc_last->next = ca_loc;
23229 call_arg_locations = ca_loc;
23230 call_arg_loc_last = ca_loc;
23232 else if (!NOTE_DURING_CALL_P (loc_note))
23233 newloc->label = last_label;
23236 if (!last_postcall_label)
23238 sprintf (loclabel, "%s-1", last_label);
23239 last_postcall_label = ggc_strdup (loclabel);
23241 newloc->label = last_postcall_label;
23244 last_var_location_insn = next_real;
23245 last_in_cold_section_p = in_cold_section_p;
23248 /* Note in one location list that text section has changed. */
23251 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
23253 var_loc_list *list = (var_loc_list *) *slot;
23255 list->last_before_switch
23256 = list->last->next ? list->last->next : list->last;
23260 /* Note in all location lists that text section has changed. */
23263 var_location_switch_text_section (void)
23265 if (decl_loc_table == NULL)
23268 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
23271 /* Create a new line number table. */
23273 static dw_line_info_table *
23274 new_line_info_table (void)
23276 dw_line_info_table *table;
23278 table = ggc_alloc_cleared_dw_line_info_table_struct ();
23279 table->file_num = 1;
23280 table->line_num = 1;
23281 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
23286 /* Lookup the "current" table into which we emit line info, so
23287 that we don't have to do it for every source line. */
23290 set_cur_line_info_table (section *sec)
23292 dw_line_info_table *table;
23294 if (sec == text_section)
23295 table = text_section_line_info;
23296 else if (sec == cold_text_section)
23298 table = cold_text_section_line_info;
23301 cold_text_section_line_info = table = new_line_info_table ();
23302 table->end_label = cold_end_label;
23307 const char *end_label;
23309 if (flag_reorder_blocks_and_partition)
23311 if (in_cold_section_p)
23312 end_label = crtl->subsections.cold_section_end_label;
23314 end_label = crtl->subsections.hot_section_end_label;
23318 char label[MAX_ARTIFICIAL_LABEL_BYTES];
23319 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
23320 current_function_funcdef_no);
23321 end_label = ggc_strdup (label);
23324 table = new_line_info_table ();
23325 table->end_label = end_label;
23327 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
23330 cur_line_info_table = table;
23334 /* We need to reset the locations at the beginning of each
23335 function. We can't do this in the end_function hook, because the
23336 declarations that use the locations won't have been output when
23337 that hook is called. Also compute have_multiple_function_sections here. */
23340 dwarf2out_begin_function (tree fun)
23342 section *sec = function_section (fun);
23344 if (sec != text_section)
23345 have_multiple_function_sections = true;
23347 if (flag_reorder_blocks_and_partition && !cold_text_section)
23349 gcc_assert (current_function_decl == fun);
23350 cold_text_section = unlikely_text_section ();
23351 switch_to_section (cold_text_section);
23352 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
23353 switch_to_section (sec);
23356 dwarf2out_note_section_used ();
23357 call_site_count = 0;
23358 tail_call_site_count = 0;
23360 set_cur_line_info_table (sec);
23363 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
23366 push_dw_line_info_entry (dw_line_info_table *table,
23367 enum dw_line_info_opcode opcode, unsigned int val)
23369 dw_line_info_entry e;
23372 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
23375 /* Output a label to mark the beginning of a source code line entry
23376 and record information relating to this source line, in
23377 'line_info_table' for later output of the .debug_line section. */
23378 /* ??? The discriminator parameter ought to be unsigned. */
23381 dwarf2out_source_line (unsigned int line, const char *filename,
23382 int discriminator, bool is_stmt)
23384 unsigned int file_num;
23385 dw_line_info_table *table;
23387 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
23390 /* The discriminator column was added in dwarf4. Simplify the below
23391 by simply removing it if we're not supposed to output it. */
23392 if (dwarf_version < 4 && dwarf_strict)
23395 table = cur_line_info_table;
23396 file_num = maybe_emit_file (lookup_filename (filename));
23398 /* ??? TODO: Elide duplicate line number entries. Traditionally,
23399 the debugger has used the second (possibly duplicate) line number
23400 at the beginning of the function to mark the end of the prologue.
23401 We could eliminate any other duplicates within the function. For
23402 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
23403 that second line number entry. */
23404 /* Recall that this end-of-prologue indication is *not* the same thing
23405 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
23406 to which the hook corresponds, follows the last insn that was
23407 emitted by gen_prologue. What we need is to preceed the first insn
23408 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
23409 insn that corresponds to something the user wrote. These may be
23410 very different locations once scheduling is enabled. */
23412 if (0 && file_num == table->file_num
23413 && line == table->line_num
23414 && discriminator == table->discrim_num
23415 && is_stmt == table->is_stmt)
23418 switch_to_section (current_function_section ());
23420 /* If requested, emit something human-readable. */
23421 if (flag_debug_asm)
23422 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
23424 if (DWARF2_ASM_LINE_DEBUG_INFO)
23426 /* Emit the .loc directive understood by GNU as. */
23427 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
23428 if (is_stmt != table->is_stmt)
23429 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
23430 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
23431 fprintf (asm_out_file, " discriminator %d", discriminator);
23432 fputc ('\n', asm_out_file);
23436 unsigned int label_num = ++line_info_label_num;
23438 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
23440 push_dw_line_info_entry (table, LI_set_address, label_num);
23441 if (file_num != table->file_num)
23442 push_dw_line_info_entry (table, LI_set_file, file_num);
23443 if (discriminator != table->discrim_num)
23444 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
23445 if (is_stmt != table->is_stmt)
23446 push_dw_line_info_entry (table, LI_negate_stmt, 0);
23447 push_dw_line_info_entry (table, LI_set_line, line);
23450 table->file_num = file_num;
23451 table->line_num = line;
23452 table->discrim_num = discriminator;
23453 table->is_stmt = is_stmt;
23454 table->in_use = true;
23457 /* Record the beginning of a new source file. */
23460 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
23462 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
23464 /* Record the beginning of the file for break_out_includes. */
23465 dw_die_ref bincl_die;
23467 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
23468 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
23471 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23474 e.code = DW_MACINFO_start_file;
23476 e.info = xstrdup (filename);
23477 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23481 /* Record the end of a source file. */
23484 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
23486 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
23487 /* Record the end of the file for break_out_includes. */
23488 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
23490 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23493 e.code = DW_MACINFO_end_file;
23496 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23500 /* Called from debug_define in toplev.c. The `buffer' parameter contains
23501 the tail part of the directive line, i.e. the part which is past the
23502 initial whitespace, #, whitespace, directive-name, whitespace part. */
23505 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
23506 const char *buffer ATTRIBUTE_UNUSED)
23508 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23511 e.code = DW_MACINFO_define;
23513 e.info = xstrdup (buffer);;
23514 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23518 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
23519 the tail part of the directive line, i.e. the part which is past the
23520 initial whitespace, #, whitespace, directive-name, whitespace part. */
23523 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
23524 const char *buffer ATTRIBUTE_UNUSED)
23526 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23529 e.code = DW_MACINFO_undef;
23531 e.info = xstrdup (buffer);;
23532 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23537 output_macinfo (void)
23540 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
23541 macinfo_entry *ref;
23546 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
23550 case DW_MACINFO_start_file:
23552 int file_num = maybe_emit_file (lookup_filename (ref->info));
23553 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
23554 dw2_asm_output_data_uleb128
23555 (ref->lineno, "Included from line number %lu",
23556 (unsigned long)ref->lineno);
23557 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
23560 case DW_MACINFO_end_file:
23561 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
23563 case DW_MACINFO_define:
23564 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
23565 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
23566 (unsigned long)ref->lineno);
23567 dw2_asm_output_nstring (ref->info, -1, "The macro");
23569 case DW_MACINFO_undef:
23570 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
23571 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
23572 (unsigned long)ref->lineno);
23573 dw2_asm_output_nstring (ref->info, -1, "The macro");
23576 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
23577 ASM_COMMENT_START, (unsigned long)ref->code);
23583 /* Set up for Dwarf output at the start of compilation. */
23586 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
23588 /* Allocate the file_table. */
23589 file_table = htab_create_ggc (50, file_table_hash,
23590 file_table_eq, NULL);
23592 /* Allocate the decl_die_table. */
23593 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
23594 decl_die_table_eq, NULL);
23596 /* Allocate the decl_loc_table. */
23597 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
23598 decl_loc_table_eq, NULL);
23600 /* Allocate the cached_dw_loc_list_table. */
23601 cached_dw_loc_list_table
23602 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
23603 cached_dw_loc_list_table_eq, NULL);
23605 /* Allocate the initial hunk of the decl_scope_table. */
23606 decl_scope_table = VEC_alloc (tree, gc, 256);
23608 /* Allocate the initial hunk of the abbrev_die_table. */
23609 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
23610 (ABBREV_DIE_TABLE_INCREMENT);
23611 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
23612 /* Zero-th entry is allocated, but unused. */
23613 abbrev_die_table_in_use = 1;
23615 /* Allocate the pubtypes and pubnames vectors. */
23616 pubname_table = VEC_alloc (pubname_entry, gc, 32);
23617 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
23619 incomplete_types = VEC_alloc (tree, gc, 64);
23621 used_rtx_array = VEC_alloc (rtx, gc, 32);
23623 debug_info_section = get_section (DEBUG_INFO_SECTION,
23624 SECTION_DEBUG, NULL);
23625 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
23626 SECTION_DEBUG, NULL);
23627 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
23628 SECTION_DEBUG, NULL);
23629 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
23630 SECTION_DEBUG, NULL);
23631 debug_line_section = get_section (DEBUG_LINE_SECTION,
23632 SECTION_DEBUG, NULL);
23633 debug_loc_section = get_section (DEBUG_LOC_SECTION,
23634 SECTION_DEBUG, NULL);
23635 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
23636 SECTION_DEBUG, NULL);
23637 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
23638 SECTION_DEBUG, NULL);
23639 debug_str_section = get_section (DEBUG_STR_SECTION,
23640 DEBUG_STR_SECTION_FLAGS, NULL);
23641 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
23642 SECTION_DEBUG, NULL);
23643 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
23644 SECTION_DEBUG, NULL);
23646 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
23647 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
23648 DEBUG_ABBREV_SECTION_LABEL, 0);
23649 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
23650 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
23651 COLD_TEXT_SECTION_LABEL, 0);
23652 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
23654 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
23655 DEBUG_INFO_SECTION_LABEL, 0);
23656 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
23657 DEBUG_LINE_SECTION_LABEL, 0);
23658 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
23659 DEBUG_RANGES_SECTION_LABEL, 0);
23660 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
23661 DEBUG_MACINFO_SECTION_LABEL, 0);
23663 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23664 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
23666 switch_to_section (text_section);
23667 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
23669 /* Make sure the line number table for .text always exists. */
23670 text_section_line_info = new_line_info_table ();
23671 text_section_line_info->end_label = text_end_label;
23674 /* Called before cgraph_optimize starts outputtting functions, variables
23675 and toplevel asms into assembly. */
23678 dwarf2out_assembly_start (void)
23680 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23681 && dwarf2out_do_cfi_asm ()
23682 && (!(flag_unwind_tables || flag_exceptions)
23683 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
23684 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
23687 /* A helper function for dwarf2out_finish called through
23688 htab_traverse. Emit one queued .debug_str string. */
23691 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
23693 struct indirect_string_node *node = (struct indirect_string_node *) *h;
23695 if (node->form == DW_FORM_strp)
23697 switch_to_section (debug_str_section);
23698 ASM_OUTPUT_LABEL (asm_out_file, node->label);
23699 assemble_string (node->str, strlen (node->str) + 1);
23705 #if ENABLE_ASSERT_CHECKING
23706 /* Verify that all marks are clear. */
23709 verify_marks_clear (dw_die_ref die)
23713 gcc_assert (! die->die_mark);
23714 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
23716 #endif /* ENABLE_ASSERT_CHECKING */
23718 /* Clear the marks for a die and its children.
23719 Be cool if the mark isn't set. */
23722 prune_unmark_dies (dw_die_ref die)
23728 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
23731 /* Given DIE that we're marking as used, find any other dies
23732 it references as attributes and mark them as used. */
23735 prune_unused_types_walk_attribs (dw_die_ref die)
23740 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23742 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
23744 /* A reference to another DIE.
23745 Make sure that it will get emitted.
23746 If it was broken out into a comdat group, don't follow it. */
23747 if (! use_debug_types
23748 || a->dw_attr == DW_AT_specification
23749 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
23750 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
23752 /* Set the string's refcount to 0 so that prune_unused_types_mark
23753 accounts properly for it. */
23754 if (AT_class (a) == dw_val_class_str)
23755 a->dw_attr_val.v.val_str->refcount = 0;
23759 /* Mark the generic parameters and arguments children DIEs of DIE. */
23762 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
23766 if (die == NULL || die->die_child == NULL)
23768 c = die->die_child;
23771 switch (c->die_tag)
23773 case DW_TAG_template_type_param:
23774 case DW_TAG_template_value_param:
23775 case DW_TAG_GNU_template_template_param:
23776 case DW_TAG_GNU_template_parameter_pack:
23777 prune_unused_types_mark (c, 1);
23783 } while (c && c != die->die_child);
23786 /* Mark DIE as being used. If DOKIDS is true, then walk down
23787 to DIE's children. */
23790 prune_unused_types_mark (dw_die_ref die, int dokids)
23794 if (die->die_mark == 0)
23796 /* We haven't done this node yet. Mark it as used. */
23798 /* If this is the DIE of a generic type instantiation,
23799 mark the children DIEs that describe its generic parms and
23801 prune_unused_types_mark_generic_parms_dies (die);
23803 /* We also have to mark its parents as used.
23804 (But we don't want to mark our parents' kids due to this.) */
23805 if (die->die_parent)
23806 prune_unused_types_mark (die->die_parent, 0);
23808 /* Mark any referenced nodes. */
23809 prune_unused_types_walk_attribs (die);
23811 /* If this node is a specification,
23812 also mark the definition, if it exists. */
23813 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
23814 prune_unused_types_mark (die->die_definition, 1);
23817 if (dokids && die->die_mark != 2)
23819 /* We need to walk the children, but haven't done so yet.
23820 Remember that we've walked the kids. */
23823 /* If this is an array type, we need to make sure our
23824 kids get marked, even if they're types. If we're
23825 breaking out types into comdat sections, do this
23826 for all type definitions. */
23827 if (die->die_tag == DW_TAG_array_type
23828 || (use_debug_types
23829 && is_type_die (die) && ! is_declaration_die (die)))
23830 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
23832 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23836 /* For local classes, look if any static member functions were emitted
23837 and if so, mark them. */
23840 prune_unused_types_walk_local_classes (dw_die_ref die)
23844 if (die->die_mark == 2)
23847 switch (die->die_tag)
23849 case DW_TAG_structure_type:
23850 case DW_TAG_union_type:
23851 case DW_TAG_class_type:
23854 case DW_TAG_subprogram:
23855 if (!get_AT_flag (die, DW_AT_declaration)
23856 || die->die_definition != NULL)
23857 prune_unused_types_mark (die, 1);
23864 /* Mark children. */
23865 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
23868 /* Walk the tree DIE and mark types that we actually use. */
23871 prune_unused_types_walk (dw_die_ref die)
23875 /* Don't do anything if this node is already marked and
23876 children have been marked as well. */
23877 if (die->die_mark == 2)
23880 switch (die->die_tag)
23882 case DW_TAG_structure_type:
23883 case DW_TAG_union_type:
23884 case DW_TAG_class_type:
23885 if (die->die_perennial_p)
23888 for (c = die->die_parent; c; c = c->die_parent)
23889 if (c->die_tag == DW_TAG_subprogram)
23892 /* Finding used static member functions inside of classes
23893 is needed just for local classes, because for other classes
23894 static member function DIEs with DW_AT_specification
23895 are emitted outside of the DW_TAG_*_type. If we ever change
23896 it, we'd need to call this even for non-local classes. */
23898 prune_unused_types_walk_local_classes (die);
23900 /* It's a type node --- don't mark it. */
23903 case DW_TAG_const_type:
23904 case DW_TAG_packed_type:
23905 case DW_TAG_pointer_type:
23906 case DW_TAG_reference_type:
23907 case DW_TAG_rvalue_reference_type:
23908 case DW_TAG_volatile_type:
23909 case DW_TAG_typedef:
23910 case DW_TAG_array_type:
23911 case DW_TAG_interface_type:
23912 case DW_TAG_friend:
23913 case DW_TAG_variant_part:
23914 case DW_TAG_enumeration_type:
23915 case DW_TAG_subroutine_type:
23916 case DW_TAG_string_type:
23917 case DW_TAG_set_type:
23918 case DW_TAG_subrange_type:
23919 case DW_TAG_ptr_to_member_type:
23920 case DW_TAG_file_type:
23921 if (die->die_perennial_p)
23924 /* It's a type node --- don't mark it. */
23928 /* Mark everything else. */
23932 if (die->die_mark == 0)
23936 /* Now, mark any dies referenced from here. */
23937 prune_unused_types_walk_attribs (die);
23942 /* Mark children. */
23943 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23946 /* Increment the string counts on strings referred to from DIE's
23950 prune_unused_types_update_strings (dw_die_ref die)
23955 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23956 if (AT_class (a) == dw_val_class_str)
23958 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
23960 /* Avoid unnecessarily putting strings that are used less than
23961 twice in the hash table. */
23963 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
23966 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
23967 htab_hash_string (s->str),
23969 gcc_assert (*slot == NULL);
23975 /* Remove from the tree DIE any dies that aren't marked. */
23978 prune_unused_types_prune (dw_die_ref die)
23982 gcc_assert (die->die_mark);
23983 prune_unused_types_update_strings (die);
23985 if (! die->die_child)
23988 c = die->die_child;
23990 dw_die_ref prev = c;
23991 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
23992 if (c == die->die_child)
23994 /* No marked children between 'prev' and the end of the list. */
23996 /* No marked children at all. */
23997 die->die_child = NULL;
24000 prev->die_sib = c->die_sib;
24001 die->die_child = prev;
24006 if (c != prev->die_sib)
24008 prune_unused_types_prune (c);
24009 } while (c != die->die_child);
24012 /* Remove dies representing declarations that we never use. */
24015 prune_unused_types (void)
24018 limbo_die_node *node;
24019 comdat_type_node *ctnode;
24021 dw_die_ref base_type;
24023 #if ENABLE_ASSERT_CHECKING
24024 /* All the marks should already be clear. */
24025 verify_marks_clear (comp_unit_die ());
24026 for (node = limbo_die_list; node; node = node->next)
24027 verify_marks_clear (node->die);
24028 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
24029 verify_marks_clear (ctnode->root_die);
24030 #endif /* ENABLE_ASSERT_CHECKING */
24032 /* Mark types that are used in global variables. */
24033 premark_types_used_by_global_vars ();
24035 /* Set the mark on nodes that are actually used. */
24036 prune_unused_types_walk (comp_unit_die ());
24037 for (node = limbo_die_list; node; node = node->next)
24038 prune_unused_types_walk (node->die);
24039 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
24041 prune_unused_types_walk (ctnode->root_die);
24042 prune_unused_types_mark (ctnode->type_die, 1);
24045 /* Also set the mark on nodes referenced from the
24047 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
24048 prune_unused_types_mark (pub->die, 1);
24049 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
24050 prune_unused_types_mark (base_type, 1);
24052 if (debug_str_hash)
24053 htab_empty (debug_str_hash);
24054 prune_unused_types_prune (comp_unit_die ());
24055 for (node = limbo_die_list; node; node = node->next)
24056 prune_unused_types_prune (node->die);
24057 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
24058 prune_unused_types_prune (ctnode->root_die);
24060 /* Leave the marks clear. */
24061 prune_unmark_dies (comp_unit_die ());
24062 for (node = limbo_die_list; node; node = node->next)
24063 prune_unmark_dies (node->die);
24064 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
24065 prune_unmark_dies (ctnode->root_die);
24068 /* Set the parameter to true if there are any relative pathnames in
24071 file_table_relative_p (void ** slot, void *param)
24073 bool *p = (bool *) param;
24074 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
24075 if (!IS_ABSOLUTE_PATH (d->filename))
24083 /* Routines to manipulate hash table of comdat type units. */
24086 htab_ct_hash (const void *of)
24089 const comdat_type_node *const type_node = (const comdat_type_node *) of;
24091 memcpy (&h, type_node->signature, sizeof (h));
24096 htab_ct_eq (const void *of1, const void *of2)
24098 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
24099 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
24101 return (! memcmp (type_node_1->signature, type_node_2->signature,
24102 DWARF_TYPE_SIGNATURE_SIZE));
24105 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
24106 to the location it would have been added, should we know its
24107 DECL_ASSEMBLER_NAME when we added other attributes. This will
24108 probably improve compactness of debug info, removing equivalent
24109 abbrevs, and hide any differences caused by deferring the
24110 computation of the assembler name, triggered by e.g. PCH. */
24113 move_linkage_attr (dw_die_ref die)
24115 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
24116 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
24118 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
24119 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
24123 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
24125 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
24129 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
24131 VEC_pop (dw_attr_node, die->die_attr);
24132 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
24136 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
24137 referenced from typed stack ops and count how often they are used. */
24140 mark_base_types (dw_loc_descr_ref loc)
24142 dw_die_ref base_type = NULL;
24144 for (; loc; loc = loc->dw_loc_next)
24146 switch (loc->dw_loc_opc)
24148 case DW_OP_GNU_regval_type:
24149 case DW_OP_GNU_deref_type:
24150 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
24152 case DW_OP_GNU_convert:
24153 case DW_OP_GNU_reinterpret:
24154 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
24157 case DW_OP_GNU_const_type:
24158 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
24160 case DW_OP_GNU_entry_value:
24161 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
24166 gcc_assert (base_type->die_parent == comp_unit_die ());
24167 if (base_type->die_mark)
24168 base_type->die_mark++;
24171 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
24172 base_type->die_mark = 1;
24177 /* Comparison function for sorting marked base types. */
24180 base_type_cmp (const void *x, const void *y)
24182 dw_die_ref dx = *(const dw_die_ref *) x;
24183 dw_die_ref dy = *(const dw_die_ref *) y;
24184 unsigned int byte_size1, byte_size2;
24185 unsigned int encoding1, encoding2;
24186 if (dx->die_mark > dy->die_mark)
24188 if (dx->die_mark < dy->die_mark)
24190 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
24191 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
24192 if (byte_size1 < byte_size2)
24194 if (byte_size1 > byte_size2)
24196 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
24197 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
24198 if (encoding1 < encoding2)
24200 if (encoding1 > encoding2)
24205 /* Move base types marked by mark_base_types as early as possible
24206 in the CU, sorted by decreasing usage count both to make the
24207 uleb128 references as small as possible and to make sure they
24208 will have die_offset already computed by calc_die_sizes when
24209 sizes of typed stack loc ops is computed. */
24212 move_marked_base_types (void)
24215 dw_die_ref base_type, die, c;
24217 if (VEC_empty (dw_die_ref, base_types))
24220 /* Sort by decreasing usage count, they will be added again in that
24222 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
24223 die = comp_unit_die ();
24224 c = die->die_child;
24227 dw_die_ref prev = c;
24229 while (c->die_mark)
24231 remove_child_with_prev (c, prev);
24232 /* As base types got marked, there must be at least
24233 one node other than DW_TAG_base_type. */
24234 gcc_assert (c != c->die_sib);
24238 while (c != die->die_child);
24239 gcc_assert (die->die_child);
24240 c = die->die_child;
24241 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
24243 base_type->die_mark = 0;
24244 base_type->die_sib = c->die_sib;
24245 c->die_sib = base_type;
24250 /* Helper function for resolve_addr, attempt to resolve
24251 one CONST_STRING, return non-zero if not successful. Similarly verify that
24252 SYMBOL_REFs refer to variables emitted in the current CU. */
24255 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
24259 if (GET_CODE (rtl) == CONST_STRING)
24261 size_t len = strlen (XSTR (rtl, 0)) + 1;
24262 tree t = build_string (len, XSTR (rtl, 0));
24263 tree tlen = size_int (len - 1);
24265 = build_array_type (char_type_node, build_index_type (tlen));
24266 rtl = lookup_constant_def (t);
24267 if (!rtl || !MEM_P (rtl))
24269 rtl = XEXP (rtl, 0);
24270 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
24275 if (GET_CODE (rtl) == SYMBOL_REF
24276 && SYMBOL_REF_DECL (rtl))
24278 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
24280 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
24283 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
24287 if (GET_CODE (rtl) == CONST
24288 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
24294 /* Helper function for resolve_addr, handle one location
24295 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24296 the location list couldn't be resolved. */
24299 resolve_addr_in_expr (dw_loc_descr_ref loc)
24301 dw_loc_descr_ref keep = NULL;
24302 for (; loc; loc = loc->dw_loc_next)
24303 switch (loc->dw_loc_opc)
24306 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
24309 case DW_OP_const4u:
24310 case DW_OP_const8u:
24312 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
24315 case DW_OP_implicit_value:
24316 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
24317 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
24320 case DW_OP_GNU_implicit_pointer:
24321 case DW_OP_GNU_parameter_ref:
24322 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
24325 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
24328 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
24329 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
24330 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
24333 case DW_OP_GNU_const_type:
24334 case DW_OP_GNU_regval_type:
24335 case DW_OP_GNU_deref_type:
24336 case DW_OP_GNU_convert:
24337 case DW_OP_GNU_reinterpret:
24338 while (loc->dw_loc_next
24339 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
24341 dw_die_ref base1, base2;
24342 unsigned enc1, enc2, size1, size2;
24343 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24344 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24345 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
24346 else if (loc->dw_loc_oprnd1.val_class
24347 == dw_val_class_unsigned_const)
24350 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
24351 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
24352 == dw_val_class_unsigned_const)
24354 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
24355 gcc_assert (base1->die_tag == DW_TAG_base_type
24356 && base2->die_tag == DW_TAG_base_type);
24357 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
24358 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
24359 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
24360 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
24362 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
24363 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
24367 /* Optimize away next DW_OP_GNU_convert after
24368 adjusting LOC's base type die reference. */
24369 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24370 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24371 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
24373 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
24374 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
24377 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24378 point typed stack entry. */
24379 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
24380 keep = loc->dw_loc_next;
24390 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24391 an address in .rodata section if the string literal is emitted there,
24392 or remove the containing location list or replace DW_AT_const_value
24393 with DW_AT_location and empty location expression, if it isn't found
24394 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24395 to something that has been emitted in the current CU. */
24398 resolve_addr (dw_die_ref die)
24402 dw_loc_list_ref *curr, *start, loc;
24405 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
24406 switch (AT_class (a))
24408 case dw_val_class_loc_list:
24409 start = curr = AT_loc_list_ptr (a);
24412 /* The same list can be referenced more than once. See if we have
24413 already recorded the result from a previous pass. */
24415 *curr = loc->dw_loc_next;
24416 else if (!loc->resolved_addr)
24418 /* As things stand, we do not expect or allow one die to
24419 reference a suffix of another die's location list chain.
24420 References must be identical or completely separate.
24421 There is therefore no need to cache the result of this
24422 pass on any list other than the first; doing so
24423 would lead to unnecessary writes. */
24426 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
24427 if (!resolve_addr_in_expr ((*curr)->expr))
24429 dw_loc_list_ref next = (*curr)->dw_loc_next;
24430 if (next && (*curr)->ll_symbol)
24432 gcc_assert (!next->ll_symbol);
24433 next->ll_symbol = (*curr)->ll_symbol;
24439 mark_base_types ((*curr)->expr);
24440 curr = &(*curr)->dw_loc_next;
24444 loc->resolved_addr = 1;
24448 loc->dw_loc_next = *start;
24453 remove_AT (die, a->dw_attr);
24457 case dw_val_class_loc:
24458 if (!resolve_addr_in_expr (AT_loc (a)))
24460 remove_AT (die, a->dw_attr);
24464 mark_base_types (AT_loc (a));
24466 case dw_val_class_addr:
24467 if (a->dw_attr == DW_AT_const_value
24468 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
24470 remove_AT (die, a->dw_attr);
24473 if (die->die_tag == DW_TAG_GNU_call_site
24474 && a->dw_attr == DW_AT_abstract_origin)
24476 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
24477 dw_die_ref tdie = lookup_decl_die (tdecl);
24479 && DECL_EXTERNAL (tdecl)
24480 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
24482 force_decl_die (tdecl);
24483 tdie = lookup_decl_die (tdecl);
24487 a->dw_attr_val.val_class = dw_val_class_die_ref;
24488 a->dw_attr_val.v.val_die_ref.die = tdie;
24489 a->dw_attr_val.v.val_die_ref.external = 0;
24493 remove_AT (die, a->dw_attr);
24502 FOR_EACH_CHILD (die, c, resolve_addr (c));
24505 /* Helper routines for optimize_location_lists.
24506 This pass tries to share identical local lists in .debug_loc
24509 /* Iteratively hash operands of LOC opcode. */
24511 static inline hashval_t
24512 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
24514 dw_val_ref val1 = &loc->dw_loc_oprnd1;
24515 dw_val_ref val2 = &loc->dw_loc_oprnd2;
24517 switch (loc->dw_loc_opc)
24519 case DW_OP_const4u:
24520 case DW_OP_const8u:
24524 case DW_OP_const1u:
24525 case DW_OP_const1s:
24526 case DW_OP_const2u:
24527 case DW_OP_const2s:
24528 case DW_OP_const4s:
24529 case DW_OP_const8s:
24533 case DW_OP_plus_uconst:
24569 case DW_OP_deref_size:
24570 case DW_OP_xderef_size:
24571 hash = iterative_hash_object (val1->v.val_int, hash);
24578 gcc_assert (val1->val_class == dw_val_class_loc);
24579 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
24580 hash = iterative_hash_object (offset, hash);
24583 case DW_OP_implicit_value:
24584 hash = iterative_hash_object (val1->v.val_unsigned, hash);
24585 switch (val2->val_class)
24587 case dw_val_class_const:
24588 hash = iterative_hash_object (val2->v.val_int, hash);
24590 case dw_val_class_vec:
24592 unsigned int elt_size = val2->v.val_vec.elt_size;
24593 unsigned int len = val2->v.val_vec.length;
24595 hash = iterative_hash_object (elt_size, hash);
24596 hash = iterative_hash_object (len, hash);
24597 hash = iterative_hash (val2->v.val_vec.array,
24598 len * elt_size, hash);
24601 case dw_val_class_const_double:
24602 hash = iterative_hash_object (val2->v.val_double.low, hash);
24603 hash = iterative_hash_object (val2->v.val_double.high, hash);
24605 case dw_val_class_addr:
24606 hash = iterative_hash_rtx (val2->v.val_addr, hash);
24609 gcc_unreachable ();
24613 case DW_OP_bit_piece:
24614 hash = iterative_hash_object (val1->v.val_int, hash);
24615 hash = iterative_hash_object (val2->v.val_int, hash);
24621 unsigned char dtprel = 0xd1;
24622 hash = iterative_hash_object (dtprel, hash);
24624 hash = iterative_hash_rtx (val1->v.val_addr, hash);
24626 case DW_OP_GNU_implicit_pointer:
24627 hash = iterative_hash_object (val2->v.val_int, hash);
24629 case DW_OP_GNU_entry_value:
24630 hash = hash_loc_operands (val1->v.val_loc, hash);
24632 case DW_OP_GNU_regval_type:
24633 case DW_OP_GNU_deref_type:
24635 unsigned int byte_size
24636 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
24637 unsigned int encoding
24638 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
24639 hash = iterative_hash_object (val1->v.val_int, hash);
24640 hash = iterative_hash_object (byte_size, hash);
24641 hash = iterative_hash_object (encoding, hash);
24644 case DW_OP_GNU_convert:
24645 case DW_OP_GNU_reinterpret:
24646 if (val1->val_class == dw_val_class_unsigned_const)
24648 hash = iterative_hash_object (val1->v.val_unsigned, hash);
24652 case DW_OP_GNU_const_type:
24654 unsigned int byte_size
24655 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
24656 unsigned int encoding
24657 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
24658 hash = iterative_hash_object (byte_size, hash);
24659 hash = iterative_hash_object (encoding, hash);
24660 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
24662 hash = iterative_hash_object (val2->val_class, hash);
24663 switch (val2->val_class)
24665 case dw_val_class_const:
24666 hash = iterative_hash_object (val2->v.val_int, hash);
24668 case dw_val_class_vec:
24670 unsigned int elt_size = val2->v.val_vec.elt_size;
24671 unsigned int len = val2->v.val_vec.length;
24673 hash = iterative_hash_object (elt_size, hash);
24674 hash = iterative_hash_object (len, hash);
24675 hash = iterative_hash (val2->v.val_vec.array,
24676 len * elt_size, hash);
24679 case dw_val_class_const_double:
24680 hash = iterative_hash_object (val2->v.val_double.low, hash);
24681 hash = iterative_hash_object (val2->v.val_double.high, hash);
24684 gcc_unreachable ();
24690 /* Other codes have no operands. */
24696 /* Iteratively hash the whole DWARF location expression LOC. */
24698 static inline hashval_t
24699 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
24701 dw_loc_descr_ref l;
24702 bool sizes_computed = false;
24703 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24704 size_of_locs (loc);
24706 for (l = loc; l != NULL; l = l->dw_loc_next)
24708 enum dwarf_location_atom opc = l->dw_loc_opc;
24709 hash = iterative_hash_object (opc, hash);
24710 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
24712 size_of_locs (loc);
24713 sizes_computed = true;
24715 hash = hash_loc_operands (l, hash);
24720 /* Compute hash of the whole location list LIST_HEAD. */
24723 hash_loc_list (dw_loc_list_ref list_head)
24725 dw_loc_list_ref curr = list_head;
24726 hashval_t hash = 0;
24728 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
24730 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
24731 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
24733 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
24735 hash = hash_locs (curr->expr, hash);
24737 list_head->hash = hash;
24740 /* Return true if X and Y opcodes have the same operands. */
24743 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
24745 dw_val_ref valx1 = &x->dw_loc_oprnd1;
24746 dw_val_ref valx2 = &x->dw_loc_oprnd2;
24747 dw_val_ref valy1 = &y->dw_loc_oprnd1;
24748 dw_val_ref valy2 = &y->dw_loc_oprnd2;
24750 switch (x->dw_loc_opc)
24752 case DW_OP_const4u:
24753 case DW_OP_const8u:
24757 case DW_OP_const1u:
24758 case DW_OP_const1s:
24759 case DW_OP_const2u:
24760 case DW_OP_const2s:
24761 case DW_OP_const4s:
24762 case DW_OP_const8s:
24766 case DW_OP_plus_uconst:
24802 case DW_OP_deref_size:
24803 case DW_OP_xderef_size:
24804 return valx1->v.val_int == valy1->v.val_int;
24807 gcc_assert (valx1->val_class == dw_val_class_loc
24808 && valy1->val_class == dw_val_class_loc
24809 && x->dw_loc_addr == y->dw_loc_addr);
24810 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
24811 case DW_OP_implicit_value:
24812 if (valx1->v.val_unsigned != valy1->v.val_unsigned
24813 || valx2->val_class != valy2->val_class)
24815 switch (valx2->val_class)
24817 case dw_val_class_const:
24818 return valx2->v.val_int == valy2->v.val_int;
24819 case dw_val_class_vec:
24820 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24821 && valx2->v.val_vec.length == valy2->v.val_vec.length
24822 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24823 valx2->v.val_vec.elt_size
24824 * valx2->v.val_vec.length) == 0;
24825 case dw_val_class_const_double:
24826 return valx2->v.val_double.low == valy2->v.val_double.low
24827 && valx2->v.val_double.high == valy2->v.val_double.high;
24828 case dw_val_class_addr:
24829 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
24831 gcc_unreachable ();
24834 case DW_OP_bit_piece:
24835 return valx1->v.val_int == valy1->v.val_int
24836 && valx2->v.val_int == valy2->v.val_int;
24839 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
24840 case DW_OP_GNU_implicit_pointer:
24841 return valx1->val_class == dw_val_class_die_ref
24842 && valx1->val_class == valy1->val_class
24843 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
24844 && valx2->v.val_int == valy2->v.val_int;
24845 case DW_OP_GNU_entry_value:
24846 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
24847 case DW_OP_GNU_const_type:
24848 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
24849 || valx2->val_class != valy2->val_class)
24851 switch (valx2->val_class)
24853 case dw_val_class_const:
24854 return valx2->v.val_int == valy2->v.val_int;
24855 case dw_val_class_vec:
24856 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24857 && valx2->v.val_vec.length == valy2->v.val_vec.length
24858 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24859 valx2->v.val_vec.elt_size
24860 * valx2->v.val_vec.length) == 0;
24861 case dw_val_class_const_double:
24862 return valx2->v.val_double.low == valy2->v.val_double.low
24863 && valx2->v.val_double.high == valy2->v.val_double.high;
24865 gcc_unreachable ();
24867 case DW_OP_GNU_regval_type:
24868 case DW_OP_GNU_deref_type:
24869 return valx1->v.val_int == valy1->v.val_int
24870 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
24871 case DW_OP_GNU_convert:
24872 case DW_OP_GNU_reinterpret:
24873 if (valx1->val_class != valy1->val_class)
24875 if (valx1->val_class == dw_val_class_unsigned_const)
24876 return valx1->v.val_unsigned == valy1->v.val_unsigned;
24877 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
24878 case DW_OP_GNU_parameter_ref:
24879 return valx1->val_class == dw_val_class_die_ref
24880 && valx1->val_class == valy1->val_class
24881 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
24883 /* Other codes have no operands. */
24888 /* Return true if DWARF location expressions X and Y are the same. */
24891 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
24893 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
24894 if (x->dw_loc_opc != y->dw_loc_opc
24895 || x->dtprel != y->dtprel
24896 || !compare_loc_operands (x, y))
24898 return x == NULL && y == NULL;
24901 /* Return precomputed hash of location list X. */
24904 loc_list_hash (const void *x)
24906 return ((const struct dw_loc_list_struct *) x)->hash;
24909 /* Return 1 if location lists X and Y are the same. */
24912 loc_list_eq (const void *x, const void *y)
24914 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
24915 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
24918 if (a->hash != b->hash)
24920 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
24921 if (strcmp (a->begin, b->begin) != 0
24922 || strcmp (a->end, b->end) != 0
24923 || (a->section == NULL) != (b->section == NULL)
24924 || (a->section && strcmp (a->section, b->section) != 0)
24925 || !compare_locs (a->expr, b->expr))
24927 return a == NULL && b == NULL;
24930 /* Recursively optimize location lists referenced from DIE
24931 children and share them whenever possible. */
24934 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
24941 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
24942 if (AT_class (a) == dw_val_class_loc_list)
24944 dw_loc_list_ref list = AT_loc_list (a);
24945 /* TODO: perform some optimizations here, before hashing
24946 it and storing into the hash table. */
24947 hash_loc_list (list);
24948 slot = htab_find_slot_with_hash (htab, list, list->hash,
24951 *slot = (void *) list;
24953 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
24956 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
24959 /* Optimize location lists referenced from DIE
24960 children and share them whenever possible. */
24963 optimize_location_lists (dw_die_ref die)
24965 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
24966 optimize_location_lists_1 (die, htab);
24967 htab_delete (htab);
24970 /* Output stuff that dwarf requires at the end of every file,
24971 and generate the DWARF-2 debugging info. */
24974 dwarf2out_finish (const char *filename)
24976 limbo_die_node *node, *next_node;
24977 comdat_type_node *ctnode;
24978 htab_t comdat_type_table;
24981 gen_scheduled_generic_parms_dies ();
24982 gen_remaining_tmpl_value_param_die_attribute ();
24984 /* Add the name for the main input file now. We delayed this from
24985 dwarf2out_init to avoid complications with PCH. */
24986 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
24987 if (!IS_ABSOLUTE_PATH (filename))
24988 add_comp_dir_attribute (comp_unit_die ());
24989 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
24992 htab_traverse (file_table, file_table_relative_p, &p);
24994 add_comp_dir_attribute (comp_unit_die ());
24997 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
24999 add_location_or_const_value_attribute (
25000 VEC_index (deferred_locations, deferred_locations_list, i)->die,
25001 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
25006 /* Traverse the limbo die list, and add parent/child links. The only
25007 dies without parents that should be here are concrete instances of
25008 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
25009 For concrete instances, we can get the parent die from the abstract
25011 for (node = limbo_die_list; node; node = next_node)
25013 dw_die_ref die = node->die;
25014 next_node = node->next;
25016 if (die->die_parent == NULL)
25018 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
25021 add_child_die (origin->die_parent, die);
25022 else if (is_cu_die (die))
25024 else if (seen_error ())
25025 /* It's OK to be confused by errors in the input. */
25026 add_child_die (comp_unit_die (), die);
25029 /* In certain situations, the lexical block containing a
25030 nested function can be optimized away, which results
25031 in the nested function die being orphaned. Likewise
25032 with the return type of that nested function. Force
25033 this to be a child of the containing function.
25035 It may happen that even the containing function got fully
25036 inlined and optimized out. In that case we are lost and
25037 assign the empty child. This should not be big issue as
25038 the function is likely unreachable too. */
25039 tree context = NULL_TREE;
25041 gcc_assert (node->created_for);
25043 if (DECL_P (node->created_for))
25044 context = DECL_CONTEXT (node->created_for);
25045 else if (TYPE_P (node->created_for))
25046 context = TYPE_CONTEXT (node->created_for);
25048 gcc_assert (context
25049 && (TREE_CODE (context) == FUNCTION_DECL
25050 || TREE_CODE (context) == NAMESPACE_DECL));
25052 origin = lookup_decl_die (context);
25054 add_child_die (origin, die);
25056 add_child_die (comp_unit_die (), die);
25061 limbo_die_list = NULL;
25063 #if ENABLE_ASSERT_CHECKING
25065 dw_die_ref die = comp_unit_die (), c;
25066 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
25069 resolve_addr (comp_unit_die ());
25070 move_marked_base_types ();
25072 for (node = deferred_asm_name; node; node = node->next)
25074 tree decl = node->created_for;
25075 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
25077 add_linkage_attr (node->die, decl);
25078 move_linkage_attr (node->die);
25082 deferred_asm_name = NULL;
25084 /* Walk through the list of incomplete types again, trying once more to
25085 emit full debugging info for them. */
25086 retry_incomplete_types ();
25088 if (flag_eliminate_unused_debug_types)
25089 prune_unused_types ();
25091 /* Generate separate CUs for each of the include files we've seen.
25092 They will go into limbo_die_list. */
25093 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
25094 break_out_includes (comp_unit_die ());
25096 /* Generate separate COMDAT sections for type DIEs. */
25097 if (use_debug_types)
25099 break_out_comdat_types (comp_unit_die ());
25101 /* Each new type_unit DIE was added to the limbo die list when created.
25102 Since these have all been added to comdat_type_list, clear the
25104 limbo_die_list = NULL;
25106 /* For each new comdat type unit, copy declarations for incomplete
25107 types to make the new unit self-contained (i.e., no direct
25108 references to the main compile unit). */
25109 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25110 copy_decls_for_unworthy_types (ctnode->root_die);
25111 copy_decls_for_unworthy_types (comp_unit_die ());
25113 /* In the process of copying declarations from one unit to another,
25114 we may have left some declarations behind that are no longer
25115 referenced. Prune them. */
25116 prune_unused_types ();
25119 /* Traverse the DIE's and add add sibling attributes to those DIE's
25120 that have children. */
25121 add_sibling_attributes (comp_unit_die ());
25122 for (node = limbo_die_list; node; node = node->next)
25123 add_sibling_attributes (node->die);
25124 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25125 add_sibling_attributes (ctnode->root_die);
25127 /* Output a terminator label for the .text section. */
25128 switch_to_section (text_section);
25129 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
25130 if (cold_text_section)
25132 switch_to_section (cold_text_section);
25133 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
25136 /* We can only use the low/high_pc attributes if all of the code was
25138 if (!have_multiple_function_sections
25139 || (dwarf_version < 3 && dwarf_strict))
25141 /* Don't add if the CU has no associated code. */
25142 if (text_section_used)
25144 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
25145 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
25150 unsigned fde_idx = 0;
25151 bool range_list_added = false;
25153 if (text_section_used)
25154 add_ranges_by_labels (comp_unit_die (), text_section_label,
25155 text_end_label, &range_list_added);
25156 if (cold_text_section_used)
25157 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
25158 cold_end_label, &range_list_added);
25160 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
25162 dw_fde_ref fde = &fde_table[fde_idx];
25164 if (!fde->in_std_section)
25165 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
25166 fde->dw_fde_end, &range_list_added);
25167 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
25168 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
25169 fde->dw_fde_second_end, &range_list_added);
25172 if (range_list_added)
25174 /* We need to give .debug_loc and .debug_ranges an appropriate
25175 "base address". Use zero so that these addresses become
25176 absolute. Historically, we've emitted the unexpected
25177 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25178 Emit both to give time for other tools to adapt. */
25179 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
25180 if (! dwarf_strict && dwarf_version < 4)
25181 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
25187 if (debug_info_level >= DINFO_LEVEL_NORMAL)
25188 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
25189 debug_line_section_label);
25191 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
25192 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
25194 if (have_location_lists)
25195 optimize_location_lists (comp_unit_die ());
25197 /* Output all of the compilation units. We put the main one last so that
25198 the offsets are available to output_pubnames. */
25199 for (node = limbo_die_list; node; node = node->next)
25200 output_comp_unit (node->die, 0);
25202 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
25203 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25205 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
25207 /* Don't output duplicate types. */
25208 if (*slot != HTAB_EMPTY_ENTRY)
25211 /* Add a pointer to the line table for the main compilation unit
25212 so that the debugger can make sense of DW_AT_decl_file
25214 if (debug_info_level >= DINFO_LEVEL_NORMAL)
25215 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
25216 debug_line_section_label);
25218 output_comdat_type_unit (ctnode);
25221 htab_delete (comdat_type_table);
25223 /* Output the main compilation unit if non-empty or if .debug_macinfo
25224 will be emitted. */
25225 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
25227 /* Output the abbreviation table. */
25228 switch_to_section (debug_abbrev_section);
25229 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
25230 output_abbrev_section ();
25232 /* Output location list section if necessary. */
25233 if (have_location_lists)
25235 /* Output the location lists info. */
25236 switch_to_section (debug_loc_section);
25237 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
25238 DEBUG_LOC_SECTION_LABEL, 0);
25239 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
25240 output_location_lists (comp_unit_die ());
25243 /* Output public names table if necessary. */
25244 if (!VEC_empty (pubname_entry, pubname_table))
25246 gcc_assert (info_section_emitted);
25247 switch_to_section (debug_pubnames_section);
25248 output_pubnames (pubname_table);
25251 /* Output public types table if necessary. */
25252 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
25253 It shouldn't hurt to emit it always, since pure DWARF2 consumers
25254 simply won't look for the section. */
25255 if (!VEC_empty (pubname_entry, pubtype_table))
25257 bool empty = false;
25259 if (flag_eliminate_unused_debug_types)
25261 /* The pubtypes table might be emptied by pruning unused items. */
25265 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
25266 if (p->die->die_offset != 0)
25274 gcc_assert (info_section_emitted);
25275 switch_to_section (debug_pubtypes_section);
25276 output_pubnames (pubtype_table);
25280 /* Output the address range information if a CU (.debug_info section)
25281 was emitted. We output an empty table even if we had no functions
25282 to put in it. This because the consumer has no way to tell the
25283 difference between an empty table that we omitted and failure to
25284 generate a table that would have contained data. */
25285 if (info_section_emitted)
25287 unsigned long aranges_length = size_of_aranges ();
25289 switch_to_section (debug_aranges_section);
25290 output_aranges (aranges_length);
25293 /* Output ranges section if necessary. */
25294 if (ranges_table_in_use)
25296 switch_to_section (debug_ranges_section);
25297 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
25301 /* Output the source line correspondence table. We must do this
25302 even if there is no line information. Otherwise, on an empty
25303 translation unit, we will generate a present, but empty,
25304 .debug_info section. IRIX 6.5 `nm' will then complain when
25305 examining the file. This is done late so that any filenames
25306 used by the debug_info section are marked as 'used'. */
25307 switch_to_section (debug_line_section);
25308 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
25309 if (! DWARF2_ASM_LINE_DEBUG_INFO)
25310 output_line_info ();
25312 /* Have to end the macro section. */
25313 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
25315 switch_to_section (debug_macinfo_section);
25316 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
25317 if (!VEC_empty (macinfo_entry, macinfo_table))
25319 dw2_asm_output_data (1, 0, "End compilation unit");
25322 /* If we emitted any DW_FORM_strp form attribute, output the string
25324 if (debug_str_hash)
25325 htab_traverse (debug_str_hash, output_indirect_string, NULL);
25328 #include "gt-dwarf2out.h"