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 typedef struct GTY(()) reg_saved_in_data {
1738 } reg_saved_in_data;
1740 DEF_VEC_O (reg_saved_in_data);
1741 DEF_VEC_ALLOC_O (reg_saved_in_data, gc);
1743 /* A set of registers saved in other registers. This is implemented as
1744 a flat array because it normally contains zero or 1 entry, depending
1745 on the target. IA-64 is the big spender here, using a maximum of
1747 static GTY(()) VEC(reg_saved_in_data, gc) *regs_saved_in_regs;
1749 /* Compare X and Y for equivalence. The inputs may be REGs or PC_RTX. */
1752 compare_reg_or_pc (rtx x, rtx y)
1754 if (REG_P (x) && REG_P (y))
1755 return REGNO (x) == REGNO (y);
1759 /* Record SRC as being saved in DEST. DEST may be null to delete an
1760 existing entry. SRC may be a register or PC_RTX. */
1763 record_reg_saved_in_reg (rtx dest, rtx src)
1765 reg_saved_in_data *elt;
1768 FOR_EACH_VEC_ELT (reg_saved_in_data, regs_saved_in_regs, i, elt)
1769 if (compare_reg_or_pc (elt->orig_reg, src))
1772 VEC_unordered_remove(reg_saved_in_data, regs_saved_in_regs, i);
1774 elt->saved_in_reg = dest;
1781 elt = VEC_safe_push(reg_saved_in_data, gc, regs_saved_in_regs, NULL);
1782 elt->orig_reg = src;
1783 elt->saved_in_reg = dest;
1786 static const char *last_reg_save_label;
1788 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1789 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1792 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1794 struct queued_reg_save *q;
1796 /* Duplicates waste space, but it's also necessary to remove them
1797 for correctness, since the queue gets output in reverse
1799 for (q = queued_reg_saves; q != NULL; q = q->next)
1800 if (REGNO (q->reg) == REGNO (reg))
1805 q = ggc_alloc_queued_reg_save ();
1806 q->next = queued_reg_saves;
1807 queued_reg_saves = q;
1811 q->cfa_offset = offset;
1812 q->saved_reg = sreg;
1814 last_reg_save_label = label;
1817 /* Output all the entries in QUEUED_REG_SAVES. */
1820 dwarf2out_flush_queued_reg_saves (void)
1822 struct queued_reg_save *q;
1824 for (q = queued_reg_saves; q; q = q->next)
1826 unsigned int reg, sreg;
1828 record_reg_saved_in_reg (q->saved_reg, q->reg);
1830 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1832 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1834 sreg = INVALID_REGNUM;
1835 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1838 queued_reg_saves = NULL;
1839 last_reg_save_label = NULL;
1842 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1843 location for? Or, does it clobber a register which we've previously
1844 said that some other register is saved in, and for which we now
1845 have a new location for? */
1848 clobbers_queued_reg_save (const_rtx insn)
1850 struct queued_reg_save *q;
1852 for (q = queued_reg_saves; q; q = q->next)
1855 reg_saved_in_data *rir;
1857 if (modified_in_p (q->reg, insn))
1860 FOR_EACH_VEC_ELT (reg_saved_in_data, regs_saved_in_regs, i, rir)
1861 if (compare_reg_or_pc (q->reg, rir->orig_reg)
1862 && modified_in_p (rir->saved_in_reg, insn))
1869 /* Entry point for saving the first register into the second. */
1872 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1874 unsigned int regno, sregno;
1876 record_reg_saved_in_reg (sreg, reg);
1878 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1879 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1880 reg_save (label, regno, sregno, 0);
1883 /* What register, if any, is currently saved in REG? */
1886 reg_saved_in (rtx reg)
1888 unsigned int regn = REGNO (reg);
1889 struct queued_reg_save *q;
1890 reg_saved_in_data *rir;
1893 for (q = queued_reg_saves; q; q = q->next)
1894 if (q->saved_reg && regn == REGNO (q->saved_reg))
1897 FOR_EACH_VEC_ELT (reg_saved_in_data, regs_saved_in_regs, i, rir)
1898 if (regn == REGNO (rir->saved_in_reg))
1899 return rir->orig_reg;
1905 /* A temporary register holding an integral value used in adjusting SP
1906 or setting up the store_reg. The "offset" field holds the integer
1907 value, not an offset. */
1908 static dw_cfa_location cfa_temp;
1910 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1913 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1915 memset (&cfa, 0, sizeof (cfa));
1917 switch (GET_CODE (pat))
1920 cfa.reg = REGNO (XEXP (pat, 0));
1921 cfa.offset = INTVAL (XEXP (pat, 1));
1925 cfa.reg = REGNO (pat);
1930 pat = XEXP (pat, 0);
1931 if (GET_CODE (pat) == PLUS)
1933 cfa.base_offset = INTVAL (XEXP (pat, 1));
1934 pat = XEXP (pat, 0);
1936 cfa.reg = REGNO (pat);
1940 /* Recurse and define an expression. */
1944 def_cfa_1 (label, &cfa);
1947 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1950 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1954 gcc_assert (GET_CODE (pat) == SET);
1955 dest = XEXP (pat, 0);
1956 src = XEXP (pat, 1);
1958 switch (GET_CODE (src))
1961 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1962 cfa.offset -= INTVAL (XEXP (src, 1));
1972 cfa.reg = REGNO (dest);
1973 gcc_assert (cfa.indirect == 0);
1975 def_cfa_1 (label, &cfa);
1978 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1981 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1983 HOST_WIDE_INT offset;
1984 rtx src, addr, span;
1985 unsigned int sregno;
1987 src = XEXP (set, 1);
1988 addr = XEXP (set, 0);
1989 gcc_assert (MEM_P (addr));
1990 addr = XEXP (addr, 0);
1992 /* As documented, only consider extremely simple addresses. */
1993 switch (GET_CODE (addr))
1996 gcc_assert (REGNO (addr) == cfa.reg);
1997 offset = -cfa.offset;
2000 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
2001 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2010 sregno = DWARF_FRAME_RETURN_COLUMN;
2014 span = targetm.dwarf_register_span (src);
2015 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2018 /* ??? We'd like to use queue_reg_save, but we need to come up with
2019 a different flushing heuristic for epilogues. */
2021 reg_save (label, sregno, INVALID_REGNUM, offset);
2024 /* We have a PARALLEL describing where the contents of SRC live.
2025 Queue register saves for each piece of the PARALLEL. */
2028 HOST_WIDE_INT span_offset = offset;
2030 gcc_assert (GET_CODE (span) == PARALLEL);
2032 limit = XVECLEN (span, 0);
2033 for (par_index = 0; par_index < limit; par_index++)
2035 rtx elem = XVECEXP (span, 0, par_index);
2037 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2038 reg_save (label, sregno, INVALID_REGNUM, span_offset);
2039 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2044 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2047 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2050 unsigned sregno, dregno;
2052 src = XEXP (set, 1);
2053 dest = XEXP (set, 0);
2056 sregno = DWARF_FRAME_RETURN_COLUMN;
2059 record_reg_saved_in_reg (dest, src);
2060 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2063 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2065 /* ??? We'd like to use queue_reg_save, but we need to come up with
2066 a different flushing heuristic for epilogues. */
2067 reg_save (label, sregno, dregno, 0);
2070 /* Helper function to get mode of MEM's address. */
2072 static inline enum machine_mode
2073 get_address_mode (rtx mem)
2075 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
2076 if (mode != VOIDmode)
2078 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
2081 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2084 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2086 rtx src, dest, span;
2087 dw_cfi_ref cfi = new_cfi ();
2089 dest = SET_DEST (set);
2090 src = SET_SRC (set);
2092 gcc_assert (REG_P (src));
2093 gcc_assert (MEM_P (dest));
2095 span = targetm.dwarf_register_span (src);
2098 cfi->dw_cfi_opc = DW_CFA_expression;
2099 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2100 cfi->dw_cfi_oprnd2.dw_cfi_loc
2101 = mem_loc_descriptor (XEXP (dest, 0), get_address_mode (dest),
2102 GET_MODE (dest), VAR_INIT_STATUS_INITIALIZED);
2104 /* ??? We'd like to use queue_reg_save, were the interface different,
2105 and, as above, we could manage flushing for epilogues. */
2106 add_fde_cfi (label, cfi);
2109 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2112 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2114 dw_cfi_ref cfi = new_cfi ();
2115 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2117 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2118 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2120 add_fde_cfi (label, cfi);
2123 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE.
2124 ??? Perhaps we should note in the CIE where windows are saved (instead of
2125 assuming 0(cfa)) and what registers are in the window. */
2128 dwarf2out_frame_debug_cfa_window_save (const char *label)
2130 dw_cfi_ref cfi = new_cfi ();
2132 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
2133 add_fde_cfi (label, cfi);
2136 /* Record call frame debugging information for an expression EXPR,
2137 which either sets SP or FP (adjusting how we calculate the frame
2138 address) or saves a register to the stack or another register.
2139 LABEL indicates the address of EXPR.
2141 This function encodes a state machine mapping rtxes to actions on
2142 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2143 users need not read the source code.
2145 The High-Level Picture
2147 Changes in the register we use to calculate the CFA: Currently we
2148 assume that if you copy the CFA register into another register, we
2149 should take the other one as the new CFA register; this seems to
2150 work pretty well. If it's wrong for some target, it's simple
2151 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2153 Changes in the register we use for saving registers to the stack:
2154 This is usually SP, but not always. Again, we deduce that if you
2155 copy SP into another register (and SP is not the CFA register),
2156 then the new register is the one we will be using for register
2157 saves. This also seems to work.
2159 Register saves: There's not much guesswork about this one; if
2160 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2161 register save, and the register used to calculate the destination
2162 had better be the one we think we're using for this purpose.
2163 It's also assumed that a copy from a call-saved register to another
2164 register is saving that register if RTX_FRAME_RELATED_P is set on
2165 that instruction. If the copy is from a call-saved register to
2166 the *same* register, that means that the register is now the same
2167 value as in the caller.
2169 Except: If the register being saved is the CFA register, and the
2170 offset is nonzero, we are saving the CFA, so we assume we have to
2171 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2172 the intent is to save the value of SP from the previous frame.
2174 In addition, if a register has previously been saved to a different
2177 Invariants / Summaries of Rules
2179 cfa current rule for calculating the CFA. It usually
2180 consists of a register and an offset.
2181 cfa_store register used by prologue code to save things to the stack
2182 cfa_store.offset is the offset from the value of
2183 cfa_store.reg to the actual CFA
2184 cfa_temp register holding an integral value. cfa_temp.offset
2185 stores the value, which will be used to adjust the
2186 stack pointer. cfa_temp is also used like cfa_store,
2187 to track stores to the stack via fp or a temp reg.
2189 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2190 with cfa.reg as the first operand changes the cfa.reg and its
2191 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2194 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2195 expression yielding a constant. This sets cfa_temp.reg
2196 and cfa_temp.offset.
2198 Rule 5: Create a new register cfa_store used to save items to the
2201 Rules 10-14: Save a register to the stack. Define offset as the
2202 difference of the original location and cfa_store's
2203 location (or cfa_temp's location if cfa_temp is used).
2205 Rules 16-20: If AND operation happens on sp in prologue, we assume
2206 stack is realigned. We will use a group of DW_OP_XXX
2207 expressions to represent the location of the stored
2208 register instead of CFA+offset.
2212 "{a,b}" indicates a choice of a xor b.
2213 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2216 (set <reg1> <reg2>:cfa.reg)
2217 effects: cfa.reg = <reg1>
2218 cfa.offset unchanged
2219 cfa_temp.reg = <reg1>
2220 cfa_temp.offset = cfa.offset
2223 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2224 {<const_int>,<reg>:cfa_temp.reg}))
2225 effects: cfa.reg = sp if fp used
2226 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2227 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2228 if cfa_store.reg==sp
2231 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2232 effects: cfa.reg = fp
2233 cfa_offset += +/- <const_int>
2236 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2237 constraints: <reg1> != fp
2239 effects: cfa.reg = <reg1>
2240 cfa_temp.reg = <reg1>
2241 cfa_temp.offset = cfa.offset
2244 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2245 constraints: <reg1> != fp
2247 effects: cfa_store.reg = <reg1>
2248 cfa_store.offset = cfa.offset - cfa_temp.offset
2251 (set <reg> <const_int>)
2252 effects: cfa_temp.reg = <reg>
2253 cfa_temp.offset = <const_int>
2256 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2257 effects: cfa_temp.reg = <reg1>
2258 cfa_temp.offset |= <const_int>
2261 (set <reg> (high <exp>))
2265 (set <reg> (lo_sum <exp> <const_int>))
2266 effects: cfa_temp.reg = <reg>
2267 cfa_temp.offset = <const_int>
2270 (set (mem ({pre,post}_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2271 effects: cfa_store.offset -= <const_int>
2272 cfa.offset = cfa_store.offset if cfa.reg == sp
2274 cfa.base_offset = -cfa_store.offset
2277 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2278 effects: cfa_store.offset += -/+ mode_size(mem)
2279 cfa.offset = cfa_store.offset if cfa.reg == sp
2281 cfa.base_offset = -cfa_store.offset
2284 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2287 effects: cfa.reg = <reg1>
2288 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2291 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2292 effects: cfa.reg = <reg1>
2293 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2296 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2297 effects: cfa.reg = <reg1>
2298 cfa.base_offset = -cfa_temp.offset
2299 cfa_temp.offset -= mode_size(mem)
2302 (set <reg> {unspec, unspec_volatile})
2303 effects: target-dependent
2306 (set sp (and: sp <const_int>))
2307 constraints: cfa_store.reg == sp
2308 effects: current_fde.stack_realign = 1
2309 cfa_store.offset = 0
2310 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2313 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2314 effects: cfa_store.offset += -/+ mode_size(mem)
2317 (set (mem ({pre_inc, pre_dec} sp)) fp)
2318 constraints: fde->stack_realign == 1
2319 effects: cfa_store.offset = 0
2320 cfa.reg != HARD_FRAME_POINTER_REGNUM
2323 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2324 constraints: fde->stack_realign == 1
2326 && cfa.indirect == 0
2327 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2328 effects: Use DW_CFA_def_cfa_expression to define cfa
2329 cfa.reg == fde->drap_reg */
2332 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2334 rtx src, dest, span;
2335 HOST_WIDE_INT offset;
2338 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2339 the PARALLEL independently. The first element is always processed if
2340 it is a SET. This is for backward compatibility. Other elements
2341 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2342 flag is set in them. */
2343 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2346 int limit = XVECLEN (expr, 0);
2349 /* PARALLELs have strict read-modify-write semantics, so we
2350 ought to evaluate every rvalue before changing any lvalue.
2351 It's cumbersome to do that in general, but there's an
2352 easy approximation that is enough for all current users:
2353 handle register saves before register assignments. */
2354 if (GET_CODE (expr) == PARALLEL)
2355 for (par_index = 0; par_index < limit; par_index++)
2357 elem = XVECEXP (expr, 0, par_index);
2358 if (GET_CODE (elem) == SET
2359 && MEM_P (SET_DEST (elem))
2360 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2361 dwarf2out_frame_debug_expr (elem, label);
2364 for (par_index = 0; par_index < limit; par_index++)
2366 elem = XVECEXP (expr, 0, par_index);
2367 if (GET_CODE (elem) == SET
2368 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2369 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2370 dwarf2out_frame_debug_expr (elem, label);
2371 else if (GET_CODE (elem) == SET
2373 && !RTX_FRAME_RELATED_P (elem))
2375 /* Stack adjustment combining might combine some post-prologue
2376 stack adjustment into a prologue stack adjustment. */
2377 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2380 dwarf2out_stack_adjust (offset, label);
2386 gcc_assert (GET_CODE (expr) == SET);
2388 src = SET_SRC (expr);
2389 dest = SET_DEST (expr);
2393 rtx rsi = reg_saved_in (src);
2398 fde = current_fde ();
2400 switch (GET_CODE (dest))
2403 switch (GET_CODE (src))
2405 /* Setting FP from SP. */
2407 if (cfa.reg == (unsigned) REGNO (src))
2410 /* Update the CFA rule wrt SP or FP. Make sure src is
2411 relative to the current CFA register.
2413 We used to require that dest be either SP or FP, but the
2414 ARM copies SP to a temporary register, and from there to
2415 FP. So we just rely on the backends to only set
2416 RTX_FRAME_RELATED_P on appropriate insns. */
2417 cfa.reg = REGNO (dest);
2418 cfa_temp.reg = cfa.reg;
2419 cfa_temp.offset = cfa.offset;
2423 /* Saving a register in a register. */
2424 gcc_assert (!fixed_regs [REGNO (dest)]
2425 /* For the SPARC and its register window. */
2426 || (DWARF_FRAME_REGNUM (REGNO (src))
2427 == DWARF_FRAME_RETURN_COLUMN));
2429 /* After stack is aligned, we can only save SP in FP
2430 if drap register is used. In this case, we have
2431 to restore stack pointer with the CFA value and we
2432 don't generate this DWARF information. */
2434 && fde->stack_realign
2435 && REGNO (src) == STACK_POINTER_REGNUM)
2436 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2437 && fde->drap_reg != INVALID_REGNUM
2438 && cfa.reg != REGNO (src));
2440 queue_reg_save (label, src, dest, 0);
2447 if (dest == stack_pointer_rtx)
2451 switch (GET_CODE (XEXP (src, 1)))
2454 offset = INTVAL (XEXP (src, 1));
2457 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2459 offset = cfa_temp.offset;
2465 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2467 /* Restoring SP from FP in the epilogue. */
2468 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2469 cfa.reg = STACK_POINTER_REGNUM;
2471 else if (GET_CODE (src) == LO_SUM)
2472 /* Assume we've set the source reg of the LO_SUM from sp. */
2475 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2477 if (GET_CODE (src) != MINUS)
2479 if (cfa.reg == STACK_POINTER_REGNUM)
2480 cfa.offset += offset;
2481 if (cfa_store.reg == STACK_POINTER_REGNUM)
2482 cfa_store.offset += offset;
2484 else if (dest == hard_frame_pointer_rtx)
2487 /* Either setting the FP from an offset of the SP,
2488 or adjusting the FP */
2489 gcc_assert (frame_pointer_needed);
2491 gcc_assert (REG_P (XEXP (src, 0))
2492 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2493 && CONST_INT_P (XEXP (src, 1)));
2494 offset = INTVAL (XEXP (src, 1));
2495 if (GET_CODE (src) != MINUS)
2497 cfa.offset += offset;
2498 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2502 gcc_assert (GET_CODE (src) != MINUS);
2505 if (REG_P (XEXP (src, 0))
2506 && REGNO (XEXP (src, 0)) == cfa.reg
2507 && CONST_INT_P (XEXP (src, 1)))
2509 /* Setting a temporary CFA register that will be copied
2510 into the FP later on. */
2511 offset = - INTVAL (XEXP (src, 1));
2512 cfa.offset += offset;
2513 cfa.reg = REGNO (dest);
2514 /* Or used to save regs to the stack. */
2515 cfa_temp.reg = cfa.reg;
2516 cfa_temp.offset = cfa.offset;
2520 else if (REG_P (XEXP (src, 0))
2521 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2522 && XEXP (src, 1) == stack_pointer_rtx)
2524 /* Setting a scratch register that we will use instead
2525 of SP for saving registers to the stack. */
2526 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2527 cfa_store.reg = REGNO (dest);
2528 cfa_store.offset = cfa.offset - cfa_temp.offset;
2532 else if (GET_CODE (src) == LO_SUM
2533 && CONST_INT_P (XEXP (src, 1)))
2535 cfa_temp.reg = REGNO (dest);
2536 cfa_temp.offset = INTVAL (XEXP (src, 1));
2545 cfa_temp.reg = REGNO (dest);
2546 cfa_temp.offset = INTVAL (src);
2551 gcc_assert (REG_P (XEXP (src, 0))
2552 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2553 && CONST_INT_P (XEXP (src, 1)));
2555 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2556 cfa_temp.reg = REGNO (dest);
2557 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2560 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2561 which will fill in all of the bits. */
2568 case UNSPEC_VOLATILE:
2569 gcc_assert (targetm.dwarf_handle_frame_unspec);
2570 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2575 /* If this AND operation happens on stack pointer in prologue,
2576 we assume the stack is realigned and we extract the
2578 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2580 /* We interpret reg_save differently with stack_realign set.
2581 Thus we must flush whatever we have queued first. */
2582 dwarf2out_flush_queued_reg_saves ();
2584 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2585 fde->stack_realign = 1;
2586 fde->stack_realignment = INTVAL (XEXP (src, 1));
2587 cfa_store.offset = 0;
2589 if (cfa.reg != STACK_POINTER_REGNUM
2590 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2591 fde->drap_reg = cfa.reg;
2599 def_cfa_1 (label, &cfa);
2604 /* Saving a register to the stack. Make sure dest is relative to the
2606 switch (GET_CODE (XEXP (dest, 0)))
2612 /* We can't handle variable size modifications. */
2613 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2615 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2617 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2618 && cfa_store.reg == STACK_POINTER_REGNUM);
2620 cfa_store.offset += offset;
2621 if (cfa.reg == STACK_POINTER_REGNUM)
2622 cfa.offset = cfa_store.offset;
2624 if (GET_CODE (XEXP (dest, 0)) == POST_MODIFY)
2625 offset -= cfa_store.offset;
2627 offset = -cfa_store.offset;
2634 offset = GET_MODE_SIZE (GET_MODE (dest));
2635 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2638 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2639 == STACK_POINTER_REGNUM)
2640 && cfa_store.reg == STACK_POINTER_REGNUM);
2642 cfa_store.offset += offset;
2644 /* Rule 18: If stack is aligned, we will use FP as a
2645 reference to represent the address of the stored
2648 && fde->stack_realign
2649 && src == hard_frame_pointer_rtx)
2651 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2652 cfa_store.offset = 0;
2655 if (cfa.reg == STACK_POINTER_REGNUM)
2656 cfa.offset = cfa_store.offset;
2658 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
2659 offset += -cfa_store.offset;
2661 offset = -cfa_store.offset;
2665 /* With an offset. */
2672 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2673 && REG_P (XEXP (XEXP (dest, 0), 0)));
2674 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2675 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2678 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2680 if (cfa.reg == (unsigned) regno)
2681 offset -= cfa.offset;
2682 else if (cfa_store.reg == (unsigned) regno)
2683 offset -= cfa_store.offset;
2686 gcc_assert (cfa_temp.reg == (unsigned) regno);
2687 offset -= cfa_temp.offset;
2693 /* Without an offset. */
2696 int regno = REGNO (XEXP (dest, 0));
2698 if (cfa.reg == (unsigned) regno)
2699 offset = -cfa.offset;
2700 else if (cfa_store.reg == (unsigned) regno)
2701 offset = -cfa_store.offset;
2704 gcc_assert (cfa_temp.reg == (unsigned) regno);
2705 offset = -cfa_temp.offset;
2712 gcc_assert (cfa_temp.reg
2713 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2714 offset = -cfa_temp.offset;
2715 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2723 /* If the source operand of this MEM operation is not a
2724 register, basically the source is return address. Here
2725 we only care how much stack grew and we don't save it. */
2729 if (REGNO (src) != STACK_POINTER_REGNUM
2730 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2731 && (unsigned) REGNO (src) == cfa.reg)
2733 /* We're storing the current CFA reg into the stack. */
2735 if (cfa.offset == 0)
2738 /* If stack is aligned, putting CFA reg into stack means
2739 we can no longer use reg + offset to represent CFA.
2740 Here we use DW_CFA_def_cfa_expression instead. The
2741 result of this expression equals to the original CFA
2744 && fde->stack_realign
2745 && cfa.indirect == 0
2746 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2748 dw_cfa_location cfa_exp;
2750 gcc_assert (fde->drap_reg == cfa.reg);
2752 cfa_exp.indirect = 1;
2753 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2754 cfa_exp.base_offset = offset;
2757 fde->drap_reg_saved = 1;
2759 def_cfa_1 (label, &cfa_exp);
2763 /* If the source register is exactly the CFA, assume
2764 we're saving SP like any other register; this happens
2766 def_cfa_1 (label, &cfa);
2767 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2772 /* Otherwise, we'll need to look in the stack to
2773 calculate the CFA. */
2774 rtx x = XEXP (dest, 0);
2778 gcc_assert (REG_P (x));
2780 cfa.reg = REGNO (x);
2781 cfa.base_offset = offset;
2783 def_cfa_1 (label, &cfa);
2788 def_cfa_1 (label, &cfa);
2790 span = targetm.dwarf_register_span (src);
2793 queue_reg_save (label, src, NULL_RTX, offset);
2796 /* We have a PARALLEL describing where the contents of SRC
2797 live. Queue register saves for each piece of the
2801 HOST_WIDE_INT span_offset = offset;
2803 gcc_assert (GET_CODE (span) == PARALLEL);
2805 limit = XVECLEN (span, 0);
2806 for (par_index = 0; par_index < limit; par_index++)
2808 rtx elem = XVECEXP (span, 0, par_index);
2810 queue_reg_save (label, elem, NULL_RTX, span_offset);
2811 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2822 /* Record call frame debugging information for INSN, which either
2823 sets SP or FP (adjusting how we calculate the frame address) or saves a
2824 register to the stack. If INSN is NULL_RTX, initialize our state.
2826 If AFTER_P is false, we're being called before the insn is emitted,
2827 otherwise after. Call instructions get invoked twice. */
2830 dwarf2out_frame_debug (rtx insn, bool after_p)
2834 bool handled_one = false;
2835 bool need_flush = false;
2837 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2838 dwarf2out_flush_queued_reg_saves ();
2840 if (!RTX_FRAME_RELATED_P (insn))
2842 /* ??? This should be done unconditionally since stack adjustments
2843 matter if the stack pointer is not the CFA register anymore but
2844 is still used to save registers. */
2845 if (!ACCUMULATE_OUTGOING_ARGS)
2846 dwarf2out_notice_stack_adjust (insn, after_p);
2850 label = dwarf2out_cfi_label (false);
2851 any_cfis_emitted = false;
2853 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2854 switch (REG_NOTE_KIND (note))
2856 case REG_FRAME_RELATED_EXPR:
2857 insn = XEXP (note, 0);
2860 case REG_CFA_DEF_CFA:
2861 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2865 case REG_CFA_ADJUST_CFA:
2870 if (GET_CODE (n) == PARALLEL)
2871 n = XVECEXP (n, 0, 0);
2873 dwarf2out_frame_debug_adjust_cfa (n, label);
2877 case REG_CFA_OFFSET:
2880 n = single_set (insn);
2881 dwarf2out_frame_debug_cfa_offset (n, label);
2885 case REG_CFA_REGISTER:
2890 if (GET_CODE (n) == PARALLEL)
2891 n = XVECEXP (n, 0, 0);
2893 dwarf2out_frame_debug_cfa_register (n, label);
2897 case REG_CFA_EXPRESSION:
2900 n = single_set (insn);
2901 dwarf2out_frame_debug_cfa_expression (n, label);
2905 case REG_CFA_RESTORE:
2910 if (GET_CODE (n) == PARALLEL)
2911 n = XVECEXP (n, 0, 0);
2914 dwarf2out_frame_debug_cfa_restore (n, label);
2918 case REG_CFA_SET_VDRAP:
2922 dw_fde_ref fde = current_fde ();
2925 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2927 fde->vdrap_reg = REGNO (n);
2933 case REG_CFA_WINDOW_SAVE:
2934 dwarf2out_frame_debug_cfa_window_save (label);
2938 case REG_CFA_FLUSH_QUEUE:
2939 /* The actual flush happens below. */
2950 /* Minimize the number of advances by emitting the entire queue
2951 once anything is emitted. */
2952 need_flush |= any_cfis_emitted;
2956 insn = PATTERN (insn);
2958 dwarf2out_frame_debug_expr (insn, label);
2960 /* Check again. A parallel can save and update the same register.
2961 We could probably check just once, here, but this is safer than
2962 removing the check at the start of the function. */
2963 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2968 dwarf2out_flush_queued_reg_saves ();
2971 /* Called once at the start of final to initialize some data for the
2972 current function. */
2974 dwarf2out_frame_debug_init (void)
2976 /* Flush any queued register saves. */
2977 dwarf2out_flush_queued_reg_saves ();
2979 /* Set up state for generating call frame debug info. */
2982 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2984 cfa.reg = STACK_POINTER_REGNUM;
2987 cfa_temp.offset = 0;
2989 regs_saved_in_regs = NULL;
2991 if (barrier_args_size)
2993 XDELETEVEC (barrier_args_size);
2994 barrier_args_size = NULL;
2998 /* Determine if we need to save and restore CFI information around this
2999 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
3000 we do need to save/restore, then emit the save now, and insert a
3001 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
3004 dwarf2out_cfi_begin_epilogue (rtx insn)
3006 bool saw_frp = false;
3009 /* Scan forward to the return insn, noticing if there are possible
3010 frame related insns. */
3011 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
3016 /* Look for both regular and sibcalls to end the block. */
3017 if (returnjump_p (i))
3019 if (CALL_P (i) && SIBLING_CALL_P (i))
3022 if (GET_CODE (PATTERN (i)) == SEQUENCE)
3025 rtx seq = PATTERN (i);
3027 if (returnjump_p (XVECEXP (seq, 0, 0)))
3029 if (CALL_P (XVECEXP (seq, 0, 0))
3030 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
3033 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
3034 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
3038 if (RTX_FRAME_RELATED_P (i))
3042 /* If the port doesn't emit epilogue unwind info, we don't need a
3043 save/restore pair. */
3047 /* Otherwise, search forward to see if the return insn was the last
3048 basic block of the function. If so, we don't need save/restore. */
3049 gcc_assert (i != NULL);
3050 i = next_real_insn (i);
3054 /* Insert the restore before that next real insn in the stream, and before
3055 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3056 properly nested. This should be after any label or alignment. This
3057 will be pushed into the CFI stream by the function below. */
3060 rtx p = PREV_INSN (i);
3063 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3067 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3069 emit_cfa_remember = true;
3071 /* And emulate the state save. */
3072 gcc_assert (!cfa_remember.in_use);
3074 cfa_remember.in_use = 1;
3077 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3081 dwarf2out_frame_debug_restore_state (void)
3083 dw_cfi_ref cfi = new_cfi ();
3084 const char *label = dwarf2out_cfi_label (false);
3086 cfi->dw_cfi_opc = DW_CFA_restore_state;
3087 add_fde_cfi (label, cfi);
3089 gcc_assert (cfa_remember.in_use);
3091 cfa_remember.in_use = 0;
3094 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3095 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3096 (enum dwarf_call_frame_info cfi);
3098 static enum dw_cfi_oprnd_type
3099 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3104 case DW_CFA_GNU_window_save:
3105 case DW_CFA_remember_state:
3106 case DW_CFA_restore_state:
3107 return dw_cfi_oprnd_unused;
3109 case DW_CFA_set_loc:
3110 case DW_CFA_advance_loc1:
3111 case DW_CFA_advance_loc2:
3112 case DW_CFA_advance_loc4:
3113 case DW_CFA_MIPS_advance_loc8:
3114 return dw_cfi_oprnd_addr;
3117 case DW_CFA_offset_extended:
3118 case DW_CFA_def_cfa:
3119 case DW_CFA_offset_extended_sf:
3120 case DW_CFA_def_cfa_sf:
3121 case DW_CFA_restore:
3122 case DW_CFA_restore_extended:
3123 case DW_CFA_undefined:
3124 case DW_CFA_same_value:
3125 case DW_CFA_def_cfa_register:
3126 case DW_CFA_register:
3127 case DW_CFA_expression:
3128 return dw_cfi_oprnd_reg_num;
3130 case DW_CFA_def_cfa_offset:
3131 case DW_CFA_GNU_args_size:
3132 case DW_CFA_def_cfa_offset_sf:
3133 return dw_cfi_oprnd_offset;
3135 case DW_CFA_def_cfa_expression:
3136 return dw_cfi_oprnd_loc;
3143 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3144 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3145 (enum dwarf_call_frame_info cfi);
3147 static enum dw_cfi_oprnd_type
3148 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3152 case DW_CFA_def_cfa:
3153 case DW_CFA_def_cfa_sf:
3155 case DW_CFA_offset_extended_sf:
3156 case DW_CFA_offset_extended:
3157 return dw_cfi_oprnd_offset;
3159 case DW_CFA_register:
3160 return dw_cfi_oprnd_reg_num;
3162 case DW_CFA_expression:
3163 return dw_cfi_oprnd_loc;
3166 return dw_cfi_oprnd_unused;
3170 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3171 switch to the data section instead, and write out a synthetic start label
3172 for collect2 the first time around. */
3175 switch_to_eh_frame_section (bool back)
3179 #ifdef EH_FRAME_SECTION_NAME
3180 if (eh_frame_section == 0)
3184 if (EH_TABLES_CAN_BE_READ_ONLY)
3190 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3192 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3194 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3196 flags = ((! flag_pic
3197 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3198 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3199 && (per_encoding & 0x70) != DW_EH_PE_absptr
3200 && (per_encoding & 0x70) != DW_EH_PE_aligned
3201 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3202 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3203 ? 0 : SECTION_WRITE);
3206 flags = SECTION_WRITE;
3207 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3209 #endif /* EH_FRAME_SECTION_NAME */
3211 if (eh_frame_section)
3212 switch_to_section (eh_frame_section);
3215 /* We have no special eh_frame section. Put the information in
3216 the data section and emit special labels to guide collect2. */
3217 switch_to_section (data_section);
3221 label = get_file_function_name ("F");
3222 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3223 targetm.asm_out.globalize_label (asm_out_file,
3224 IDENTIFIER_POINTER (label));
3225 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3230 /* Switch [BACK] to the eh or debug frame table section, depending on
3234 switch_to_frame_table_section (int for_eh, bool back)
3237 switch_to_eh_frame_section (back);
3240 if (!debug_frame_section)
3241 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3242 SECTION_DEBUG, NULL);
3243 switch_to_section (debug_frame_section);
3247 /* Output a Call Frame Information opcode and its operand(s). */
3250 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3255 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3256 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3257 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3258 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3259 ((unsigned HOST_WIDE_INT)
3260 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3261 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3263 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3264 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3265 "DW_CFA_offset, column %#lx", r);
3266 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3267 dw2_asm_output_data_uleb128 (off, NULL);
3269 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3271 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3272 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3273 "DW_CFA_restore, column %#lx", r);
3277 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3278 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3280 switch (cfi->dw_cfi_opc)
3282 case DW_CFA_set_loc:
3284 dw2_asm_output_encoded_addr_rtx (
3285 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3286 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3289 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3290 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3291 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3294 case DW_CFA_advance_loc1:
3295 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3296 fde->dw_fde_current_label, NULL);
3297 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3300 case DW_CFA_advance_loc2:
3301 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3302 fde->dw_fde_current_label, NULL);
3303 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3306 case DW_CFA_advance_loc4:
3307 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3308 fde->dw_fde_current_label, NULL);
3309 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3312 case DW_CFA_MIPS_advance_loc8:
3313 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3314 fde->dw_fde_current_label, NULL);
3315 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3318 case DW_CFA_offset_extended:
3319 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3320 dw2_asm_output_data_uleb128 (r, NULL);
3321 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3322 dw2_asm_output_data_uleb128 (off, NULL);
3325 case DW_CFA_def_cfa:
3326 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3327 dw2_asm_output_data_uleb128 (r, NULL);
3328 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3331 case DW_CFA_offset_extended_sf:
3332 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3333 dw2_asm_output_data_uleb128 (r, NULL);
3334 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3335 dw2_asm_output_data_sleb128 (off, NULL);
3338 case DW_CFA_def_cfa_sf:
3339 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3340 dw2_asm_output_data_uleb128 (r, NULL);
3341 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3342 dw2_asm_output_data_sleb128 (off, NULL);
3345 case DW_CFA_restore_extended:
3346 case DW_CFA_undefined:
3347 case DW_CFA_same_value:
3348 case DW_CFA_def_cfa_register:
3349 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3350 dw2_asm_output_data_uleb128 (r, NULL);
3353 case DW_CFA_register:
3354 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3355 dw2_asm_output_data_uleb128 (r, NULL);
3356 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3357 dw2_asm_output_data_uleb128 (r, NULL);
3360 case DW_CFA_def_cfa_offset:
3361 case DW_CFA_GNU_args_size:
3362 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3365 case DW_CFA_def_cfa_offset_sf:
3366 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3367 dw2_asm_output_data_sleb128 (off, NULL);
3370 case DW_CFA_GNU_window_save:
3373 case DW_CFA_def_cfa_expression:
3374 case DW_CFA_expression:
3375 output_cfa_loc (cfi, for_eh);
3378 case DW_CFA_GNU_negative_offset_extended:
3379 /* Obsoleted by DW_CFA_offset_extended_sf. */
3388 /* Similar, but do it via assembler directives instead. */
3391 output_cfi_directive (dw_cfi_ref cfi)
3393 unsigned long r, r2;
3395 switch (cfi->dw_cfi_opc)
3397 case DW_CFA_advance_loc:
3398 case DW_CFA_advance_loc1:
3399 case DW_CFA_advance_loc2:
3400 case DW_CFA_advance_loc4:
3401 case DW_CFA_MIPS_advance_loc8:
3402 case DW_CFA_set_loc:
3403 /* Should only be created by add_fde_cfi in a code path not
3404 followed when emitting via directives. The assembler is
3405 going to take care of this for us. */
3409 case DW_CFA_offset_extended:
3410 case DW_CFA_offset_extended_sf:
3411 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3412 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3413 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3416 case DW_CFA_restore:
3417 case DW_CFA_restore_extended:
3418 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3419 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3422 case DW_CFA_undefined:
3423 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3424 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3427 case DW_CFA_same_value:
3428 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3429 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3432 case DW_CFA_def_cfa:
3433 case DW_CFA_def_cfa_sf:
3434 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3435 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3436 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3439 case DW_CFA_def_cfa_register:
3440 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3441 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3444 case DW_CFA_register:
3445 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3446 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3447 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3450 case DW_CFA_def_cfa_offset:
3451 case DW_CFA_def_cfa_offset_sf:
3452 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3453 HOST_WIDE_INT_PRINT_DEC"\n",
3454 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3457 case DW_CFA_remember_state:
3458 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3460 case DW_CFA_restore_state:
3461 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3464 case DW_CFA_GNU_args_size:
3465 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3466 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3468 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3469 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3470 fputc ('\n', asm_out_file);
3473 case DW_CFA_GNU_window_save:
3474 fprintf (asm_out_file, "\t.cfi_window_save\n");
3477 case DW_CFA_def_cfa_expression:
3478 case DW_CFA_expression:
3479 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3480 output_cfa_loc_raw (cfi);
3481 fputc ('\n', asm_out_file);
3489 /* Output CFIs from VEC, up to index UPTO, to bring current FDE to the
3490 same state as after executing CFIs in CFI chain. DO_CFI_ASM is
3491 true if .cfi_* directives shall be emitted, false otherwise. If it
3492 is false, FDE and FOR_EH are the other arguments to pass to
3496 output_cfis (cfi_vec vec, int upto, bool do_cfi_asm,
3497 dw_fde_ref fde, bool for_eh)
3500 struct dw_cfi_struct cfi_buf;
3502 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3503 VEC(dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3504 unsigned int len, idx;
3506 for (ix = 0; ix < upto + 1; ix++)
3508 dw_cfi_ref cfi = ix < upto ? VEC_index (dw_cfi_ref, vec, ix) : NULL;
3509 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3511 case DW_CFA_advance_loc:
3512 case DW_CFA_advance_loc1:
3513 case DW_CFA_advance_loc2:
3514 case DW_CFA_advance_loc4:
3515 case DW_CFA_MIPS_advance_loc8:
3516 case DW_CFA_set_loc:
3517 /* All advances should be ignored. */
3519 case DW_CFA_remember_state:
3521 dw_cfi_ref args_size = cfi_args_size;
3523 /* Skip everything between .cfi_remember_state and
3524 .cfi_restore_state. */
3529 for (; ix < upto; ix++)
3531 cfi2 = VEC_index (dw_cfi_ref, vec, ix);
3532 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3534 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3537 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3540 cfi_args_size = args_size;
3543 case DW_CFA_GNU_args_size:
3544 cfi_args_size = cfi;
3546 case DW_CFA_GNU_window_save:
3549 case DW_CFA_offset_extended:
3550 case DW_CFA_offset_extended_sf:
3551 case DW_CFA_restore:
3552 case DW_CFA_restore_extended:
3553 case DW_CFA_undefined:
3554 case DW_CFA_same_value:
3555 case DW_CFA_register:
3556 case DW_CFA_val_offset:
3557 case DW_CFA_val_offset_sf:
3558 case DW_CFA_expression:
3559 case DW_CFA_val_expression:
3560 case DW_CFA_GNU_negative_offset_extended:
3561 if (VEC_length (dw_cfi_ref, regs)
3562 <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3563 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3564 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3565 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
3568 case DW_CFA_def_cfa:
3569 case DW_CFA_def_cfa_sf:
3570 case DW_CFA_def_cfa_expression:
3572 cfi_cfa_offset = cfi;
3574 case DW_CFA_def_cfa_register:
3577 case DW_CFA_def_cfa_offset:
3578 case DW_CFA_def_cfa_offset_sf:
3579 cfi_cfa_offset = cfi;
3582 gcc_assert (cfi == NULL);
3584 len = VEC_length (dw_cfi_ref, regs);
3585 for (idx = 0; idx < len; idx++)
3587 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3589 && cfi2->dw_cfi_opc != DW_CFA_restore
3590 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3593 output_cfi_directive (cfi2);
3595 output_cfi (cfi2, fde, for_eh);
3598 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3600 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3602 switch (cfi_cfa_offset->dw_cfi_opc)
3604 case DW_CFA_def_cfa_offset:
3605 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3606 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3608 case DW_CFA_def_cfa_offset_sf:
3609 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3610 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3612 case DW_CFA_def_cfa:
3613 case DW_CFA_def_cfa_sf:
3614 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3615 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3622 else if (cfi_cfa_offset)
3623 cfi_cfa = cfi_cfa_offset;
3627 output_cfi_directive (cfi_cfa);
3629 output_cfi (cfi_cfa, fde, for_eh);
3632 cfi_cfa_offset = NULL;
3634 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3637 output_cfi_directive (cfi_args_size);
3639 output_cfi (cfi_args_size, fde, for_eh);
3641 cfi_args_size = NULL;
3644 VEC_free (dw_cfi_ref, heap, regs);
3647 else if (do_cfi_asm)
3648 output_cfi_directive (cfi);
3650 output_cfi (cfi, fde, for_eh);
3658 /* Like output_cfis, but emit all CFIs in the vector. */
3660 output_all_cfis (cfi_vec vec, bool do_cfi_asm,
3661 dw_fde_ref fde, bool for_eh)
3663 output_cfis (vec, VEC_length (dw_cfi_ref, vec), do_cfi_asm, fde, for_eh);
3666 /* Output one FDE. */
3669 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3670 char *section_start_label, int fde_encoding, char *augmentation,
3671 bool any_lsda_needed, int lsda_encoding)
3674 const char *begin, *end;
3675 static unsigned int j;
3676 char l1[20], l2[20];
3679 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3681 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3683 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3684 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3685 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3686 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3687 " indicating 64-bit DWARF extension");
3688 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3690 ASM_OUTPUT_LABEL (asm_out_file, l1);
3693 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3695 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3696 debug_frame_section, "FDE CIE offset");
3698 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
3699 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
3703 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3704 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3705 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3706 "FDE initial location");
3707 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3708 end, begin, "FDE address range");
3712 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3713 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3716 if (augmentation[0])
3718 if (any_lsda_needed)
3720 int size = size_of_encoded_value (lsda_encoding);
3722 if (lsda_encoding == DW_EH_PE_aligned)
3724 int offset = ( 4 /* Length */
3725 + 4 /* CIE offset */
3726 + 2 * size_of_encoded_value (fde_encoding)
3727 + 1 /* Augmentation size */ );
3728 int pad = -offset & (PTR_SIZE - 1);
3731 gcc_assert (size_of_uleb128 (size) == 1);
3734 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3736 if (fde->uses_eh_lsda)
3738 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3739 fde->funcdef_number);
3740 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3741 gen_rtx_SYMBOL_REF (Pmode, l1),
3743 "Language Specific Data Area");
3747 if (lsda_encoding == DW_EH_PE_aligned)
3748 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3749 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3750 "Language Specific Data Area (none)");
3754 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3757 /* Loop through the Call Frame Instructions associated with
3759 fde->dw_fde_current_label = begin;
3760 if (fde->dw_fde_second_begin == NULL)
3761 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
3762 output_cfi (cfi, fde, for_eh);
3765 if (fde->dw_fde_switch_cfi_index > 0)
3766 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
3768 if (ix == fde->dw_fde_switch_cfi_index)
3770 output_cfi (cfi, fde, for_eh);
3776 int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
3778 if (fde->dw_fde_switch_cfi_index > 0)
3780 from = fde->dw_fde_switch_cfi_index;
3781 output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh);
3783 for (i = from; i < until; i++)
3784 output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i),
3788 /* If we are to emit a ref/link from function bodies to their frame tables,
3789 do it now. This is typically performed to make sure that tables
3790 associated with functions are dragged with them and not discarded in
3791 garbage collecting links. We need to do this on a per function basis to
3792 cope with -ffunction-sections. */
3794 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3795 /* Switch to the function section, emit the ref to the tables, and
3796 switch *back* into the table section. */
3797 switch_to_section (function_section (fde->decl));
3798 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3799 switch_to_frame_table_section (for_eh, true);
3802 /* Pad the FDE out to an address sized boundary. */
3803 ASM_OUTPUT_ALIGN (asm_out_file,
3804 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3805 ASM_OUTPUT_LABEL (asm_out_file, l2);
3810 /* Return true if frame description entry FDE is needed for EH. */
3813 fde_needed_for_eh_p (dw_fde_ref fde)
3815 if (flag_asynchronous_unwind_tables)
3818 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3821 if (fde->uses_eh_lsda)
3824 /* If exceptions are enabled, we have collected nothrow info. */
3825 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3831 /* Output the call frame information used to record information
3832 that relates to calculating the frame pointer, and records the
3833 location of saved registers. */
3836 output_call_frame_info (int for_eh)
3841 char l1[20], l2[20], section_start_label[20];
3842 bool any_lsda_needed = false;
3843 char augmentation[6];
3844 int augmentation_size;
3845 int fde_encoding = DW_EH_PE_absptr;
3846 int per_encoding = DW_EH_PE_absptr;
3847 int lsda_encoding = DW_EH_PE_absptr;
3849 rtx personality = NULL;
3852 /* Don't emit a CIE if there won't be any FDEs. */
3853 if (fde_table_in_use == 0)
3856 /* Nothing to do if the assembler's doing it all. */
3857 if (dwarf2out_do_cfi_asm ())
3860 /* If we don't have any functions we'll want to unwind out of, don't emit
3861 any EH unwind information. If we make FDEs linkonce, we may have to
3862 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3863 want to avoid having an FDE kept around when the function it refers to
3864 is discarded. Example where this matters: a primary function template
3865 in C++ requires EH information, an explicit specialization doesn't. */
3868 bool any_eh_needed = false;
3870 for (i = 0; i < fde_table_in_use; i++)
3871 if (fde_table[i].uses_eh_lsda)
3872 any_eh_needed = any_lsda_needed = true;
3873 else if (fde_needed_for_eh_p (&fde_table[i]))
3874 any_eh_needed = true;
3875 else if (TARGET_USES_WEAK_UNWIND_INFO)
3876 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3883 /* We're going to be generating comments, so turn on app. */
3887 /* Switch to the proper frame section, first time. */
3888 switch_to_frame_table_section (for_eh, false);
3890 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3891 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3893 /* Output the CIE. */
3894 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3895 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3896 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3897 dw2_asm_output_data (4, 0xffffffff,
3898 "Initial length escape value indicating 64-bit DWARF extension");
3899 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3900 "Length of Common Information Entry");
3901 ASM_OUTPUT_LABEL (asm_out_file, l1);
3903 /* Now that the CIE pointer is PC-relative for EH,
3904 use 0 to identify the CIE. */
3905 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3906 (for_eh ? 0 : DWARF_CIE_ID),
3907 "CIE Identifier Tag");
3909 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3910 use CIE version 1, unless that would produce incorrect results
3911 due to overflowing the return register column. */
3912 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3914 if (return_reg >= 256 || dwarf_version > 2)
3916 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3918 augmentation[0] = 0;
3919 augmentation_size = 0;
3921 personality = current_unit_personality;
3927 z Indicates that a uleb128 is present to size the
3928 augmentation section.
3929 L Indicates the encoding (and thus presence) of
3930 an LSDA pointer in the FDE augmentation.
3931 R Indicates a non-default pointer encoding for
3933 P Indicates the presence of an encoding + language
3934 personality routine in the CIE augmentation. */
3936 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3937 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3938 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3940 p = augmentation + 1;
3944 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3945 assemble_external_libcall (personality);
3947 if (any_lsda_needed)
3950 augmentation_size += 1;
3952 if (fde_encoding != DW_EH_PE_absptr)
3955 augmentation_size += 1;
3957 if (p > augmentation + 1)
3959 augmentation[0] = 'z';
3963 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3964 if (personality && per_encoding == DW_EH_PE_aligned)
3966 int offset = ( 4 /* Length */
3968 + 1 /* CIE version */
3969 + strlen (augmentation) + 1 /* Augmentation */
3970 + size_of_uleb128 (1) /* Code alignment */
3971 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3973 + 1 /* Augmentation size */
3974 + 1 /* Personality encoding */ );
3975 int pad = -offset & (PTR_SIZE - 1);
3977 augmentation_size += pad;
3979 /* Augmentations should be small, so there's scarce need to
3980 iterate for a solution. Die if we exceed one uleb128 byte. */
3981 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3985 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3986 if (dw_cie_version >= 4)
3988 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3989 dw2_asm_output_data (1, 0, "CIE Segment Size");
3991 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3992 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3993 "CIE Data Alignment Factor");
3995 if (dw_cie_version == 1)
3996 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3998 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
4000 if (augmentation[0])
4002 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
4005 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
4006 eh_data_format_name (per_encoding));
4007 dw2_asm_output_encoded_addr_rtx (per_encoding,
4012 if (any_lsda_needed)
4013 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
4014 eh_data_format_name (lsda_encoding));
4016 if (fde_encoding != DW_EH_PE_absptr)
4017 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
4018 eh_data_format_name (fde_encoding));
4021 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
4022 output_cfi (cfi, NULL, for_eh);
4024 /* Pad the CIE out to an address sized boundary. */
4025 ASM_OUTPUT_ALIGN (asm_out_file,
4026 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
4027 ASM_OUTPUT_LABEL (asm_out_file, l2);
4029 /* Loop through all of the FDE's. */
4030 for (i = 0; i < fde_table_in_use; i++)
4033 fde = &fde_table[i];
4035 /* Don't emit EH unwind info for leaf functions that don't need it. */
4036 if (for_eh && !fde_needed_for_eh_p (fde))
4039 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
4040 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
4041 augmentation, any_lsda_needed, lsda_encoding);
4044 if (for_eh && targetm.terminate_dw2_eh_frame_info)
4045 dw2_asm_output_data (4, 0, "End of Table");
4046 #ifdef MIPS_DEBUGGING_INFO
4047 /* Work around Irix 6 assembler bug whereby labels at the end of a section
4048 get a value of 0. Putting .align 0 after the label fixes it. */
4049 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4052 /* Turn off app to make assembly quicker. */
4057 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4060 dwarf2out_do_cfi_startproc (bool second)
4064 rtx personality = get_personality_function (current_function_decl);
4066 fprintf (asm_out_file, "\t.cfi_startproc\n");
4070 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4073 /* ??? The GAS support isn't entirely consistent. We have to
4074 handle indirect support ourselves, but PC-relative is done
4075 in the assembler. Further, the assembler can't handle any
4076 of the weirder relocation types. */
4077 if (enc & DW_EH_PE_indirect)
4078 ref = dw2_force_const_mem (ref, true);
4080 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4081 output_addr_const (asm_out_file, ref);
4082 fputc ('\n', asm_out_file);
4085 if (crtl->uses_eh_lsda)
4089 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4090 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4091 current_function_funcdef_no);
4092 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4093 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4095 if (enc & DW_EH_PE_indirect)
4096 ref = dw2_force_const_mem (ref, true);
4098 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4099 output_addr_const (asm_out_file, ref);
4100 fputc ('\n', asm_out_file);
4104 /* Output a marker (i.e. a label) for the beginning of a function, before
4108 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4109 const char *file ATTRIBUTE_UNUSED)
4111 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4117 current_function_func_begin_label = NULL;
4119 do_frame = dwarf2out_do_frame ();
4121 /* ??? current_function_func_begin_label is also used by except.c for
4122 call-site information. We must emit this label if it might be used. */
4124 && (!flag_exceptions
4125 || targetm_common.except_unwind_info (&global_options) != UI_TARGET))
4128 fnsec = function_section (current_function_decl);
4129 switch_to_section (fnsec);
4130 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4131 current_function_funcdef_no);
4132 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4133 current_function_funcdef_no);
4134 dup_label = xstrdup (label);
4135 current_function_func_begin_label = dup_label;
4137 /* We can elide the fde allocation if we're not emitting debug info. */
4141 /* Expand the fde table if necessary. */
4142 if (fde_table_in_use == fde_table_allocated)
4144 fde_table_allocated += FDE_TABLE_INCREMENT;
4145 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4146 memset (fde_table + fde_table_in_use, 0,
4147 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4150 /* Record the FDE associated with this function. */
4151 current_funcdef_fde = fde_table_in_use;
4153 /* Add the new FDE at the end of the fde_table. */
4154 fde = &fde_table[fde_table_in_use++];
4155 fde->decl = current_function_decl;
4156 fde->dw_fde_begin = dup_label;
4157 fde->dw_fde_end = NULL;
4158 fde->dw_fde_current_label = dup_label;
4159 fde->dw_fde_second_begin = NULL;
4160 fde->dw_fde_second_end = NULL;
4161 fde->dw_fde_vms_end_prologue = NULL;
4162 fde->dw_fde_vms_begin_epilogue = NULL;
4163 fde->dw_fde_cfi = VEC_alloc (dw_cfi_ref, gc, 20);
4164 fde->dw_fde_switch_cfi_index = 0;
4165 fde->funcdef_number = current_function_funcdef_no;
4166 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4167 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4168 fde->nothrow = crtl->nothrow;
4169 fde->drap_reg = INVALID_REGNUM;
4170 fde->vdrap_reg = INVALID_REGNUM;
4171 fde->in_std_section = (fnsec == text_section
4172 || (cold_text_section && fnsec == cold_text_section));
4173 fde->second_in_std_section = 0;
4175 args_size = old_args_size = 0;
4177 /* We only want to output line number information for the genuine dwarf2
4178 prologue case, not the eh frame case. */
4179 #ifdef DWARF2_DEBUGGING_INFO
4181 dwarf2out_source_line (line, file, 0, true);
4184 if (dwarf2out_do_cfi_asm ())
4185 dwarf2out_do_cfi_startproc (false);
4188 rtx personality = get_personality_function (current_function_decl);
4189 if (!current_unit_personality)
4190 current_unit_personality = personality;
4192 /* We cannot keep a current personality per function as without CFI
4193 asm, at the point where we emit the CFI data, there is no current
4194 function anymore. */
4195 if (personality && current_unit_personality != personality)
4196 sorry ("multiple EH personalities are supported only with assemblers "
4197 "supporting .cfi_personality directive");
4201 /* Output a marker (i.e. a label) for the end of the generated code
4202 for a function prologue. This gets called *after* the prologue code has
4206 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4207 const char *file ATTRIBUTE_UNUSED)
4210 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4212 /* Output a label to mark the endpoint of the code generated for this
4214 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4215 current_function_funcdef_no);
4216 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4217 current_function_funcdef_no);
4218 fde = &fde_table[fde_table_in_use - 1];
4219 fde->dw_fde_vms_end_prologue = xstrdup (label);
4222 /* Output a marker (i.e. a label) for the beginning of the generated code
4223 for a function epilogue. This gets called *before* the prologue code has
4227 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4228 const char *file ATTRIBUTE_UNUSED)
4231 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4233 fde = &fde_table[fde_table_in_use - 1];
4234 if (fde->dw_fde_vms_begin_epilogue)
4237 /* Output a label to mark the endpoint of the code generated for this
4239 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4240 current_function_funcdef_no);
4241 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4242 current_function_funcdef_no);
4243 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4246 /* Output a marker (i.e. a label) for the absolute end of the generated code
4247 for a function definition. This gets called *after* the epilogue code has
4251 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4252 const char *file ATTRIBUTE_UNUSED)
4255 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4257 last_var_location_insn = NULL_RTX;
4259 if (dwarf2out_do_cfi_asm ())
4260 fprintf (asm_out_file, "\t.cfi_endproc\n");
4262 /* Output a label to mark the endpoint of the code generated for this
4264 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4265 current_function_funcdef_no);
4266 ASM_OUTPUT_LABEL (asm_out_file, label);
4267 fde = current_fde ();
4268 gcc_assert (fde != NULL);
4269 if (fde->dw_fde_second_begin == NULL)
4270 fde->dw_fde_end = xstrdup (label);
4274 dwarf2out_frame_init (void)
4276 /* Allocate the initial hunk of the fde_table. */
4277 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4278 fde_table_allocated = FDE_TABLE_INCREMENT;
4279 fde_table_in_use = 0;
4281 /* Generate the CFA instructions common to all FDE's. Do it now for the
4282 sake of lookup_cfa. */
4284 /* On entry, the Canonical Frame Address is at SP. */
4285 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4287 if (targetm.debug_unwind_info () == UI_DWARF2
4288 || targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
4289 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4293 dwarf2out_frame_finish (void)
4295 /* Output call frame information. */
4296 if (targetm.debug_unwind_info () == UI_DWARF2)
4297 output_call_frame_info (0);
4299 /* Output another copy for the unwinder. */
4300 if ((flag_unwind_tables || flag_exceptions)
4301 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
4302 output_call_frame_info (1);
4305 /* Note that the current function section is being used for code. */
4308 dwarf2out_note_section_used (void)
4310 section *sec = current_function_section ();
4311 if (sec == text_section)
4312 text_section_used = true;
4313 else if (sec == cold_text_section)
4314 cold_text_section_used = true;
4317 static void var_location_switch_text_section (void);
4318 static void set_cur_line_info_table (section *);
4321 dwarf2out_switch_text_section (void)
4324 dw_fde_ref fde = current_fde ();
4326 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
4328 if (!in_cold_section_p)
4330 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
4331 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
4332 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
4336 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
4337 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
4338 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
4340 have_multiple_function_sections = true;
4342 /* Reset the current label on switching text sections, so that we
4343 don't attempt to advance_loc4 between labels in different sections. */
4344 fde->dw_fde_current_label = NULL;
4346 /* There is no need to mark used sections when not debugging. */
4347 if (cold_text_section != NULL)
4348 dwarf2out_note_section_used ();
4350 if (dwarf2out_do_cfi_asm ())
4351 fprintf (asm_out_file, "\t.cfi_endproc\n");
4353 /* Now do the real section switch. */
4354 sect = current_function_section ();
4355 switch_to_section (sect);
4357 fde->second_in_std_section
4358 = (sect == text_section
4359 || (cold_text_section && sect == cold_text_section));
4361 if (dwarf2out_do_cfi_asm ())
4363 dwarf2out_do_cfi_startproc (true);
4364 /* As this is a different FDE, insert all current CFI instructions
4366 output_all_cfis (fde->dw_fde_cfi, true, fde, true);
4368 fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
4369 var_location_switch_text_section ();
4371 set_cur_line_info_table (sect);
4374 /* And now, the subset of the debugging information support code necessary
4375 for emitting location expressions. */
4377 /* Data about a single source file. */
4378 struct GTY(()) dwarf_file_data {
4379 const char * filename;
4383 typedef struct dw_val_struct *dw_val_ref;
4384 typedef struct die_struct *dw_die_ref;
4385 typedef const struct die_struct *const_dw_die_ref;
4386 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4387 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4389 typedef struct GTY(()) deferred_locations_struct
4393 } deferred_locations;
4395 DEF_VEC_O(deferred_locations);
4396 DEF_VEC_ALLOC_O(deferred_locations,gc);
4398 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4400 DEF_VEC_P(dw_die_ref);
4401 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4403 /* Each DIE may have a series of attribute/value pairs. Values
4404 can take on several forms. The forms that are used in this
4405 implementation are listed below. */
4410 dw_val_class_offset,
4412 dw_val_class_loc_list,
4413 dw_val_class_range_list,
4415 dw_val_class_unsigned_const,
4416 dw_val_class_const_double,
4419 dw_val_class_die_ref,
4420 dw_val_class_fde_ref,
4421 dw_val_class_lbl_id,
4422 dw_val_class_lineptr,
4424 dw_val_class_macptr,
4427 dw_val_class_decl_ref,
4428 dw_val_class_vms_delta
4431 /* Describe a floating point constant value, or a vector constant value. */
4433 typedef struct GTY(()) dw_vec_struct {
4434 unsigned char * GTY((length ("%h.length"))) array;
4440 /* The dw_val_node describes an attribute's value, as it is
4441 represented internally. */
4443 typedef struct GTY(()) dw_val_struct {
4444 enum dw_val_class val_class;
4445 union dw_val_struct_union
4447 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4448 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4449 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4450 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4451 HOST_WIDE_INT GTY ((default)) val_int;
4452 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4453 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4454 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4455 struct dw_val_die_union
4459 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4460 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4461 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4462 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4463 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4464 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4465 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4466 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4467 struct dw_val_vms_delta_union
4471 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4473 GTY ((desc ("%1.val_class"))) v;
4477 /* Locations in memory are described using a sequence of stack machine
4480 typedef struct GTY(()) dw_loc_descr_struct {
4481 dw_loc_descr_ref dw_loc_next;
4482 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4483 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4484 from DW_OP_addr with a dtp-relative symbol relocation. */
4485 unsigned int dtprel : 1;
4487 dw_val_node dw_loc_oprnd1;
4488 dw_val_node dw_loc_oprnd2;
4492 /* Location lists are ranges + location descriptions for that range,
4493 so you can track variables that are in different places over
4494 their entire life. */
4495 typedef struct GTY(()) dw_loc_list_struct {
4496 dw_loc_list_ref dw_loc_next;
4497 const char *begin; /* Label for begin address of range */
4498 const char *end; /* Label for end address of range */
4499 char *ll_symbol; /* Label for beginning of location list.
4500 Only on head of list */
4501 const char *section; /* Section this loclist is relative to */
4502 dw_loc_descr_ref expr;
4504 /* True if all addresses in this and subsequent lists are known to be
4507 /* True if this list has been replaced by dw_loc_next. */
4510 /* True if the range should be emitted even if begin and end
4515 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4517 /* Convert a DWARF stack opcode into its string name. */
4520 dwarf_stack_op_name (unsigned int op)
4525 return "DW_OP_addr";
4527 return "DW_OP_deref";
4529 return "DW_OP_const1u";
4531 return "DW_OP_const1s";
4533 return "DW_OP_const2u";
4535 return "DW_OP_const2s";
4537 return "DW_OP_const4u";
4539 return "DW_OP_const4s";
4541 return "DW_OP_const8u";
4543 return "DW_OP_const8s";
4545 return "DW_OP_constu";
4547 return "DW_OP_consts";
4551 return "DW_OP_drop";
4553 return "DW_OP_over";
4555 return "DW_OP_pick";
4557 return "DW_OP_swap";
4561 return "DW_OP_xderef";
4569 return "DW_OP_minus";
4581 return "DW_OP_plus";
4582 case DW_OP_plus_uconst:
4583 return "DW_OP_plus_uconst";
4589 return "DW_OP_shra";
4607 return "DW_OP_skip";
4609 return "DW_OP_lit0";
4611 return "DW_OP_lit1";
4613 return "DW_OP_lit2";
4615 return "DW_OP_lit3";
4617 return "DW_OP_lit4";
4619 return "DW_OP_lit5";
4621 return "DW_OP_lit6";
4623 return "DW_OP_lit7";
4625 return "DW_OP_lit8";
4627 return "DW_OP_lit9";
4629 return "DW_OP_lit10";
4631 return "DW_OP_lit11";
4633 return "DW_OP_lit12";
4635 return "DW_OP_lit13";
4637 return "DW_OP_lit14";
4639 return "DW_OP_lit15";
4641 return "DW_OP_lit16";
4643 return "DW_OP_lit17";
4645 return "DW_OP_lit18";
4647 return "DW_OP_lit19";
4649 return "DW_OP_lit20";
4651 return "DW_OP_lit21";
4653 return "DW_OP_lit22";
4655 return "DW_OP_lit23";
4657 return "DW_OP_lit24";
4659 return "DW_OP_lit25";
4661 return "DW_OP_lit26";
4663 return "DW_OP_lit27";
4665 return "DW_OP_lit28";
4667 return "DW_OP_lit29";
4669 return "DW_OP_lit30";
4671 return "DW_OP_lit31";
4673 return "DW_OP_reg0";
4675 return "DW_OP_reg1";
4677 return "DW_OP_reg2";
4679 return "DW_OP_reg3";
4681 return "DW_OP_reg4";
4683 return "DW_OP_reg5";
4685 return "DW_OP_reg6";
4687 return "DW_OP_reg7";
4689 return "DW_OP_reg8";
4691 return "DW_OP_reg9";
4693 return "DW_OP_reg10";
4695 return "DW_OP_reg11";
4697 return "DW_OP_reg12";
4699 return "DW_OP_reg13";
4701 return "DW_OP_reg14";
4703 return "DW_OP_reg15";
4705 return "DW_OP_reg16";
4707 return "DW_OP_reg17";
4709 return "DW_OP_reg18";
4711 return "DW_OP_reg19";
4713 return "DW_OP_reg20";
4715 return "DW_OP_reg21";
4717 return "DW_OP_reg22";
4719 return "DW_OP_reg23";
4721 return "DW_OP_reg24";
4723 return "DW_OP_reg25";
4725 return "DW_OP_reg26";
4727 return "DW_OP_reg27";
4729 return "DW_OP_reg28";
4731 return "DW_OP_reg29";
4733 return "DW_OP_reg30";
4735 return "DW_OP_reg31";
4737 return "DW_OP_breg0";
4739 return "DW_OP_breg1";
4741 return "DW_OP_breg2";
4743 return "DW_OP_breg3";
4745 return "DW_OP_breg4";
4747 return "DW_OP_breg5";
4749 return "DW_OP_breg6";
4751 return "DW_OP_breg7";
4753 return "DW_OP_breg8";
4755 return "DW_OP_breg9";
4757 return "DW_OP_breg10";
4759 return "DW_OP_breg11";
4761 return "DW_OP_breg12";
4763 return "DW_OP_breg13";
4765 return "DW_OP_breg14";
4767 return "DW_OP_breg15";
4769 return "DW_OP_breg16";
4771 return "DW_OP_breg17";
4773 return "DW_OP_breg18";
4775 return "DW_OP_breg19";
4777 return "DW_OP_breg20";
4779 return "DW_OP_breg21";
4781 return "DW_OP_breg22";
4783 return "DW_OP_breg23";
4785 return "DW_OP_breg24";
4787 return "DW_OP_breg25";
4789 return "DW_OP_breg26";
4791 return "DW_OP_breg27";
4793 return "DW_OP_breg28";
4795 return "DW_OP_breg29";
4797 return "DW_OP_breg30";
4799 return "DW_OP_breg31";
4801 return "DW_OP_regx";
4803 return "DW_OP_fbreg";
4805 return "DW_OP_bregx";
4807 return "DW_OP_piece";
4808 case DW_OP_deref_size:
4809 return "DW_OP_deref_size";
4810 case DW_OP_xderef_size:
4811 return "DW_OP_xderef_size";
4815 case DW_OP_push_object_address:
4816 return "DW_OP_push_object_address";
4818 return "DW_OP_call2";
4820 return "DW_OP_call4";
4821 case DW_OP_call_ref:
4822 return "DW_OP_call_ref";
4823 case DW_OP_implicit_value:
4824 return "DW_OP_implicit_value";
4825 case DW_OP_stack_value:
4826 return "DW_OP_stack_value";
4827 case DW_OP_form_tls_address:
4828 return "DW_OP_form_tls_address";
4829 case DW_OP_call_frame_cfa:
4830 return "DW_OP_call_frame_cfa";
4831 case DW_OP_bit_piece:
4832 return "DW_OP_bit_piece";
4834 case DW_OP_GNU_push_tls_address:
4835 return "DW_OP_GNU_push_tls_address";
4836 case DW_OP_GNU_uninit:
4837 return "DW_OP_GNU_uninit";
4838 case DW_OP_GNU_encoded_addr:
4839 return "DW_OP_GNU_encoded_addr";
4840 case DW_OP_GNU_implicit_pointer:
4841 return "DW_OP_GNU_implicit_pointer";
4842 case DW_OP_GNU_entry_value:
4843 return "DW_OP_GNU_entry_value";
4844 case DW_OP_GNU_const_type:
4845 return "DW_OP_GNU_const_type";
4846 case DW_OP_GNU_regval_type:
4847 return "DW_OP_GNU_regval_type";
4848 case DW_OP_GNU_deref_type:
4849 return "DW_OP_GNU_deref_type";
4850 case DW_OP_GNU_convert:
4851 return "DW_OP_GNU_convert";
4852 case DW_OP_GNU_reinterpret:
4853 return "DW_OP_GNU_reinterpret";
4854 case DW_OP_GNU_parameter_ref:
4855 return "DW_OP_GNU_parameter_ref";
4858 return "OP_<unknown>";
4862 /* Return a pointer to a newly allocated location description. Location
4863 descriptions are simple expression terms that can be strung
4864 together to form more complicated location (address) descriptions. */
4866 static inline dw_loc_descr_ref
4867 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4868 unsigned HOST_WIDE_INT oprnd2)
4870 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4872 descr->dw_loc_opc = op;
4873 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4874 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4875 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4876 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4881 /* Return a pointer to a newly allocated location description for
4884 static inline dw_loc_descr_ref
4885 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4888 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4891 return new_loc_descr (DW_OP_bregx, reg, offset);
4894 /* Add a location description term to a location description expression. */
4897 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4899 dw_loc_descr_ref *d;
4901 /* Find the end of the chain. */
4902 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4908 /* Add a constant OFFSET to a location expression. */
4911 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4913 dw_loc_descr_ref loc;
4916 gcc_assert (*list_head != NULL);
4921 /* Find the end of the chain. */
4922 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4926 if (loc->dw_loc_opc == DW_OP_fbreg
4927 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4928 p = &loc->dw_loc_oprnd1.v.val_int;
4929 else if (loc->dw_loc_opc == DW_OP_bregx)
4930 p = &loc->dw_loc_oprnd2.v.val_int;
4932 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4933 offset. Don't optimize if an signed integer overflow would happen. */
4935 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4936 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4939 else if (offset > 0)
4940 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4944 loc->dw_loc_next = int_loc_descriptor (-offset);
4945 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4949 /* Add a constant OFFSET to a location list. */
4952 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4955 for (d = list_head; d != NULL; d = d->dw_loc_next)
4956 loc_descr_plus_const (&d->expr, offset);
4959 #define DWARF_REF_SIZE \
4960 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4962 static unsigned long size_of_locs (dw_loc_descr_ref);
4963 static unsigned long int get_base_type_offset (dw_die_ref);
4965 /* Return the size of a location descriptor. */
4967 static unsigned long
4968 size_of_loc_descr (dw_loc_descr_ref loc)
4970 unsigned long size = 1;
4972 switch (loc->dw_loc_opc)
4975 size += DWARF2_ADDR_SIZE;
4994 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4997 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
5002 case DW_OP_plus_uconst:
5003 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5041 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
5044 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5047 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
5050 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5051 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5054 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5056 case DW_OP_bit_piece:
5057 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5058 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
5060 case DW_OP_deref_size:
5061 case DW_OP_xderef_size:
5070 case DW_OP_call_ref:
5071 size += DWARF_REF_SIZE;
5073 case DW_OP_implicit_value:
5074 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5075 + loc->dw_loc_oprnd1.v.val_unsigned;
5077 case DW_OP_GNU_implicit_pointer:
5078 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5080 case DW_OP_GNU_entry_value:
5082 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
5083 size += size_of_uleb128 (op_size) + op_size;
5086 case DW_OP_GNU_const_type:
5089 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
5090 size += size_of_uleb128 (o) + 1;
5091 switch (loc->dw_loc_oprnd2.val_class)
5093 case dw_val_class_vec:
5094 size += loc->dw_loc_oprnd2.v.val_vec.length
5095 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
5097 case dw_val_class_const:
5098 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
5100 case dw_val_class_const_double:
5101 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
5108 case DW_OP_GNU_regval_type:
5111 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
5112 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5113 + size_of_uleb128 (o);
5116 case DW_OP_GNU_deref_type:
5119 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
5120 size += 1 + size_of_uleb128 (o);
5123 case DW_OP_GNU_convert:
5124 case DW_OP_GNU_reinterpret:
5125 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
5126 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5130 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
5131 size += size_of_uleb128 (o);
5134 case DW_OP_GNU_parameter_ref:
5144 /* Return the size of a series of location descriptors. */
5146 static unsigned long
5147 size_of_locs (dw_loc_descr_ref loc)
5152 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5153 field, to avoid writing to a PCH file. */
5154 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5156 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5158 size += size_of_loc_descr (l);
5163 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5165 l->dw_loc_addr = size;
5166 size += size_of_loc_descr (l);
5172 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5173 static void get_ref_die_offset_label (char *, dw_die_ref);
5174 static unsigned long int get_ref_die_offset (dw_die_ref);
5175 static void output_loc_sequence (dw_loc_descr_ref, int);
5177 /* Output location description stack opcode's operands (if any).
5178 The for_eh_or_skip parameter controls whether register numbers are
5179 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5180 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5181 info). This should be suppressed for the cases that have not been converted
5182 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5185 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5187 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5188 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5190 switch (loc->dw_loc_opc)
5192 #ifdef DWARF2_DEBUGGING_INFO
5195 dw2_asm_output_data (2, val1->v.val_int, NULL);
5200 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5201 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5203 fputc ('\n', asm_out_file);
5208 dw2_asm_output_data (4, val1->v.val_int, NULL);
5213 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5214 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5216 fputc ('\n', asm_out_file);
5221 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5222 dw2_asm_output_data (8, val1->v.val_int, NULL);
5229 gcc_assert (val1->val_class == dw_val_class_loc);
5230 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5232 dw2_asm_output_data (2, offset, NULL);
5235 case DW_OP_implicit_value:
5236 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5237 switch (val2->val_class)
5239 case dw_val_class_const:
5240 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5242 case dw_val_class_vec:
5244 unsigned int elt_size = val2->v.val_vec.elt_size;
5245 unsigned int len = val2->v.val_vec.length;
5249 if (elt_size > sizeof (HOST_WIDE_INT))
5254 for (i = 0, p = val2->v.val_vec.array;
5257 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5258 "fp or vector constant word %u", i);
5261 case dw_val_class_const_double:
5263 unsigned HOST_WIDE_INT first, second;
5265 if (WORDS_BIG_ENDIAN)
5267 first = val2->v.val_double.high;
5268 second = val2->v.val_double.low;
5272 first = val2->v.val_double.low;
5273 second = val2->v.val_double.high;
5275 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5277 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5281 case dw_val_class_addr:
5282 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5283 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5298 case DW_OP_implicit_value:
5299 /* We currently don't make any attempt to make sure these are
5300 aligned properly like we do for the main unwind info, so
5301 don't support emitting things larger than a byte if we're
5302 only doing unwinding. */
5307 dw2_asm_output_data (1, val1->v.val_int, NULL);
5310 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5313 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5316 dw2_asm_output_data (1, val1->v.val_int, NULL);
5318 case DW_OP_plus_uconst:
5319 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5353 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5357 unsigned r = val1->v.val_unsigned;
5358 if (for_eh_or_skip >= 0)
5359 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5360 gcc_assert (size_of_uleb128 (r)
5361 == size_of_uleb128 (val1->v.val_unsigned));
5362 dw2_asm_output_data_uleb128 (r, NULL);
5366 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5370 unsigned r = val1->v.val_unsigned;
5371 if (for_eh_or_skip >= 0)
5372 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5373 gcc_assert (size_of_uleb128 (r)
5374 == size_of_uleb128 (val1->v.val_unsigned));
5375 dw2_asm_output_data_uleb128 (r, NULL);
5376 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5380 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5382 case DW_OP_bit_piece:
5383 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5384 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5386 case DW_OP_deref_size:
5387 case DW_OP_xderef_size:
5388 dw2_asm_output_data (1, val1->v.val_int, NULL);
5394 if (targetm.asm_out.output_dwarf_dtprel)
5396 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5399 fputc ('\n', asm_out_file);
5406 #ifdef DWARF2_DEBUGGING_INFO
5407 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5414 case DW_OP_GNU_implicit_pointer:
5416 char label[MAX_ARTIFICIAL_LABEL_BYTES
5417 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5418 gcc_assert (val1->val_class == dw_val_class_die_ref);
5419 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5420 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5421 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5425 case DW_OP_GNU_entry_value:
5426 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5427 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5430 case DW_OP_GNU_const_type:
5432 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
5434 dw2_asm_output_data_uleb128 (o, NULL);
5435 switch (val2->val_class)
5437 case dw_val_class_const:
5438 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5439 dw2_asm_output_data (1, l, NULL);
5440 dw2_asm_output_data (l, val2->v.val_int, NULL);
5442 case dw_val_class_vec:
5444 unsigned int elt_size = val2->v.val_vec.elt_size;
5445 unsigned int len = val2->v.val_vec.length;
5450 dw2_asm_output_data (1, l, NULL);
5451 if (elt_size > sizeof (HOST_WIDE_INT))
5456 for (i = 0, p = val2->v.val_vec.array;
5459 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5460 "fp or vector constant word %u", i);
5463 case dw_val_class_const_double:
5465 unsigned HOST_WIDE_INT first, second;
5466 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5468 dw2_asm_output_data (1, 2 * l, NULL);
5469 if (WORDS_BIG_ENDIAN)
5471 first = val2->v.val_double.high;
5472 second = val2->v.val_double.low;
5476 first = val2->v.val_double.low;
5477 second = val2->v.val_double.high;
5479 dw2_asm_output_data (l, first, NULL);
5480 dw2_asm_output_data (l, second, NULL);
5488 case DW_OP_GNU_regval_type:
5490 unsigned r = val1->v.val_unsigned;
5491 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
5493 if (for_eh_or_skip >= 0)
5495 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5496 gcc_assert (size_of_uleb128 (r)
5497 == size_of_uleb128 (val1->v.val_unsigned));
5499 dw2_asm_output_data_uleb128 (r, NULL);
5500 dw2_asm_output_data_uleb128 (o, NULL);
5503 case DW_OP_GNU_deref_type:
5505 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
5507 dw2_asm_output_data (1, val1->v.val_int, NULL);
5508 dw2_asm_output_data_uleb128 (o, NULL);
5511 case DW_OP_GNU_convert:
5512 case DW_OP_GNU_reinterpret:
5513 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
5514 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5517 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
5519 dw2_asm_output_data_uleb128 (o, NULL);
5523 case DW_OP_GNU_parameter_ref:
5526 gcc_assert (val1->val_class == dw_val_class_die_ref);
5527 o = get_ref_die_offset (val1->v.val_die_ref.die);
5528 dw2_asm_output_data (4, o, NULL);
5533 /* Other codes have no operands. */
5538 /* Output a sequence of location operations.
5539 The for_eh_or_skip parameter controls whether register numbers are
5540 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5541 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5542 info). This should be suppressed for the cases that have not been converted
5543 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5546 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5548 for (; loc != NULL; loc = loc->dw_loc_next)
5550 enum dwarf_location_atom opc = loc->dw_loc_opc;
5551 /* Output the opcode. */
5552 if (for_eh_or_skip >= 0
5553 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5555 unsigned r = (opc - DW_OP_breg0);
5556 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5557 gcc_assert (r <= 31);
5558 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5560 else if (for_eh_or_skip >= 0
5561 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5563 unsigned r = (opc - DW_OP_reg0);
5564 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5565 gcc_assert (r <= 31);
5566 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5569 dw2_asm_output_data (1, opc,
5570 "%s", dwarf_stack_op_name (opc));
5572 /* Output the operand(s) (if any). */
5573 output_loc_operands (loc, for_eh_or_skip);
5577 /* Output location description stack opcode's operands (if any).
5578 The output is single bytes on a line, suitable for .cfi_escape. */
5581 output_loc_operands_raw (dw_loc_descr_ref loc)
5583 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5584 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5586 switch (loc->dw_loc_opc)
5589 case DW_OP_implicit_value:
5590 /* We cannot output addresses in .cfi_escape, only bytes. */
5596 case DW_OP_deref_size:
5597 case DW_OP_xderef_size:
5598 fputc (',', asm_out_file);
5599 dw2_asm_output_data_raw (1, val1->v.val_int);
5604 fputc (',', asm_out_file);
5605 dw2_asm_output_data_raw (2, val1->v.val_int);
5610 fputc (',', asm_out_file);
5611 dw2_asm_output_data_raw (4, val1->v.val_int);
5616 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5617 fputc (',', asm_out_file);
5618 dw2_asm_output_data_raw (8, val1->v.val_int);
5626 gcc_assert (val1->val_class == dw_val_class_loc);
5627 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5629 fputc (',', asm_out_file);
5630 dw2_asm_output_data_raw (2, offset);
5636 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5637 gcc_assert (size_of_uleb128 (r)
5638 == size_of_uleb128 (val1->v.val_unsigned));
5639 fputc (',', asm_out_file);
5640 dw2_asm_output_data_uleb128_raw (r);
5645 case DW_OP_plus_uconst:
5647 fputc (',', asm_out_file);
5648 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5651 case DW_OP_bit_piece:
5652 fputc (',', asm_out_file);
5653 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5654 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5691 fputc (',', asm_out_file);
5692 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5697 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5698 gcc_assert (size_of_uleb128 (r)
5699 == size_of_uleb128 (val1->v.val_unsigned));
5700 fputc (',', asm_out_file);
5701 dw2_asm_output_data_uleb128_raw (r);
5702 fputc (',', asm_out_file);
5703 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5707 case DW_OP_GNU_implicit_pointer:
5708 case DW_OP_GNU_entry_value:
5709 case DW_OP_GNU_const_type:
5710 case DW_OP_GNU_regval_type:
5711 case DW_OP_GNU_deref_type:
5712 case DW_OP_GNU_convert:
5713 case DW_OP_GNU_reinterpret:
5714 case DW_OP_GNU_parameter_ref:
5719 /* Other codes have no operands. */
5725 output_loc_sequence_raw (dw_loc_descr_ref loc)
5729 enum dwarf_location_atom opc = loc->dw_loc_opc;
5730 /* Output the opcode. */
5731 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5733 unsigned r = (opc - DW_OP_breg0);
5734 r = DWARF2_FRAME_REG_OUT (r, 1);
5735 gcc_assert (r <= 31);
5736 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5738 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5740 unsigned r = (opc - DW_OP_reg0);
5741 r = DWARF2_FRAME_REG_OUT (r, 1);
5742 gcc_assert (r <= 31);
5743 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5745 /* Output the opcode. */
5746 fprintf (asm_out_file, "%#x", opc);
5747 output_loc_operands_raw (loc);
5749 if (!loc->dw_loc_next)
5751 loc = loc->dw_loc_next;
5753 fputc (',', asm_out_file);
5757 /* This routine will generate the correct assembly data for a location
5758 description based on a cfi entry with a complex address. */
5761 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5763 dw_loc_descr_ref loc;
5766 if (cfi->dw_cfi_opc == DW_CFA_expression)
5769 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5770 dw2_asm_output_data (1, r, NULL);
5771 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5774 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5776 /* Output the size of the block. */
5777 size = size_of_locs (loc);
5778 dw2_asm_output_data_uleb128 (size, NULL);
5780 /* Now output the operations themselves. */
5781 output_loc_sequence (loc, for_eh);
5784 /* Similar, but used for .cfi_escape. */
5787 output_cfa_loc_raw (dw_cfi_ref cfi)
5789 dw_loc_descr_ref loc;
5792 if (cfi->dw_cfi_opc == DW_CFA_expression)
5795 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5796 fprintf (asm_out_file, "%#x,", r);
5797 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5800 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5802 /* Output the size of the block. */
5803 size = size_of_locs (loc);
5804 dw2_asm_output_data_uleb128_raw (size);
5805 fputc (',', asm_out_file);
5807 /* Now output the operations themselves. */
5808 output_loc_sequence_raw (loc);
5811 /* This function builds a dwarf location descriptor sequence from a
5812 dw_cfa_location, adding the given OFFSET to the result of the
5815 static struct dw_loc_descr_struct *
5816 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5818 struct dw_loc_descr_struct *head, *tmp;
5820 offset += cfa->offset;
5824 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5825 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5826 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5827 add_loc_descr (&head, tmp);
5830 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5831 add_loc_descr (&head, tmp);
5835 head = new_reg_loc_descr (cfa->reg, offset);
5840 /* This function builds a dwarf location descriptor sequence for
5841 the address at OFFSET from the CFA when stack is aligned to
5844 static struct dw_loc_descr_struct *
5845 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5847 struct dw_loc_descr_struct *head;
5848 unsigned int dwarf_fp
5849 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5851 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5852 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5854 head = new_reg_loc_descr (dwarf_fp, 0);
5855 add_loc_descr (&head, int_loc_descriptor (alignment));
5856 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5857 loc_descr_plus_const (&head, offset);
5860 head = new_reg_loc_descr (dwarf_fp, offset);
5864 /* This function fills in aa dw_cfa_location structure from a dwarf location
5865 descriptor sequence. */
5868 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5870 struct dw_loc_descr_struct *ptr;
5872 cfa->base_offset = 0;
5876 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5878 enum dwarf_location_atom op = ptr->dw_loc_opc;
5914 cfa->reg = op - DW_OP_reg0;
5917 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5951 cfa->reg = op - DW_OP_breg0;
5952 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5955 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5956 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5961 case DW_OP_plus_uconst:
5962 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5965 internal_error ("DW_LOC_OP %s not implemented",
5966 dwarf_stack_op_name (ptr->dw_loc_opc));
5971 /* And now, the support for symbolic debugging information. */
5973 /* .debug_str support. */
5974 static int output_indirect_string (void **, void *);
5976 static void dwarf2out_init (const char *);
5977 static void dwarf2out_finish (const char *);
5978 static void dwarf2out_assembly_start (void);
5979 static void dwarf2out_define (unsigned int, const char *);
5980 static void dwarf2out_undef (unsigned int, const char *);
5981 static void dwarf2out_start_source_file (unsigned, const char *);
5982 static void dwarf2out_end_source_file (unsigned);
5983 static void dwarf2out_function_decl (tree);
5984 static void dwarf2out_begin_block (unsigned, unsigned);
5985 static void dwarf2out_end_block (unsigned, unsigned);
5986 static bool dwarf2out_ignore_block (const_tree);
5987 static void dwarf2out_global_decl (tree);
5988 static void dwarf2out_type_decl (tree, int);
5989 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5990 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5992 static void dwarf2out_abstract_function (tree);
5993 static void dwarf2out_var_location (rtx);
5994 static void dwarf2out_begin_function (tree);
5995 static void dwarf2out_set_name (tree, tree);
5997 /* The debug hooks structure. */
5999 const struct gcc_debug_hooks dwarf2_debug_hooks =
6003 dwarf2out_assembly_start,
6006 dwarf2out_start_source_file,
6007 dwarf2out_end_source_file,
6008 dwarf2out_begin_block,
6009 dwarf2out_end_block,
6010 dwarf2out_ignore_block,
6011 dwarf2out_source_line,
6012 dwarf2out_begin_prologue,
6013 #if VMS_DEBUGGING_INFO
6014 dwarf2out_vms_end_prologue,
6015 dwarf2out_vms_begin_epilogue,
6017 debug_nothing_int_charstar,
6018 debug_nothing_int_charstar,
6020 dwarf2out_end_epilogue,
6021 dwarf2out_begin_function,
6022 debug_nothing_int, /* end_function */
6023 dwarf2out_function_decl, /* function_decl */
6024 dwarf2out_global_decl,
6025 dwarf2out_type_decl, /* type_decl */
6026 dwarf2out_imported_module_or_decl,
6027 debug_nothing_tree, /* deferred_inline_function */
6028 /* The DWARF 2 backend tries to reduce debugging bloat by not
6029 emitting the abstract description of inline functions until
6030 something tries to reference them. */
6031 dwarf2out_abstract_function, /* outlining_inline_function */
6032 debug_nothing_rtx, /* label */
6033 debug_nothing_int, /* handle_pch */
6034 dwarf2out_var_location,
6035 dwarf2out_switch_text_section,
6037 1, /* start_end_main_source_file */
6038 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
6041 /* NOTE: In the comments in this file, many references are made to
6042 "Debugging Information Entries". This term is abbreviated as `DIE'
6043 throughout the remainder of this file. */
6045 /* An internal representation of the DWARF output is built, and then
6046 walked to generate the DWARF debugging info. The walk of the internal
6047 representation is done after the entire program has been compiled.
6048 The types below are used to describe the internal representation. */
6050 /* Whether to put type DIEs into their own section .debug_types instead
6051 of making them part of the .debug_info section. Only supported for
6052 Dwarf V4 or higher and the user didn't disable them through
6053 -fno-debug-types-section. It is more efficient to put them in a
6054 separate comdat sections since the linker will then be able to
6055 remove duplicates. But not all tools support .debug_types sections
6058 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
6060 /* Various DIE's use offsets relative to the beginning of the
6061 .debug_info section to refer to each other. */
6063 typedef long int dw_offset;
6065 /* Define typedefs here to avoid circular dependencies. */
6067 typedef struct dw_attr_struct *dw_attr_ref;
6068 typedef struct dw_line_info_struct *dw_line_info_ref;
6069 typedef struct pubname_struct *pubname_ref;
6070 typedef struct dw_ranges_struct *dw_ranges_ref;
6071 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
6072 typedef struct comdat_type_struct *comdat_type_node_ref;
6074 /* The entries in the line_info table more-or-less mirror the opcodes
6075 that are used in the real dwarf line table. Arrays of these entries
6076 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
6079 enum dw_line_info_opcode {
6080 /* Emit DW_LNE_set_address; the operand is the label index. */
6083 /* Emit a row to the matrix with the given line. This may be done
6084 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
6088 /* Emit a DW_LNS_set_file. */
6091 /* Emit a DW_LNS_set_column. */
6094 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
6097 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
6098 LI_set_prologue_end,
6099 LI_set_epilogue_begin,
6101 /* Emit a DW_LNE_set_discriminator. */
6102 LI_set_discriminator
6105 typedef struct GTY(()) dw_line_info_struct {
6106 enum dw_line_info_opcode opcode;
6108 } dw_line_info_entry;
6110 DEF_VEC_O(dw_line_info_entry);
6111 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
6113 typedef struct GTY(()) dw_line_info_table_struct {
6114 /* The label that marks the end of this section. */
6115 const char *end_label;
6117 /* The values for the last row of the matrix, as collected in the table.
6118 These are used to minimize the changes to the next row. */
6119 unsigned int file_num;
6120 unsigned int line_num;
6121 unsigned int column_num;
6126 VEC(dw_line_info_entry, gc) *entries;
6127 } dw_line_info_table;
6129 typedef dw_line_info_table *dw_line_info_table_p;
6131 DEF_VEC_P(dw_line_info_table_p);
6132 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
6134 /* Each DIE attribute has a field specifying the attribute kind,
6135 a link to the next attribute in the chain, and an attribute value.
6136 Attributes are typically linked below the DIE they modify. */
6138 typedef struct GTY(()) dw_attr_struct {
6139 enum dwarf_attribute dw_attr;
6140 dw_val_node dw_attr_val;
6144 DEF_VEC_O(dw_attr_node);
6145 DEF_VEC_ALLOC_O(dw_attr_node,gc);
6147 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
6148 The children of each node form a circular list linked by
6149 die_sib. die_child points to the node *before* the "first" child node. */
6151 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
6152 union die_symbol_or_type_node
6154 char * GTY ((tag ("0"))) die_symbol;
6155 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
6157 GTY ((desc ("use_debug_types"))) die_id;
6158 VEC(dw_attr_node,gc) * die_attr;
6159 dw_die_ref die_parent;
6160 dw_die_ref die_child;
6162 dw_die_ref die_definition; /* ref from a specification to its definition */
6163 dw_offset die_offset;
6164 unsigned long die_abbrev;
6166 /* Die is used and must not be pruned as unused. */
6167 int die_perennial_p;
6168 unsigned int decl_id;
6169 enum dwarf_tag die_tag;
6173 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
6174 #define FOR_EACH_CHILD(die, c, expr) do { \
6175 c = die->die_child; \
6179 } while (c != die->die_child); \
6182 /* The pubname structure */
6184 typedef struct GTY(()) pubname_struct {
6190 DEF_VEC_O(pubname_entry);
6191 DEF_VEC_ALLOC_O(pubname_entry, gc);
6193 struct GTY(()) dw_ranges_struct {
6194 /* If this is positive, it's a block number, otherwise it's a
6195 bitwise-negated index into dw_ranges_by_label. */
6199 /* A structure to hold a macinfo entry. */
6201 typedef struct GTY(()) macinfo_struct {
6202 unsigned HOST_WIDE_INT code;
6203 unsigned HOST_WIDE_INT lineno;
6208 DEF_VEC_O(macinfo_entry);
6209 DEF_VEC_ALLOC_O(macinfo_entry, gc);
6211 struct GTY(()) dw_ranges_by_label_struct {
6216 /* The comdat type node structure. */
6217 typedef struct GTY(()) comdat_type_struct
6219 dw_die_ref root_die;
6220 dw_die_ref type_die;
6221 char signature[DWARF_TYPE_SIGNATURE_SIZE];
6222 struct comdat_type_struct *next;
6226 /* The limbo die list structure. */
6227 typedef struct GTY(()) limbo_die_struct {
6230 struct limbo_die_struct *next;
6234 typedef struct skeleton_chain_struct
6238 struct skeleton_chain_struct *parent;
6240 skeleton_chain_node;
6242 /* How to start an assembler comment. */
6243 #ifndef ASM_COMMENT_START
6244 #define ASM_COMMENT_START ";#"
6247 /* Define a macro which returns nonzero for a TYPE_DECL which was
6248 implicitly generated for a type.
6250 Note that, unlike the C front-end (which generates a NULL named
6251 TYPE_DECL node for each complete tagged type, each array type,
6252 and each function type node created) the C++ front-end generates
6253 a _named_ TYPE_DECL node for each tagged type node created.
6254 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
6255 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
6256 front-end, but for each type, tagged or not. */
6258 #define TYPE_DECL_IS_STUB(decl) \
6259 (DECL_NAME (decl) == NULL_TREE \
6260 || (DECL_ARTIFICIAL (decl) \
6261 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
6262 /* This is necessary for stub decls that \
6263 appear in nested inline functions. */ \
6264 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6265 && (decl_ultimate_origin (decl) \
6266 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6268 /* Information concerning the compilation unit's programming
6269 language, and compiler version. */
6271 /* Fixed size portion of the DWARF compilation unit header. */
6272 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6273 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6275 /* Fixed size portion of the DWARF comdat type unit header. */
6276 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6277 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6278 + DWARF_OFFSET_SIZE)
6280 /* Fixed size portion of public names info. */
6281 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6283 /* Fixed size portion of the address range info. */
6284 #define DWARF_ARANGES_HEADER_SIZE \
6285 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6286 DWARF2_ADDR_SIZE * 2) \
6287 - DWARF_INITIAL_LENGTH_SIZE)
6289 /* Size of padding portion in the address range info. It must be
6290 aligned to twice the pointer size. */
6291 #define DWARF_ARANGES_PAD_SIZE \
6292 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6293 DWARF2_ADDR_SIZE * 2) \
6294 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6296 /* Use assembler line directives if available. */
6297 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6298 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6299 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6301 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6305 /* Minimum line offset in a special line info. opcode.
6306 This value was chosen to give a reasonable range of values. */
6307 #define DWARF_LINE_BASE -10
6309 /* First special line opcode - leave room for the standard opcodes. */
6310 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
6312 /* Range of line offsets in a special line info. opcode. */
6313 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6315 /* Flag that indicates the initial value of the is_stmt_start flag.
6316 In the present implementation, we do not mark any lines as
6317 the beginning of a source statement, because that information
6318 is not made available by the GCC front-end. */
6319 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6321 /* Maximum number of operations per instruction bundle. */
6322 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6323 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6326 /* This location is used by calc_die_sizes() to keep track
6327 the offset of each DIE within the .debug_info section. */
6328 static unsigned long next_die_offset;
6330 /* Record the root of the DIE's built for the current compilation unit. */
6331 static GTY(()) dw_die_ref single_comp_unit_die;
6333 /* A list of type DIEs that have been separated into comdat sections. */
6334 static GTY(()) comdat_type_node *comdat_type_list;
6336 /* A list of DIEs with a NULL parent waiting to be relocated. */
6337 static GTY(()) limbo_die_node *limbo_die_list;
6339 /* A list of DIEs for which we may have to generate
6340 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6341 static GTY(()) limbo_die_node *deferred_asm_name;
6343 /* Filenames referenced by this compilation unit. */
6344 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6346 /* A hash table of references to DIE's that describe declarations.
6347 The key is a DECL_UID() which is a unique number identifying each decl. */
6348 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6350 /* A hash table of references to DIE's that describe COMMON blocks.
6351 The key is DECL_UID() ^ die_parent. */
6352 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6354 typedef struct GTY(()) die_arg_entry_struct {
6359 DEF_VEC_O(die_arg_entry);
6360 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6362 /* Node of the variable location list. */
6363 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6364 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6365 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6366 in mode of the EXPR_LIST node and first EXPR_LIST operand
6367 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6368 location or NULL for padding. For larger bitsizes,
6369 mode is 0 and first operand is a CONCAT with bitsize
6370 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6371 NULL as second operand. */
6373 const char * GTY (()) label;
6374 struct var_loc_node * GTY (()) next;
6377 /* Variable location list. */
6378 struct GTY (()) var_loc_list_def {
6379 struct var_loc_node * GTY (()) first;
6381 /* Pointer to the last but one or last element of the
6382 chained list. If the list is empty, both first and
6383 last are NULL, if the list contains just one node
6384 or the last node certainly is not redundant, it points
6385 to the last node, otherwise points to the last but one.
6386 Do not mark it for GC because it is marked through the chain. */
6387 struct var_loc_node * GTY ((skip ("%h"))) last;
6389 /* Pointer to the last element before section switch,
6390 if NULL, either sections weren't switched or first
6391 is after section switch. */
6392 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
6394 /* DECL_UID of the variable decl. */
6395 unsigned int decl_id;
6397 typedef struct var_loc_list_def var_loc_list;
6399 /* Call argument location list. */
6400 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6401 rtx GTY (()) call_arg_loc_note;
6402 const char * GTY (()) label;
6403 tree GTY (()) block;
6405 rtx GTY (()) symbol_ref;
6406 struct call_arg_loc_node * GTY (()) next;
6410 /* Table of decl location linked lists. */
6411 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6413 /* Head and tail of call_arg_loc chain. */
6414 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6415 static struct call_arg_loc_node *call_arg_loc_last;
6417 /* Number of call sites in the current function. */
6418 static int call_site_count = -1;
6419 /* Number of tail call sites in the current function. */
6420 static int tail_call_site_count = -1;
6422 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6424 static VEC (dw_die_ref, heap) *block_map;
6426 /* A cached location list. */
6427 struct GTY (()) cached_dw_loc_list_def {
6428 /* The DECL_UID of the decl that this entry describes. */
6429 unsigned int decl_id;
6431 /* The cached location list. */
6432 dw_loc_list_ref loc_list;
6434 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
6436 /* Table of cached location lists. */
6437 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
6439 /* A pointer to the base of a list of references to DIE's that
6440 are uniquely identified by their tag, presence/absence of
6441 children DIE's, and list of attribute/value pairs. */
6442 static GTY((length ("abbrev_die_table_allocated")))
6443 dw_die_ref *abbrev_die_table;
6445 /* Number of elements currently allocated for abbrev_die_table. */
6446 static GTY(()) unsigned abbrev_die_table_allocated;
6448 /* Number of elements in type_die_table currently in use. */
6449 static GTY(()) unsigned abbrev_die_table_in_use;
6451 /* Size (in elements) of increments by which we may expand the
6452 abbrev_die_table. */
6453 #define ABBREV_DIE_TABLE_INCREMENT 256
6455 /* A global counter for generating labels for line number data. */
6456 static unsigned int line_info_label_num;
6458 /* The current table to which we should emit line number information
6459 for the current function. This will be set up at the beginning of
6460 assembly for the function. */
6461 static dw_line_info_table *cur_line_info_table;
6463 /* The two default tables of line number info. */
6464 static GTY(()) dw_line_info_table *text_section_line_info;
6465 static GTY(()) dw_line_info_table *cold_text_section_line_info;
6467 /* The set of all non-default tables of line number info. */
6468 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
6470 /* A flag to tell pubnames/types export if there is an info section to
6472 static bool info_section_emitted;
6474 /* A pointer to the base of a table that contains a list of publicly
6475 accessible names. */
6476 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6478 /* A pointer to the base of a table that contains a list of publicly
6479 accessible types. */
6480 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6482 /* A pointer to the base of a table that contains a list of macro
6483 defines/undefines (and file start/end markers). */
6484 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6486 /* Array of dies for which we should generate .debug_ranges info. */
6487 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6489 /* Number of elements currently allocated for ranges_table. */
6490 static GTY(()) unsigned ranges_table_allocated;
6492 /* Number of elements in ranges_table currently in use. */
6493 static GTY(()) unsigned ranges_table_in_use;
6495 /* Array of pairs of labels referenced in ranges_table. */
6496 static GTY ((length ("ranges_by_label_allocated")))
6497 dw_ranges_by_label_ref ranges_by_label;
6499 /* Number of elements currently allocated for ranges_by_label. */
6500 static GTY(()) unsigned ranges_by_label_allocated;
6502 /* Number of elements in ranges_by_label currently in use. */
6503 static GTY(()) unsigned ranges_by_label_in_use;
6505 /* Size (in elements) of increments by which we may expand the
6507 #define RANGES_TABLE_INCREMENT 64
6509 /* Whether we have location lists that need outputting */
6510 static GTY(()) bool have_location_lists;
6512 /* Unique label counter. */
6513 static GTY(()) unsigned int loclabel_num;
6515 /* Unique label counter for point-of-call tables. */
6516 static GTY(()) unsigned int poc_label_num;
6518 /* Record whether the function being analyzed contains inlined functions. */
6519 static int current_function_has_inlines;
6521 /* The last file entry emitted by maybe_emit_file(). */
6522 static GTY(()) struct dwarf_file_data * last_emitted_file;
6524 /* Number of internal labels generated by gen_internal_sym(). */
6525 static GTY(()) int label_num;
6527 /* Cached result of previous call to lookup_filename. */
6528 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6530 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6532 /* Instances of generic types for which we need to generate debug
6533 info that describe their generic parameters and arguments. That
6534 generation needs to happen once all types are properly laid out so
6535 we do it at the end of compilation. */
6536 static GTY(()) VEC(tree,gc) *generic_type_instances;
6538 /* Offset from the "steady-state frame pointer" to the frame base,
6539 within the current function. */
6540 static HOST_WIDE_INT frame_pointer_fb_offset;
6541 static bool frame_pointer_fb_offset_valid;
6543 static VEC (dw_die_ref, heap) *base_types;
6545 /* Forward declarations for functions defined in this file. */
6547 static int is_pseudo_reg (const_rtx);
6548 static tree type_main_variant (tree);
6549 static int is_tagged_type (const_tree);
6550 static const char *dwarf_tag_name (unsigned);
6551 static const char *dwarf_attr_name (unsigned);
6552 static const char *dwarf_form_name (unsigned);
6553 static tree decl_ultimate_origin (const_tree);
6554 static tree decl_class_context (tree);
6555 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6556 static inline enum dw_val_class AT_class (dw_attr_ref);
6557 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6558 static inline unsigned AT_flag (dw_attr_ref);
6559 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6560 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6561 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6562 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6563 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6564 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6565 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6566 unsigned int, unsigned char *);
6567 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6568 static hashval_t debug_str_do_hash (const void *);
6569 static int debug_str_eq (const void *, const void *);
6570 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6571 static inline const char *AT_string (dw_attr_ref);
6572 static enum dwarf_form AT_string_form (dw_attr_ref);
6573 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6574 static void add_AT_specification (dw_die_ref, dw_die_ref);
6575 static inline dw_die_ref AT_ref (dw_attr_ref);
6576 static inline int AT_ref_external (dw_attr_ref);
6577 static inline void set_AT_ref_external (dw_attr_ref, int);
6578 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6579 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6580 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6581 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6583 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6584 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6585 static inline rtx AT_addr (dw_attr_ref);
6586 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6587 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6588 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6589 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6590 unsigned HOST_WIDE_INT);
6591 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6593 static inline const char *AT_lbl (dw_attr_ref);
6594 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6595 static const char *get_AT_low_pc (dw_die_ref);
6596 static const char *get_AT_hi_pc (dw_die_ref);
6597 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6598 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6599 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6600 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6601 static bool is_cxx (void);
6602 static bool is_fortran (void);
6603 static bool is_ada (void);
6604 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6605 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6606 static void add_child_die (dw_die_ref, dw_die_ref);
6607 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6608 static dw_die_ref lookup_type_die (tree);
6609 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6610 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6611 static void equate_type_number_to_die (tree, dw_die_ref);
6612 static hashval_t decl_die_table_hash (const void *);
6613 static int decl_die_table_eq (const void *, const void *);
6614 static dw_die_ref lookup_decl_die (tree);
6615 static hashval_t common_block_die_table_hash (const void *);
6616 static int common_block_die_table_eq (const void *, const void *);
6617 static hashval_t decl_loc_table_hash (const void *);
6618 static int decl_loc_table_eq (const void *, const void *);
6619 static var_loc_list *lookup_decl_loc (const_tree);
6620 static void equate_decl_number_to_die (tree, dw_die_ref);
6621 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6622 static void print_spaces (FILE *);
6623 static void print_die (dw_die_ref, FILE *);
6624 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6625 static dw_die_ref pop_compile_unit (dw_die_ref);
6626 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6627 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6628 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6629 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6630 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6631 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6632 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6633 struct md5_ctx *, int *);
6634 struct checksum_attributes;
6635 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6636 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6637 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6638 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6639 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6640 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6641 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6642 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6643 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6644 static void compute_section_prefix (dw_die_ref);
6645 static int is_type_die (dw_die_ref);
6646 static int is_comdat_die (dw_die_ref);
6647 static int is_symbol_die (dw_die_ref);
6648 static void assign_symbol_names (dw_die_ref);
6649 static void break_out_includes (dw_die_ref);
6650 static int is_declaration_die (dw_die_ref);
6651 static int should_move_die_to_comdat (dw_die_ref);
6652 static dw_die_ref clone_as_declaration (dw_die_ref);
6653 static dw_die_ref clone_die (dw_die_ref);
6654 static dw_die_ref clone_tree (dw_die_ref);
6655 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6656 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6657 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6658 static dw_die_ref generate_skeleton (dw_die_ref);
6659 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6661 static void break_out_comdat_types (dw_die_ref);
6662 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6663 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6664 static void copy_decls_for_unworthy_types (dw_die_ref);
6666 static hashval_t htab_cu_hash (const void *);
6667 static int htab_cu_eq (const void *, const void *);
6668 static void htab_cu_del (void *);
6669 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6670 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6671 static void add_sibling_attributes (dw_die_ref);
6672 static void build_abbrev_table (dw_die_ref);
6673 static void output_location_lists (dw_die_ref);
6674 static int constant_size (unsigned HOST_WIDE_INT);
6675 static unsigned long size_of_die (dw_die_ref);
6676 static void calc_die_sizes (dw_die_ref);
6677 static void calc_base_type_die_sizes (void);
6678 static void mark_dies (dw_die_ref);
6679 static void unmark_dies (dw_die_ref);
6680 static void unmark_all_dies (dw_die_ref);
6681 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6682 static unsigned long size_of_aranges (void);
6683 static enum dwarf_form value_format (dw_attr_ref);
6684 static void output_value_format (dw_attr_ref);
6685 static void output_abbrev_section (void);
6686 static void output_die_symbol (dw_die_ref);
6687 static void output_die (dw_die_ref);
6688 static void output_compilation_unit_header (void);
6689 static void output_comp_unit (dw_die_ref, int);
6690 static void output_comdat_type_unit (comdat_type_node *);
6691 static const char *dwarf2_name (tree, int);
6692 static void add_pubname (tree, dw_die_ref);
6693 static void add_pubname_string (const char *, dw_die_ref);
6694 static void add_pubtype (tree, dw_die_ref);
6695 static void output_pubnames (VEC (pubname_entry,gc) *);
6696 static void output_aranges (unsigned long);
6697 static unsigned int add_ranges_num (int);
6698 static unsigned int add_ranges (const_tree);
6699 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6701 static void output_ranges (void);
6702 static dw_line_info_table *new_line_info_table (void);
6703 static void output_line_info (void);
6704 static void output_file_names (void);
6705 static dw_die_ref base_type_die (tree);
6706 static int is_base_type (tree);
6707 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6708 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6709 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6710 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6711 static int type_is_enum (const_tree);
6712 static unsigned int dbx_reg_number (const_rtx);
6713 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6714 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6715 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6716 enum var_init_status);
6717 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6718 enum var_init_status);
6719 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6720 enum var_init_status);
6721 static int is_based_loc (const_rtx);
6722 static int resolve_one_addr (rtx *, void *);
6723 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6724 enum var_init_status);
6725 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6726 enum var_init_status);
6727 static dw_loc_list_ref loc_list_from_tree (tree, int);
6728 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6729 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6730 static tree field_type (const_tree);
6731 static unsigned int simple_type_align_in_bits (const_tree);
6732 static unsigned int simple_decl_align_in_bits (const_tree);
6733 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6734 static HOST_WIDE_INT field_byte_offset (const_tree);
6735 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6737 static void add_data_member_location_attribute (dw_die_ref, tree);
6738 static bool add_const_value_attribute (dw_die_ref, rtx);
6739 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6740 static void insert_double (double_int, unsigned char *);
6741 static void insert_float (const_rtx, unsigned char *);
6742 static rtx rtl_for_decl_location (tree);
6743 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
6744 enum dwarf_attribute);
6745 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6746 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6747 static void add_name_attribute (dw_die_ref, const char *);
6748 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
6749 static void add_comp_dir_attribute (dw_die_ref);
6750 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6751 static void add_subscript_info (dw_die_ref, tree, bool);
6752 static void add_byte_size_attribute (dw_die_ref, tree);
6753 static void add_bit_offset_attribute (dw_die_ref, tree);
6754 static void add_bit_size_attribute (dw_die_ref, tree);
6755 static void add_prototyped_attribute (dw_die_ref, tree);
6756 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6757 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6758 static void add_src_coords_attributes (dw_die_ref, tree);
6759 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6760 static void push_decl_scope (tree);
6761 static void pop_decl_scope (void);
6762 static dw_die_ref scope_die_for (tree, dw_die_ref);
6763 static inline int local_scope_p (dw_die_ref);
6764 static inline int class_scope_p (dw_die_ref);
6765 static inline int class_or_namespace_scope_p (dw_die_ref);
6766 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6767 static void add_calling_convention_attribute (dw_die_ref, tree);
6768 static const char *type_tag (const_tree);
6769 static tree member_declared_type (const_tree);
6771 static const char *decl_start_label (tree);
6773 static void gen_array_type_die (tree, dw_die_ref);
6774 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6776 static void gen_entry_point_die (tree, dw_die_ref);
6778 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6779 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6780 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6781 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6782 static void gen_formal_types_die (tree, dw_die_ref);
6783 static void gen_subprogram_die (tree, dw_die_ref);
6784 static void gen_variable_die (tree, tree, dw_die_ref);
6785 static void gen_const_die (tree, dw_die_ref);
6786 static void gen_label_die (tree, dw_die_ref);
6787 static void gen_lexical_block_die (tree, dw_die_ref, int);
6788 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6789 static void gen_field_die (tree, dw_die_ref);
6790 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6791 static dw_die_ref gen_compile_unit_die (const char *);
6792 static void gen_inheritance_die (tree, tree, dw_die_ref);
6793 static void gen_member_die (tree, dw_die_ref);
6794 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6795 enum debug_info_usage);
6796 static void gen_subroutine_type_die (tree, dw_die_ref);
6797 static void gen_typedef_die (tree, dw_die_ref);
6798 static void gen_type_die (tree, dw_die_ref);
6799 static void gen_block_die (tree, dw_die_ref, int);
6800 static void decls_for_scope (tree, dw_die_ref, int);
6801 static inline int is_redundant_typedef (const_tree);
6802 static bool is_naming_typedef_decl (const_tree);
6803 static inline dw_die_ref get_context_die (tree);
6804 static void gen_namespace_die (tree, dw_die_ref);
6805 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6806 static dw_die_ref force_decl_die (tree);
6807 static dw_die_ref force_type_die (tree);
6808 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6809 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6810 static struct dwarf_file_data * lookup_filename (const char *);
6811 static void retry_incomplete_types (void);
6812 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6813 static void gen_generic_params_dies (tree);
6814 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6815 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6816 static void splice_child_die (dw_die_ref, dw_die_ref);
6817 static int file_info_cmp (const void *, const void *);
6818 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6819 const char *, const char *);
6820 static void output_loc_list (dw_loc_list_ref);
6821 static char *gen_internal_sym (const char *);
6823 static void prune_unmark_dies (dw_die_ref);
6824 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6825 static void prune_unused_types_mark (dw_die_ref, int);
6826 static void prune_unused_types_walk (dw_die_ref);
6827 static void prune_unused_types_walk_attribs (dw_die_ref);
6828 static void prune_unused_types_prune (dw_die_ref);
6829 static void prune_unused_types (void);
6830 static int maybe_emit_file (struct dwarf_file_data *fd);
6831 static inline const char *AT_vms_delta1 (dw_attr_ref);
6832 static inline const char *AT_vms_delta2 (dw_attr_ref);
6833 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6834 const char *, const char *);
6835 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6836 static void gen_remaining_tmpl_value_param_die_attribute (void);
6837 static bool generic_type_p (tree);
6838 static void schedule_generic_params_dies_gen (tree t);
6839 static void gen_scheduled_generic_parms_dies (void);
6841 /* Section names used to hold DWARF debugging information. */
6842 #ifndef DEBUG_INFO_SECTION
6843 #define DEBUG_INFO_SECTION ".debug_info"
6845 #ifndef DEBUG_ABBREV_SECTION
6846 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6848 #ifndef DEBUG_ARANGES_SECTION
6849 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6851 #ifndef DEBUG_MACINFO_SECTION
6852 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6854 #ifndef DEBUG_LINE_SECTION
6855 #define DEBUG_LINE_SECTION ".debug_line"
6857 #ifndef DEBUG_LOC_SECTION
6858 #define DEBUG_LOC_SECTION ".debug_loc"
6860 #ifndef DEBUG_PUBNAMES_SECTION
6861 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6863 #ifndef DEBUG_PUBTYPES_SECTION
6864 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6866 #ifndef DEBUG_STR_SECTION
6867 #define DEBUG_STR_SECTION ".debug_str"
6869 #ifndef DEBUG_RANGES_SECTION
6870 #define DEBUG_RANGES_SECTION ".debug_ranges"
6873 /* Standard ELF section names for compiled code and data. */
6874 #ifndef TEXT_SECTION_NAME
6875 #define TEXT_SECTION_NAME ".text"
6878 /* Section flags for .debug_str section. */
6879 #define DEBUG_STR_SECTION_FLAGS \
6880 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6881 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6884 /* Labels we insert at beginning sections we can reference instead of
6885 the section names themselves. */
6887 #ifndef TEXT_SECTION_LABEL
6888 #define TEXT_SECTION_LABEL "Ltext"
6890 #ifndef COLD_TEXT_SECTION_LABEL
6891 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6893 #ifndef DEBUG_LINE_SECTION_LABEL
6894 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6896 #ifndef DEBUG_INFO_SECTION_LABEL
6897 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6899 #ifndef DEBUG_ABBREV_SECTION_LABEL
6900 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6902 #ifndef DEBUG_LOC_SECTION_LABEL
6903 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6905 #ifndef DEBUG_RANGES_SECTION_LABEL
6906 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6908 #ifndef DEBUG_MACINFO_SECTION_LABEL
6909 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6913 /* Definitions of defaults for formats and names of various special
6914 (artificial) labels which may be generated within this file (when the -g
6915 options is used and DWARF2_DEBUGGING_INFO is in effect.
6916 If necessary, these may be overridden from within the tm.h file, but
6917 typically, overriding these defaults is unnecessary. */
6919 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6920 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6921 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6922 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6923 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6924 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6925 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6926 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6927 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6928 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6930 #ifndef TEXT_END_LABEL
6931 #define TEXT_END_LABEL "Letext"
6933 #ifndef COLD_END_LABEL
6934 #define COLD_END_LABEL "Letext_cold"
6936 #ifndef BLOCK_BEGIN_LABEL
6937 #define BLOCK_BEGIN_LABEL "LBB"
6939 #ifndef BLOCK_END_LABEL
6940 #define BLOCK_END_LABEL "LBE"
6942 #ifndef LINE_CODE_LABEL
6943 #define LINE_CODE_LABEL "LM"
6947 /* Return the root of the DIE's built for the current compilation unit. */
6949 comp_unit_die (void)
6951 if (!single_comp_unit_die)
6952 single_comp_unit_die = gen_compile_unit_die (NULL);
6953 return single_comp_unit_die;
6956 /* We allow a language front-end to designate a function that is to be
6957 called to "demangle" any name before it is put into a DIE. */
6959 static const char *(*demangle_name_func) (const char *);
6962 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6964 demangle_name_func = func;
6967 /* Test if rtl node points to a pseudo register. */
6970 is_pseudo_reg (const_rtx rtl)
6972 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6973 || (GET_CODE (rtl) == SUBREG
6974 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6977 /* Return a reference to a type, with its const and volatile qualifiers
6981 type_main_variant (tree type)
6983 type = TYPE_MAIN_VARIANT (type);
6985 /* ??? There really should be only one main variant among any group of
6986 variants of a given type (and all of the MAIN_VARIANT values for all
6987 members of the group should point to that one type) but sometimes the C
6988 front-end messes this up for array types, so we work around that bug
6990 if (TREE_CODE (type) == ARRAY_TYPE)
6991 while (type != TYPE_MAIN_VARIANT (type))
6992 type = TYPE_MAIN_VARIANT (type);
6997 /* Return nonzero if the given type node represents a tagged type. */
7000 is_tagged_type (const_tree type)
7002 enum tree_code code = TREE_CODE (type);
7004 return (code == RECORD_TYPE || code == UNION_TYPE
7005 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
7008 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
7011 get_ref_die_offset_label (char *label, dw_die_ref ref)
7013 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
7016 /* Return die_offset of a DIE reference to a base type. */
7018 static unsigned long int
7019 get_base_type_offset (dw_die_ref ref)
7021 if (ref->die_offset)
7022 return ref->die_offset;
7023 if (comp_unit_die ()->die_abbrev)
7025 calc_base_type_die_sizes ();
7026 gcc_assert (ref->die_offset);
7028 return ref->die_offset;
7031 /* Return die_offset of a DIE reference other than base type. */
7033 static unsigned long int
7034 get_ref_die_offset (dw_die_ref ref)
7036 gcc_assert (ref->die_offset);
7037 return ref->die_offset;
7040 /* Convert a DIE tag into its string name. */
7043 dwarf_tag_name (unsigned int tag)
7047 case DW_TAG_padding:
7048 return "DW_TAG_padding";
7049 case DW_TAG_array_type:
7050 return "DW_TAG_array_type";
7051 case DW_TAG_class_type:
7052 return "DW_TAG_class_type";
7053 case DW_TAG_entry_point:
7054 return "DW_TAG_entry_point";
7055 case DW_TAG_enumeration_type:
7056 return "DW_TAG_enumeration_type";
7057 case DW_TAG_formal_parameter:
7058 return "DW_TAG_formal_parameter";
7059 case DW_TAG_imported_declaration:
7060 return "DW_TAG_imported_declaration";
7062 return "DW_TAG_label";
7063 case DW_TAG_lexical_block:
7064 return "DW_TAG_lexical_block";
7066 return "DW_TAG_member";
7067 case DW_TAG_pointer_type:
7068 return "DW_TAG_pointer_type";
7069 case DW_TAG_reference_type:
7070 return "DW_TAG_reference_type";
7071 case DW_TAG_compile_unit:
7072 return "DW_TAG_compile_unit";
7073 case DW_TAG_string_type:
7074 return "DW_TAG_string_type";
7075 case DW_TAG_structure_type:
7076 return "DW_TAG_structure_type";
7077 case DW_TAG_subroutine_type:
7078 return "DW_TAG_subroutine_type";
7079 case DW_TAG_typedef:
7080 return "DW_TAG_typedef";
7081 case DW_TAG_union_type:
7082 return "DW_TAG_union_type";
7083 case DW_TAG_unspecified_parameters:
7084 return "DW_TAG_unspecified_parameters";
7085 case DW_TAG_variant:
7086 return "DW_TAG_variant";
7087 case DW_TAG_common_block:
7088 return "DW_TAG_common_block";
7089 case DW_TAG_common_inclusion:
7090 return "DW_TAG_common_inclusion";
7091 case DW_TAG_inheritance:
7092 return "DW_TAG_inheritance";
7093 case DW_TAG_inlined_subroutine:
7094 return "DW_TAG_inlined_subroutine";
7096 return "DW_TAG_module";
7097 case DW_TAG_ptr_to_member_type:
7098 return "DW_TAG_ptr_to_member_type";
7099 case DW_TAG_set_type:
7100 return "DW_TAG_set_type";
7101 case DW_TAG_subrange_type:
7102 return "DW_TAG_subrange_type";
7103 case DW_TAG_with_stmt:
7104 return "DW_TAG_with_stmt";
7105 case DW_TAG_access_declaration:
7106 return "DW_TAG_access_declaration";
7107 case DW_TAG_base_type:
7108 return "DW_TAG_base_type";
7109 case DW_TAG_catch_block:
7110 return "DW_TAG_catch_block";
7111 case DW_TAG_const_type:
7112 return "DW_TAG_const_type";
7113 case DW_TAG_constant:
7114 return "DW_TAG_constant";
7115 case DW_TAG_enumerator:
7116 return "DW_TAG_enumerator";
7117 case DW_TAG_file_type:
7118 return "DW_TAG_file_type";
7120 return "DW_TAG_friend";
7121 case DW_TAG_namelist:
7122 return "DW_TAG_namelist";
7123 case DW_TAG_namelist_item:
7124 return "DW_TAG_namelist_item";
7125 case DW_TAG_packed_type:
7126 return "DW_TAG_packed_type";
7127 case DW_TAG_subprogram:
7128 return "DW_TAG_subprogram";
7129 case DW_TAG_template_type_param:
7130 return "DW_TAG_template_type_param";
7131 case DW_TAG_template_value_param:
7132 return "DW_TAG_template_value_param";
7133 case DW_TAG_thrown_type:
7134 return "DW_TAG_thrown_type";
7135 case DW_TAG_try_block:
7136 return "DW_TAG_try_block";
7137 case DW_TAG_variant_part:
7138 return "DW_TAG_variant_part";
7139 case DW_TAG_variable:
7140 return "DW_TAG_variable";
7141 case DW_TAG_volatile_type:
7142 return "DW_TAG_volatile_type";
7143 case DW_TAG_dwarf_procedure:
7144 return "DW_TAG_dwarf_procedure";
7145 case DW_TAG_restrict_type:
7146 return "DW_TAG_restrict_type";
7147 case DW_TAG_interface_type:
7148 return "DW_TAG_interface_type";
7149 case DW_TAG_namespace:
7150 return "DW_TAG_namespace";
7151 case DW_TAG_imported_module:
7152 return "DW_TAG_imported_module";
7153 case DW_TAG_unspecified_type:
7154 return "DW_TAG_unspecified_type";
7155 case DW_TAG_partial_unit:
7156 return "DW_TAG_partial_unit";
7157 case DW_TAG_imported_unit:
7158 return "DW_TAG_imported_unit";
7159 case DW_TAG_condition:
7160 return "DW_TAG_condition";
7161 case DW_TAG_shared_type:
7162 return "DW_TAG_shared_type";
7163 case DW_TAG_type_unit:
7164 return "DW_TAG_type_unit";
7165 case DW_TAG_rvalue_reference_type:
7166 return "DW_TAG_rvalue_reference_type";
7167 case DW_TAG_template_alias:
7168 return "DW_TAG_template_alias";
7169 case DW_TAG_GNU_template_parameter_pack:
7170 return "DW_TAG_GNU_template_parameter_pack";
7171 case DW_TAG_GNU_formal_parameter_pack:
7172 return "DW_TAG_GNU_formal_parameter_pack";
7173 case DW_TAG_MIPS_loop:
7174 return "DW_TAG_MIPS_loop";
7175 case DW_TAG_format_label:
7176 return "DW_TAG_format_label";
7177 case DW_TAG_function_template:
7178 return "DW_TAG_function_template";
7179 case DW_TAG_class_template:
7180 return "DW_TAG_class_template";
7181 case DW_TAG_GNU_BINCL:
7182 return "DW_TAG_GNU_BINCL";
7183 case DW_TAG_GNU_EINCL:
7184 return "DW_TAG_GNU_EINCL";
7185 case DW_TAG_GNU_template_template_param:
7186 return "DW_TAG_GNU_template_template_param";
7187 case DW_TAG_GNU_call_site:
7188 return "DW_TAG_GNU_call_site";
7189 case DW_TAG_GNU_call_site_parameter:
7190 return "DW_TAG_GNU_call_site_parameter";
7192 return "DW_TAG_<unknown>";
7196 /* Convert a DWARF attribute code into its string name. */
7199 dwarf_attr_name (unsigned int attr)
7204 return "DW_AT_sibling";
7205 case DW_AT_location:
7206 return "DW_AT_location";
7208 return "DW_AT_name";
7209 case DW_AT_ordering:
7210 return "DW_AT_ordering";
7211 case DW_AT_subscr_data:
7212 return "DW_AT_subscr_data";
7213 case DW_AT_byte_size:
7214 return "DW_AT_byte_size";
7215 case DW_AT_bit_offset:
7216 return "DW_AT_bit_offset";
7217 case DW_AT_bit_size:
7218 return "DW_AT_bit_size";
7219 case DW_AT_element_list:
7220 return "DW_AT_element_list";
7221 case DW_AT_stmt_list:
7222 return "DW_AT_stmt_list";
7224 return "DW_AT_low_pc";
7226 return "DW_AT_high_pc";
7227 case DW_AT_language:
7228 return "DW_AT_language";
7230 return "DW_AT_member";
7232 return "DW_AT_discr";
7233 case DW_AT_discr_value:
7234 return "DW_AT_discr_value";
7235 case DW_AT_visibility:
7236 return "DW_AT_visibility";
7238 return "DW_AT_import";
7239 case DW_AT_string_length:
7240 return "DW_AT_string_length";
7241 case DW_AT_common_reference:
7242 return "DW_AT_common_reference";
7243 case DW_AT_comp_dir:
7244 return "DW_AT_comp_dir";
7245 case DW_AT_const_value:
7246 return "DW_AT_const_value";
7247 case DW_AT_containing_type:
7248 return "DW_AT_containing_type";
7249 case DW_AT_default_value:
7250 return "DW_AT_default_value";
7252 return "DW_AT_inline";
7253 case DW_AT_is_optional:
7254 return "DW_AT_is_optional";
7255 case DW_AT_lower_bound:
7256 return "DW_AT_lower_bound";
7257 case DW_AT_producer:
7258 return "DW_AT_producer";
7259 case DW_AT_prototyped:
7260 return "DW_AT_prototyped";
7261 case DW_AT_return_addr:
7262 return "DW_AT_return_addr";
7263 case DW_AT_start_scope:
7264 return "DW_AT_start_scope";
7265 case DW_AT_bit_stride:
7266 return "DW_AT_bit_stride";
7267 case DW_AT_upper_bound:
7268 return "DW_AT_upper_bound";
7269 case DW_AT_abstract_origin:
7270 return "DW_AT_abstract_origin";
7271 case DW_AT_accessibility:
7272 return "DW_AT_accessibility";
7273 case DW_AT_address_class:
7274 return "DW_AT_address_class";
7275 case DW_AT_artificial:
7276 return "DW_AT_artificial";
7277 case DW_AT_base_types:
7278 return "DW_AT_base_types";
7279 case DW_AT_calling_convention:
7280 return "DW_AT_calling_convention";
7282 return "DW_AT_count";
7283 case DW_AT_data_member_location:
7284 return "DW_AT_data_member_location";
7285 case DW_AT_decl_column:
7286 return "DW_AT_decl_column";
7287 case DW_AT_decl_file:
7288 return "DW_AT_decl_file";
7289 case DW_AT_decl_line:
7290 return "DW_AT_decl_line";
7291 case DW_AT_declaration:
7292 return "DW_AT_declaration";
7293 case DW_AT_discr_list:
7294 return "DW_AT_discr_list";
7295 case DW_AT_encoding:
7296 return "DW_AT_encoding";
7297 case DW_AT_external:
7298 return "DW_AT_external";
7299 case DW_AT_explicit:
7300 return "DW_AT_explicit";
7301 case DW_AT_frame_base:
7302 return "DW_AT_frame_base";
7304 return "DW_AT_friend";
7305 case DW_AT_identifier_case:
7306 return "DW_AT_identifier_case";
7307 case DW_AT_macro_info:
7308 return "DW_AT_macro_info";
7309 case DW_AT_namelist_items:
7310 return "DW_AT_namelist_items";
7311 case DW_AT_priority:
7312 return "DW_AT_priority";
7314 return "DW_AT_segment";
7315 case DW_AT_specification:
7316 return "DW_AT_specification";
7317 case DW_AT_static_link:
7318 return "DW_AT_static_link";
7320 return "DW_AT_type";
7321 case DW_AT_use_location:
7322 return "DW_AT_use_location";
7323 case DW_AT_variable_parameter:
7324 return "DW_AT_variable_parameter";
7325 case DW_AT_virtuality:
7326 return "DW_AT_virtuality";
7327 case DW_AT_vtable_elem_location:
7328 return "DW_AT_vtable_elem_location";
7330 case DW_AT_allocated:
7331 return "DW_AT_allocated";
7332 case DW_AT_associated:
7333 return "DW_AT_associated";
7334 case DW_AT_data_location:
7335 return "DW_AT_data_location";
7336 case DW_AT_byte_stride:
7337 return "DW_AT_byte_stride";
7338 case DW_AT_entry_pc:
7339 return "DW_AT_entry_pc";
7340 case DW_AT_use_UTF8:
7341 return "DW_AT_use_UTF8";
7342 case DW_AT_extension:
7343 return "DW_AT_extension";
7345 return "DW_AT_ranges";
7346 case DW_AT_trampoline:
7347 return "DW_AT_trampoline";
7348 case DW_AT_call_column:
7349 return "DW_AT_call_column";
7350 case DW_AT_call_file:
7351 return "DW_AT_call_file";
7352 case DW_AT_call_line:
7353 return "DW_AT_call_line";
7354 case DW_AT_object_pointer:
7355 return "DW_AT_object_pointer";
7357 case DW_AT_signature:
7358 return "DW_AT_signature";
7359 case DW_AT_main_subprogram:
7360 return "DW_AT_main_subprogram";
7361 case DW_AT_data_bit_offset:
7362 return "DW_AT_data_bit_offset";
7363 case DW_AT_const_expr:
7364 return "DW_AT_const_expr";
7365 case DW_AT_enum_class:
7366 return "DW_AT_enum_class";
7367 case DW_AT_linkage_name:
7368 return "DW_AT_linkage_name";
7370 case DW_AT_MIPS_fde:
7371 return "DW_AT_MIPS_fde";
7372 case DW_AT_MIPS_loop_begin:
7373 return "DW_AT_MIPS_loop_begin";
7374 case DW_AT_MIPS_tail_loop_begin:
7375 return "DW_AT_MIPS_tail_loop_begin";
7376 case DW_AT_MIPS_epilog_begin:
7377 return "DW_AT_MIPS_epilog_begin";
7378 #if VMS_DEBUGGING_INFO
7379 case DW_AT_HP_prologue:
7380 return "DW_AT_HP_prologue";
7382 case DW_AT_MIPS_loop_unroll_factor:
7383 return "DW_AT_MIPS_loop_unroll_factor";
7385 case DW_AT_MIPS_software_pipeline_depth:
7386 return "DW_AT_MIPS_software_pipeline_depth";
7387 case DW_AT_MIPS_linkage_name:
7388 return "DW_AT_MIPS_linkage_name";
7389 #if VMS_DEBUGGING_INFO
7390 case DW_AT_HP_epilogue:
7391 return "DW_AT_HP_epilogue";
7393 case DW_AT_MIPS_stride:
7394 return "DW_AT_MIPS_stride";
7396 case DW_AT_MIPS_abstract_name:
7397 return "DW_AT_MIPS_abstract_name";
7398 case DW_AT_MIPS_clone_origin:
7399 return "DW_AT_MIPS_clone_origin";
7400 case DW_AT_MIPS_has_inlines:
7401 return "DW_AT_MIPS_has_inlines";
7403 case DW_AT_sf_names:
7404 return "DW_AT_sf_names";
7405 case DW_AT_src_info:
7406 return "DW_AT_src_info";
7407 case DW_AT_mac_info:
7408 return "DW_AT_mac_info";
7409 case DW_AT_src_coords:
7410 return "DW_AT_src_coords";
7411 case DW_AT_body_begin:
7412 return "DW_AT_body_begin";
7413 case DW_AT_body_end:
7414 return "DW_AT_body_end";
7416 case DW_AT_GNU_vector:
7417 return "DW_AT_GNU_vector";
7418 case DW_AT_GNU_guarded_by:
7419 return "DW_AT_GNU_guarded_by";
7420 case DW_AT_GNU_pt_guarded_by:
7421 return "DW_AT_GNU_pt_guarded_by";
7422 case DW_AT_GNU_guarded:
7423 return "DW_AT_GNU_guarded";
7424 case DW_AT_GNU_pt_guarded:
7425 return "DW_AT_GNU_pt_guarded";
7426 case DW_AT_GNU_locks_excluded:
7427 return "DW_AT_GNU_locks_excluded";
7428 case DW_AT_GNU_exclusive_locks_required:
7429 return "DW_AT_GNU_exclusive_locks_required";
7430 case DW_AT_GNU_shared_locks_required:
7431 return "DW_AT_GNU_shared_locks_required";
7432 case DW_AT_GNU_odr_signature:
7433 return "DW_AT_GNU_odr_signature";
7434 case DW_AT_GNU_template_name:
7435 return "DW_AT_GNU_template_name";
7436 case DW_AT_GNU_call_site_value:
7437 return "DW_AT_GNU_call_site_value";
7438 case DW_AT_GNU_call_site_data_value:
7439 return "DW_AT_GNU_call_site_data_value";
7440 case DW_AT_GNU_call_site_target:
7441 return "DW_AT_GNU_call_site_target";
7442 case DW_AT_GNU_call_site_target_clobbered:
7443 return "DW_AT_GNU_call_site_target_clobbered";
7444 case DW_AT_GNU_tail_call:
7445 return "DW_AT_GNU_tail_call";
7446 case DW_AT_GNU_all_tail_call_sites:
7447 return "DW_AT_GNU_all_tail_call_sites";
7448 case DW_AT_GNU_all_call_sites:
7449 return "DW_AT_GNU_all_call_sites";
7450 case DW_AT_GNU_all_source_call_sites:
7451 return "DW_AT_GNU_all_source_call_sites";
7453 case DW_AT_GNAT_descriptive_type:
7454 return "DW_AT_GNAT_descriptive_type";
7456 case DW_AT_VMS_rtnbeg_pd_address:
7457 return "DW_AT_VMS_rtnbeg_pd_address";
7460 return "DW_AT_<unknown>";
7464 /* Convert a DWARF value form code into its string name. */
7467 dwarf_form_name (unsigned int form)
7472 return "DW_FORM_addr";
7473 case DW_FORM_block2:
7474 return "DW_FORM_block2";
7475 case DW_FORM_block4:
7476 return "DW_FORM_block4";
7478 return "DW_FORM_data2";
7480 return "DW_FORM_data4";
7482 return "DW_FORM_data8";
7483 case DW_FORM_string:
7484 return "DW_FORM_string";
7486 return "DW_FORM_block";
7487 case DW_FORM_block1:
7488 return "DW_FORM_block1";
7490 return "DW_FORM_data1";
7492 return "DW_FORM_flag";
7494 return "DW_FORM_sdata";
7496 return "DW_FORM_strp";
7498 return "DW_FORM_udata";
7499 case DW_FORM_ref_addr:
7500 return "DW_FORM_ref_addr";
7502 return "DW_FORM_ref1";
7504 return "DW_FORM_ref2";
7506 return "DW_FORM_ref4";
7508 return "DW_FORM_ref8";
7509 case DW_FORM_ref_udata:
7510 return "DW_FORM_ref_udata";
7511 case DW_FORM_indirect:
7512 return "DW_FORM_indirect";
7513 case DW_FORM_sec_offset:
7514 return "DW_FORM_sec_offset";
7515 case DW_FORM_exprloc:
7516 return "DW_FORM_exprloc";
7517 case DW_FORM_flag_present:
7518 return "DW_FORM_flag_present";
7519 case DW_FORM_ref_sig8:
7520 return "DW_FORM_ref_sig8";
7522 return "DW_FORM_<unknown>";
7526 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7527 instance of an inlined instance of a decl which is local to an inline
7528 function, so we have to trace all of the way back through the origin chain
7529 to find out what sort of node actually served as the original seed for the
7533 decl_ultimate_origin (const_tree decl)
7535 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7538 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7539 nodes in the function to point to themselves; ignore that if
7540 we're trying to output the abstract instance of this function. */
7541 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7544 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7545 most distant ancestor, this should never happen. */
7546 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7548 return DECL_ABSTRACT_ORIGIN (decl);
7551 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7552 of a virtual function may refer to a base class, so we check the 'this'
7556 decl_class_context (tree decl)
7558 tree context = NULL_TREE;
7560 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7561 context = DECL_CONTEXT (decl);
7563 context = TYPE_MAIN_VARIANT
7564 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7566 if (context && !TYPE_P (context))
7567 context = NULL_TREE;
7572 /* Add an attribute/value pair to a DIE. */
7575 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7577 /* Maybe this should be an assert? */
7581 if (die->die_attr == NULL)
7582 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7583 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7586 static inline enum dw_val_class
7587 AT_class (dw_attr_ref a)
7589 return a->dw_attr_val.val_class;
7592 /* Add a flag value attribute to a DIE. */
7595 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7599 attr.dw_attr = attr_kind;
7600 attr.dw_attr_val.val_class = dw_val_class_flag;
7601 attr.dw_attr_val.v.val_flag = flag;
7602 add_dwarf_attr (die, &attr);
7605 static inline unsigned
7606 AT_flag (dw_attr_ref a)
7608 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7609 return a->dw_attr_val.v.val_flag;
7612 /* Add a signed integer attribute value to a DIE. */
7615 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7619 attr.dw_attr = attr_kind;
7620 attr.dw_attr_val.val_class = dw_val_class_const;
7621 attr.dw_attr_val.v.val_int = int_val;
7622 add_dwarf_attr (die, &attr);
7625 static inline HOST_WIDE_INT
7626 AT_int (dw_attr_ref a)
7628 gcc_assert (a && AT_class (a) == dw_val_class_const);
7629 return a->dw_attr_val.v.val_int;
7632 /* Add an unsigned integer attribute value to a DIE. */
7635 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7636 unsigned HOST_WIDE_INT unsigned_val)
7640 attr.dw_attr = attr_kind;
7641 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7642 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7643 add_dwarf_attr (die, &attr);
7646 static inline unsigned HOST_WIDE_INT
7647 AT_unsigned (dw_attr_ref a)
7649 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7650 return a->dw_attr_val.v.val_unsigned;
7653 /* Add an unsigned double integer attribute value to a DIE. */
7656 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7657 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7661 attr.dw_attr = attr_kind;
7662 attr.dw_attr_val.val_class = dw_val_class_const_double;
7663 attr.dw_attr_val.v.val_double.high = high;
7664 attr.dw_attr_val.v.val_double.low = low;
7665 add_dwarf_attr (die, &attr);
7668 /* Add a floating point attribute value to a DIE and return it. */
7671 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7672 unsigned int length, unsigned int elt_size, unsigned char *array)
7676 attr.dw_attr = attr_kind;
7677 attr.dw_attr_val.val_class = dw_val_class_vec;
7678 attr.dw_attr_val.v.val_vec.length = length;
7679 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7680 attr.dw_attr_val.v.val_vec.array = array;
7681 add_dwarf_attr (die, &attr);
7684 /* Add an 8-byte data attribute value to a DIE. */
7687 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7688 unsigned char data8[8])
7692 attr.dw_attr = attr_kind;
7693 attr.dw_attr_val.val_class = dw_val_class_data8;
7694 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7695 add_dwarf_attr (die, &attr);
7698 /* Hash and equality functions for debug_str_hash. */
7701 debug_str_do_hash (const void *x)
7703 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7707 debug_str_eq (const void *x1, const void *x2)
7709 return strcmp ((((const struct indirect_string_node *)x1)->str),
7710 (const char *)x2) == 0;
7713 /* Add STR to the indirect string hash table. */
7715 static struct indirect_string_node *
7716 find_AT_string (const char *str)
7718 struct indirect_string_node *node;
7721 if (! debug_str_hash)
7722 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7723 debug_str_eq, NULL);
7725 slot = htab_find_slot_with_hash (debug_str_hash, str,
7726 htab_hash_string (str), INSERT);
7729 node = ggc_alloc_cleared_indirect_string_node ();
7730 node->str = ggc_strdup (str);
7734 node = (struct indirect_string_node *) *slot;
7740 /* Add a string attribute value to a DIE. */
7743 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7746 struct indirect_string_node *node;
7748 node = find_AT_string (str);
7750 attr.dw_attr = attr_kind;
7751 attr.dw_attr_val.val_class = dw_val_class_str;
7752 attr.dw_attr_val.v.val_str = node;
7753 add_dwarf_attr (die, &attr);
7756 static inline const char *
7757 AT_string (dw_attr_ref a)
7759 gcc_assert (a && AT_class (a) == dw_val_class_str);
7760 return a->dw_attr_val.v.val_str->str;
7763 /* Find out whether a string should be output inline in DIE
7764 or out-of-line in .debug_str section. */
7766 static enum dwarf_form
7767 AT_string_form (dw_attr_ref a)
7769 struct indirect_string_node *node;
7773 gcc_assert (a && AT_class (a) == dw_val_class_str);
7775 node = a->dw_attr_val.v.val_str;
7779 len = strlen (node->str) + 1;
7781 /* If the string is shorter or equal to the size of the reference, it is
7782 always better to put it inline. */
7783 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7784 return node->form = DW_FORM_string;
7786 /* If we cannot expect the linker to merge strings in .debug_str
7787 section, only put it into .debug_str if it is worth even in this
7789 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7790 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7791 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7792 return node->form = DW_FORM_string;
7794 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7795 ++dw2_string_counter;
7796 node->label = xstrdup (label);
7798 return node->form = DW_FORM_strp;
7801 /* Add a DIE reference attribute value to a DIE. */
7804 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7808 #ifdef ENABLE_CHECKING
7809 gcc_assert (targ_die != NULL);
7811 /* With LTO we can end up trying to reference something we didn't create
7812 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7813 if (targ_die == NULL)
7817 attr.dw_attr = attr_kind;
7818 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7819 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7820 attr.dw_attr_val.v.val_die_ref.external = 0;
7821 add_dwarf_attr (die, &attr);
7824 /* Add an AT_specification attribute to a DIE, and also make the back
7825 pointer from the specification to the definition. */
7828 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7830 add_AT_die_ref (die, DW_AT_specification, targ_die);
7831 gcc_assert (!targ_die->die_definition);
7832 targ_die->die_definition = die;
7835 static inline dw_die_ref
7836 AT_ref (dw_attr_ref a)
7838 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7839 return a->dw_attr_val.v.val_die_ref.die;
7843 AT_ref_external (dw_attr_ref a)
7845 if (a && AT_class (a) == dw_val_class_die_ref)
7846 return a->dw_attr_val.v.val_die_ref.external;
7852 set_AT_ref_external (dw_attr_ref a, int i)
7854 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7855 a->dw_attr_val.v.val_die_ref.external = i;
7858 /* Add an FDE reference attribute value to a DIE. */
7861 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7865 attr.dw_attr = attr_kind;
7866 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7867 attr.dw_attr_val.v.val_fde_index = targ_fde;
7868 add_dwarf_attr (die, &attr);
7871 /* Add a location description attribute value to a DIE. */
7874 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7878 attr.dw_attr = attr_kind;
7879 attr.dw_attr_val.val_class = dw_val_class_loc;
7880 attr.dw_attr_val.v.val_loc = loc;
7881 add_dwarf_attr (die, &attr);
7884 static inline dw_loc_descr_ref
7885 AT_loc (dw_attr_ref a)
7887 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7888 return a->dw_attr_val.v.val_loc;
7892 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7896 attr.dw_attr = attr_kind;
7897 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7898 attr.dw_attr_val.v.val_loc_list = loc_list;
7899 add_dwarf_attr (die, &attr);
7900 have_location_lists = true;
7903 static inline dw_loc_list_ref
7904 AT_loc_list (dw_attr_ref a)
7906 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7907 return a->dw_attr_val.v.val_loc_list;
7910 static inline dw_loc_list_ref *
7911 AT_loc_list_ptr (dw_attr_ref a)
7913 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7914 return &a->dw_attr_val.v.val_loc_list;
7917 /* Add an address constant attribute value to a DIE. */
7920 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7924 attr.dw_attr = attr_kind;
7925 attr.dw_attr_val.val_class = dw_val_class_addr;
7926 attr.dw_attr_val.v.val_addr = addr;
7927 add_dwarf_attr (die, &attr);
7930 /* Get the RTX from to an address DIE attribute. */
7933 AT_addr (dw_attr_ref a)
7935 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7936 return a->dw_attr_val.v.val_addr;
7939 /* Add a file attribute value to a DIE. */
7942 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7943 struct dwarf_file_data *fd)
7947 attr.dw_attr = attr_kind;
7948 attr.dw_attr_val.val_class = dw_val_class_file;
7949 attr.dw_attr_val.v.val_file = fd;
7950 add_dwarf_attr (die, &attr);
7953 /* Get the dwarf_file_data from a file DIE attribute. */
7955 static inline struct dwarf_file_data *
7956 AT_file (dw_attr_ref a)
7958 gcc_assert (a && AT_class (a) == dw_val_class_file);
7959 return a->dw_attr_val.v.val_file;
7962 /* Add a vms delta attribute value to a DIE. */
7965 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7966 const char *lbl1, const char *lbl2)
7970 attr.dw_attr = attr_kind;
7971 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7972 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7973 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7974 add_dwarf_attr (die, &attr);
7977 /* Add a label identifier attribute value to a DIE. */
7980 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7984 attr.dw_attr = attr_kind;
7985 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7986 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7987 add_dwarf_attr (die, &attr);
7990 /* Add a section offset attribute value to a DIE, an offset into the
7991 debug_line section. */
7994 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7999 attr.dw_attr = attr_kind;
8000 attr.dw_attr_val.val_class = dw_val_class_lineptr;
8001 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
8002 add_dwarf_attr (die, &attr);
8005 /* Add a section offset attribute value to a DIE, an offset into the
8006 debug_macinfo section. */
8009 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
8014 attr.dw_attr = attr_kind;
8015 attr.dw_attr_val.val_class = dw_val_class_macptr;
8016 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
8017 add_dwarf_attr (die, &attr);
8020 /* Add an offset attribute value to a DIE. */
8023 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
8024 unsigned HOST_WIDE_INT offset)
8028 attr.dw_attr = attr_kind;
8029 attr.dw_attr_val.val_class = dw_val_class_offset;
8030 attr.dw_attr_val.v.val_offset = offset;
8031 add_dwarf_attr (die, &attr);
8034 /* Add an range_list attribute value to a DIE. */
8037 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
8038 long unsigned int offset)
8042 attr.dw_attr = attr_kind;
8043 attr.dw_attr_val.val_class = dw_val_class_range_list;
8044 attr.dw_attr_val.v.val_offset = offset;
8045 add_dwarf_attr (die, &attr);
8048 /* Return the start label of a delta attribute. */
8050 static inline const char *
8051 AT_vms_delta1 (dw_attr_ref a)
8053 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
8054 return a->dw_attr_val.v.val_vms_delta.lbl1;
8057 /* Return the end label of a delta attribute. */
8059 static inline const char *
8060 AT_vms_delta2 (dw_attr_ref a)
8062 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
8063 return a->dw_attr_val.v.val_vms_delta.lbl2;
8066 static inline const char *
8067 AT_lbl (dw_attr_ref a)
8069 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
8070 || AT_class (a) == dw_val_class_lineptr
8071 || AT_class (a) == dw_val_class_macptr));
8072 return a->dw_attr_val.v.val_lbl_id;
8075 /* Get the attribute of type attr_kind. */
8078 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
8082 dw_die_ref spec = NULL;
8087 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8088 if (a->dw_attr == attr_kind)
8090 else if (a->dw_attr == DW_AT_specification
8091 || a->dw_attr == DW_AT_abstract_origin)
8095 return get_AT (spec, attr_kind);
8100 /* Return the "low pc" attribute value, typically associated with a subprogram
8101 DIE. Return null if the "low pc" attribute is either not present, or if it
8102 cannot be represented as an assembler label identifier. */
8104 static inline const char *
8105 get_AT_low_pc (dw_die_ref die)
8107 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
8109 return a ? AT_lbl (a) : NULL;
8112 /* Return the "high pc" attribute value, typically associated with a subprogram
8113 DIE. Return null if the "high pc" attribute is either not present, or if it
8114 cannot be represented as an assembler label identifier. */
8116 static inline const char *
8117 get_AT_hi_pc (dw_die_ref die)
8119 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
8121 return a ? AT_lbl (a) : NULL;
8124 /* Return the value of the string attribute designated by ATTR_KIND, or
8125 NULL if it is not present. */
8127 static inline const char *
8128 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
8130 dw_attr_ref a = get_AT (die, attr_kind);
8132 return a ? AT_string (a) : NULL;
8135 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
8136 if it is not present. */
8139 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
8141 dw_attr_ref a = get_AT (die, attr_kind);
8143 return a ? AT_flag (a) : 0;
8146 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
8147 if it is not present. */
8149 static inline unsigned
8150 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
8152 dw_attr_ref a = get_AT (die, attr_kind);
8154 return a ? AT_unsigned (a) : 0;
8157 static inline dw_die_ref
8158 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
8160 dw_attr_ref a = get_AT (die, attr_kind);
8162 return a ? AT_ref (a) : NULL;
8165 static inline struct dwarf_file_data *
8166 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
8168 dw_attr_ref a = get_AT (die, attr_kind);
8170 return a ? AT_file (a) : NULL;
8173 /* Return TRUE if the language is C++. */
8178 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8180 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
8183 /* Return TRUE if the language is Fortran. */
8188 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8190 return (lang == DW_LANG_Fortran77
8191 || lang == DW_LANG_Fortran90
8192 || lang == DW_LANG_Fortran95);
8195 /* Return TRUE if the language is Ada. */
8200 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8202 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
8205 /* Remove the specified attribute if present. */
8208 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
8216 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8217 if (a->dw_attr == attr_kind)
8219 if (AT_class (a) == dw_val_class_str)
8220 if (a->dw_attr_val.v.val_str->refcount)
8221 a->dw_attr_val.v.val_str->refcount--;
8223 /* VEC_ordered_remove should help reduce the number of abbrevs
8225 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
8230 /* Remove CHILD from its parent. PREV must have the property that
8231 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
8234 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
8236 gcc_assert (child->die_parent == prev->die_parent);
8237 gcc_assert (prev->die_sib == child);
8240 gcc_assert (child->die_parent->die_child == child);
8244 prev->die_sib = child->die_sib;
8245 if (child->die_parent->die_child == child)
8246 child->die_parent->die_child = prev;
8249 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
8250 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
8253 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
8255 dw_die_ref parent = old_child->die_parent;
8257 gcc_assert (parent == prev->die_parent);
8258 gcc_assert (prev->die_sib == old_child);
8260 new_child->die_parent = parent;
8261 if (prev == old_child)
8263 gcc_assert (parent->die_child == old_child);
8264 new_child->die_sib = new_child;
8268 prev->die_sib = new_child;
8269 new_child->die_sib = old_child->die_sib;
8271 if (old_child->die_parent->die_child == old_child)
8272 old_child->die_parent->die_child = new_child;
8275 /* Move all children from OLD_PARENT to NEW_PARENT. */
8278 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
8281 new_parent->die_child = old_parent->die_child;
8282 old_parent->die_child = NULL;
8283 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
8286 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8290 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8296 dw_die_ref prev = c;
8298 while (c->die_tag == tag)
8300 remove_child_with_prev (c, prev);
8301 /* Might have removed every child. */
8302 if (c == c->die_sib)
8306 } while (c != die->die_child);
8309 /* Add a CHILD_DIE as the last child of DIE. */
8312 add_child_die (dw_die_ref die, dw_die_ref child_die)
8314 /* FIXME this should probably be an assert. */
8315 if (! die || ! child_die)
8317 gcc_assert (die != child_die);
8319 child_die->die_parent = die;
8322 child_die->die_sib = die->die_child->die_sib;
8323 die->die_child->die_sib = child_die;
8326 child_die->die_sib = child_die;
8327 die->die_child = child_die;
8330 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8331 is the specification, to the end of PARENT's list of children.
8332 This is done by removing and re-adding it. */
8335 splice_child_die (dw_die_ref parent, dw_die_ref child)
8339 /* We want the declaration DIE from inside the class, not the
8340 specification DIE at toplevel. */
8341 if (child->die_parent != parent)
8343 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8349 gcc_assert (child->die_parent == parent
8350 || (child->die_parent
8351 == get_AT_ref (parent, DW_AT_specification)));
8353 for (p = child->die_parent->die_child; ; p = p->die_sib)
8354 if (p->die_sib == child)
8356 remove_child_with_prev (child, p);
8360 add_child_die (parent, child);
8363 /* Return a pointer to a newly created DIE node. */
8365 static inline dw_die_ref
8366 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8368 dw_die_ref die = ggc_alloc_cleared_die_node ();
8370 die->die_tag = tag_value;
8372 if (parent_die != NULL)
8373 add_child_die (parent_die, die);
8376 limbo_die_node *limbo_node;
8378 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8379 limbo_node->die = die;
8380 limbo_node->created_for = t;
8381 limbo_node->next = limbo_die_list;
8382 limbo_die_list = limbo_node;
8388 /* Return the DIE associated with the given type specifier. */
8390 static inline dw_die_ref
8391 lookup_type_die (tree type)
8393 return TYPE_SYMTAB_DIE (type);
8396 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8397 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8398 anonymous type instead the one of the naming typedef. */
8400 static inline dw_die_ref
8401 strip_naming_typedef (tree type, dw_die_ref type_die)
8404 && TREE_CODE (type) == RECORD_TYPE
8406 && type_die->die_tag == DW_TAG_typedef
8407 && is_naming_typedef_decl (TYPE_NAME (type)))
8408 type_die = get_AT_ref (type_die, DW_AT_type);
8412 /* Like lookup_type_die, but if type is an anonymous type named by a
8413 typedef[1], return the DIE of the anonymous type instead the one of
8414 the naming typedef. This is because in gen_typedef_die, we did
8415 equate the anonymous struct named by the typedef with the DIE of
8416 the naming typedef. So by default, lookup_type_die on an anonymous
8417 struct yields the DIE of the naming typedef.
8419 [1]: Read the comment of is_naming_typedef_decl to learn about what
8420 a naming typedef is. */
8422 static inline dw_die_ref
8423 lookup_type_die_strip_naming_typedef (tree type)
8425 dw_die_ref die = lookup_type_die (type);
8426 return strip_naming_typedef (type, die);
8429 /* Equate a DIE to a given type specifier. */
8432 equate_type_number_to_die (tree type, dw_die_ref type_die)
8434 TYPE_SYMTAB_DIE (type) = type_die;
8437 /* Returns a hash value for X (which really is a die_struct). */
8440 decl_die_table_hash (const void *x)
8442 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8445 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8448 decl_die_table_eq (const void *x, const void *y)
8450 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8453 /* Return the DIE associated with a given declaration. */
8455 static inline dw_die_ref
8456 lookup_decl_die (tree decl)
8458 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8461 /* Returns a hash value for X (which really is a var_loc_list). */
8464 decl_loc_table_hash (const void *x)
8466 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8469 /* Return nonzero if decl_id of var_loc_list X is the same as
8473 decl_loc_table_eq (const void *x, const void *y)
8475 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8478 /* Return the var_loc list associated with a given declaration. */
8480 static inline var_loc_list *
8481 lookup_decl_loc (const_tree decl)
8483 if (!decl_loc_table)
8485 return (var_loc_list *)
8486 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8489 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
8492 cached_dw_loc_list_table_hash (const void *x)
8494 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
8497 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
8501 cached_dw_loc_list_table_eq (const void *x, const void *y)
8503 return (((const cached_dw_loc_list *) x)->decl_id
8504 == DECL_UID ((const_tree) y));
8507 /* Equate a DIE to a particular declaration. */
8510 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8512 unsigned int decl_id = DECL_UID (decl);
8515 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8517 decl_die->decl_id = decl_id;
8520 /* Return how many bits covers PIECE EXPR_LIST. */
8523 decl_piece_bitsize (rtx piece)
8525 int ret = (int) GET_MODE (piece);
8528 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8529 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8530 return INTVAL (XEXP (XEXP (piece, 0), 0));
8533 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8536 decl_piece_varloc_ptr (rtx piece)
8538 if ((int) GET_MODE (piece))
8539 return &XEXP (piece, 0);
8541 return &XEXP (XEXP (piece, 0), 1);
8544 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8545 Next is the chain of following piece nodes. */
8548 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8550 if (bitsize <= (int) MAX_MACHINE_MODE)
8551 return alloc_EXPR_LIST (bitsize, loc_note, next);
8553 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8558 /* Return rtx that should be stored into loc field for
8559 LOC_NOTE and BITPOS/BITSIZE. */
8562 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8563 HOST_WIDE_INT bitsize)
8567 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8569 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8574 /* This function either modifies location piece list *DEST in
8575 place (if SRC and INNER is NULL), or copies location piece list
8576 *SRC to *DEST while modifying it. Location BITPOS is modified
8577 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8578 not copied and if needed some padding around it is added.
8579 When modifying in place, DEST should point to EXPR_LIST where
8580 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8581 to the start of the whole list and INNER points to the EXPR_LIST
8582 where earlier pieces cover PIECE_BITPOS bits. */
8585 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8586 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8587 HOST_WIDE_INT bitsize, rtx loc_note)
8590 bool copy = inner != NULL;
8594 /* First copy all nodes preceeding the current bitpos. */
8595 while (src != inner)
8597 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8598 decl_piece_bitsize (*src), NULL_RTX);
8599 dest = &XEXP (*dest, 1);
8600 src = &XEXP (*src, 1);
8603 /* Add padding if needed. */
8604 if (bitpos != piece_bitpos)
8606 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8607 copy ? NULL_RTX : *dest);
8608 dest = &XEXP (*dest, 1);
8610 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8613 /* A piece with correct bitpos and bitsize already exist,
8614 just update the location for it and return. */
8615 *decl_piece_varloc_ptr (*dest) = loc_note;
8618 /* Add the piece that changed. */
8619 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8620 dest = &XEXP (*dest, 1);
8621 /* Skip over pieces that overlap it. */
8622 diff = bitpos - piece_bitpos + bitsize;
8625 while (diff > 0 && *src)
8628 diff -= decl_piece_bitsize (piece);
8630 src = &XEXP (piece, 1);
8633 *src = XEXP (piece, 1);
8634 free_EXPR_LIST_node (piece);
8637 /* Add padding if needed. */
8638 if (diff < 0 && *src)
8642 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8643 dest = &XEXP (*dest, 1);
8647 /* Finally copy all nodes following it. */
8650 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8651 decl_piece_bitsize (*src), NULL_RTX);
8652 dest = &XEXP (*dest, 1);
8653 src = &XEXP (*src, 1);
8657 /* Add a variable location node to the linked list for DECL. */
8659 static struct var_loc_node *
8660 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8662 unsigned int decl_id;
8665 struct var_loc_node *loc = NULL;
8666 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8668 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8670 tree realdecl = DECL_DEBUG_EXPR (decl);
8671 if (realdecl && handled_component_p (realdecl))
8673 HOST_WIDE_INT maxsize;
8676 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8677 if (!DECL_P (innerdecl)
8678 || DECL_IGNORED_P (innerdecl)
8679 || TREE_STATIC (innerdecl)
8681 || bitpos + bitsize > 256
8682 || bitsize != maxsize)
8688 decl_id = DECL_UID (decl);
8689 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8692 temp = ggc_alloc_cleared_var_loc_list ();
8693 temp->decl_id = decl_id;
8697 temp = (var_loc_list *) *slot;
8699 /* For PARM_DECLs try to keep around the original incoming value,
8700 even if that means we'll emit a zero-range .debug_loc entry. */
8702 && temp->first == temp->last
8703 && TREE_CODE (decl) == PARM_DECL
8704 && GET_CODE (temp->first->loc) == NOTE
8705 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
8706 && DECL_INCOMING_RTL (decl)
8707 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
8708 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
8709 == GET_CODE (DECL_INCOMING_RTL (decl))
8710 && prev_real_insn (temp->first->loc) == NULL_RTX
8712 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
8713 NOTE_VAR_LOCATION_LOC (loc_note))
8714 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
8715 != NOTE_VAR_LOCATION_STATUS (loc_note))))
8717 loc = ggc_alloc_cleared_var_loc_node ();
8718 temp->first->next = loc;
8720 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8722 else if (temp->last)
8724 struct var_loc_node *last = temp->last, *unused = NULL;
8725 rtx *piece_loc = NULL, last_loc_note;
8726 int piece_bitpos = 0;
8730 gcc_assert (last->next == NULL);
8732 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8734 piece_loc = &last->loc;
8737 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8738 if (piece_bitpos + cur_bitsize > bitpos)
8740 piece_bitpos += cur_bitsize;
8741 piece_loc = &XEXP (*piece_loc, 1);
8745 /* TEMP->LAST here is either pointer to the last but one or
8746 last element in the chained list, LAST is pointer to the
8748 if (label && strcmp (last->label, label) == 0)
8750 /* For SRA optimized variables if there weren't any real
8751 insns since last note, just modify the last node. */
8752 if (piece_loc != NULL)
8754 adjust_piece_list (piece_loc, NULL, NULL,
8755 bitpos, piece_bitpos, bitsize, loc_note);
8758 /* If the last note doesn't cover any instructions, remove it. */
8759 if (temp->last != last)
8761 temp->last->next = NULL;
8764 gcc_assert (strcmp (last->label, label) != 0);
8768 gcc_assert (temp->first == temp->last
8769 || (temp->first->next == temp->last
8770 && TREE_CODE (decl) == PARM_DECL));
8771 memset (temp->last, '\0', sizeof (*temp->last));
8772 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8776 if (bitsize == -1 && NOTE_P (last->loc))
8777 last_loc_note = last->loc;
8778 else if (piece_loc != NULL
8779 && *piece_loc != NULL_RTX
8780 && piece_bitpos == bitpos
8781 && decl_piece_bitsize (*piece_loc) == bitsize)
8782 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8784 last_loc_note = NULL_RTX;
8785 /* If the current location is the same as the end of the list,
8786 and either both or neither of the locations is uninitialized,
8787 we have nothing to do. */
8788 if (last_loc_note == NULL_RTX
8789 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8790 NOTE_VAR_LOCATION_LOC (loc_note)))
8791 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8792 != NOTE_VAR_LOCATION_STATUS (loc_note))
8793 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8794 == VAR_INIT_STATUS_UNINITIALIZED)
8795 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8796 == VAR_INIT_STATUS_UNINITIALIZED))))
8798 /* Add LOC to the end of list and update LAST. If the last
8799 element of the list has been removed above, reuse its
8800 memory for the new node, otherwise allocate a new one. */
8804 memset (loc, '\0', sizeof (*loc));
8807 loc = ggc_alloc_cleared_var_loc_node ();
8808 if (bitsize == -1 || piece_loc == NULL)
8809 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8811 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8812 bitpos, piece_bitpos, bitsize, loc_note);
8814 /* Ensure TEMP->LAST will point either to the new last but one
8815 element of the chain, or to the last element in it. */
8816 if (last != temp->last)
8824 loc = ggc_alloc_cleared_var_loc_node ();
8827 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8832 /* Keep track of the number of spaces used to indent the
8833 output of the debugging routines that print the structure of
8834 the DIE internal representation. */
8835 static int print_indent;
8837 /* Indent the line the number of spaces given by print_indent. */
8840 print_spaces (FILE *outfile)
8842 fprintf (outfile, "%*s", print_indent, "");
8845 /* Print a type signature in hex. */
8848 print_signature (FILE *outfile, char *sig)
8852 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8853 fprintf (outfile, "%02x", sig[i] & 0xff);
8856 /* Print the information associated with a given DIE, and its children.
8857 This routine is a debugging aid only. */
8860 print_die (dw_die_ref die, FILE *outfile)
8866 print_spaces (outfile);
8867 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8868 die->die_offset, dwarf_tag_name (die->die_tag),
8870 print_spaces (outfile);
8871 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8872 fprintf (outfile, " offset: %ld", die->die_offset);
8873 fprintf (outfile, " mark: %d\n", die->die_mark);
8875 if (use_debug_types && die->die_id.die_type_node)
8877 print_spaces (outfile);
8878 fprintf (outfile, " signature: ");
8879 print_signature (outfile, die->die_id.die_type_node->signature);
8880 fprintf (outfile, "\n");
8883 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8885 print_spaces (outfile);
8886 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8888 switch (AT_class (a))
8890 case dw_val_class_addr:
8891 fprintf (outfile, "address");
8893 case dw_val_class_offset:
8894 fprintf (outfile, "offset");
8896 case dw_val_class_loc:
8897 fprintf (outfile, "location descriptor");
8899 case dw_val_class_loc_list:
8900 fprintf (outfile, "location list -> label:%s",
8901 AT_loc_list (a)->ll_symbol);
8903 case dw_val_class_range_list:
8904 fprintf (outfile, "range list");
8906 case dw_val_class_const:
8907 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8909 case dw_val_class_unsigned_const:
8910 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8912 case dw_val_class_const_double:
8913 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8914 HOST_WIDE_INT_PRINT_UNSIGNED")",
8915 a->dw_attr_val.v.val_double.high,
8916 a->dw_attr_val.v.val_double.low);
8918 case dw_val_class_vec:
8919 fprintf (outfile, "floating-point or vector constant");
8921 case dw_val_class_flag:
8922 fprintf (outfile, "%u", AT_flag (a));
8924 case dw_val_class_die_ref:
8925 if (AT_ref (a) != NULL)
8927 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
8929 fprintf (outfile, "die -> signature: ");
8930 print_signature (outfile,
8931 AT_ref (a)->die_id.die_type_node->signature);
8933 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
8934 fprintf (outfile, "die -> label: %s",
8935 AT_ref (a)->die_id.die_symbol);
8937 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8938 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8941 fprintf (outfile, "die -> <null>");
8943 case dw_val_class_vms_delta:
8944 fprintf (outfile, "delta: @slotcount(%s-%s)",
8945 AT_vms_delta2 (a), AT_vms_delta1 (a));
8947 case dw_val_class_lbl_id:
8948 case dw_val_class_lineptr:
8949 case dw_val_class_macptr:
8950 fprintf (outfile, "label: %s", AT_lbl (a));
8952 case dw_val_class_str:
8953 if (AT_string (a) != NULL)
8954 fprintf (outfile, "\"%s\"", AT_string (a));
8956 fprintf (outfile, "<null>");
8958 case dw_val_class_file:
8959 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8960 AT_file (a)->emitted_number);
8962 case dw_val_class_data8:
8966 for (i = 0; i < 8; i++)
8967 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8974 fprintf (outfile, "\n");
8977 if (die->die_child != NULL)
8980 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8983 if (print_indent == 0)
8984 fprintf (outfile, "\n");
8987 /* Print the information collected for a given DIE. */
8990 debug_dwarf_die (dw_die_ref die)
8992 print_die (die, stderr);
8995 /* Print all DWARF information collected for the compilation unit.
8996 This routine is a debugging aid only. */
9002 print_die (comp_unit_die (), stderr);
9005 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
9006 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
9007 DIE that marks the start of the DIEs for this include file. */
9010 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
9012 const char *filename = get_AT_string (bincl_die, DW_AT_name);
9013 dw_die_ref new_unit = gen_compile_unit_die (filename);
9015 new_unit->die_sib = old_unit;
9019 /* Close an include-file CU and reopen the enclosing one. */
9022 pop_compile_unit (dw_die_ref old_unit)
9024 dw_die_ref new_unit = old_unit->die_sib;
9026 old_unit->die_sib = NULL;
9030 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
9031 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
9033 /* Calculate the checksum of a location expression. */
9036 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
9040 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
9042 CHECKSUM (loc->dw_loc_oprnd1);
9043 CHECKSUM (loc->dw_loc_oprnd2);
9046 /* Calculate the checksum of an attribute. */
9049 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
9051 dw_loc_descr_ref loc;
9054 CHECKSUM (at->dw_attr);
9056 /* We don't care that this was compiled with a different compiler
9057 snapshot; if the output is the same, that's what matters. */
9058 if (at->dw_attr == DW_AT_producer)
9061 switch (AT_class (at))
9063 case dw_val_class_const:
9064 CHECKSUM (at->dw_attr_val.v.val_int);
9066 case dw_val_class_unsigned_const:
9067 CHECKSUM (at->dw_attr_val.v.val_unsigned);
9069 case dw_val_class_const_double:
9070 CHECKSUM (at->dw_attr_val.v.val_double);
9072 case dw_val_class_vec:
9073 CHECKSUM (at->dw_attr_val.v.val_vec);
9075 case dw_val_class_flag:
9076 CHECKSUM (at->dw_attr_val.v.val_flag);
9078 case dw_val_class_str:
9079 CHECKSUM_STRING (AT_string (at));
9082 case dw_val_class_addr:
9084 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9085 CHECKSUM_STRING (XSTR (r, 0));
9088 case dw_val_class_offset:
9089 CHECKSUM (at->dw_attr_val.v.val_offset);
9092 case dw_val_class_loc:
9093 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9094 loc_checksum (loc, ctx);
9097 case dw_val_class_die_ref:
9098 die_checksum (AT_ref (at), ctx, mark);
9101 case dw_val_class_fde_ref:
9102 case dw_val_class_vms_delta:
9103 case dw_val_class_lbl_id:
9104 case dw_val_class_lineptr:
9105 case dw_val_class_macptr:
9108 case dw_val_class_file:
9109 CHECKSUM_STRING (AT_file (at)->filename);
9112 case dw_val_class_data8:
9113 CHECKSUM (at->dw_attr_val.v.val_data8);
9121 /* Calculate the checksum of a DIE. */
9124 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9130 /* To avoid infinite recursion. */
9133 CHECKSUM (die->die_mark);
9136 die->die_mark = ++(*mark);
9138 CHECKSUM (die->die_tag);
9140 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9141 attr_checksum (a, ctx, mark);
9143 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
9147 #undef CHECKSUM_STRING
9149 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
9150 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
9151 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
9152 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
9153 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
9154 #define CHECKSUM_ATTR(FOO) \
9155 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
9157 /* Calculate the checksum of a number in signed LEB128 format. */
9160 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
9167 byte = (value & 0x7f);
9169 more = !((value == 0 && (byte & 0x40) == 0)
9170 || (value == -1 && (byte & 0x40) != 0));
9179 /* Calculate the checksum of a number in unsigned LEB128 format. */
9182 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
9186 unsigned char byte = (value & 0x7f);
9189 /* More bytes to follow. */
9197 /* Checksum the context of the DIE. This adds the names of any
9198 surrounding namespaces or structures to the checksum. */
9201 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
9205 int tag = die->die_tag;
9207 if (tag != DW_TAG_namespace
9208 && tag != DW_TAG_structure_type
9209 && tag != DW_TAG_class_type)
9212 name = get_AT_string (die, DW_AT_name);
9214 spec = get_AT_ref (die, DW_AT_specification);
9218 if (die->die_parent != NULL)
9219 checksum_die_context (die->die_parent, ctx);
9221 CHECKSUM_ULEB128 ('C');
9222 CHECKSUM_ULEB128 (tag);
9224 CHECKSUM_STRING (name);
9227 /* Calculate the checksum of a location expression. */
9230 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
9232 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
9233 were emitted as a DW_FORM_sdata instead of a location expression. */
9234 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
9236 CHECKSUM_ULEB128 (DW_FORM_sdata);
9237 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
9241 /* Otherwise, just checksum the raw location expression. */
9244 CHECKSUM_ULEB128 (loc->dw_loc_opc);
9245 CHECKSUM (loc->dw_loc_oprnd1);
9246 CHECKSUM (loc->dw_loc_oprnd2);
9247 loc = loc->dw_loc_next;
9251 /* Calculate the checksum of an attribute. */
9254 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
9255 struct md5_ctx *ctx, int *mark)
9257 dw_loc_descr_ref loc;
9260 if (AT_class (at) == dw_val_class_die_ref)
9262 dw_die_ref target_die = AT_ref (at);
9264 /* For pointer and reference types, we checksum only the (qualified)
9265 name of the target type (if there is a name). For friend entries,
9266 we checksum only the (qualified) name of the target type or function.
9267 This allows the checksum to remain the same whether the target type
9268 is complete or not. */
9269 if ((at->dw_attr == DW_AT_type
9270 && (tag == DW_TAG_pointer_type
9271 || tag == DW_TAG_reference_type
9272 || tag == DW_TAG_rvalue_reference_type
9273 || tag == DW_TAG_ptr_to_member_type))
9274 || (at->dw_attr == DW_AT_friend
9275 && tag == DW_TAG_friend))
9277 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
9279 if (name_attr != NULL)
9281 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9285 CHECKSUM_ULEB128 ('N');
9286 CHECKSUM_ULEB128 (at->dw_attr);
9287 if (decl->die_parent != NULL)
9288 checksum_die_context (decl->die_parent, ctx);
9289 CHECKSUM_ULEB128 ('E');
9290 CHECKSUM_STRING (AT_string (name_attr));
9295 /* For all other references to another DIE, we check to see if the
9296 target DIE has already been visited. If it has, we emit a
9297 backward reference; if not, we descend recursively. */
9298 if (target_die->die_mark > 0)
9300 CHECKSUM_ULEB128 ('R');
9301 CHECKSUM_ULEB128 (at->dw_attr);
9302 CHECKSUM_ULEB128 (target_die->die_mark);
9306 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9310 target_die->die_mark = ++(*mark);
9311 CHECKSUM_ULEB128 ('T');
9312 CHECKSUM_ULEB128 (at->dw_attr);
9313 if (decl->die_parent != NULL)
9314 checksum_die_context (decl->die_parent, ctx);
9315 die_checksum_ordered (target_die, ctx, mark);
9320 CHECKSUM_ULEB128 ('A');
9321 CHECKSUM_ULEB128 (at->dw_attr);
9323 switch (AT_class (at))
9325 case dw_val_class_const:
9326 CHECKSUM_ULEB128 (DW_FORM_sdata);
9327 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9330 case dw_val_class_unsigned_const:
9331 CHECKSUM_ULEB128 (DW_FORM_sdata);
9332 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9335 case dw_val_class_const_double:
9336 CHECKSUM_ULEB128 (DW_FORM_block);
9337 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9338 CHECKSUM (at->dw_attr_val.v.val_double);
9341 case dw_val_class_vec:
9342 CHECKSUM_ULEB128 (DW_FORM_block);
9343 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9344 CHECKSUM (at->dw_attr_val.v.val_vec);
9347 case dw_val_class_flag:
9348 CHECKSUM_ULEB128 (DW_FORM_flag);
9349 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9352 case dw_val_class_str:
9353 CHECKSUM_ULEB128 (DW_FORM_string);
9354 CHECKSUM_STRING (AT_string (at));
9357 case dw_val_class_addr:
9359 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9360 CHECKSUM_ULEB128 (DW_FORM_string);
9361 CHECKSUM_STRING (XSTR (r, 0));
9364 case dw_val_class_offset:
9365 CHECKSUM_ULEB128 (DW_FORM_sdata);
9366 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9369 case dw_val_class_loc:
9370 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9371 loc_checksum_ordered (loc, ctx);
9374 case dw_val_class_fde_ref:
9375 case dw_val_class_lbl_id:
9376 case dw_val_class_lineptr:
9377 case dw_val_class_macptr:
9380 case dw_val_class_file:
9381 CHECKSUM_ULEB128 (DW_FORM_string);
9382 CHECKSUM_STRING (AT_file (at)->filename);
9385 case dw_val_class_data8:
9386 CHECKSUM (at->dw_attr_val.v.val_data8);
9394 struct checksum_attributes
9396 dw_attr_ref at_name;
9397 dw_attr_ref at_type;
9398 dw_attr_ref at_friend;
9399 dw_attr_ref at_accessibility;
9400 dw_attr_ref at_address_class;
9401 dw_attr_ref at_allocated;
9402 dw_attr_ref at_artificial;
9403 dw_attr_ref at_associated;
9404 dw_attr_ref at_binary_scale;
9405 dw_attr_ref at_bit_offset;
9406 dw_attr_ref at_bit_size;
9407 dw_attr_ref at_bit_stride;
9408 dw_attr_ref at_byte_size;
9409 dw_attr_ref at_byte_stride;
9410 dw_attr_ref at_const_value;
9411 dw_attr_ref at_containing_type;
9412 dw_attr_ref at_count;
9413 dw_attr_ref at_data_location;
9414 dw_attr_ref at_data_member_location;
9415 dw_attr_ref at_decimal_scale;
9416 dw_attr_ref at_decimal_sign;
9417 dw_attr_ref at_default_value;
9418 dw_attr_ref at_digit_count;
9419 dw_attr_ref at_discr;
9420 dw_attr_ref at_discr_list;
9421 dw_attr_ref at_discr_value;
9422 dw_attr_ref at_encoding;
9423 dw_attr_ref at_endianity;
9424 dw_attr_ref at_explicit;
9425 dw_attr_ref at_is_optional;
9426 dw_attr_ref at_location;
9427 dw_attr_ref at_lower_bound;
9428 dw_attr_ref at_mutable;
9429 dw_attr_ref at_ordering;
9430 dw_attr_ref at_picture_string;
9431 dw_attr_ref at_prototyped;
9432 dw_attr_ref at_small;
9433 dw_attr_ref at_segment;
9434 dw_attr_ref at_string_length;
9435 dw_attr_ref at_threads_scaled;
9436 dw_attr_ref at_upper_bound;
9437 dw_attr_ref at_use_location;
9438 dw_attr_ref at_use_UTF8;
9439 dw_attr_ref at_variable_parameter;
9440 dw_attr_ref at_virtuality;
9441 dw_attr_ref at_visibility;
9442 dw_attr_ref at_vtable_elem_location;
9445 /* Collect the attributes that we will want to use for the checksum. */
9448 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9453 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9464 attrs->at_friend = a;
9466 case DW_AT_accessibility:
9467 attrs->at_accessibility = a;
9469 case DW_AT_address_class:
9470 attrs->at_address_class = a;
9472 case DW_AT_allocated:
9473 attrs->at_allocated = a;
9475 case DW_AT_artificial:
9476 attrs->at_artificial = a;
9478 case DW_AT_associated:
9479 attrs->at_associated = a;
9481 case DW_AT_binary_scale:
9482 attrs->at_binary_scale = a;
9484 case DW_AT_bit_offset:
9485 attrs->at_bit_offset = a;
9487 case DW_AT_bit_size:
9488 attrs->at_bit_size = a;
9490 case DW_AT_bit_stride:
9491 attrs->at_bit_stride = a;
9493 case DW_AT_byte_size:
9494 attrs->at_byte_size = a;
9496 case DW_AT_byte_stride:
9497 attrs->at_byte_stride = a;
9499 case DW_AT_const_value:
9500 attrs->at_const_value = a;
9502 case DW_AT_containing_type:
9503 attrs->at_containing_type = a;
9506 attrs->at_count = a;
9508 case DW_AT_data_location:
9509 attrs->at_data_location = a;
9511 case DW_AT_data_member_location:
9512 attrs->at_data_member_location = a;
9514 case DW_AT_decimal_scale:
9515 attrs->at_decimal_scale = a;
9517 case DW_AT_decimal_sign:
9518 attrs->at_decimal_sign = a;
9520 case DW_AT_default_value:
9521 attrs->at_default_value = a;
9523 case DW_AT_digit_count:
9524 attrs->at_digit_count = a;
9527 attrs->at_discr = a;
9529 case DW_AT_discr_list:
9530 attrs->at_discr_list = a;
9532 case DW_AT_discr_value:
9533 attrs->at_discr_value = a;
9535 case DW_AT_encoding:
9536 attrs->at_encoding = a;
9538 case DW_AT_endianity:
9539 attrs->at_endianity = a;
9541 case DW_AT_explicit:
9542 attrs->at_explicit = a;
9544 case DW_AT_is_optional:
9545 attrs->at_is_optional = a;
9547 case DW_AT_location:
9548 attrs->at_location = a;
9550 case DW_AT_lower_bound:
9551 attrs->at_lower_bound = a;
9554 attrs->at_mutable = a;
9556 case DW_AT_ordering:
9557 attrs->at_ordering = a;
9559 case DW_AT_picture_string:
9560 attrs->at_picture_string = a;
9562 case DW_AT_prototyped:
9563 attrs->at_prototyped = a;
9566 attrs->at_small = a;
9569 attrs->at_segment = a;
9571 case DW_AT_string_length:
9572 attrs->at_string_length = a;
9574 case DW_AT_threads_scaled:
9575 attrs->at_threads_scaled = a;
9577 case DW_AT_upper_bound:
9578 attrs->at_upper_bound = a;
9580 case DW_AT_use_location:
9581 attrs->at_use_location = a;
9583 case DW_AT_use_UTF8:
9584 attrs->at_use_UTF8 = a;
9586 case DW_AT_variable_parameter:
9587 attrs->at_variable_parameter = a;
9589 case DW_AT_virtuality:
9590 attrs->at_virtuality = a;
9592 case DW_AT_visibility:
9593 attrs->at_visibility = a;
9595 case DW_AT_vtable_elem_location:
9596 attrs->at_vtable_elem_location = a;
9604 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9607 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9611 struct checksum_attributes attrs;
9613 CHECKSUM_ULEB128 ('D');
9614 CHECKSUM_ULEB128 (die->die_tag);
9616 memset (&attrs, 0, sizeof (attrs));
9618 decl = get_AT_ref (die, DW_AT_specification);
9620 collect_checksum_attributes (&attrs, decl);
9621 collect_checksum_attributes (&attrs, die);
9623 CHECKSUM_ATTR (attrs.at_name);
9624 CHECKSUM_ATTR (attrs.at_accessibility);
9625 CHECKSUM_ATTR (attrs.at_address_class);
9626 CHECKSUM_ATTR (attrs.at_allocated);
9627 CHECKSUM_ATTR (attrs.at_artificial);
9628 CHECKSUM_ATTR (attrs.at_associated);
9629 CHECKSUM_ATTR (attrs.at_binary_scale);
9630 CHECKSUM_ATTR (attrs.at_bit_offset);
9631 CHECKSUM_ATTR (attrs.at_bit_size);
9632 CHECKSUM_ATTR (attrs.at_bit_stride);
9633 CHECKSUM_ATTR (attrs.at_byte_size);
9634 CHECKSUM_ATTR (attrs.at_byte_stride);
9635 CHECKSUM_ATTR (attrs.at_const_value);
9636 CHECKSUM_ATTR (attrs.at_containing_type);
9637 CHECKSUM_ATTR (attrs.at_count);
9638 CHECKSUM_ATTR (attrs.at_data_location);
9639 CHECKSUM_ATTR (attrs.at_data_member_location);
9640 CHECKSUM_ATTR (attrs.at_decimal_scale);
9641 CHECKSUM_ATTR (attrs.at_decimal_sign);
9642 CHECKSUM_ATTR (attrs.at_default_value);
9643 CHECKSUM_ATTR (attrs.at_digit_count);
9644 CHECKSUM_ATTR (attrs.at_discr);
9645 CHECKSUM_ATTR (attrs.at_discr_list);
9646 CHECKSUM_ATTR (attrs.at_discr_value);
9647 CHECKSUM_ATTR (attrs.at_encoding);
9648 CHECKSUM_ATTR (attrs.at_endianity);
9649 CHECKSUM_ATTR (attrs.at_explicit);
9650 CHECKSUM_ATTR (attrs.at_is_optional);
9651 CHECKSUM_ATTR (attrs.at_location);
9652 CHECKSUM_ATTR (attrs.at_lower_bound);
9653 CHECKSUM_ATTR (attrs.at_mutable);
9654 CHECKSUM_ATTR (attrs.at_ordering);
9655 CHECKSUM_ATTR (attrs.at_picture_string);
9656 CHECKSUM_ATTR (attrs.at_prototyped);
9657 CHECKSUM_ATTR (attrs.at_small);
9658 CHECKSUM_ATTR (attrs.at_segment);
9659 CHECKSUM_ATTR (attrs.at_string_length);
9660 CHECKSUM_ATTR (attrs.at_threads_scaled);
9661 CHECKSUM_ATTR (attrs.at_upper_bound);
9662 CHECKSUM_ATTR (attrs.at_use_location);
9663 CHECKSUM_ATTR (attrs.at_use_UTF8);
9664 CHECKSUM_ATTR (attrs.at_variable_parameter);
9665 CHECKSUM_ATTR (attrs.at_virtuality);
9666 CHECKSUM_ATTR (attrs.at_visibility);
9667 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9668 CHECKSUM_ATTR (attrs.at_type);
9669 CHECKSUM_ATTR (attrs.at_friend);
9671 /* Checksum the child DIEs, except for nested types and member functions. */
9674 dw_attr_ref name_attr;
9677 name_attr = get_AT (c, DW_AT_name);
9678 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9679 && name_attr != NULL)
9681 CHECKSUM_ULEB128 ('S');
9682 CHECKSUM_ULEB128 (c->die_tag);
9683 CHECKSUM_STRING (AT_string (name_attr));
9687 /* Mark this DIE so it gets processed when unmarking. */
9688 if (c->die_mark == 0)
9690 die_checksum_ordered (c, ctx, mark);
9692 } while (c != die->die_child);
9694 CHECKSUM_ULEB128 (0);
9698 #undef CHECKSUM_STRING
9699 #undef CHECKSUM_ATTR
9700 #undef CHECKSUM_LEB128
9701 #undef CHECKSUM_ULEB128
9703 /* Generate the type signature for DIE. This is computed by generating an
9704 MD5 checksum over the DIE's tag, its relevant attributes, and its
9705 children. Attributes that are references to other DIEs are processed
9706 by recursion, using the MARK field to prevent infinite recursion.
9707 If the DIE is nested inside a namespace or another type, we also
9708 need to include that context in the signature. The lower 64 bits
9709 of the resulting MD5 checksum comprise the signature. */
9712 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9716 unsigned char checksum[16];
9720 name = get_AT_string (die, DW_AT_name);
9721 decl = get_AT_ref (die, DW_AT_specification);
9723 /* First, compute a signature for just the type name (and its surrounding
9724 context, if any. This is stored in the type unit DIE for link-time
9725 ODR (one-definition rule) checking. */
9727 if (is_cxx() && name != NULL)
9729 md5_init_ctx (&ctx);
9731 /* Checksum the names of surrounding namespaces and structures. */
9732 if (decl != NULL && decl->die_parent != NULL)
9733 checksum_die_context (decl->die_parent, &ctx);
9735 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9736 md5_process_bytes (name, strlen (name) + 1, &ctx);
9737 md5_finish_ctx (&ctx, checksum);
9739 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9742 /* Next, compute the complete type signature. */
9744 md5_init_ctx (&ctx);
9746 die->die_mark = mark;
9748 /* Checksum the names of surrounding namespaces and structures. */
9749 if (decl != NULL && decl->die_parent != NULL)
9750 checksum_die_context (decl->die_parent, &ctx);
9752 /* Checksum the DIE and its children. */
9753 die_checksum_ordered (die, &ctx, &mark);
9754 unmark_all_dies (die);
9755 md5_finish_ctx (&ctx, checksum);
9757 /* Store the signature in the type node and link the type DIE and the
9758 type node together. */
9759 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9760 DWARF_TYPE_SIGNATURE_SIZE);
9761 die->die_id.die_type_node = type_node;
9762 type_node->type_die = die;
9764 /* If the DIE is a specification, link its declaration to the type node
9767 decl->die_id.die_type_node = type_node;
9770 /* Do the location expressions look same? */
9772 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9774 return loc1->dw_loc_opc == loc2->dw_loc_opc
9775 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9776 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9779 /* Do the values look the same? */
9781 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9783 dw_loc_descr_ref loc1, loc2;
9786 if (v1->val_class != v2->val_class)
9789 switch (v1->val_class)
9791 case dw_val_class_const:
9792 return v1->v.val_int == v2->v.val_int;
9793 case dw_val_class_unsigned_const:
9794 return v1->v.val_unsigned == v2->v.val_unsigned;
9795 case dw_val_class_const_double:
9796 return v1->v.val_double.high == v2->v.val_double.high
9797 && v1->v.val_double.low == v2->v.val_double.low;
9798 case dw_val_class_vec:
9799 if (v1->v.val_vec.length != v2->v.val_vec.length
9800 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9802 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9803 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9806 case dw_val_class_flag:
9807 return v1->v.val_flag == v2->v.val_flag;
9808 case dw_val_class_str:
9809 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9811 case dw_val_class_addr:
9812 r1 = v1->v.val_addr;
9813 r2 = v2->v.val_addr;
9814 if (GET_CODE (r1) != GET_CODE (r2))
9816 return !rtx_equal_p (r1, r2);
9818 case dw_val_class_offset:
9819 return v1->v.val_offset == v2->v.val_offset;
9821 case dw_val_class_loc:
9822 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9824 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9825 if (!same_loc_p (loc1, loc2, mark))
9827 return !loc1 && !loc2;
9829 case dw_val_class_die_ref:
9830 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9832 case dw_val_class_fde_ref:
9833 case dw_val_class_vms_delta:
9834 case dw_val_class_lbl_id:
9835 case dw_val_class_lineptr:
9836 case dw_val_class_macptr:
9839 case dw_val_class_file:
9840 return v1->v.val_file == v2->v.val_file;
9842 case dw_val_class_data8:
9843 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9850 /* Do the attributes look the same? */
9853 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9855 if (at1->dw_attr != at2->dw_attr)
9858 /* We don't care that this was compiled with a different compiler
9859 snapshot; if the output is the same, that's what matters. */
9860 if (at1->dw_attr == DW_AT_producer)
9863 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9866 /* Do the dies look the same? */
9869 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9875 /* To avoid infinite recursion. */
9877 return die1->die_mark == die2->die_mark;
9878 die1->die_mark = die2->die_mark = ++(*mark);
9880 if (die1->die_tag != die2->die_tag)
9883 if (VEC_length (dw_attr_node, die1->die_attr)
9884 != VEC_length (dw_attr_node, die2->die_attr))
9887 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9888 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9891 c1 = die1->die_child;
9892 c2 = die2->die_child;
9901 if (!same_die_p (c1, c2, mark))
9905 if (c1 == die1->die_child)
9907 if (c2 == die2->die_child)
9917 /* Do the dies look the same? Wrapper around same_die_p. */
9920 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9923 int ret = same_die_p (die1, die2, &mark);
9925 unmark_all_dies (die1);
9926 unmark_all_dies (die2);
9931 /* The prefix to attach to symbols on DIEs in the current comdat debug
9933 static char *comdat_symbol_id;
9935 /* The index of the current symbol within the current comdat CU. */
9936 static unsigned int comdat_symbol_number;
9938 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9939 children, and set comdat_symbol_id accordingly. */
9942 compute_section_prefix (dw_die_ref unit_die)
9944 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9945 const char *base = die_name ? lbasename (die_name) : "anonymous";
9946 char *name = XALLOCAVEC (char, strlen (base) + 64);
9949 unsigned char checksum[16];
9952 /* Compute the checksum of the DIE, then append part of it as hex digits to
9953 the name filename of the unit. */
9955 md5_init_ctx (&ctx);
9957 die_checksum (unit_die, &ctx, &mark);
9958 unmark_all_dies (unit_die);
9959 md5_finish_ctx (&ctx, checksum);
9961 sprintf (name, "%s.", base);
9962 clean_symbol_name (name);
9964 p = name + strlen (name);
9965 for (i = 0; i < 4; i++)
9967 sprintf (p, "%.2x", checksum[i]);
9971 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9972 comdat_symbol_number = 0;
9975 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9978 is_type_die (dw_die_ref die)
9980 switch (die->die_tag)
9982 case DW_TAG_array_type:
9983 case DW_TAG_class_type:
9984 case DW_TAG_interface_type:
9985 case DW_TAG_enumeration_type:
9986 case DW_TAG_pointer_type:
9987 case DW_TAG_reference_type:
9988 case DW_TAG_rvalue_reference_type:
9989 case DW_TAG_string_type:
9990 case DW_TAG_structure_type:
9991 case DW_TAG_subroutine_type:
9992 case DW_TAG_union_type:
9993 case DW_TAG_ptr_to_member_type:
9994 case DW_TAG_set_type:
9995 case DW_TAG_subrange_type:
9996 case DW_TAG_base_type:
9997 case DW_TAG_const_type:
9998 case DW_TAG_file_type:
9999 case DW_TAG_packed_type:
10000 case DW_TAG_volatile_type:
10001 case DW_TAG_typedef:
10008 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
10009 Basically, we want to choose the bits that are likely to be shared between
10010 compilations (types) and leave out the bits that are specific to individual
10011 compilations (functions). */
10014 is_comdat_die (dw_die_ref c)
10016 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
10017 we do for stabs. The advantage is a greater likelihood of sharing between
10018 objects that don't include headers in the same order (and therefore would
10019 put the base types in a different comdat). jason 8/28/00 */
10021 if (c->die_tag == DW_TAG_base_type)
10024 if (c->die_tag == DW_TAG_pointer_type
10025 || c->die_tag == DW_TAG_reference_type
10026 || c->die_tag == DW_TAG_rvalue_reference_type
10027 || c->die_tag == DW_TAG_const_type
10028 || c->die_tag == DW_TAG_volatile_type)
10030 dw_die_ref t = get_AT_ref (c, DW_AT_type);
10032 return t ? is_comdat_die (t) : 0;
10035 return is_type_die (c);
10038 /* Returns 1 iff C is the sort of DIE that might be referred to from another
10039 compilation unit. */
10042 is_symbol_die (dw_die_ref c)
10044 return (is_type_die (c)
10045 || is_declaration_die (c)
10046 || c->die_tag == DW_TAG_namespace
10047 || c->die_tag == DW_TAG_module);
10050 /* Returns true iff C is a compile-unit DIE. */
10053 is_cu_die (dw_die_ref c)
10055 return c && c->die_tag == DW_TAG_compile_unit;
10059 gen_internal_sym (const char *prefix)
10063 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
10064 return xstrdup (buf);
10067 /* Assign symbols to all worthy DIEs under DIE. */
10070 assign_symbol_names (dw_die_ref die)
10074 if (is_symbol_die (die))
10076 if (comdat_symbol_id)
10078 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
10080 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
10081 comdat_symbol_id, comdat_symbol_number++);
10082 die->die_id.die_symbol = xstrdup (p);
10085 die->die_id.die_symbol = gen_internal_sym ("LDIE");
10088 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
10091 struct cu_hash_table_entry
10094 unsigned min_comdat_num, max_comdat_num;
10095 struct cu_hash_table_entry *next;
10098 /* Routines to manipulate hash table of CUs. */
10100 htab_cu_hash (const void *of)
10102 const struct cu_hash_table_entry *const entry =
10103 (const struct cu_hash_table_entry *) of;
10105 return htab_hash_string (entry->cu->die_id.die_symbol);
10109 htab_cu_eq (const void *of1, const void *of2)
10111 const struct cu_hash_table_entry *const entry1 =
10112 (const struct cu_hash_table_entry *) of1;
10113 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10115 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
10119 htab_cu_del (void *what)
10121 struct cu_hash_table_entry *next,
10122 *entry = (struct cu_hash_table_entry *) what;
10126 next = entry->next;
10132 /* Check whether we have already seen this CU and set up SYM_NUM
10135 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
10137 struct cu_hash_table_entry dummy;
10138 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
10140 dummy.max_comdat_num = 0;
10142 slot = (struct cu_hash_table_entry **)
10143 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
10147 for (; entry; last = entry, entry = entry->next)
10149 if (same_die_p_wrap (cu, entry->cu))
10155 *sym_num = entry->min_comdat_num;
10159 entry = XCNEW (struct cu_hash_table_entry);
10161 entry->min_comdat_num = *sym_num = last->max_comdat_num;
10162 entry->next = *slot;
10168 /* Record SYM_NUM to record of CU in HTABLE. */
10170 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
10172 struct cu_hash_table_entry **slot, *entry;
10174 slot = (struct cu_hash_table_entry **)
10175 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
10179 entry->max_comdat_num = sym_num;
10182 /* Traverse the DIE (which is always comp_unit_die), and set up
10183 additional compilation units for each of the include files we see
10184 bracketed by BINCL/EINCL. */
10187 break_out_includes (dw_die_ref die)
10190 dw_die_ref unit = NULL;
10191 limbo_die_node *node, **pnode;
10192 htab_t cu_hash_table;
10194 c = die->die_child;
10196 dw_die_ref prev = c;
10198 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
10199 || (unit && is_comdat_die (c)))
10201 dw_die_ref next = c->die_sib;
10203 /* This DIE is for a secondary CU; remove it from the main one. */
10204 remove_child_with_prev (c, prev);
10206 if (c->die_tag == DW_TAG_GNU_BINCL)
10207 unit = push_new_compile_unit (unit, c);
10208 else if (c->die_tag == DW_TAG_GNU_EINCL)
10209 unit = pop_compile_unit (unit);
10211 add_child_die (unit, c);
10213 if (c == die->die_child)
10216 } while (c != die->die_child);
10219 /* We can only use this in debugging, since the frontend doesn't check
10220 to make sure that we leave every include file we enter. */
10221 gcc_assert (!unit);
10224 assign_symbol_names (die);
10225 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
10226 for (node = limbo_die_list, pnode = &limbo_die_list;
10232 compute_section_prefix (node->die);
10233 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
10234 &comdat_symbol_number);
10235 assign_symbol_names (node->die);
10237 *pnode = node->next;
10240 pnode = &node->next;
10241 record_comdat_symbol_number (node->die, cu_hash_table,
10242 comdat_symbol_number);
10245 htab_delete (cu_hash_table);
10248 /* Return non-zero if this DIE is a declaration. */
10251 is_declaration_die (dw_die_ref die)
10256 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10257 if (a->dw_attr == DW_AT_declaration)
10263 /* Return non-zero if this DIE is nested inside a subprogram. */
10266 is_nested_in_subprogram (dw_die_ref die)
10268 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
10272 return local_scope_p (decl);
10275 /* Return non-zero if this DIE contains a defining declaration of a
10279 contains_subprogram_definition (dw_die_ref die)
10283 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
10285 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
10289 /* Return non-zero if this is a type DIE that should be moved to a
10290 COMDAT .debug_types section. */
10293 should_move_die_to_comdat (dw_die_ref die)
10295 switch (die->die_tag)
10297 case DW_TAG_class_type:
10298 case DW_TAG_structure_type:
10299 case DW_TAG_enumeration_type:
10300 case DW_TAG_union_type:
10301 /* Don't move declarations, inlined instances, or types nested in a
10303 if (is_declaration_die (die)
10304 || get_AT (die, DW_AT_abstract_origin)
10305 || is_nested_in_subprogram (die))
10307 /* A type definition should never contain a subprogram definition. */
10308 gcc_assert (!contains_subprogram_definition (die));
10310 case DW_TAG_array_type:
10311 case DW_TAG_interface_type:
10312 case DW_TAG_pointer_type:
10313 case DW_TAG_reference_type:
10314 case DW_TAG_rvalue_reference_type:
10315 case DW_TAG_string_type:
10316 case DW_TAG_subroutine_type:
10317 case DW_TAG_ptr_to_member_type:
10318 case DW_TAG_set_type:
10319 case DW_TAG_subrange_type:
10320 case DW_TAG_base_type:
10321 case DW_TAG_const_type:
10322 case DW_TAG_file_type:
10323 case DW_TAG_packed_type:
10324 case DW_TAG_volatile_type:
10325 case DW_TAG_typedef:
10331 /* Make a clone of DIE. */
10334 clone_die (dw_die_ref die)
10340 clone = ggc_alloc_cleared_die_node ();
10341 clone->die_tag = die->die_tag;
10343 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10344 add_dwarf_attr (clone, a);
10349 /* Make a clone of the tree rooted at DIE. */
10352 clone_tree (dw_die_ref die)
10355 dw_die_ref clone = clone_die (die);
10357 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10362 /* Make a clone of DIE as a declaration. */
10365 clone_as_declaration (dw_die_ref die)
10372 /* If the DIE is already a declaration, just clone it. */
10373 if (is_declaration_die (die))
10374 return clone_die (die);
10376 /* If the DIE is a specification, just clone its declaration DIE. */
10377 decl = get_AT_ref (die, DW_AT_specification);
10379 return clone_die (decl);
10381 clone = ggc_alloc_cleared_die_node ();
10382 clone->die_tag = die->die_tag;
10384 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10386 /* We don't want to copy over all attributes.
10387 For example we don't want DW_AT_byte_size because otherwise we will no
10388 longer have a declaration and GDB will treat it as a definition. */
10390 switch (a->dw_attr)
10392 case DW_AT_artificial:
10393 case DW_AT_containing_type:
10394 case DW_AT_external:
10397 case DW_AT_virtuality:
10398 case DW_AT_linkage_name:
10399 case DW_AT_MIPS_linkage_name:
10400 add_dwarf_attr (clone, a);
10402 case DW_AT_byte_size:
10408 if (die->die_id.die_type_node)
10409 add_AT_die_ref (clone, DW_AT_signature, die);
10411 add_AT_flag (clone, DW_AT_declaration, 1);
10415 /* Copy the declaration context to the new compile unit DIE. This includes
10416 any surrounding namespace or type declarations. If the DIE has an
10417 AT_specification attribute, it also includes attributes and children
10418 attached to the specification. */
10421 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10424 dw_die_ref new_decl;
10426 decl = get_AT_ref (die, DW_AT_specification);
10435 /* Copy the type node pointer from the new DIE to the original
10436 declaration DIE so we can forward references later. */
10437 decl->die_id.die_type_node = die->die_id.die_type_node;
10439 remove_AT (die, DW_AT_specification);
10441 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10443 if (a->dw_attr != DW_AT_name
10444 && a->dw_attr != DW_AT_declaration
10445 && a->dw_attr != DW_AT_external)
10446 add_dwarf_attr (die, a);
10449 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10452 if (decl->die_parent != NULL
10453 && decl->die_parent->die_tag != DW_TAG_compile_unit
10454 && decl->die_parent->die_tag != DW_TAG_type_unit)
10456 new_decl = copy_ancestor_tree (unit, decl, NULL);
10457 if (new_decl != NULL)
10459 remove_AT (new_decl, DW_AT_signature);
10460 add_AT_specification (die, new_decl);
10465 /* Generate the skeleton ancestor tree for the given NODE, then clone
10466 the DIE and add the clone into the tree. */
10469 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10471 if (node->new_die != NULL)
10474 node->new_die = clone_as_declaration (node->old_die);
10476 if (node->parent != NULL)
10478 generate_skeleton_ancestor_tree (node->parent);
10479 add_child_die (node->parent->new_die, node->new_die);
10483 /* Generate a skeleton tree of DIEs containing any declarations that are
10484 found in the original tree. We traverse the tree looking for declaration
10485 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10488 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10490 skeleton_chain_node node;
10493 dw_die_ref prev = NULL;
10494 dw_die_ref next = NULL;
10496 node.parent = parent;
10498 first = c = parent->old_die->die_child;
10502 if (prev == NULL || prev->die_sib == c)
10505 next = (c == first ? NULL : c->die_sib);
10507 node.new_die = NULL;
10508 if (is_declaration_die (c))
10510 /* Clone the existing DIE, move the original to the skeleton
10511 tree (which is in the main CU), and put the clone, with
10512 all the original's children, where the original came from. */
10513 dw_die_ref clone = clone_die (c);
10514 move_all_children (c, clone);
10516 replace_child (c, clone, prev);
10517 generate_skeleton_ancestor_tree (parent);
10518 add_child_die (parent->new_die, c);
10522 generate_skeleton_bottom_up (&node);
10523 } while (next != NULL);
10526 /* Wrapper function for generate_skeleton_bottom_up. */
10529 generate_skeleton (dw_die_ref die)
10531 skeleton_chain_node node;
10533 node.old_die = die;
10534 node.new_die = NULL;
10535 node.parent = NULL;
10537 /* If this type definition is nested inside another type,
10538 always leave at least a declaration in its place. */
10539 if (die->die_parent != NULL && is_type_die (die->die_parent))
10540 node.new_die = clone_as_declaration (die);
10542 generate_skeleton_bottom_up (&node);
10543 return node.new_die;
10546 /* Remove the DIE from its parent, possibly replacing it with a cloned
10547 declaration. The original DIE will be moved to a new compile unit
10548 so that existing references to it follow it to the new location. If
10549 any of the original DIE's descendants is a declaration, we need to
10550 replace the original DIE with a skeleton tree and move the
10551 declarations back into the skeleton tree. */
10554 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10556 dw_die_ref skeleton;
10558 skeleton = generate_skeleton (child);
10559 if (skeleton == NULL)
10560 remove_child_with_prev (child, prev);
10563 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10564 replace_child (child, skeleton, prev);
10570 /* Traverse the DIE and set up additional .debug_types sections for each
10571 type worthy of being placed in a COMDAT section. */
10574 break_out_comdat_types (dw_die_ref die)
10578 dw_die_ref prev = NULL;
10579 dw_die_ref next = NULL;
10580 dw_die_ref unit = NULL;
10582 first = c = die->die_child;
10586 if (prev == NULL || prev->die_sib == c)
10589 next = (c == first ? NULL : c->die_sib);
10590 if (should_move_die_to_comdat (c))
10592 dw_die_ref replacement;
10593 comdat_type_node_ref type_node;
10595 /* Create a new type unit DIE as the root for the new tree, and
10596 add it to the list of comdat types. */
10597 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10598 add_AT_unsigned (unit, DW_AT_language,
10599 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10600 type_node = ggc_alloc_cleared_comdat_type_node ();
10601 type_node->root_die = unit;
10602 type_node->next = comdat_type_list;
10603 comdat_type_list = type_node;
10605 /* Generate the type signature. */
10606 generate_type_signature (c, type_node);
10608 /* Copy the declaration context, attributes, and children of the
10609 declaration into the new compile unit DIE. */
10610 copy_declaration_context (unit, c);
10612 /* Remove this DIE from the main CU. */
10613 replacement = remove_child_or_replace_with_skeleton (c, prev);
10615 /* Break out nested types into their own type units. */
10616 break_out_comdat_types (c);
10618 /* Add the DIE to the new compunit. */
10619 add_child_die (unit, c);
10621 if (replacement != NULL)
10624 else if (c->die_tag == DW_TAG_namespace
10625 || c->die_tag == DW_TAG_class_type
10626 || c->die_tag == DW_TAG_structure_type
10627 || c->die_tag == DW_TAG_union_type)
10629 /* Look for nested types that can be broken out. */
10630 break_out_comdat_types (c);
10632 } while (next != NULL);
10635 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10637 struct decl_table_entry
10643 /* Routines to manipulate hash table of copied declarations. */
10646 htab_decl_hash (const void *of)
10648 const struct decl_table_entry *const entry =
10649 (const struct decl_table_entry *) of;
10651 return htab_hash_pointer (entry->orig);
10655 htab_decl_eq (const void *of1, const void *of2)
10657 const struct decl_table_entry *const entry1 =
10658 (const struct decl_table_entry *) of1;
10659 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10661 return entry1->orig == entry2;
10665 htab_decl_del (void *what)
10667 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10672 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10673 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10674 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10675 to check if the ancestor has already been copied into UNIT. */
10678 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10680 dw_die_ref parent = die->die_parent;
10681 dw_die_ref new_parent = unit;
10683 void **slot = NULL;
10684 struct decl_table_entry *entry = NULL;
10688 /* Check if the entry has already been copied to UNIT. */
10689 slot = htab_find_slot_with_hash (decl_table, die,
10690 htab_hash_pointer (die), INSERT);
10691 if (*slot != HTAB_EMPTY_ENTRY)
10693 entry = (struct decl_table_entry *) *slot;
10694 return entry->copy;
10697 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10698 entry = XCNEW (struct decl_table_entry);
10700 entry->copy = NULL;
10704 if (parent != NULL)
10706 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10709 if (parent->die_tag != DW_TAG_compile_unit
10710 && parent->die_tag != DW_TAG_type_unit)
10711 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10714 copy = clone_as_declaration (die);
10715 add_child_die (new_parent, copy);
10717 if (decl_table != NULL)
10719 /* Record the pointer to the copy. */
10720 entry->copy = copy;
10726 /* Walk the DIE and its children, looking for references to incomplete
10727 or trivial types that are unmarked (i.e., that are not in the current
10731 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10737 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10739 if (AT_class (a) == dw_val_class_die_ref)
10741 dw_die_ref targ = AT_ref (a);
10742 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10744 struct decl_table_entry *entry;
10746 if (targ->die_mark != 0 || type_node != NULL)
10749 slot = htab_find_slot_with_hash (decl_table, targ,
10750 htab_hash_pointer (targ), INSERT);
10752 if (*slot != HTAB_EMPTY_ENTRY)
10754 /* TARG has already been copied, so we just need to
10755 modify the reference to point to the copy. */
10756 entry = (struct decl_table_entry *) *slot;
10757 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10761 dw_die_ref parent = unit;
10762 dw_die_ref copy = clone_tree (targ);
10764 /* Make sure the cloned tree is marked as part of the
10768 /* Record in DECL_TABLE that TARG has been copied.
10769 Need to do this now, before the recursive call,
10770 because DECL_TABLE may be expanded and SLOT
10771 would no longer be a valid pointer. */
10772 entry = XCNEW (struct decl_table_entry);
10773 entry->orig = targ;
10774 entry->copy = copy;
10777 /* If TARG has surrounding context, copy its ancestor tree
10778 into the new type unit. */
10779 if (targ->die_parent != NULL
10780 && targ->die_parent->die_tag != DW_TAG_compile_unit
10781 && targ->die_parent->die_tag != DW_TAG_type_unit)
10782 parent = copy_ancestor_tree (unit, targ->die_parent,
10785 add_child_die (parent, copy);
10786 a->dw_attr_val.v.val_die_ref.die = copy;
10788 /* Make sure the newly-copied DIE is walked. If it was
10789 installed in a previously-added context, it won't
10790 get visited otherwise. */
10791 if (parent != unit)
10793 /* Find the highest point of the newly-added tree,
10794 mark each node along the way, and walk from there. */
10795 parent->die_mark = 1;
10796 while (parent->die_parent
10797 && parent->die_parent->die_mark == 0)
10799 parent = parent->die_parent;
10800 parent->die_mark = 1;
10802 copy_decls_walk (unit, parent, decl_table);
10808 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10811 /* Copy declarations for "unworthy" types into the new comdat section.
10812 Incomplete types, modified types, and certain other types aren't broken
10813 out into comdat sections of their own, so they don't have a signature,
10814 and we need to copy the declaration into the same section so that we
10815 don't have an external reference. */
10818 copy_decls_for_unworthy_types (dw_die_ref unit)
10823 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10824 copy_decls_walk (unit, unit, decl_table);
10825 htab_delete (decl_table);
10826 unmark_dies (unit);
10829 /* Traverse the DIE and add a sibling attribute if it may have the
10830 effect of speeding up access to siblings. To save some space,
10831 avoid generating sibling attributes for DIE's without children. */
10834 add_sibling_attributes (dw_die_ref die)
10838 if (! die->die_child)
10841 if (die->die_parent && die != die->die_parent->die_child)
10842 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10844 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10847 /* Output all location lists for the DIE and its children. */
10850 output_location_lists (dw_die_ref die)
10856 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10857 if (AT_class (a) == dw_val_class_loc_list)
10858 output_loc_list (AT_loc_list (a));
10860 FOR_EACH_CHILD (die, c, output_location_lists (c));
10863 /* The format of each DIE (and its attribute value pairs) is encoded in an
10864 abbreviation table. This routine builds the abbreviation table and assigns
10865 a unique abbreviation id for each abbreviation entry. The children of each
10866 die are visited recursively. */
10869 build_abbrev_table (dw_die_ref die)
10871 unsigned long abbrev_id;
10872 unsigned int n_alloc;
10877 /* Scan the DIE references, and mark as external any that refer to
10878 DIEs from other CUs (i.e. those which are not marked). */
10879 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10880 if (AT_class (a) == dw_val_class_die_ref
10881 && AT_ref (a)->die_mark == 0)
10883 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
10884 set_AT_ref_external (a, 1);
10887 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10889 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10890 dw_attr_ref die_a, abbrev_a;
10894 if (abbrev->die_tag != die->die_tag)
10896 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10899 if (VEC_length (dw_attr_node, abbrev->die_attr)
10900 != VEC_length (dw_attr_node, die->die_attr))
10903 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10905 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10906 if ((abbrev_a->dw_attr != die_a->dw_attr)
10907 || (value_format (abbrev_a) != value_format (die_a)))
10917 if (abbrev_id >= abbrev_die_table_in_use)
10919 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10921 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10922 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10925 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10926 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10927 abbrev_die_table_allocated = n_alloc;
10930 ++abbrev_die_table_in_use;
10931 abbrev_die_table[abbrev_id] = die;
10934 die->die_abbrev = abbrev_id;
10935 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10938 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10941 constant_size (unsigned HOST_WIDE_INT value)
10948 log = floor_log2 (value);
10951 log = 1 << (floor_log2 (log) + 1);
10956 /* Return the size of a DIE as it is represented in the
10957 .debug_info section. */
10959 static unsigned long
10960 size_of_die (dw_die_ref die)
10962 unsigned long size = 0;
10966 size += size_of_uleb128 (die->die_abbrev);
10967 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10969 switch (AT_class (a))
10971 case dw_val_class_addr:
10972 size += DWARF2_ADDR_SIZE;
10974 case dw_val_class_offset:
10975 size += DWARF_OFFSET_SIZE;
10977 case dw_val_class_loc:
10979 unsigned long lsize = size_of_locs (AT_loc (a));
10981 /* Block length. */
10982 if (dwarf_version >= 4)
10983 size += size_of_uleb128 (lsize);
10985 size += constant_size (lsize);
10989 case dw_val_class_loc_list:
10990 size += DWARF_OFFSET_SIZE;
10992 case dw_val_class_range_list:
10993 size += DWARF_OFFSET_SIZE;
10995 case dw_val_class_const:
10996 size += size_of_sleb128 (AT_int (a));
10998 case dw_val_class_unsigned_const:
10999 size += constant_size (AT_unsigned (a));
11001 case dw_val_class_const_double:
11002 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
11003 if (HOST_BITS_PER_WIDE_INT >= 64)
11004 size++; /* block */
11006 case dw_val_class_vec:
11007 size += constant_size (a->dw_attr_val.v.val_vec.length
11008 * a->dw_attr_val.v.val_vec.elt_size)
11009 + a->dw_attr_val.v.val_vec.length
11010 * a->dw_attr_val.v.val_vec.elt_size; /* block */
11012 case dw_val_class_flag:
11013 if (dwarf_version >= 4)
11014 /* Currently all add_AT_flag calls pass in 1 as last argument,
11015 so DW_FORM_flag_present can be used. If that ever changes,
11016 we'll need to use DW_FORM_flag and have some optimization
11017 in build_abbrev_table that will change those to
11018 DW_FORM_flag_present if it is set to 1 in all DIEs using
11019 the same abbrev entry. */
11020 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11024 case dw_val_class_die_ref:
11025 if (AT_ref_external (a))
11027 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
11028 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
11029 is sized by target address length, whereas in DWARF3
11030 it's always sized as an offset. */
11031 if (use_debug_types)
11032 size += DWARF_TYPE_SIGNATURE_SIZE;
11033 else if (dwarf_version == 2)
11034 size += DWARF2_ADDR_SIZE;
11036 size += DWARF_OFFSET_SIZE;
11039 size += DWARF_OFFSET_SIZE;
11041 case dw_val_class_fde_ref:
11042 size += DWARF_OFFSET_SIZE;
11044 case dw_val_class_lbl_id:
11045 size += DWARF2_ADDR_SIZE;
11047 case dw_val_class_lineptr:
11048 case dw_val_class_macptr:
11049 size += DWARF_OFFSET_SIZE;
11051 case dw_val_class_str:
11052 if (AT_string_form (a) == DW_FORM_strp)
11053 size += DWARF_OFFSET_SIZE;
11055 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
11057 case dw_val_class_file:
11058 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
11060 case dw_val_class_data8:
11063 case dw_val_class_vms_delta:
11064 size += DWARF_OFFSET_SIZE;
11067 gcc_unreachable ();
11074 /* Size the debugging information associated with a given DIE. Visits the
11075 DIE's children recursively. Updates the global variable next_die_offset, on
11076 each time through. Uses the current value of next_die_offset to update the
11077 die_offset field in each DIE. */
11080 calc_die_sizes (dw_die_ref die)
11084 gcc_assert (die->die_offset == 0
11085 || (unsigned long int) die->die_offset == next_die_offset);
11086 die->die_offset = next_die_offset;
11087 next_die_offset += size_of_die (die);
11089 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
11091 if (die->die_child != NULL)
11092 /* Count the null byte used to terminate sibling lists. */
11093 next_die_offset += 1;
11096 /* Size just the base type children at the start of the CU.
11097 This is needed because build_abbrev needs to size locs
11098 and sizing of type based stack ops needs to know die_offset
11099 values for the base types. */
11102 calc_base_type_die_sizes (void)
11104 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11106 dw_die_ref base_type;
11107 #if ENABLE_ASSERT_CHECKING
11108 dw_die_ref prev = comp_unit_die ()->die_child;
11111 die_offset += size_of_die (comp_unit_die ());
11112 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
11114 #if ENABLE_ASSERT_CHECKING
11115 gcc_assert (base_type->die_offset == 0
11116 && prev->die_sib == base_type
11117 && base_type->die_child == NULL
11118 && base_type->die_abbrev);
11121 base_type->die_offset = die_offset;
11122 die_offset += size_of_die (base_type);
11126 /* Set the marks for a die and its children. We do this so
11127 that we know whether or not a reference needs to use FORM_ref_addr; only
11128 DIEs in the same CU will be marked. We used to clear out the offset
11129 and use that as the flag, but ran into ordering problems. */
11132 mark_dies (dw_die_ref die)
11136 gcc_assert (!die->die_mark);
11139 FOR_EACH_CHILD (die, c, mark_dies (c));
11142 /* Clear the marks for a die and its children. */
11145 unmark_dies (dw_die_ref die)
11149 if (! use_debug_types)
11150 gcc_assert (die->die_mark);
11153 FOR_EACH_CHILD (die, c, unmark_dies (c));
11156 /* Clear the marks for a die, its children and referred dies. */
11159 unmark_all_dies (dw_die_ref die)
11165 if (!die->die_mark)
11169 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
11171 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11172 if (AT_class (a) == dw_val_class_die_ref)
11173 unmark_all_dies (AT_ref (a));
11176 /* Return the size of the .debug_pubnames or .debug_pubtypes table
11177 generated for the compilation unit. */
11179 static unsigned long
11180 size_of_pubnames (VEC (pubname_entry, gc) * names)
11182 unsigned long size;
11186 size = DWARF_PUBNAMES_HEADER_SIZE;
11187 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
11188 if (names != pubtype_table
11189 || p->die->die_offset != 0
11190 || !flag_eliminate_unused_debug_types)
11191 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
11193 size += DWARF_OFFSET_SIZE;
11197 /* Return the size of the information in the .debug_aranges section. */
11199 static unsigned long
11200 size_of_aranges (void)
11202 unsigned long size;
11204 size = DWARF_ARANGES_HEADER_SIZE;
11206 /* Count the address/length pair for this compilation unit. */
11207 if (text_section_used)
11208 size += 2 * DWARF2_ADDR_SIZE;
11209 if (cold_text_section_used)
11210 size += 2 * DWARF2_ADDR_SIZE;
11211 if (have_multiple_function_sections)
11213 unsigned fde_idx = 0;
11215 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
11217 dw_fde_ref fde = &fde_table[fde_idx];
11219 if (!fde->in_std_section)
11220 size += 2 * DWARF2_ADDR_SIZE;
11221 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11222 size += 2 * DWARF2_ADDR_SIZE;
11226 /* Count the two zero words used to terminated the address range table. */
11227 size += 2 * DWARF2_ADDR_SIZE;
11231 /* Select the encoding of an attribute value. */
11233 static enum dwarf_form
11234 value_format (dw_attr_ref a)
11236 switch (a->dw_attr_val.val_class)
11238 case dw_val_class_addr:
11239 /* Only very few attributes allow DW_FORM_addr. */
11240 switch (a->dw_attr)
11243 case DW_AT_high_pc:
11244 case DW_AT_entry_pc:
11245 case DW_AT_trampoline:
11246 return DW_FORM_addr;
11250 switch (DWARF2_ADDR_SIZE)
11253 return DW_FORM_data1;
11255 return DW_FORM_data2;
11257 return DW_FORM_data4;
11259 return DW_FORM_data8;
11261 gcc_unreachable ();
11263 case dw_val_class_range_list:
11264 case dw_val_class_loc_list:
11265 if (dwarf_version >= 4)
11266 return DW_FORM_sec_offset;
11268 case dw_val_class_vms_delta:
11269 case dw_val_class_offset:
11270 switch (DWARF_OFFSET_SIZE)
11273 return DW_FORM_data4;
11275 return DW_FORM_data8;
11277 gcc_unreachable ();
11279 case dw_val_class_loc:
11280 if (dwarf_version >= 4)
11281 return DW_FORM_exprloc;
11282 switch (constant_size (size_of_locs (AT_loc (a))))
11285 return DW_FORM_block1;
11287 return DW_FORM_block2;
11289 gcc_unreachable ();
11291 case dw_val_class_const:
11292 return DW_FORM_sdata;
11293 case dw_val_class_unsigned_const:
11294 switch (constant_size (AT_unsigned (a)))
11297 return DW_FORM_data1;
11299 return DW_FORM_data2;
11301 return DW_FORM_data4;
11303 return DW_FORM_data8;
11305 gcc_unreachable ();
11307 case dw_val_class_const_double:
11308 switch (HOST_BITS_PER_WIDE_INT)
11311 return DW_FORM_data2;
11313 return DW_FORM_data4;
11315 return DW_FORM_data8;
11318 return DW_FORM_block1;
11320 case dw_val_class_vec:
11321 switch (constant_size (a->dw_attr_val.v.val_vec.length
11322 * a->dw_attr_val.v.val_vec.elt_size))
11325 return DW_FORM_block1;
11327 return DW_FORM_block2;
11329 return DW_FORM_block4;
11331 gcc_unreachable ();
11333 case dw_val_class_flag:
11334 if (dwarf_version >= 4)
11336 /* Currently all add_AT_flag calls pass in 1 as last argument,
11337 so DW_FORM_flag_present can be used. If that ever changes,
11338 we'll need to use DW_FORM_flag and have some optimization
11339 in build_abbrev_table that will change those to
11340 DW_FORM_flag_present if it is set to 1 in all DIEs using
11341 the same abbrev entry. */
11342 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11343 return DW_FORM_flag_present;
11345 return DW_FORM_flag;
11346 case dw_val_class_die_ref:
11347 if (AT_ref_external (a))
11348 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
11350 return DW_FORM_ref;
11351 case dw_val_class_fde_ref:
11352 return DW_FORM_data;
11353 case dw_val_class_lbl_id:
11354 return DW_FORM_addr;
11355 case dw_val_class_lineptr:
11356 case dw_val_class_macptr:
11357 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11358 case dw_val_class_str:
11359 return AT_string_form (a);
11360 case dw_val_class_file:
11361 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11364 return DW_FORM_data1;
11366 return DW_FORM_data2;
11368 return DW_FORM_data4;
11370 gcc_unreachable ();
11373 case dw_val_class_data8:
11374 return DW_FORM_data8;
11377 gcc_unreachable ();
11381 /* Output the encoding of an attribute value. */
11384 output_value_format (dw_attr_ref a)
11386 enum dwarf_form form = value_format (a);
11388 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11391 /* Output the .debug_abbrev section which defines the DIE abbreviation
11395 output_abbrev_section (void)
11397 unsigned long abbrev_id;
11399 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11401 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11403 dw_attr_ref a_attr;
11405 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11406 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11407 dwarf_tag_name (abbrev->die_tag));
11409 if (abbrev->die_child != NULL)
11410 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11412 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11414 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11417 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11418 dwarf_attr_name (a_attr->dw_attr));
11419 output_value_format (a_attr);
11422 dw2_asm_output_data (1, 0, NULL);
11423 dw2_asm_output_data (1, 0, NULL);
11426 /* Terminate the table. */
11427 dw2_asm_output_data (1, 0, NULL);
11430 /* Output a symbol we can use to refer to this DIE from another CU. */
11433 output_die_symbol (dw_die_ref die)
11435 char *sym = die->die_id.die_symbol;
11440 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11441 /* We make these global, not weak; if the target doesn't support
11442 .linkonce, it doesn't support combining the sections, so debugging
11444 targetm.asm_out.globalize_label (asm_out_file, sym);
11446 ASM_OUTPUT_LABEL (asm_out_file, sym);
11449 /* Return a new location list, given the begin and end range, and the
11452 static inline dw_loc_list_ref
11453 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11454 const char *section)
11456 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11458 retlist->begin = begin;
11459 retlist->end = end;
11460 retlist->expr = expr;
11461 retlist->section = section;
11466 /* Generate a new internal symbol for this location list node, if it
11467 hasn't got one yet. */
11470 gen_llsym (dw_loc_list_ref list)
11472 gcc_assert (!list->ll_symbol);
11473 list->ll_symbol = gen_internal_sym ("LLST");
11476 /* Output the location list given to us. */
11479 output_loc_list (dw_loc_list_ref list_head)
11481 dw_loc_list_ref curr = list_head;
11483 if (list_head->emitted)
11485 list_head->emitted = true;
11487 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11489 /* Walk the location list, and output each range + expression. */
11490 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11492 unsigned long size;
11493 /* Don't output an entry that starts and ends at the same address. */
11494 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
11496 if (!have_multiple_function_sections)
11498 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11499 "Location list begin address (%s)",
11500 list_head->ll_symbol);
11501 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11502 "Location list end address (%s)",
11503 list_head->ll_symbol);
11507 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11508 "Location list begin address (%s)",
11509 list_head->ll_symbol);
11510 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11511 "Location list end address (%s)",
11512 list_head->ll_symbol);
11514 size = size_of_locs (curr->expr);
11516 /* Output the block length for this list of location operations. */
11517 gcc_assert (size <= 0xffff);
11518 dw2_asm_output_data (2, size, "%s", "Location expression size");
11520 output_loc_sequence (curr->expr, -1);
11523 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11524 "Location list terminator begin (%s)",
11525 list_head->ll_symbol);
11526 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11527 "Location list terminator end (%s)",
11528 list_head->ll_symbol);
11531 /* Output a type signature. */
11534 output_signature (const char *sig, const char *name)
11538 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11539 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11542 /* Output the DIE and its attributes. Called recursively to generate
11543 the definitions of each child DIE. */
11546 output_die (dw_die_ref die)
11550 unsigned long size;
11553 /* If someone in another CU might refer to us, set up a symbol for
11554 them to point to. */
11555 if (! use_debug_types && die->die_id.die_symbol)
11556 output_die_symbol (die);
11558 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11559 (unsigned long)die->die_offset,
11560 dwarf_tag_name (die->die_tag));
11562 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11564 const char *name = dwarf_attr_name (a->dw_attr);
11566 switch (AT_class (a))
11568 case dw_val_class_addr:
11569 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11572 case dw_val_class_offset:
11573 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11577 case dw_val_class_range_list:
11579 char *p = strchr (ranges_section_label, '\0');
11581 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11582 a->dw_attr_val.v.val_offset);
11583 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11584 debug_ranges_section, "%s", name);
11589 case dw_val_class_loc:
11590 size = size_of_locs (AT_loc (a));
11592 /* Output the block length for this list of location operations. */
11593 if (dwarf_version >= 4)
11594 dw2_asm_output_data_uleb128 (size, "%s", name);
11596 dw2_asm_output_data (constant_size (size), size, "%s", name);
11598 output_loc_sequence (AT_loc (a), -1);
11601 case dw_val_class_const:
11602 /* ??? It would be slightly more efficient to use a scheme like is
11603 used for unsigned constants below, but gdb 4.x does not sign
11604 extend. Gdb 5.x does sign extend. */
11605 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11608 case dw_val_class_unsigned_const:
11609 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11610 AT_unsigned (a), "%s", name);
11613 case dw_val_class_const_double:
11615 unsigned HOST_WIDE_INT first, second;
11617 if (HOST_BITS_PER_WIDE_INT >= 64)
11618 dw2_asm_output_data (1,
11619 2 * HOST_BITS_PER_WIDE_INT
11620 / HOST_BITS_PER_CHAR,
11623 if (WORDS_BIG_ENDIAN)
11625 first = a->dw_attr_val.v.val_double.high;
11626 second = a->dw_attr_val.v.val_double.low;
11630 first = a->dw_attr_val.v.val_double.low;
11631 second = a->dw_attr_val.v.val_double.high;
11634 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11636 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11641 case dw_val_class_vec:
11643 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11644 unsigned int len = a->dw_attr_val.v.val_vec.length;
11648 dw2_asm_output_data (constant_size (len * elt_size),
11649 len * elt_size, "%s", name);
11650 if (elt_size > sizeof (HOST_WIDE_INT))
11655 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11657 i++, p += elt_size)
11658 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11659 "fp or vector constant word %u", i);
11663 case dw_val_class_flag:
11664 if (dwarf_version >= 4)
11666 /* Currently all add_AT_flag calls pass in 1 as last argument,
11667 so DW_FORM_flag_present can be used. If that ever changes,
11668 we'll need to use DW_FORM_flag and have some optimization
11669 in build_abbrev_table that will change those to
11670 DW_FORM_flag_present if it is set to 1 in all DIEs using
11671 the same abbrev entry. */
11672 gcc_assert (AT_flag (a) == 1);
11673 if (flag_debug_asm)
11674 fprintf (asm_out_file, "\t\t\t%s %s\n",
11675 ASM_COMMENT_START, name);
11678 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11681 case dw_val_class_loc_list:
11683 char *sym = AT_loc_list (a)->ll_symbol;
11686 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11691 case dw_val_class_die_ref:
11692 if (AT_ref_external (a))
11694 if (use_debug_types)
11696 comdat_type_node_ref type_node =
11697 AT_ref (a)->die_id.die_type_node;
11699 gcc_assert (type_node);
11700 output_signature (type_node->signature, name);
11704 char *sym = AT_ref (a)->die_id.die_symbol;
11708 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11709 length, whereas in DWARF3 it's always sized as an
11711 if (dwarf_version == 2)
11712 size = DWARF2_ADDR_SIZE;
11714 size = DWARF_OFFSET_SIZE;
11715 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11721 gcc_assert (AT_ref (a)->die_offset);
11722 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11727 case dw_val_class_fde_ref:
11731 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11732 a->dw_attr_val.v.val_fde_index * 2);
11733 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11738 case dw_val_class_vms_delta:
11739 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11740 AT_vms_delta2 (a), AT_vms_delta1 (a),
11744 case dw_val_class_lbl_id:
11745 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11748 case dw_val_class_lineptr:
11749 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11750 debug_line_section, "%s", name);
11753 case dw_val_class_macptr:
11754 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11755 debug_macinfo_section, "%s", name);
11758 case dw_val_class_str:
11759 if (AT_string_form (a) == DW_FORM_strp)
11760 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11761 a->dw_attr_val.v.val_str->label,
11763 "%s: \"%s\"", name, AT_string (a));
11765 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11768 case dw_val_class_file:
11770 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11772 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11773 a->dw_attr_val.v.val_file->filename);
11777 case dw_val_class_data8:
11781 for (i = 0; i < 8; i++)
11782 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11783 i == 0 ? "%s" : NULL, name);
11788 gcc_unreachable ();
11792 FOR_EACH_CHILD (die, c, output_die (c));
11794 /* Add null byte to terminate sibling list. */
11795 if (die->die_child != NULL)
11796 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11797 (unsigned long) die->die_offset);
11800 /* Output the compilation unit that appears at the beginning of the
11801 .debug_info section, and precedes the DIE descriptions. */
11804 output_compilation_unit_header (void)
11806 int ver = dwarf_version;
11808 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11809 dw2_asm_output_data (4, 0xffffffff,
11810 "Initial length escape value indicating 64-bit DWARF extension");
11811 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11812 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11813 "Length of Compilation Unit Info");
11814 dw2_asm_output_data (2, ver, "DWARF version number");
11815 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11816 debug_abbrev_section,
11817 "Offset Into Abbrev. Section");
11818 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11821 /* Output the compilation unit DIE and its children. */
11824 output_comp_unit (dw_die_ref die, int output_if_empty)
11826 const char *secname;
11827 char *oldsym, *tmp;
11829 /* Unless we are outputting main CU, we may throw away empty ones. */
11830 if (!output_if_empty && die->die_child == NULL)
11833 /* Even if there are no children of this DIE, we must output the information
11834 about the compilation unit. Otherwise, on an empty translation unit, we
11835 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11836 will then complain when examining the file. First mark all the DIEs in
11837 this CU so we know which get local refs. */
11840 build_abbrev_table (die);
11842 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11843 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11844 calc_die_sizes (die);
11846 oldsym = die->die_id.die_symbol;
11849 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11851 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11853 die->die_id.die_symbol = NULL;
11854 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11858 switch_to_section (debug_info_section);
11859 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11860 info_section_emitted = true;
11863 /* Output debugging information. */
11864 output_compilation_unit_header ();
11867 /* Leave the marks on the main CU, so we can check them in
11868 output_pubnames. */
11872 die->die_id.die_symbol = oldsym;
11876 /* Output a comdat type unit DIE and its children. */
11879 output_comdat_type_unit (comdat_type_node *node)
11881 const char *secname;
11884 #if defined (OBJECT_FORMAT_ELF)
11888 /* First mark all the DIEs in this CU so we know which get local refs. */
11889 mark_dies (node->root_die);
11891 build_abbrev_table (node->root_die);
11893 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11894 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11895 calc_die_sizes (node->root_die);
11897 #if defined (OBJECT_FORMAT_ELF)
11898 secname = ".debug_types";
11899 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11900 sprintf (tmp, "wt.");
11901 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11902 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11903 comdat_key = get_identifier (tmp);
11904 targetm.asm_out.named_section (secname,
11905 SECTION_DEBUG | SECTION_LINKONCE,
11908 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11909 sprintf (tmp, ".gnu.linkonce.wt.");
11910 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11911 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11913 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11916 /* Output debugging information. */
11917 output_compilation_unit_header ();
11918 output_signature (node->signature, "Type Signature");
11919 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11920 "Offset to Type DIE");
11921 output_die (node->root_die);
11923 unmark_dies (node->root_die);
11926 /* Return the DWARF2/3 pubname associated with a decl. */
11928 static const char *
11929 dwarf2_name (tree decl, int scope)
11931 if (DECL_NAMELESS (decl))
11933 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11936 /* Add a new entry to .debug_pubnames if appropriate. */
11939 add_pubname_string (const char *str, dw_die_ref die)
11941 if (targetm.want_debug_pub_sections)
11946 e.name = xstrdup (str);
11947 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11952 add_pubname (tree decl, dw_die_ref die)
11954 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11956 const char *name = dwarf2_name (decl, 1);
11958 add_pubname_string (name, die);
11962 /* Add a new entry to .debug_pubtypes if appropriate. */
11965 add_pubtype (tree decl, dw_die_ref die)
11969 if (!targetm.want_debug_pub_sections)
11973 if ((TREE_PUBLIC (decl)
11974 || is_cu_die (die->die_parent))
11975 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11980 if (TYPE_NAME (decl))
11982 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11983 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11984 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11985 && DECL_NAME (TYPE_NAME (decl)))
11986 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11988 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11993 e.name = dwarf2_name (decl, 1);
11995 e.name = xstrdup (e.name);
11998 /* If we don't have a name for the type, there's no point in adding
11999 it to the table. */
12000 if (e.name && e.name[0] != '\0')
12001 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
12005 /* Output the public names table used to speed up access to externally
12006 visible names; or the public types table used to find type definitions. */
12009 output_pubnames (VEC (pubname_entry, gc) * names)
12012 unsigned long pubnames_length = size_of_pubnames (names);
12015 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12016 dw2_asm_output_data (4, 0xffffffff,
12017 "Initial length escape value indicating 64-bit DWARF extension");
12018 if (names == pubname_table)
12019 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
12020 "Length of Public Names Info");
12022 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
12023 "Length of Public Type Names Info");
12024 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
12025 dw2_asm_output_data (2, 2, "DWARF Version");
12026 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12027 debug_info_section,
12028 "Offset of Compilation Unit Info");
12029 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
12030 "Compilation Unit Length");
12032 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
12034 /* We shouldn't see pubnames for DIEs outside of the main CU. */
12035 if (names == pubname_table)
12036 gcc_assert (pub->die->die_mark);
12038 if (names != pubtype_table
12039 || pub->die->die_offset != 0
12040 || !flag_eliminate_unused_debug_types)
12042 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
12045 dw2_asm_output_nstring (pub->name, -1, "external name");
12049 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
12052 /* Output the information that goes into the .debug_aranges table.
12053 Namely, define the beginning and ending address range of the
12054 text section generated for this compilation unit. */
12057 output_aranges (unsigned long aranges_length)
12061 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12062 dw2_asm_output_data (4, 0xffffffff,
12063 "Initial length escape value indicating 64-bit DWARF extension");
12064 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
12065 "Length of Address Ranges Info");
12066 /* Version number for aranges is still 2, even in DWARF3. */
12067 dw2_asm_output_data (2, 2, "DWARF Version");
12068 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12069 debug_info_section,
12070 "Offset of Compilation Unit Info");
12071 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
12072 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
12074 /* We need to align to twice the pointer size here. */
12075 if (DWARF_ARANGES_PAD_SIZE)
12077 /* Pad using a 2 byte words so that padding is correct for any
12079 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
12080 2 * DWARF2_ADDR_SIZE);
12081 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
12082 dw2_asm_output_data (2, 0, NULL);
12085 /* It is necessary not to output these entries if the sections were
12086 not used; if the sections were not used, the length will be 0 and
12087 the address may end up as 0 if the section is discarded by ld
12088 --gc-sections, leaving an invalid (0, 0) entry that can be
12089 confused with the terminator. */
12090 if (text_section_used)
12092 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
12093 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
12094 text_section_label, "Length");
12096 if (cold_text_section_used)
12098 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
12100 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
12101 cold_text_section_label, "Length");
12104 if (have_multiple_function_sections)
12106 unsigned fde_idx = 0;
12108 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
12110 dw_fde_ref fde = &fde_table[fde_idx];
12112 if (!fde->in_std_section)
12114 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
12116 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
12117 fde->dw_fde_begin, "Length");
12119 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
12121 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
12123 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
12124 fde->dw_fde_second_begin, "Length");
12129 /* Output the terminator words. */
12130 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12131 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12134 /* Add a new entry to .debug_ranges. Return the offset at which it
12137 static unsigned int
12138 add_ranges_num (int num)
12140 unsigned int in_use = ranges_table_in_use;
12142 if (in_use == ranges_table_allocated)
12144 ranges_table_allocated += RANGES_TABLE_INCREMENT;
12145 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
12146 ranges_table_allocated);
12147 memset (ranges_table + ranges_table_in_use, 0,
12148 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
12151 ranges_table[in_use].num = num;
12152 ranges_table_in_use = in_use + 1;
12154 return in_use * 2 * DWARF2_ADDR_SIZE;
12157 /* Add a new entry to .debug_ranges corresponding to a block, or a
12158 range terminator if BLOCK is NULL. */
12160 static unsigned int
12161 add_ranges (const_tree block)
12163 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
12166 /* Add a new entry to .debug_ranges corresponding to a pair of
12170 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
12173 unsigned int in_use = ranges_by_label_in_use;
12174 unsigned int offset;
12176 if (in_use == ranges_by_label_allocated)
12178 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
12179 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
12181 ranges_by_label_allocated);
12182 memset (ranges_by_label + ranges_by_label_in_use, 0,
12183 RANGES_TABLE_INCREMENT
12184 * sizeof (struct dw_ranges_by_label_struct));
12187 ranges_by_label[in_use].begin = begin;
12188 ranges_by_label[in_use].end = end;
12189 ranges_by_label_in_use = in_use + 1;
12191 offset = add_ranges_num (-(int)in_use - 1);
12194 add_AT_range_list (die, DW_AT_ranges, offset);
12200 output_ranges (void)
12203 static const char *const start_fmt = "Offset %#x";
12204 const char *fmt = start_fmt;
12206 for (i = 0; i < ranges_table_in_use; i++)
12208 int block_num = ranges_table[i].num;
12212 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12213 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12215 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12216 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12218 /* If all code is in the text section, then the compilation
12219 unit base address defaults to DW_AT_low_pc, which is the
12220 base of the text section. */
12221 if (!have_multiple_function_sections)
12223 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
12224 text_section_label,
12225 fmt, i * 2 * DWARF2_ADDR_SIZE);
12226 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
12227 text_section_label, NULL);
12230 /* Otherwise, the compilation unit base address is zero,
12231 which allows us to use absolute addresses, and not worry
12232 about whether the target supports cross-section
12236 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12237 fmt, i * 2 * DWARF2_ADDR_SIZE);
12238 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
12244 /* Negative block_num stands for an index into ranges_by_label. */
12245 else if (block_num < 0)
12247 int lab_idx = - block_num - 1;
12249 if (!have_multiple_function_sections)
12251 gcc_unreachable ();
12253 /* If we ever use add_ranges_by_labels () for a single
12254 function section, all we have to do is to take out
12255 the #if 0 above. */
12256 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12257 ranges_by_label[lab_idx].begin,
12258 text_section_label,
12259 fmt, i * 2 * DWARF2_ADDR_SIZE);
12260 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12261 ranges_by_label[lab_idx].end,
12262 text_section_label, NULL);
12267 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12268 ranges_by_label[lab_idx].begin,
12269 fmt, i * 2 * DWARF2_ADDR_SIZE);
12270 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12271 ranges_by_label[lab_idx].end,
12277 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12278 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12284 /* Data structure containing information about input files. */
12287 const char *path; /* Complete file name. */
12288 const char *fname; /* File name part. */
12289 int length; /* Length of entire string. */
12290 struct dwarf_file_data * file_idx; /* Index in input file table. */
12291 int dir_idx; /* Index in directory table. */
12294 /* Data structure containing information about directories with source
12298 const char *path; /* Path including directory name. */
12299 int length; /* Path length. */
12300 int prefix; /* Index of directory entry which is a prefix. */
12301 int count; /* Number of files in this directory. */
12302 int dir_idx; /* Index of directory used as base. */
12305 /* Callback function for file_info comparison. We sort by looking at
12306 the directories in the path. */
12309 file_info_cmp (const void *p1, const void *p2)
12311 const struct file_info *const s1 = (const struct file_info *) p1;
12312 const struct file_info *const s2 = (const struct file_info *) p2;
12313 const unsigned char *cp1;
12314 const unsigned char *cp2;
12316 /* Take care of file names without directories. We need to make sure that
12317 we return consistent values to qsort since some will get confused if
12318 we return the same value when identical operands are passed in opposite
12319 orders. So if neither has a directory, return 0 and otherwise return
12320 1 or -1 depending on which one has the directory. */
12321 if ((s1->path == s1->fname || s2->path == s2->fname))
12322 return (s2->path == s2->fname) - (s1->path == s1->fname);
12324 cp1 = (const unsigned char *) s1->path;
12325 cp2 = (const unsigned char *) s2->path;
12331 /* Reached the end of the first path? If so, handle like above. */
12332 if ((cp1 == (const unsigned char *) s1->fname)
12333 || (cp2 == (const unsigned char *) s2->fname))
12334 return ((cp2 == (const unsigned char *) s2->fname)
12335 - (cp1 == (const unsigned char *) s1->fname));
12337 /* Character of current path component the same? */
12338 else if (*cp1 != *cp2)
12339 return *cp1 - *cp2;
12343 struct file_name_acquire_data
12345 struct file_info *files;
12350 /* Traversal function for the hash table. */
12353 file_name_acquire (void ** slot, void *data)
12355 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12356 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12357 struct file_info *fi;
12360 gcc_assert (fnad->max_files >= d->emitted_number);
12362 if (! d->emitted_number)
12365 gcc_assert (fnad->max_files != fnad->used_files);
12367 fi = fnad->files + fnad->used_files++;
12369 /* Skip all leading "./". */
12371 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12374 /* Create a new array entry. */
12376 fi->length = strlen (f);
12379 /* Search for the file name part. */
12380 f = strrchr (f, DIR_SEPARATOR);
12381 #if defined (DIR_SEPARATOR_2)
12383 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12387 if (f == NULL || f < g)
12393 fi->fname = f == NULL ? fi->path : f + 1;
12397 /* Output the directory table and the file name table. We try to minimize
12398 the total amount of memory needed. A heuristic is used to avoid large
12399 slowdowns with many input files. */
12402 output_file_names (void)
12404 struct file_name_acquire_data fnad;
12406 struct file_info *files;
12407 struct dir_info *dirs;
12415 if (!last_emitted_file)
12417 dw2_asm_output_data (1, 0, "End directory table");
12418 dw2_asm_output_data (1, 0, "End file name table");
12422 numfiles = last_emitted_file->emitted_number;
12424 /* Allocate the various arrays we need. */
12425 files = XALLOCAVEC (struct file_info, numfiles);
12426 dirs = XALLOCAVEC (struct dir_info, numfiles);
12428 fnad.files = files;
12429 fnad.used_files = 0;
12430 fnad.max_files = numfiles;
12431 htab_traverse (file_table, file_name_acquire, &fnad);
12432 gcc_assert (fnad.used_files == fnad.max_files);
12434 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12436 /* Find all the different directories used. */
12437 dirs[0].path = files[0].path;
12438 dirs[0].length = files[0].fname - files[0].path;
12439 dirs[0].prefix = -1;
12441 dirs[0].dir_idx = 0;
12442 files[0].dir_idx = 0;
12445 for (i = 1; i < numfiles; i++)
12446 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12447 && memcmp (dirs[ndirs - 1].path, files[i].path,
12448 dirs[ndirs - 1].length) == 0)
12450 /* Same directory as last entry. */
12451 files[i].dir_idx = ndirs - 1;
12452 ++dirs[ndirs - 1].count;
12458 /* This is a new directory. */
12459 dirs[ndirs].path = files[i].path;
12460 dirs[ndirs].length = files[i].fname - files[i].path;
12461 dirs[ndirs].count = 1;
12462 dirs[ndirs].dir_idx = ndirs;
12463 files[i].dir_idx = ndirs;
12465 /* Search for a prefix. */
12466 dirs[ndirs].prefix = -1;
12467 for (j = 0; j < ndirs; j++)
12468 if (dirs[j].length < dirs[ndirs].length
12469 && dirs[j].length > 1
12470 && (dirs[ndirs].prefix == -1
12471 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12472 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12473 dirs[ndirs].prefix = j;
12478 /* Now to the actual work. We have to find a subset of the directories which
12479 allow expressing the file name using references to the directory table
12480 with the least amount of characters. We do not do an exhaustive search
12481 where we would have to check out every combination of every single
12482 possible prefix. Instead we use a heuristic which provides nearly optimal
12483 results in most cases and never is much off. */
12484 saved = XALLOCAVEC (int, ndirs);
12485 savehere = XALLOCAVEC (int, ndirs);
12487 memset (saved, '\0', ndirs * sizeof (saved[0]));
12488 for (i = 0; i < ndirs; i++)
12493 /* We can always save some space for the current directory. But this
12494 does not mean it will be enough to justify adding the directory. */
12495 savehere[i] = dirs[i].length;
12496 total = (savehere[i] - saved[i]) * dirs[i].count;
12498 for (j = i + 1; j < ndirs; j++)
12501 if (saved[j] < dirs[i].length)
12503 /* Determine whether the dirs[i] path is a prefix of the
12507 k = dirs[j].prefix;
12508 while (k != -1 && k != (int) i)
12509 k = dirs[k].prefix;
12513 /* Yes it is. We can possibly save some memory by
12514 writing the filenames in dirs[j] relative to
12516 savehere[j] = dirs[i].length;
12517 total += (savehere[j] - saved[j]) * dirs[j].count;
12522 /* Check whether we can save enough to justify adding the dirs[i]
12524 if (total > dirs[i].length + 1)
12526 /* It's worthwhile adding. */
12527 for (j = i; j < ndirs; j++)
12528 if (savehere[j] > 0)
12530 /* Remember how much we saved for this directory so far. */
12531 saved[j] = savehere[j];
12533 /* Remember the prefix directory. */
12534 dirs[j].dir_idx = i;
12539 /* Emit the directory name table. */
12540 idx_offset = dirs[0].length > 0 ? 1 : 0;
12541 for (i = 1 - idx_offset; i < ndirs; i++)
12542 dw2_asm_output_nstring (dirs[i].path,
12544 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12545 "Directory Entry: %#x", i + idx_offset);
12547 dw2_asm_output_data (1, 0, "End directory table");
12549 /* We have to emit them in the order of emitted_number since that's
12550 used in the debug info generation. To do this efficiently we
12551 generate a back-mapping of the indices first. */
12552 backmap = XALLOCAVEC (int, numfiles);
12553 for (i = 0; i < numfiles; i++)
12554 backmap[files[i].file_idx->emitted_number - 1] = i;
12556 /* Now write all the file names. */
12557 for (i = 0; i < numfiles; i++)
12559 int file_idx = backmap[i];
12560 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12562 #ifdef VMS_DEBUGGING_INFO
12563 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12565 /* Setting these fields can lead to debugger miscomparisons,
12566 but VMS Debug requires them to be set correctly. */
12571 int maxfilelen = strlen (files[file_idx].path)
12572 + dirs[dir_idx].length
12573 + MAX_VMS_VERSION_LEN + 1;
12574 char *filebuf = XALLOCAVEC (char, maxfilelen);
12576 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12577 snprintf (filebuf, maxfilelen, "%s;%d",
12578 files[file_idx].path + dirs[dir_idx].length, ver);
12580 dw2_asm_output_nstring
12581 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12583 /* Include directory index. */
12584 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12586 /* Modification time. */
12587 dw2_asm_output_data_uleb128
12588 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12592 /* File length in bytes. */
12593 dw2_asm_output_data_uleb128
12594 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12598 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12599 "File Entry: %#x", (unsigned) i + 1);
12601 /* Include directory index. */
12602 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12604 /* Modification time. */
12605 dw2_asm_output_data_uleb128 (0, NULL);
12607 /* File length in bytes. */
12608 dw2_asm_output_data_uleb128 (0, NULL);
12609 #endif /* VMS_DEBUGGING_INFO */
12612 dw2_asm_output_data (1, 0, "End file name table");
12616 /* Output one line number table into the .debug_line section. */
12619 output_one_line_info_table (dw_line_info_table *table)
12621 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12622 unsigned int current_line = 1;
12623 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
12624 dw_line_info_entry *ent;
12627 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
12629 switch (ent->opcode)
12631 case LI_set_address:
12632 /* ??? Unfortunately, we have little choice here currently, and
12633 must always use the most general form. GCC does not know the
12634 address delta itself, so we can't use DW_LNS_advance_pc. Many
12635 ports do have length attributes which will give an upper bound
12636 on the address range. We could perhaps use length attributes
12637 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12638 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
12640 /* This can handle any delta. This takes
12641 4+DWARF2_ADDR_SIZE bytes. */
12642 dw2_asm_output_data (1, 0, "set address %s", line_label);
12643 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12644 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12645 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12649 if (ent->val == current_line)
12651 /* We still need to start a new row, so output a copy insn. */
12652 dw2_asm_output_data (1, DW_LNS_copy,
12653 "copy line %u", current_line);
12657 int line_offset = ent->val - current_line;
12658 int line_delta = line_offset - DWARF_LINE_BASE;
12660 current_line = ent->val;
12661 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12663 /* This can handle deltas from -10 to 234, using the current
12664 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
12665 This takes 1 byte. */
12666 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12667 "line %u", current_line);
12671 /* This can handle any delta. This takes at least 4 bytes,
12672 depending on the value being encoded. */
12673 dw2_asm_output_data (1, DW_LNS_advance_line,
12674 "advance to line %u", current_line);
12675 dw2_asm_output_data_sleb128 (line_offset, NULL);
12676 dw2_asm_output_data (1, DW_LNS_copy, NULL);
12682 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
12683 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12686 case LI_set_column:
12687 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
12688 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12691 case LI_negate_stmt:
12692 current_is_stmt = !current_is_stmt;
12693 dw2_asm_output_data (1, DW_LNS_negate_stmt,
12694 "is_stmt %d", current_is_stmt);
12697 case LI_set_prologue_end:
12698 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
12699 "set prologue end");
12702 case LI_set_epilogue_begin:
12703 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
12704 "set epilogue begin");
12707 case LI_set_discriminator:
12708 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
12709 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
12710 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
12711 dw2_asm_output_data_uleb128 (ent->val, NULL);
12716 /* Emit debug info for the address of the end of the table. */
12717 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
12718 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12719 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12720 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
12722 dw2_asm_output_data (1, 0, "end sequence");
12723 dw2_asm_output_data_uleb128 (1, NULL);
12724 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12727 /* Output the source line number correspondence information. This
12728 information goes into the .debug_line section. */
12731 output_line_info (void)
12733 char l1[20], l2[20], p1[20], p2[20];
12734 int ver = dwarf_version;
12735 bool saw_one = false;
12738 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12739 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12740 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12741 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12743 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12744 dw2_asm_output_data (4, 0xffffffff,
12745 "Initial length escape value indicating 64-bit DWARF extension");
12746 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12747 "Length of Source Line Info");
12748 ASM_OUTPUT_LABEL (asm_out_file, l1);
12750 dw2_asm_output_data (2, ver, "DWARF Version");
12751 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12752 ASM_OUTPUT_LABEL (asm_out_file, p1);
12754 /* Define the architecture-dependent minimum instruction length (in bytes).
12755 In this implementation of DWARF, this field is used for information
12756 purposes only. Since GCC generates assembly language, we have no
12757 a priori knowledge of how many instruction bytes are generated for each
12758 source line, and therefore can use only the DW_LNE_set_address and
12759 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12760 this as '1', which is "correct enough" for all architectures,
12761 and don't let the target override. */
12762 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12765 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12766 "Maximum Operations Per Instruction");
12767 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12768 "Default is_stmt_start flag");
12769 dw2_asm_output_data (1, DWARF_LINE_BASE,
12770 "Line Base Value (Special Opcodes)");
12771 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12772 "Line Range Value (Special Opcodes)");
12773 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12774 "Special Opcode Base");
12776 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12781 case DW_LNS_advance_pc:
12782 case DW_LNS_advance_line:
12783 case DW_LNS_set_file:
12784 case DW_LNS_set_column:
12785 case DW_LNS_fixed_advance_pc:
12786 case DW_LNS_set_isa:
12794 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12798 /* Write out the information about the files we use. */
12799 output_file_names ();
12800 ASM_OUTPUT_LABEL (asm_out_file, p2);
12802 if (separate_line_info)
12804 dw_line_info_table *table;
12807 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
12810 output_one_line_info_table (table);
12814 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
12816 output_one_line_info_table (cold_text_section_line_info);
12820 /* ??? Some Darwin linkers crash on a .debug_line section with no
12821 sequences. Further, merely a DW_LNE_end_sequence entry is not
12822 sufficient -- the address column must also be initialized.
12823 Make sure to output at least one set_address/end_sequence pair,
12824 choosing .text since that section is always present. */
12825 if (text_section_line_info->in_use || !saw_one)
12826 output_one_line_info_table (text_section_line_info);
12828 /* Output the marker for the end of the line number info. */
12829 ASM_OUTPUT_LABEL (asm_out_file, l2);
12832 /* Given a pointer to a tree node for some base type, return a pointer to
12833 a DIE that describes the given type.
12835 This routine must only be called for GCC type nodes that correspond to
12836 Dwarf base (fundamental) types. */
12839 base_type_die (tree type)
12841 dw_die_ref base_type_result;
12842 enum dwarf_type encoding;
12844 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12847 /* If this is a subtype that should not be emitted as a subrange type,
12848 use the base type. See subrange_type_for_debug_p. */
12849 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12850 type = TREE_TYPE (type);
12852 switch (TREE_CODE (type))
12855 if ((dwarf_version >= 4 || !dwarf_strict)
12856 && TYPE_NAME (type)
12857 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12858 && DECL_IS_BUILTIN (TYPE_NAME (type))
12859 && DECL_NAME (TYPE_NAME (type)))
12861 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12862 if (strcmp (name, "char16_t") == 0
12863 || strcmp (name, "char32_t") == 0)
12865 encoding = DW_ATE_UTF;
12869 if (TYPE_STRING_FLAG (type))
12871 if (TYPE_UNSIGNED (type))
12872 encoding = DW_ATE_unsigned_char;
12874 encoding = DW_ATE_signed_char;
12876 else if (TYPE_UNSIGNED (type))
12877 encoding = DW_ATE_unsigned;
12879 encoding = DW_ATE_signed;
12883 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12885 if (dwarf_version >= 3 || !dwarf_strict)
12886 encoding = DW_ATE_decimal_float;
12888 encoding = DW_ATE_lo_user;
12891 encoding = DW_ATE_float;
12894 case FIXED_POINT_TYPE:
12895 if (!(dwarf_version >= 3 || !dwarf_strict))
12896 encoding = DW_ATE_lo_user;
12897 else if (TYPE_UNSIGNED (type))
12898 encoding = DW_ATE_unsigned_fixed;
12900 encoding = DW_ATE_signed_fixed;
12903 /* Dwarf2 doesn't know anything about complex ints, so use
12904 a user defined type for it. */
12906 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12907 encoding = DW_ATE_complex_float;
12909 encoding = DW_ATE_lo_user;
12913 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12914 encoding = DW_ATE_boolean;
12918 /* No other TREE_CODEs are Dwarf fundamental types. */
12919 gcc_unreachable ();
12922 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12924 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12925 int_size_in_bytes (type));
12926 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12928 return base_type_result;
12931 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12932 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12935 is_base_type (tree type)
12937 switch (TREE_CODE (type))
12943 case FIXED_POINT_TYPE:
12951 case QUAL_UNION_TYPE:
12952 case ENUMERAL_TYPE:
12953 case FUNCTION_TYPE:
12956 case REFERENCE_TYPE:
12964 gcc_unreachable ();
12970 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12971 node, return the size in bits for the type if it is a constant, or else
12972 return the alignment for the type if the type's size is not constant, or
12973 else return BITS_PER_WORD if the type actually turns out to be an
12974 ERROR_MARK node. */
12976 static inline unsigned HOST_WIDE_INT
12977 simple_type_size_in_bits (const_tree type)
12979 if (TREE_CODE (type) == ERROR_MARK)
12980 return BITS_PER_WORD;
12981 else if (TYPE_SIZE (type) == NULL_TREE)
12983 else if (host_integerp (TYPE_SIZE (type), 1))
12984 return tree_low_cst (TYPE_SIZE (type), 1);
12986 return TYPE_ALIGN (type);
12989 /* Similarly, but return a double_int instead of UHWI. */
12991 static inline double_int
12992 double_int_type_size_in_bits (const_tree type)
12994 if (TREE_CODE (type) == ERROR_MARK)
12995 return uhwi_to_double_int (BITS_PER_WORD);
12996 else if (TYPE_SIZE (type) == NULL_TREE)
12997 return double_int_zero;
12998 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12999 return tree_to_double_int (TYPE_SIZE (type));
13001 return uhwi_to_double_int (TYPE_ALIGN (type));
13004 /* Given a pointer to a tree node for a subrange type, return a pointer
13005 to a DIE that describes the given type. */
13008 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
13010 dw_die_ref subrange_die;
13011 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
13013 if (context_die == NULL)
13014 context_die = comp_unit_die ();
13016 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
13018 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
13020 /* The size of the subrange type and its base type do not match,
13021 so we need to generate a size attribute for the subrange type. */
13022 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
13026 add_bound_info (subrange_die, DW_AT_lower_bound, low);
13028 add_bound_info (subrange_die, DW_AT_upper_bound, high);
13030 return subrange_die;
13033 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
13034 entry that chains various modifiers in front of the given type. */
13037 modified_type_die (tree type, int is_const_type, int is_volatile_type,
13038 dw_die_ref context_die)
13040 enum tree_code code = TREE_CODE (type);
13041 dw_die_ref mod_type_die;
13042 dw_die_ref sub_die = NULL;
13043 tree item_type = NULL;
13044 tree qualified_type;
13045 tree name, low, high;
13047 if (code == ERROR_MARK)
13050 /* See if we already have the appropriately qualified variant of
13053 = get_qualified_type (type,
13054 ((is_const_type ? TYPE_QUAL_CONST : 0)
13055 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
13057 if (qualified_type == sizetype
13058 && TYPE_NAME (qualified_type)
13059 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
13061 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
13063 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
13064 && TYPE_PRECISION (t)
13065 == TYPE_PRECISION (qualified_type)
13066 && TYPE_UNSIGNED (t)
13067 == TYPE_UNSIGNED (qualified_type));
13068 qualified_type = t;
13071 /* If we do, then we can just use its DIE, if it exists. */
13072 if (qualified_type)
13074 mod_type_die = lookup_type_die (qualified_type);
13076 return mod_type_die;
13079 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
13081 /* Handle C typedef types. */
13082 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
13083 && !DECL_ARTIFICIAL (name))
13085 tree dtype = TREE_TYPE (name);
13087 if (qualified_type == dtype)
13089 /* For a named type, use the typedef. */
13090 gen_type_die (qualified_type, context_die);
13091 return lookup_type_die (qualified_type);
13093 else if (is_const_type < TYPE_READONLY (dtype)
13094 || is_volatile_type < TYPE_VOLATILE (dtype)
13095 || (is_const_type <= TYPE_READONLY (dtype)
13096 && is_volatile_type <= TYPE_VOLATILE (dtype)
13097 && DECL_ORIGINAL_TYPE (name) != type))
13098 /* cv-unqualified version of named type. Just use the unnamed
13099 type to which it refers. */
13100 return modified_type_die (DECL_ORIGINAL_TYPE (name),
13101 is_const_type, is_volatile_type,
13103 /* Else cv-qualified version of named type; fall through. */
13107 /* If both is_const_type and is_volatile_type, prefer the path
13108 which leads to a qualified type. */
13109 && (!is_volatile_type
13110 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
13111 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
13113 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
13114 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
13116 else if (is_volatile_type)
13118 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
13119 sub_die = modified_type_die (type, is_const_type, 0, context_die);
13121 else if (code == POINTER_TYPE)
13123 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
13124 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13125 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13126 item_type = TREE_TYPE (type);
13127 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13128 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13129 TYPE_ADDR_SPACE (item_type));
13131 else if (code == REFERENCE_TYPE)
13133 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
13134 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
13137 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
13138 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13139 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13140 item_type = TREE_TYPE (type);
13141 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13142 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13143 TYPE_ADDR_SPACE (item_type));
13145 else if (code == INTEGER_TYPE
13146 && TREE_TYPE (type) != NULL_TREE
13147 && subrange_type_for_debug_p (type, &low, &high))
13149 mod_type_die = subrange_type_die (type, low, high, context_die);
13150 item_type = TREE_TYPE (type);
13152 else if (is_base_type (type))
13153 mod_type_die = base_type_die (type);
13156 gen_type_die (type, context_die);
13158 /* We have to get the type_main_variant here (and pass that to the
13159 `lookup_type_die' routine) because the ..._TYPE node we have
13160 might simply be a *copy* of some original type node (where the
13161 copy was created to help us keep track of typedef names) and
13162 that copy might have a different TYPE_UID from the original
13164 if (TREE_CODE (type) != VECTOR_TYPE)
13165 return lookup_type_die (type_main_variant (type));
13167 /* Vectors have the debugging information in the type,
13168 not the main variant. */
13169 return lookup_type_die (type);
13172 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
13173 don't output a DW_TAG_typedef, since there isn't one in the
13174 user's program; just attach a DW_AT_name to the type.
13175 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
13176 if the base type already has the same name. */
13178 && ((TREE_CODE (name) != TYPE_DECL
13179 && (qualified_type == TYPE_MAIN_VARIANT (type)
13180 || (!is_const_type && !is_volatile_type)))
13181 || (TREE_CODE (name) == TYPE_DECL
13182 && TREE_TYPE (name) == qualified_type
13183 && DECL_NAME (name))))
13185 if (TREE_CODE (name) == TYPE_DECL)
13186 /* Could just call add_name_and_src_coords_attributes here,
13187 but since this is a builtin type it doesn't have any
13188 useful source coordinates anyway. */
13189 name = DECL_NAME (name);
13190 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
13191 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
13193 /* This probably indicates a bug. */
13194 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
13195 add_name_attribute (mod_type_die, "__unknown__");
13197 if (qualified_type)
13198 equate_type_number_to_die (qualified_type, mod_type_die);
13201 /* We must do this after the equate_type_number_to_die call, in case
13202 this is a recursive type. This ensures that the modified_type_die
13203 recursion will terminate even if the type is recursive. Recursive
13204 types are possible in Ada. */
13205 sub_die = modified_type_die (item_type,
13206 TYPE_READONLY (item_type),
13207 TYPE_VOLATILE (item_type),
13210 if (sub_die != NULL)
13211 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
13213 return mod_type_die;
13216 /* Generate DIEs for the generic parameters of T.
13217 T must be either a generic type or a generic function.
13218 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13221 gen_generic_params_dies (tree t)
13225 dw_die_ref die = NULL;
13227 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13231 die = lookup_type_die (t);
13232 else if (DECL_P (t))
13233 die = lookup_decl_die (t);
13237 parms = lang_hooks.get_innermost_generic_parms (t);
13239 /* T has no generic parameter. It means T is neither a generic type
13240 or function. End of story. */
13243 parms_num = TREE_VEC_LENGTH (parms);
13244 args = lang_hooks.get_innermost_generic_args (t);
13245 for (i = 0; i < parms_num; i++)
13247 tree parm, arg, arg_pack_elems;
13249 parm = TREE_VEC_ELT (parms, i);
13250 arg = TREE_VEC_ELT (args, i);
13251 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13252 gcc_assert (parm && TREE_VALUE (parm) && arg);
13254 if (parm && TREE_VALUE (parm) && arg)
13256 /* If PARM represents a template parameter pack,
13257 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13258 by DW_TAG_template_*_parameter DIEs for the argument
13259 pack elements of ARG. Note that ARG would then be
13260 an argument pack. */
13261 if (arg_pack_elems)
13262 template_parameter_pack_die (TREE_VALUE (parm),
13266 generic_parameter_die (TREE_VALUE (parm), arg,
13267 true /* Emit DW_AT_name */, die);
13272 /* Create and return a DIE for PARM which should be
13273 the representation of a generic type parameter.
13274 For instance, in the C++ front end, PARM would be a template parameter.
13275 ARG is the argument to PARM.
13276 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13278 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13279 as a child node. */
13282 generic_parameter_die (tree parm, tree arg,
13284 dw_die_ref parent_die)
13286 dw_die_ref tmpl_die = NULL;
13287 const char *name = NULL;
13289 if (!parm || !DECL_NAME (parm) || !arg)
13292 /* We support non-type generic parameters and arguments,
13293 type generic parameters and arguments, as well as
13294 generic generic parameters (a.k.a. template template parameters in C++)
13296 if (TREE_CODE (parm) == PARM_DECL)
13297 /* PARM is a nontype generic parameter */
13298 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13299 else if (TREE_CODE (parm) == TYPE_DECL)
13300 /* PARM is a type generic parameter. */
13301 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13302 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13303 /* PARM is a generic generic parameter.
13304 Its DIE is a GNU extension. It shall have a
13305 DW_AT_name attribute to represent the name of the template template
13306 parameter, and a DW_AT_GNU_template_name attribute to represent the
13307 name of the template template argument. */
13308 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13311 gcc_unreachable ();
13317 /* If PARM is a generic parameter pack, it means we are
13318 emitting debug info for a template argument pack element.
13319 In other terms, ARG is a template argument pack element.
13320 In that case, we don't emit any DW_AT_name attribute for
13324 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13326 add_AT_string (tmpl_die, DW_AT_name, name);
13329 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13331 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13332 TMPL_DIE should have a child DW_AT_type attribute that is set
13333 to the type of the argument to PARM, which is ARG.
13334 If PARM is a type generic parameter, TMPL_DIE should have a
13335 child DW_AT_type that is set to ARG. */
13336 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13337 add_type_attribute (tmpl_die, tmpl_type, 0,
13338 TREE_THIS_VOLATILE (tmpl_type),
13343 /* So TMPL_DIE is a DIE representing a
13344 a generic generic template parameter, a.k.a template template
13345 parameter in C++ and arg is a template. */
13347 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13348 to the name of the argument. */
13349 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13351 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13354 if (TREE_CODE (parm) == PARM_DECL)
13355 /* So PARM is a non-type generic parameter.
13356 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13357 attribute of TMPL_DIE which value represents the value
13359 We must be careful here:
13360 The value of ARG might reference some function decls.
13361 We might currently be emitting debug info for a generic
13362 type and types are emitted before function decls, we don't
13363 know if the function decls referenced by ARG will actually be
13364 emitted after cgraph computations.
13365 So must defer the generation of the DW_AT_const_value to
13366 after cgraph is ready. */
13367 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13373 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13374 PARM_PACK must be a template parameter pack. The returned DIE
13375 will be child DIE of PARENT_DIE. */
13378 template_parameter_pack_die (tree parm_pack,
13379 tree parm_pack_args,
13380 dw_die_ref parent_die)
13385 gcc_assert (parent_die && parm_pack);
13387 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13388 add_name_and_src_coords_attributes (die, parm_pack);
13389 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13390 generic_parameter_die (parm_pack,
13391 TREE_VEC_ELT (parm_pack_args, j),
13392 false /* Don't emit DW_AT_name */,
13397 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13398 an enumerated type. */
13401 type_is_enum (const_tree type)
13403 return TREE_CODE (type) == ENUMERAL_TYPE;
13406 /* Return the DBX register number described by a given RTL node. */
13408 static unsigned int
13409 dbx_reg_number (const_rtx rtl)
13411 unsigned regno = REGNO (rtl);
13413 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13415 #ifdef LEAF_REG_REMAP
13416 if (current_function_uses_only_leaf_regs)
13418 int leaf_reg = LEAF_REG_REMAP (regno);
13419 if (leaf_reg != -1)
13420 regno = (unsigned) leaf_reg;
13424 return DBX_REGISTER_NUMBER (regno);
13427 /* Optionally add a DW_OP_piece term to a location description expression.
13428 DW_OP_piece is only added if the location description expression already
13429 doesn't end with DW_OP_piece. */
13432 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13434 dw_loc_descr_ref loc;
13436 if (*list_head != NULL)
13438 /* Find the end of the chain. */
13439 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13442 if (loc->dw_loc_opc != DW_OP_piece)
13443 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13447 /* Return a location descriptor that designates a machine register or
13448 zero if there is none. */
13450 static dw_loc_descr_ref
13451 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13455 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13458 /* We only use "frame base" when we're sure we're talking about the
13459 post-prologue local stack frame. We do this by *not* running
13460 register elimination until this point, and recognizing the special
13461 argument pointer and soft frame pointer rtx's.
13462 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13463 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13464 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13466 dw_loc_descr_ref result = NULL;
13468 if (dwarf_version >= 4 || !dwarf_strict)
13470 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
13473 add_loc_descr (&result,
13474 new_loc_descr (DW_OP_stack_value, 0, 0));
13479 regs = targetm.dwarf_register_span (rtl);
13481 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13482 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13484 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13487 /* Return a location descriptor that designates a machine register for
13488 a given hard register number. */
13490 static dw_loc_descr_ref
13491 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13493 dw_loc_descr_ref reg_loc_descr;
13497 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13499 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13501 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13502 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13504 return reg_loc_descr;
13507 /* Given an RTL of a register, return a location descriptor that
13508 designates a value that spans more than one register. */
13510 static dw_loc_descr_ref
13511 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13512 enum var_init_status initialized)
13514 int nregs, size, i;
13516 dw_loc_descr_ref loc_result = NULL;
13519 #ifdef LEAF_REG_REMAP
13520 if (current_function_uses_only_leaf_regs)
13522 int leaf_reg = LEAF_REG_REMAP (reg);
13523 if (leaf_reg != -1)
13524 reg = (unsigned) leaf_reg;
13527 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13528 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13530 /* Simple, contiguous registers. */
13531 if (regs == NULL_RTX)
13533 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13538 dw_loc_descr_ref t;
13540 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13541 VAR_INIT_STATUS_INITIALIZED);
13542 add_loc_descr (&loc_result, t);
13543 add_loc_descr_op_piece (&loc_result, size);
13549 /* Now onto stupid register sets in non contiguous locations. */
13551 gcc_assert (GET_CODE (regs) == PARALLEL);
13553 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13556 for (i = 0; i < XVECLEN (regs, 0); ++i)
13558 dw_loc_descr_ref t;
13560 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13561 VAR_INIT_STATUS_INITIALIZED);
13562 add_loc_descr (&loc_result, t);
13563 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13564 add_loc_descr_op_piece (&loc_result, size);
13567 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13568 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13572 /* Return a location descriptor that designates a constant. */
13574 static dw_loc_descr_ref
13575 int_loc_descriptor (HOST_WIDE_INT i)
13577 enum dwarf_location_atom op;
13579 /* Pick the smallest representation of a constant, rather than just
13580 defaulting to the LEB encoding. */
13584 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13585 else if (i <= 0xff)
13586 op = DW_OP_const1u;
13587 else if (i <= 0xffff)
13588 op = DW_OP_const2u;
13589 else if (HOST_BITS_PER_WIDE_INT == 32
13590 || i <= 0xffffffff)
13591 op = DW_OP_const4u;
13598 op = DW_OP_const1s;
13599 else if (i >= -0x8000)
13600 op = DW_OP_const2s;
13601 else if (HOST_BITS_PER_WIDE_INT == 32
13602 || i >= -0x80000000)
13603 op = DW_OP_const4s;
13608 return new_loc_descr (op, i, 0);
13611 /* Return loc description representing "address" of integer value.
13612 This can appear only as toplevel expression. */
13614 static dw_loc_descr_ref
13615 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13618 dw_loc_descr_ref loc_result = NULL;
13620 if (!(dwarf_version >= 4 || !dwarf_strict))
13627 else if (i <= 0xff)
13629 else if (i <= 0xffff)
13631 else if (HOST_BITS_PER_WIDE_INT == 32
13632 || i <= 0xffffffff)
13635 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13641 else if (i >= -0x8000)
13643 else if (HOST_BITS_PER_WIDE_INT == 32
13644 || i >= -0x80000000)
13647 litsize = 1 + size_of_sleb128 (i);
13649 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13650 is more compact. For DW_OP_stack_value we need:
13651 litsize + 1 (DW_OP_stack_value)
13652 and for DW_OP_implicit_value:
13653 1 (DW_OP_implicit_value) + 1 (length) + size. */
13654 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13656 loc_result = int_loc_descriptor (i);
13657 add_loc_descr (&loc_result,
13658 new_loc_descr (DW_OP_stack_value, 0, 0));
13662 loc_result = new_loc_descr (DW_OP_implicit_value,
13664 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13665 loc_result->dw_loc_oprnd2.v.val_int = i;
13669 /* Return a location descriptor that designates a base+offset location. */
13671 static dw_loc_descr_ref
13672 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13673 enum var_init_status initialized)
13675 unsigned int regno;
13676 dw_loc_descr_ref result;
13677 dw_fde_ref fde = current_fde ();
13679 /* We only use "frame base" when we're sure we're talking about the
13680 post-prologue local stack frame. We do this by *not* running
13681 register elimination until this point, and recognizing the special
13682 argument pointer and soft frame pointer rtx's. */
13683 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13685 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13689 if (GET_CODE (elim) == PLUS)
13691 offset += INTVAL (XEXP (elim, 1));
13692 elim = XEXP (elim, 0);
13694 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13695 && (elim == hard_frame_pointer_rtx
13696 || elim == stack_pointer_rtx))
13697 || elim == (frame_pointer_needed
13698 ? hard_frame_pointer_rtx
13699 : stack_pointer_rtx));
13701 /* If drap register is used to align stack, use frame
13702 pointer + offset to access stack variables. If stack
13703 is aligned without drap, use stack pointer + offset to
13704 access stack variables. */
13705 if (crtl->stack_realign_tried
13706 && reg == frame_pointer_rtx)
13709 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13710 ? HARD_FRAME_POINTER_REGNUM
13712 return new_reg_loc_descr (base_reg, offset);
13715 gcc_assert (frame_pointer_fb_offset_valid);
13716 offset += frame_pointer_fb_offset;
13717 return new_loc_descr (DW_OP_fbreg, offset, 0);
13722 && (fde->drap_reg == REGNO (reg)
13723 || fde->vdrap_reg == REGNO (reg)))
13725 /* Use cfa+offset to represent the location of arguments passed
13726 on the stack when drap is used to align stack.
13727 Only do this when not optimizing, for optimized code var-tracking
13728 is supposed to track where the arguments live and the register
13729 used as vdrap or drap in some spot might be used for something
13730 else in other part of the routine. */
13731 return new_loc_descr (DW_OP_fbreg, offset, 0);
13734 regno = dbx_reg_number (reg);
13736 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13739 result = new_loc_descr (DW_OP_bregx, regno, offset);
13741 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13742 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13747 /* Return true if this RTL expression describes a base+offset calculation. */
13750 is_based_loc (const_rtx rtl)
13752 return (GET_CODE (rtl) == PLUS
13753 && ((REG_P (XEXP (rtl, 0))
13754 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13755 && CONST_INT_P (XEXP (rtl, 1)))));
13758 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13761 static dw_loc_descr_ref
13762 tls_mem_loc_descriptor (rtx mem)
13765 dw_loc_descr_ref loc_result;
13767 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13770 base = get_base_address (MEM_EXPR (mem));
13772 || TREE_CODE (base) != VAR_DECL
13773 || !DECL_THREAD_LOCAL_P (base))
13776 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13777 if (loc_result == NULL)
13780 if (INTVAL (MEM_OFFSET (mem)))
13781 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13786 /* Output debug info about reason why we failed to expand expression as dwarf
13790 expansion_failed (tree expr, rtx rtl, char const *reason)
13792 if (dump_file && (dump_flags & TDF_DETAILS))
13794 fprintf (dump_file, "Failed to expand as dwarf: ");
13796 print_generic_expr (dump_file, expr, dump_flags);
13799 fprintf (dump_file, "\n");
13800 print_rtl (dump_file, rtl);
13802 fprintf (dump_file, "\nReason: %s\n", reason);
13806 /* Helper function for const_ok_for_output, called either directly
13807 or via for_each_rtx. */
13810 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13814 if (GET_CODE (rtl) == UNSPEC)
13816 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13817 we can't express it in the debug info. */
13818 #ifdef ENABLE_CHECKING
13819 /* Don't complain about TLS UNSPECs, those are just too hard to
13821 if (XVECLEN (rtl, 0) != 1
13822 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13823 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13824 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13825 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13826 inform (current_function_decl
13827 ? DECL_SOURCE_LOCATION (current_function_decl)
13828 : UNKNOWN_LOCATION,
13829 #if NUM_UNSPEC_VALUES > 0
13830 "non-delegitimized UNSPEC %s (%d) found in variable location",
13831 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
13832 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
13835 "non-delegitimized UNSPEC %d found in variable location",
13839 expansion_failed (NULL_TREE, rtl,
13840 "UNSPEC hasn't been delegitimized.\n");
13844 if (GET_CODE (rtl) != SYMBOL_REF)
13847 if (CONSTANT_POOL_ADDRESS_P (rtl))
13850 get_pool_constant_mark (rtl, &marked);
13851 /* If all references to this pool constant were optimized away,
13852 it was not output and thus we can't represent it. */
13855 expansion_failed (NULL_TREE, rtl,
13856 "Constant was removed from constant pool.\n");
13861 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13864 /* Avoid references to external symbols in debug info, on several targets
13865 the linker might even refuse to link when linking a shared library,
13866 and in many other cases the relocations for .debug_info/.debug_loc are
13867 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13868 to be defined within the same shared library or executable are fine. */
13869 if (SYMBOL_REF_EXTERNAL_P (rtl))
13871 tree decl = SYMBOL_REF_DECL (rtl);
13873 if (decl == NULL || !targetm.binds_local_p (decl))
13875 expansion_failed (NULL_TREE, rtl,
13876 "Symbol not defined in current TU.\n");
13884 /* Return true if constant RTL can be emitted in DW_OP_addr or
13885 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13886 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13889 const_ok_for_output (rtx rtl)
13891 if (GET_CODE (rtl) == SYMBOL_REF)
13892 return const_ok_for_output_1 (&rtl, NULL) == 0;
13894 if (GET_CODE (rtl) == CONST)
13895 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13900 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13901 if possible, NULL otherwise. */
13904 base_type_for_mode (enum machine_mode mode, bool unsignedp)
13906 dw_die_ref type_die;
13907 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
13911 switch (TREE_CODE (type))
13919 type_die = lookup_type_die (type);
13921 type_die = modified_type_die (type, false, false, comp_unit_die ());
13922 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
13927 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
13928 type matching MODE, or, if MODE is narrower than or as wide as
13929 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
13932 static dw_loc_descr_ref
13933 convert_descriptor_to_mode (enum machine_mode mode, dw_loc_descr_ref op)
13935 enum machine_mode outer_mode = mode;
13936 dw_die_ref type_die;
13937 dw_loc_descr_ref cvt;
13939 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
13941 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
13944 type_die = base_type_for_mode (outer_mode, 1);
13945 if (type_die == NULL)
13947 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13948 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13949 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13950 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13951 add_loc_descr (&op, cvt);
13955 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13957 static dw_loc_descr_ref
13958 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
13959 dw_loc_descr_ref op1)
13961 dw_loc_descr_ref ret = op0;
13962 add_loc_descr (&ret, op1);
13963 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
13964 if (STORE_FLAG_VALUE != 1)
13966 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
13967 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
13972 /* Return location descriptor for signed comparison OP RTL. */
13974 static dw_loc_descr_ref
13975 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
13976 enum machine_mode mem_mode)
13978 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13979 dw_loc_descr_ref op0, op1;
13982 if (op_mode == VOIDmode)
13983 op_mode = GET_MODE (XEXP (rtl, 1));
13984 if (op_mode == VOIDmode)
13988 && (GET_MODE_CLASS (op_mode) != MODE_INT
13989 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
13992 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
13993 VAR_INIT_STATUS_INITIALIZED);
13994 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
13995 VAR_INIT_STATUS_INITIALIZED);
13997 if (op0 == NULL || op1 == NULL)
14000 if (GET_MODE_CLASS (op_mode) != MODE_INT
14001 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
14002 return compare_loc_descriptor (op, op0, op1);
14004 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
14006 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
14007 dw_loc_descr_ref cvt;
14009 if (type_die == NULL)
14011 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14012 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14013 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14014 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14015 add_loc_descr (&op0, cvt);
14016 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14017 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14018 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14019 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14020 add_loc_descr (&op1, cvt);
14021 return compare_loc_descriptor (op, op0, op1);
14024 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
14025 /* For eq/ne, if the operands are known to be zero-extended,
14026 there is no need to do the fancy shifting up. */
14027 if (op == DW_OP_eq || op == DW_OP_ne)
14029 dw_loc_descr_ref last0, last1;
14030 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
14032 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
14034 /* deref_size zero extends, and for constants we can check
14035 whether they are zero extended or not. */
14036 if (((last0->dw_loc_opc == DW_OP_deref_size
14037 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
14038 || (CONST_INT_P (XEXP (rtl, 0))
14039 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14040 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
14041 && ((last1->dw_loc_opc == DW_OP_deref_size
14042 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
14043 || (CONST_INT_P (XEXP (rtl, 1))
14044 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
14045 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
14046 return compare_loc_descriptor (op, op0, op1);
14048 add_loc_descr (&op0, int_loc_descriptor (shift));
14049 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14050 if (CONST_INT_P (XEXP (rtl, 1)))
14051 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14054 add_loc_descr (&op1, int_loc_descriptor (shift));
14055 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14057 return compare_loc_descriptor (op, op0, op1);
14060 /* Return location descriptor for unsigned comparison OP RTL. */
14062 static dw_loc_descr_ref
14063 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
14064 enum machine_mode mem_mode)
14066 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14067 dw_loc_descr_ref op0, op1;
14069 if (op_mode == VOIDmode)
14070 op_mode = GET_MODE (XEXP (rtl, 1));
14071 if (op_mode == VOIDmode)
14073 if (GET_MODE_CLASS (op_mode) != MODE_INT)
14076 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
14079 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
14080 VAR_INIT_STATUS_INITIALIZED);
14081 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
14082 VAR_INIT_STATUS_INITIALIZED);
14084 if (op0 == NULL || op1 == NULL)
14087 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14089 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14090 dw_loc_descr_ref last0, last1;
14091 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
14093 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
14095 if (CONST_INT_P (XEXP (rtl, 0)))
14096 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14097 /* deref_size zero extends, so no need to mask it again. */
14098 else if (last0->dw_loc_opc != DW_OP_deref_size
14099 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
14101 add_loc_descr (&op0, int_loc_descriptor (mask));
14102 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14104 if (CONST_INT_P (XEXP (rtl, 1)))
14105 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14106 /* deref_size zero extends, so no need to mask it again. */
14107 else if (last1->dw_loc_opc != DW_OP_deref_size
14108 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
14110 add_loc_descr (&op1, int_loc_descriptor (mask));
14111 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14114 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
14116 HOST_WIDE_INT bias = 1;
14117 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14118 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14119 if (CONST_INT_P (XEXP (rtl, 1)))
14120 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14121 + INTVAL (XEXP (rtl, 1)));
14123 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14126 return compare_loc_descriptor (op, op0, op1);
14129 /* Return location descriptor for {U,S}{MIN,MAX}. */
14131 static dw_loc_descr_ref
14132 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
14133 enum machine_mode mem_mode)
14135 enum dwarf_location_atom op;
14136 dw_loc_descr_ref op0, op1, ret;
14137 dw_loc_descr_ref bra_node, drop_node;
14140 && (GET_MODE_CLASS (mode) != MODE_INT
14141 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
14144 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14145 VAR_INIT_STATUS_INITIALIZED);
14146 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14147 VAR_INIT_STATUS_INITIALIZED);
14149 if (op0 == NULL || op1 == NULL)
14152 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14153 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14154 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14155 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14157 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14159 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
14160 add_loc_descr (&op0, int_loc_descriptor (mask));
14161 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14162 add_loc_descr (&op1, int_loc_descriptor (mask));
14163 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14165 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
14167 HOST_WIDE_INT bias = 1;
14168 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14169 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14170 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14173 else if (GET_MODE_CLASS (mode) == MODE_INT
14174 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14176 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
14177 add_loc_descr (&op0, int_loc_descriptor (shift));
14178 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14179 add_loc_descr (&op1, int_loc_descriptor (shift));
14180 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14182 else if (GET_MODE_CLASS (mode) == MODE_INT
14183 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
14185 dw_die_ref type_die = base_type_for_mode (mode, 0);
14186 dw_loc_descr_ref cvt;
14187 if (type_die == NULL)
14189 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14190 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14191 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14192 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14193 add_loc_descr (&op0, cvt);
14194 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14195 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14196 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14197 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14198 add_loc_descr (&op1, cvt);
14201 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14206 add_loc_descr (&ret, op1);
14207 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
14208 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14209 add_loc_descr (&ret, bra_node);
14210 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14211 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14212 add_loc_descr (&ret, drop_node);
14213 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14214 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14215 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
14216 && GET_MODE_CLASS (mode) == MODE_INT
14217 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
14218 ret = convert_descriptor_to_mode (mode, ret);
14222 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14223 but after converting arguments to type_die, afterwards
14224 convert back to unsigned. */
14226 static dw_loc_descr_ref
14227 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
14228 enum machine_mode mode, enum machine_mode mem_mode)
14230 dw_loc_descr_ref cvt, op0, op1;
14232 if (type_die == NULL)
14234 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14235 VAR_INIT_STATUS_INITIALIZED);
14236 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14237 VAR_INIT_STATUS_INITIALIZED);
14238 if (op0 == NULL || op1 == NULL)
14240 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14241 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14242 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14243 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14244 add_loc_descr (&op0, cvt);
14245 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14246 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14247 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14248 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14249 add_loc_descr (&op1, cvt);
14250 add_loc_descr (&op0, op1);
14251 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
14252 return convert_descriptor_to_mode (mode, op0);
14255 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14256 const0 is DW_OP_lit0 or corresponding typed constant,
14257 const1 is DW_OP_lit1 or corresponding typed constant
14258 and constMSB is constant with just the MSB bit set
14260 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14261 L1: const0 DW_OP_swap
14262 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14263 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14268 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14269 L1: const0 DW_OP_swap
14270 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14271 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14276 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14277 L1: const1 DW_OP_swap
14278 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14279 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14283 static dw_loc_descr_ref
14284 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
14285 enum machine_mode mem_mode)
14287 dw_loc_descr_ref op0, ret, tmp;
14288 HOST_WIDE_INT valv;
14289 dw_loc_descr_ref l1jump, l1label;
14290 dw_loc_descr_ref l2jump, l2label;
14291 dw_loc_descr_ref l3jump, l3label;
14292 dw_loc_descr_ref l4jump, l4label;
14295 if (GET_MODE_CLASS (mode) != MODE_INT
14296 || GET_MODE (XEXP (rtl, 0)) != mode
14297 || (GET_CODE (rtl) == CLZ
14298 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
14301 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14302 VAR_INIT_STATUS_INITIALIZED);
14306 if (GET_CODE (rtl) == CLZ)
14308 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
14309 valv = GET_MODE_BITSIZE (mode);
14311 else if (GET_CODE (rtl) == FFS)
14313 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
14314 valv = GET_MODE_BITSIZE (mode);
14315 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
14316 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
14317 add_loc_descr (&ret, l1jump);
14318 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
14319 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
14320 VAR_INIT_STATUS_INITIALIZED);
14323 add_loc_descr (&ret, tmp);
14324 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
14325 add_loc_descr (&ret, l4jump);
14326 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
14327 ? const1_rtx : const0_rtx,
14329 VAR_INIT_STATUS_INITIALIZED);
14330 if (l1label == NULL)
14332 add_loc_descr (&ret, l1label);
14333 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14334 l2label = new_loc_descr (DW_OP_dup, 0, 0);
14335 add_loc_descr (&ret, l2label);
14336 if (GET_CODE (rtl) != CLZ)
14338 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
14339 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
14340 << (GET_MODE_BITSIZE (mode) - 1));
14342 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
14343 << (GET_MODE_BITSIZE (mode)
14344 - HOST_BITS_PER_WIDE_INT - 1), mode);
14345 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
14346 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
14347 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
14348 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
14350 tmp = mem_loc_descriptor (msb, mode, mem_mode,
14351 VAR_INIT_STATUS_INITIALIZED);
14354 add_loc_descr (&ret, tmp);
14355 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
14356 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
14357 add_loc_descr (&ret, l3jump);
14358 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
14359 VAR_INIT_STATUS_INITIALIZED);
14362 add_loc_descr (&ret, tmp);
14363 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
14364 ? DW_OP_shl : DW_OP_shr, 0, 0));
14365 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14366 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
14367 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14368 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
14369 add_loc_descr (&ret, l2jump);
14370 l3label = new_loc_descr (DW_OP_drop, 0, 0);
14371 add_loc_descr (&ret, l3label);
14372 l4label = new_loc_descr (DW_OP_nop, 0, 0);
14373 add_loc_descr (&ret, l4label);
14374 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14375 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
14376 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14377 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
14378 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14379 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
14380 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14381 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
14385 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14386 const1 is DW_OP_lit1 or corresponding typed constant):
14388 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14389 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14393 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14394 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14397 static dw_loc_descr_ref
14398 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
14399 enum machine_mode mem_mode)
14401 dw_loc_descr_ref op0, ret, tmp;
14402 dw_loc_descr_ref l1jump, l1label;
14403 dw_loc_descr_ref l2jump, l2label;
14405 if (GET_MODE_CLASS (mode) != MODE_INT
14406 || GET_MODE (XEXP (rtl, 0)) != mode)
14409 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14410 VAR_INIT_STATUS_INITIALIZED);
14414 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
14415 VAR_INIT_STATUS_INITIALIZED);
14418 add_loc_descr (&ret, tmp);
14419 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14420 l1label = new_loc_descr (DW_OP_dup, 0, 0);
14421 add_loc_descr (&ret, l1label);
14422 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
14423 add_loc_descr (&ret, l2jump);
14424 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
14425 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
14426 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
14427 VAR_INIT_STATUS_INITIALIZED);
14430 add_loc_descr (&ret, tmp);
14431 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
14432 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
14433 ? DW_OP_plus : DW_OP_xor, 0, 0));
14434 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14435 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
14436 VAR_INIT_STATUS_INITIALIZED);
14437 add_loc_descr (&ret, tmp);
14438 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14439 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
14440 add_loc_descr (&ret, l1jump);
14441 l2label = new_loc_descr (DW_OP_drop, 0, 0);
14442 add_loc_descr (&ret, l2label);
14443 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14444 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
14445 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14446 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
14450 /* BSWAP (constS is initial shift count, either 56 or 24):
14452 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14453 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14454 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14455 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14456 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14458 static dw_loc_descr_ref
14459 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
14460 enum machine_mode mem_mode)
14462 dw_loc_descr_ref op0, ret, tmp;
14463 dw_loc_descr_ref l1jump, l1label;
14464 dw_loc_descr_ref l2jump, l2label;
14466 if (GET_MODE_CLASS (mode) != MODE_INT
14467 || BITS_PER_UNIT != 8
14468 || (GET_MODE_BITSIZE (mode) != 32
14469 && GET_MODE_BITSIZE (mode) != 64))
14472 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14473 VAR_INIT_STATUS_INITIALIZED);
14478 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
14480 VAR_INIT_STATUS_INITIALIZED);
14483 add_loc_descr (&ret, tmp);
14484 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
14485 VAR_INIT_STATUS_INITIALIZED);
14488 add_loc_descr (&ret, tmp);
14489 l1label = new_loc_descr (DW_OP_pick, 2, 0);
14490 add_loc_descr (&ret, l1label);
14491 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
14493 VAR_INIT_STATUS_INITIALIZED);
14494 add_loc_descr (&ret, tmp);
14495 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
14496 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
14497 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14498 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
14499 VAR_INIT_STATUS_INITIALIZED);
14502 add_loc_descr (&ret, tmp);
14503 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
14504 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
14505 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
14506 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
14507 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14508 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
14509 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
14510 VAR_INIT_STATUS_INITIALIZED);
14511 add_loc_descr (&ret, tmp);
14512 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
14513 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
14514 add_loc_descr (&ret, l2jump);
14515 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
14516 VAR_INIT_STATUS_INITIALIZED);
14517 add_loc_descr (&ret, tmp);
14518 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
14519 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14520 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
14521 add_loc_descr (&ret, l1jump);
14522 l2label = new_loc_descr (DW_OP_drop, 0, 0);
14523 add_loc_descr (&ret, l2label);
14524 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14525 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
14526 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14527 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
14528 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14529 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
14533 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14534 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14535 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14536 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14538 ROTATERT is similar:
14539 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14540 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14541 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14543 static dw_loc_descr_ref
14544 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
14545 enum machine_mode mem_mode)
14547 rtx rtlop1 = XEXP (rtl, 1);
14548 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
14551 if (GET_MODE_CLASS (mode) != MODE_INT)
14554 if (GET_MODE (rtlop1) != VOIDmode
14555 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
14556 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
14557 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14558 VAR_INIT_STATUS_INITIALIZED);
14559 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
14560 VAR_INIT_STATUS_INITIALIZED);
14561 if (op0 == NULL || op1 == NULL)
14563 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14564 for (i = 0; i < 2; i++)
14566 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
14567 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
14569 VAR_INIT_STATUS_INITIALIZED);
14570 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
14571 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
14573 : HOST_BITS_PER_WIDE_INT == 64
14574 ? DW_OP_const8u : DW_OP_constu,
14575 GET_MODE_MASK (mode), 0);
14578 if (mask[i] == NULL)
14580 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
14583 add_loc_descr (&ret, op1);
14584 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
14585 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
14586 if (GET_CODE (rtl) == ROTATERT)
14588 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14589 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
14590 GET_MODE_BITSIZE (mode), 0));
14592 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
14593 if (mask[0] != NULL)
14594 add_loc_descr (&ret, mask[0]);
14595 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
14596 if (mask[1] != NULL)
14598 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14599 add_loc_descr (&ret, mask[1]);
14600 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14602 if (GET_CODE (rtl) == ROTATE)
14604 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14605 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
14606 GET_MODE_BITSIZE (mode), 0));
14608 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14609 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
14613 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
14614 for DEBUG_PARAMETER_REF RTL. */
14616 static dw_loc_descr_ref
14617 parameter_ref_descriptor (rtx rtl)
14619 dw_loc_descr_ref ret;
14624 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
14625 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
14626 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
14629 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14630 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14631 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14635 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14636 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
14641 /* The following routine converts the RTL for a variable or parameter
14642 (resident in memory) into an equivalent Dwarf representation of a
14643 mechanism for getting the address of that same variable onto the top of a
14644 hypothetical "address evaluation" stack.
14646 When creating memory location descriptors, we are effectively transforming
14647 the RTL for a memory-resident object into its Dwarf postfix expression
14648 equivalent. This routine recursively descends an RTL tree, turning
14649 it into Dwarf postfix code as it goes.
14651 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14653 MEM_MODE is the mode of the memory reference, needed to handle some
14654 autoincrement addressing modes.
14656 Return 0 if we can't represent the location. */
14658 static dw_loc_descr_ref
14659 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
14660 enum machine_mode mem_mode,
14661 enum var_init_status initialized)
14663 dw_loc_descr_ref mem_loc_result = NULL;
14664 enum dwarf_location_atom op;
14665 dw_loc_descr_ref op0, op1;
14667 if (mode == VOIDmode)
14668 mode = GET_MODE (rtl);
14670 /* Note that for a dynamically sized array, the location we will generate a
14671 description of here will be the lowest numbered location which is
14672 actually within the array. That's *not* necessarily the same as the
14673 zeroth element of the array. */
14675 rtl = targetm.delegitimize_address (rtl);
14677 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
14680 switch (GET_CODE (rtl))
14685 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
14688 /* The case of a subreg may arise when we have a local (register)
14689 variable or a formal (register) parameter which doesn't quite fill
14690 up an entire register. For now, just assume that it is
14691 legitimate to make the Dwarf info refer to the whole register which
14692 contains the given subreg. */
14693 if (!subreg_lowpart_p (rtl))
14695 if (GET_MODE_CLASS (mode) == MODE_INT
14696 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
14697 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14698 #ifdef POINTERS_EXTEND_UNSIGNED
14699 || (mode == Pmode && mem_mode != VOIDmode)
14702 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
14704 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
14705 GET_MODE (SUBREG_REG (rtl)),
14706 mem_mode, initialized);
14711 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
14713 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
14714 && (GET_MODE_CLASS (mode) != MODE_INT
14715 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
14719 dw_die_ref type_die;
14720 dw_loc_descr_ref cvt;
14722 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
14723 GET_MODE (SUBREG_REG (rtl)),
14724 mem_mode, initialized);
14725 if (mem_loc_result == NULL)
14727 type_die = base_type_for_mode (mode,
14728 GET_MODE_CLASS (mode) == MODE_INT);
14729 if (type_die == NULL)
14731 mem_loc_result = NULL;
14734 if (GET_MODE_SIZE (mode)
14735 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
14736 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14738 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
14739 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14740 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14741 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14742 add_loc_descr (&mem_loc_result, cvt);
14747 if (GET_MODE_CLASS (mode) != MODE_INT
14748 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14749 #ifdef POINTERS_EXTEND_UNSIGNED
14750 && (mode != Pmode || mem_mode == VOIDmode)
14754 dw_die_ref type_die;
14758 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
14760 type_die = base_type_for_mode (mode,
14761 GET_MODE_CLASS (mode) == MODE_INT);
14762 if (type_die == NULL)
14764 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
14765 dbx_reg_number (rtl), 0);
14766 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
14767 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
14768 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
14771 /* Whenever a register number forms a part of the description of the
14772 method for calculating the (dynamic) address of a memory resident
14773 object, DWARF rules require the register number be referred to as
14774 a "base register". This distinction is not based in any way upon
14775 what category of register the hardware believes the given register
14776 belongs to. This is strictly DWARF terminology we're dealing with
14777 here. Note that in cases where the location of a memory-resident
14778 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14779 OP_CONST (0)) the actual DWARF location descriptor that we generate
14780 may just be OP_BASEREG (basereg). This may look deceptively like
14781 the object in question was allocated to a register (rather than in
14782 memory) so DWARF consumers need to be aware of the subtle
14783 distinction between OP_REG and OP_BASEREG. */
14784 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
14785 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
14786 else if (stack_realign_drap
14788 && crtl->args.internal_arg_pointer == rtl
14789 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
14791 /* If RTL is internal_arg_pointer, which has been optimized
14792 out, use DRAP instead. */
14793 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
14794 VAR_INIT_STATUS_INITIALIZED);
14800 if (GET_MODE_CLASS (mode) != MODE_INT)
14802 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
14803 mem_mode, VAR_INIT_STATUS_INITIALIZED);
14806 else if (GET_CODE (rtl) == ZERO_EXTEND
14807 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14808 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14809 < HOST_BITS_PER_WIDE_INT
14810 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14811 to expand zero extend as two shifts instead of
14813 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
14815 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
14816 mem_loc_result = op0;
14817 add_loc_descr (&mem_loc_result,
14818 int_loc_descriptor (GET_MODE_MASK (imode)));
14819 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
14821 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
14823 int shift = DWARF2_ADDR_SIZE
14824 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14825 shift *= BITS_PER_UNIT;
14826 if (GET_CODE (rtl) == SIGN_EXTEND)
14830 mem_loc_result = op0;
14831 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
14832 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14833 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
14834 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14836 else if (!dwarf_strict)
14838 dw_die_ref type_die1, type_die2;
14839 dw_loc_descr_ref cvt;
14841 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
14842 GET_CODE (rtl) == ZERO_EXTEND);
14843 if (type_die1 == NULL)
14845 type_die2 = base_type_for_mode (mode, 1);
14846 if (type_die2 == NULL)
14848 mem_loc_result = op0;
14849 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14850 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14851 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
14852 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14853 add_loc_descr (&mem_loc_result, cvt);
14854 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14855 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14856 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
14857 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14858 add_loc_descr (&mem_loc_result, cvt);
14863 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
14864 get_address_mode (rtl), mode,
14865 VAR_INIT_STATUS_INITIALIZED);
14866 if (mem_loc_result == NULL)
14867 mem_loc_result = tls_mem_loc_descriptor (rtl);
14868 if (mem_loc_result != 0)
14870 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14871 || GET_MODE_CLASS (mode) != MODE_INT)
14873 dw_die_ref type_die;
14874 dw_loc_descr_ref deref;
14879 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
14880 if (type_die == NULL)
14882 deref = new_loc_descr (DW_OP_GNU_deref_type,
14883 GET_MODE_SIZE (mode), 0);
14884 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
14885 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
14886 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
14887 add_loc_descr (&mem_loc_result, deref);
14889 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
14890 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
14892 add_loc_descr (&mem_loc_result,
14893 new_loc_descr (DW_OP_deref_size,
14894 GET_MODE_SIZE (mode), 0));
14898 rtx new_rtl = avoid_constant_pool_reference (rtl);
14899 if (new_rtl != rtl)
14900 return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
14905 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
14908 /* Some ports can transform a symbol ref into a label ref, because
14909 the symbol ref is too far away and has to be dumped into a constant
14913 if (GET_MODE_CLASS (mode) != MODE_INT
14914 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14915 #ifdef POINTERS_EXTEND_UNSIGNED
14916 && (mode != Pmode || mem_mode == VOIDmode)
14920 if (GET_CODE (rtl) == SYMBOL_REF
14921 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
14923 dw_loc_descr_ref temp;
14925 /* If this is not defined, we have no way to emit the data. */
14926 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
14929 /* We used to emit DW_OP_addr here, but that's wrong, since
14930 DW_OP_addr should be relocated by the debug info consumer,
14931 while DW_OP_GNU_push_tls_address operand should not. */
14932 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
14933 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
14934 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
14935 temp->dw_loc_oprnd1.v.val_addr = rtl;
14936 temp->dtprel = true;
14938 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
14939 add_loc_descr (&mem_loc_result, temp);
14944 if (!const_ok_for_output (rtl))
14948 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14949 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14950 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14951 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14957 case DEBUG_IMPLICIT_PTR:
14958 expansion_failed (NULL_TREE, rtl,
14959 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14965 if (REG_P (ENTRY_VALUE_EXP (rtl)))
14967 if (GET_MODE_CLASS (mode) != MODE_INT
14968 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
14969 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
14970 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14973 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
14974 VAR_INIT_STATUS_INITIALIZED);
14976 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
14977 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
14979 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
14980 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14981 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
14985 gcc_unreachable ();
14988 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
14989 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
14990 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
14993 case DEBUG_PARAMETER_REF:
14994 mem_loc_result = parameter_ref_descriptor (rtl);
14998 /* Extract the PLUS expression nested inside and fall into
14999 PLUS code below. */
15000 rtl = XEXP (rtl, 1);
15005 /* Turn these into a PLUS expression and fall into the PLUS code
15007 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
15008 GEN_INT (GET_CODE (rtl) == PRE_INC
15009 ? GET_MODE_UNIT_SIZE (mem_mode)
15010 : -GET_MODE_UNIT_SIZE (mem_mode)));
15012 /* ... fall through ... */
15016 if (is_based_loc (rtl)
15017 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
15018 && GET_MODE_CLASS (mode) == MODE_INT)
15019 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
15020 INTVAL (XEXP (rtl, 1)),
15021 VAR_INIT_STATUS_INITIALIZED);
15024 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15025 VAR_INIT_STATUS_INITIALIZED);
15026 if (mem_loc_result == 0)
15029 if (CONST_INT_P (XEXP (rtl, 1))
15030 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
15031 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
15034 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15035 VAR_INIT_STATUS_INITIALIZED);
15038 add_loc_descr (&mem_loc_result, op1);
15039 add_loc_descr (&mem_loc_result,
15040 new_loc_descr (DW_OP_plus, 0, 0));
15045 /* If a pseudo-reg is optimized away, it is possible for it to
15046 be replaced with a MEM containing a multiply or shift. */
15057 && GET_MODE_CLASS (mode) == MODE_INT
15058 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
15060 mem_loc_result = typed_binop (DW_OP_div, rtl,
15061 base_type_for_mode (mode, 0),
15085 if (GET_MODE_CLASS (mode) != MODE_INT)
15087 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15088 VAR_INIT_STATUS_INITIALIZED);
15090 rtx rtlop1 = XEXP (rtl, 1);
15091 if (GET_MODE (rtlop1) != VOIDmode
15092 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
15093 < GET_MODE_BITSIZE (mode))
15094 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
15095 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
15096 VAR_INIT_STATUS_INITIALIZED);
15099 if (op0 == 0 || op1 == 0)
15102 mem_loc_result = op0;
15103 add_loc_descr (&mem_loc_result, op1);
15104 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15120 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15121 VAR_INIT_STATUS_INITIALIZED);
15122 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15123 VAR_INIT_STATUS_INITIALIZED);
15125 if (op0 == 0 || op1 == 0)
15128 mem_loc_result = op0;
15129 add_loc_descr (&mem_loc_result, op1);
15130 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15134 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
15136 mem_loc_result = typed_binop (DW_OP_mod, rtl,
15137 base_type_for_mode (mode, 0),
15142 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15143 VAR_INIT_STATUS_INITIALIZED);
15144 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15145 VAR_INIT_STATUS_INITIALIZED);
15147 if (op0 == 0 || op1 == 0)
15150 mem_loc_result = op0;
15151 add_loc_descr (&mem_loc_result, op1);
15152 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
15153 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
15154 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
15155 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
15156 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
15160 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
15162 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
15167 mem_loc_result = typed_binop (DW_OP_div, rtl,
15168 base_type_for_mode (mode, 1),
15186 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15187 VAR_INIT_STATUS_INITIALIZED);
15192 mem_loc_result = op0;
15193 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15197 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
15198 #ifdef POINTERS_EXTEND_UNSIGNED
15200 && mem_mode != VOIDmode
15201 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
15205 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
15209 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
15210 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
15212 dw_die_ref type_die = base_type_for_mode (mode, 1);
15213 if (type_die == NULL)
15215 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
15217 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15218 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15219 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
15220 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
15221 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
15224 mem_loc_result->dw_loc_oprnd2.val_class
15225 = dw_val_class_const_double;
15226 mem_loc_result->dw_loc_oprnd2.v.val_double
15227 = shwi_to_double_int (INTVAL (rtl));
15235 dw_die_ref type_die;
15237 /* Note that a CONST_DOUBLE rtx could represent either an integer
15238 or a floating-point constant. A CONST_DOUBLE is used whenever
15239 the constant requires more than one word in order to be
15240 adequately represented. We output CONST_DOUBLEs as blocks. */
15241 if (mode == VOIDmode
15242 || (GET_MODE (rtl) == VOIDmode
15243 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
15245 type_die = base_type_for_mode (mode,
15246 GET_MODE_CLASS (mode) == MODE_INT);
15247 if (type_die == NULL)
15249 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
15250 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15251 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15252 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
15253 if (SCALAR_FLOAT_MODE_P (mode))
15255 unsigned int length = GET_MODE_SIZE (mode);
15256 unsigned char *array
15257 = (unsigned char*) ggc_alloc_atomic (length);
15259 insert_float (rtl, array);
15260 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15261 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
15262 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
15263 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15267 mem_loc_result->dw_loc_oprnd2.val_class
15268 = dw_val_class_const_double;
15269 mem_loc_result->dw_loc_oprnd2.v.val_double
15270 = rtx_to_double_int (rtl);
15276 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
15280 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
15284 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
15288 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
15292 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
15296 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
15300 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
15304 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
15308 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
15312 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
15317 if (GET_MODE_CLASS (mode) != MODE_INT)
15322 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
15327 if (CONST_INT_P (XEXP (rtl, 1))
15328 && CONST_INT_P (XEXP (rtl, 2))
15329 && ((unsigned) INTVAL (XEXP (rtl, 1))
15330 + (unsigned) INTVAL (XEXP (rtl, 2))
15331 <= GET_MODE_BITSIZE (mode))
15332 && GET_MODE_CLASS (mode) == MODE_INT
15333 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
15334 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
15337 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
15338 mem_mode, VAR_INIT_STATUS_INITIALIZED);
15341 if (GET_CODE (rtl) == SIGN_EXTRACT)
15345 mem_loc_result = op0;
15346 size = INTVAL (XEXP (rtl, 1));
15347 shift = INTVAL (XEXP (rtl, 2));
15348 if (BITS_BIG_ENDIAN)
15349 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
15351 if (shift + size != (int) DWARF2_ADDR_SIZE)
15353 add_loc_descr (&mem_loc_result,
15354 int_loc_descriptor (DWARF2_ADDR_SIZE
15356 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
15358 if (size != (int) DWARF2_ADDR_SIZE)
15360 add_loc_descr (&mem_loc_result,
15361 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
15362 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15369 dw_loc_descr_ref op2, bra_node, drop_node;
15370 op0 = mem_loc_descriptor (XEXP (rtl, 0),
15371 GET_MODE (XEXP (rtl, 0)) == VOIDmode
15372 ? word_mode : GET_MODE (XEXP (rtl, 0)),
15373 mem_mode, VAR_INIT_STATUS_INITIALIZED);
15374 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15375 VAR_INIT_STATUS_INITIALIZED);
15376 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
15377 VAR_INIT_STATUS_INITIALIZED);
15378 if (op0 == NULL || op1 == NULL || op2 == NULL)
15381 mem_loc_result = op1;
15382 add_loc_descr (&mem_loc_result, op2);
15383 add_loc_descr (&mem_loc_result, op0);
15384 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15385 add_loc_descr (&mem_loc_result, bra_node);
15386 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
15387 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
15388 add_loc_descr (&mem_loc_result, drop_node);
15389 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15390 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
15395 case FLOAT_TRUNCATE:
15397 case UNSIGNED_FLOAT:
15402 dw_die_ref type_die;
15403 dw_loc_descr_ref cvt;
15405 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
15406 mem_mode, VAR_INIT_STATUS_INITIALIZED);
15409 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
15410 && (GET_CODE (rtl) == FLOAT
15411 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
15412 <= DWARF2_ADDR_SIZE))
15414 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
15415 GET_CODE (rtl) == UNSIGNED_FLOAT);
15416 if (type_die == NULL)
15418 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
15419 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15420 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15421 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15422 add_loc_descr (&op0, cvt);
15424 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
15425 if (type_die == NULL)
15427 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
15428 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15429 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15430 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15431 add_loc_descr (&op0, cvt);
15432 if (GET_MODE_CLASS (mode) == MODE_INT
15433 && (GET_CODE (rtl) == FIX
15434 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
15436 op0 = convert_descriptor_to_mode (mode, op0);
15440 mem_loc_result = op0;
15447 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
15452 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
15456 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
15461 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
15466 /* In theory, we could implement the above. */
15467 /* DWARF cannot represent the unsigned compare operations
15492 case FRACT_CONVERT:
15493 case UNSIGNED_FRACT_CONVERT:
15495 case UNSIGNED_SAT_FRACT:
15501 case VEC_DUPLICATE:
15505 case STRICT_LOW_PART:
15509 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15510 can't express it in the debug info. This can happen e.g. with some
15515 resolve_one_addr (&rtl, NULL);
15519 #ifdef ENABLE_CHECKING
15520 print_rtl (stderr, rtl);
15521 gcc_unreachable ();
15527 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
15528 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15530 return mem_loc_result;
15533 /* Return a descriptor that describes the concatenation of two locations.
15534 This is typically a complex variable. */
15536 static dw_loc_descr_ref
15537 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
15539 dw_loc_descr_ref cc_loc_result = NULL;
15540 dw_loc_descr_ref x0_ref
15541 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
15542 dw_loc_descr_ref x1_ref
15543 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
15545 if (x0_ref == 0 || x1_ref == 0)
15548 cc_loc_result = x0_ref;
15549 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
15551 add_loc_descr (&cc_loc_result, x1_ref);
15552 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
15554 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
15555 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15557 return cc_loc_result;
15560 /* Return a descriptor that describes the concatenation of N
15563 static dw_loc_descr_ref
15564 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
15567 dw_loc_descr_ref cc_loc_result = NULL;
15568 unsigned int n = XVECLEN (concatn, 0);
15570 for (i = 0; i < n; ++i)
15572 dw_loc_descr_ref ref;
15573 rtx x = XVECEXP (concatn, 0, i);
15575 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
15579 add_loc_descr (&cc_loc_result, ref);
15580 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
15583 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
15584 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15586 return cc_loc_result;
15589 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
15590 for DEBUG_IMPLICIT_PTR RTL. */
15592 static dw_loc_descr_ref
15593 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
15595 dw_loc_descr_ref ret;
15600 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
15601 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
15602 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
15603 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
15604 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
15605 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
15608 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15609 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
15610 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
15614 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
15615 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
15620 /* Output a proper Dwarf location descriptor for a variable or parameter
15621 which is either allocated in a register or in a memory location. For a
15622 register, we just generate an OP_REG and the register number. For a
15623 memory location we provide a Dwarf postfix expression describing how to
15624 generate the (dynamic) address of the object onto the address stack.
15626 MODE is mode of the decl if this loc_descriptor is going to be used in
15627 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15628 allowed, VOIDmode otherwise.
15630 If we don't know how to describe it, return 0. */
15632 static dw_loc_descr_ref
15633 loc_descriptor (rtx rtl, enum machine_mode mode,
15634 enum var_init_status initialized)
15636 dw_loc_descr_ref loc_result = NULL;
15638 switch (GET_CODE (rtl))
15641 /* The case of a subreg may arise when we have a local (register)
15642 variable or a formal (register) parameter which doesn't quite fill
15643 up an entire register. For now, just assume that it is
15644 legitimate to make the Dwarf info refer to the whole register which
15645 contains the given subreg. */
15646 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
15647 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
15653 loc_result = reg_loc_descriptor (rtl, initialized);
15657 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
15658 GET_MODE (rtl), initialized);
15659 if (loc_result == NULL)
15660 loc_result = tls_mem_loc_descriptor (rtl);
15661 if (loc_result == NULL)
15663 rtx new_rtl = avoid_constant_pool_reference (rtl);
15664 if (new_rtl != rtl)
15665 loc_result = loc_descriptor (new_rtl, mode, initialized);
15670 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
15675 loc_result = concatn_loc_descriptor (rtl, initialized);
15680 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
15682 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
15683 if (GET_CODE (loc) == EXPR_LIST)
15684 loc = XEXP (loc, 0);
15685 loc_result = loc_descriptor (loc, mode, initialized);
15689 rtl = XEXP (rtl, 1);
15694 rtvec par_elems = XVEC (rtl, 0);
15695 int num_elem = GET_NUM_ELEM (par_elems);
15696 enum machine_mode mode;
15699 /* Create the first one, so we have something to add to. */
15700 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
15701 VOIDmode, initialized);
15702 if (loc_result == NULL)
15704 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
15705 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
15706 for (i = 1; i < num_elem; i++)
15708 dw_loc_descr_ref temp;
15710 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
15711 VOIDmode, initialized);
15714 add_loc_descr (&loc_result, temp);
15715 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
15716 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
15722 if (mode != VOIDmode && mode != BLKmode)
15723 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
15728 if (mode == VOIDmode)
15729 mode = GET_MODE (rtl);
15731 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
15733 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
15735 /* Note that a CONST_DOUBLE rtx could represent either an integer
15736 or a floating-point constant. A CONST_DOUBLE is used whenever
15737 the constant requires more than one word in order to be
15738 adequately represented. We output CONST_DOUBLEs as blocks. */
15739 loc_result = new_loc_descr (DW_OP_implicit_value,
15740 GET_MODE_SIZE (mode), 0);
15741 if (SCALAR_FLOAT_MODE_P (mode))
15743 unsigned int length = GET_MODE_SIZE (mode);
15744 unsigned char *array
15745 = (unsigned char*) ggc_alloc_atomic (length);
15747 insert_float (rtl, array);
15748 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15749 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
15750 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
15751 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15755 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
15756 loc_result->dw_loc_oprnd2.v.val_double
15757 = rtx_to_double_int (rtl);
15763 if (mode == VOIDmode)
15764 mode = GET_MODE (rtl);
15766 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
15768 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
15769 unsigned int length = CONST_VECTOR_NUNITS (rtl);
15770 unsigned char *array = (unsigned char *)
15771 ggc_alloc_atomic (length * elt_size);
15775 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
15776 switch (GET_MODE_CLASS (mode))
15778 case MODE_VECTOR_INT:
15779 for (i = 0, p = array; i < length; i++, p += elt_size)
15781 rtx elt = CONST_VECTOR_ELT (rtl, i);
15782 double_int val = rtx_to_double_int (elt);
15784 if (elt_size <= sizeof (HOST_WIDE_INT))
15785 insert_int (double_int_to_shwi (val), elt_size, p);
15788 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
15789 insert_double (val, p);
15794 case MODE_VECTOR_FLOAT:
15795 for (i = 0, p = array; i < length; i++, p += elt_size)
15797 rtx elt = CONST_VECTOR_ELT (rtl, i);
15798 insert_float (elt, p);
15803 gcc_unreachable ();
15806 loc_result = new_loc_descr (DW_OP_implicit_value,
15807 length * elt_size, 0);
15808 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15809 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
15810 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
15811 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15816 if (mode == VOIDmode
15817 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
15818 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
15819 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
15821 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
15826 if (!const_ok_for_output (rtl))
15829 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
15830 && (dwarf_version >= 4 || !dwarf_strict))
15832 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
15833 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
15834 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
15835 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
15836 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
15840 case DEBUG_IMPLICIT_PTR:
15841 loc_result = implicit_ptr_descriptor (rtl, 0);
15845 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
15846 && CONST_INT_P (XEXP (rtl, 1)))
15849 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
15855 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
15856 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
15857 && dwarf_version >= 4)
15858 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
15860 /* Value expression. */
15861 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
15863 add_loc_descr (&loc_result,
15864 new_loc_descr (DW_OP_stack_value, 0, 0));
15872 /* We need to figure out what section we should use as the base for the
15873 address ranges where a given location is valid.
15874 1. If this particular DECL has a section associated with it, use that.
15875 2. If this function has a section associated with it, use that.
15876 3. Otherwise, use the text section.
15877 XXX: If you split a variable across multiple sections, we won't notice. */
15879 static const char *
15880 secname_for_decl (const_tree decl)
15882 const char *secname;
15884 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
15886 tree sectree = DECL_SECTION_NAME (decl);
15887 secname = TREE_STRING_POINTER (sectree);
15889 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
15891 tree sectree = DECL_SECTION_NAME (current_function_decl);
15892 secname = TREE_STRING_POINTER (sectree);
15894 else if (cfun && in_cold_section_p)
15895 secname = crtl->subsections.cold_section_label;
15897 secname = text_section_label;
15902 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
15905 decl_by_reference_p (tree decl)
15907 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
15908 || TREE_CODE (decl) == VAR_DECL)
15909 && DECL_BY_REFERENCE (decl));
15912 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15915 static dw_loc_descr_ref
15916 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
15917 enum var_init_status initialized)
15919 int have_address = 0;
15920 dw_loc_descr_ref descr;
15921 enum machine_mode mode;
15923 if (want_address != 2)
15925 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
15927 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15929 varloc = PAT_VAR_LOCATION_LOC (varloc);
15930 if (GET_CODE (varloc) == EXPR_LIST)
15931 varloc = XEXP (varloc, 0);
15932 mode = GET_MODE (varloc);
15933 if (MEM_P (varloc))
15935 rtx addr = XEXP (varloc, 0);
15936 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
15937 mode, initialized);
15942 rtx x = avoid_constant_pool_reference (varloc);
15944 descr = mem_loc_descriptor (x, mode, VOIDmode,
15949 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
15956 if (GET_CODE (varloc) == VAR_LOCATION)
15957 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
15959 mode = DECL_MODE (loc);
15960 descr = loc_descriptor (varloc, mode, initialized);
15967 if (want_address == 2 && !have_address
15968 && (dwarf_version >= 4 || !dwarf_strict))
15970 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15972 expansion_failed (loc, NULL_RTX,
15973 "DWARF address size mismatch");
15976 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
15979 /* Show if we can't fill the request for an address. */
15980 if (want_address && !have_address)
15982 expansion_failed (loc, NULL_RTX,
15983 "Want address and only have value");
15987 /* If we've got an address and don't want one, dereference. */
15988 if (!want_address && have_address)
15990 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15991 enum dwarf_location_atom op;
15993 if (size > DWARF2_ADDR_SIZE || size == -1)
15995 expansion_failed (loc, NULL_RTX,
15996 "DWARF address size mismatch");
15999 else if (size == DWARF2_ADDR_SIZE)
16002 op = DW_OP_deref_size;
16004 add_loc_descr (&descr, new_loc_descr (op, size, 0));
16010 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
16011 if it is not possible. */
16013 static dw_loc_descr_ref
16014 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
16016 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
16017 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
16018 else if (dwarf_version >= 3 || !dwarf_strict)
16019 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
16024 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16025 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
16027 static dw_loc_descr_ref
16028 dw_sra_loc_expr (tree decl, rtx loc)
16031 unsigned int padsize = 0;
16032 dw_loc_descr_ref descr, *descr_tail;
16033 unsigned HOST_WIDE_INT decl_size;
16035 enum var_init_status initialized;
16037 if (DECL_SIZE (decl) == NULL
16038 || !host_integerp (DECL_SIZE (decl), 1))
16041 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
16043 descr_tail = &descr;
16045 for (p = loc; p; p = XEXP (p, 1))
16047 unsigned int bitsize = decl_piece_bitsize (p);
16048 rtx loc_note = *decl_piece_varloc_ptr (p);
16049 dw_loc_descr_ref cur_descr;
16050 dw_loc_descr_ref *tail, last = NULL;
16051 unsigned int opsize = 0;
16053 if (loc_note == NULL_RTX
16054 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
16056 padsize += bitsize;
16059 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
16060 varloc = NOTE_VAR_LOCATION (loc_note);
16061 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
16062 if (cur_descr == NULL)
16064 padsize += bitsize;
16068 /* Check that cur_descr either doesn't use
16069 DW_OP_*piece operations, or their sum is equal
16070 to bitsize. Otherwise we can't embed it. */
16071 for (tail = &cur_descr; *tail != NULL;
16072 tail = &(*tail)->dw_loc_next)
16073 if ((*tail)->dw_loc_opc == DW_OP_piece)
16075 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
16079 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
16081 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
16085 if (last != NULL && opsize != bitsize)
16087 padsize += bitsize;
16091 /* If there is a hole, add DW_OP_*piece after empty DWARF
16092 expression, which means that those bits are optimized out. */
16095 if (padsize > decl_size)
16097 decl_size -= padsize;
16098 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
16099 if (*descr_tail == NULL)
16101 descr_tail = &(*descr_tail)->dw_loc_next;
16104 *descr_tail = cur_descr;
16106 if (bitsize > decl_size)
16108 decl_size -= bitsize;
16111 HOST_WIDE_INT offset = 0;
16112 if (GET_CODE (varloc) == VAR_LOCATION
16113 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
16115 varloc = PAT_VAR_LOCATION_LOC (varloc);
16116 if (GET_CODE (varloc) == EXPR_LIST)
16117 varloc = XEXP (varloc, 0);
16121 if (GET_CODE (varloc) == CONST
16122 || GET_CODE (varloc) == SIGN_EXTEND
16123 || GET_CODE (varloc) == ZERO_EXTEND)
16124 varloc = XEXP (varloc, 0);
16125 else if (GET_CODE (varloc) == SUBREG)
16126 varloc = SUBREG_REG (varloc);
16131 /* DW_OP_bit_size offset should be zero for register
16132 or implicit location descriptions and empty location
16133 descriptions, but for memory addresses needs big endian
16135 if (MEM_P (varloc))
16137 unsigned HOST_WIDE_INT memsize
16138 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
16139 if (memsize != bitsize)
16141 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
16142 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
16144 if (memsize < bitsize)
16146 if (BITS_BIG_ENDIAN)
16147 offset = memsize - bitsize;
16151 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
16152 if (*descr_tail == NULL)
16154 descr_tail = &(*descr_tail)->dw_loc_next;
16158 /* If there were any non-empty expressions, add padding till the end of
16160 if (descr != NULL && decl_size != 0)
16162 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
16163 if (*descr_tail == NULL)
16169 /* Return the dwarf representation of the location list LOC_LIST of
16170 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16173 static dw_loc_list_ref
16174 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
16176 const char *endname, *secname;
16178 enum var_init_status initialized;
16179 struct var_loc_node *node;
16180 dw_loc_descr_ref descr;
16181 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
16182 dw_loc_list_ref list = NULL;
16183 dw_loc_list_ref *listp = &list;
16185 /* Now that we know what section we are using for a base,
16186 actually construct the list of locations.
16187 The first location information is what is passed to the
16188 function that creates the location list, and the remaining
16189 locations just get added on to that list.
16190 Note that we only know the start address for a location
16191 (IE location changes), so to build the range, we use
16192 the range [current location start, next location start].
16193 This means we have to special case the last node, and generate
16194 a range of [last location start, end of function label]. */
16196 secname = secname_for_decl (decl);
16198 for (node = loc_list->first; node; node = node->next)
16199 if (GET_CODE (node->loc) == EXPR_LIST
16200 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
16202 if (GET_CODE (node->loc) == EXPR_LIST)
16204 /* This requires DW_OP_{,bit_}piece, which is not usable
16205 inside DWARF expressions. */
16206 if (want_address != 2)
16208 descr = dw_sra_loc_expr (decl, node->loc);
16214 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
16215 varloc = NOTE_VAR_LOCATION (node->loc);
16216 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
16220 bool range_across_switch = false;
16221 /* If section switch happens in between node->label
16222 and node->next->label (or end of function) and
16223 we can't emit it as a single entry list,
16224 emit two ranges, first one ending at the end
16225 of first partition and second one starting at the
16226 beginning of second partition. */
16227 if (node == loc_list->last_before_switch
16228 && (node != loc_list->first || loc_list->first->next)
16229 && current_function_decl)
16231 endname = current_fde ()->dw_fde_end;
16232 range_across_switch = true;
16234 /* The variable has a location between NODE->LABEL and
16235 NODE->NEXT->LABEL. */
16236 else if (node->next)
16237 endname = node->next->label;
16238 /* If the variable has a location at the last label
16239 it keeps its location until the end of function. */
16240 else if (!current_function_decl)
16241 endname = text_end_label;
16244 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
16245 current_function_funcdef_no);
16246 endname = ggc_strdup (label_id);
16249 *listp = new_loc_list (descr, node->label, endname, secname);
16250 if (TREE_CODE (decl) == PARM_DECL
16251 && node == loc_list->first
16252 && GET_CODE (node->loc) == NOTE
16253 && strcmp (node->label, endname) == 0)
16254 (*listp)->force = true;
16255 listp = &(*listp)->dw_loc_next;
16257 if (range_across_switch)
16259 if (GET_CODE (node->loc) == EXPR_LIST)
16260 descr = dw_sra_loc_expr (decl, node->loc);
16263 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
16264 varloc = NOTE_VAR_LOCATION (node->loc);
16265 descr = dw_loc_list_1 (decl, varloc, want_address,
16268 gcc_assert (descr);
16269 /* The variable has a location between NODE->LABEL and
16270 NODE->NEXT->LABEL. */
16272 endname = node->next->label;
16274 endname = current_fde ()->dw_fde_second_end;
16275 *listp = new_loc_list (descr,
16276 current_fde ()->dw_fde_second_begin,
16278 listp = &(*listp)->dw_loc_next;
16283 /* Try to avoid the overhead of a location list emitting a location
16284 expression instead, but only if we didn't have more than one
16285 location entry in the first place. If some entries were not
16286 representable, we don't want to pretend a single entry that was
16287 applies to the entire scope in which the variable is
16289 if (list && loc_list->first->next)
16295 /* Return if the loc_list has only single element and thus can be represented
16296 as location description. */
16299 single_element_loc_list_p (dw_loc_list_ref list)
16301 gcc_assert (!list->dw_loc_next || list->ll_symbol);
16302 return !list->ll_symbol;
16305 /* To each location in list LIST add loc descr REF. */
16308 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
16310 dw_loc_descr_ref copy;
16311 add_loc_descr (&list->expr, ref);
16312 list = list->dw_loc_next;
16315 copy = ggc_alloc_dw_loc_descr_node ();
16316 memcpy (copy, ref, sizeof (dw_loc_descr_node));
16317 add_loc_descr (&list->expr, copy);
16318 while (copy->dw_loc_next)
16320 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
16321 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
16322 copy->dw_loc_next = new_copy;
16325 list = list->dw_loc_next;
16329 /* Given two lists RET and LIST
16330 produce location list that is result of adding expression in LIST
16331 to expression in RET on each possition in program.
16332 Might be destructive on both RET and LIST.
16334 TODO: We handle only simple cases of RET or LIST having at most one
16335 element. General case would inolve sorting the lists in program order
16336 and merging them that will need some additional work.
16337 Adding that will improve quality of debug info especially for SRA-ed
16341 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
16350 if (!list->dw_loc_next)
16352 add_loc_descr_to_each (*ret, list->expr);
16355 if (!(*ret)->dw_loc_next)
16357 add_loc_descr_to_each (list, (*ret)->expr);
16361 expansion_failed (NULL_TREE, NULL_RTX,
16362 "Don't know how to merge two non-trivial"
16363 " location lists.\n");
16368 /* LOC is constant expression. Try a luck, look it up in constant
16369 pool and return its loc_descr of its address. */
16371 static dw_loc_descr_ref
16372 cst_pool_loc_descr (tree loc)
16374 /* Get an RTL for this, if something has been emitted. */
16375 rtx rtl = lookup_constant_def (loc);
16377 if (!rtl || !MEM_P (rtl))
16382 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
16384 /* TODO: We might get more coverage if we was actually delaying expansion
16385 of all expressions till end of compilation when constant pools are fully
16387 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
16389 expansion_failed (loc, NULL_RTX,
16390 "CST value in contant pool but not marked.");
16393 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
16394 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
16397 /* Return dw_loc_list representing address of addr_expr LOC
16398 by looking for innder INDIRECT_REF expression and turing it
16399 into simple arithmetics. */
16401 static dw_loc_list_ref
16402 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
16405 HOST_WIDE_INT bitsize, bitpos, bytepos;
16406 enum machine_mode mode;
16408 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
16409 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
16411 obj = get_inner_reference (TREE_OPERAND (loc, 0),
16412 &bitsize, &bitpos, &offset, &mode,
16413 &unsignedp, &volatilep, false);
16415 if (bitpos % BITS_PER_UNIT)
16417 expansion_failed (loc, NULL_RTX, "bitfield access");
16420 if (!INDIRECT_REF_P (obj))
16422 expansion_failed (obj,
16423 NULL_RTX, "no indirect ref in inner refrence");
16426 if (!offset && !bitpos)
16427 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
16429 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
16430 && (dwarf_version >= 4 || !dwarf_strict))
16432 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
16437 /* Variable offset. */
16438 list_ret1 = loc_list_from_tree (offset, 0);
16439 if (list_ret1 == 0)
16441 add_loc_list (&list_ret, list_ret1);
16444 add_loc_descr_to_each (list_ret,
16445 new_loc_descr (DW_OP_plus, 0, 0));
16447 bytepos = bitpos / BITS_PER_UNIT;
16449 add_loc_descr_to_each (list_ret,
16450 new_loc_descr (DW_OP_plus_uconst,
16452 else if (bytepos < 0)
16453 loc_list_plus_const (list_ret, bytepos);
16454 add_loc_descr_to_each (list_ret,
16455 new_loc_descr (DW_OP_stack_value, 0, 0));
16461 /* Generate Dwarf location list representing LOC.
16462 If WANT_ADDRESS is false, expression computing LOC will be computed
16463 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
16464 if WANT_ADDRESS is 2, expression computing address useable in location
16465 will be returned (i.e. DW_OP_reg can be used
16466 to refer to register values). */
16468 static dw_loc_list_ref
16469 loc_list_from_tree (tree loc, int want_address)
16471 dw_loc_descr_ref ret = NULL, ret1 = NULL;
16472 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
16473 int have_address = 0;
16474 enum dwarf_location_atom op;
16476 /* ??? Most of the time we do not take proper care for sign/zero
16477 extending the values properly. Hopefully this won't be a real
16480 switch (TREE_CODE (loc))
16483 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
16486 case PLACEHOLDER_EXPR:
16487 /* This case involves extracting fields from an object to determine the
16488 position of other fields. We don't try to encode this here. The
16489 only user of this is Ada, which encodes the needed information using
16490 the names of types. */
16491 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
16495 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
16496 /* There are no opcodes for these operations. */
16499 case PREINCREMENT_EXPR:
16500 case PREDECREMENT_EXPR:
16501 case POSTINCREMENT_EXPR:
16502 case POSTDECREMENT_EXPR:
16503 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
16504 /* There are no opcodes for these operations. */
16508 /* If we already want an address, see if there is INDIRECT_REF inside
16509 e.g. for &this->field. */
16512 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
16513 (loc, want_address == 2);
16516 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
16517 && (ret = cst_pool_loc_descr (loc)))
16520 /* Otherwise, process the argument and look for the address. */
16521 if (!list_ret && !ret)
16522 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
16526 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
16532 if (DECL_THREAD_LOCAL_P (loc))
16535 enum dwarf_location_atom first_op;
16536 enum dwarf_location_atom second_op;
16537 bool dtprel = false;
16539 if (targetm.have_tls)
16541 /* If this is not defined, we have no way to emit the
16543 if (!targetm.asm_out.output_dwarf_dtprel)
16546 /* The way DW_OP_GNU_push_tls_address is specified, we
16547 can only look up addresses of objects in the current
16548 module. We used DW_OP_addr as first op, but that's
16549 wrong, because DW_OP_addr is relocated by the debug
16550 info consumer, while DW_OP_GNU_push_tls_address
16551 operand shouldn't be. */
16552 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
16554 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
16556 second_op = DW_OP_GNU_push_tls_address;
16560 if (!targetm.emutls.debug_form_tls_address
16561 || !(dwarf_version >= 3 || !dwarf_strict))
16563 /* We stuffed the control variable into the DECL_VALUE_EXPR
16564 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
16565 no longer appear in gimple code. We used the control
16566 variable in specific so that we could pick it up here. */
16567 loc = DECL_VALUE_EXPR (loc);
16568 first_op = DW_OP_addr;
16569 second_op = DW_OP_form_tls_address;
16572 rtl = rtl_for_decl_location (loc);
16573 if (rtl == NULL_RTX)
16578 rtl = XEXP (rtl, 0);
16579 if (! CONSTANT_P (rtl))
16582 ret = new_loc_descr (first_op, 0, 0);
16583 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
16584 ret->dw_loc_oprnd1.v.val_addr = rtl;
16585 ret->dtprel = dtprel;
16587 ret1 = new_loc_descr (second_op, 0, 0);
16588 add_loc_descr (&ret, ret1);
16597 if (DECL_HAS_VALUE_EXPR_P (loc))
16598 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
16602 case FUNCTION_DECL:
16605 var_loc_list *loc_list = lookup_decl_loc (loc);
16607 if (loc_list && loc_list->first)
16609 list_ret = dw_loc_list (loc_list, loc, want_address);
16610 have_address = want_address != 0;
16613 rtl = rtl_for_decl_location (loc);
16614 if (rtl == NULL_RTX)
16616 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
16619 else if (CONST_INT_P (rtl))
16621 HOST_WIDE_INT val = INTVAL (rtl);
16622 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16623 val &= GET_MODE_MASK (DECL_MODE (loc));
16624 ret = int_loc_descriptor (val);
16626 else if (GET_CODE (rtl) == CONST_STRING)
16628 expansion_failed (loc, NULL_RTX, "CONST_STRING");
16631 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
16633 ret = new_loc_descr (DW_OP_addr, 0, 0);
16634 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
16635 ret->dw_loc_oprnd1.v.val_addr = rtl;
16639 enum machine_mode mode, mem_mode;
16641 /* Certain constructs can only be represented at top-level. */
16642 if (want_address == 2)
16644 ret = loc_descriptor (rtl, VOIDmode,
16645 VAR_INIT_STATUS_INITIALIZED);
16650 mode = GET_MODE (rtl);
16651 mem_mode = VOIDmode;
16655 mode = get_address_mode (rtl);
16656 rtl = XEXP (rtl, 0);
16659 ret = mem_loc_descriptor (rtl, mode, mem_mode,
16660 VAR_INIT_STATUS_INITIALIZED);
16663 expansion_failed (loc, rtl,
16664 "failed to produce loc descriptor for rtl");
16671 if (!integer_zerop (TREE_OPERAND (loc, 1)))
16675 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16679 case COMPOUND_EXPR:
16680 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
16683 case VIEW_CONVERT_EXPR:
16686 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
16688 case COMPONENT_REF:
16689 case BIT_FIELD_REF:
16691 case ARRAY_RANGE_REF:
16692 case REALPART_EXPR:
16693 case IMAGPART_EXPR:
16696 HOST_WIDE_INT bitsize, bitpos, bytepos;
16697 enum machine_mode mode;
16699 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
16701 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
16702 &unsignedp, &volatilep, false);
16704 gcc_assert (obj != loc);
16706 list_ret = loc_list_from_tree (obj,
16708 && !bitpos && !offset ? 2 : 1);
16709 /* TODO: We can extract value of the small expression via shifting even
16710 for nonzero bitpos. */
16713 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
16715 expansion_failed (loc, NULL_RTX,
16716 "bitfield access");
16720 if (offset != NULL_TREE)
16722 /* Variable offset. */
16723 list_ret1 = loc_list_from_tree (offset, 0);
16724 if (list_ret1 == 0)
16726 add_loc_list (&list_ret, list_ret1);
16729 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
16732 bytepos = bitpos / BITS_PER_UNIT;
16734 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
16735 else if (bytepos < 0)
16736 loc_list_plus_const (list_ret, bytepos);
16743 if ((want_address || !host_integerp (loc, 0))
16744 && (ret = cst_pool_loc_descr (loc)))
16746 else if (want_address == 2
16747 && host_integerp (loc, 0)
16748 && (ret = address_of_int_loc_descriptor
16749 (int_size_in_bytes (TREE_TYPE (loc)),
16750 tree_low_cst (loc, 0))))
16752 else if (host_integerp (loc, 0))
16753 ret = int_loc_descriptor (tree_low_cst (loc, 0));
16756 expansion_failed (loc, NULL_RTX,
16757 "Integer operand is not host integer");
16766 if ((ret = cst_pool_loc_descr (loc)))
16769 /* We can construct small constants here using int_loc_descriptor. */
16770 expansion_failed (loc, NULL_RTX,
16771 "constructor or constant not in constant pool");
16774 case TRUTH_AND_EXPR:
16775 case TRUTH_ANDIF_EXPR:
16780 case TRUTH_XOR_EXPR:
16785 case TRUTH_OR_EXPR:
16786 case TRUTH_ORIF_EXPR:
16791 case FLOOR_DIV_EXPR:
16792 case CEIL_DIV_EXPR:
16793 case ROUND_DIV_EXPR:
16794 case TRUNC_DIV_EXPR:
16795 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16804 case FLOOR_MOD_EXPR:
16805 case CEIL_MOD_EXPR:
16806 case ROUND_MOD_EXPR:
16807 case TRUNC_MOD_EXPR:
16808 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16813 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16814 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
16815 if (list_ret == 0 || list_ret1 == 0)
16818 add_loc_list (&list_ret, list_ret1);
16821 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16822 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16823 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
16824 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
16825 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
16837 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
16840 case POINTER_PLUS_EXPR:
16842 if (host_integerp (TREE_OPERAND (loc, 1), 0))
16844 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16848 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
16856 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16863 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16870 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16877 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16892 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16893 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
16894 if (list_ret == 0 || list_ret1 == 0)
16897 add_loc_list (&list_ret, list_ret1);
16900 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16903 case TRUTH_NOT_EXPR:
16917 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16921 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16927 const enum tree_code code =
16928 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
16930 loc = build3 (COND_EXPR, TREE_TYPE (loc),
16931 build2 (code, integer_type_node,
16932 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
16933 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
16936 /* ... fall through ... */
16940 dw_loc_descr_ref lhs
16941 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
16942 dw_loc_list_ref rhs
16943 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
16944 dw_loc_descr_ref bra_node, jump_node, tmp;
16946 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16947 if (list_ret == 0 || lhs == 0 || rhs == 0)
16950 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
16951 add_loc_descr_to_each (list_ret, bra_node);
16953 add_loc_list (&list_ret, rhs);
16954 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
16955 add_loc_descr_to_each (list_ret, jump_node);
16957 add_loc_descr_to_each (list_ret, lhs);
16958 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16959 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
16961 /* ??? Need a node to point the skip at. Use a nop. */
16962 tmp = new_loc_descr (DW_OP_nop, 0, 0);
16963 add_loc_descr_to_each (list_ret, tmp);
16964 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16965 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
16969 case FIX_TRUNC_EXPR:
16973 /* Leave front-end specific codes as simply unknown. This comes
16974 up, for instance, with the C STMT_EXPR. */
16975 if ((unsigned int) TREE_CODE (loc)
16976 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
16978 expansion_failed (loc, NULL_RTX,
16979 "language specific tree node");
16983 #ifdef ENABLE_CHECKING
16984 /* Otherwise this is a generic code; we should just lists all of
16985 these explicitly. We forgot one. */
16986 gcc_unreachable ();
16988 /* In a release build, we want to degrade gracefully: better to
16989 generate incomplete debugging information than to crash. */
16994 if (!ret && !list_ret)
16997 if (want_address == 2 && !have_address
16998 && (dwarf_version >= 4 || !dwarf_strict))
17000 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
17002 expansion_failed (loc, NULL_RTX,
17003 "DWARF address size mismatch");
17007 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
17009 add_loc_descr_to_each (list_ret,
17010 new_loc_descr (DW_OP_stack_value, 0, 0));
17013 /* Show if we can't fill the request for an address. */
17014 if (want_address && !have_address)
17016 expansion_failed (loc, NULL_RTX,
17017 "Want address and only have value");
17021 gcc_assert (!ret || !list_ret);
17023 /* If we've got an address and don't want one, dereference. */
17024 if (!want_address && have_address)
17026 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
17028 if (size > DWARF2_ADDR_SIZE || size == -1)
17030 expansion_failed (loc, NULL_RTX,
17031 "DWARF address size mismatch");
17034 else if (size == DWARF2_ADDR_SIZE)
17037 op = DW_OP_deref_size;
17040 add_loc_descr (&ret, new_loc_descr (op, size, 0));
17042 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
17045 list_ret = new_loc_list (ret, NULL, NULL, NULL);
17050 /* Same as above but return only single location expression. */
17051 static dw_loc_descr_ref
17052 loc_descriptor_from_tree (tree loc, int want_address)
17054 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
17057 if (ret->dw_loc_next)
17059 expansion_failed (loc, NULL_RTX,
17060 "Location list where only loc descriptor needed");
17066 /* Given a value, round it up to the lowest multiple of `boundary'
17067 which is not less than the value itself. */
17069 static inline HOST_WIDE_INT
17070 ceiling (HOST_WIDE_INT value, unsigned int boundary)
17072 return (((value + boundary - 1) / boundary) * boundary);
17075 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
17076 pointer to the declared type for the relevant field variable, or return
17077 `integer_type_node' if the given node turns out to be an
17078 ERROR_MARK node. */
17081 field_type (const_tree decl)
17085 if (TREE_CODE (decl) == ERROR_MARK)
17086 return integer_type_node;
17088 type = DECL_BIT_FIELD_TYPE (decl);
17089 if (type == NULL_TREE)
17090 type = TREE_TYPE (decl);
17095 /* Given a pointer to a tree node, return the alignment in bits for
17096 it, or else return BITS_PER_WORD if the node actually turns out to
17097 be an ERROR_MARK node. */
17099 static inline unsigned
17100 simple_type_align_in_bits (const_tree type)
17102 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
17105 static inline unsigned
17106 simple_decl_align_in_bits (const_tree decl)
17108 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
17111 /* Return the result of rounding T up to ALIGN. */
17113 static inline double_int
17114 round_up_to_align (double_int t, unsigned int align)
17116 double_int alignd = uhwi_to_double_int (align);
17117 t = double_int_add (t, alignd);
17118 t = double_int_add (t, double_int_minus_one);
17119 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
17120 t = double_int_mul (t, alignd);
17124 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
17125 lowest addressed byte of the "containing object" for the given FIELD_DECL,
17126 or return 0 if we are unable to determine what that offset is, either
17127 because the argument turns out to be a pointer to an ERROR_MARK node, or
17128 because the offset is actually variable. (We can't handle the latter case
17131 static HOST_WIDE_INT
17132 field_byte_offset (const_tree decl)
17134 double_int object_offset_in_bits;
17135 double_int object_offset_in_bytes;
17136 double_int bitpos_int;
17138 if (TREE_CODE (decl) == ERROR_MARK)
17141 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
17143 /* We cannot yet cope with fields whose positions are variable, so
17144 for now, when we see such things, we simply return 0. Someday, we may
17145 be able to handle such cases, but it will be damn difficult. */
17146 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
17149 bitpos_int = tree_to_double_int (bit_position (decl));
17151 #ifdef PCC_BITFIELD_TYPE_MATTERS
17152 if (PCC_BITFIELD_TYPE_MATTERS)
17155 tree field_size_tree;
17156 double_int deepest_bitpos;
17157 double_int field_size_in_bits;
17158 unsigned int type_align_in_bits;
17159 unsigned int decl_align_in_bits;
17160 double_int type_size_in_bits;
17162 type = field_type (decl);
17163 type_size_in_bits = double_int_type_size_in_bits (type);
17164 type_align_in_bits = simple_type_align_in_bits (type);
17166 field_size_tree = DECL_SIZE (decl);
17168 /* The size could be unspecified if there was an error, or for
17169 a flexible array member. */
17170 if (!field_size_tree)
17171 field_size_tree = bitsize_zero_node;
17173 /* If the size of the field is not constant, use the type size. */
17174 if (TREE_CODE (field_size_tree) == INTEGER_CST)
17175 field_size_in_bits = tree_to_double_int (field_size_tree);
17177 field_size_in_bits = type_size_in_bits;
17179 decl_align_in_bits = simple_decl_align_in_bits (decl);
17181 /* The GCC front-end doesn't make any attempt to keep track of the
17182 starting bit offset (relative to the start of the containing
17183 structure type) of the hypothetical "containing object" for a
17184 bit-field. Thus, when computing the byte offset value for the
17185 start of the "containing object" of a bit-field, we must deduce
17186 this information on our own. This can be rather tricky to do in
17187 some cases. For example, handling the following structure type
17188 definition when compiling for an i386/i486 target (which only
17189 aligns long long's to 32-bit boundaries) can be very tricky:
17191 struct S { int field1; long long field2:31; };
17193 Fortunately, there is a simple rule-of-thumb which can be used
17194 in such cases. When compiling for an i386/i486, GCC will
17195 allocate 8 bytes for the structure shown above. It decides to
17196 do this based upon one simple rule for bit-field allocation.
17197 GCC allocates each "containing object" for each bit-field at
17198 the first (i.e. lowest addressed) legitimate alignment boundary
17199 (based upon the required minimum alignment for the declared
17200 type of the field) which it can possibly use, subject to the
17201 condition that there is still enough available space remaining
17202 in the containing object (when allocated at the selected point)
17203 to fully accommodate all of the bits of the bit-field itself.
17205 This simple rule makes it obvious why GCC allocates 8 bytes for
17206 each object of the structure type shown above. When looking
17207 for a place to allocate the "containing object" for `field2',
17208 the compiler simply tries to allocate a 64-bit "containing
17209 object" at each successive 32-bit boundary (starting at zero)
17210 until it finds a place to allocate that 64- bit field such that
17211 at least 31 contiguous (and previously unallocated) bits remain
17212 within that selected 64 bit field. (As it turns out, for the
17213 example above, the compiler finds it is OK to allocate the
17214 "containing object" 64-bit field at bit-offset zero within the
17217 Here we attempt to work backwards from the limited set of facts
17218 we're given, and we try to deduce from those facts, where GCC
17219 must have believed that the containing object started (within
17220 the structure type). The value we deduce is then used (by the
17221 callers of this routine) to generate DW_AT_location and
17222 DW_AT_bit_offset attributes for fields (both bit-fields and, in
17223 the case of DW_AT_location, regular fields as well). */
17225 /* Figure out the bit-distance from the start of the structure to
17226 the "deepest" bit of the bit-field. */
17227 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
17229 /* This is the tricky part. Use some fancy footwork to deduce
17230 where the lowest addressed bit of the containing object must
17232 object_offset_in_bits
17233 = double_int_sub (deepest_bitpos, type_size_in_bits);
17235 /* Round up to type_align by default. This works best for
17237 object_offset_in_bits
17238 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
17240 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
17242 object_offset_in_bits
17243 = double_int_sub (deepest_bitpos, type_size_in_bits);
17245 /* Round up to decl_align instead. */
17246 object_offset_in_bits
17247 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
17251 #endif /* PCC_BITFIELD_TYPE_MATTERS */
17252 object_offset_in_bits = bitpos_int;
17254 object_offset_in_bytes
17255 = double_int_div (object_offset_in_bits,
17256 uhwi_to_double_int (BITS_PER_UNIT), true,
17258 return double_int_to_shwi (object_offset_in_bytes);
17261 /* The following routines define various Dwarf attributes and any data
17262 associated with them. */
17264 /* Add a location description attribute value to a DIE.
17266 This emits location attributes suitable for whole variables and
17267 whole parameters. Note that the location attributes for struct fields are
17268 generated by the routine `data_member_location_attribute' below. */
17271 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
17272 dw_loc_list_ref descr)
17276 if (single_element_loc_list_p (descr))
17277 add_AT_loc (die, attr_kind, descr->expr);
17279 add_AT_loc_list (die, attr_kind, descr);
17282 /* Add DW_AT_accessibility attribute to DIE if needed. */
17285 add_accessibility_attribute (dw_die_ref die, tree decl)
17287 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
17288 children, otherwise the default is DW_ACCESS_public. In DWARF2
17289 the default has always been DW_ACCESS_public. */
17290 if (TREE_PROTECTED (decl))
17291 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
17292 else if (TREE_PRIVATE (decl))
17294 if (dwarf_version == 2
17295 || die->die_parent == NULL
17296 || die->die_parent->die_tag != DW_TAG_class_type)
17297 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
17299 else if (dwarf_version > 2
17301 && die->die_parent->die_tag == DW_TAG_class_type)
17302 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
17305 /* Attach the specialized form of location attribute used for data members of
17306 struct and union types. In the special case of a FIELD_DECL node which
17307 represents a bit-field, the "offset" part of this special location
17308 descriptor must indicate the distance in bytes from the lowest-addressed
17309 byte of the containing struct or union type to the lowest-addressed byte of
17310 the "containing object" for the bit-field. (See the `field_byte_offset'
17313 For any given bit-field, the "containing object" is a hypothetical object
17314 (of some integral or enum type) within which the given bit-field lives. The
17315 type of this hypothetical "containing object" is always the same as the
17316 declared type of the individual bit-field itself (for GCC anyway... the
17317 DWARF spec doesn't actually mandate this). Note that it is the size (in
17318 bytes) of the hypothetical "containing object" which will be given in the
17319 DW_AT_byte_size attribute for this bit-field. (See the
17320 `byte_size_attribute' function below.) It is also used when calculating the
17321 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
17322 function below.) */
17325 add_data_member_location_attribute (dw_die_ref die, tree decl)
17327 HOST_WIDE_INT offset;
17328 dw_loc_descr_ref loc_descr = 0;
17330 if (TREE_CODE (decl) == TREE_BINFO)
17332 /* We're working on the TAG_inheritance for a base class. */
17333 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
17335 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
17336 aren't at a fixed offset from all (sub)objects of the same
17337 type. We need to extract the appropriate offset from our
17338 vtable. The following dwarf expression means
17340 BaseAddr = ObAddr + *((*ObAddr) - Offset)
17342 This is specific to the V3 ABI, of course. */
17344 dw_loc_descr_ref tmp;
17346 /* Make a copy of the object address. */
17347 tmp = new_loc_descr (DW_OP_dup, 0, 0);
17348 add_loc_descr (&loc_descr, tmp);
17350 /* Extract the vtable address. */
17351 tmp = new_loc_descr (DW_OP_deref, 0, 0);
17352 add_loc_descr (&loc_descr, tmp);
17354 /* Calculate the address of the offset. */
17355 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
17356 gcc_assert (offset < 0);
17358 tmp = int_loc_descriptor (-offset);
17359 add_loc_descr (&loc_descr, tmp);
17360 tmp = new_loc_descr (DW_OP_minus, 0, 0);
17361 add_loc_descr (&loc_descr, tmp);
17363 /* Extract the offset. */
17364 tmp = new_loc_descr (DW_OP_deref, 0, 0);
17365 add_loc_descr (&loc_descr, tmp);
17367 /* Add it to the object address. */
17368 tmp = new_loc_descr (DW_OP_plus, 0, 0);
17369 add_loc_descr (&loc_descr, tmp);
17372 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
17375 offset = field_byte_offset (decl);
17379 if (dwarf_version > 2)
17381 /* Don't need to output a location expression, just the constant. */
17383 add_AT_int (die, DW_AT_data_member_location, offset);
17385 add_AT_unsigned (die, DW_AT_data_member_location, offset);
17390 enum dwarf_location_atom op;
17392 /* The DWARF2 standard says that we should assume that the structure
17393 address is already on the stack, so we can specify a structure
17394 field address by using DW_OP_plus_uconst. */
17396 #ifdef MIPS_DEBUGGING_INFO
17397 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
17398 operator correctly. It works only if we leave the offset on the
17402 op = DW_OP_plus_uconst;
17405 loc_descr = new_loc_descr (op, offset, 0);
17409 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
17412 /* Writes integer values to dw_vec_const array. */
17415 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
17419 *dest++ = val & 0xff;
17425 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
17427 static HOST_WIDE_INT
17428 extract_int (const unsigned char *src, unsigned int size)
17430 HOST_WIDE_INT val = 0;
17436 val |= *--src & 0xff;
17442 /* Writes double_int values to dw_vec_const array. */
17445 insert_double (double_int val, unsigned char *dest)
17447 unsigned char *p0 = dest;
17448 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
17450 if (WORDS_BIG_ENDIAN)
17456 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
17457 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
17460 /* Writes floating point values to dw_vec_const array. */
17463 insert_float (const_rtx rtl, unsigned char *array)
17465 REAL_VALUE_TYPE rv;
17469 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
17470 real_to_target (val, &rv, GET_MODE (rtl));
17472 /* real_to_target puts 32-bit pieces in each long. Pack them. */
17473 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
17475 insert_int (val[i], 4, array);
17480 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
17481 does not have a "location" either in memory or in a register. These
17482 things can arise in GNU C when a constant is passed as an actual parameter
17483 to an inlined function. They can also arise in C++ where declared
17484 constants do not necessarily get memory "homes". */
17487 add_const_value_attribute (dw_die_ref die, rtx rtl)
17489 switch (GET_CODE (rtl))
17493 HOST_WIDE_INT val = INTVAL (rtl);
17496 add_AT_int (die, DW_AT_const_value, val);
17498 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
17503 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
17504 floating-point constant. A CONST_DOUBLE is used whenever the
17505 constant requires more than one word in order to be adequately
17508 enum machine_mode mode = GET_MODE (rtl);
17510 if (SCALAR_FLOAT_MODE_P (mode))
17512 unsigned int length = GET_MODE_SIZE (mode);
17513 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
17515 insert_float (rtl, array);
17516 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
17519 add_AT_double (die, DW_AT_const_value,
17520 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
17526 enum machine_mode mode = GET_MODE (rtl);
17527 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
17528 unsigned int length = CONST_VECTOR_NUNITS (rtl);
17529 unsigned char *array = (unsigned char *) ggc_alloc_atomic
17530 (length * elt_size);
17534 switch (GET_MODE_CLASS (mode))
17536 case MODE_VECTOR_INT:
17537 for (i = 0, p = array; i < length; i++, p += elt_size)
17539 rtx elt = CONST_VECTOR_ELT (rtl, i);
17540 double_int val = rtx_to_double_int (elt);
17542 if (elt_size <= sizeof (HOST_WIDE_INT))
17543 insert_int (double_int_to_shwi (val), elt_size, p);
17546 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
17547 insert_double (val, p);
17552 case MODE_VECTOR_FLOAT:
17553 for (i = 0, p = array; i < length; i++, p += elt_size)
17555 rtx elt = CONST_VECTOR_ELT (rtl, i);
17556 insert_float (elt, p);
17561 gcc_unreachable ();
17564 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
17569 if (dwarf_version >= 4 || !dwarf_strict)
17571 dw_loc_descr_ref loc_result;
17572 resolve_one_addr (&rtl, NULL);
17574 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
17575 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
17576 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
17577 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
17578 add_AT_loc (die, DW_AT_location, loc_result);
17579 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
17585 if (CONSTANT_P (XEXP (rtl, 0)))
17586 return add_const_value_attribute (die, XEXP (rtl, 0));
17589 if (!const_ok_for_output (rtl))
17592 if (dwarf_version >= 4 || !dwarf_strict)
17597 /* In cases where an inlined instance of an inline function is passed
17598 the address of an `auto' variable (which is local to the caller) we
17599 can get a situation where the DECL_RTL of the artificial local
17600 variable (for the inlining) which acts as a stand-in for the
17601 corresponding formal parameter (of the inline function) will look
17602 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
17603 exactly a compile-time constant expression, but it isn't the address
17604 of the (artificial) local variable either. Rather, it represents the
17605 *value* which the artificial local variable always has during its
17606 lifetime. We currently have no way to represent such quasi-constant
17607 values in Dwarf, so for now we just punt and generate nothing. */
17615 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
17616 && MEM_READONLY_P (rtl)
17617 && GET_MODE (rtl) == BLKmode)
17619 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
17625 /* No other kinds of rtx should be possible here. */
17626 gcc_unreachable ();
17631 /* Determine whether the evaluation of EXPR references any variables
17632 or functions which aren't otherwise used (and therefore may not be
17635 reference_to_unused (tree * tp, int * walk_subtrees,
17636 void * data ATTRIBUTE_UNUSED)
17638 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
17639 *walk_subtrees = 0;
17641 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
17642 && ! TREE_ASM_WRITTEN (*tp))
17644 /* ??? The C++ FE emits debug information for using decls, so
17645 putting gcc_unreachable here falls over. See PR31899. For now
17646 be conservative. */
17647 else if (!cgraph_global_info_ready
17648 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
17650 else if (TREE_CODE (*tp) == VAR_DECL)
17652 struct varpool_node *node = varpool_get_node (*tp);
17653 if (!node || !node->needed)
17656 else if (TREE_CODE (*tp) == FUNCTION_DECL
17657 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
17659 /* The call graph machinery must have finished analyzing,
17660 optimizing and gimplifying the CU by now.
17661 So if *TP has no call graph node associated
17662 to it, it means *TP will not be emitted. */
17663 if (!cgraph_get_node (*tp))
17666 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
17672 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
17673 for use in a later add_const_value_attribute call. */
17676 rtl_for_decl_init (tree init, tree type)
17678 rtx rtl = NULL_RTX;
17682 /* If a variable is initialized with a string constant without embedded
17683 zeros, build CONST_STRING. */
17684 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
17686 tree enttype = TREE_TYPE (type);
17687 tree domain = TYPE_DOMAIN (type);
17688 enum machine_mode mode = TYPE_MODE (enttype);
17690 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
17692 && integer_zerop (TYPE_MIN_VALUE (domain))
17693 && compare_tree_int (TYPE_MAX_VALUE (domain),
17694 TREE_STRING_LENGTH (init) - 1) == 0
17695 && ((size_t) TREE_STRING_LENGTH (init)
17696 == strlen (TREE_STRING_POINTER (init)) + 1))
17698 rtl = gen_rtx_CONST_STRING (VOIDmode,
17699 ggc_strdup (TREE_STRING_POINTER (init)));
17700 rtl = gen_rtx_MEM (BLKmode, rtl);
17701 MEM_READONLY_P (rtl) = 1;
17704 /* Other aggregates, and complex values, could be represented using
17706 else if (AGGREGATE_TYPE_P (type)
17707 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
17708 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
17709 || TREE_CODE (type) == COMPLEX_TYPE)
17711 /* Vectors only work if their mode is supported by the target.
17712 FIXME: generic vectors ought to work too. */
17713 else if (TREE_CODE (type) == VECTOR_TYPE
17714 && !VECTOR_MODE_P (TYPE_MODE (type)))
17716 /* If the initializer is something that we know will expand into an
17717 immediate RTL constant, expand it now. We must be careful not to
17718 reference variables which won't be output. */
17719 else if (initializer_constant_valid_p (init, type)
17720 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
17722 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
17724 if (TREE_CODE (type) == VECTOR_TYPE)
17725 switch (TREE_CODE (init))
17730 if (TREE_CONSTANT (init))
17732 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
17733 bool constant_p = true;
17735 unsigned HOST_WIDE_INT ix;
17737 /* Even when ctor is constant, it might contain non-*_CST
17738 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
17739 belong into VECTOR_CST nodes. */
17740 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
17741 if (!CONSTANT_CLASS_P (value))
17743 constant_p = false;
17749 init = build_vector_from_ctor (type, elts);
17759 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
17761 /* If expand_expr returns a MEM, it wasn't immediate. */
17762 gcc_assert (!rtl || !MEM_P (rtl));
17768 /* Generate RTL for the variable DECL to represent its location. */
17771 rtl_for_decl_location (tree decl)
17775 /* Here we have to decide where we are going to say the parameter "lives"
17776 (as far as the debugger is concerned). We only have a couple of
17777 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
17779 DECL_RTL normally indicates where the parameter lives during most of the
17780 activation of the function. If optimization is enabled however, this
17781 could be either NULL or else a pseudo-reg. Both of those cases indicate
17782 that the parameter doesn't really live anywhere (as far as the code
17783 generation parts of GCC are concerned) during most of the function's
17784 activation. That will happen (for example) if the parameter is never
17785 referenced within the function.
17787 We could just generate a location descriptor here for all non-NULL
17788 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
17789 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
17790 where DECL_RTL is NULL or is a pseudo-reg.
17792 Note however that we can only get away with using DECL_INCOMING_RTL as
17793 a backup substitute for DECL_RTL in certain limited cases. In cases
17794 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
17795 we can be sure that the parameter was passed using the same type as it is
17796 declared to have within the function, and that its DECL_INCOMING_RTL
17797 points us to a place where a value of that type is passed.
17799 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
17800 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
17801 because in these cases DECL_INCOMING_RTL points us to a value of some
17802 type which is *different* from the type of the parameter itself. Thus,
17803 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
17804 such cases, the debugger would end up (for example) trying to fetch a
17805 `float' from a place which actually contains the first part of a
17806 `double'. That would lead to really incorrect and confusing
17807 output at debug-time.
17809 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
17810 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
17811 are a couple of exceptions however. On little-endian machines we can
17812 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
17813 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
17814 an integral type that is smaller than TREE_TYPE (decl). These cases arise
17815 when (on a little-endian machine) a non-prototyped function has a
17816 parameter declared to be of type `short' or `char'. In such cases,
17817 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
17818 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
17819 passed `int' value. If the debugger then uses that address to fetch
17820 a `short' or a `char' (on a little-endian machine) the result will be
17821 the correct data, so we allow for such exceptional cases below.
17823 Note that our goal here is to describe the place where the given formal
17824 parameter lives during most of the function's activation (i.e. between the
17825 end of the prologue and the start of the epilogue). We'll do that as best
17826 as we can. Note however that if the given formal parameter is modified
17827 sometime during the execution of the function, then a stack backtrace (at
17828 debug-time) will show the function as having been called with the *new*
17829 value rather than the value which was originally passed in. This happens
17830 rarely enough that it is not a major problem, but it *is* a problem, and
17831 I'd like to fix it.
17833 A future version of dwarf2out.c may generate two additional attributes for
17834 any given DW_TAG_formal_parameter DIE which will describe the "passed
17835 type" and the "passed location" for the given formal parameter in addition
17836 to the attributes we now generate to indicate the "declared type" and the
17837 "active location" for each parameter. This additional set of attributes
17838 could be used by debuggers for stack backtraces. Separately, note that
17839 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
17840 This happens (for example) for inlined-instances of inline function formal
17841 parameters which are never referenced. This really shouldn't be
17842 happening. All PARM_DECL nodes should get valid non-NULL
17843 DECL_INCOMING_RTL values. FIXME. */
17845 /* Use DECL_RTL as the "location" unless we find something better. */
17846 rtl = DECL_RTL_IF_SET (decl);
17848 /* When generating abstract instances, ignore everything except
17849 constants, symbols living in memory, and symbols living in
17850 fixed registers. */
17851 if (! reload_completed)
17854 && (CONSTANT_P (rtl)
17856 && CONSTANT_P (XEXP (rtl, 0)))
17858 && TREE_CODE (decl) == VAR_DECL
17859 && TREE_STATIC (decl))))
17861 rtl = targetm.delegitimize_address (rtl);
17866 else if (TREE_CODE (decl) == PARM_DECL)
17868 if (rtl == NULL_RTX
17869 || is_pseudo_reg (rtl)
17871 && is_pseudo_reg (XEXP (rtl, 0))
17872 && DECL_INCOMING_RTL (decl)
17873 && MEM_P (DECL_INCOMING_RTL (decl))
17874 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
17876 tree declared_type = TREE_TYPE (decl);
17877 tree passed_type = DECL_ARG_TYPE (decl);
17878 enum machine_mode dmode = TYPE_MODE (declared_type);
17879 enum machine_mode pmode = TYPE_MODE (passed_type);
17881 /* This decl represents a formal parameter which was optimized out.
17882 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
17883 all cases where (rtl == NULL_RTX) just below. */
17884 if (dmode == pmode)
17885 rtl = DECL_INCOMING_RTL (decl);
17886 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
17887 && SCALAR_INT_MODE_P (dmode)
17888 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
17889 && DECL_INCOMING_RTL (decl))
17891 rtx inc = DECL_INCOMING_RTL (decl);
17894 else if (MEM_P (inc))
17896 if (BYTES_BIG_ENDIAN)
17897 rtl = adjust_address_nv (inc, dmode,
17898 GET_MODE_SIZE (pmode)
17899 - GET_MODE_SIZE (dmode));
17906 /* If the parm was passed in registers, but lives on the stack, then
17907 make a big endian correction if the mode of the type of the
17908 parameter is not the same as the mode of the rtl. */
17909 /* ??? This is the same series of checks that are made in dbxout.c before
17910 we reach the big endian correction code there. It isn't clear if all
17911 of these checks are necessary here, but keeping them all is the safe
17913 else if (MEM_P (rtl)
17914 && XEXP (rtl, 0) != const0_rtx
17915 && ! CONSTANT_P (XEXP (rtl, 0))
17916 /* Not passed in memory. */
17917 && !MEM_P (DECL_INCOMING_RTL (decl))
17918 /* Not passed by invisible reference. */
17919 && (!REG_P (XEXP (rtl, 0))
17920 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
17921 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
17922 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
17923 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
17926 /* Big endian correction check. */
17927 && BYTES_BIG_ENDIAN
17928 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
17929 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
17932 int offset = (UNITS_PER_WORD
17933 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
17935 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17936 plus_constant (XEXP (rtl, 0), offset));
17939 else if (TREE_CODE (decl) == VAR_DECL
17942 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
17943 && BYTES_BIG_ENDIAN)
17945 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
17946 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
17948 /* If a variable is declared "register" yet is smaller than
17949 a register, then if we store the variable to memory, it
17950 looks like we're storing a register-sized value, when in
17951 fact we are not. We need to adjust the offset of the
17952 storage location to reflect the actual value's bytes,
17953 else gdb will not be able to display it. */
17955 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17956 plus_constant (XEXP (rtl, 0), rsize-dsize));
17959 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
17960 and will have been substituted directly into all expressions that use it.
17961 C does not have such a concept, but C++ and other languages do. */
17962 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
17963 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
17966 rtl = targetm.delegitimize_address (rtl);
17968 /* If we don't look past the constant pool, we risk emitting a
17969 reference to a constant pool entry that isn't referenced from
17970 code, and thus is not emitted. */
17972 rtl = avoid_constant_pool_reference (rtl);
17974 /* Try harder to get a rtl. If this symbol ends up not being emitted
17975 in the current CU, resolve_addr will remove the expression referencing
17977 if (rtl == NULL_RTX
17978 && TREE_CODE (decl) == VAR_DECL
17979 && !DECL_EXTERNAL (decl)
17980 && TREE_STATIC (decl)
17981 && DECL_NAME (decl)
17982 && !DECL_HARD_REGISTER (decl)
17983 && DECL_MODE (decl) != VOIDmode)
17985 rtl = make_decl_rtl_for_debug (decl);
17987 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
17988 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
17995 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17996 returned. If so, the decl for the COMMON block is returned, and the
17997 value is the offset into the common block for the symbol. */
18000 fortran_common (tree decl, HOST_WIDE_INT *value)
18002 tree val_expr, cvar;
18003 enum machine_mode mode;
18004 HOST_WIDE_INT bitsize, bitpos;
18006 int volatilep = 0, unsignedp = 0;
18008 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
18009 it does not have a value (the offset into the common area), or if it
18010 is thread local (as opposed to global) then it isn't common, and shouldn't
18011 be handled as such. */
18012 if (TREE_CODE (decl) != VAR_DECL
18013 || !TREE_STATIC (decl)
18014 || !DECL_HAS_VALUE_EXPR_P (decl)
18018 val_expr = DECL_VALUE_EXPR (decl);
18019 if (TREE_CODE (val_expr) != COMPONENT_REF)
18022 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
18023 &mode, &unsignedp, &volatilep, true);
18025 if (cvar == NULL_TREE
18026 || TREE_CODE (cvar) != VAR_DECL
18027 || DECL_ARTIFICIAL (cvar)
18028 || !TREE_PUBLIC (cvar))
18032 if (offset != NULL)
18034 if (!host_integerp (offset, 0))
18036 *value = tree_low_cst (offset, 0);
18039 *value += bitpos / BITS_PER_UNIT;
18044 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
18045 data attribute for a variable or a parameter. We generate the
18046 DW_AT_const_value attribute only in those cases where the given variable
18047 or parameter does not have a true "location" either in memory or in a
18048 register. This can happen (for example) when a constant is passed as an
18049 actual argument in a call to an inline function. (It's possible that
18050 these things can crop up in other ways also.) Note that one type of
18051 constant value which can be passed into an inlined function is a constant
18052 pointer. This can happen for example if an actual argument in an inlined
18053 function call evaluates to a compile-time constant address.
18055 CACHE_P is true if it is worth caching the location list for DECL,
18056 so that future calls can reuse it rather than regenerate it from scratch.
18057 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
18058 since we will need to refer to them each time the function is inlined. */
18061 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
18062 enum dwarf_attribute attr)
18065 dw_loc_list_ref list;
18066 var_loc_list *loc_list;
18067 cached_dw_loc_list *cache;
18070 if (TREE_CODE (decl) == ERROR_MARK)
18073 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
18074 || TREE_CODE (decl) == RESULT_DECL);
18076 /* Try to get some constant RTL for this decl, and use that as the value of
18079 rtl = rtl_for_decl_location (decl);
18080 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
18081 && add_const_value_attribute (die, rtl))
18084 /* See if we have single element location list that is equivalent to
18085 a constant value. That way we are better to use add_const_value_attribute
18086 rather than expanding constant value equivalent. */
18087 loc_list = lookup_decl_loc (decl);
18090 && loc_list->first->next == NULL
18091 && NOTE_P (loc_list->first->loc)
18092 && NOTE_VAR_LOCATION (loc_list->first->loc)
18093 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
18095 struct var_loc_node *node;
18097 node = loc_list->first;
18098 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
18099 if (GET_CODE (rtl) == EXPR_LIST)
18100 rtl = XEXP (rtl, 0);
18101 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
18102 && add_const_value_attribute (die, rtl))
18105 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
18106 list several times. See if we've already cached the contents. */
18108 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
18112 cache = (cached_dw_loc_list *)
18113 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
18115 list = cache->loc_list;
18119 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
18120 /* It is usually worth caching this result if the decl is from
18121 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
18122 if (cache_p && list && list->dw_loc_next)
18124 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
18125 DECL_UID (decl), INSERT);
18126 cache = ggc_alloc_cleared_cached_dw_loc_list ();
18127 cache->decl_id = DECL_UID (decl);
18128 cache->loc_list = list;
18134 add_AT_location_description (die, attr, list);
18137 /* None of that worked, so it must not really have a location;
18138 try adding a constant value attribute from the DECL_INITIAL. */
18139 return tree_add_const_value_attribute_for_decl (die, decl);
18142 /* Add VARIABLE and DIE into deferred locations list. */
18145 defer_location (tree variable, dw_die_ref die)
18147 deferred_locations entry;
18148 entry.variable = variable;
18150 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
18153 /* Helper function for tree_add_const_value_attribute. Natively encode
18154 initializer INIT into an array. Return true if successful. */
18157 native_encode_initializer (tree init, unsigned char *array, int size)
18161 if (init == NULL_TREE)
18165 switch (TREE_CODE (init))
18168 type = TREE_TYPE (init);
18169 if (TREE_CODE (type) == ARRAY_TYPE)
18171 tree enttype = TREE_TYPE (type);
18172 enum machine_mode mode = TYPE_MODE (enttype);
18174 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
18176 if (int_size_in_bytes (type) != size)
18178 if (size > TREE_STRING_LENGTH (init))
18180 memcpy (array, TREE_STRING_POINTER (init),
18181 TREE_STRING_LENGTH (init));
18182 memset (array + TREE_STRING_LENGTH (init),
18183 '\0', size - TREE_STRING_LENGTH (init));
18186 memcpy (array, TREE_STRING_POINTER (init), size);
18191 type = TREE_TYPE (init);
18192 if (int_size_in_bytes (type) != size)
18194 if (TREE_CODE (type) == ARRAY_TYPE)
18196 HOST_WIDE_INT min_index;
18197 unsigned HOST_WIDE_INT cnt;
18198 int curpos = 0, fieldsize;
18199 constructor_elt *ce;
18201 if (TYPE_DOMAIN (type) == NULL_TREE
18202 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
18205 fieldsize = int_size_in_bytes (TREE_TYPE (type));
18206 if (fieldsize <= 0)
18209 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
18210 memset (array, '\0', size);
18211 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
18213 tree val = ce->value;
18214 tree index = ce->index;
18216 if (index && TREE_CODE (index) == RANGE_EXPR)
18217 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
18220 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
18225 if (!native_encode_initializer (val, array + pos, fieldsize))
18228 curpos = pos + fieldsize;
18229 if (index && TREE_CODE (index) == RANGE_EXPR)
18231 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
18232 - tree_low_cst (TREE_OPERAND (index, 0), 0);
18233 while (count-- > 0)
18236 memcpy (array + curpos, array + pos, fieldsize);
18237 curpos += fieldsize;
18240 gcc_assert (curpos <= size);
18244 else if (TREE_CODE (type) == RECORD_TYPE
18245 || TREE_CODE (type) == UNION_TYPE)
18247 tree field = NULL_TREE;
18248 unsigned HOST_WIDE_INT cnt;
18249 constructor_elt *ce;
18251 if (int_size_in_bytes (type) != size)
18254 if (TREE_CODE (type) == RECORD_TYPE)
18255 field = TYPE_FIELDS (type);
18257 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
18259 tree val = ce->value;
18260 int pos, fieldsize;
18262 if (ce->index != 0)
18268 if (field == NULL_TREE || DECL_BIT_FIELD (field))
18271 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
18272 && TYPE_DOMAIN (TREE_TYPE (field))
18273 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
18275 else if (DECL_SIZE_UNIT (field) == NULL_TREE
18276 || !host_integerp (DECL_SIZE_UNIT (field), 0))
18278 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
18279 pos = int_byte_position (field);
18280 gcc_assert (pos + fieldsize <= size);
18282 && !native_encode_initializer (val, array + pos, fieldsize))
18288 case VIEW_CONVERT_EXPR:
18289 case NON_LVALUE_EXPR:
18290 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
18292 return native_encode_expr (init, array, size) == size;
18296 /* Attach a DW_AT_const_value attribute to DIE. The value of the
18297 attribute is the const value T. */
18300 tree_add_const_value_attribute (dw_die_ref die, tree t)
18303 tree type = TREE_TYPE (t);
18306 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
18310 gcc_assert (!DECL_P (init));
18312 rtl = rtl_for_decl_init (init, type);
18314 return add_const_value_attribute (die, rtl);
18315 /* If the host and target are sane, try harder. */
18316 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
18317 && initializer_constant_valid_p (init, type))
18319 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
18320 if (size > 0 && (int) size == size)
18322 unsigned char *array = (unsigned char *)
18323 ggc_alloc_cleared_atomic (size);
18325 if (native_encode_initializer (init, array, size))
18327 add_AT_vec (die, DW_AT_const_value, size, 1, array);
18335 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
18336 attribute is the const value of T, where T is an integral constant
18337 variable with static storage duration
18338 (so it can't be a PARM_DECL or a RESULT_DECL). */
18341 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
18345 || (TREE_CODE (decl) != VAR_DECL
18346 && TREE_CODE (decl) != CONST_DECL)
18347 || (TREE_CODE (decl) == VAR_DECL
18348 && !TREE_STATIC (decl)))
18351 if (TREE_READONLY (decl)
18352 && ! TREE_THIS_VOLATILE (decl)
18353 && DECL_INITIAL (decl))
18358 /* Don't add DW_AT_const_value if abstract origin already has one. */
18359 if (get_AT (var_die, DW_AT_const_value))
18362 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
18365 /* Convert the CFI instructions for the current function into a
18366 location list. This is used for DW_AT_frame_base when we targeting
18367 a dwarf2 consumer that does not support the dwarf3
18368 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
18371 static dw_loc_list_ref
18372 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
18376 dw_loc_list_ref list, *list_tail;
18378 dw_cfa_location last_cfa, next_cfa;
18379 const char *start_label, *last_label, *section;
18380 dw_cfa_location remember;
18382 fde = current_fde ();
18383 gcc_assert (fde != NULL);
18385 section = secname_for_decl (current_function_decl);
18389 memset (&next_cfa, 0, sizeof (next_cfa));
18390 next_cfa.reg = INVALID_REGNUM;
18391 remember = next_cfa;
18393 start_label = fde->dw_fde_begin;
18395 /* ??? Bald assumption that the CIE opcode list does not contain
18396 advance opcodes. */
18397 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
18398 lookup_cfa_1 (cfi, &next_cfa, &remember);
18400 last_cfa = next_cfa;
18401 last_label = start_label;
18403 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
18405 /* If the first partition contained no CFI adjustments, the
18406 CIE opcodes apply to the whole first partition. */
18407 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18408 fde->dw_fde_begin, fde->dw_fde_end, section);
18409 list_tail =&(*list_tail)->dw_loc_next;
18410 start_label = last_label = fde->dw_fde_second_begin;
18413 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
18415 switch (cfi->dw_cfi_opc)
18417 case DW_CFA_set_loc:
18418 case DW_CFA_advance_loc1:
18419 case DW_CFA_advance_loc2:
18420 case DW_CFA_advance_loc4:
18421 if (!cfa_equal_p (&last_cfa, &next_cfa))
18423 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18424 start_label, last_label, section);
18426 list_tail = &(*list_tail)->dw_loc_next;
18427 last_cfa = next_cfa;
18428 start_label = last_label;
18430 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
18433 case DW_CFA_advance_loc:
18434 /* The encoding is complex enough that we should never emit this. */
18435 gcc_unreachable ();
18438 lookup_cfa_1 (cfi, &next_cfa, &remember);
18441 if (ix + 1 == fde->dw_fde_switch_cfi_index)
18443 if (!cfa_equal_p (&last_cfa, &next_cfa))
18445 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18446 start_label, last_label, section);
18448 list_tail = &(*list_tail)->dw_loc_next;
18449 last_cfa = next_cfa;
18450 start_label = last_label;
18452 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18453 start_label, fde->dw_fde_end, section);
18454 list_tail = &(*list_tail)->dw_loc_next;
18455 start_label = last_label = fde->dw_fde_second_begin;
18459 if (!cfa_equal_p (&last_cfa, &next_cfa))
18461 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18462 start_label, last_label, section);
18463 list_tail = &(*list_tail)->dw_loc_next;
18464 start_label = last_label;
18467 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
18469 fde->dw_fde_second_begin
18470 ? fde->dw_fde_second_end : fde->dw_fde_end,
18473 if (list && list->dw_loc_next)
18479 /* Compute a displacement from the "steady-state frame pointer" to the
18480 frame base (often the same as the CFA), and store it in
18481 frame_pointer_fb_offset. OFFSET is added to the displacement
18482 before the latter is negated. */
18485 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
18489 #ifdef FRAME_POINTER_CFA_OFFSET
18490 reg = frame_pointer_rtx;
18491 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
18493 reg = arg_pointer_rtx;
18494 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
18497 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
18498 if (GET_CODE (elim) == PLUS)
18500 offset += INTVAL (XEXP (elim, 1));
18501 elim = XEXP (elim, 0);
18504 frame_pointer_fb_offset = -offset;
18506 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
18507 in which to eliminate. This is because it's stack pointer isn't
18508 directly accessible as a register within the ISA. To work around
18509 this, assume that while we cannot provide a proper value for
18510 frame_pointer_fb_offset, we won't need one either. */
18511 frame_pointer_fb_offset_valid
18512 = ((SUPPORTS_STACK_ALIGNMENT
18513 && (elim == hard_frame_pointer_rtx
18514 || elim == stack_pointer_rtx))
18515 || elim == (frame_pointer_needed
18516 ? hard_frame_pointer_rtx
18517 : stack_pointer_rtx));
18520 /* Generate a DW_AT_name attribute given some string value to be included as
18521 the value of the attribute. */
18524 add_name_attribute (dw_die_ref die, const char *name_string)
18526 if (name_string != NULL && *name_string != 0)
18528 if (demangle_name_func)
18529 name_string = (*demangle_name_func) (name_string);
18531 add_AT_string (die, DW_AT_name, name_string);
18535 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
18536 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
18537 of TYPE accordingly.
18539 ??? This is a temporary measure until after we're able to generate
18540 regular DWARF for the complex Ada type system. */
18543 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
18544 dw_die_ref context_die)
18547 dw_die_ref dtype_die;
18549 if (!lang_hooks.types.descriptive_type)
18552 dtype = lang_hooks.types.descriptive_type (type);
18556 dtype_die = lookup_type_die (dtype);
18559 gen_type_die (dtype, context_die);
18560 dtype_die = lookup_type_die (dtype);
18561 gcc_assert (dtype_die);
18564 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
18567 /* Generate a DW_AT_comp_dir attribute for DIE. */
18570 add_comp_dir_attribute (dw_die_ref die)
18572 const char *wd = get_src_pwd ();
18578 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
18582 wdlen = strlen (wd);
18583 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
18585 wd1 [wdlen] = DIR_SEPARATOR;
18586 wd1 [wdlen + 1] = 0;
18590 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
18593 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
18597 lower_bound_default (void)
18599 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
18604 case DW_LANG_C_plus_plus:
18606 case DW_LANG_ObjC_plus_plus:
18609 case DW_LANG_Fortran77:
18610 case DW_LANG_Fortran90:
18611 case DW_LANG_Fortran95:
18615 case DW_LANG_Python:
18616 return dwarf_version >= 4 ? 0 : -1;
18617 case DW_LANG_Ada95:
18618 case DW_LANG_Ada83:
18619 case DW_LANG_Cobol74:
18620 case DW_LANG_Cobol85:
18621 case DW_LANG_Pascal83:
18622 case DW_LANG_Modula2:
18624 return dwarf_version >= 4 ? 1 : -1;
18630 /* Given a tree node describing an array bound (either lower or upper) output
18631 a representation for that bound. */
18634 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
18636 switch (TREE_CODE (bound))
18641 /* All fixed-bounds are represented by INTEGER_CST nodes. */
18644 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
18647 /* Use the default if possible. */
18648 if (bound_attr == DW_AT_lower_bound
18649 && host_integerp (bound, 0)
18650 && (dflt = lower_bound_default ()) != -1
18651 && tree_low_cst (bound, 0) == dflt)
18654 /* Otherwise represent the bound as an unsigned value with the
18655 precision of its type. The precision and signedness of the
18656 type will be necessary to re-interpret it unambiguously. */
18657 else if (prec < HOST_BITS_PER_WIDE_INT)
18659 unsigned HOST_WIDE_INT mask
18660 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
18661 add_AT_unsigned (subrange_die, bound_attr,
18662 TREE_INT_CST_LOW (bound) & mask);
18664 else if (prec == HOST_BITS_PER_WIDE_INT
18665 || TREE_INT_CST_HIGH (bound) == 0)
18666 add_AT_unsigned (subrange_die, bound_attr,
18667 TREE_INT_CST_LOW (bound));
18669 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
18670 TREE_INT_CST_LOW (bound));
18675 case VIEW_CONVERT_EXPR:
18676 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
18686 dw_die_ref decl_die = lookup_decl_die (bound);
18688 /* ??? Can this happen, or should the variable have been bound
18689 first? Probably it can, since I imagine that we try to create
18690 the types of parameters in the order in which they exist in
18691 the list, and won't have created a forward reference to a
18692 later parameter. */
18693 if (decl_die != NULL)
18695 add_AT_die_ref (subrange_die, bound_attr, decl_die);
18703 /* Otherwise try to create a stack operation procedure to
18704 evaluate the value of the array bound. */
18706 dw_die_ref ctx, decl_die;
18707 dw_loc_list_ref list;
18709 list = loc_list_from_tree (bound, 2);
18710 if (list == NULL || single_element_loc_list_p (list))
18712 /* If DW_AT_*bound is not a reference nor constant, it is
18713 a DWARF expression rather than location description.
18714 For that loc_list_from_tree (bound, 0) is needed.
18715 If that fails to give a single element list,
18716 fall back to outputting this as a reference anyway. */
18717 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
18718 if (list2 && single_element_loc_list_p (list2))
18720 add_AT_loc (subrange_die, bound_attr, list2->expr);
18727 if (current_function_decl == 0)
18728 ctx = comp_unit_die ();
18730 ctx = lookup_decl_die (current_function_decl);
18732 decl_die = new_die (DW_TAG_variable, ctx, bound);
18733 add_AT_flag (decl_die, DW_AT_artificial, 1);
18734 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
18735 add_AT_location_description (decl_die, DW_AT_location, list);
18736 add_AT_die_ref (subrange_die, bound_attr, decl_die);
18742 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
18743 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
18744 Note that the block of subscript information for an array type also
18745 includes information about the element type of the given array type. */
18748 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
18750 unsigned dimension_number;
18752 dw_die_ref subrange_die;
18754 for (dimension_number = 0;
18755 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
18756 type = TREE_TYPE (type), dimension_number++)
18758 tree domain = TYPE_DOMAIN (type);
18760 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
18763 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
18764 and (in GNU C only) variable bounds. Handle all three forms
18766 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
18769 /* We have an array type with specified bounds. */
18770 lower = TYPE_MIN_VALUE (domain);
18771 upper = TYPE_MAX_VALUE (domain);
18773 /* Define the index type. */
18774 if (TREE_TYPE (domain))
18776 /* ??? This is probably an Ada unnamed subrange type. Ignore the
18777 TREE_TYPE field. We can't emit debug info for this
18778 because it is an unnamed integral type. */
18779 if (TREE_CODE (domain) == INTEGER_TYPE
18780 && TYPE_NAME (domain) == NULL_TREE
18781 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
18782 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
18785 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
18789 /* ??? If upper is NULL, the array has unspecified length,
18790 but it does have a lower bound. This happens with Fortran
18792 Since the debugger is definitely going to need to know N
18793 to produce useful results, go ahead and output the lower
18794 bound solo, and hope the debugger can cope. */
18796 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
18798 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
18801 /* Otherwise we have an array type with an unspecified length. The
18802 DWARF-2 spec does not say how to handle this; let's just leave out the
18808 add_byte_size_attribute (dw_die_ref die, tree tree_node)
18812 switch (TREE_CODE (tree_node))
18817 case ENUMERAL_TYPE:
18820 case QUAL_UNION_TYPE:
18821 size = int_size_in_bytes (tree_node);
18824 /* For a data member of a struct or union, the DW_AT_byte_size is
18825 generally given as the number of bytes normally allocated for an
18826 object of the *declared* type of the member itself. This is true
18827 even for bit-fields. */
18828 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
18831 gcc_unreachable ();
18834 /* Note that `size' might be -1 when we get to this point. If it is, that
18835 indicates that the byte size of the entity in question is variable. We
18836 have no good way of expressing this fact in Dwarf at the present time,
18837 so just let the -1 pass on through. */
18838 add_AT_unsigned (die, DW_AT_byte_size, size);
18841 /* For a FIELD_DECL node which represents a bit-field, output an attribute
18842 which specifies the distance in bits from the highest order bit of the
18843 "containing object" for the bit-field to the highest order bit of the
18846 For any given bit-field, the "containing object" is a hypothetical object
18847 (of some integral or enum type) within which the given bit-field lives. The
18848 type of this hypothetical "containing object" is always the same as the
18849 declared type of the individual bit-field itself. The determination of the
18850 exact location of the "containing object" for a bit-field is rather
18851 complicated. It's handled by the `field_byte_offset' function (above).
18853 Note that it is the size (in bytes) of the hypothetical "containing object"
18854 which will be given in the DW_AT_byte_size attribute for this bit-field.
18855 (See `byte_size_attribute' above). */
18858 add_bit_offset_attribute (dw_die_ref die, tree decl)
18860 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
18861 tree type = DECL_BIT_FIELD_TYPE (decl);
18862 HOST_WIDE_INT bitpos_int;
18863 HOST_WIDE_INT highest_order_object_bit_offset;
18864 HOST_WIDE_INT highest_order_field_bit_offset;
18865 HOST_WIDE_INT bit_offset;
18867 /* Must be a field and a bit field. */
18868 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
18870 /* We can't yet handle bit-fields whose offsets are variable, so if we
18871 encounter such things, just return without generating any attribute
18872 whatsoever. Likewise for variable or too large size. */
18873 if (! host_integerp (bit_position (decl), 0)
18874 || ! host_integerp (DECL_SIZE (decl), 1))
18877 bitpos_int = int_bit_position (decl);
18879 /* Note that the bit offset is always the distance (in bits) from the
18880 highest-order bit of the "containing object" to the highest-order bit of
18881 the bit-field itself. Since the "high-order end" of any object or field
18882 is different on big-endian and little-endian machines, the computation
18883 below must take account of these differences. */
18884 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
18885 highest_order_field_bit_offset = bitpos_int;
18887 if (! BYTES_BIG_ENDIAN)
18889 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
18890 highest_order_object_bit_offset += simple_type_size_in_bits (type);
18894 = (! BYTES_BIG_ENDIAN
18895 ? highest_order_object_bit_offset - highest_order_field_bit_offset
18896 : highest_order_field_bit_offset - highest_order_object_bit_offset);
18898 if (bit_offset < 0)
18899 add_AT_int (die, DW_AT_bit_offset, bit_offset);
18901 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
18904 /* For a FIELD_DECL node which represents a bit field, output an attribute
18905 which specifies the length in bits of the given field. */
18908 add_bit_size_attribute (dw_die_ref die, tree decl)
18910 /* Must be a field and a bit field. */
18911 gcc_assert (TREE_CODE (decl) == FIELD_DECL
18912 && DECL_BIT_FIELD_TYPE (decl));
18914 if (host_integerp (DECL_SIZE (decl), 1))
18915 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
18918 /* If the compiled language is ANSI C, then add a 'prototyped'
18919 attribute, if arg types are given for the parameters of a function. */
18922 add_prototyped_attribute (dw_die_ref die, tree func_type)
18924 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
18925 && prototype_p (func_type))
18926 add_AT_flag (die, DW_AT_prototyped, 1);
18929 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
18930 by looking in either the type declaration or object declaration
18933 static inline dw_die_ref
18934 add_abstract_origin_attribute (dw_die_ref die, tree origin)
18936 dw_die_ref origin_die = NULL;
18938 if (TREE_CODE (origin) != FUNCTION_DECL)
18940 /* We may have gotten separated from the block for the inlined
18941 function, if we're in an exception handler or some such; make
18942 sure that the abstract function has been written out.
18944 Doing this for nested functions is wrong, however; functions are
18945 distinct units, and our context might not even be inline. */
18949 fn = TYPE_STUB_DECL (fn);
18951 fn = decl_function_context (fn);
18953 dwarf2out_abstract_function (fn);
18956 if (DECL_P (origin))
18957 origin_die = lookup_decl_die (origin);
18958 else if (TYPE_P (origin))
18959 origin_die = lookup_type_die (origin);
18961 /* XXX: Functions that are never lowered don't always have correct block
18962 trees (in the case of java, they simply have no block tree, in some other
18963 languages). For these functions, there is nothing we can really do to
18964 output correct debug info for inlined functions in all cases. Rather
18965 than die, we'll just produce deficient debug info now, in that we will
18966 have variables without a proper abstract origin. In the future, when all
18967 functions are lowered, we should re-add a gcc_assert (origin_die)
18971 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
18975 /* We do not currently support the pure_virtual attribute. */
18978 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
18980 if (DECL_VINDEX (func_decl))
18982 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18984 if (host_integerp (DECL_VINDEX (func_decl), 0))
18985 add_AT_loc (die, DW_AT_vtable_elem_location,
18986 new_loc_descr (DW_OP_constu,
18987 tree_low_cst (DECL_VINDEX (func_decl), 0),
18990 /* GNU extension: Record what type this method came from originally. */
18991 if (debug_info_level > DINFO_LEVEL_TERSE
18992 && DECL_CONTEXT (func_decl))
18993 add_AT_die_ref (die, DW_AT_containing_type,
18994 lookup_type_die (DECL_CONTEXT (func_decl)));
18998 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
18999 given decl. This used to be a vendor extension until after DWARF 4
19000 standardized it. */
19003 add_linkage_attr (dw_die_ref die, tree decl)
19005 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
19007 /* Mimic what assemble_name_raw does with a leading '*'. */
19008 if (name[0] == '*')
19011 if (dwarf_version >= 4)
19012 add_AT_string (die, DW_AT_linkage_name, name);
19014 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
19017 /* Add source coordinate attributes for the given decl. */
19020 add_src_coords_attributes (dw_die_ref die, tree decl)
19022 expanded_location s;
19024 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
19026 s = expand_location (DECL_SOURCE_LOCATION (decl));
19027 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
19028 add_AT_unsigned (die, DW_AT_decl_line, s.line);
19031 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
19034 add_linkage_name (dw_die_ref die, tree decl)
19036 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
19037 && TREE_PUBLIC (decl)
19038 && !DECL_ABSTRACT (decl)
19039 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
19040 && die->die_tag != DW_TAG_member)
19042 /* Defer until we have an assembler name set. */
19043 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
19045 limbo_die_node *asm_name;
19047 asm_name = ggc_alloc_cleared_limbo_die_node ();
19048 asm_name->die = die;
19049 asm_name->created_for = decl;
19050 asm_name->next = deferred_asm_name;
19051 deferred_asm_name = asm_name;
19053 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
19054 add_linkage_attr (die, decl);
19058 /* Add a DW_AT_name attribute and source coordinate attribute for the
19059 given decl, but only if it actually has a name. */
19062 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
19066 decl_name = DECL_NAME (decl);
19067 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
19069 const char *name = dwarf2_name (decl, 0);
19071 add_name_attribute (die, name);
19072 if (! DECL_ARTIFICIAL (decl))
19073 add_src_coords_attributes (die, decl);
19075 add_linkage_name (die, decl);
19078 #ifdef VMS_DEBUGGING_INFO
19079 /* Get the function's name, as described by its RTL. This may be different
19080 from the DECL_NAME name used in the source file. */
19081 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
19083 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
19084 XEXP (DECL_RTL (decl), 0));
19085 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
19087 #endif /* VMS_DEBUGGING_INFO */
19090 #ifdef VMS_DEBUGGING_INFO
19091 /* Output the debug main pointer die for VMS */
19094 dwarf2out_vms_debug_main_pointer (void)
19096 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19099 /* Allocate the VMS debug main subprogram die. */
19100 die = ggc_alloc_cleared_die_node ();
19101 die->die_tag = DW_TAG_subprogram;
19102 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
19103 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
19104 current_function_funcdef_no);
19105 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19107 /* Make it the first child of comp_unit_die (). */
19108 die->die_parent = comp_unit_die ();
19109 if (comp_unit_die ()->die_child)
19111 die->die_sib = comp_unit_die ()->die_child->die_sib;
19112 comp_unit_die ()->die_child->die_sib = die;
19116 die->die_sib = die;
19117 comp_unit_die ()->die_child = die;
19120 #endif /* VMS_DEBUGGING_INFO */
19122 /* Push a new declaration scope. */
19125 push_decl_scope (tree scope)
19127 VEC_safe_push (tree, gc, decl_scope_table, scope);
19130 /* Pop a declaration scope. */
19133 pop_decl_scope (void)
19135 VEC_pop (tree, decl_scope_table);
19138 /* Return the DIE for the scope that immediately contains this type.
19139 Non-named types get global scope. Named types nested in other
19140 types get their containing scope if it's open, or global scope
19141 otherwise. All other types (i.e. function-local named types) get
19142 the current active scope. */
19145 scope_die_for (tree t, dw_die_ref context_die)
19147 dw_die_ref scope_die = NULL;
19148 tree containing_scope;
19151 /* Non-types always go in the current scope. */
19152 gcc_assert (TYPE_P (t));
19154 containing_scope = TYPE_CONTEXT (t);
19156 /* Use the containing namespace if it was passed in (for a declaration). */
19157 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
19159 if (context_die == lookup_decl_die (containing_scope))
19162 containing_scope = NULL_TREE;
19165 /* Ignore function type "scopes" from the C frontend. They mean that
19166 a tagged type is local to a parmlist of a function declarator, but
19167 that isn't useful to DWARF. */
19168 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
19169 containing_scope = NULL_TREE;
19171 if (SCOPE_FILE_SCOPE_P (containing_scope))
19172 scope_die = comp_unit_die ();
19173 else if (TYPE_P (containing_scope))
19175 /* For types, we can just look up the appropriate DIE. But
19176 first we check to see if we're in the middle of emitting it
19177 so we know where the new DIE should go. */
19178 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
19179 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
19184 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
19185 || TREE_ASM_WRITTEN (containing_scope));
19186 /*We are not in the middle of emitting the type
19187 CONTAINING_SCOPE. Let's see if it's emitted already. */
19188 scope_die = lookup_type_die (containing_scope);
19190 /* If none of the current dies are suitable, we get file scope. */
19191 if (scope_die == NULL)
19192 scope_die = comp_unit_die ();
19195 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
19198 scope_die = context_die;
19203 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
19206 local_scope_p (dw_die_ref context_die)
19208 for (; context_die; context_die = context_die->die_parent)
19209 if (context_die->die_tag == DW_TAG_inlined_subroutine
19210 || context_die->die_tag == DW_TAG_subprogram)
19216 /* Returns nonzero if CONTEXT_DIE is a class. */
19219 class_scope_p (dw_die_ref context_die)
19221 return (context_die
19222 && (context_die->die_tag == DW_TAG_structure_type
19223 || context_die->die_tag == DW_TAG_class_type
19224 || context_die->die_tag == DW_TAG_interface_type
19225 || context_die->die_tag == DW_TAG_union_type));
19228 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
19229 whether or not to treat a DIE in this context as a declaration. */
19232 class_or_namespace_scope_p (dw_die_ref context_die)
19234 return (class_scope_p (context_die)
19235 || (context_die && context_die->die_tag == DW_TAG_namespace));
19238 /* Many forms of DIEs require a "type description" attribute. This
19239 routine locates the proper "type descriptor" die for the type given
19240 by 'type', and adds a DW_AT_type attribute below the given die. */
19243 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
19244 int decl_volatile, dw_die_ref context_die)
19246 enum tree_code code = TREE_CODE (type);
19247 dw_die_ref type_die = NULL;
19249 /* ??? If this type is an unnamed subrange type of an integral, floating-point
19250 or fixed-point type, use the inner type. This is because we have no
19251 support for unnamed types in base_type_die. This can happen if this is
19252 an Ada subrange type. Correct solution is emit a subrange type die. */
19253 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
19254 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
19255 type = TREE_TYPE (type), code = TREE_CODE (type);
19257 if (code == ERROR_MARK
19258 /* Handle a special case. For functions whose return type is void, we
19259 generate *no* type attribute. (Note that no object may have type
19260 `void', so this only applies to function return types). */
19261 || code == VOID_TYPE)
19264 type_die = modified_type_die (type,
19265 decl_const || TYPE_READONLY (type),
19266 decl_volatile || TYPE_VOLATILE (type),
19269 if (type_die != NULL)
19270 add_AT_die_ref (object_die, DW_AT_type, type_die);
19273 /* Given an object die, add the calling convention attribute for the
19274 function call type. */
19276 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
19278 enum dwarf_calling_convention value = DW_CC_normal;
19280 value = ((enum dwarf_calling_convention)
19281 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
19284 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
19286 /* DWARF 2 doesn't provide a way to identify a program's source-level
19287 entry point. DW_AT_calling_convention attributes are only meant
19288 to describe functions' calling conventions. However, lacking a
19289 better way to signal the Fortran main program, we used this for
19290 a long time, following existing custom. Now, DWARF 4 has
19291 DW_AT_main_subprogram, which we add below, but some tools still
19292 rely on the old way, which we thus keep. */
19293 value = DW_CC_program;
19295 if (dwarf_version >= 4 || !dwarf_strict)
19296 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
19299 /* Only add the attribute if the backend requests it, and
19300 is not DW_CC_normal. */
19301 if (value && (value != DW_CC_normal))
19302 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
19305 /* Given a tree pointer to a struct, class, union, or enum type node, return
19306 a pointer to the (string) tag name for the given type, or zero if the type
19307 was declared without a tag. */
19309 static const char *
19310 type_tag (const_tree type)
19312 const char *name = 0;
19314 if (TYPE_NAME (type) != 0)
19318 /* Find the IDENTIFIER_NODE for the type name. */
19319 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
19320 && !TYPE_NAMELESS (type))
19321 t = TYPE_NAME (type);
19323 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
19324 a TYPE_DECL node, regardless of whether or not a `typedef' was
19326 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
19327 && ! DECL_IGNORED_P (TYPE_NAME (type)))
19329 /* We want to be extra verbose. Don't call dwarf_name if
19330 DECL_NAME isn't set. The default hook for decl_printable_name
19331 doesn't like that, and in this context it's correct to return
19332 0, instead of "<anonymous>" or the like. */
19333 if (DECL_NAME (TYPE_NAME (type))
19334 && !DECL_NAMELESS (TYPE_NAME (type)))
19335 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
19338 /* Now get the name as a string, or invent one. */
19339 if (!name && t != 0)
19340 name = IDENTIFIER_POINTER (t);
19343 return (name == 0 || *name == '\0') ? 0 : name;
19346 /* Return the type associated with a data member, make a special check
19347 for bit field types. */
19350 member_declared_type (const_tree member)
19352 return (DECL_BIT_FIELD_TYPE (member)
19353 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
19356 /* Get the decl's label, as described by its RTL. This may be different
19357 from the DECL_NAME name used in the source file. */
19360 static const char *
19361 decl_start_label (tree decl)
19364 const char *fnname;
19366 x = DECL_RTL (decl);
19367 gcc_assert (MEM_P (x));
19370 gcc_assert (GET_CODE (x) == SYMBOL_REF);
19372 fnname = XSTR (x, 0);
19377 /* These routines generate the internal representation of the DIE's for
19378 the compilation unit. Debugging information is collected by walking
19379 the declaration trees passed in from dwarf2out_decl(). */
19382 gen_array_type_die (tree type, dw_die_ref context_die)
19384 dw_die_ref scope_die = scope_die_for (type, context_die);
19385 dw_die_ref array_die;
19387 /* GNU compilers represent multidimensional array types as sequences of one
19388 dimensional array types whose element types are themselves array types.
19389 We sometimes squish that down to a single array_type DIE with multiple
19390 subscripts in the Dwarf debugging info. The draft Dwarf specification
19391 say that we are allowed to do this kind of compression in C, because
19392 there is no difference between an array of arrays and a multidimensional
19393 array. We don't do this for Ada to remain as close as possible to the
19394 actual representation, which is especially important against the language
19395 flexibilty wrt arrays of variable size. */
19397 bool collapse_nested_arrays = !is_ada ();
19400 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
19401 DW_TAG_string_type doesn't have DW_AT_type attribute). */
19402 if (TYPE_STRING_FLAG (type)
19403 && TREE_CODE (type) == ARRAY_TYPE
19405 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
19407 HOST_WIDE_INT size;
19409 array_die = new_die (DW_TAG_string_type, scope_die, type);
19410 add_name_attribute (array_die, type_tag (type));
19411 equate_type_number_to_die (type, array_die);
19412 size = int_size_in_bytes (type);
19414 add_AT_unsigned (array_die, DW_AT_byte_size, size);
19415 else if (TYPE_DOMAIN (type) != NULL_TREE
19416 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
19417 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
19419 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
19420 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
19422 size = int_size_in_bytes (TREE_TYPE (szdecl));
19423 if (loc && size > 0)
19425 add_AT_location_description (array_die, DW_AT_string_length, loc);
19426 if (size != DWARF2_ADDR_SIZE)
19427 add_AT_unsigned (array_die, DW_AT_byte_size, size);
19433 /* ??? The SGI dwarf reader fails for array of array of enum types
19434 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
19435 array type comes before the outer array type. We thus call gen_type_die
19436 before we new_die and must prevent nested array types collapsing for this
19439 #ifdef MIPS_DEBUGGING_INFO
19440 gen_type_die (TREE_TYPE (type), context_die);
19441 collapse_nested_arrays = false;
19444 array_die = new_die (DW_TAG_array_type, scope_die, type);
19445 add_name_attribute (array_die, type_tag (type));
19446 add_gnat_descriptive_type_attribute (array_die, type, context_die);
19447 equate_type_number_to_die (type, array_die);
19449 if (TREE_CODE (type) == VECTOR_TYPE)
19450 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
19452 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19454 && TREE_CODE (type) == ARRAY_TYPE
19455 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
19456 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
19457 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
19460 /* We default the array ordering. SDB will probably do
19461 the right things even if DW_AT_ordering is not present. It's not even
19462 an issue until we start to get into multidimensional arrays anyway. If
19463 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
19464 then we'll have to put the DW_AT_ordering attribute back in. (But if
19465 and when we find out that we need to put these in, we will only do so
19466 for multidimensional arrays. */
19467 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
19470 #ifdef MIPS_DEBUGGING_INFO
19471 /* The SGI compilers handle arrays of unknown bound by setting
19472 AT_declaration and not emitting any subrange DIEs. */
19473 if (TREE_CODE (type) == ARRAY_TYPE
19474 && ! TYPE_DOMAIN (type))
19475 add_AT_flag (array_die, DW_AT_declaration, 1);
19478 if (TREE_CODE (type) == VECTOR_TYPE)
19480 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
19481 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
19482 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
19483 add_bound_info (subrange_die, DW_AT_upper_bound,
19484 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
19487 add_subscript_info (array_die, type, collapse_nested_arrays);
19489 /* Add representation of the type of the elements of this array type and
19490 emit the corresponding DIE if we haven't done it already. */
19491 element_type = TREE_TYPE (type);
19492 if (collapse_nested_arrays)
19493 while (TREE_CODE (element_type) == ARRAY_TYPE)
19495 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
19497 element_type = TREE_TYPE (element_type);
19500 #ifndef MIPS_DEBUGGING_INFO
19501 gen_type_die (element_type, context_die);
19504 add_type_attribute (array_die, element_type, 0, 0, context_die);
19506 if (get_AT (array_die, DW_AT_name))
19507 add_pubtype (type, array_die);
19510 static dw_loc_descr_ref
19511 descr_info_loc (tree val, tree base_decl)
19513 HOST_WIDE_INT size;
19514 dw_loc_descr_ref loc, loc2;
19515 enum dwarf_location_atom op;
19517 if (val == base_decl)
19518 return new_loc_descr (DW_OP_push_object_address, 0, 0);
19520 switch (TREE_CODE (val))
19523 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19525 return loc_descriptor_from_tree (val, 0);
19527 if (host_integerp (val, 0))
19528 return int_loc_descriptor (tree_low_cst (val, 0));
19531 size = int_size_in_bytes (TREE_TYPE (val));
19534 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19537 if (size == DWARF2_ADDR_SIZE)
19538 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
19540 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
19542 case POINTER_PLUS_EXPR:
19544 if (host_integerp (TREE_OPERAND (val, 1), 1)
19545 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
19548 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19551 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
19557 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19560 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
19563 add_loc_descr (&loc, loc2);
19564 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
19586 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
19587 tree val, tree base_decl)
19589 dw_loc_descr_ref loc;
19591 if (host_integerp (val, 0))
19593 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
19597 loc = descr_info_loc (val, base_decl);
19601 add_AT_loc (die, attr, loc);
19604 /* This routine generates DIE for array with hidden descriptor, details
19605 are filled into *info by a langhook. */
19608 gen_descr_array_type_die (tree type, struct array_descr_info *info,
19609 dw_die_ref context_die)
19611 dw_die_ref scope_die = scope_die_for (type, context_die);
19612 dw_die_ref array_die;
19615 array_die = new_die (DW_TAG_array_type, scope_die, type);
19616 add_name_attribute (array_die, type_tag (type));
19617 equate_type_number_to_die (type, array_die);
19619 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19621 && info->ndimensions >= 2)
19622 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
19624 if (info->data_location)
19625 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
19627 if (info->associated)
19628 add_descr_info_field (array_die, DW_AT_associated, info->associated,
19630 if (info->allocated)
19631 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
19634 for (dim = 0; dim < info->ndimensions; dim++)
19636 dw_die_ref subrange_die
19637 = new_die (DW_TAG_subrange_type, array_die, NULL);
19639 if (info->dimen[dim].lower_bound)
19641 /* If it is the default value, omit it. */
19644 if (host_integerp (info->dimen[dim].lower_bound, 0)
19645 && (dflt = lower_bound_default ()) != -1
19646 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
19649 add_descr_info_field (subrange_die, DW_AT_lower_bound,
19650 info->dimen[dim].lower_bound,
19653 if (info->dimen[dim].upper_bound)
19654 add_descr_info_field (subrange_die, DW_AT_upper_bound,
19655 info->dimen[dim].upper_bound,
19657 if (info->dimen[dim].stride)
19658 add_descr_info_field (subrange_die, DW_AT_byte_stride,
19659 info->dimen[dim].stride,
19663 gen_type_die (info->element_type, context_die);
19664 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
19666 if (get_AT (array_die, DW_AT_name))
19667 add_pubtype (type, array_die);
19672 gen_entry_point_die (tree decl, dw_die_ref context_die)
19674 tree origin = decl_ultimate_origin (decl);
19675 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
19677 if (origin != NULL)
19678 add_abstract_origin_attribute (decl_die, origin);
19681 add_name_and_src_coords_attributes (decl_die, decl);
19682 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
19683 0, 0, context_die);
19686 if (DECL_ABSTRACT (decl))
19687 equate_decl_number_to_die (decl, decl_die);
19689 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
19693 /* Walk through the list of incomplete types again, trying once more to
19694 emit full debugging info for them. */
19697 retry_incomplete_types (void)
19701 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
19702 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
19703 DINFO_USAGE_DIR_USE))
19704 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
19707 /* Determine what tag to use for a record type. */
19709 static enum dwarf_tag
19710 record_type_tag (tree type)
19712 if (! lang_hooks.types.classify_record)
19713 return DW_TAG_structure_type;
19715 switch (lang_hooks.types.classify_record (type))
19717 case RECORD_IS_STRUCT:
19718 return DW_TAG_structure_type;
19720 case RECORD_IS_CLASS:
19721 return DW_TAG_class_type;
19723 case RECORD_IS_INTERFACE:
19724 if (dwarf_version >= 3 || !dwarf_strict)
19725 return DW_TAG_interface_type;
19726 return DW_TAG_structure_type;
19729 gcc_unreachable ();
19733 /* Generate a DIE to represent an enumeration type. Note that these DIEs
19734 include all of the information about the enumeration values also. Each
19735 enumerated type name/value is listed as a child of the enumerated type
19739 gen_enumeration_type_die (tree type, dw_die_ref context_die)
19741 dw_die_ref type_die = lookup_type_die (type);
19743 if (type_die == NULL)
19745 type_die = new_die (DW_TAG_enumeration_type,
19746 scope_die_for (type, context_die), type);
19747 equate_type_number_to_die (type, type_die);
19748 add_name_attribute (type_die, type_tag (type));
19749 add_gnat_descriptive_type_attribute (type_die, type, context_die);
19750 if (dwarf_version >= 4 || !dwarf_strict)
19752 if (ENUM_IS_SCOPED (type))
19753 add_AT_flag (type_die, DW_AT_enum_class, 1);
19754 if (ENUM_IS_OPAQUE (type))
19755 add_AT_flag (type_die, DW_AT_declaration, 1);
19758 else if (! TYPE_SIZE (type))
19761 remove_AT (type_die, DW_AT_declaration);
19763 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
19764 given enum type is incomplete, do not generate the DW_AT_byte_size
19765 attribute or the DW_AT_element_list attribute. */
19766 if (TYPE_SIZE (type))
19770 TREE_ASM_WRITTEN (type) = 1;
19771 add_byte_size_attribute (type_die, type);
19772 if (TYPE_STUB_DECL (type) != NULL_TREE)
19774 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
19775 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
19778 /* If the first reference to this type was as the return type of an
19779 inline function, then it may not have a parent. Fix this now. */
19780 if (type_die->die_parent == NULL)
19781 add_child_die (scope_die_for (type, context_die), type_die);
19783 for (link = TYPE_VALUES (type);
19784 link != NULL; link = TREE_CHAIN (link))
19786 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
19787 tree value = TREE_VALUE (link);
19789 add_name_attribute (enum_die,
19790 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
19792 if (TREE_CODE (value) == CONST_DECL)
19793 value = DECL_INITIAL (value);
19795 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
19796 /* DWARF2 does not provide a way of indicating whether or
19797 not enumeration constants are signed or unsigned. GDB
19798 always assumes the values are signed, so we output all
19799 values as if they were signed. That means that
19800 enumeration constants with very large unsigned values
19801 will appear to have negative values in the debugger. */
19802 add_AT_int (enum_die, DW_AT_const_value,
19803 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
19807 add_AT_flag (type_die, DW_AT_declaration, 1);
19809 if (get_AT (type_die, DW_AT_name))
19810 add_pubtype (type, type_die);
19815 /* Generate a DIE to represent either a real live formal parameter decl or to
19816 represent just the type of some formal parameter position in some function
19819 Note that this routine is a bit unusual because its argument may be a
19820 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
19821 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
19822 node. If it's the former then this function is being called to output a
19823 DIE to represent a formal parameter object (or some inlining thereof). If
19824 it's the latter, then this function is only being called to output a
19825 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
19826 argument type of some subprogram type.
19827 If EMIT_NAME_P is true, name and source coordinate attributes
19831 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
19832 dw_die_ref context_die)
19834 tree node_or_origin = node ? node : origin;
19835 tree ultimate_origin;
19836 dw_die_ref parm_die
19837 = new_die (DW_TAG_formal_parameter, context_die, node);
19839 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
19841 case tcc_declaration:
19842 ultimate_origin = decl_ultimate_origin (node_or_origin);
19843 if (node || ultimate_origin)
19844 origin = ultimate_origin;
19845 if (origin != NULL)
19846 add_abstract_origin_attribute (parm_die, origin);
19847 else if (emit_name_p)
19848 add_name_and_src_coords_attributes (parm_die, node);
19850 || (! DECL_ABSTRACT (node_or_origin)
19851 && variably_modified_type_p (TREE_TYPE (node_or_origin),
19852 decl_function_context
19853 (node_or_origin))))
19855 tree type = TREE_TYPE (node_or_origin);
19856 if (decl_by_reference_p (node_or_origin))
19857 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
19860 add_type_attribute (parm_die, type,
19861 TREE_READONLY (node_or_origin),
19862 TREE_THIS_VOLATILE (node_or_origin),
19865 if (origin == NULL && DECL_ARTIFICIAL (node))
19866 add_AT_flag (parm_die, DW_AT_artificial, 1);
19868 if (node && node != origin)
19869 equate_decl_number_to_die (node, parm_die);
19870 if (! DECL_ABSTRACT (node_or_origin))
19871 add_location_or_const_value_attribute (parm_die, node_or_origin,
19872 node == NULL, DW_AT_location);
19877 /* We were called with some kind of a ..._TYPE node. */
19878 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
19882 gcc_unreachable ();
19888 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
19889 children DW_TAG_formal_parameter DIEs representing the arguments of the
19892 PARM_PACK must be a function parameter pack.
19893 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
19894 must point to the subsequent arguments of the function PACK_ARG belongs to.
19895 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
19896 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
19897 following the last one for which a DIE was generated. */
19900 gen_formal_parameter_pack_die (tree parm_pack,
19902 dw_die_ref subr_die,
19906 dw_die_ref parm_pack_die;
19908 gcc_assert (parm_pack
19909 && lang_hooks.function_parameter_pack_p (parm_pack)
19912 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
19913 add_src_coords_attributes (parm_pack_die, parm_pack);
19915 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
19917 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
19920 gen_formal_parameter_die (arg, NULL,
19921 false /* Don't emit name attribute. */,
19926 return parm_pack_die;
19929 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
19930 at the end of an (ANSI prototyped) formal parameters list. */
19933 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
19935 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
19938 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
19939 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
19940 parameters as specified in some function type specification (except for
19941 those which appear as part of a function *definition*). */
19944 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
19947 tree formal_type = NULL;
19948 tree first_parm_type;
19951 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
19953 arg = DECL_ARGUMENTS (function_or_method_type);
19954 function_or_method_type = TREE_TYPE (function_or_method_type);
19959 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
19961 /* Make our first pass over the list of formal parameter types and output a
19962 DW_TAG_formal_parameter DIE for each one. */
19963 for (link = first_parm_type; link; )
19965 dw_die_ref parm_die;
19967 formal_type = TREE_VALUE (link);
19968 if (formal_type == void_type_node)
19971 /* Output a (nameless) DIE to represent the formal parameter itself. */
19972 parm_die = gen_formal_parameter_die (formal_type, NULL,
19973 true /* Emit name attribute. */,
19975 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
19976 && link == first_parm_type)
19978 add_AT_flag (parm_die, DW_AT_artificial, 1);
19979 if (dwarf_version >= 3 || !dwarf_strict)
19980 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
19982 else if (arg && DECL_ARTIFICIAL (arg))
19983 add_AT_flag (parm_die, DW_AT_artificial, 1);
19985 link = TREE_CHAIN (link);
19987 arg = DECL_CHAIN (arg);
19990 /* If this function type has an ellipsis, add a
19991 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
19992 if (formal_type != void_type_node)
19993 gen_unspecified_parameters_die (function_or_method_type, context_die);
19995 /* Make our second (and final) pass over the list of formal parameter types
19996 and output DIEs to represent those types (as necessary). */
19997 for (link = TYPE_ARG_TYPES (function_or_method_type);
19998 link && TREE_VALUE (link);
19999 link = TREE_CHAIN (link))
20000 gen_type_die (TREE_VALUE (link), context_die);
20003 /* We want to generate the DIE for TYPE so that we can generate the
20004 die for MEMBER, which has been defined; we will need to refer back
20005 to the member declaration nested within TYPE. If we're trying to
20006 generate minimal debug info for TYPE, processing TYPE won't do the
20007 trick; we need to attach the member declaration by hand. */
20010 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
20012 gen_type_die (type, context_die);
20014 /* If we're trying to avoid duplicate debug info, we may not have
20015 emitted the member decl for this function. Emit it now. */
20016 if (TYPE_STUB_DECL (type)
20017 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
20018 && ! lookup_decl_die (member))
20020 dw_die_ref type_die;
20021 gcc_assert (!decl_ultimate_origin (member));
20023 push_decl_scope (type);
20024 type_die = lookup_type_die_strip_naming_typedef (type);
20025 if (TREE_CODE (member) == FUNCTION_DECL)
20026 gen_subprogram_die (member, type_die);
20027 else if (TREE_CODE (member) == FIELD_DECL)
20029 /* Ignore the nameless fields that are used to skip bits but handle
20030 C++ anonymous unions and structs. */
20031 if (DECL_NAME (member) != NULL_TREE
20032 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
20033 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
20035 gen_type_die (member_declared_type (member), type_die);
20036 gen_field_die (member, type_die);
20040 gen_variable_die (member, NULL_TREE, type_die);
20046 /* Generate the DWARF2 info for the "abstract" instance of a function which we
20047 may later generate inlined and/or out-of-line instances of. */
20050 dwarf2out_abstract_function (tree decl)
20052 dw_die_ref old_die;
20056 htab_t old_decl_loc_table;
20057 htab_t old_cached_dw_loc_list_table;
20058 int old_call_site_count, old_tail_call_site_count;
20059 struct call_arg_loc_node *old_call_arg_locations;
20061 /* Make sure we have the actual abstract inline, not a clone. */
20062 decl = DECL_ORIGIN (decl);
20064 old_die = lookup_decl_die (decl);
20065 if (old_die && get_AT (old_die, DW_AT_inline))
20066 /* We've already generated the abstract instance. */
20069 /* We can be called while recursively when seeing block defining inlined subroutine
20070 DIE. Be sure to not clobber the outer location table nor use it or we would
20071 get locations in abstract instantces. */
20072 old_decl_loc_table = decl_loc_table;
20073 decl_loc_table = NULL;
20074 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
20075 cached_dw_loc_list_table = NULL;
20076 old_call_arg_locations = call_arg_locations;
20077 call_arg_locations = NULL;
20078 old_call_site_count = call_site_count;
20079 call_site_count = -1;
20080 old_tail_call_site_count = tail_call_site_count;
20081 tail_call_site_count = -1;
20083 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
20084 we don't get confused by DECL_ABSTRACT. */
20085 if (debug_info_level > DINFO_LEVEL_TERSE)
20087 context = decl_class_context (decl);
20089 gen_type_die_for_member
20090 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
20093 /* Pretend we've just finished compiling this function. */
20094 save_fn = current_function_decl;
20095 current_function_decl = decl;
20096 push_cfun (DECL_STRUCT_FUNCTION (decl));
20098 was_abstract = DECL_ABSTRACT (decl);
20099 set_decl_abstract_flags (decl, 1);
20100 dwarf2out_decl (decl);
20101 if (! was_abstract)
20102 set_decl_abstract_flags (decl, 0);
20104 current_function_decl = save_fn;
20105 decl_loc_table = old_decl_loc_table;
20106 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
20107 call_arg_locations = old_call_arg_locations;
20108 call_site_count = old_call_site_count;
20109 tail_call_site_count = old_tail_call_site_count;
20113 /* Helper function of premark_used_types() which gets called through
20116 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20117 marked as unused by prune_unused_types. */
20120 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
20125 type = (tree) *slot;
20126 die = lookup_type_die (type);
20128 die->die_perennial_p = 1;
20132 /* Helper function of premark_types_used_by_global_vars which gets called
20133 through htab_traverse.
20135 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20136 marked as unused by prune_unused_types. The DIE of the type is marked
20137 only if the global variable using the type will actually be emitted. */
20140 premark_types_used_by_global_vars_helper (void **slot,
20141 void *data ATTRIBUTE_UNUSED)
20143 struct types_used_by_vars_entry *entry;
20146 entry = (struct types_used_by_vars_entry *) *slot;
20147 gcc_assert (entry->type != NULL
20148 && entry->var_decl != NULL);
20149 die = lookup_type_die (entry->type);
20152 /* Ask cgraph if the global variable really is to be emitted.
20153 If yes, then we'll keep the DIE of ENTRY->TYPE. */
20154 struct varpool_node *node = varpool_get_node (entry->var_decl);
20155 if (node && node->needed)
20157 die->die_perennial_p = 1;
20158 /* Keep the parent DIEs as well. */
20159 while ((die = die->die_parent) && die->die_perennial_p == 0)
20160 die->die_perennial_p = 1;
20166 /* Mark all members of used_types_hash as perennial. */
20169 premark_used_types (void)
20171 if (cfun && cfun->used_types_hash)
20172 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
20175 /* Mark all members of types_used_by_vars_entry as perennial. */
20178 premark_types_used_by_global_vars (void)
20180 if (types_used_by_vars_hash)
20181 htab_traverse (types_used_by_vars_hash,
20182 premark_types_used_by_global_vars_helper, NULL);
20185 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
20186 for CA_LOC call arg loc node. */
20189 gen_call_site_die (tree decl, dw_die_ref subr_die,
20190 struct call_arg_loc_node *ca_loc)
20192 dw_die_ref stmt_die = NULL, die;
20193 tree block = ca_loc->block;
20196 && block != DECL_INITIAL (decl)
20197 && TREE_CODE (block) == BLOCK)
20199 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
20200 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
20203 block = BLOCK_SUPERCONTEXT (block);
20205 if (stmt_die == NULL)
20206 stmt_die = subr_die;
20207 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
20208 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
20209 if (ca_loc->tail_call_p)
20210 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
20211 if (ca_loc->symbol_ref)
20213 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
20215 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
20217 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
20222 /* Generate a DIE to represent a declared function (either file-scope or
20226 gen_subprogram_die (tree decl, dw_die_ref context_die)
20228 tree origin = decl_ultimate_origin (decl);
20229 dw_die_ref subr_die;
20231 dw_die_ref old_die = lookup_decl_die (decl);
20232 int declaration = (current_function_decl != decl
20233 || class_or_namespace_scope_p (context_die));
20235 premark_used_types ();
20237 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
20238 started to generate the abstract instance of an inline, decided to output
20239 its containing class, and proceeded to emit the declaration of the inline
20240 from the member list for the class. If so, DECLARATION takes priority;
20241 we'll get back to the abstract instance when done with the class. */
20243 /* The class-scope declaration DIE must be the primary DIE. */
20244 if (origin && declaration && class_or_namespace_scope_p (context_die))
20247 gcc_assert (!old_die);
20250 /* Now that the C++ front end lazily declares artificial member fns, we
20251 might need to retrofit the declaration into its class. */
20252 if (!declaration && !origin && !old_die
20253 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
20254 && !class_or_namespace_scope_p (context_die)
20255 && debug_info_level > DINFO_LEVEL_TERSE)
20256 old_die = force_decl_die (decl);
20258 if (origin != NULL)
20260 gcc_assert (!declaration || local_scope_p (context_die));
20262 /* Fixup die_parent for the abstract instance of a nested
20263 inline function. */
20264 if (old_die && old_die->die_parent == NULL)
20265 add_child_die (context_die, old_die);
20267 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20268 add_abstract_origin_attribute (subr_die, origin);
20269 /* This is where the actual code for a cloned function is.
20270 Let's emit linkage name attribute for it. This helps
20271 debuggers to e.g, set breakpoints into
20272 constructors/destructors when the user asks "break
20274 add_linkage_name (subr_die, decl);
20278 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
20279 struct dwarf_file_data * file_index = lookup_filename (s.file);
20281 if (!get_AT_flag (old_die, DW_AT_declaration)
20282 /* We can have a normal definition following an inline one in the
20283 case of redefinition of GNU C extern inlines.
20284 It seems reasonable to use AT_specification in this case. */
20285 && !get_AT (old_die, DW_AT_inline))
20287 /* Detect and ignore this case, where we are trying to output
20288 something we have already output. */
20292 /* If the definition comes from the same place as the declaration,
20293 maybe use the old DIE. We always want the DIE for this function
20294 that has the *_pc attributes to be under comp_unit_die so the
20295 debugger can find it. We also need to do this for abstract
20296 instances of inlines, since the spec requires the out-of-line copy
20297 to have the same parent. For local class methods, this doesn't
20298 apply; we just use the old DIE. */
20299 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
20300 && (DECL_ARTIFICIAL (decl)
20301 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
20302 && (get_AT_unsigned (old_die, DW_AT_decl_line)
20303 == (unsigned) s.line))))
20305 subr_die = old_die;
20307 /* Clear out the declaration attribute and the formal parameters.
20308 Do not remove all children, because it is possible that this
20309 declaration die was forced using force_decl_die(). In such
20310 cases die that forced declaration die (e.g. TAG_imported_module)
20311 is one of the children that we do not want to remove. */
20312 remove_AT (subr_die, DW_AT_declaration);
20313 remove_AT (subr_die, DW_AT_object_pointer);
20314 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
20318 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20319 add_AT_specification (subr_die, old_die);
20320 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
20321 add_AT_file (subr_die, DW_AT_decl_file, file_index);
20322 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
20323 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
20328 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20330 if (TREE_PUBLIC (decl))
20331 add_AT_flag (subr_die, DW_AT_external, 1);
20333 add_name_and_src_coords_attributes (subr_die, decl);
20334 if (debug_info_level > DINFO_LEVEL_TERSE)
20336 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
20337 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
20338 0, 0, context_die);
20341 add_pure_or_virtual_attribute (subr_die, decl);
20342 if (DECL_ARTIFICIAL (decl))
20343 add_AT_flag (subr_die, DW_AT_artificial, 1);
20345 add_accessibility_attribute (subr_die, decl);
20350 if (!old_die || !get_AT (old_die, DW_AT_inline))
20352 add_AT_flag (subr_die, DW_AT_declaration, 1);
20354 /* If this is an explicit function declaration then generate
20355 a DW_AT_explicit attribute. */
20356 if (lang_hooks.decls.function_decl_explicit_p (decl)
20357 && (dwarf_version >= 3 || !dwarf_strict))
20358 add_AT_flag (subr_die, DW_AT_explicit, 1);
20360 /* The first time we see a member function, it is in the context of
20361 the class to which it belongs. We make sure of this by emitting
20362 the class first. The next time is the definition, which is
20363 handled above. The two may come from the same source text.
20365 Note that force_decl_die() forces function declaration die. It is
20366 later reused to represent definition. */
20367 equate_decl_number_to_die (decl, subr_die);
20370 else if (DECL_ABSTRACT (decl))
20372 if (DECL_DECLARED_INLINE_P (decl))
20374 if (cgraph_function_possibly_inlined_p (decl))
20375 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
20377 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
20381 if (cgraph_function_possibly_inlined_p (decl))
20382 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
20384 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
20387 if (DECL_DECLARED_INLINE_P (decl)
20388 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
20389 add_AT_flag (subr_die, DW_AT_artificial, 1);
20391 equate_decl_number_to_die (decl, subr_die);
20393 else if (!DECL_EXTERNAL (decl))
20395 HOST_WIDE_INT cfa_fb_offset;
20397 if (!old_die || !get_AT (old_die, DW_AT_inline))
20398 equate_decl_number_to_die (decl, subr_die);
20400 if (!flag_reorder_blocks_and_partition)
20402 dw_fde_ref fde = &fde_table[current_funcdef_fde];
20403 if (fde->dw_fde_begin)
20405 /* We have already generated the labels. */
20406 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
20407 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
20411 /* Create start/end labels and add the range. */
20412 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
20413 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
20414 current_function_funcdef_no);
20415 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
20416 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
20417 current_function_funcdef_no);
20418 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
20421 #if VMS_DEBUGGING_INFO
20422 /* HP OpenVMS Industry Standard 64: DWARF Extensions
20423 Section 2.3 Prologue and Epilogue Attributes:
20424 When a breakpoint is set on entry to a function, it is generally
20425 desirable for execution to be suspended, not on the very first
20426 instruction of the function, but rather at a point after the
20427 function's frame has been set up, after any language defined local
20428 declaration processing has been completed, and before execution of
20429 the first statement of the function begins. Debuggers generally
20430 cannot properly determine where this point is. Similarly for a
20431 breakpoint set on exit from a function. The prologue and epilogue
20432 attributes allow a compiler to communicate the location(s) to use. */
20435 if (fde->dw_fde_vms_end_prologue)
20436 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
20437 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
20439 if (fde->dw_fde_vms_begin_epilogue)
20440 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
20441 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
20445 add_pubname (decl, subr_die);
20448 { /* Generate pubnames entries for the split function code
20450 dw_fde_ref fde = &fde_table[current_funcdef_fde];
20452 if (fde->dw_fde_second_begin)
20454 if (dwarf_version >= 3 || !dwarf_strict)
20456 /* We should use ranges for non-contiguous code section
20457 addresses. Use the actual code range for the initial
20458 section, since the HOT/COLD labels might precede an
20459 alignment offset. */
20460 bool range_list_added = false;
20461 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
20462 fde->dw_fde_end, &range_list_added);
20463 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
20464 fde->dw_fde_second_end,
20465 &range_list_added);
20466 add_pubname (decl, subr_die);
20467 if (range_list_added)
20472 /* There is no real support in DW2 for this .. so we make
20473 a work-around. First, emit the pub name for the segment
20474 containing the function label. Then make and emit a
20475 simplified subprogram DIE for the second segment with the
20476 name pre-fixed by __hot/cold_sect_of_. We use the same
20477 linkage name for the second die so that gdb will find both
20478 sections when given "b foo". */
20479 const char *name = NULL;
20480 tree decl_name = DECL_NAME (decl);
20481 dw_die_ref seg_die;
20483 /* Do the 'primary' section. */
20484 add_AT_lbl_id (subr_die, DW_AT_low_pc,
20485 fde->dw_fde_begin);
20486 add_AT_lbl_id (subr_die, DW_AT_high_pc,
20489 add_pubname (decl, subr_die);
20491 /* Build a minimal DIE for the secondary section. */
20492 seg_die = new_die (DW_TAG_subprogram,
20493 subr_die->die_parent, decl);
20495 if (TREE_PUBLIC (decl))
20496 add_AT_flag (seg_die, DW_AT_external, 1);
20498 if (decl_name != NULL
20499 && IDENTIFIER_POINTER (decl_name) != NULL)
20501 name = dwarf2_name (decl, 1);
20502 if (! DECL_ARTIFICIAL (decl))
20503 add_src_coords_attributes (seg_die, decl);
20505 add_linkage_name (seg_die, decl);
20507 gcc_assert (name != NULL);
20508 add_pure_or_virtual_attribute (seg_die, decl);
20509 if (DECL_ARTIFICIAL (decl))
20510 add_AT_flag (seg_die, DW_AT_artificial, 1);
20512 name = concat ("__second_sect_of_", name, NULL);
20513 add_AT_lbl_id (seg_die, DW_AT_low_pc,
20514 fde->dw_fde_second_begin);
20515 add_AT_lbl_id (seg_die, DW_AT_high_pc,
20516 fde->dw_fde_second_end);
20517 add_name_attribute (seg_die, name);
20518 add_pubname_string (name, seg_die);
20523 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
20524 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
20525 add_pubname (decl, subr_die);
20529 #ifdef MIPS_DEBUGGING_INFO
20530 /* Add a reference to the FDE for this routine. */
20531 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
20534 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
20536 /* We define the "frame base" as the function's CFA. This is more
20537 convenient for several reasons: (1) It's stable across the prologue
20538 and epilogue, which makes it better than just a frame pointer,
20539 (2) With dwarf3, there exists a one-byte encoding that allows us
20540 to reference the .debug_frame data by proxy, but failing that,
20541 (3) We can at least reuse the code inspection and interpretation
20542 code that determines the CFA position at various points in the
20544 if (dwarf_version >= 3)
20546 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
20547 add_AT_loc (subr_die, DW_AT_frame_base, op);
20551 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
20552 if (list->dw_loc_next)
20553 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
20555 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
20558 /* Compute a displacement from the "steady-state frame pointer" to
20559 the CFA. The former is what all stack slots and argument slots
20560 will reference in the rtl; the later is what we've told the
20561 debugger about. We'll need to adjust all frame_base references
20562 by this displacement. */
20563 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
20565 if (cfun->static_chain_decl)
20566 add_AT_location_description (subr_die, DW_AT_static_link,
20567 loc_list_from_tree (cfun->static_chain_decl, 2));
20570 /* Generate child dies for template paramaters. */
20571 if (debug_info_level > DINFO_LEVEL_TERSE)
20572 gen_generic_params_dies (decl);
20574 /* Now output descriptions of the arguments for this function. This gets
20575 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
20576 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
20577 `...' at the end of the formal parameter list. In order to find out if
20578 there was a trailing ellipsis or not, we must instead look at the type
20579 associated with the FUNCTION_DECL. This will be a node of type
20580 FUNCTION_TYPE. If the chain of type nodes hanging off of this
20581 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
20582 an ellipsis at the end. */
20584 /* In the case where we are describing a mere function declaration, all we
20585 need to do here (and all we *can* do here) is to describe the *types* of
20586 its formal parameters. */
20587 if (debug_info_level <= DINFO_LEVEL_TERSE)
20589 else if (declaration)
20590 gen_formal_types_die (decl, subr_die);
20593 /* Generate DIEs to represent all known formal parameters. */
20594 tree parm = DECL_ARGUMENTS (decl);
20595 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
20596 tree generic_decl_parm = generic_decl
20597 ? DECL_ARGUMENTS (generic_decl)
20600 /* Now we want to walk the list of parameters of the function and
20601 emit their relevant DIEs.
20603 We consider the case of DECL being an instance of a generic function
20604 as well as it being a normal function.
20606 If DECL is an instance of a generic function we walk the
20607 parameters of the generic function declaration _and_ the parameters of
20608 DECL itself. This is useful because we want to emit specific DIEs for
20609 function parameter packs and those are declared as part of the
20610 generic function declaration. In that particular case,
20611 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
20612 That DIE has children DIEs representing the set of arguments
20613 of the pack. Note that the set of pack arguments can be empty.
20614 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
20617 Otherwise, we just consider the parameters of DECL. */
20618 while (generic_decl_parm || parm)
20620 if (generic_decl_parm
20621 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
20622 gen_formal_parameter_pack_die (generic_decl_parm,
20627 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
20629 if (parm == DECL_ARGUMENTS (decl)
20630 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
20632 && (dwarf_version >= 3 || !dwarf_strict))
20633 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
20635 parm = DECL_CHAIN (parm);
20638 if (generic_decl_parm)
20639 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
20642 /* Decide whether we need an unspecified_parameters DIE at the end.
20643 There are 2 more cases to do this for: 1) the ansi ... declaration -
20644 this is detectable when the end of the arg list is not a
20645 void_type_node 2) an unprototyped function declaration (not a
20646 definition). This just means that we have no info about the
20647 parameters at all. */
20648 if (prototype_p (TREE_TYPE (decl)))
20650 /* This is the prototyped case, check for.... */
20651 if (stdarg_p (TREE_TYPE (decl)))
20652 gen_unspecified_parameters_die (decl, subr_die);
20654 else if (DECL_INITIAL (decl) == NULL_TREE)
20655 gen_unspecified_parameters_die (decl, subr_die);
20658 /* Output Dwarf info for all of the stuff within the body of the function
20659 (if it has one - it may be just a declaration). */
20660 outer_scope = DECL_INITIAL (decl);
20662 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
20663 a function. This BLOCK actually represents the outermost binding contour
20664 for the function, i.e. the contour in which the function's formal
20665 parameters and labels get declared. Curiously, it appears that the front
20666 end doesn't actually put the PARM_DECL nodes for the current function onto
20667 the BLOCK_VARS list for this outer scope, but are strung off of the
20668 DECL_ARGUMENTS list for the function instead.
20670 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
20671 the LABEL_DECL nodes for the function however, and we output DWARF info
20672 for those in decls_for_scope. Just within the `outer_scope' there will be
20673 a BLOCK node representing the function's outermost pair of curly braces,
20674 and any blocks used for the base and member initializers of a C++
20675 constructor function. */
20676 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
20678 int call_site_note_count = 0;
20679 int tail_call_site_note_count = 0;
20681 /* Emit a DW_TAG_variable DIE for a named return value. */
20682 if (DECL_NAME (DECL_RESULT (decl)))
20683 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
20685 current_function_has_inlines = 0;
20686 decls_for_scope (outer_scope, subr_die, 0);
20688 if (call_arg_locations && !dwarf_strict)
20690 struct call_arg_loc_node *ca_loc;
20691 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
20693 dw_die_ref die = NULL;
20694 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
20697 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
20698 arg; arg = next_arg)
20700 dw_loc_descr_ref reg, val;
20701 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
20702 dw_die_ref cdie, tdie = NULL;
20704 next_arg = XEXP (arg, 1);
20705 if (REG_P (XEXP (XEXP (arg, 0), 0))
20707 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
20708 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
20709 && REGNO (XEXP (XEXP (arg, 0), 0))
20710 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
20711 next_arg = XEXP (next_arg, 1);
20712 if (mode == VOIDmode)
20714 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
20715 if (mode == VOIDmode)
20716 mode = GET_MODE (XEXP (arg, 0));
20718 if (mode == VOIDmode || mode == BLKmode)
20720 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
20722 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
20723 tloc = XEXP (XEXP (arg, 0), 1);
20726 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
20727 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
20729 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
20730 tlocc = XEXP (XEXP (arg, 0), 1);
20734 if (REG_P (XEXP (XEXP (arg, 0), 0)))
20735 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
20736 VAR_INIT_STATUS_INITIALIZED);
20737 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
20739 rtx mem = XEXP (XEXP (arg, 0), 0);
20740 reg = mem_loc_descriptor (XEXP (mem, 0),
20741 get_address_mode (mem),
20743 VAR_INIT_STATUS_INITIALIZED);
20745 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
20746 == DEBUG_PARAMETER_REF)
20749 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
20750 tdie = lookup_decl_die (tdecl);
20757 && GET_CODE (XEXP (XEXP (arg, 0), 0))
20758 != DEBUG_PARAMETER_REF)
20760 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
20762 VAR_INIT_STATUS_INITIALIZED);
20766 die = gen_call_site_die (decl, subr_die, ca_loc);
20767 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
20770 add_AT_loc (cdie, DW_AT_location, reg);
20771 else if (tdie != NULL)
20772 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
20773 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
20774 if (next_arg != XEXP (arg, 1))
20776 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
20777 if (mode == VOIDmode)
20778 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
20779 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
20782 VAR_INIT_STATUS_INITIALIZED);
20784 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
20788 && (ca_loc->symbol_ref || tloc))
20789 die = gen_call_site_die (decl, subr_die, ca_loc);
20790 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
20792 dw_loc_descr_ref tval = NULL;
20794 if (tloc != NULL_RTX)
20795 tval = mem_loc_descriptor (tloc,
20796 GET_MODE (tloc) == VOIDmode
20797 ? Pmode : GET_MODE (tloc),
20799 VAR_INIT_STATUS_INITIALIZED);
20801 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
20802 else if (tlocc != NULL_RTX)
20804 tval = mem_loc_descriptor (tlocc,
20805 GET_MODE (tlocc) == VOIDmode
20806 ? Pmode : GET_MODE (tlocc),
20808 VAR_INIT_STATUS_INITIALIZED);
20810 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
20816 call_site_note_count++;
20817 if (ca_loc->tail_call_p)
20818 tail_call_site_note_count++;
20822 call_arg_locations = NULL;
20823 call_arg_loc_last = NULL;
20824 if (tail_call_site_count >= 0
20825 && tail_call_site_count == tail_call_site_note_count
20828 if (call_site_count >= 0
20829 && call_site_count == call_site_note_count)
20830 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
20832 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
20834 call_site_count = -1;
20835 tail_call_site_count = -1;
20837 /* Add the calling convention attribute if requested. */
20838 add_calling_convention_attribute (subr_die, decl);
20842 /* Returns a hash value for X (which really is a die_struct). */
20845 common_block_die_table_hash (const void *x)
20847 const_dw_die_ref d = (const_dw_die_ref) x;
20848 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
20851 /* Return nonzero if decl_id and die_parent of die_struct X is the same
20852 as decl_id and die_parent of die_struct Y. */
20855 common_block_die_table_eq (const void *x, const void *y)
20857 const_dw_die_ref d = (const_dw_die_ref) x;
20858 const_dw_die_ref e = (const_dw_die_ref) y;
20859 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
20862 /* Generate a DIE to represent a declared data object.
20863 Either DECL or ORIGIN must be non-null. */
20866 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
20870 tree decl_or_origin = decl ? decl : origin;
20871 tree ultimate_origin;
20872 dw_die_ref var_die;
20873 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
20874 dw_die_ref origin_die;
20875 bool declaration = (DECL_EXTERNAL (decl_or_origin)
20876 || class_or_namespace_scope_p (context_die));
20877 bool specialization_p = false;
20879 ultimate_origin = decl_ultimate_origin (decl_or_origin);
20880 if (decl || ultimate_origin)
20881 origin = ultimate_origin;
20882 com_decl = fortran_common (decl_or_origin, &off);
20884 /* Symbol in common gets emitted as a child of the common block, in the form
20885 of a data member. */
20888 dw_die_ref com_die;
20889 dw_loc_list_ref loc;
20890 die_node com_die_arg;
20892 var_die = lookup_decl_die (decl_or_origin);
20895 if (get_AT (var_die, DW_AT_location) == NULL)
20897 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
20902 /* Optimize the common case. */
20903 if (single_element_loc_list_p (loc)
20904 && loc->expr->dw_loc_opc == DW_OP_addr
20905 && loc->expr->dw_loc_next == NULL
20906 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
20908 loc->expr->dw_loc_oprnd1.v.val_addr
20909 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
20911 loc_list_plus_const (loc, off);
20913 add_AT_location_description (var_die, DW_AT_location, loc);
20914 remove_AT (var_die, DW_AT_declaration);
20920 if (common_block_die_table == NULL)
20921 common_block_die_table
20922 = htab_create_ggc (10, common_block_die_table_hash,
20923 common_block_die_table_eq, NULL);
20925 com_die_arg.decl_id = DECL_UID (com_decl);
20926 com_die_arg.die_parent = context_die;
20927 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
20928 loc = loc_list_from_tree (com_decl, 2);
20929 if (com_die == NULL)
20932 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
20935 com_die = new_die (DW_TAG_common_block, context_die, decl);
20936 add_name_and_src_coords_attributes (com_die, com_decl);
20939 add_AT_location_description (com_die, DW_AT_location, loc);
20940 /* Avoid sharing the same loc descriptor between
20941 DW_TAG_common_block and DW_TAG_variable. */
20942 loc = loc_list_from_tree (com_decl, 2);
20944 else if (DECL_EXTERNAL (decl))
20945 add_AT_flag (com_die, DW_AT_declaration, 1);
20946 add_pubname_string (cnam, com_die); /* ??? needed? */
20947 com_die->decl_id = DECL_UID (com_decl);
20948 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
20949 *slot = (void *) com_die;
20951 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
20953 add_AT_location_description (com_die, DW_AT_location, loc);
20954 loc = loc_list_from_tree (com_decl, 2);
20955 remove_AT (com_die, DW_AT_declaration);
20957 var_die = new_die (DW_TAG_variable, com_die, decl);
20958 add_name_and_src_coords_attributes (var_die, decl);
20959 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
20960 TREE_THIS_VOLATILE (decl), context_die);
20961 add_AT_flag (var_die, DW_AT_external, 1);
20966 /* Optimize the common case. */
20967 if (single_element_loc_list_p (loc)
20968 && loc->expr->dw_loc_opc == DW_OP_addr
20969 && loc->expr->dw_loc_next == NULL
20970 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
20971 loc->expr->dw_loc_oprnd1.v.val_addr
20972 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
20974 loc_list_plus_const (loc, off);
20976 add_AT_location_description (var_die, DW_AT_location, loc);
20978 else if (DECL_EXTERNAL (decl))
20979 add_AT_flag (var_die, DW_AT_declaration, 1);
20980 equate_decl_number_to_die (decl, var_die);
20984 /* If the compiler emitted a definition for the DECL declaration
20985 and if we already emitted a DIE for it, don't emit a second
20986 DIE for it again. Allow re-declarations of DECLs that are
20987 inside functions, though. */
20988 if (old_die && declaration && !local_scope_p (context_die))
20991 /* For static data members, the declaration in the class is supposed
20992 to have DW_TAG_member tag; the specification should still be
20993 DW_TAG_variable referencing the DW_TAG_member DIE. */
20994 if (declaration && class_scope_p (context_die))
20995 var_die = new_die (DW_TAG_member, context_die, decl);
20997 var_die = new_die (DW_TAG_variable, context_die, decl);
21000 if (origin != NULL)
21001 origin_die = add_abstract_origin_attribute (var_die, origin);
21003 /* Loop unrolling can create multiple blocks that refer to the same
21004 static variable, so we must test for the DW_AT_declaration flag.
21006 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
21007 copy decls and set the DECL_ABSTRACT flag on them instead of
21010 ??? Duplicated blocks have been rewritten to use .debug_ranges.
21012 ??? The declare_in_namespace support causes us to get two DIEs for one
21013 variable, both of which are declarations. We want to avoid considering
21014 one to be a specification, so we must test that this DIE is not a
21016 else if (old_die && TREE_STATIC (decl) && ! declaration
21017 && get_AT_flag (old_die, DW_AT_declaration) == 1)
21019 /* This is a definition of a C++ class level static. */
21020 add_AT_specification (var_die, old_die);
21021 specialization_p = true;
21022 if (DECL_NAME (decl))
21024 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
21025 struct dwarf_file_data * file_index = lookup_filename (s.file);
21027 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
21028 add_AT_file (var_die, DW_AT_decl_file, file_index);
21030 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
21031 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
21033 if (old_die->die_tag == DW_TAG_member)
21034 add_linkage_name (var_die, decl);
21038 add_name_and_src_coords_attributes (var_die, decl);
21040 if ((origin == NULL && !specialization_p)
21042 && !DECL_ABSTRACT (decl_or_origin)
21043 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
21044 decl_function_context
21045 (decl_or_origin))))
21047 tree type = TREE_TYPE (decl_or_origin);
21049 if (decl_by_reference_p (decl_or_origin))
21050 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
21052 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
21053 TREE_THIS_VOLATILE (decl_or_origin), context_die);
21056 if (origin == NULL && !specialization_p)
21058 if (TREE_PUBLIC (decl))
21059 add_AT_flag (var_die, DW_AT_external, 1);
21061 if (DECL_ARTIFICIAL (decl))
21062 add_AT_flag (var_die, DW_AT_artificial, 1);
21064 add_accessibility_attribute (var_die, decl);
21068 add_AT_flag (var_die, DW_AT_declaration, 1);
21070 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
21071 equate_decl_number_to_die (decl, var_die);
21074 && (! DECL_ABSTRACT (decl_or_origin)
21075 /* Local static vars are shared between all clones/inlines,
21076 so emit DW_AT_location on the abstract DIE if DECL_RTL is
21078 || (TREE_CODE (decl_or_origin) == VAR_DECL
21079 && TREE_STATIC (decl_or_origin)
21080 && DECL_RTL_SET_P (decl_or_origin)))
21081 /* When abstract origin already has DW_AT_location attribute, no need
21082 to add it again. */
21083 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
21085 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
21086 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
21087 defer_location (decl_or_origin, var_die);
21089 add_location_or_const_value_attribute (var_die, decl_or_origin,
21090 decl == NULL, DW_AT_location);
21091 add_pubname (decl_or_origin, var_die);
21094 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
21097 /* Generate a DIE to represent a named constant. */
21100 gen_const_die (tree decl, dw_die_ref context_die)
21102 dw_die_ref const_die;
21103 tree type = TREE_TYPE (decl);
21105 const_die = new_die (DW_TAG_constant, context_die, decl);
21106 add_name_and_src_coords_attributes (const_die, decl);
21107 add_type_attribute (const_die, type, 1, 0, context_die);
21108 if (TREE_PUBLIC (decl))
21109 add_AT_flag (const_die, DW_AT_external, 1);
21110 if (DECL_ARTIFICIAL (decl))
21111 add_AT_flag (const_die, DW_AT_artificial, 1);
21112 tree_add_const_value_attribute_for_decl (const_die, decl);
21115 /* Generate a DIE to represent a label identifier. */
21118 gen_label_die (tree decl, dw_die_ref context_die)
21120 tree origin = decl_ultimate_origin (decl);
21121 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
21123 char label[MAX_ARTIFICIAL_LABEL_BYTES];
21125 if (origin != NULL)
21126 add_abstract_origin_attribute (lbl_die, origin);
21128 add_name_and_src_coords_attributes (lbl_die, decl);
21130 if (DECL_ABSTRACT (decl))
21131 equate_decl_number_to_die (decl, lbl_die);
21134 insn = DECL_RTL_IF_SET (decl);
21136 /* Deleted labels are programmer specified labels which have been
21137 eliminated because of various optimizations. We still emit them
21138 here so that it is possible to put breakpoints on them. */
21142 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
21144 /* When optimization is enabled (via -O) some parts of the compiler
21145 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
21146 represent source-level labels which were explicitly declared by
21147 the user. This really shouldn't be happening though, so catch
21148 it if it ever does happen. */
21149 gcc_assert (!INSN_DELETED_P (insn));
21151 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
21152 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
21157 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
21158 attributes to the DIE for a block STMT, to describe where the inlined
21159 function was called from. This is similar to add_src_coords_attributes. */
21162 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
21164 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
21166 if (dwarf_version >= 3 || !dwarf_strict)
21168 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
21169 add_AT_unsigned (die, DW_AT_call_line, s.line);
21174 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
21175 Add low_pc and high_pc attributes to the DIE for a block STMT. */
21178 add_high_low_attributes (tree stmt, dw_die_ref die)
21180 char label[MAX_ARTIFICIAL_LABEL_BYTES];
21182 if (BLOCK_FRAGMENT_CHAIN (stmt)
21183 && (dwarf_version >= 3 || !dwarf_strict))
21187 if (inlined_function_outer_scope_p (stmt))
21189 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
21190 BLOCK_NUMBER (stmt));
21191 add_AT_lbl_id (die, DW_AT_entry_pc, label);
21194 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
21196 chain = BLOCK_FRAGMENT_CHAIN (stmt);
21199 add_ranges (chain);
21200 chain = BLOCK_FRAGMENT_CHAIN (chain);
21207 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
21208 BLOCK_NUMBER (stmt));
21209 add_AT_lbl_id (die, DW_AT_low_pc, label);
21210 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
21211 BLOCK_NUMBER (stmt));
21212 add_AT_lbl_id (die, DW_AT_high_pc, label);
21216 /* Generate a DIE for a lexical block. */
21219 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
21221 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
21223 if (call_arg_locations)
21225 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
21226 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
21227 BLOCK_NUMBER (stmt) + 1);
21228 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
21231 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
21232 add_high_low_attributes (stmt, stmt_die);
21234 decls_for_scope (stmt, stmt_die, depth);
21237 /* Generate a DIE for an inlined subprogram. */
21240 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
21244 /* The instance of function that is effectively being inlined shall not
21246 gcc_assert (! BLOCK_ABSTRACT (stmt));
21248 decl = block_ultimate_origin (stmt);
21250 /* Emit info for the abstract instance first, if we haven't yet. We
21251 must emit this even if the block is abstract, otherwise when we
21252 emit the block below (or elsewhere), we may end up trying to emit
21253 a die whose origin die hasn't been emitted, and crashing. */
21254 dwarf2out_abstract_function (decl);
21256 if (! BLOCK_ABSTRACT (stmt))
21258 dw_die_ref subr_die
21259 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
21261 if (call_arg_locations)
21263 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
21264 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
21265 BLOCK_NUMBER (stmt) + 1);
21266 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
21268 add_abstract_origin_attribute (subr_die, decl);
21269 if (TREE_ASM_WRITTEN (stmt))
21270 add_high_low_attributes (stmt, subr_die);
21271 add_call_src_coords_attributes (stmt, subr_die);
21273 decls_for_scope (stmt, subr_die, depth);
21274 current_function_has_inlines = 1;
21278 /* Generate a DIE for a field in a record, or structure. */
21281 gen_field_die (tree decl, dw_die_ref context_die)
21283 dw_die_ref decl_die;
21285 if (TREE_TYPE (decl) == error_mark_node)
21288 decl_die = new_die (DW_TAG_member, context_die, decl);
21289 add_name_and_src_coords_attributes (decl_die, decl);
21290 add_type_attribute (decl_die, member_declared_type (decl),
21291 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
21294 if (DECL_BIT_FIELD_TYPE (decl))
21296 add_byte_size_attribute (decl_die, decl);
21297 add_bit_size_attribute (decl_die, decl);
21298 add_bit_offset_attribute (decl_die, decl);
21301 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
21302 add_data_member_location_attribute (decl_die, decl);
21304 if (DECL_ARTIFICIAL (decl))
21305 add_AT_flag (decl_die, DW_AT_artificial, 1);
21307 add_accessibility_attribute (decl_die, decl);
21309 /* Equate decl number to die, so that we can look up this decl later on. */
21310 equate_decl_number_to_die (decl, decl_die);
21314 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21315 Use modified_type_die instead.
21316 We keep this code here just in case these types of DIEs may be needed to
21317 represent certain things in other languages (e.g. Pascal) someday. */
21320 gen_pointer_type_die (tree type, dw_die_ref context_die)
21323 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
21325 equate_type_number_to_die (type, ptr_die);
21326 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
21327 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
21330 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21331 Use modified_type_die instead.
21332 We keep this code here just in case these types of DIEs may be needed to
21333 represent certain things in other languages (e.g. Pascal) someday. */
21336 gen_reference_type_die (tree type, dw_die_ref context_die)
21338 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
21340 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
21341 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
21343 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
21345 equate_type_number_to_die (type, ref_die);
21346 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
21347 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
21351 /* Generate a DIE for a pointer to a member type. */
21354 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
21357 = new_die (DW_TAG_ptr_to_member_type,
21358 scope_die_for (type, context_die), type);
21360 equate_type_number_to_die (type, ptr_die);
21361 add_AT_die_ref (ptr_die, DW_AT_containing_type,
21362 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
21363 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
21366 /* Generate the DIE for the compilation unit. */
21369 gen_compile_unit_die (const char *filename)
21372 char producer[250];
21373 const char *language_string = lang_hooks.name;
21376 die = new_die (DW_TAG_compile_unit, NULL, NULL);
21380 add_name_attribute (die, filename);
21381 /* Don't add cwd for <built-in>. */
21382 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
21383 add_comp_dir_attribute (die);
21386 sprintf (producer, "%s %s", language_string, version_string);
21388 #ifdef MIPS_DEBUGGING_INFO
21389 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
21390 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
21391 not appear in the producer string, the debugger reaches the conclusion
21392 that the object file is stripped and has no debugging information.
21393 To get the MIPS/SGI debugger to believe that there is debugging
21394 information in the object file, we add a -g to the producer string. */
21395 if (debug_info_level > DINFO_LEVEL_TERSE)
21396 strcat (producer, " -g");
21399 add_AT_string (die, DW_AT_producer, producer);
21401 /* If our producer is LTO try to figure out a common language to use
21402 from the global list of translation units. */
21403 if (strcmp (language_string, "GNU GIMPLE") == 0)
21407 const char *common_lang = NULL;
21409 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
21411 if (!TRANSLATION_UNIT_LANGUAGE (t))
21414 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
21415 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
21417 else if (strncmp (common_lang, "GNU C", 5) == 0
21418 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
21419 /* Mixing C and C++ is ok, use C++ in that case. */
21420 common_lang = "GNU C++";
21423 /* Fall back to C. */
21424 common_lang = NULL;
21430 language_string = common_lang;
21433 language = DW_LANG_C89;
21434 if (strcmp (language_string, "GNU C++") == 0)
21435 language = DW_LANG_C_plus_plus;
21436 else if (strcmp (language_string, "GNU F77") == 0)
21437 language = DW_LANG_Fortran77;
21438 else if (strcmp (language_string, "GNU Pascal") == 0)
21439 language = DW_LANG_Pascal83;
21440 else if (dwarf_version >= 3 || !dwarf_strict)
21442 if (strcmp (language_string, "GNU Ada") == 0)
21443 language = DW_LANG_Ada95;
21444 else if (strcmp (language_string, "GNU Fortran") == 0)
21445 language = DW_LANG_Fortran95;
21446 else if (strcmp (language_string, "GNU Java") == 0)
21447 language = DW_LANG_Java;
21448 else if (strcmp (language_string, "GNU Objective-C") == 0)
21449 language = DW_LANG_ObjC;
21450 else if (strcmp (language_string, "GNU Objective-C++") == 0)
21451 language = DW_LANG_ObjC_plus_plus;
21454 add_AT_unsigned (die, DW_AT_language, language);
21458 case DW_LANG_Fortran77:
21459 case DW_LANG_Fortran90:
21460 case DW_LANG_Fortran95:
21461 /* Fortran has case insensitive identifiers and the front-end
21462 lowercases everything. */
21463 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
21466 /* The default DW_ID_case_sensitive doesn't need to be specified. */
21472 /* Generate the DIE for a base class. */
21475 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
21477 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
21479 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
21480 add_data_member_location_attribute (die, binfo);
21482 if (BINFO_VIRTUAL_P (binfo))
21483 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
21485 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
21486 children, otherwise the default is DW_ACCESS_public. In DWARF2
21487 the default has always been DW_ACCESS_private. */
21488 if (access == access_public_node)
21490 if (dwarf_version == 2
21491 || context_die->die_tag == DW_TAG_class_type)
21492 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
21494 else if (access == access_protected_node)
21495 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
21496 else if (dwarf_version > 2
21497 && context_die->die_tag != DW_TAG_class_type)
21498 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
21501 /* Generate a DIE for a class member. */
21504 gen_member_die (tree type, dw_die_ref context_die)
21507 tree binfo = TYPE_BINFO (type);
21510 /* If this is not an incomplete type, output descriptions of each of its
21511 members. Note that as we output the DIEs necessary to represent the
21512 members of this record or union type, we will also be trying to output
21513 DIEs to represent the *types* of those members. However the `type'
21514 function (above) will specifically avoid generating type DIEs for member
21515 types *within* the list of member DIEs for this (containing) type except
21516 for those types (of members) which are explicitly marked as also being
21517 members of this (containing) type themselves. The g++ front- end can
21518 force any given type to be treated as a member of some other (containing)
21519 type by setting the TYPE_CONTEXT of the given (member) type to point to
21520 the TREE node representing the appropriate (containing) type. */
21522 /* First output info about the base classes. */
21525 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
21529 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
21530 gen_inheritance_die (base,
21531 (accesses ? VEC_index (tree, accesses, i)
21532 : access_public_node), context_die);
21535 /* Now output info about the data members and type members. */
21536 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
21538 /* If we thought we were generating minimal debug info for TYPE
21539 and then changed our minds, some of the member declarations
21540 may have already been defined. Don't define them again, but
21541 do put them in the right order. */
21543 child = lookup_decl_die (member);
21545 splice_child_die (context_die, child);
21547 gen_decl_die (member, NULL, context_die);
21550 /* Now output info about the function members (if any). */
21551 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
21553 /* Don't include clones in the member list. */
21554 if (DECL_ABSTRACT_ORIGIN (member))
21557 child = lookup_decl_die (member);
21559 splice_child_die (context_die, child);
21561 gen_decl_die (member, NULL, context_die);
21565 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
21566 is set, we pretend that the type was never defined, so we only get the
21567 member DIEs needed by later specification DIEs. */
21570 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
21571 enum debug_info_usage usage)
21573 dw_die_ref type_die = lookup_type_die (type);
21574 dw_die_ref scope_die = 0;
21576 int complete = (TYPE_SIZE (type)
21577 && (! TYPE_STUB_DECL (type)
21578 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
21579 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
21580 complete = complete && should_emit_struct_debug (type, usage);
21582 if (type_die && ! complete)
21585 if (TYPE_CONTEXT (type) != NULL_TREE
21586 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
21587 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
21590 scope_die = scope_die_for (type, context_die);
21592 if (! type_die || (nested && is_cu_die (scope_die)))
21593 /* First occurrence of type or toplevel definition of nested class. */
21595 dw_die_ref old_die = type_die;
21597 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
21598 ? record_type_tag (type) : DW_TAG_union_type,
21600 equate_type_number_to_die (type, type_die);
21602 add_AT_specification (type_die, old_die);
21605 add_name_attribute (type_die, type_tag (type));
21606 add_gnat_descriptive_type_attribute (type_die, type, context_die);
21610 remove_AT (type_die, DW_AT_declaration);
21612 /* Generate child dies for template paramaters. */
21613 if (debug_info_level > DINFO_LEVEL_TERSE
21614 && COMPLETE_TYPE_P (type))
21615 schedule_generic_params_dies_gen (type);
21617 /* If this type has been completed, then give it a byte_size attribute and
21618 then give a list of members. */
21619 if (complete && !ns_decl)
21621 /* Prevent infinite recursion in cases where the type of some member of
21622 this type is expressed in terms of this type itself. */
21623 TREE_ASM_WRITTEN (type) = 1;
21624 add_byte_size_attribute (type_die, type);
21625 if (TYPE_STUB_DECL (type) != NULL_TREE)
21627 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
21628 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
21631 /* If the first reference to this type was as the return type of an
21632 inline function, then it may not have a parent. Fix this now. */
21633 if (type_die->die_parent == NULL)
21634 add_child_die (scope_die, type_die);
21636 push_decl_scope (type);
21637 gen_member_die (type, type_die);
21640 /* GNU extension: Record what type our vtable lives in. */
21641 if (TYPE_VFIELD (type))
21643 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
21645 gen_type_die (vtype, context_die);
21646 add_AT_die_ref (type_die, DW_AT_containing_type,
21647 lookup_type_die (vtype));
21652 add_AT_flag (type_die, DW_AT_declaration, 1);
21654 /* We don't need to do this for function-local types. */
21655 if (TYPE_STUB_DECL (type)
21656 && ! decl_function_context (TYPE_STUB_DECL (type)))
21657 VEC_safe_push (tree, gc, incomplete_types, type);
21660 if (get_AT (type_die, DW_AT_name))
21661 add_pubtype (type, type_die);
21664 /* Generate a DIE for a subroutine _type_. */
21667 gen_subroutine_type_die (tree type, dw_die_ref context_die)
21669 tree return_type = TREE_TYPE (type);
21670 dw_die_ref subr_die
21671 = new_die (DW_TAG_subroutine_type,
21672 scope_die_for (type, context_die), type);
21674 equate_type_number_to_die (type, subr_die);
21675 add_prototyped_attribute (subr_die, type);
21676 add_type_attribute (subr_die, return_type, 0, 0, context_die);
21677 gen_formal_types_die (type, subr_die);
21679 if (get_AT (subr_die, DW_AT_name))
21680 add_pubtype (type, subr_die);
21683 /* Generate a DIE for a type definition. */
21686 gen_typedef_die (tree decl, dw_die_ref context_die)
21688 dw_die_ref type_die;
21691 if (TREE_ASM_WRITTEN (decl))
21694 TREE_ASM_WRITTEN (decl) = 1;
21695 type_die = new_die (DW_TAG_typedef, context_die, decl);
21696 origin = decl_ultimate_origin (decl);
21697 if (origin != NULL)
21698 add_abstract_origin_attribute (type_die, origin);
21703 add_name_and_src_coords_attributes (type_die, decl);
21704 if (DECL_ORIGINAL_TYPE (decl))
21706 type = DECL_ORIGINAL_TYPE (decl);
21708 gcc_assert (type != TREE_TYPE (decl));
21709 equate_type_number_to_die (TREE_TYPE (decl), type_die);
21713 type = TREE_TYPE (decl);
21715 if (is_naming_typedef_decl (TYPE_NAME (type)))
21717 /* Here, we are in the case of decl being a typedef naming
21718 an anonymous type, e.g:
21719 typedef struct {...} foo;
21720 In that case TREE_TYPE (decl) is not a typedef variant
21721 type and TYPE_NAME of the anonymous type is set to the
21722 TYPE_DECL of the typedef. This construct is emitted by
21725 TYPE is the anonymous struct named by the typedef
21726 DECL. As we need the DW_AT_type attribute of the
21727 DW_TAG_typedef to point to the DIE of TYPE, let's
21728 generate that DIE right away. add_type_attribute
21729 called below will then pick (via lookup_type_die) that
21730 anonymous struct DIE. */
21731 if (!TREE_ASM_WRITTEN (type))
21732 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
21734 /* This is a GNU Extension. We are adding a
21735 DW_AT_linkage_name attribute to the DIE of the
21736 anonymous struct TYPE. The value of that attribute
21737 is the name of the typedef decl naming the anonymous
21738 struct. This greatly eases the work of consumers of
21739 this debug info. */
21740 add_linkage_attr (lookup_type_die (type), decl);
21744 add_type_attribute (type_die, type, TREE_READONLY (decl),
21745 TREE_THIS_VOLATILE (decl), context_die);
21747 if (is_naming_typedef_decl (decl))
21748 /* We want that all subsequent calls to lookup_type_die with
21749 TYPE in argument yield the DW_TAG_typedef we have just
21751 equate_type_number_to_die (type, type_die);
21753 add_accessibility_attribute (type_die, decl);
21756 if (DECL_ABSTRACT (decl))
21757 equate_decl_number_to_die (decl, type_die);
21759 if (get_AT (type_die, DW_AT_name))
21760 add_pubtype (decl, type_die);
21763 /* Generate a DIE for a struct, class, enum or union type. */
21766 gen_tagged_type_die (tree type,
21767 dw_die_ref context_die,
21768 enum debug_info_usage usage)
21772 if (type == NULL_TREE
21773 || !is_tagged_type (type))
21776 /* If this is a nested type whose containing class hasn't been written
21777 out yet, writing it out will cover this one, too. This does not apply
21778 to instantiations of member class templates; they need to be added to
21779 the containing class as they are generated. FIXME: This hurts the
21780 idea of combining type decls from multiple TUs, since we can't predict
21781 what set of template instantiations we'll get. */
21782 if (TYPE_CONTEXT (type)
21783 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
21784 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
21786 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
21788 if (TREE_ASM_WRITTEN (type))
21791 /* If that failed, attach ourselves to the stub. */
21792 push_decl_scope (TYPE_CONTEXT (type));
21793 context_die = lookup_type_die (TYPE_CONTEXT (type));
21796 else if (TYPE_CONTEXT (type) != NULL_TREE
21797 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
21799 /* If this type is local to a function that hasn't been written
21800 out yet, use a NULL context for now; it will be fixed up in
21801 decls_for_scope. */
21802 context_die = lookup_decl_die (TYPE_CONTEXT (type));
21803 /* A declaration DIE doesn't count; nested types need to go in the
21805 if (context_die && is_declaration_die (context_die))
21806 context_die = NULL;
21811 context_die = declare_in_namespace (type, context_die);
21815 if (TREE_CODE (type) == ENUMERAL_TYPE)
21817 /* This might have been written out by the call to
21818 declare_in_namespace. */
21819 if (!TREE_ASM_WRITTEN (type))
21820 gen_enumeration_type_die (type, context_die);
21823 gen_struct_or_union_type_die (type, context_die, usage);
21828 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
21829 it up if it is ever completed. gen_*_type_die will set it for us
21830 when appropriate. */
21833 /* Generate a type description DIE. */
21836 gen_type_die_with_usage (tree type, dw_die_ref context_die,
21837 enum debug_info_usage usage)
21839 struct array_descr_info info;
21841 if (type == NULL_TREE || type == error_mark_node)
21844 if (TYPE_NAME (type) != NULL_TREE
21845 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
21846 && is_redundant_typedef (TYPE_NAME (type))
21847 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
21848 /* The DECL of this type is a typedef we don't want to emit debug
21849 info for but we want debug info for its underlying typedef.
21850 This can happen for e.g, the injected-class-name of a C++
21852 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
21854 /* If TYPE is a typedef type variant, let's generate debug info
21855 for the parent typedef which TYPE is a type of. */
21856 if (typedef_variant_p (type))
21858 if (TREE_ASM_WRITTEN (type))
21861 /* Prevent broken recursion; we can't hand off to the same type. */
21862 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
21864 /* Use the DIE of the containing namespace as the parent DIE of
21865 the type description DIE we want to generate. */
21866 if (DECL_CONTEXT (TYPE_NAME (type))
21867 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
21868 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
21870 TREE_ASM_WRITTEN (type) = 1;
21872 gen_decl_die (TYPE_NAME (type), NULL, context_die);
21876 /* If type is an anonymous tagged type named by a typedef, let's
21877 generate debug info for the typedef. */
21878 if (is_naming_typedef_decl (TYPE_NAME (type)))
21880 /* Use the DIE of the containing namespace as the parent DIE of
21881 the type description DIE we want to generate. */
21882 if (DECL_CONTEXT (TYPE_NAME (type))
21883 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
21884 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
21886 gen_decl_die (TYPE_NAME (type), NULL, context_die);
21890 /* If this is an array type with hidden descriptor, handle it first. */
21891 if (!TREE_ASM_WRITTEN (type)
21892 && lang_hooks.types.get_array_descr_info
21893 && lang_hooks.types.get_array_descr_info (type, &info)
21894 && (dwarf_version >= 3 || !dwarf_strict))
21896 gen_descr_array_type_die (type, &info, context_die);
21897 TREE_ASM_WRITTEN (type) = 1;
21901 /* We are going to output a DIE to represent the unqualified version
21902 of this type (i.e. without any const or volatile qualifiers) so
21903 get the main variant (i.e. the unqualified version) of this type
21904 now. (Vectors are special because the debugging info is in the
21905 cloned type itself). */
21906 if (TREE_CODE (type) != VECTOR_TYPE)
21907 type = type_main_variant (type);
21909 if (TREE_ASM_WRITTEN (type))
21912 switch (TREE_CODE (type))
21918 case REFERENCE_TYPE:
21919 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
21920 ensures that the gen_type_die recursion will terminate even if the
21921 type is recursive. Recursive types are possible in Ada. */
21922 /* ??? We could perhaps do this for all types before the switch
21924 TREE_ASM_WRITTEN (type) = 1;
21926 /* For these types, all that is required is that we output a DIE (or a
21927 set of DIEs) to represent the "basis" type. */
21928 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21929 DINFO_USAGE_IND_USE);
21933 /* This code is used for C++ pointer-to-data-member types.
21934 Output a description of the relevant class type. */
21935 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
21936 DINFO_USAGE_IND_USE);
21938 /* Output a description of the type of the object pointed to. */
21939 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21940 DINFO_USAGE_IND_USE);
21942 /* Now output a DIE to represent this pointer-to-data-member type
21944 gen_ptr_to_mbr_type_die (type, context_die);
21947 case FUNCTION_TYPE:
21948 /* Force out return type (in case it wasn't forced out already). */
21949 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21950 DINFO_USAGE_DIR_USE);
21951 gen_subroutine_type_die (type, context_die);
21955 /* Force out return type (in case it wasn't forced out already). */
21956 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21957 DINFO_USAGE_DIR_USE);
21958 gen_subroutine_type_die (type, context_die);
21962 gen_array_type_die (type, context_die);
21966 gen_array_type_die (type, context_die);
21969 case ENUMERAL_TYPE:
21972 case QUAL_UNION_TYPE:
21973 gen_tagged_type_die (type, context_die, usage);
21979 case FIXED_POINT_TYPE:
21982 /* No DIEs needed for fundamental types. */
21987 /* Just use DW_TAG_unspecified_type. */
21989 dw_die_ref type_die = lookup_type_die (type);
21990 if (type_die == NULL)
21992 tree name = TYPE_NAME (type);
21993 if (TREE_CODE (name) == TYPE_DECL)
21994 name = DECL_NAME (name);
21995 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
21996 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
21997 equate_type_number_to_die (type, type_die);
22003 gcc_unreachable ();
22006 TREE_ASM_WRITTEN (type) = 1;
22010 gen_type_die (tree type, dw_die_ref context_die)
22012 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
22015 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
22016 things which are local to the given block. */
22019 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
22021 int must_output_die = 0;
22024 /* Ignore blocks that are NULL. */
22025 if (stmt == NULL_TREE)
22028 inlined_func = inlined_function_outer_scope_p (stmt);
22030 /* If the block is one fragment of a non-contiguous block, do not
22031 process the variables, since they will have been done by the
22032 origin block. Do process subblocks. */
22033 if (BLOCK_FRAGMENT_ORIGIN (stmt))
22037 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
22038 gen_block_die (sub, context_die, depth + 1);
22043 /* Determine if we need to output any Dwarf DIEs at all to represent this
22046 /* The outer scopes for inlinings *must* always be represented. We
22047 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
22048 must_output_die = 1;
22051 /* Determine if this block directly contains any "significant"
22052 local declarations which we will need to output DIEs for. */
22053 if (debug_info_level > DINFO_LEVEL_TERSE)
22054 /* We are not in terse mode so *any* local declaration counts
22055 as being a "significant" one. */
22056 must_output_die = ((BLOCK_VARS (stmt) != NULL
22057 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
22058 && (TREE_USED (stmt)
22059 || TREE_ASM_WRITTEN (stmt)
22060 || BLOCK_ABSTRACT (stmt)));
22061 else if ((TREE_USED (stmt)
22062 || TREE_ASM_WRITTEN (stmt)
22063 || BLOCK_ABSTRACT (stmt))
22064 && !dwarf2out_ignore_block (stmt))
22065 must_output_die = 1;
22068 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
22069 DIE for any block which contains no significant local declarations at
22070 all. Rather, in such cases we just call `decls_for_scope' so that any
22071 needed Dwarf info for any sub-blocks will get properly generated. Note
22072 that in terse mode, our definition of what constitutes a "significant"
22073 local declaration gets restricted to include only inlined function
22074 instances and local (nested) function definitions. */
22075 if (must_output_die)
22079 /* If STMT block is abstract, that means we have been called
22080 indirectly from dwarf2out_abstract_function.
22081 That function rightfully marks the descendent blocks (of
22082 the abstract function it is dealing with) as being abstract,
22083 precisely to prevent us from emitting any
22084 DW_TAG_inlined_subroutine DIE as a descendent
22085 of an abstract function instance. So in that case, we should
22086 not call gen_inlined_subroutine_die.
22088 Later though, when cgraph asks dwarf2out to emit info
22089 for the concrete instance of the function decl into which
22090 the concrete instance of STMT got inlined, the later will lead
22091 to the generation of a DW_TAG_inlined_subroutine DIE. */
22092 if (! BLOCK_ABSTRACT (stmt))
22093 gen_inlined_subroutine_die (stmt, context_die, depth);
22096 gen_lexical_block_die (stmt, context_die, depth);
22099 decls_for_scope (stmt, context_die, depth);
22102 /* Process variable DECL (or variable with origin ORIGIN) within
22103 block STMT and add it to CONTEXT_DIE. */
22105 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
22108 tree decl_or_origin = decl ? decl : origin;
22110 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
22111 die = lookup_decl_die (decl_or_origin);
22112 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
22113 && TYPE_DECL_IS_STUB (decl_or_origin))
22114 die = lookup_type_die (TREE_TYPE (decl_or_origin));
22118 if (die != NULL && die->die_parent == NULL)
22119 add_child_die (context_die, die);
22120 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
22121 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
22122 stmt, context_die);
22124 gen_decl_die (decl, origin, context_die);
22127 /* Generate all of the decls declared within a given scope and (recursively)
22128 all of its sub-blocks. */
22131 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
22137 /* Ignore NULL blocks. */
22138 if (stmt == NULL_TREE)
22141 /* Output the DIEs to represent all of the data objects and typedefs
22142 declared directly within this block but not within any nested
22143 sub-blocks. Also, nested function and tag DIEs have been
22144 generated with a parent of NULL; fix that up now. */
22145 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
22146 process_scope_var (stmt, decl, NULL_TREE, context_die);
22147 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
22148 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
22151 /* If we're at -g1, we're not interested in subblocks. */
22152 if (debug_info_level <= DINFO_LEVEL_TERSE)
22155 /* Output the DIEs to represent all sub-blocks (and the items declared
22156 therein) of this block. */
22157 for (subblocks = BLOCK_SUBBLOCKS (stmt);
22159 subblocks = BLOCK_CHAIN (subblocks))
22160 gen_block_die (subblocks, context_die, depth + 1);
22163 /* Is this a typedef we can avoid emitting? */
22166 is_redundant_typedef (const_tree decl)
22168 if (TYPE_DECL_IS_STUB (decl))
22171 if (DECL_ARTIFICIAL (decl)
22172 && DECL_CONTEXT (decl)
22173 && is_tagged_type (DECL_CONTEXT (decl))
22174 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
22175 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
22176 /* Also ignore the artificial member typedef for the class name. */
22182 /* Return TRUE if TYPE is a typedef that names a type for linkage
22183 purposes. This kind of typedefs is produced by the C++ FE for
22186 typedef struct {...} foo;
22188 In that case, there is no typedef variant type produced for foo.
22189 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
22193 is_naming_typedef_decl (const_tree decl)
22195 if (decl == NULL_TREE
22196 || TREE_CODE (decl) != TYPE_DECL
22197 || !is_tagged_type (TREE_TYPE (decl))
22198 || DECL_IS_BUILTIN (decl)
22199 || is_redundant_typedef (decl)
22200 /* It looks like Ada produces TYPE_DECLs that are very similar
22201 to C++ naming typedefs but that have different
22202 semantics. Let's be specific to c++ for now. */
22206 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
22207 && TYPE_NAME (TREE_TYPE (decl)) == decl
22208 && (TYPE_STUB_DECL (TREE_TYPE (decl))
22209 != TYPE_NAME (TREE_TYPE (decl))));
22212 /* Returns the DIE for a context. */
22214 static inline dw_die_ref
22215 get_context_die (tree context)
22219 /* Find die that represents this context. */
22220 if (TYPE_P (context))
22222 context = TYPE_MAIN_VARIANT (context);
22223 return strip_naming_typedef (context, force_type_die (context));
22226 return force_decl_die (context);
22228 return comp_unit_die ();
22231 /* Returns the DIE for decl. A DIE will always be returned. */
22234 force_decl_die (tree decl)
22236 dw_die_ref decl_die;
22237 unsigned saved_external_flag;
22238 tree save_fn = NULL_TREE;
22239 decl_die = lookup_decl_die (decl);
22242 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
22244 decl_die = lookup_decl_die (decl);
22248 switch (TREE_CODE (decl))
22250 case FUNCTION_DECL:
22251 /* Clear current_function_decl, so that gen_subprogram_die thinks
22252 that this is a declaration. At this point, we just want to force
22253 declaration die. */
22254 save_fn = current_function_decl;
22255 current_function_decl = NULL_TREE;
22256 gen_subprogram_die (decl, context_die);
22257 current_function_decl = save_fn;
22261 /* Set external flag to force declaration die. Restore it after
22262 gen_decl_die() call. */
22263 saved_external_flag = DECL_EXTERNAL (decl);
22264 DECL_EXTERNAL (decl) = 1;
22265 gen_decl_die (decl, NULL, context_die);
22266 DECL_EXTERNAL (decl) = saved_external_flag;
22269 case NAMESPACE_DECL:
22270 if (dwarf_version >= 3 || !dwarf_strict)
22271 dwarf2out_decl (decl);
22273 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
22274 decl_die = comp_unit_die ();
22277 case TRANSLATION_UNIT_DECL:
22278 decl_die = comp_unit_die ();
22282 gcc_unreachable ();
22285 /* We should be able to find the DIE now. */
22287 decl_die = lookup_decl_die (decl);
22288 gcc_assert (decl_die);
22294 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
22295 always returned. */
22298 force_type_die (tree type)
22300 dw_die_ref type_die;
22302 type_die = lookup_type_die (type);
22305 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
22307 type_die = modified_type_die (type, TYPE_READONLY (type),
22308 TYPE_VOLATILE (type), context_die);
22309 gcc_assert (type_die);
22314 /* Force out any required namespaces to be able to output DECL,
22315 and return the new context_die for it, if it's changed. */
22318 setup_namespace_context (tree thing, dw_die_ref context_die)
22320 tree context = (DECL_P (thing)
22321 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
22322 if (context && TREE_CODE (context) == NAMESPACE_DECL)
22323 /* Force out the namespace. */
22324 context_die = force_decl_die (context);
22326 return context_die;
22329 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
22330 type) within its namespace, if appropriate.
22332 For compatibility with older debuggers, namespace DIEs only contain
22333 declarations; all definitions are emitted at CU scope. */
22336 declare_in_namespace (tree thing, dw_die_ref context_die)
22338 dw_die_ref ns_context;
22340 if (debug_info_level <= DINFO_LEVEL_TERSE)
22341 return context_die;
22343 /* If this decl is from an inlined function, then don't try to emit it in its
22344 namespace, as we will get confused. It would have already been emitted
22345 when the abstract instance of the inline function was emitted anyways. */
22346 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
22347 return context_die;
22349 ns_context = setup_namespace_context (thing, context_die);
22351 if (ns_context != context_die)
22355 if (DECL_P (thing))
22356 gen_decl_die (thing, NULL, ns_context);
22358 gen_type_die (thing, ns_context);
22360 return context_die;
22363 /* Generate a DIE for a namespace or namespace alias. */
22366 gen_namespace_die (tree decl, dw_die_ref context_die)
22368 dw_die_ref namespace_die;
22370 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
22371 they are an alias of. */
22372 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
22374 /* Output a real namespace or module. */
22375 context_die = setup_namespace_context (decl, comp_unit_die ());
22376 namespace_die = new_die (is_fortran ()
22377 ? DW_TAG_module : DW_TAG_namespace,
22378 context_die, decl);
22379 /* For Fortran modules defined in different CU don't add src coords. */
22380 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
22382 const char *name = dwarf2_name (decl, 0);
22384 add_name_attribute (namespace_die, name);
22387 add_name_and_src_coords_attributes (namespace_die, decl);
22388 if (DECL_EXTERNAL (decl))
22389 add_AT_flag (namespace_die, DW_AT_declaration, 1);
22390 equate_decl_number_to_die (decl, namespace_die);
22394 /* Output a namespace alias. */
22396 /* Force out the namespace we are an alias of, if necessary. */
22397 dw_die_ref origin_die
22398 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
22400 if (DECL_FILE_SCOPE_P (decl)
22401 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
22402 context_die = setup_namespace_context (decl, comp_unit_die ());
22403 /* Now create the namespace alias DIE. */
22404 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
22405 add_name_and_src_coords_attributes (namespace_die, decl);
22406 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
22407 equate_decl_number_to_die (decl, namespace_die);
22411 /* Generate Dwarf debug information for a decl described by DECL.
22412 The return value is currently only meaningful for PARM_DECLs,
22413 for all other decls it returns NULL. */
22416 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
22418 tree decl_or_origin = decl ? decl : origin;
22419 tree class_origin = NULL, ultimate_origin;
22421 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
22424 switch (TREE_CODE (decl_or_origin))
22430 if (!is_fortran () && !is_ada ())
22432 /* The individual enumerators of an enum type get output when we output
22433 the Dwarf representation of the relevant enum type itself. */
22437 /* Emit its type. */
22438 gen_type_die (TREE_TYPE (decl), context_die);
22440 /* And its containing namespace. */
22441 context_die = declare_in_namespace (decl, context_die);
22443 gen_const_die (decl, context_die);
22446 case FUNCTION_DECL:
22447 /* Don't output any DIEs to represent mere function declarations,
22448 unless they are class members or explicit block externs. */
22449 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
22450 && DECL_FILE_SCOPE_P (decl_or_origin)
22451 && (current_function_decl == NULL_TREE
22452 || DECL_ARTIFICIAL (decl_or_origin)))
22457 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
22458 on local redeclarations of global functions. That seems broken. */
22459 if (current_function_decl != decl)
22460 /* This is only a declaration. */;
22463 /* If we're emitting a clone, emit info for the abstract instance. */
22464 if (origin || DECL_ORIGIN (decl) != decl)
22465 dwarf2out_abstract_function (origin
22466 ? DECL_ORIGIN (origin)
22467 : DECL_ABSTRACT_ORIGIN (decl));
22469 /* If we're emitting an out-of-line copy of an inline function,
22470 emit info for the abstract instance and set up to refer to it. */
22471 else if (cgraph_function_possibly_inlined_p (decl)
22472 && ! DECL_ABSTRACT (decl)
22473 && ! class_or_namespace_scope_p (context_die)
22474 /* dwarf2out_abstract_function won't emit a die if this is just
22475 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
22476 that case, because that works only if we have a die. */
22477 && DECL_INITIAL (decl) != NULL_TREE)
22479 dwarf2out_abstract_function (decl);
22480 set_decl_origin_self (decl);
22483 /* Otherwise we're emitting the primary DIE for this decl. */
22484 else if (debug_info_level > DINFO_LEVEL_TERSE)
22486 /* Before we describe the FUNCTION_DECL itself, make sure that we
22487 have its containing type. */
22489 origin = decl_class_context (decl);
22490 if (origin != NULL_TREE)
22491 gen_type_die (origin, context_die);
22493 /* And its return type. */
22494 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
22496 /* And its virtual context. */
22497 if (DECL_VINDEX (decl) != NULL_TREE)
22498 gen_type_die (DECL_CONTEXT (decl), context_die);
22500 /* Make sure we have a member DIE for decl. */
22501 if (origin != NULL_TREE)
22502 gen_type_die_for_member (origin, decl, context_die);
22504 /* And its containing namespace. */
22505 context_die = declare_in_namespace (decl, context_die);
22508 /* Now output a DIE to represent the function itself. */
22510 gen_subprogram_die (decl, context_die);
22514 /* If we are in terse mode, don't generate any DIEs to represent any
22515 actual typedefs. */
22516 if (debug_info_level <= DINFO_LEVEL_TERSE)
22519 /* In the special case of a TYPE_DECL node representing the declaration
22520 of some type tag, if the given TYPE_DECL is marked as having been
22521 instantiated from some other (original) TYPE_DECL node (e.g. one which
22522 was generated within the original definition of an inline function) we
22523 used to generate a special (abbreviated) DW_TAG_structure_type,
22524 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
22525 should be actually referencing those DIEs, as variable DIEs with that
22526 type would be emitted already in the abstract origin, so it was always
22527 removed during unused type prunning. Don't add anything in this
22529 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
22532 if (is_redundant_typedef (decl))
22533 gen_type_die (TREE_TYPE (decl), context_die);
22535 /* Output a DIE to represent the typedef itself. */
22536 gen_typedef_die (decl, context_die);
22540 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22541 gen_label_die (decl, context_die);
22546 /* If we are in terse mode, don't generate any DIEs to represent any
22547 variable declarations or definitions. */
22548 if (debug_info_level <= DINFO_LEVEL_TERSE)
22551 /* Output any DIEs that are needed to specify the type of this data
22553 if (decl_by_reference_p (decl_or_origin))
22554 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
22556 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
22558 /* And its containing type. */
22559 class_origin = decl_class_context (decl_or_origin);
22560 if (class_origin != NULL_TREE)
22561 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
22563 /* And its containing namespace. */
22564 context_die = declare_in_namespace (decl_or_origin, context_die);
22566 /* Now output the DIE to represent the data object itself. This gets
22567 complicated because of the possibility that the VAR_DECL really
22568 represents an inlined instance of a formal parameter for an inline
22570 ultimate_origin = decl_ultimate_origin (decl_or_origin);
22571 if (ultimate_origin != NULL_TREE
22572 && TREE_CODE (ultimate_origin) == PARM_DECL)
22573 gen_formal_parameter_die (decl, origin,
22574 true /* Emit name attribute. */,
22577 gen_variable_die (decl, origin, context_die);
22581 /* Ignore the nameless fields that are used to skip bits but handle C++
22582 anonymous unions and structs. */
22583 if (DECL_NAME (decl) != NULL_TREE
22584 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
22585 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
22587 gen_type_die (member_declared_type (decl), context_die);
22588 gen_field_die (decl, context_die);
22593 if (DECL_BY_REFERENCE (decl_or_origin))
22594 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
22596 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
22597 return gen_formal_parameter_die (decl, origin,
22598 true /* Emit name attribute. */,
22601 case NAMESPACE_DECL:
22602 case IMPORTED_DECL:
22603 if (dwarf_version >= 3 || !dwarf_strict)
22604 gen_namespace_die (decl, context_die);
22608 /* Probably some frontend-internal decl. Assume we don't care. */
22609 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
22616 /* Output debug information for global decl DECL. Called from toplev.c after
22617 compilation proper has finished. */
22620 dwarf2out_global_decl (tree decl)
22622 /* Output DWARF2 information for file-scope tentative data object
22623 declarations, file-scope (extern) function declarations (which
22624 had no corresponding body) and file-scope tagged type declarations
22625 and definitions which have not yet been forced out. */
22626 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
22627 dwarf2out_decl (decl);
22630 /* Output debug information for type decl DECL. Called from toplev.c
22631 and from language front ends (to record built-in types). */
22633 dwarf2out_type_decl (tree decl, int local)
22636 dwarf2out_decl (decl);
22639 /* Output debug information for imported module or decl DECL.
22640 NAME is non-NULL name in the lexical block if the decl has been renamed.
22641 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
22642 that DECL belongs to.
22643 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
22645 dwarf2out_imported_module_or_decl_1 (tree decl,
22647 tree lexical_block,
22648 dw_die_ref lexical_block_die)
22650 expanded_location xloc;
22651 dw_die_ref imported_die = NULL;
22652 dw_die_ref at_import_die;
22654 if (TREE_CODE (decl) == IMPORTED_DECL)
22656 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
22657 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
22661 xloc = expand_location (input_location);
22663 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
22665 at_import_die = force_type_die (TREE_TYPE (decl));
22666 /* For namespace N { typedef void T; } using N::T; base_type_die
22667 returns NULL, but DW_TAG_imported_declaration requires
22668 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
22669 if (!at_import_die)
22671 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
22672 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
22673 at_import_die = lookup_type_die (TREE_TYPE (decl));
22674 gcc_assert (at_import_die);
22679 at_import_die = lookup_decl_die (decl);
22680 if (!at_import_die)
22682 /* If we're trying to avoid duplicate debug info, we may not have
22683 emitted the member decl for this field. Emit it now. */
22684 if (TREE_CODE (decl) == FIELD_DECL)
22686 tree type = DECL_CONTEXT (decl);
22688 if (TYPE_CONTEXT (type)
22689 && TYPE_P (TYPE_CONTEXT (type))
22690 && !should_emit_struct_debug (TYPE_CONTEXT (type),
22691 DINFO_USAGE_DIR_USE))
22693 gen_type_die_for_member (type, decl,
22694 get_context_die (TYPE_CONTEXT (type)));
22696 at_import_die = force_decl_die (decl);
22700 if (TREE_CODE (decl) == NAMESPACE_DECL)
22702 if (dwarf_version >= 3 || !dwarf_strict)
22703 imported_die = new_die (DW_TAG_imported_module,
22710 imported_die = new_die (DW_TAG_imported_declaration,
22714 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
22715 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
22717 add_AT_string (imported_die, DW_AT_name,
22718 IDENTIFIER_POINTER (name));
22719 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
22722 /* Output debug information for imported module or decl DECL.
22723 NAME is non-NULL name in context if the decl has been renamed.
22724 CHILD is true if decl is one of the renamed decls as part of
22725 importing whole module. */
22728 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
22731 /* dw_die_ref at_import_die; */
22732 dw_die_ref scope_die;
22734 if (debug_info_level <= DINFO_LEVEL_TERSE)
22739 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
22740 We need decl DIE for reference and scope die. First, get DIE for the decl
22743 /* Get the scope die for decl context. Use comp_unit_die for global module
22744 or decl. If die is not found for non globals, force new die. */
22746 && TYPE_P (context)
22747 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
22750 if (!(dwarf_version >= 3 || !dwarf_strict))
22753 scope_die = get_context_die (context);
22757 gcc_assert (scope_die->die_child);
22758 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
22759 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
22760 scope_die = scope_die->die_child;
22763 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
22764 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
22768 /* Write the debugging output for DECL. */
22771 dwarf2out_decl (tree decl)
22773 dw_die_ref context_die = comp_unit_die ();
22775 switch (TREE_CODE (decl))
22780 case FUNCTION_DECL:
22781 /* What we would really like to do here is to filter out all mere
22782 file-scope declarations of file-scope functions which are never
22783 referenced later within this translation unit (and keep all of ones
22784 that *are* referenced later on) but we aren't clairvoyant, so we have
22785 no idea which functions will be referenced in the future (i.e. later
22786 on within the current translation unit). So here we just ignore all
22787 file-scope function declarations which are not also definitions. If
22788 and when the debugger needs to know something about these functions,
22789 it will have to hunt around and find the DWARF information associated
22790 with the definition of the function.
22792 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
22793 nodes represent definitions and which ones represent mere
22794 declarations. We have to check DECL_INITIAL instead. That's because
22795 the C front-end supports some weird semantics for "extern inline"
22796 function definitions. These can get inlined within the current
22797 translation unit (and thus, we need to generate Dwarf info for their
22798 abstract instances so that the Dwarf info for the concrete inlined
22799 instances can have something to refer to) but the compiler never
22800 generates any out-of-lines instances of such things (despite the fact
22801 that they *are* definitions).
22803 The important point is that the C front-end marks these "extern
22804 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
22805 them anyway. Note that the C++ front-end also plays some similar games
22806 for inline function definitions appearing within include files which
22807 also contain `#pragma interface' pragmas. */
22808 if (DECL_INITIAL (decl) == NULL_TREE)
22811 /* If we're a nested function, initially use a parent of NULL; if we're
22812 a plain function, this will be fixed up in decls_for_scope. If
22813 we're a method, it will be ignored, since we already have a DIE. */
22814 if (decl_function_context (decl)
22815 /* But if we're in terse mode, we don't care about scope. */
22816 && debug_info_level > DINFO_LEVEL_TERSE)
22817 context_die = NULL;
22821 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
22822 declaration and if the declaration was never even referenced from
22823 within this entire compilation unit. We suppress these DIEs in
22824 order to save space in the .debug section (by eliminating entries
22825 which are probably useless). Note that we must not suppress
22826 block-local extern declarations (whether used or not) because that
22827 would screw-up the debugger's name lookup mechanism and cause it to
22828 miss things which really ought to be in scope at a given point. */
22829 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
22832 /* For local statics lookup proper context die. */
22833 if (TREE_STATIC (decl) && decl_function_context (decl))
22834 context_die = lookup_decl_die (DECL_CONTEXT (decl));
22836 /* If we are in terse mode, don't generate any DIEs to represent any
22837 variable declarations or definitions. */
22838 if (debug_info_level <= DINFO_LEVEL_TERSE)
22843 if (debug_info_level <= DINFO_LEVEL_TERSE)
22845 if (!is_fortran () && !is_ada ())
22847 if (TREE_STATIC (decl) && decl_function_context (decl))
22848 context_die = lookup_decl_die (DECL_CONTEXT (decl));
22851 case NAMESPACE_DECL:
22852 case IMPORTED_DECL:
22853 if (debug_info_level <= DINFO_LEVEL_TERSE)
22855 if (lookup_decl_die (decl) != NULL)
22860 /* Don't emit stubs for types unless they are needed by other DIEs. */
22861 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
22864 /* Don't bother trying to generate any DIEs to represent any of the
22865 normal built-in types for the language we are compiling. */
22866 if (DECL_IS_BUILTIN (decl))
22869 /* If we are in terse mode, don't generate any DIEs for types. */
22870 if (debug_info_level <= DINFO_LEVEL_TERSE)
22873 /* If we're a function-scope tag, initially use a parent of NULL;
22874 this will be fixed up in decls_for_scope. */
22875 if (decl_function_context (decl))
22876 context_die = NULL;
22884 gen_decl_die (decl, NULL, context_die);
22887 /* Write the debugging output for DECL. */
22890 dwarf2out_function_decl (tree decl)
22892 dwarf2out_decl (decl);
22893 call_arg_locations = NULL;
22894 call_arg_loc_last = NULL;
22895 call_site_count = -1;
22896 tail_call_site_count = -1;
22897 VEC_free (dw_die_ref, heap, block_map);
22898 htab_empty (decl_loc_table);
22899 htab_empty (cached_dw_loc_list_table);
22902 /* Output a marker (i.e. a label) for the beginning of the generated code for
22903 a lexical block. */
22906 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
22907 unsigned int blocknum)
22909 switch_to_section (current_function_section ());
22910 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
22913 /* Output a marker (i.e. a label) for the end of the generated code for a
22917 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
22919 switch_to_section (current_function_section ());
22920 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
22923 /* Returns nonzero if it is appropriate not to emit any debugging
22924 information for BLOCK, because it doesn't contain any instructions.
22926 Don't allow this for blocks with nested functions or local classes
22927 as we would end up with orphans, and in the presence of scheduling
22928 we may end up calling them anyway. */
22931 dwarf2out_ignore_block (const_tree block)
22936 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
22937 if (TREE_CODE (decl) == FUNCTION_DECL
22938 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22940 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
22942 decl = BLOCK_NONLOCALIZED_VAR (block, i);
22943 if (TREE_CODE (decl) == FUNCTION_DECL
22944 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22951 /* Hash table routines for file_hash. */
22954 file_table_eq (const void *p1_p, const void *p2_p)
22956 const struct dwarf_file_data *const p1 =
22957 (const struct dwarf_file_data *) p1_p;
22958 const char *const p2 = (const char *) p2_p;
22959 return filename_cmp (p1->filename, p2) == 0;
22963 file_table_hash (const void *p_p)
22965 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
22966 return htab_hash_string (p->filename);
22969 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22970 dwarf2out.c) and return its "index". The index of each (known) filename is
22971 just a unique number which is associated with only that one filename. We
22972 need such numbers for the sake of generating labels (in the .debug_sfnames
22973 section) and references to those files numbers (in the .debug_srcinfo
22974 and.debug_macinfo sections). If the filename given as an argument is not
22975 found in our current list, add it to the list and assign it the next
22976 available unique index number. In order to speed up searches, we remember
22977 the index of the filename was looked up last. This handles the majority of
22980 static struct dwarf_file_data *
22981 lookup_filename (const char *file_name)
22984 struct dwarf_file_data * created;
22986 /* Check to see if the file name that was searched on the previous
22987 call matches this file name. If so, return the index. */
22988 if (file_table_last_lookup
22989 && (file_name == file_table_last_lookup->filename
22990 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
22991 return file_table_last_lookup;
22993 /* Didn't match the previous lookup, search the table. */
22994 slot = htab_find_slot_with_hash (file_table, file_name,
22995 htab_hash_string (file_name), INSERT);
22997 return (struct dwarf_file_data *) *slot;
22999 created = ggc_alloc_dwarf_file_data ();
23000 created->filename = file_name;
23001 created->emitted_number = 0;
23006 /* If the assembler will construct the file table, then translate the compiler
23007 internal file table number into the assembler file table number, and emit
23008 a .file directive if we haven't already emitted one yet. The file table
23009 numbers are different because we prune debug info for unused variables and
23010 types, which may include filenames. */
23013 maybe_emit_file (struct dwarf_file_data * fd)
23015 if (! fd->emitted_number)
23017 if (last_emitted_file)
23018 fd->emitted_number = last_emitted_file->emitted_number + 1;
23020 fd->emitted_number = 1;
23021 last_emitted_file = fd;
23023 if (DWARF2_ASM_LINE_DEBUG_INFO)
23025 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
23026 output_quoted_string (asm_out_file,
23027 remap_debug_filename (fd->filename));
23028 fputc ('\n', asm_out_file);
23032 return fd->emitted_number;
23035 /* Schedule generation of a DW_AT_const_value attribute to DIE.
23036 That generation should happen after function debug info has been
23037 generated. The value of the attribute is the constant value of ARG. */
23040 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
23042 die_arg_entry entry;
23047 if (!tmpl_value_parm_die_table)
23048 tmpl_value_parm_die_table
23049 = VEC_alloc (die_arg_entry, gc, 32);
23053 VEC_safe_push (die_arg_entry, gc,
23054 tmpl_value_parm_die_table,
23058 /* Return TRUE if T is an instance of generic type, FALSE
23062 generic_type_p (tree t)
23064 if (t == NULL_TREE || !TYPE_P (t))
23066 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
23069 /* Schedule the generation of the generic parameter dies for the
23070 instance of generic type T. The proper generation itself is later
23071 done by gen_scheduled_generic_parms_dies. */
23074 schedule_generic_params_dies_gen (tree t)
23076 if (!generic_type_p (t))
23079 if (generic_type_instances == NULL)
23080 generic_type_instances = VEC_alloc (tree, gc, 256);
23082 VEC_safe_push (tree, gc, generic_type_instances, t);
23085 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
23086 by append_entry_to_tmpl_value_parm_die_table. This function must
23087 be called after function DIEs have been generated. */
23090 gen_remaining_tmpl_value_param_die_attribute (void)
23092 if (tmpl_value_parm_die_table)
23097 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
23098 tree_add_const_value_attribute (e->die, e->arg);
23102 /* Generate generic parameters DIEs for instances of generic types
23103 that have been previously scheduled by
23104 schedule_generic_params_dies_gen. This function must be called
23105 after all the types of the CU have been laid out. */
23108 gen_scheduled_generic_parms_dies (void)
23113 if (generic_type_instances == NULL)
23116 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
23117 gen_generic_params_dies (t);
23121 /* Replace DW_AT_name for the decl with name. */
23124 dwarf2out_set_name (tree decl, tree name)
23130 die = TYPE_SYMTAB_DIE (decl);
23134 dname = dwarf2_name (name, 0);
23138 attr = get_AT (die, DW_AT_name);
23141 struct indirect_string_node *node;
23143 node = find_AT_string (dname);
23144 /* replace the string. */
23145 attr->dw_attr_val.v.val_str = node;
23149 add_name_attribute (die, dname);
23152 /* Called by the final INSN scan whenever we see a var location. We
23153 use it to drop labels in the right places, and throw the location in
23154 our lookup table. */
23157 dwarf2out_var_location (rtx loc_note)
23159 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
23160 struct var_loc_node *newloc;
23162 static const char *last_label;
23163 static const char *last_postcall_label;
23164 static bool last_in_cold_section_p;
23168 if (!NOTE_P (loc_note))
23170 if (CALL_P (loc_note))
23173 if (SIBLING_CALL_P (loc_note))
23174 tail_call_site_count++;
23179 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
23180 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
23183 next_real = next_real_insn (loc_note);
23185 /* If there are no instructions which would be affected by this note,
23186 don't do anything. */
23188 && next_real == NULL_RTX
23189 && !NOTE_DURING_CALL_P (loc_note))
23192 if (next_real == NULL_RTX)
23193 next_real = get_last_insn ();
23195 /* If there were any real insns between note we processed last time
23196 and this note (or if it is the first note), clear
23197 last_{,postcall_}label so that they are not reused this time. */
23198 if (last_var_location_insn == NULL_RTX
23199 || last_var_location_insn != next_real
23200 || last_in_cold_section_p != in_cold_section_p)
23203 last_postcall_label = NULL;
23208 decl = NOTE_VAR_LOCATION_DECL (loc_note);
23209 newloc = add_var_loc_to_decl (decl, loc_note,
23210 NOTE_DURING_CALL_P (loc_note)
23211 ? last_postcall_label : last_label);
23212 if (newloc == NULL)
23221 /* If there were no real insns between note we processed last time
23222 and this note, use the label we emitted last time. Otherwise
23223 create a new label and emit it. */
23224 if (last_label == NULL)
23226 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
23227 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
23229 last_label = ggc_strdup (loclabel);
23234 struct call_arg_loc_node *ca_loc
23235 = ggc_alloc_cleared_call_arg_loc_node ();
23236 rtx prev = prev_real_insn (loc_note), x;
23237 ca_loc->call_arg_loc_note = loc_note;
23238 ca_loc->next = NULL;
23239 ca_loc->label = last_label;
23242 || (NONJUMP_INSN_P (prev)
23243 && GET_CODE (PATTERN (prev)) == SEQUENCE
23244 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
23245 if (!CALL_P (prev))
23246 prev = XVECEXP (PATTERN (prev), 0, 0);
23247 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
23248 x = PATTERN (prev);
23249 if (GET_CODE (x) == PARALLEL)
23250 x = XVECEXP (x, 0, 0);
23251 if (GET_CODE (x) == SET)
23253 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
23255 x = XEXP (XEXP (x, 0), 0);
23256 if (GET_CODE (x) == SYMBOL_REF
23257 && SYMBOL_REF_DECL (x)
23258 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
23259 ca_loc->symbol_ref = x;
23261 ca_loc->block = insn_scope (prev);
23262 if (call_arg_locations)
23263 call_arg_loc_last->next = ca_loc;
23265 call_arg_locations = ca_loc;
23266 call_arg_loc_last = ca_loc;
23268 else if (!NOTE_DURING_CALL_P (loc_note))
23269 newloc->label = last_label;
23272 if (!last_postcall_label)
23274 sprintf (loclabel, "%s-1", last_label);
23275 last_postcall_label = ggc_strdup (loclabel);
23277 newloc->label = last_postcall_label;
23280 last_var_location_insn = next_real;
23281 last_in_cold_section_p = in_cold_section_p;
23284 /* Note in one location list that text section has changed. */
23287 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
23289 var_loc_list *list = (var_loc_list *) *slot;
23291 list->last_before_switch
23292 = list->last->next ? list->last->next : list->last;
23296 /* Note in all location lists that text section has changed. */
23299 var_location_switch_text_section (void)
23301 if (decl_loc_table == NULL)
23304 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
23307 /* Create a new line number table. */
23309 static dw_line_info_table *
23310 new_line_info_table (void)
23312 dw_line_info_table *table;
23314 table = ggc_alloc_cleared_dw_line_info_table_struct ();
23315 table->file_num = 1;
23316 table->line_num = 1;
23317 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
23322 /* Lookup the "current" table into which we emit line info, so
23323 that we don't have to do it for every source line. */
23326 set_cur_line_info_table (section *sec)
23328 dw_line_info_table *table;
23330 if (sec == text_section)
23331 table = text_section_line_info;
23332 else if (sec == cold_text_section)
23334 table = cold_text_section_line_info;
23337 cold_text_section_line_info = table = new_line_info_table ();
23338 table->end_label = cold_end_label;
23343 const char *end_label;
23345 if (flag_reorder_blocks_and_partition)
23347 if (in_cold_section_p)
23348 end_label = crtl->subsections.cold_section_end_label;
23350 end_label = crtl->subsections.hot_section_end_label;
23354 char label[MAX_ARTIFICIAL_LABEL_BYTES];
23355 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
23356 current_function_funcdef_no);
23357 end_label = ggc_strdup (label);
23360 table = new_line_info_table ();
23361 table->end_label = end_label;
23363 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
23366 cur_line_info_table = table;
23370 /* We need to reset the locations at the beginning of each
23371 function. We can't do this in the end_function hook, because the
23372 declarations that use the locations won't have been output when
23373 that hook is called. Also compute have_multiple_function_sections here. */
23376 dwarf2out_begin_function (tree fun)
23378 section *sec = function_section (fun);
23380 if (sec != text_section)
23381 have_multiple_function_sections = true;
23383 if (flag_reorder_blocks_and_partition && !cold_text_section)
23385 gcc_assert (current_function_decl == fun);
23386 cold_text_section = unlikely_text_section ();
23387 switch_to_section (cold_text_section);
23388 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
23389 switch_to_section (sec);
23392 dwarf2out_note_section_used ();
23393 call_site_count = 0;
23394 tail_call_site_count = 0;
23396 set_cur_line_info_table (sec);
23399 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
23402 push_dw_line_info_entry (dw_line_info_table *table,
23403 enum dw_line_info_opcode opcode, unsigned int val)
23405 dw_line_info_entry e;
23408 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
23411 /* Output a label to mark the beginning of a source code line entry
23412 and record information relating to this source line, in
23413 'line_info_table' for later output of the .debug_line section. */
23414 /* ??? The discriminator parameter ought to be unsigned. */
23417 dwarf2out_source_line (unsigned int line, const char *filename,
23418 int discriminator, bool is_stmt)
23420 unsigned int file_num;
23421 dw_line_info_table *table;
23423 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
23426 /* The discriminator column was added in dwarf4. Simplify the below
23427 by simply removing it if we're not supposed to output it. */
23428 if (dwarf_version < 4 && dwarf_strict)
23431 table = cur_line_info_table;
23432 file_num = maybe_emit_file (lookup_filename (filename));
23434 /* ??? TODO: Elide duplicate line number entries. Traditionally,
23435 the debugger has used the second (possibly duplicate) line number
23436 at the beginning of the function to mark the end of the prologue.
23437 We could eliminate any other duplicates within the function. For
23438 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
23439 that second line number entry. */
23440 /* Recall that this end-of-prologue indication is *not* the same thing
23441 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
23442 to which the hook corresponds, follows the last insn that was
23443 emitted by gen_prologue. What we need is to preceed the first insn
23444 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
23445 insn that corresponds to something the user wrote. These may be
23446 very different locations once scheduling is enabled. */
23448 if (0 && file_num == table->file_num
23449 && line == table->line_num
23450 && discriminator == table->discrim_num
23451 && is_stmt == table->is_stmt)
23454 switch_to_section (current_function_section ());
23456 /* If requested, emit something human-readable. */
23457 if (flag_debug_asm)
23458 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
23460 if (DWARF2_ASM_LINE_DEBUG_INFO)
23462 /* Emit the .loc directive understood by GNU as. */
23463 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
23464 if (is_stmt != table->is_stmt)
23465 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
23466 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
23467 fprintf (asm_out_file, " discriminator %d", discriminator);
23468 fputc ('\n', asm_out_file);
23472 unsigned int label_num = ++line_info_label_num;
23474 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
23476 push_dw_line_info_entry (table, LI_set_address, label_num);
23477 if (file_num != table->file_num)
23478 push_dw_line_info_entry (table, LI_set_file, file_num);
23479 if (discriminator != table->discrim_num)
23480 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
23481 if (is_stmt != table->is_stmt)
23482 push_dw_line_info_entry (table, LI_negate_stmt, 0);
23483 push_dw_line_info_entry (table, LI_set_line, line);
23486 table->file_num = file_num;
23487 table->line_num = line;
23488 table->discrim_num = discriminator;
23489 table->is_stmt = is_stmt;
23490 table->in_use = true;
23493 /* Record the beginning of a new source file. */
23496 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
23498 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
23500 /* Record the beginning of the file for break_out_includes. */
23501 dw_die_ref bincl_die;
23503 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
23504 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
23507 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23510 e.code = DW_MACINFO_start_file;
23512 e.info = xstrdup (filename);
23513 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23517 /* Record the end of a source file. */
23520 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
23522 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
23523 /* Record the end of the file for break_out_includes. */
23524 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
23526 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23529 e.code = DW_MACINFO_end_file;
23532 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23536 /* Called from debug_define in toplev.c. The `buffer' parameter contains
23537 the tail part of the directive line, i.e. the part which is past the
23538 initial whitespace, #, whitespace, directive-name, whitespace part. */
23541 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
23542 const char *buffer ATTRIBUTE_UNUSED)
23544 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23547 e.code = DW_MACINFO_define;
23549 e.info = xstrdup (buffer);;
23550 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23554 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
23555 the tail part of the directive line, i.e. the part which is past the
23556 initial whitespace, #, whitespace, directive-name, whitespace part. */
23559 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
23560 const char *buffer ATTRIBUTE_UNUSED)
23562 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23565 e.code = DW_MACINFO_undef;
23567 e.info = xstrdup (buffer);;
23568 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23573 output_macinfo (void)
23576 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
23577 macinfo_entry *ref;
23582 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
23586 case DW_MACINFO_start_file:
23588 int file_num = maybe_emit_file (lookup_filename (ref->info));
23589 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
23590 dw2_asm_output_data_uleb128
23591 (ref->lineno, "Included from line number %lu",
23592 (unsigned long)ref->lineno);
23593 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
23596 case DW_MACINFO_end_file:
23597 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
23599 case DW_MACINFO_define:
23600 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
23601 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
23602 (unsigned long)ref->lineno);
23603 dw2_asm_output_nstring (ref->info, -1, "The macro");
23605 case DW_MACINFO_undef:
23606 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
23607 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
23608 (unsigned long)ref->lineno);
23609 dw2_asm_output_nstring (ref->info, -1, "The macro");
23612 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
23613 ASM_COMMENT_START, (unsigned long)ref->code);
23619 /* Set up for Dwarf output at the start of compilation. */
23622 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
23624 /* Allocate the file_table. */
23625 file_table = htab_create_ggc (50, file_table_hash,
23626 file_table_eq, NULL);
23628 /* Allocate the decl_die_table. */
23629 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
23630 decl_die_table_eq, NULL);
23632 /* Allocate the decl_loc_table. */
23633 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
23634 decl_loc_table_eq, NULL);
23636 /* Allocate the cached_dw_loc_list_table. */
23637 cached_dw_loc_list_table
23638 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
23639 cached_dw_loc_list_table_eq, NULL);
23641 /* Allocate the initial hunk of the decl_scope_table. */
23642 decl_scope_table = VEC_alloc (tree, gc, 256);
23644 /* Allocate the initial hunk of the abbrev_die_table. */
23645 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
23646 (ABBREV_DIE_TABLE_INCREMENT);
23647 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
23648 /* Zero-th entry is allocated, but unused. */
23649 abbrev_die_table_in_use = 1;
23651 /* Allocate the pubtypes and pubnames vectors. */
23652 pubname_table = VEC_alloc (pubname_entry, gc, 32);
23653 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
23655 incomplete_types = VEC_alloc (tree, gc, 64);
23657 used_rtx_array = VEC_alloc (rtx, gc, 32);
23659 debug_info_section = get_section (DEBUG_INFO_SECTION,
23660 SECTION_DEBUG, NULL);
23661 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
23662 SECTION_DEBUG, NULL);
23663 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
23664 SECTION_DEBUG, NULL);
23665 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
23666 SECTION_DEBUG, NULL);
23667 debug_line_section = get_section (DEBUG_LINE_SECTION,
23668 SECTION_DEBUG, NULL);
23669 debug_loc_section = get_section (DEBUG_LOC_SECTION,
23670 SECTION_DEBUG, NULL);
23671 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
23672 SECTION_DEBUG, NULL);
23673 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
23674 SECTION_DEBUG, NULL);
23675 debug_str_section = get_section (DEBUG_STR_SECTION,
23676 DEBUG_STR_SECTION_FLAGS, NULL);
23677 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
23678 SECTION_DEBUG, NULL);
23679 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
23680 SECTION_DEBUG, NULL);
23682 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
23683 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
23684 DEBUG_ABBREV_SECTION_LABEL, 0);
23685 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
23686 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
23687 COLD_TEXT_SECTION_LABEL, 0);
23688 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
23690 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
23691 DEBUG_INFO_SECTION_LABEL, 0);
23692 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
23693 DEBUG_LINE_SECTION_LABEL, 0);
23694 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
23695 DEBUG_RANGES_SECTION_LABEL, 0);
23696 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
23697 DEBUG_MACINFO_SECTION_LABEL, 0);
23699 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23700 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
23702 switch_to_section (text_section);
23703 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
23705 /* Make sure the line number table for .text always exists. */
23706 text_section_line_info = new_line_info_table ();
23707 text_section_line_info->end_label = text_end_label;
23710 /* Called before cgraph_optimize starts outputtting functions, variables
23711 and toplevel asms into assembly. */
23714 dwarf2out_assembly_start (void)
23716 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23717 && dwarf2out_do_cfi_asm ()
23718 && (!(flag_unwind_tables || flag_exceptions)
23719 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
23720 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
23723 /* A helper function for dwarf2out_finish called through
23724 htab_traverse. Emit one queued .debug_str string. */
23727 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
23729 struct indirect_string_node *node = (struct indirect_string_node *) *h;
23731 if (node->form == DW_FORM_strp)
23733 switch_to_section (debug_str_section);
23734 ASM_OUTPUT_LABEL (asm_out_file, node->label);
23735 assemble_string (node->str, strlen (node->str) + 1);
23741 #if ENABLE_ASSERT_CHECKING
23742 /* Verify that all marks are clear. */
23745 verify_marks_clear (dw_die_ref die)
23749 gcc_assert (! die->die_mark);
23750 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
23752 #endif /* ENABLE_ASSERT_CHECKING */
23754 /* Clear the marks for a die and its children.
23755 Be cool if the mark isn't set. */
23758 prune_unmark_dies (dw_die_ref die)
23764 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
23767 /* Given DIE that we're marking as used, find any other dies
23768 it references as attributes and mark them as used. */
23771 prune_unused_types_walk_attribs (dw_die_ref die)
23776 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23778 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
23780 /* A reference to another DIE.
23781 Make sure that it will get emitted.
23782 If it was broken out into a comdat group, don't follow it. */
23783 if (! use_debug_types
23784 || a->dw_attr == DW_AT_specification
23785 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
23786 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
23788 /* Set the string's refcount to 0 so that prune_unused_types_mark
23789 accounts properly for it. */
23790 if (AT_class (a) == dw_val_class_str)
23791 a->dw_attr_val.v.val_str->refcount = 0;
23795 /* Mark the generic parameters and arguments children DIEs of DIE. */
23798 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
23802 if (die == NULL || die->die_child == NULL)
23804 c = die->die_child;
23807 switch (c->die_tag)
23809 case DW_TAG_template_type_param:
23810 case DW_TAG_template_value_param:
23811 case DW_TAG_GNU_template_template_param:
23812 case DW_TAG_GNU_template_parameter_pack:
23813 prune_unused_types_mark (c, 1);
23819 } while (c && c != die->die_child);
23822 /* Mark DIE as being used. If DOKIDS is true, then walk down
23823 to DIE's children. */
23826 prune_unused_types_mark (dw_die_ref die, int dokids)
23830 if (die->die_mark == 0)
23832 /* We haven't done this node yet. Mark it as used. */
23834 /* If this is the DIE of a generic type instantiation,
23835 mark the children DIEs that describe its generic parms and
23837 prune_unused_types_mark_generic_parms_dies (die);
23839 /* We also have to mark its parents as used.
23840 (But we don't want to mark our parents' kids due to this.) */
23841 if (die->die_parent)
23842 prune_unused_types_mark (die->die_parent, 0);
23844 /* Mark any referenced nodes. */
23845 prune_unused_types_walk_attribs (die);
23847 /* If this node is a specification,
23848 also mark the definition, if it exists. */
23849 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
23850 prune_unused_types_mark (die->die_definition, 1);
23853 if (dokids && die->die_mark != 2)
23855 /* We need to walk the children, but haven't done so yet.
23856 Remember that we've walked the kids. */
23859 /* If this is an array type, we need to make sure our
23860 kids get marked, even if they're types. If we're
23861 breaking out types into comdat sections, do this
23862 for all type definitions. */
23863 if (die->die_tag == DW_TAG_array_type
23864 || (use_debug_types
23865 && is_type_die (die) && ! is_declaration_die (die)))
23866 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
23868 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23872 /* For local classes, look if any static member functions were emitted
23873 and if so, mark them. */
23876 prune_unused_types_walk_local_classes (dw_die_ref die)
23880 if (die->die_mark == 2)
23883 switch (die->die_tag)
23885 case DW_TAG_structure_type:
23886 case DW_TAG_union_type:
23887 case DW_TAG_class_type:
23890 case DW_TAG_subprogram:
23891 if (!get_AT_flag (die, DW_AT_declaration)
23892 || die->die_definition != NULL)
23893 prune_unused_types_mark (die, 1);
23900 /* Mark children. */
23901 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
23904 /* Walk the tree DIE and mark types that we actually use. */
23907 prune_unused_types_walk (dw_die_ref die)
23911 /* Don't do anything if this node is already marked and
23912 children have been marked as well. */
23913 if (die->die_mark == 2)
23916 switch (die->die_tag)
23918 case DW_TAG_structure_type:
23919 case DW_TAG_union_type:
23920 case DW_TAG_class_type:
23921 if (die->die_perennial_p)
23924 for (c = die->die_parent; c; c = c->die_parent)
23925 if (c->die_tag == DW_TAG_subprogram)
23928 /* Finding used static member functions inside of classes
23929 is needed just for local classes, because for other classes
23930 static member function DIEs with DW_AT_specification
23931 are emitted outside of the DW_TAG_*_type. If we ever change
23932 it, we'd need to call this even for non-local classes. */
23934 prune_unused_types_walk_local_classes (die);
23936 /* It's a type node --- don't mark it. */
23939 case DW_TAG_const_type:
23940 case DW_TAG_packed_type:
23941 case DW_TAG_pointer_type:
23942 case DW_TAG_reference_type:
23943 case DW_TAG_rvalue_reference_type:
23944 case DW_TAG_volatile_type:
23945 case DW_TAG_typedef:
23946 case DW_TAG_array_type:
23947 case DW_TAG_interface_type:
23948 case DW_TAG_friend:
23949 case DW_TAG_variant_part:
23950 case DW_TAG_enumeration_type:
23951 case DW_TAG_subroutine_type:
23952 case DW_TAG_string_type:
23953 case DW_TAG_set_type:
23954 case DW_TAG_subrange_type:
23955 case DW_TAG_ptr_to_member_type:
23956 case DW_TAG_file_type:
23957 if (die->die_perennial_p)
23960 /* It's a type node --- don't mark it. */
23964 /* Mark everything else. */
23968 if (die->die_mark == 0)
23972 /* Now, mark any dies referenced from here. */
23973 prune_unused_types_walk_attribs (die);
23978 /* Mark children. */
23979 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23982 /* Increment the string counts on strings referred to from DIE's
23986 prune_unused_types_update_strings (dw_die_ref die)
23991 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23992 if (AT_class (a) == dw_val_class_str)
23994 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
23996 /* Avoid unnecessarily putting strings that are used less than
23997 twice in the hash table. */
23999 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
24002 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
24003 htab_hash_string (s->str),
24005 gcc_assert (*slot == NULL);
24011 /* Remove from the tree DIE any dies that aren't marked. */
24014 prune_unused_types_prune (dw_die_ref die)
24018 gcc_assert (die->die_mark);
24019 prune_unused_types_update_strings (die);
24021 if (! die->die_child)
24024 c = die->die_child;
24026 dw_die_ref prev = c;
24027 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
24028 if (c == die->die_child)
24030 /* No marked children between 'prev' and the end of the list. */
24032 /* No marked children at all. */
24033 die->die_child = NULL;
24036 prev->die_sib = c->die_sib;
24037 die->die_child = prev;
24042 if (c != prev->die_sib)
24044 prune_unused_types_prune (c);
24045 } while (c != die->die_child);
24048 /* Remove dies representing declarations that we never use. */
24051 prune_unused_types (void)
24054 limbo_die_node *node;
24055 comdat_type_node *ctnode;
24057 dw_die_ref base_type;
24059 #if ENABLE_ASSERT_CHECKING
24060 /* All the marks should already be clear. */
24061 verify_marks_clear (comp_unit_die ());
24062 for (node = limbo_die_list; node; node = node->next)
24063 verify_marks_clear (node->die);
24064 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
24065 verify_marks_clear (ctnode->root_die);
24066 #endif /* ENABLE_ASSERT_CHECKING */
24068 /* Mark types that are used in global variables. */
24069 premark_types_used_by_global_vars ();
24071 /* Set the mark on nodes that are actually used. */
24072 prune_unused_types_walk (comp_unit_die ());
24073 for (node = limbo_die_list; node; node = node->next)
24074 prune_unused_types_walk (node->die);
24075 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
24077 prune_unused_types_walk (ctnode->root_die);
24078 prune_unused_types_mark (ctnode->type_die, 1);
24081 /* Also set the mark on nodes referenced from the
24083 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
24084 prune_unused_types_mark (pub->die, 1);
24085 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
24086 prune_unused_types_mark (base_type, 1);
24088 if (debug_str_hash)
24089 htab_empty (debug_str_hash);
24090 prune_unused_types_prune (comp_unit_die ());
24091 for (node = limbo_die_list; node; node = node->next)
24092 prune_unused_types_prune (node->die);
24093 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
24094 prune_unused_types_prune (ctnode->root_die);
24096 /* Leave the marks clear. */
24097 prune_unmark_dies (comp_unit_die ());
24098 for (node = limbo_die_list; node; node = node->next)
24099 prune_unmark_dies (node->die);
24100 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
24101 prune_unmark_dies (ctnode->root_die);
24104 /* Set the parameter to true if there are any relative pathnames in
24107 file_table_relative_p (void ** slot, void *param)
24109 bool *p = (bool *) param;
24110 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
24111 if (!IS_ABSOLUTE_PATH (d->filename))
24119 /* Routines to manipulate hash table of comdat type units. */
24122 htab_ct_hash (const void *of)
24125 const comdat_type_node *const type_node = (const comdat_type_node *) of;
24127 memcpy (&h, type_node->signature, sizeof (h));
24132 htab_ct_eq (const void *of1, const void *of2)
24134 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
24135 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
24137 return (! memcmp (type_node_1->signature, type_node_2->signature,
24138 DWARF_TYPE_SIGNATURE_SIZE));
24141 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
24142 to the location it would have been added, should we know its
24143 DECL_ASSEMBLER_NAME when we added other attributes. This will
24144 probably improve compactness of debug info, removing equivalent
24145 abbrevs, and hide any differences caused by deferring the
24146 computation of the assembler name, triggered by e.g. PCH. */
24149 move_linkage_attr (dw_die_ref die)
24151 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
24152 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
24154 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
24155 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
24159 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
24161 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
24165 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
24167 VEC_pop (dw_attr_node, die->die_attr);
24168 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
24172 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
24173 referenced from typed stack ops and count how often they are used. */
24176 mark_base_types (dw_loc_descr_ref loc)
24178 dw_die_ref base_type = NULL;
24180 for (; loc; loc = loc->dw_loc_next)
24182 switch (loc->dw_loc_opc)
24184 case DW_OP_GNU_regval_type:
24185 case DW_OP_GNU_deref_type:
24186 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
24188 case DW_OP_GNU_convert:
24189 case DW_OP_GNU_reinterpret:
24190 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
24193 case DW_OP_GNU_const_type:
24194 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
24196 case DW_OP_GNU_entry_value:
24197 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
24202 gcc_assert (base_type->die_parent == comp_unit_die ());
24203 if (base_type->die_mark)
24204 base_type->die_mark++;
24207 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
24208 base_type->die_mark = 1;
24213 /* Comparison function for sorting marked base types. */
24216 base_type_cmp (const void *x, const void *y)
24218 dw_die_ref dx = *(const dw_die_ref *) x;
24219 dw_die_ref dy = *(const dw_die_ref *) y;
24220 unsigned int byte_size1, byte_size2;
24221 unsigned int encoding1, encoding2;
24222 if (dx->die_mark > dy->die_mark)
24224 if (dx->die_mark < dy->die_mark)
24226 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
24227 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
24228 if (byte_size1 < byte_size2)
24230 if (byte_size1 > byte_size2)
24232 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
24233 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
24234 if (encoding1 < encoding2)
24236 if (encoding1 > encoding2)
24241 /* Move base types marked by mark_base_types as early as possible
24242 in the CU, sorted by decreasing usage count both to make the
24243 uleb128 references as small as possible and to make sure they
24244 will have die_offset already computed by calc_die_sizes when
24245 sizes of typed stack loc ops is computed. */
24248 move_marked_base_types (void)
24251 dw_die_ref base_type, die, c;
24253 if (VEC_empty (dw_die_ref, base_types))
24256 /* Sort by decreasing usage count, they will be added again in that
24258 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
24259 die = comp_unit_die ();
24260 c = die->die_child;
24263 dw_die_ref prev = c;
24265 while (c->die_mark)
24267 remove_child_with_prev (c, prev);
24268 /* As base types got marked, there must be at least
24269 one node other than DW_TAG_base_type. */
24270 gcc_assert (c != c->die_sib);
24274 while (c != die->die_child);
24275 gcc_assert (die->die_child);
24276 c = die->die_child;
24277 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
24279 base_type->die_mark = 0;
24280 base_type->die_sib = c->die_sib;
24281 c->die_sib = base_type;
24286 /* Helper function for resolve_addr, attempt to resolve
24287 one CONST_STRING, return non-zero if not successful. Similarly verify that
24288 SYMBOL_REFs refer to variables emitted in the current CU. */
24291 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
24295 if (GET_CODE (rtl) == CONST_STRING)
24297 size_t len = strlen (XSTR (rtl, 0)) + 1;
24298 tree t = build_string (len, XSTR (rtl, 0));
24299 tree tlen = size_int (len - 1);
24301 = build_array_type (char_type_node, build_index_type (tlen));
24302 rtl = lookup_constant_def (t);
24303 if (!rtl || !MEM_P (rtl))
24305 rtl = XEXP (rtl, 0);
24306 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
24311 if (GET_CODE (rtl) == SYMBOL_REF
24312 && SYMBOL_REF_DECL (rtl))
24314 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
24316 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
24319 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
24323 if (GET_CODE (rtl) == CONST
24324 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
24330 /* Helper function for resolve_addr, handle one location
24331 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24332 the location list couldn't be resolved. */
24335 resolve_addr_in_expr (dw_loc_descr_ref loc)
24337 dw_loc_descr_ref keep = NULL;
24338 for (; loc; loc = loc->dw_loc_next)
24339 switch (loc->dw_loc_opc)
24342 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
24345 case DW_OP_const4u:
24346 case DW_OP_const8u:
24348 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
24351 case DW_OP_implicit_value:
24352 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
24353 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
24356 case DW_OP_GNU_implicit_pointer:
24357 case DW_OP_GNU_parameter_ref:
24358 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
24361 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
24364 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
24365 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
24366 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
24369 case DW_OP_GNU_const_type:
24370 case DW_OP_GNU_regval_type:
24371 case DW_OP_GNU_deref_type:
24372 case DW_OP_GNU_convert:
24373 case DW_OP_GNU_reinterpret:
24374 while (loc->dw_loc_next
24375 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
24377 dw_die_ref base1, base2;
24378 unsigned enc1, enc2, size1, size2;
24379 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24380 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24381 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
24382 else if (loc->dw_loc_oprnd1.val_class
24383 == dw_val_class_unsigned_const)
24386 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
24387 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
24388 == dw_val_class_unsigned_const)
24390 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
24391 gcc_assert (base1->die_tag == DW_TAG_base_type
24392 && base2->die_tag == DW_TAG_base_type);
24393 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
24394 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
24395 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
24396 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
24398 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
24399 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
24403 /* Optimize away next DW_OP_GNU_convert after
24404 adjusting LOC's base type die reference. */
24405 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24406 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24407 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
24409 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
24410 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
24413 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24414 point typed stack entry. */
24415 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
24416 keep = loc->dw_loc_next;
24426 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24427 an address in .rodata section if the string literal is emitted there,
24428 or remove the containing location list or replace DW_AT_const_value
24429 with DW_AT_location and empty location expression, if it isn't found
24430 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24431 to something that has been emitted in the current CU. */
24434 resolve_addr (dw_die_ref die)
24438 dw_loc_list_ref *curr, *start, loc;
24441 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
24442 switch (AT_class (a))
24444 case dw_val_class_loc_list:
24445 start = curr = AT_loc_list_ptr (a);
24448 /* The same list can be referenced more than once. See if we have
24449 already recorded the result from a previous pass. */
24451 *curr = loc->dw_loc_next;
24452 else if (!loc->resolved_addr)
24454 /* As things stand, we do not expect or allow one die to
24455 reference a suffix of another die's location list chain.
24456 References must be identical or completely separate.
24457 There is therefore no need to cache the result of this
24458 pass on any list other than the first; doing so
24459 would lead to unnecessary writes. */
24462 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
24463 if (!resolve_addr_in_expr ((*curr)->expr))
24465 dw_loc_list_ref next = (*curr)->dw_loc_next;
24466 if (next && (*curr)->ll_symbol)
24468 gcc_assert (!next->ll_symbol);
24469 next->ll_symbol = (*curr)->ll_symbol;
24475 mark_base_types ((*curr)->expr);
24476 curr = &(*curr)->dw_loc_next;
24480 loc->resolved_addr = 1;
24484 loc->dw_loc_next = *start;
24489 remove_AT (die, a->dw_attr);
24493 case dw_val_class_loc:
24494 if (!resolve_addr_in_expr (AT_loc (a)))
24496 remove_AT (die, a->dw_attr);
24500 mark_base_types (AT_loc (a));
24502 case dw_val_class_addr:
24503 if (a->dw_attr == DW_AT_const_value
24504 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
24506 remove_AT (die, a->dw_attr);
24509 if (die->die_tag == DW_TAG_GNU_call_site
24510 && a->dw_attr == DW_AT_abstract_origin)
24512 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
24513 dw_die_ref tdie = lookup_decl_die (tdecl);
24515 && DECL_EXTERNAL (tdecl)
24516 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
24518 force_decl_die (tdecl);
24519 tdie = lookup_decl_die (tdecl);
24523 a->dw_attr_val.val_class = dw_val_class_die_ref;
24524 a->dw_attr_val.v.val_die_ref.die = tdie;
24525 a->dw_attr_val.v.val_die_ref.external = 0;
24529 remove_AT (die, a->dw_attr);
24538 FOR_EACH_CHILD (die, c, resolve_addr (c));
24541 /* Helper routines for optimize_location_lists.
24542 This pass tries to share identical local lists in .debug_loc
24545 /* Iteratively hash operands of LOC opcode. */
24547 static inline hashval_t
24548 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
24550 dw_val_ref val1 = &loc->dw_loc_oprnd1;
24551 dw_val_ref val2 = &loc->dw_loc_oprnd2;
24553 switch (loc->dw_loc_opc)
24555 case DW_OP_const4u:
24556 case DW_OP_const8u:
24560 case DW_OP_const1u:
24561 case DW_OP_const1s:
24562 case DW_OP_const2u:
24563 case DW_OP_const2s:
24564 case DW_OP_const4s:
24565 case DW_OP_const8s:
24569 case DW_OP_plus_uconst:
24605 case DW_OP_deref_size:
24606 case DW_OP_xderef_size:
24607 hash = iterative_hash_object (val1->v.val_int, hash);
24614 gcc_assert (val1->val_class == dw_val_class_loc);
24615 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
24616 hash = iterative_hash_object (offset, hash);
24619 case DW_OP_implicit_value:
24620 hash = iterative_hash_object (val1->v.val_unsigned, hash);
24621 switch (val2->val_class)
24623 case dw_val_class_const:
24624 hash = iterative_hash_object (val2->v.val_int, hash);
24626 case dw_val_class_vec:
24628 unsigned int elt_size = val2->v.val_vec.elt_size;
24629 unsigned int len = val2->v.val_vec.length;
24631 hash = iterative_hash_object (elt_size, hash);
24632 hash = iterative_hash_object (len, hash);
24633 hash = iterative_hash (val2->v.val_vec.array,
24634 len * elt_size, hash);
24637 case dw_val_class_const_double:
24638 hash = iterative_hash_object (val2->v.val_double.low, hash);
24639 hash = iterative_hash_object (val2->v.val_double.high, hash);
24641 case dw_val_class_addr:
24642 hash = iterative_hash_rtx (val2->v.val_addr, hash);
24645 gcc_unreachable ();
24649 case DW_OP_bit_piece:
24650 hash = iterative_hash_object (val1->v.val_int, hash);
24651 hash = iterative_hash_object (val2->v.val_int, hash);
24657 unsigned char dtprel = 0xd1;
24658 hash = iterative_hash_object (dtprel, hash);
24660 hash = iterative_hash_rtx (val1->v.val_addr, hash);
24662 case DW_OP_GNU_implicit_pointer:
24663 hash = iterative_hash_object (val2->v.val_int, hash);
24665 case DW_OP_GNU_entry_value:
24666 hash = hash_loc_operands (val1->v.val_loc, hash);
24668 case DW_OP_GNU_regval_type:
24669 case DW_OP_GNU_deref_type:
24671 unsigned int byte_size
24672 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
24673 unsigned int encoding
24674 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
24675 hash = iterative_hash_object (val1->v.val_int, hash);
24676 hash = iterative_hash_object (byte_size, hash);
24677 hash = iterative_hash_object (encoding, hash);
24680 case DW_OP_GNU_convert:
24681 case DW_OP_GNU_reinterpret:
24682 if (val1->val_class == dw_val_class_unsigned_const)
24684 hash = iterative_hash_object (val1->v.val_unsigned, hash);
24688 case DW_OP_GNU_const_type:
24690 unsigned int byte_size
24691 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
24692 unsigned int encoding
24693 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
24694 hash = iterative_hash_object (byte_size, hash);
24695 hash = iterative_hash_object (encoding, hash);
24696 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
24698 hash = iterative_hash_object (val2->val_class, hash);
24699 switch (val2->val_class)
24701 case dw_val_class_const:
24702 hash = iterative_hash_object (val2->v.val_int, hash);
24704 case dw_val_class_vec:
24706 unsigned int elt_size = val2->v.val_vec.elt_size;
24707 unsigned int len = val2->v.val_vec.length;
24709 hash = iterative_hash_object (elt_size, hash);
24710 hash = iterative_hash_object (len, hash);
24711 hash = iterative_hash (val2->v.val_vec.array,
24712 len * elt_size, hash);
24715 case dw_val_class_const_double:
24716 hash = iterative_hash_object (val2->v.val_double.low, hash);
24717 hash = iterative_hash_object (val2->v.val_double.high, hash);
24720 gcc_unreachable ();
24726 /* Other codes have no operands. */
24732 /* Iteratively hash the whole DWARF location expression LOC. */
24734 static inline hashval_t
24735 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
24737 dw_loc_descr_ref l;
24738 bool sizes_computed = false;
24739 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24740 size_of_locs (loc);
24742 for (l = loc; l != NULL; l = l->dw_loc_next)
24744 enum dwarf_location_atom opc = l->dw_loc_opc;
24745 hash = iterative_hash_object (opc, hash);
24746 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
24748 size_of_locs (loc);
24749 sizes_computed = true;
24751 hash = hash_loc_operands (l, hash);
24756 /* Compute hash of the whole location list LIST_HEAD. */
24759 hash_loc_list (dw_loc_list_ref list_head)
24761 dw_loc_list_ref curr = list_head;
24762 hashval_t hash = 0;
24764 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
24766 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
24767 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
24769 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
24771 hash = hash_locs (curr->expr, hash);
24773 list_head->hash = hash;
24776 /* Return true if X and Y opcodes have the same operands. */
24779 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
24781 dw_val_ref valx1 = &x->dw_loc_oprnd1;
24782 dw_val_ref valx2 = &x->dw_loc_oprnd2;
24783 dw_val_ref valy1 = &y->dw_loc_oprnd1;
24784 dw_val_ref valy2 = &y->dw_loc_oprnd2;
24786 switch (x->dw_loc_opc)
24788 case DW_OP_const4u:
24789 case DW_OP_const8u:
24793 case DW_OP_const1u:
24794 case DW_OP_const1s:
24795 case DW_OP_const2u:
24796 case DW_OP_const2s:
24797 case DW_OP_const4s:
24798 case DW_OP_const8s:
24802 case DW_OP_plus_uconst:
24838 case DW_OP_deref_size:
24839 case DW_OP_xderef_size:
24840 return valx1->v.val_int == valy1->v.val_int;
24843 gcc_assert (valx1->val_class == dw_val_class_loc
24844 && valy1->val_class == dw_val_class_loc
24845 && x->dw_loc_addr == y->dw_loc_addr);
24846 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
24847 case DW_OP_implicit_value:
24848 if (valx1->v.val_unsigned != valy1->v.val_unsigned
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;
24864 case dw_val_class_addr:
24865 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
24867 gcc_unreachable ();
24870 case DW_OP_bit_piece:
24871 return valx1->v.val_int == valy1->v.val_int
24872 && valx2->v.val_int == valy2->v.val_int;
24875 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
24876 case DW_OP_GNU_implicit_pointer:
24877 return valx1->val_class == dw_val_class_die_ref
24878 && valx1->val_class == valy1->val_class
24879 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
24880 && valx2->v.val_int == valy2->v.val_int;
24881 case DW_OP_GNU_entry_value:
24882 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
24883 case DW_OP_GNU_const_type:
24884 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
24885 || valx2->val_class != valy2->val_class)
24887 switch (valx2->val_class)
24889 case dw_val_class_const:
24890 return valx2->v.val_int == valy2->v.val_int;
24891 case dw_val_class_vec:
24892 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24893 && valx2->v.val_vec.length == valy2->v.val_vec.length
24894 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24895 valx2->v.val_vec.elt_size
24896 * valx2->v.val_vec.length) == 0;
24897 case dw_val_class_const_double:
24898 return valx2->v.val_double.low == valy2->v.val_double.low
24899 && valx2->v.val_double.high == valy2->v.val_double.high;
24901 gcc_unreachable ();
24903 case DW_OP_GNU_regval_type:
24904 case DW_OP_GNU_deref_type:
24905 return valx1->v.val_int == valy1->v.val_int
24906 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
24907 case DW_OP_GNU_convert:
24908 case DW_OP_GNU_reinterpret:
24909 if (valx1->val_class != valy1->val_class)
24911 if (valx1->val_class == dw_val_class_unsigned_const)
24912 return valx1->v.val_unsigned == valy1->v.val_unsigned;
24913 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
24914 case DW_OP_GNU_parameter_ref:
24915 return valx1->val_class == dw_val_class_die_ref
24916 && valx1->val_class == valy1->val_class
24917 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
24919 /* Other codes have no operands. */
24924 /* Return true if DWARF location expressions X and Y are the same. */
24927 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
24929 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
24930 if (x->dw_loc_opc != y->dw_loc_opc
24931 || x->dtprel != y->dtprel
24932 || !compare_loc_operands (x, y))
24934 return x == NULL && y == NULL;
24937 /* Return precomputed hash of location list X. */
24940 loc_list_hash (const void *x)
24942 return ((const struct dw_loc_list_struct *) x)->hash;
24945 /* Return 1 if location lists X and Y are the same. */
24948 loc_list_eq (const void *x, const void *y)
24950 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
24951 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
24954 if (a->hash != b->hash)
24956 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
24957 if (strcmp (a->begin, b->begin) != 0
24958 || strcmp (a->end, b->end) != 0
24959 || (a->section == NULL) != (b->section == NULL)
24960 || (a->section && strcmp (a->section, b->section) != 0)
24961 || !compare_locs (a->expr, b->expr))
24963 return a == NULL && b == NULL;
24966 /* Recursively optimize location lists referenced from DIE
24967 children and share them whenever possible. */
24970 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
24977 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
24978 if (AT_class (a) == dw_val_class_loc_list)
24980 dw_loc_list_ref list = AT_loc_list (a);
24981 /* TODO: perform some optimizations here, before hashing
24982 it and storing into the hash table. */
24983 hash_loc_list (list);
24984 slot = htab_find_slot_with_hash (htab, list, list->hash,
24987 *slot = (void *) list;
24989 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
24992 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
24995 /* Optimize location lists referenced from DIE
24996 children and share them whenever possible. */
24999 optimize_location_lists (dw_die_ref die)
25001 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
25002 optimize_location_lists_1 (die, htab);
25003 htab_delete (htab);
25006 /* Output stuff that dwarf requires at the end of every file,
25007 and generate the DWARF-2 debugging info. */
25010 dwarf2out_finish (const char *filename)
25012 limbo_die_node *node, *next_node;
25013 comdat_type_node *ctnode;
25014 htab_t comdat_type_table;
25017 gen_scheduled_generic_parms_dies ();
25018 gen_remaining_tmpl_value_param_die_attribute ();
25020 /* Add the name for the main input file now. We delayed this from
25021 dwarf2out_init to avoid complications with PCH. */
25022 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
25023 if (!IS_ABSOLUTE_PATH (filename))
25024 add_comp_dir_attribute (comp_unit_die ());
25025 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
25028 htab_traverse (file_table, file_table_relative_p, &p);
25030 add_comp_dir_attribute (comp_unit_die ());
25033 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
25035 add_location_or_const_value_attribute (
25036 VEC_index (deferred_locations, deferred_locations_list, i)->die,
25037 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
25042 /* Traverse the limbo die list, and add parent/child links. The only
25043 dies without parents that should be here are concrete instances of
25044 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
25045 For concrete instances, we can get the parent die from the abstract
25047 for (node = limbo_die_list; node; node = next_node)
25049 dw_die_ref die = node->die;
25050 next_node = node->next;
25052 if (die->die_parent == NULL)
25054 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
25056 if (origin && origin->die_parent)
25057 add_child_die (origin->die_parent, die);
25058 else if (is_cu_die (die))
25060 else if (seen_error ())
25061 /* It's OK to be confused by errors in the input. */
25062 add_child_die (comp_unit_die (), die);
25065 /* In certain situations, the lexical block containing a
25066 nested function can be optimized away, which results
25067 in the nested function die being orphaned. Likewise
25068 with the return type of that nested function. Force
25069 this to be a child of the containing function.
25071 It may happen that even the containing function got fully
25072 inlined and optimized out. In that case we are lost and
25073 assign the empty child. This should not be big issue as
25074 the function is likely unreachable too. */
25075 tree context = NULL_TREE;
25077 gcc_assert (node->created_for);
25079 if (DECL_P (node->created_for))
25080 context = DECL_CONTEXT (node->created_for);
25081 else if (TYPE_P (node->created_for))
25082 context = TYPE_CONTEXT (node->created_for);
25084 gcc_assert (context
25085 && (TREE_CODE (context) == FUNCTION_DECL
25086 || TREE_CODE (context) == NAMESPACE_DECL));
25088 origin = lookup_decl_die (context);
25090 add_child_die (origin, die);
25092 add_child_die (comp_unit_die (), die);
25097 limbo_die_list = NULL;
25099 #if ENABLE_ASSERT_CHECKING
25101 dw_die_ref die = comp_unit_die (), c;
25102 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
25105 resolve_addr (comp_unit_die ());
25106 move_marked_base_types ();
25108 for (node = deferred_asm_name; node; node = node->next)
25110 tree decl = node->created_for;
25111 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
25113 add_linkage_attr (node->die, decl);
25114 move_linkage_attr (node->die);
25118 deferred_asm_name = NULL;
25120 /* Walk through the list of incomplete types again, trying once more to
25121 emit full debugging info for them. */
25122 retry_incomplete_types ();
25124 if (flag_eliminate_unused_debug_types)
25125 prune_unused_types ();
25127 /* Generate separate CUs for each of the include files we've seen.
25128 They will go into limbo_die_list. */
25129 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
25130 break_out_includes (comp_unit_die ());
25132 /* Generate separate COMDAT sections for type DIEs. */
25133 if (use_debug_types)
25135 break_out_comdat_types (comp_unit_die ());
25137 /* Each new type_unit DIE was added to the limbo die list when created.
25138 Since these have all been added to comdat_type_list, clear the
25140 limbo_die_list = NULL;
25142 /* For each new comdat type unit, copy declarations for incomplete
25143 types to make the new unit self-contained (i.e., no direct
25144 references to the main compile unit). */
25145 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25146 copy_decls_for_unworthy_types (ctnode->root_die);
25147 copy_decls_for_unworthy_types (comp_unit_die ());
25149 /* In the process of copying declarations from one unit to another,
25150 we may have left some declarations behind that are no longer
25151 referenced. Prune them. */
25152 prune_unused_types ();
25155 /* Traverse the DIE's and add add sibling attributes to those DIE's
25156 that have children. */
25157 add_sibling_attributes (comp_unit_die ());
25158 for (node = limbo_die_list; node; node = node->next)
25159 add_sibling_attributes (node->die);
25160 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25161 add_sibling_attributes (ctnode->root_die);
25163 /* Output a terminator label for the .text section. */
25164 switch_to_section (text_section);
25165 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
25166 if (cold_text_section)
25168 switch_to_section (cold_text_section);
25169 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
25172 /* We can only use the low/high_pc attributes if all of the code was
25174 if (!have_multiple_function_sections
25175 || (dwarf_version < 3 && dwarf_strict))
25177 /* Don't add if the CU has no associated code. */
25178 if (text_section_used)
25180 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
25181 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
25186 unsigned fde_idx = 0;
25187 bool range_list_added = false;
25189 if (text_section_used)
25190 add_ranges_by_labels (comp_unit_die (), text_section_label,
25191 text_end_label, &range_list_added);
25192 if (cold_text_section_used)
25193 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
25194 cold_end_label, &range_list_added);
25196 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
25198 dw_fde_ref fde = &fde_table[fde_idx];
25200 if (!fde->in_std_section)
25201 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
25202 fde->dw_fde_end, &range_list_added);
25203 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
25204 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
25205 fde->dw_fde_second_end, &range_list_added);
25208 if (range_list_added)
25210 /* We need to give .debug_loc and .debug_ranges an appropriate
25211 "base address". Use zero so that these addresses become
25212 absolute. Historically, we've emitted the unexpected
25213 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25214 Emit both to give time for other tools to adapt. */
25215 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
25216 if (! dwarf_strict && dwarf_version < 4)
25217 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
25223 if (debug_info_level >= DINFO_LEVEL_NORMAL)
25224 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
25225 debug_line_section_label);
25227 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
25228 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
25230 if (have_location_lists)
25231 optimize_location_lists (comp_unit_die ());
25233 /* Output all of the compilation units. We put the main one last so that
25234 the offsets are available to output_pubnames. */
25235 for (node = limbo_die_list; node; node = node->next)
25236 output_comp_unit (node->die, 0);
25238 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
25239 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25241 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
25243 /* Don't output duplicate types. */
25244 if (*slot != HTAB_EMPTY_ENTRY)
25247 /* Add a pointer to the line table for the main compilation unit
25248 so that the debugger can make sense of DW_AT_decl_file
25250 if (debug_info_level >= DINFO_LEVEL_NORMAL)
25251 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
25252 debug_line_section_label);
25254 output_comdat_type_unit (ctnode);
25257 htab_delete (comdat_type_table);
25259 /* Output the main compilation unit if non-empty or if .debug_macinfo
25260 will be emitted. */
25261 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
25263 /* Output the abbreviation table. */
25264 if (abbrev_die_table_in_use != 1)
25266 switch_to_section (debug_abbrev_section);
25267 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
25268 output_abbrev_section ();
25271 /* Output location list section if necessary. */
25272 if (have_location_lists)
25274 /* Output the location lists info. */
25275 switch_to_section (debug_loc_section);
25276 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
25277 DEBUG_LOC_SECTION_LABEL, 0);
25278 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
25279 output_location_lists (comp_unit_die ());
25282 /* Output public names table if necessary. */
25283 if (!VEC_empty (pubname_entry, pubname_table))
25285 gcc_assert (info_section_emitted);
25286 switch_to_section (debug_pubnames_section);
25287 output_pubnames (pubname_table);
25290 /* Output public types table if necessary. */
25291 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
25292 It shouldn't hurt to emit it always, since pure DWARF2 consumers
25293 simply won't look for the section. */
25294 if (!VEC_empty (pubname_entry, pubtype_table))
25296 bool empty = false;
25298 if (flag_eliminate_unused_debug_types)
25300 /* The pubtypes table might be emptied by pruning unused items. */
25304 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
25305 if (p->die->die_offset != 0)
25313 gcc_assert (info_section_emitted);
25314 switch_to_section (debug_pubtypes_section);
25315 output_pubnames (pubtype_table);
25319 /* Output the address range information if a CU (.debug_info section)
25320 was emitted. We output an empty table even if we had no functions
25321 to put in it. This because the consumer has no way to tell the
25322 difference between an empty table that we omitted and failure to
25323 generate a table that would have contained data. */
25324 if (info_section_emitted)
25326 unsigned long aranges_length = size_of_aranges ();
25328 switch_to_section (debug_aranges_section);
25329 output_aranges (aranges_length);
25332 /* Output ranges section if necessary. */
25333 if (ranges_table_in_use)
25335 switch_to_section (debug_ranges_section);
25336 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
25340 /* Output the source line correspondence table. We must do this
25341 even if there is no line information. Otherwise, on an empty
25342 translation unit, we will generate a present, but empty,
25343 .debug_info section. IRIX 6.5 `nm' will then complain when
25344 examining the file. This is done late so that any filenames
25345 used by the debug_info section are marked as 'used'. */
25346 switch_to_section (debug_line_section);
25347 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
25348 if (! DWARF2_ASM_LINE_DEBUG_INFO)
25349 output_line_info ();
25351 /* Have to end the macro section. */
25352 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
25354 switch_to_section (debug_macinfo_section);
25355 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
25356 if (!VEC_empty (macinfo_entry, macinfo_table))
25358 dw2_asm_output_data (1, 0, "End compilation unit");
25361 /* If we emitted any DW_FORM_strp form attribute, output the string
25363 if (debug_str_hash)
25364 htab_traverse (debug_str_hash, output_indirect_string, NULL);
25367 #include "gt-dwarf2out.h"