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 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1236 This CFI tells the unwinder that it needs to restore the window registers
1237 from the previous frame's window save area.
1239 ??? Perhaps we should note in the CIE where windows are saved (instead of
1240 assuming 0(cfa)) and what registers are in the window. */
1243 dwarf2out_window_save (const char *label)
1245 dw_cfi_ref cfi = new_cfi ();
1247 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1248 add_fde_cfi (label, cfi);
1251 /* Entry point for saving a register to the stack. REG is the GCC register
1252 number. LABEL and OFFSET are passed to reg_save. */
1255 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1257 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1260 /* Entry point for saving the return address in the stack.
1261 LABEL and OFFSET are passed to reg_save. */
1264 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1266 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1269 /* Entry point for saving the return address in a register.
1270 LABEL and SREG are passed to reg_save. */
1273 dwarf2out_return_reg (const char *label, unsigned int sreg)
1275 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1278 /* Record the initial position of the return address. RTL is
1279 INCOMING_RETURN_ADDR_RTX. */
1282 initial_return_save (rtx rtl)
1284 unsigned int reg = INVALID_REGNUM;
1285 HOST_WIDE_INT offset = 0;
1287 switch (GET_CODE (rtl))
1290 /* RA is in a register. */
1291 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1295 /* RA is on the stack. */
1296 rtl = XEXP (rtl, 0);
1297 switch (GET_CODE (rtl))
1300 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1305 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1306 offset = INTVAL (XEXP (rtl, 1));
1310 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1311 offset = -INTVAL (XEXP (rtl, 1));
1321 /* The return address is at some offset from any value we can
1322 actually load. For instance, on the SPARC it is in %i7+8. Just
1323 ignore the offset for now; it doesn't matter for unwinding frames. */
1324 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1325 initial_return_save (XEXP (rtl, 0));
1332 if (reg != DWARF_FRAME_RETURN_COLUMN)
1333 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1336 /* Given a SET, calculate the amount of stack adjustment it
1339 static HOST_WIDE_INT
1340 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1341 HOST_WIDE_INT cur_offset)
1343 const_rtx src = SET_SRC (pattern);
1344 const_rtx dest = SET_DEST (pattern);
1345 HOST_WIDE_INT offset = 0;
1348 if (dest == stack_pointer_rtx)
1350 code = GET_CODE (src);
1352 /* Assume (set (reg sp) (reg whatever)) sets args_size
1354 if (code == REG && src != stack_pointer_rtx)
1356 offset = -cur_args_size;
1357 #ifndef STACK_GROWS_DOWNWARD
1360 return offset - cur_offset;
1363 if (! (code == PLUS || code == MINUS)
1364 || XEXP (src, 0) != stack_pointer_rtx
1365 || !CONST_INT_P (XEXP (src, 1)))
1368 /* (set (reg sp) (plus (reg sp) (const_int))) */
1369 offset = INTVAL (XEXP (src, 1));
1375 if (MEM_P (src) && !MEM_P (dest))
1379 /* (set (mem (pre_dec (reg sp))) (foo)) */
1380 src = XEXP (dest, 0);
1381 code = GET_CODE (src);
1387 if (XEXP (src, 0) == stack_pointer_rtx)
1389 rtx val = XEXP (XEXP (src, 1), 1);
1390 /* We handle only adjustments by constant amount. */
1391 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1392 && CONST_INT_P (val));
1393 offset = -INTVAL (val);
1400 if (XEXP (src, 0) == stack_pointer_rtx)
1402 offset = GET_MODE_SIZE (GET_MODE (dest));
1409 if (XEXP (src, 0) == stack_pointer_rtx)
1411 offset = -GET_MODE_SIZE (GET_MODE (dest));
1426 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1427 indexed by INSN_UID. */
1429 static HOST_WIDE_INT *barrier_args_size;
1431 /* Helper function for compute_barrier_args_size. Handle one insn. */
1433 static HOST_WIDE_INT
1434 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1435 VEC (rtx, heap) **next)
1437 HOST_WIDE_INT offset = 0;
1440 if (! RTX_FRAME_RELATED_P (insn))
1442 if (prologue_epilogue_contains (insn))
1444 else if (GET_CODE (PATTERN (insn)) == SET)
1445 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1446 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1447 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1449 /* There may be stack adjustments inside compound insns. Search
1451 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1452 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1453 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1454 cur_args_size, offset);
1459 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1463 expr = XEXP (expr, 0);
1464 if (GET_CODE (expr) == PARALLEL
1465 || GET_CODE (expr) == SEQUENCE)
1466 for (i = 1; i < XVECLEN (expr, 0); i++)
1468 rtx elem = XVECEXP (expr, 0, i);
1470 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1471 offset += stack_adjust_offset (elem, cur_args_size, offset);
1476 #ifndef STACK_GROWS_DOWNWARD
1480 cur_args_size += offset;
1481 if (cur_args_size < 0)
1486 rtx dest = JUMP_LABEL (insn);
1490 if (barrier_args_size [INSN_UID (dest)] < 0)
1492 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1493 VEC_safe_push (rtx, heap, *next, dest);
1498 return cur_args_size;
1501 /* Walk the whole function and compute args_size on BARRIERs. */
1504 compute_barrier_args_size (void)
1506 int max_uid = get_max_uid (), i;
1508 VEC (rtx, heap) *worklist, *next, *tmp;
1510 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1511 for (i = 0; i < max_uid; i++)
1512 barrier_args_size[i] = -1;
1514 worklist = VEC_alloc (rtx, heap, 20);
1515 next = VEC_alloc (rtx, heap, 20);
1516 insn = get_insns ();
1517 barrier_args_size[INSN_UID (insn)] = 0;
1518 VEC_quick_push (rtx, worklist, insn);
1521 while (!VEC_empty (rtx, worklist))
1523 rtx prev, body, first_insn;
1524 HOST_WIDE_INT cur_args_size;
1526 first_insn = insn = VEC_pop (rtx, worklist);
1527 cur_args_size = barrier_args_size[INSN_UID (insn)];
1528 prev = prev_nonnote_insn (insn);
1529 if (prev && BARRIER_P (prev))
1530 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1532 for (; insn; insn = NEXT_INSN (insn))
1534 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1536 if (BARRIER_P (insn))
1541 if (insn == first_insn)
1543 else if (barrier_args_size[INSN_UID (insn)] < 0)
1545 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1550 /* The insns starting with this label have been
1551 already scanned or are in the worklist. */
1556 body = PATTERN (insn);
1557 if (GET_CODE (body) == SEQUENCE)
1559 HOST_WIDE_INT dest_args_size = cur_args_size;
1560 for (i = 1; i < XVECLEN (body, 0); i++)
1561 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1562 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1564 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1565 dest_args_size, &next);
1568 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1569 cur_args_size, &next);
1571 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1572 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1573 dest_args_size, &next);
1576 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1577 cur_args_size, &next);
1581 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1585 if (VEC_empty (rtx, next))
1588 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1592 VEC_truncate (rtx, next, 0);
1595 VEC_free (rtx, heap, worklist);
1596 VEC_free (rtx, heap, next);
1599 /* Add a CFI to update the running total of the size of arguments
1600 pushed onto the stack. */
1603 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1607 if (size == old_args_size)
1610 old_args_size = size;
1613 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1614 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1615 add_fde_cfi (label, cfi);
1618 /* Record a stack adjustment of OFFSET bytes. */
1621 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1623 if (cfa.reg == STACK_POINTER_REGNUM)
1624 cfa.offset += offset;
1626 if (cfa_store.reg == STACK_POINTER_REGNUM)
1627 cfa_store.offset += offset;
1629 if (ACCUMULATE_OUTGOING_ARGS)
1632 #ifndef STACK_GROWS_DOWNWARD
1636 args_size += offset;
1640 def_cfa_1 (label, &cfa);
1641 if (flag_asynchronous_unwind_tables)
1642 dwarf2out_args_size (label, args_size);
1645 /* Check INSN to see if it looks like a push or a stack adjustment, and
1646 make a note of it if it does. EH uses this information to find out
1647 how much extra space it needs to pop off the stack. */
1650 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1652 HOST_WIDE_INT offset;
1656 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1657 with this function. Proper support would require all frame-related
1658 insns to be marked, and to be able to handle saving state around
1659 epilogues textually in the middle of the function. */
1660 if (prologue_epilogue_contains (insn))
1663 /* If INSN is an instruction from target of an annulled branch, the
1664 effects are for the target only and so current argument size
1665 shouldn't change at all. */
1667 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1668 && INSN_FROM_TARGET_P (insn))
1671 /* If only calls can throw, and we have a frame pointer,
1672 save up adjustments until we see the CALL_INSN. */
1673 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1675 if (CALL_P (insn) && !after_p)
1677 /* Extract the size of the args from the CALL rtx itself. */
1678 insn = PATTERN (insn);
1679 if (GET_CODE (insn) == PARALLEL)
1680 insn = XVECEXP (insn, 0, 0);
1681 if (GET_CODE (insn) == SET)
1682 insn = SET_SRC (insn);
1683 gcc_assert (GET_CODE (insn) == CALL);
1684 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1689 if (CALL_P (insn) && !after_p)
1691 if (!flag_asynchronous_unwind_tables)
1692 dwarf2out_args_size ("", args_size);
1695 else if (BARRIER_P (insn))
1697 /* Don't call compute_barrier_args_size () if the only
1698 BARRIER is at the end of function. */
1699 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1700 compute_barrier_args_size ();
1701 if (barrier_args_size == NULL)
1705 offset = barrier_args_size[INSN_UID (insn)];
1710 offset -= args_size;
1711 #ifndef STACK_GROWS_DOWNWARD
1715 else if (GET_CODE (PATTERN (insn)) == SET)
1716 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1717 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1718 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1720 /* There may be stack adjustments inside compound insns. Search
1722 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1723 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1724 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1733 label = dwarf2out_cfi_label (false);
1734 dwarf2out_stack_adjust (offset, label);
1737 /* We delay emitting a register save until either (a) we reach the end
1738 of the prologue or (b) the register is clobbered. This clusters
1739 register saves so that there are fewer pc advances. */
1741 struct GTY(()) queued_reg_save {
1742 struct queued_reg_save *next;
1744 HOST_WIDE_INT cfa_offset;
1748 static GTY(()) struct queued_reg_save *queued_reg_saves;
1750 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1751 struct GTY(()) reg_saved_in_data {
1756 /* A list of registers saved in other registers.
1757 The list intentionally has a small maximum capacity of 4; if your
1758 port needs more than that, you might consider implementing a
1759 more efficient data structure. */
1760 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1761 static GTY(()) size_t num_regs_saved_in_regs;
1763 static const char *last_reg_save_label;
1765 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1766 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1769 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1771 struct queued_reg_save *q;
1773 /* Duplicates waste space, but it's also necessary to remove them
1774 for correctness, since the queue gets output in reverse
1776 for (q = queued_reg_saves; q != NULL; q = q->next)
1777 if (REGNO (q->reg) == REGNO (reg))
1782 q = ggc_alloc_queued_reg_save ();
1783 q->next = queued_reg_saves;
1784 queued_reg_saves = q;
1788 q->cfa_offset = offset;
1789 q->saved_reg = sreg;
1791 last_reg_save_label = label;
1794 /* Output all the entries in QUEUED_REG_SAVES. */
1797 dwarf2out_flush_queued_reg_saves (void)
1799 struct queued_reg_save *q;
1801 for (q = queued_reg_saves; q; q = q->next)
1804 unsigned int reg, sreg;
1806 for (i = 0; i < num_regs_saved_in_regs; i++)
1807 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1809 if (q->saved_reg && i == num_regs_saved_in_regs)
1811 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1812 num_regs_saved_in_regs++;
1814 if (i != num_regs_saved_in_regs)
1816 regs_saved_in_regs[i].orig_reg = q->reg;
1817 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1820 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1822 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1824 sreg = INVALID_REGNUM;
1825 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1828 queued_reg_saves = NULL;
1829 last_reg_save_label = NULL;
1832 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1833 location for? Or, does it clobber a register which we've previously
1834 said that some other register is saved in, and for which we now
1835 have a new location for? */
1838 clobbers_queued_reg_save (const_rtx insn)
1840 struct queued_reg_save *q;
1842 for (q = queued_reg_saves; q; q = q->next)
1845 if (modified_in_p (q->reg, insn))
1847 for (i = 0; i < num_regs_saved_in_regs; i++)
1848 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1849 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1856 /* Entry point for saving the first register into the second. */
1859 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1862 unsigned int regno, sregno;
1864 for (i = 0; i < num_regs_saved_in_regs; i++)
1865 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1867 if (i == num_regs_saved_in_regs)
1869 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1870 num_regs_saved_in_regs++;
1872 regs_saved_in_regs[i].orig_reg = reg;
1873 regs_saved_in_regs[i].saved_in_reg = sreg;
1875 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1876 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1877 reg_save (label, regno, sregno, 0);
1880 /* What register, if any, is currently saved in REG? */
1883 reg_saved_in (rtx reg)
1885 unsigned int regn = REGNO (reg);
1887 struct queued_reg_save *q;
1889 for (q = queued_reg_saves; q; q = q->next)
1890 if (q->saved_reg && regn == REGNO (q->saved_reg))
1893 for (i = 0; i < num_regs_saved_in_regs; i++)
1894 if (regs_saved_in_regs[i].saved_in_reg
1895 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1896 return regs_saved_in_regs[i].orig_reg;
1902 /* A temporary register holding an integral value used in adjusting SP
1903 or setting up the store_reg. The "offset" field holds the integer
1904 value, not an offset. */
1905 static dw_cfa_location cfa_temp;
1907 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1910 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1912 memset (&cfa, 0, sizeof (cfa));
1914 switch (GET_CODE (pat))
1917 cfa.reg = REGNO (XEXP (pat, 0));
1918 cfa.offset = INTVAL (XEXP (pat, 1));
1922 cfa.reg = REGNO (pat);
1927 pat = XEXP (pat, 0);
1928 if (GET_CODE (pat) == PLUS)
1930 cfa.base_offset = INTVAL (XEXP (pat, 1));
1931 pat = XEXP (pat, 0);
1933 cfa.reg = REGNO (pat);
1937 /* Recurse and define an expression. */
1941 def_cfa_1 (label, &cfa);
1944 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1947 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1951 gcc_assert (GET_CODE (pat) == SET);
1952 dest = XEXP (pat, 0);
1953 src = XEXP (pat, 1);
1955 switch (GET_CODE (src))
1958 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1959 cfa.offset -= INTVAL (XEXP (src, 1));
1969 cfa.reg = REGNO (dest);
1970 gcc_assert (cfa.indirect == 0);
1972 def_cfa_1 (label, &cfa);
1975 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1978 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1980 HOST_WIDE_INT offset;
1981 rtx src, addr, span;
1983 src = XEXP (set, 1);
1984 addr = XEXP (set, 0);
1985 gcc_assert (MEM_P (addr));
1986 addr = XEXP (addr, 0);
1988 /* As documented, only consider extremely simple addresses. */
1989 switch (GET_CODE (addr))
1992 gcc_assert (REGNO (addr) == cfa.reg);
1993 offset = -cfa.offset;
1996 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1997 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2003 span = targetm.dwarf_register_span (src);
2005 /* ??? We'd like to use queue_reg_save, but we need to come up with
2006 a different flushing heuristic for epilogues. */
2008 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2011 /* We have a PARALLEL describing where the contents of SRC live.
2012 Queue register saves for each piece of the PARALLEL. */
2015 HOST_WIDE_INT span_offset = offset;
2017 gcc_assert (GET_CODE (span) == PARALLEL);
2019 limit = XVECLEN (span, 0);
2020 for (par_index = 0; par_index < limit; par_index++)
2022 rtx elem = XVECEXP (span, 0, par_index);
2024 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2025 INVALID_REGNUM, span_offset);
2026 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2031 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2034 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2037 unsigned sregno, dregno;
2039 src = XEXP (set, 1);
2040 dest = XEXP (set, 0);
2043 sregno = DWARF_FRAME_RETURN_COLUMN;
2045 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2047 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2049 /* ??? We'd like to use queue_reg_save, but we need to come up with
2050 a different flushing heuristic for epilogues. */
2051 reg_save (label, sregno, dregno, 0);
2054 /* Helper function to get mode of MEM's address. */
2056 static inline enum machine_mode
2057 get_address_mode (rtx mem)
2059 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
2060 if (mode != VOIDmode)
2062 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
2065 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2068 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2070 rtx src, dest, span;
2071 dw_cfi_ref cfi = new_cfi ();
2073 dest = SET_DEST (set);
2074 src = SET_SRC (set);
2076 gcc_assert (REG_P (src));
2077 gcc_assert (MEM_P (dest));
2079 span = targetm.dwarf_register_span (src);
2082 cfi->dw_cfi_opc = DW_CFA_expression;
2083 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2084 cfi->dw_cfi_oprnd2.dw_cfi_loc
2085 = mem_loc_descriptor (XEXP (dest, 0), get_address_mode (dest),
2086 GET_MODE (dest), VAR_INIT_STATUS_INITIALIZED);
2088 /* ??? We'd like to use queue_reg_save, were the interface different,
2089 and, as above, we could manage flushing for epilogues. */
2090 add_fde_cfi (label, cfi);
2093 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2096 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2098 dw_cfi_ref cfi = new_cfi ();
2099 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2101 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2102 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2104 add_fde_cfi (label, cfi);
2107 /* Record call frame debugging information for an expression EXPR,
2108 which either sets SP or FP (adjusting how we calculate the frame
2109 address) or saves a register to the stack or another register.
2110 LABEL indicates the address of EXPR.
2112 This function encodes a state machine mapping rtxes to actions on
2113 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2114 users need not read the source code.
2116 The High-Level Picture
2118 Changes in the register we use to calculate the CFA: Currently we
2119 assume that if you copy the CFA register into another register, we
2120 should take the other one as the new CFA register; this seems to
2121 work pretty well. If it's wrong for some target, it's simple
2122 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2124 Changes in the register we use for saving registers to the stack:
2125 This is usually SP, but not always. Again, we deduce that if you
2126 copy SP into another register (and SP is not the CFA register),
2127 then the new register is the one we will be using for register
2128 saves. This also seems to work.
2130 Register saves: There's not much guesswork about this one; if
2131 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2132 register save, and the register used to calculate the destination
2133 had better be the one we think we're using for this purpose.
2134 It's also assumed that a copy from a call-saved register to another
2135 register is saving that register if RTX_FRAME_RELATED_P is set on
2136 that instruction. If the copy is from a call-saved register to
2137 the *same* register, that means that the register is now the same
2138 value as in the caller.
2140 Except: If the register being saved is the CFA register, and the
2141 offset is nonzero, we are saving the CFA, so we assume we have to
2142 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2143 the intent is to save the value of SP from the previous frame.
2145 In addition, if a register has previously been saved to a different
2148 Invariants / Summaries of Rules
2150 cfa current rule for calculating the CFA. It usually
2151 consists of a register and an offset.
2152 cfa_store register used by prologue code to save things to the stack
2153 cfa_store.offset is the offset from the value of
2154 cfa_store.reg to the actual CFA
2155 cfa_temp register holding an integral value. cfa_temp.offset
2156 stores the value, which will be used to adjust the
2157 stack pointer. cfa_temp is also used like cfa_store,
2158 to track stores to the stack via fp or a temp reg.
2160 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2161 with cfa.reg as the first operand changes the cfa.reg and its
2162 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2165 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2166 expression yielding a constant. This sets cfa_temp.reg
2167 and cfa_temp.offset.
2169 Rule 5: Create a new register cfa_store used to save items to the
2172 Rules 10-14: Save a register to the stack. Define offset as the
2173 difference of the original location and cfa_store's
2174 location (or cfa_temp's location if cfa_temp is used).
2176 Rules 16-20: If AND operation happens on sp in prologue, we assume
2177 stack is realigned. We will use a group of DW_OP_XXX
2178 expressions to represent the location of the stored
2179 register instead of CFA+offset.
2183 "{a,b}" indicates a choice of a xor b.
2184 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2187 (set <reg1> <reg2>:cfa.reg)
2188 effects: cfa.reg = <reg1>
2189 cfa.offset unchanged
2190 cfa_temp.reg = <reg1>
2191 cfa_temp.offset = cfa.offset
2194 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2195 {<const_int>,<reg>:cfa_temp.reg}))
2196 effects: cfa.reg = sp if fp used
2197 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2198 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2199 if cfa_store.reg==sp
2202 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2203 effects: cfa.reg = fp
2204 cfa_offset += +/- <const_int>
2207 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2208 constraints: <reg1> != fp
2210 effects: cfa.reg = <reg1>
2211 cfa_temp.reg = <reg1>
2212 cfa_temp.offset = cfa.offset
2215 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2216 constraints: <reg1> != fp
2218 effects: cfa_store.reg = <reg1>
2219 cfa_store.offset = cfa.offset - cfa_temp.offset
2222 (set <reg> <const_int>)
2223 effects: cfa_temp.reg = <reg>
2224 cfa_temp.offset = <const_int>
2227 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2228 effects: cfa_temp.reg = <reg1>
2229 cfa_temp.offset |= <const_int>
2232 (set <reg> (high <exp>))
2236 (set <reg> (lo_sum <exp> <const_int>))
2237 effects: cfa_temp.reg = <reg>
2238 cfa_temp.offset = <const_int>
2241 (set (mem ({pre,post}_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2242 effects: cfa_store.offset -= <const_int>
2243 cfa.offset = cfa_store.offset if cfa.reg == sp
2245 cfa.base_offset = -cfa_store.offset
2248 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2249 effects: cfa_store.offset += -/+ mode_size(mem)
2250 cfa.offset = cfa_store.offset if cfa.reg == sp
2252 cfa.base_offset = -cfa_store.offset
2255 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2258 effects: cfa.reg = <reg1>
2259 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2262 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2263 effects: cfa.reg = <reg1>
2264 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2267 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2268 effects: cfa.reg = <reg1>
2269 cfa.base_offset = -cfa_temp.offset
2270 cfa_temp.offset -= mode_size(mem)
2273 (set <reg> {unspec, unspec_volatile})
2274 effects: target-dependent
2277 (set sp (and: sp <const_int>))
2278 constraints: cfa_store.reg == sp
2279 effects: current_fde.stack_realign = 1
2280 cfa_store.offset = 0
2281 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2284 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2285 effects: cfa_store.offset += -/+ mode_size(mem)
2288 (set (mem ({pre_inc, pre_dec} sp)) fp)
2289 constraints: fde->stack_realign == 1
2290 effects: cfa_store.offset = 0
2291 cfa.reg != HARD_FRAME_POINTER_REGNUM
2294 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2295 constraints: fde->stack_realign == 1
2297 && cfa.indirect == 0
2298 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2299 effects: Use DW_CFA_def_cfa_expression to define cfa
2300 cfa.reg == fde->drap_reg */
2303 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2305 rtx src, dest, span;
2306 HOST_WIDE_INT offset;
2309 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2310 the PARALLEL independently. The first element is always processed if
2311 it is a SET. This is for backward compatibility. Other elements
2312 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2313 flag is set in them. */
2314 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2317 int limit = XVECLEN (expr, 0);
2320 /* PARALLELs have strict read-modify-write semantics, so we
2321 ought to evaluate every rvalue before changing any lvalue.
2322 It's cumbersome to do that in general, but there's an
2323 easy approximation that is enough for all current users:
2324 handle register saves before register assignments. */
2325 if (GET_CODE (expr) == PARALLEL)
2326 for (par_index = 0; par_index < limit; par_index++)
2328 elem = XVECEXP (expr, 0, par_index);
2329 if (GET_CODE (elem) == SET
2330 && MEM_P (SET_DEST (elem))
2331 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2332 dwarf2out_frame_debug_expr (elem, label);
2335 for (par_index = 0; par_index < limit; par_index++)
2337 elem = XVECEXP (expr, 0, par_index);
2338 if (GET_CODE (elem) == SET
2339 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2340 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2341 dwarf2out_frame_debug_expr (elem, label);
2342 else if (GET_CODE (elem) == SET
2344 && !RTX_FRAME_RELATED_P (elem))
2346 /* Stack adjustment combining might combine some post-prologue
2347 stack adjustment into a prologue stack adjustment. */
2348 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2351 dwarf2out_stack_adjust (offset, label);
2357 gcc_assert (GET_CODE (expr) == SET);
2359 src = SET_SRC (expr);
2360 dest = SET_DEST (expr);
2364 rtx rsi = reg_saved_in (src);
2369 fde = current_fde ();
2371 switch (GET_CODE (dest))
2374 switch (GET_CODE (src))
2376 /* Setting FP from SP. */
2378 if (cfa.reg == (unsigned) REGNO (src))
2381 /* Update the CFA rule wrt SP or FP. Make sure src is
2382 relative to the current CFA register.
2384 We used to require that dest be either SP or FP, but the
2385 ARM copies SP to a temporary register, and from there to
2386 FP. So we just rely on the backends to only set
2387 RTX_FRAME_RELATED_P on appropriate insns. */
2388 cfa.reg = REGNO (dest);
2389 cfa_temp.reg = cfa.reg;
2390 cfa_temp.offset = cfa.offset;
2394 /* Saving a register in a register. */
2395 gcc_assert (!fixed_regs [REGNO (dest)]
2396 /* For the SPARC and its register window. */
2397 || (DWARF_FRAME_REGNUM (REGNO (src))
2398 == DWARF_FRAME_RETURN_COLUMN));
2400 /* After stack is aligned, we can only save SP in FP
2401 if drap register is used. In this case, we have
2402 to restore stack pointer with the CFA value and we
2403 don't generate this DWARF information. */
2405 && fde->stack_realign
2406 && REGNO (src) == STACK_POINTER_REGNUM)
2407 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2408 && fde->drap_reg != INVALID_REGNUM
2409 && cfa.reg != REGNO (src));
2411 queue_reg_save (label, src, dest, 0);
2418 if (dest == stack_pointer_rtx)
2422 switch (GET_CODE (XEXP (src, 1)))
2425 offset = INTVAL (XEXP (src, 1));
2428 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2430 offset = cfa_temp.offset;
2436 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2438 /* Restoring SP from FP in the epilogue. */
2439 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2440 cfa.reg = STACK_POINTER_REGNUM;
2442 else if (GET_CODE (src) == LO_SUM)
2443 /* Assume we've set the source reg of the LO_SUM from sp. */
2446 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2448 if (GET_CODE (src) != MINUS)
2450 if (cfa.reg == STACK_POINTER_REGNUM)
2451 cfa.offset += offset;
2452 if (cfa_store.reg == STACK_POINTER_REGNUM)
2453 cfa_store.offset += offset;
2455 else if (dest == hard_frame_pointer_rtx)
2458 /* Either setting the FP from an offset of the SP,
2459 or adjusting the FP */
2460 gcc_assert (frame_pointer_needed);
2462 gcc_assert (REG_P (XEXP (src, 0))
2463 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2464 && CONST_INT_P (XEXP (src, 1)));
2465 offset = INTVAL (XEXP (src, 1));
2466 if (GET_CODE (src) != MINUS)
2468 cfa.offset += offset;
2469 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2473 gcc_assert (GET_CODE (src) != MINUS);
2476 if (REG_P (XEXP (src, 0))
2477 && REGNO (XEXP (src, 0)) == cfa.reg
2478 && CONST_INT_P (XEXP (src, 1)))
2480 /* Setting a temporary CFA register that will be copied
2481 into the FP later on. */
2482 offset = - INTVAL (XEXP (src, 1));
2483 cfa.offset += offset;
2484 cfa.reg = REGNO (dest);
2485 /* Or used to save regs to the stack. */
2486 cfa_temp.reg = cfa.reg;
2487 cfa_temp.offset = cfa.offset;
2491 else if (REG_P (XEXP (src, 0))
2492 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2493 && XEXP (src, 1) == stack_pointer_rtx)
2495 /* Setting a scratch register that we will use instead
2496 of SP for saving registers to the stack. */
2497 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2498 cfa_store.reg = REGNO (dest);
2499 cfa_store.offset = cfa.offset - cfa_temp.offset;
2503 else if (GET_CODE (src) == LO_SUM
2504 && CONST_INT_P (XEXP (src, 1)))
2506 cfa_temp.reg = REGNO (dest);
2507 cfa_temp.offset = INTVAL (XEXP (src, 1));
2516 cfa_temp.reg = REGNO (dest);
2517 cfa_temp.offset = INTVAL (src);
2522 gcc_assert (REG_P (XEXP (src, 0))
2523 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2524 && CONST_INT_P (XEXP (src, 1)));
2526 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2527 cfa_temp.reg = REGNO (dest);
2528 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2531 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2532 which will fill in all of the bits. */
2539 case UNSPEC_VOLATILE:
2540 gcc_assert (targetm.dwarf_handle_frame_unspec);
2541 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2546 /* If this AND operation happens on stack pointer in prologue,
2547 we assume the stack is realigned and we extract the
2549 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2551 /* We interpret reg_save differently with stack_realign set.
2552 Thus we must flush whatever we have queued first. */
2553 dwarf2out_flush_queued_reg_saves ();
2555 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2556 fde->stack_realign = 1;
2557 fde->stack_realignment = INTVAL (XEXP (src, 1));
2558 cfa_store.offset = 0;
2560 if (cfa.reg != STACK_POINTER_REGNUM
2561 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2562 fde->drap_reg = cfa.reg;
2570 def_cfa_1 (label, &cfa);
2575 /* Saving a register to the stack. Make sure dest is relative to the
2577 switch (GET_CODE (XEXP (dest, 0)))
2583 /* We can't handle variable size modifications. */
2584 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2586 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2588 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2589 && cfa_store.reg == STACK_POINTER_REGNUM);
2591 cfa_store.offset += offset;
2592 if (cfa.reg == STACK_POINTER_REGNUM)
2593 cfa.offset = cfa_store.offset;
2595 if (GET_CODE (XEXP (dest, 0)) == POST_MODIFY)
2596 offset -= cfa_store.offset;
2598 offset = -cfa_store.offset;
2605 offset = GET_MODE_SIZE (GET_MODE (dest));
2606 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2609 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2610 == STACK_POINTER_REGNUM)
2611 && cfa_store.reg == STACK_POINTER_REGNUM);
2613 cfa_store.offset += offset;
2615 /* Rule 18: If stack is aligned, we will use FP as a
2616 reference to represent the address of the stored
2619 && fde->stack_realign
2620 && src == hard_frame_pointer_rtx)
2622 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2623 cfa_store.offset = 0;
2626 if (cfa.reg == STACK_POINTER_REGNUM)
2627 cfa.offset = cfa_store.offset;
2629 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
2630 offset += -cfa_store.offset;
2632 offset = -cfa_store.offset;
2636 /* With an offset. */
2643 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2644 && REG_P (XEXP (XEXP (dest, 0), 0)));
2645 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2646 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2649 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2651 if (cfa.reg == (unsigned) regno)
2652 offset -= cfa.offset;
2653 else if (cfa_store.reg == (unsigned) regno)
2654 offset -= cfa_store.offset;
2657 gcc_assert (cfa_temp.reg == (unsigned) regno);
2658 offset -= cfa_temp.offset;
2664 /* Without an offset. */
2667 int regno = REGNO (XEXP (dest, 0));
2669 if (cfa.reg == (unsigned) regno)
2670 offset = -cfa.offset;
2671 else if (cfa_store.reg == (unsigned) regno)
2672 offset = -cfa_store.offset;
2675 gcc_assert (cfa_temp.reg == (unsigned) regno);
2676 offset = -cfa_temp.offset;
2683 gcc_assert (cfa_temp.reg
2684 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2685 offset = -cfa_temp.offset;
2686 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2694 /* If the source operand of this MEM operation is not a
2695 register, basically the source is return address. Here
2696 we only care how much stack grew and we don't save it. */
2700 if (REGNO (src) != STACK_POINTER_REGNUM
2701 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2702 && (unsigned) REGNO (src) == cfa.reg)
2704 /* We're storing the current CFA reg into the stack. */
2706 if (cfa.offset == 0)
2709 /* If stack is aligned, putting CFA reg into stack means
2710 we can no longer use reg + offset to represent CFA.
2711 Here we use DW_CFA_def_cfa_expression instead. The
2712 result of this expression equals to the original CFA
2715 && fde->stack_realign
2716 && cfa.indirect == 0
2717 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2719 dw_cfa_location cfa_exp;
2721 gcc_assert (fde->drap_reg == cfa.reg);
2723 cfa_exp.indirect = 1;
2724 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2725 cfa_exp.base_offset = offset;
2728 fde->drap_reg_saved = 1;
2730 def_cfa_1 (label, &cfa_exp);
2734 /* If the source register is exactly the CFA, assume
2735 we're saving SP like any other register; this happens
2737 def_cfa_1 (label, &cfa);
2738 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2743 /* Otherwise, we'll need to look in the stack to
2744 calculate the CFA. */
2745 rtx x = XEXP (dest, 0);
2749 gcc_assert (REG_P (x));
2751 cfa.reg = REGNO (x);
2752 cfa.base_offset = offset;
2754 def_cfa_1 (label, &cfa);
2759 def_cfa_1 (label, &cfa);
2761 span = targetm.dwarf_register_span (src);
2764 queue_reg_save (label, src, NULL_RTX, offset);
2767 /* We have a PARALLEL describing where the contents of SRC
2768 live. Queue register saves for each piece of the
2772 HOST_WIDE_INT span_offset = offset;
2774 gcc_assert (GET_CODE (span) == PARALLEL);
2776 limit = XVECLEN (span, 0);
2777 for (par_index = 0; par_index < limit; par_index++)
2779 rtx elem = XVECEXP (span, 0, par_index);
2781 queue_reg_save (label, elem, NULL_RTX, span_offset);
2782 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2793 /* Record call frame debugging information for INSN, which either
2794 sets SP or FP (adjusting how we calculate the frame address) or saves a
2795 register to the stack. If INSN is NULL_RTX, initialize our state.
2797 If AFTER_P is false, we're being called before the insn is emitted,
2798 otherwise after. Call instructions get invoked twice. */
2801 dwarf2out_frame_debug (rtx insn, bool after_p)
2805 bool handled_one = false;
2807 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2808 dwarf2out_flush_queued_reg_saves ();
2810 if (!RTX_FRAME_RELATED_P (insn))
2812 /* ??? This should be done unconditionally since stack adjustments
2813 matter if the stack pointer is not the CFA register anymore but
2814 is still used to save registers. */
2815 if (!ACCUMULATE_OUTGOING_ARGS)
2816 dwarf2out_notice_stack_adjust (insn, after_p);
2820 label = dwarf2out_cfi_label (false);
2821 any_cfis_emitted = false;
2823 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2824 switch (REG_NOTE_KIND (note))
2826 case REG_FRAME_RELATED_EXPR:
2827 insn = XEXP (note, 0);
2830 case REG_CFA_DEF_CFA:
2831 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2835 case REG_CFA_ADJUST_CFA:
2840 if (GET_CODE (n) == PARALLEL)
2841 n = XVECEXP (n, 0, 0);
2843 dwarf2out_frame_debug_adjust_cfa (n, label);
2847 case REG_CFA_OFFSET:
2850 n = single_set (insn);
2851 dwarf2out_frame_debug_cfa_offset (n, label);
2855 case REG_CFA_REGISTER:
2860 if (GET_CODE (n) == PARALLEL)
2861 n = XVECEXP (n, 0, 0);
2863 dwarf2out_frame_debug_cfa_register (n, label);
2867 case REG_CFA_EXPRESSION:
2870 n = single_set (insn);
2871 dwarf2out_frame_debug_cfa_expression (n, label);
2875 case REG_CFA_RESTORE:
2880 if (GET_CODE (n) == PARALLEL)
2881 n = XVECEXP (n, 0, 0);
2884 dwarf2out_frame_debug_cfa_restore (n, label);
2888 case REG_CFA_SET_VDRAP:
2892 dw_fde_ref fde = current_fde ();
2895 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2897 fde->vdrap_reg = REGNO (n);
2908 if (any_cfis_emitted)
2909 dwarf2out_flush_queued_reg_saves ();
2913 insn = PATTERN (insn);
2915 dwarf2out_frame_debug_expr (insn, label);
2917 /* Check again. A parallel can save and update the same register.
2918 We could probably check just once, here, but this is safer than
2919 removing the check above. */
2920 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2921 dwarf2out_flush_queued_reg_saves ();
2924 /* Called once at the start of final to initialize some data for the
2925 current function. */
2927 dwarf2out_frame_debug_init (void)
2931 /* Flush any queued register saves. */
2932 dwarf2out_flush_queued_reg_saves ();
2934 /* Set up state for generating call frame debug info. */
2937 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2939 cfa.reg = STACK_POINTER_REGNUM;
2942 cfa_temp.offset = 0;
2944 for (i = 0; i < num_regs_saved_in_regs; i++)
2946 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2947 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2949 num_regs_saved_in_regs = 0;
2951 if (barrier_args_size)
2953 XDELETEVEC (barrier_args_size);
2954 barrier_args_size = NULL;
2958 /* Determine if we need to save and restore CFI information around this
2959 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2960 we do need to save/restore, then emit the save now, and insert a
2961 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2964 dwarf2out_cfi_begin_epilogue (rtx insn)
2966 bool saw_frp = false;
2969 /* Scan forward to the return insn, noticing if there are possible
2970 frame related insns. */
2971 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2976 /* Look for both regular and sibcalls to end the block. */
2977 if (returnjump_p (i))
2979 if (CALL_P (i) && SIBLING_CALL_P (i))
2982 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2985 rtx seq = PATTERN (i);
2987 if (returnjump_p (XVECEXP (seq, 0, 0)))
2989 if (CALL_P (XVECEXP (seq, 0, 0))
2990 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2993 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2994 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2998 if (RTX_FRAME_RELATED_P (i))
3002 /* If the port doesn't emit epilogue unwind info, we don't need a
3003 save/restore pair. */
3007 /* Otherwise, search forward to see if the return insn was the last
3008 basic block of the function. If so, we don't need save/restore. */
3009 gcc_assert (i != NULL);
3010 i = next_real_insn (i);
3014 /* Insert the restore before that next real insn in the stream, and before
3015 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3016 properly nested. This should be after any label or alignment. This
3017 will be pushed into the CFI stream by the function below. */
3020 rtx p = PREV_INSN (i);
3023 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3027 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3029 emit_cfa_remember = true;
3031 /* And emulate the state save. */
3032 gcc_assert (!cfa_remember.in_use);
3034 cfa_remember.in_use = 1;
3037 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3041 dwarf2out_frame_debug_restore_state (void)
3043 dw_cfi_ref cfi = new_cfi ();
3044 const char *label = dwarf2out_cfi_label (false);
3046 cfi->dw_cfi_opc = DW_CFA_restore_state;
3047 add_fde_cfi (label, cfi);
3049 gcc_assert (cfa_remember.in_use);
3051 cfa_remember.in_use = 0;
3054 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3055 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3056 (enum dwarf_call_frame_info cfi);
3058 static enum dw_cfi_oprnd_type
3059 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3064 case DW_CFA_GNU_window_save:
3065 case DW_CFA_remember_state:
3066 case DW_CFA_restore_state:
3067 return dw_cfi_oprnd_unused;
3069 case DW_CFA_set_loc:
3070 case DW_CFA_advance_loc1:
3071 case DW_CFA_advance_loc2:
3072 case DW_CFA_advance_loc4:
3073 case DW_CFA_MIPS_advance_loc8:
3074 return dw_cfi_oprnd_addr;
3077 case DW_CFA_offset_extended:
3078 case DW_CFA_def_cfa:
3079 case DW_CFA_offset_extended_sf:
3080 case DW_CFA_def_cfa_sf:
3081 case DW_CFA_restore:
3082 case DW_CFA_restore_extended:
3083 case DW_CFA_undefined:
3084 case DW_CFA_same_value:
3085 case DW_CFA_def_cfa_register:
3086 case DW_CFA_register:
3087 case DW_CFA_expression:
3088 return dw_cfi_oprnd_reg_num;
3090 case DW_CFA_def_cfa_offset:
3091 case DW_CFA_GNU_args_size:
3092 case DW_CFA_def_cfa_offset_sf:
3093 return dw_cfi_oprnd_offset;
3095 case DW_CFA_def_cfa_expression:
3096 return dw_cfi_oprnd_loc;
3103 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3104 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3105 (enum dwarf_call_frame_info cfi);
3107 static enum dw_cfi_oprnd_type
3108 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3112 case DW_CFA_def_cfa:
3113 case DW_CFA_def_cfa_sf:
3115 case DW_CFA_offset_extended_sf:
3116 case DW_CFA_offset_extended:
3117 return dw_cfi_oprnd_offset;
3119 case DW_CFA_register:
3120 return dw_cfi_oprnd_reg_num;
3122 case DW_CFA_expression:
3123 return dw_cfi_oprnd_loc;
3126 return dw_cfi_oprnd_unused;
3130 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3131 switch to the data section instead, and write out a synthetic start label
3132 for collect2 the first time around. */
3135 switch_to_eh_frame_section (bool back)
3139 #ifdef EH_FRAME_SECTION_NAME
3140 if (eh_frame_section == 0)
3144 if (EH_TABLES_CAN_BE_READ_ONLY)
3150 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3152 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3154 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3156 flags = ((! flag_pic
3157 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3158 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3159 && (per_encoding & 0x70) != DW_EH_PE_absptr
3160 && (per_encoding & 0x70) != DW_EH_PE_aligned
3161 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3162 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3163 ? 0 : SECTION_WRITE);
3166 flags = SECTION_WRITE;
3167 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3169 #endif /* EH_FRAME_SECTION_NAME */
3171 if (eh_frame_section)
3172 switch_to_section (eh_frame_section);
3175 /* We have no special eh_frame section. Put the information in
3176 the data section and emit special labels to guide collect2. */
3177 switch_to_section (data_section);
3181 label = get_file_function_name ("F");
3182 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3183 targetm.asm_out.globalize_label (asm_out_file,
3184 IDENTIFIER_POINTER (label));
3185 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3190 /* Switch [BACK] to the eh or debug frame table section, depending on
3194 switch_to_frame_table_section (int for_eh, bool back)
3197 switch_to_eh_frame_section (back);
3200 if (!debug_frame_section)
3201 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3202 SECTION_DEBUG, NULL);
3203 switch_to_section (debug_frame_section);
3207 /* Output a Call Frame Information opcode and its operand(s). */
3210 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3215 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3216 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3217 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3218 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3219 ((unsigned HOST_WIDE_INT)
3220 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3221 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3223 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3224 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3225 "DW_CFA_offset, column %#lx", r);
3226 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3227 dw2_asm_output_data_uleb128 (off, NULL);
3229 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3231 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3232 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3233 "DW_CFA_restore, column %#lx", r);
3237 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3238 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3240 switch (cfi->dw_cfi_opc)
3242 case DW_CFA_set_loc:
3244 dw2_asm_output_encoded_addr_rtx (
3245 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3246 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3249 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3250 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3251 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3254 case DW_CFA_advance_loc1:
3255 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3256 fde->dw_fde_current_label, NULL);
3257 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3260 case DW_CFA_advance_loc2:
3261 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3262 fde->dw_fde_current_label, NULL);
3263 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3266 case DW_CFA_advance_loc4:
3267 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3268 fde->dw_fde_current_label, NULL);
3269 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3272 case DW_CFA_MIPS_advance_loc8:
3273 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3274 fde->dw_fde_current_label, NULL);
3275 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3278 case DW_CFA_offset_extended:
3279 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3280 dw2_asm_output_data_uleb128 (r, NULL);
3281 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3282 dw2_asm_output_data_uleb128 (off, NULL);
3285 case DW_CFA_def_cfa:
3286 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3287 dw2_asm_output_data_uleb128 (r, NULL);
3288 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3291 case DW_CFA_offset_extended_sf:
3292 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3293 dw2_asm_output_data_uleb128 (r, NULL);
3294 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3295 dw2_asm_output_data_sleb128 (off, NULL);
3298 case DW_CFA_def_cfa_sf:
3299 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3300 dw2_asm_output_data_uleb128 (r, NULL);
3301 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3302 dw2_asm_output_data_sleb128 (off, NULL);
3305 case DW_CFA_restore_extended:
3306 case DW_CFA_undefined:
3307 case DW_CFA_same_value:
3308 case DW_CFA_def_cfa_register:
3309 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3310 dw2_asm_output_data_uleb128 (r, NULL);
3313 case DW_CFA_register:
3314 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3315 dw2_asm_output_data_uleb128 (r, NULL);
3316 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3317 dw2_asm_output_data_uleb128 (r, NULL);
3320 case DW_CFA_def_cfa_offset:
3321 case DW_CFA_GNU_args_size:
3322 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3325 case DW_CFA_def_cfa_offset_sf:
3326 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3327 dw2_asm_output_data_sleb128 (off, NULL);
3330 case DW_CFA_GNU_window_save:
3333 case DW_CFA_def_cfa_expression:
3334 case DW_CFA_expression:
3335 output_cfa_loc (cfi, for_eh);
3338 case DW_CFA_GNU_negative_offset_extended:
3339 /* Obsoleted by DW_CFA_offset_extended_sf. */
3348 /* Similar, but do it via assembler directives instead. */
3351 output_cfi_directive (dw_cfi_ref cfi)
3353 unsigned long r, r2;
3355 switch (cfi->dw_cfi_opc)
3357 case DW_CFA_advance_loc:
3358 case DW_CFA_advance_loc1:
3359 case DW_CFA_advance_loc2:
3360 case DW_CFA_advance_loc4:
3361 case DW_CFA_MIPS_advance_loc8:
3362 case DW_CFA_set_loc:
3363 /* Should only be created by add_fde_cfi in a code path not
3364 followed when emitting via directives. The assembler is
3365 going to take care of this for us. */
3369 case DW_CFA_offset_extended:
3370 case DW_CFA_offset_extended_sf:
3371 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3372 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3373 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3376 case DW_CFA_restore:
3377 case DW_CFA_restore_extended:
3378 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3379 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3382 case DW_CFA_undefined:
3383 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3384 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3387 case DW_CFA_same_value:
3388 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3389 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3392 case DW_CFA_def_cfa:
3393 case DW_CFA_def_cfa_sf:
3394 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3395 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3396 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3399 case DW_CFA_def_cfa_register:
3400 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3401 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3404 case DW_CFA_register:
3405 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3406 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3407 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3410 case DW_CFA_def_cfa_offset:
3411 case DW_CFA_def_cfa_offset_sf:
3412 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3413 HOST_WIDE_INT_PRINT_DEC"\n",
3414 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3417 case DW_CFA_remember_state:
3418 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3420 case DW_CFA_restore_state:
3421 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3424 case DW_CFA_GNU_args_size:
3425 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3426 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3428 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3429 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3430 fputc ('\n', asm_out_file);
3433 case DW_CFA_GNU_window_save:
3434 fprintf (asm_out_file, "\t.cfi_window_save\n");
3437 case DW_CFA_def_cfa_expression:
3438 case DW_CFA_expression:
3439 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3440 output_cfa_loc_raw (cfi);
3441 fputc ('\n', asm_out_file);
3449 /* Output CFIs from VEC, up to index UPTO, to bring current FDE to the
3450 same state as after executing CFIs in CFI chain. DO_CFI_ASM is
3451 true if .cfi_* directives shall be emitted, false otherwise. If it
3452 is false, FDE and FOR_EH are the other arguments to pass to
3456 output_cfis (cfi_vec vec, int upto, bool do_cfi_asm,
3457 dw_fde_ref fde, bool for_eh)
3460 struct dw_cfi_struct cfi_buf;
3462 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3463 VEC(dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3464 unsigned int len, idx;
3466 for (ix = 0; ix < upto + 1; ix++)
3468 dw_cfi_ref cfi = ix < upto ? VEC_index (dw_cfi_ref, vec, ix) : NULL;
3469 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3471 case DW_CFA_advance_loc:
3472 case DW_CFA_advance_loc1:
3473 case DW_CFA_advance_loc2:
3474 case DW_CFA_advance_loc4:
3475 case DW_CFA_MIPS_advance_loc8:
3476 case DW_CFA_set_loc:
3477 /* All advances should be ignored. */
3479 case DW_CFA_remember_state:
3481 dw_cfi_ref args_size = cfi_args_size;
3483 /* Skip everything between .cfi_remember_state and
3484 .cfi_restore_state. */
3489 for (; ix < upto; ix++)
3491 cfi2 = VEC_index (dw_cfi_ref, vec, ix);
3492 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3494 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3497 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3500 cfi_args_size = args_size;
3503 case DW_CFA_GNU_args_size:
3504 cfi_args_size = cfi;
3506 case DW_CFA_GNU_window_save:
3509 case DW_CFA_offset_extended:
3510 case DW_CFA_offset_extended_sf:
3511 case DW_CFA_restore:
3512 case DW_CFA_restore_extended:
3513 case DW_CFA_undefined:
3514 case DW_CFA_same_value:
3515 case DW_CFA_register:
3516 case DW_CFA_val_offset:
3517 case DW_CFA_val_offset_sf:
3518 case DW_CFA_expression:
3519 case DW_CFA_val_expression:
3520 case DW_CFA_GNU_negative_offset_extended:
3521 if (VEC_length (dw_cfi_ref, regs)
3522 <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3523 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3524 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3525 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
3528 case DW_CFA_def_cfa:
3529 case DW_CFA_def_cfa_sf:
3530 case DW_CFA_def_cfa_expression:
3532 cfi_cfa_offset = cfi;
3534 case DW_CFA_def_cfa_register:
3537 case DW_CFA_def_cfa_offset:
3538 case DW_CFA_def_cfa_offset_sf:
3539 cfi_cfa_offset = cfi;
3542 gcc_assert (cfi == NULL);
3544 len = VEC_length (dw_cfi_ref, regs);
3545 for (idx = 0; idx < len; idx++)
3547 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3549 && cfi2->dw_cfi_opc != DW_CFA_restore
3550 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3553 output_cfi_directive (cfi2);
3555 output_cfi (cfi2, fde, for_eh);
3558 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3560 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3562 switch (cfi_cfa_offset->dw_cfi_opc)
3564 case DW_CFA_def_cfa_offset:
3565 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3566 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3568 case DW_CFA_def_cfa_offset_sf:
3569 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3570 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3572 case DW_CFA_def_cfa:
3573 case DW_CFA_def_cfa_sf:
3574 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3575 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3582 else if (cfi_cfa_offset)
3583 cfi_cfa = cfi_cfa_offset;
3587 output_cfi_directive (cfi_cfa);
3589 output_cfi (cfi_cfa, fde, for_eh);
3592 cfi_cfa_offset = NULL;
3594 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3597 output_cfi_directive (cfi_args_size);
3599 output_cfi (cfi_args_size, fde, for_eh);
3601 cfi_args_size = NULL;
3604 VEC_free (dw_cfi_ref, heap, regs);
3607 else if (do_cfi_asm)
3608 output_cfi_directive (cfi);
3610 output_cfi (cfi, fde, for_eh);
3618 /* Like output_cfis, but emit all CFIs in the vector. */
3620 output_all_cfis (cfi_vec vec, bool do_cfi_asm,
3621 dw_fde_ref fde, bool for_eh)
3623 output_cfis (vec, VEC_length (dw_cfi_ref, vec), do_cfi_asm, fde, for_eh);
3626 /* Output one FDE. */
3629 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3630 char *section_start_label, int fde_encoding, char *augmentation,
3631 bool any_lsda_needed, int lsda_encoding)
3634 const char *begin, *end;
3635 static unsigned int j;
3636 char l1[20], l2[20];
3639 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3641 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3643 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3644 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3645 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3646 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3647 " indicating 64-bit DWARF extension");
3648 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3650 ASM_OUTPUT_LABEL (asm_out_file, l1);
3653 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3655 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3656 debug_frame_section, "FDE CIE offset");
3658 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
3659 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
3663 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3664 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3665 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3666 "FDE initial location");
3667 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3668 end, begin, "FDE address range");
3672 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3673 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3676 if (augmentation[0])
3678 if (any_lsda_needed)
3680 int size = size_of_encoded_value (lsda_encoding);
3682 if (lsda_encoding == DW_EH_PE_aligned)
3684 int offset = ( 4 /* Length */
3685 + 4 /* CIE offset */
3686 + 2 * size_of_encoded_value (fde_encoding)
3687 + 1 /* Augmentation size */ );
3688 int pad = -offset & (PTR_SIZE - 1);
3691 gcc_assert (size_of_uleb128 (size) == 1);
3694 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3696 if (fde->uses_eh_lsda)
3698 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3699 fde->funcdef_number);
3700 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3701 gen_rtx_SYMBOL_REF (Pmode, l1),
3703 "Language Specific Data Area");
3707 if (lsda_encoding == DW_EH_PE_aligned)
3708 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3709 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3710 "Language Specific Data Area (none)");
3714 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3717 /* Loop through the Call Frame Instructions associated with
3719 fde->dw_fde_current_label = begin;
3720 if (fde->dw_fde_second_begin == NULL)
3721 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
3722 output_cfi (cfi, fde, for_eh);
3725 if (fde->dw_fde_switch_cfi_index > 0)
3726 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
3728 if (ix == fde->dw_fde_switch_cfi_index)
3730 output_cfi (cfi, fde, for_eh);
3736 int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
3738 if (fde->dw_fde_switch_cfi_index > 0)
3740 from = fde->dw_fde_switch_cfi_index;
3741 output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh);
3743 for (i = from; i < until; i++)
3744 output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i),
3748 /* If we are to emit a ref/link from function bodies to their frame tables,
3749 do it now. This is typically performed to make sure that tables
3750 associated with functions are dragged with them and not discarded in
3751 garbage collecting links. We need to do this on a per function basis to
3752 cope with -ffunction-sections. */
3754 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3755 /* Switch to the function section, emit the ref to the tables, and
3756 switch *back* into the table section. */
3757 switch_to_section (function_section (fde->decl));
3758 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3759 switch_to_frame_table_section (for_eh, true);
3762 /* Pad the FDE out to an address sized boundary. */
3763 ASM_OUTPUT_ALIGN (asm_out_file,
3764 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3765 ASM_OUTPUT_LABEL (asm_out_file, l2);
3770 /* Return true if frame description entry FDE is needed for EH. */
3773 fde_needed_for_eh_p (dw_fde_ref fde)
3775 if (flag_asynchronous_unwind_tables)
3778 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3781 if (fde->uses_eh_lsda)
3784 /* If exceptions are enabled, we have collected nothrow info. */
3785 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3791 /* Output the call frame information used to record information
3792 that relates to calculating the frame pointer, and records the
3793 location of saved registers. */
3796 output_call_frame_info (int for_eh)
3801 char l1[20], l2[20], section_start_label[20];
3802 bool any_lsda_needed = false;
3803 char augmentation[6];
3804 int augmentation_size;
3805 int fde_encoding = DW_EH_PE_absptr;
3806 int per_encoding = DW_EH_PE_absptr;
3807 int lsda_encoding = DW_EH_PE_absptr;
3809 rtx personality = NULL;
3812 /* Don't emit a CIE if there won't be any FDEs. */
3813 if (fde_table_in_use == 0)
3816 /* Nothing to do if the assembler's doing it all. */
3817 if (dwarf2out_do_cfi_asm ())
3820 /* If we don't have any functions we'll want to unwind out of, don't emit
3821 any EH unwind information. If we make FDEs linkonce, we may have to
3822 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3823 want to avoid having an FDE kept around when the function it refers to
3824 is discarded. Example where this matters: a primary function template
3825 in C++ requires EH information, an explicit specialization doesn't. */
3828 bool any_eh_needed = false;
3830 for (i = 0; i < fde_table_in_use; i++)
3831 if (fde_table[i].uses_eh_lsda)
3832 any_eh_needed = any_lsda_needed = true;
3833 else if (fde_needed_for_eh_p (&fde_table[i]))
3834 any_eh_needed = true;
3835 else if (TARGET_USES_WEAK_UNWIND_INFO)
3836 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3843 /* We're going to be generating comments, so turn on app. */
3847 /* Switch to the proper frame section, first time. */
3848 switch_to_frame_table_section (for_eh, false);
3850 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3851 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3853 /* Output the CIE. */
3854 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3855 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3856 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3857 dw2_asm_output_data (4, 0xffffffff,
3858 "Initial length escape value indicating 64-bit DWARF extension");
3859 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3860 "Length of Common Information Entry");
3861 ASM_OUTPUT_LABEL (asm_out_file, l1);
3863 /* Now that the CIE pointer is PC-relative for EH,
3864 use 0 to identify the CIE. */
3865 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3866 (for_eh ? 0 : DWARF_CIE_ID),
3867 "CIE Identifier Tag");
3869 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3870 use CIE version 1, unless that would produce incorrect results
3871 due to overflowing the return register column. */
3872 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3874 if (return_reg >= 256 || dwarf_version > 2)
3876 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3878 augmentation[0] = 0;
3879 augmentation_size = 0;
3881 personality = current_unit_personality;
3887 z Indicates that a uleb128 is present to size the
3888 augmentation section.
3889 L Indicates the encoding (and thus presence) of
3890 an LSDA pointer in the FDE augmentation.
3891 R Indicates a non-default pointer encoding for
3893 P Indicates the presence of an encoding + language
3894 personality routine in the CIE augmentation. */
3896 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3897 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3898 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3900 p = augmentation + 1;
3904 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3905 assemble_external_libcall (personality);
3907 if (any_lsda_needed)
3910 augmentation_size += 1;
3912 if (fde_encoding != DW_EH_PE_absptr)
3915 augmentation_size += 1;
3917 if (p > augmentation + 1)
3919 augmentation[0] = 'z';
3923 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3924 if (personality && per_encoding == DW_EH_PE_aligned)
3926 int offset = ( 4 /* Length */
3928 + 1 /* CIE version */
3929 + strlen (augmentation) + 1 /* Augmentation */
3930 + size_of_uleb128 (1) /* Code alignment */
3931 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3933 + 1 /* Augmentation size */
3934 + 1 /* Personality encoding */ );
3935 int pad = -offset & (PTR_SIZE - 1);
3937 augmentation_size += pad;
3939 /* Augmentations should be small, so there's scarce need to
3940 iterate for a solution. Die if we exceed one uleb128 byte. */
3941 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3945 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3946 if (dw_cie_version >= 4)
3948 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3949 dw2_asm_output_data (1, 0, "CIE Segment Size");
3951 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3952 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3953 "CIE Data Alignment Factor");
3955 if (dw_cie_version == 1)
3956 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3958 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3960 if (augmentation[0])
3962 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3965 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3966 eh_data_format_name (per_encoding));
3967 dw2_asm_output_encoded_addr_rtx (per_encoding,
3972 if (any_lsda_needed)
3973 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3974 eh_data_format_name (lsda_encoding));
3976 if (fde_encoding != DW_EH_PE_absptr)
3977 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3978 eh_data_format_name (fde_encoding));
3981 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
3982 output_cfi (cfi, NULL, for_eh);
3984 /* Pad the CIE out to an address sized boundary. */
3985 ASM_OUTPUT_ALIGN (asm_out_file,
3986 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3987 ASM_OUTPUT_LABEL (asm_out_file, l2);
3989 /* Loop through all of the FDE's. */
3990 for (i = 0; i < fde_table_in_use; i++)
3993 fde = &fde_table[i];
3995 /* Don't emit EH unwind info for leaf functions that don't need it. */
3996 if (for_eh && !fde_needed_for_eh_p (fde))
3999 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
4000 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
4001 augmentation, any_lsda_needed, lsda_encoding);
4004 if (for_eh && targetm.terminate_dw2_eh_frame_info)
4005 dw2_asm_output_data (4, 0, "End of Table");
4006 #ifdef MIPS_DEBUGGING_INFO
4007 /* Work around Irix 6 assembler bug whereby labels at the end of a section
4008 get a value of 0. Putting .align 0 after the label fixes it. */
4009 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4012 /* Turn off app to make assembly quicker. */
4017 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4020 dwarf2out_do_cfi_startproc (bool second)
4024 rtx personality = get_personality_function (current_function_decl);
4026 fprintf (asm_out_file, "\t.cfi_startproc\n");
4030 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4033 /* ??? The GAS support isn't entirely consistent. We have to
4034 handle indirect support ourselves, but PC-relative is done
4035 in the assembler. Further, the assembler can't handle any
4036 of the weirder relocation types. */
4037 if (enc & DW_EH_PE_indirect)
4038 ref = dw2_force_const_mem (ref, true);
4040 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4041 output_addr_const (asm_out_file, ref);
4042 fputc ('\n', asm_out_file);
4045 if (crtl->uses_eh_lsda)
4049 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4050 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4051 current_function_funcdef_no);
4052 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4053 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4055 if (enc & DW_EH_PE_indirect)
4056 ref = dw2_force_const_mem (ref, true);
4058 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4059 output_addr_const (asm_out_file, ref);
4060 fputc ('\n', asm_out_file);
4064 /* Output a marker (i.e. a label) for the beginning of a function, before
4068 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4069 const char *file ATTRIBUTE_UNUSED)
4071 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4077 current_function_func_begin_label = NULL;
4079 do_frame = dwarf2out_do_frame ();
4081 /* ??? current_function_func_begin_label is also used by except.c for
4082 call-site information. We must emit this label if it might be used. */
4084 && (!flag_exceptions
4085 || targetm_common.except_unwind_info (&global_options) != UI_TARGET))
4088 fnsec = function_section (current_function_decl);
4089 switch_to_section (fnsec);
4090 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4091 current_function_funcdef_no);
4092 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4093 current_function_funcdef_no);
4094 dup_label = xstrdup (label);
4095 current_function_func_begin_label = dup_label;
4097 /* We can elide the fde allocation if we're not emitting debug info. */
4101 /* Expand the fde table if necessary. */
4102 if (fde_table_in_use == fde_table_allocated)
4104 fde_table_allocated += FDE_TABLE_INCREMENT;
4105 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4106 memset (fde_table + fde_table_in_use, 0,
4107 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4110 /* Record the FDE associated with this function. */
4111 current_funcdef_fde = fde_table_in_use;
4113 /* Add the new FDE at the end of the fde_table. */
4114 fde = &fde_table[fde_table_in_use++];
4115 fde->decl = current_function_decl;
4116 fde->dw_fde_begin = dup_label;
4117 fde->dw_fde_end = NULL;
4118 fde->dw_fde_current_label = dup_label;
4119 fde->dw_fde_second_begin = NULL;
4120 fde->dw_fde_second_end = NULL;
4121 fde->dw_fde_vms_end_prologue = NULL;
4122 fde->dw_fde_vms_begin_epilogue = NULL;
4123 fde->dw_fde_cfi = VEC_alloc (dw_cfi_ref, gc, 20);
4124 fde->dw_fde_switch_cfi_index = 0;
4125 fde->funcdef_number = current_function_funcdef_no;
4126 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4127 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4128 fde->nothrow = crtl->nothrow;
4129 fde->drap_reg = INVALID_REGNUM;
4130 fde->vdrap_reg = INVALID_REGNUM;
4131 fde->in_std_section = (fnsec == text_section
4132 || (cold_text_section && fnsec == cold_text_section));
4133 fde->second_in_std_section = 0;
4135 args_size = old_args_size = 0;
4137 /* We only want to output line number information for the genuine dwarf2
4138 prologue case, not the eh frame case. */
4139 #ifdef DWARF2_DEBUGGING_INFO
4141 dwarf2out_source_line (line, file, 0, true);
4144 if (dwarf2out_do_cfi_asm ())
4145 dwarf2out_do_cfi_startproc (false);
4148 rtx personality = get_personality_function (current_function_decl);
4149 if (!current_unit_personality)
4150 current_unit_personality = personality;
4152 /* We cannot keep a current personality per function as without CFI
4153 asm, at the point where we emit the CFI data, there is no current
4154 function anymore. */
4155 if (personality && current_unit_personality != personality)
4156 sorry ("multiple EH personalities are supported only with assemblers "
4157 "supporting .cfi_personality directive");
4161 /* Output a marker (i.e. a label) for the end of the generated code
4162 for a function prologue. This gets called *after* the prologue code has
4166 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4167 const char *file ATTRIBUTE_UNUSED)
4170 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4172 /* Output a label to mark the endpoint of the code generated for this
4174 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4175 current_function_funcdef_no);
4176 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4177 current_function_funcdef_no);
4178 fde = &fde_table[fde_table_in_use - 1];
4179 fde->dw_fde_vms_end_prologue = xstrdup (label);
4182 /* Output a marker (i.e. a label) for the beginning of the generated code
4183 for a function epilogue. This gets called *before* the prologue code has
4187 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4188 const char *file ATTRIBUTE_UNUSED)
4191 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4193 fde = &fde_table[fde_table_in_use - 1];
4194 if (fde->dw_fde_vms_begin_epilogue)
4197 /* Output a label to mark the endpoint of the code generated for this
4199 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4200 current_function_funcdef_no);
4201 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4202 current_function_funcdef_no);
4203 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4206 /* Output a marker (i.e. a label) for the absolute end of the generated code
4207 for a function definition. This gets called *after* the epilogue code has
4211 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4212 const char *file ATTRIBUTE_UNUSED)
4215 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4217 last_var_location_insn = NULL_RTX;
4219 if (dwarf2out_do_cfi_asm ())
4220 fprintf (asm_out_file, "\t.cfi_endproc\n");
4222 /* Output a label to mark the endpoint of the code generated for this
4224 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4225 current_function_funcdef_no);
4226 ASM_OUTPUT_LABEL (asm_out_file, label);
4227 fde = current_fde ();
4228 gcc_assert (fde != NULL);
4229 if (fde->dw_fde_second_begin == NULL)
4230 fde->dw_fde_end = xstrdup (label);
4234 dwarf2out_frame_init (void)
4236 /* Allocate the initial hunk of the fde_table. */
4237 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4238 fde_table_allocated = FDE_TABLE_INCREMENT;
4239 fde_table_in_use = 0;
4241 /* Generate the CFA instructions common to all FDE's. Do it now for the
4242 sake of lookup_cfa. */
4244 /* On entry, the Canonical Frame Address is at SP. */
4245 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4247 if (targetm.debug_unwind_info () == UI_DWARF2
4248 || targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
4249 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4253 dwarf2out_frame_finish (void)
4255 /* Output call frame information. */
4256 if (targetm.debug_unwind_info () == UI_DWARF2)
4257 output_call_frame_info (0);
4259 /* Output another copy for the unwinder. */
4260 if ((flag_unwind_tables || flag_exceptions)
4261 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
4262 output_call_frame_info (1);
4265 /* Note that the current function section is being used for code. */
4268 dwarf2out_note_section_used (void)
4270 section *sec = current_function_section ();
4271 if (sec == text_section)
4272 text_section_used = true;
4273 else if (sec == cold_text_section)
4274 cold_text_section_used = true;
4277 static void var_location_switch_text_section (void);
4278 static void set_cur_line_info_table (section *);
4281 dwarf2out_switch_text_section (void)
4284 dw_fde_ref fde = current_fde ();
4286 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
4288 if (!in_cold_section_p)
4290 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
4291 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
4292 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
4296 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
4297 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
4298 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
4300 have_multiple_function_sections = true;
4302 /* Reset the current label on switching text sections, so that we
4303 don't attempt to advance_loc4 between labels in different sections. */
4304 fde->dw_fde_current_label = NULL;
4306 /* There is no need to mark used sections when not debugging. */
4307 if (cold_text_section != NULL)
4308 dwarf2out_note_section_used ();
4310 if (dwarf2out_do_cfi_asm ())
4311 fprintf (asm_out_file, "\t.cfi_endproc\n");
4313 /* Now do the real section switch. */
4314 sect = current_function_section ();
4315 switch_to_section (sect);
4317 fde->second_in_std_section
4318 = (sect == text_section
4319 || (cold_text_section && sect == cold_text_section));
4321 if (dwarf2out_do_cfi_asm ())
4323 dwarf2out_do_cfi_startproc (true);
4324 /* As this is a different FDE, insert all current CFI instructions
4326 output_all_cfis (fde->dw_fde_cfi, true, fde, true);
4328 fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
4329 var_location_switch_text_section ();
4331 set_cur_line_info_table (sect);
4334 /* And now, the subset of the debugging information support code necessary
4335 for emitting location expressions. */
4337 /* Data about a single source file. */
4338 struct GTY(()) dwarf_file_data {
4339 const char * filename;
4343 typedef struct dw_val_struct *dw_val_ref;
4344 typedef struct die_struct *dw_die_ref;
4345 typedef const struct die_struct *const_dw_die_ref;
4346 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4347 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4349 typedef struct GTY(()) deferred_locations_struct
4353 } deferred_locations;
4355 DEF_VEC_O(deferred_locations);
4356 DEF_VEC_ALLOC_O(deferred_locations,gc);
4358 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4360 DEF_VEC_P(dw_die_ref);
4361 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4363 /* Each DIE may have a series of attribute/value pairs. Values
4364 can take on several forms. The forms that are used in this
4365 implementation are listed below. */
4370 dw_val_class_offset,
4372 dw_val_class_loc_list,
4373 dw_val_class_range_list,
4375 dw_val_class_unsigned_const,
4376 dw_val_class_const_double,
4379 dw_val_class_die_ref,
4380 dw_val_class_fde_ref,
4381 dw_val_class_lbl_id,
4382 dw_val_class_lineptr,
4384 dw_val_class_macptr,
4387 dw_val_class_decl_ref,
4388 dw_val_class_vms_delta
4391 /* Describe a floating point constant value, or a vector constant value. */
4393 typedef struct GTY(()) dw_vec_struct {
4394 unsigned char * GTY((length ("%h.length"))) array;
4400 /* The dw_val_node describes an attribute's value, as it is
4401 represented internally. */
4403 typedef struct GTY(()) dw_val_struct {
4404 enum dw_val_class val_class;
4405 union dw_val_struct_union
4407 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4408 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4409 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4410 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4411 HOST_WIDE_INT GTY ((default)) val_int;
4412 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4413 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4414 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4415 struct dw_val_die_union
4419 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4420 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4421 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4422 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4423 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4424 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4425 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4426 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4427 struct dw_val_vms_delta_union
4431 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4433 GTY ((desc ("%1.val_class"))) v;
4437 /* Locations in memory are described using a sequence of stack machine
4440 typedef struct GTY(()) dw_loc_descr_struct {
4441 dw_loc_descr_ref dw_loc_next;
4442 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4443 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4444 from DW_OP_addr with a dtp-relative symbol relocation. */
4445 unsigned int dtprel : 1;
4447 dw_val_node dw_loc_oprnd1;
4448 dw_val_node dw_loc_oprnd2;
4452 /* Location lists are ranges + location descriptions for that range,
4453 so you can track variables that are in different places over
4454 their entire life. */
4455 typedef struct GTY(()) dw_loc_list_struct {
4456 dw_loc_list_ref dw_loc_next;
4457 const char *begin; /* Label for begin address of range */
4458 const char *end; /* Label for end address of range */
4459 char *ll_symbol; /* Label for beginning of location list.
4460 Only on head of list */
4461 const char *section; /* Section this loclist is relative to */
4462 dw_loc_descr_ref expr;
4464 /* True if all addresses in this and subsequent lists are known to be
4467 /* True if this list has been replaced by dw_loc_next. */
4470 /* True if the range should be emitted even if begin and end
4475 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4477 /* Convert a DWARF stack opcode into its string name. */
4480 dwarf_stack_op_name (unsigned int op)
4485 return "DW_OP_addr";
4487 return "DW_OP_deref";
4489 return "DW_OP_const1u";
4491 return "DW_OP_const1s";
4493 return "DW_OP_const2u";
4495 return "DW_OP_const2s";
4497 return "DW_OP_const4u";
4499 return "DW_OP_const4s";
4501 return "DW_OP_const8u";
4503 return "DW_OP_const8s";
4505 return "DW_OP_constu";
4507 return "DW_OP_consts";
4511 return "DW_OP_drop";
4513 return "DW_OP_over";
4515 return "DW_OP_pick";
4517 return "DW_OP_swap";
4521 return "DW_OP_xderef";
4529 return "DW_OP_minus";
4541 return "DW_OP_plus";
4542 case DW_OP_plus_uconst:
4543 return "DW_OP_plus_uconst";
4549 return "DW_OP_shra";
4567 return "DW_OP_skip";
4569 return "DW_OP_lit0";
4571 return "DW_OP_lit1";
4573 return "DW_OP_lit2";
4575 return "DW_OP_lit3";
4577 return "DW_OP_lit4";
4579 return "DW_OP_lit5";
4581 return "DW_OP_lit6";
4583 return "DW_OP_lit7";
4585 return "DW_OP_lit8";
4587 return "DW_OP_lit9";
4589 return "DW_OP_lit10";
4591 return "DW_OP_lit11";
4593 return "DW_OP_lit12";
4595 return "DW_OP_lit13";
4597 return "DW_OP_lit14";
4599 return "DW_OP_lit15";
4601 return "DW_OP_lit16";
4603 return "DW_OP_lit17";
4605 return "DW_OP_lit18";
4607 return "DW_OP_lit19";
4609 return "DW_OP_lit20";
4611 return "DW_OP_lit21";
4613 return "DW_OP_lit22";
4615 return "DW_OP_lit23";
4617 return "DW_OP_lit24";
4619 return "DW_OP_lit25";
4621 return "DW_OP_lit26";
4623 return "DW_OP_lit27";
4625 return "DW_OP_lit28";
4627 return "DW_OP_lit29";
4629 return "DW_OP_lit30";
4631 return "DW_OP_lit31";
4633 return "DW_OP_reg0";
4635 return "DW_OP_reg1";
4637 return "DW_OP_reg2";
4639 return "DW_OP_reg3";
4641 return "DW_OP_reg4";
4643 return "DW_OP_reg5";
4645 return "DW_OP_reg6";
4647 return "DW_OP_reg7";
4649 return "DW_OP_reg8";
4651 return "DW_OP_reg9";
4653 return "DW_OP_reg10";
4655 return "DW_OP_reg11";
4657 return "DW_OP_reg12";
4659 return "DW_OP_reg13";
4661 return "DW_OP_reg14";
4663 return "DW_OP_reg15";
4665 return "DW_OP_reg16";
4667 return "DW_OP_reg17";
4669 return "DW_OP_reg18";
4671 return "DW_OP_reg19";
4673 return "DW_OP_reg20";
4675 return "DW_OP_reg21";
4677 return "DW_OP_reg22";
4679 return "DW_OP_reg23";
4681 return "DW_OP_reg24";
4683 return "DW_OP_reg25";
4685 return "DW_OP_reg26";
4687 return "DW_OP_reg27";
4689 return "DW_OP_reg28";
4691 return "DW_OP_reg29";
4693 return "DW_OP_reg30";
4695 return "DW_OP_reg31";
4697 return "DW_OP_breg0";
4699 return "DW_OP_breg1";
4701 return "DW_OP_breg2";
4703 return "DW_OP_breg3";
4705 return "DW_OP_breg4";
4707 return "DW_OP_breg5";
4709 return "DW_OP_breg6";
4711 return "DW_OP_breg7";
4713 return "DW_OP_breg8";
4715 return "DW_OP_breg9";
4717 return "DW_OP_breg10";
4719 return "DW_OP_breg11";
4721 return "DW_OP_breg12";
4723 return "DW_OP_breg13";
4725 return "DW_OP_breg14";
4727 return "DW_OP_breg15";
4729 return "DW_OP_breg16";
4731 return "DW_OP_breg17";
4733 return "DW_OP_breg18";
4735 return "DW_OP_breg19";
4737 return "DW_OP_breg20";
4739 return "DW_OP_breg21";
4741 return "DW_OP_breg22";
4743 return "DW_OP_breg23";
4745 return "DW_OP_breg24";
4747 return "DW_OP_breg25";
4749 return "DW_OP_breg26";
4751 return "DW_OP_breg27";
4753 return "DW_OP_breg28";
4755 return "DW_OP_breg29";
4757 return "DW_OP_breg30";
4759 return "DW_OP_breg31";
4761 return "DW_OP_regx";
4763 return "DW_OP_fbreg";
4765 return "DW_OP_bregx";
4767 return "DW_OP_piece";
4768 case DW_OP_deref_size:
4769 return "DW_OP_deref_size";
4770 case DW_OP_xderef_size:
4771 return "DW_OP_xderef_size";
4775 case DW_OP_push_object_address:
4776 return "DW_OP_push_object_address";
4778 return "DW_OP_call2";
4780 return "DW_OP_call4";
4781 case DW_OP_call_ref:
4782 return "DW_OP_call_ref";
4783 case DW_OP_implicit_value:
4784 return "DW_OP_implicit_value";
4785 case DW_OP_stack_value:
4786 return "DW_OP_stack_value";
4787 case DW_OP_form_tls_address:
4788 return "DW_OP_form_tls_address";
4789 case DW_OP_call_frame_cfa:
4790 return "DW_OP_call_frame_cfa";
4791 case DW_OP_bit_piece:
4792 return "DW_OP_bit_piece";
4794 case DW_OP_GNU_push_tls_address:
4795 return "DW_OP_GNU_push_tls_address";
4796 case DW_OP_GNU_uninit:
4797 return "DW_OP_GNU_uninit";
4798 case DW_OP_GNU_encoded_addr:
4799 return "DW_OP_GNU_encoded_addr";
4800 case DW_OP_GNU_implicit_pointer:
4801 return "DW_OP_GNU_implicit_pointer";
4802 case DW_OP_GNU_entry_value:
4803 return "DW_OP_GNU_entry_value";
4804 case DW_OP_GNU_const_type:
4805 return "DW_OP_GNU_const_type";
4806 case DW_OP_GNU_regval_type:
4807 return "DW_OP_GNU_regval_type";
4808 case DW_OP_GNU_deref_type:
4809 return "DW_OP_GNU_deref_type";
4810 case DW_OP_GNU_convert:
4811 return "DW_OP_GNU_convert";
4812 case DW_OP_GNU_reinterpret:
4813 return "DW_OP_GNU_reinterpret";
4816 return "OP_<unknown>";
4820 /* Return a pointer to a newly allocated location description. Location
4821 descriptions are simple expression terms that can be strung
4822 together to form more complicated location (address) descriptions. */
4824 static inline dw_loc_descr_ref
4825 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4826 unsigned HOST_WIDE_INT oprnd2)
4828 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4830 descr->dw_loc_opc = op;
4831 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4832 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4833 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4834 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4839 /* Return a pointer to a newly allocated location description for
4842 static inline dw_loc_descr_ref
4843 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4846 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4849 return new_loc_descr (DW_OP_bregx, reg, offset);
4852 /* Add a location description term to a location description expression. */
4855 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4857 dw_loc_descr_ref *d;
4859 /* Find the end of the chain. */
4860 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4866 /* Add a constant OFFSET to a location expression. */
4869 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4871 dw_loc_descr_ref loc;
4874 gcc_assert (*list_head != NULL);
4879 /* Find the end of the chain. */
4880 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4884 if (loc->dw_loc_opc == DW_OP_fbreg
4885 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4886 p = &loc->dw_loc_oprnd1.v.val_int;
4887 else if (loc->dw_loc_opc == DW_OP_bregx)
4888 p = &loc->dw_loc_oprnd2.v.val_int;
4890 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4891 offset. Don't optimize if an signed integer overflow would happen. */
4893 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4894 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4897 else if (offset > 0)
4898 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4902 loc->dw_loc_next = int_loc_descriptor (-offset);
4903 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4907 /* Add a constant OFFSET to a location list. */
4910 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4913 for (d = list_head; d != NULL; d = d->dw_loc_next)
4914 loc_descr_plus_const (&d->expr, offset);
4917 #define DWARF_REF_SIZE \
4918 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4920 static unsigned long size_of_locs (dw_loc_descr_ref);
4921 static unsigned long int get_base_type_offset (dw_die_ref);
4923 /* Return the size of a location descriptor. */
4925 static unsigned long
4926 size_of_loc_descr (dw_loc_descr_ref loc)
4928 unsigned long size = 1;
4930 switch (loc->dw_loc_opc)
4933 size += DWARF2_ADDR_SIZE;
4952 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4955 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4960 case DW_OP_plus_uconst:
4961 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4999 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
5002 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5005 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
5008 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5009 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5012 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5014 case DW_OP_bit_piece:
5015 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5016 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
5018 case DW_OP_deref_size:
5019 case DW_OP_xderef_size:
5028 case DW_OP_call_ref:
5029 size += DWARF_REF_SIZE;
5031 case DW_OP_implicit_value:
5032 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5033 + loc->dw_loc_oprnd1.v.val_unsigned;
5035 case DW_OP_GNU_implicit_pointer:
5036 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5038 case DW_OP_GNU_entry_value:
5040 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
5041 size += size_of_uleb128 (op_size) + op_size;
5044 case DW_OP_GNU_const_type:
5047 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
5048 size += size_of_uleb128 (o) + 1;
5049 switch (loc->dw_loc_oprnd2.val_class)
5051 case dw_val_class_vec:
5052 size += loc->dw_loc_oprnd2.v.val_vec.length
5053 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
5055 case dw_val_class_const:
5056 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
5058 case dw_val_class_const_double:
5059 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
5066 case DW_OP_GNU_regval_type:
5069 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
5070 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5071 + size_of_uleb128 (o);
5074 case DW_OP_GNU_deref_type:
5077 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
5078 size += 1 + size_of_uleb128 (o);
5081 case DW_OP_GNU_convert:
5082 case DW_OP_GNU_reinterpret:
5085 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
5086 size += size_of_uleb128 (o);
5095 /* Return the size of a series of location descriptors. */
5097 static unsigned long
5098 size_of_locs (dw_loc_descr_ref loc)
5103 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5104 field, to avoid writing to a PCH file. */
5105 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5107 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5109 size += size_of_loc_descr (l);
5114 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5116 l->dw_loc_addr = size;
5117 size += size_of_loc_descr (l);
5123 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5124 static void get_ref_die_offset_label (char *, dw_die_ref);
5125 static void output_loc_sequence (dw_loc_descr_ref, int);
5127 /* Output location description stack opcode's operands (if any).
5128 The for_eh_or_skip parameter controls whether register numbers are
5129 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5130 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5131 info). This should be suppressed for the cases that have not been converted
5132 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5135 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5137 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5138 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5140 switch (loc->dw_loc_opc)
5142 #ifdef DWARF2_DEBUGGING_INFO
5145 dw2_asm_output_data (2, val1->v.val_int, NULL);
5150 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5151 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5153 fputc ('\n', asm_out_file);
5158 dw2_asm_output_data (4, val1->v.val_int, NULL);
5163 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5164 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5166 fputc ('\n', asm_out_file);
5171 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5172 dw2_asm_output_data (8, val1->v.val_int, NULL);
5179 gcc_assert (val1->val_class == dw_val_class_loc);
5180 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5182 dw2_asm_output_data (2, offset, NULL);
5185 case DW_OP_implicit_value:
5186 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5187 switch (val2->val_class)
5189 case dw_val_class_const:
5190 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5192 case dw_val_class_vec:
5194 unsigned int elt_size = val2->v.val_vec.elt_size;
5195 unsigned int len = val2->v.val_vec.length;
5199 if (elt_size > sizeof (HOST_WIDE_INT))
5204 for (i = 0, p = val2->v.val_vec.array;
5207 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5208 "fp or vector constant word %u", i);
5211 case dw_val_class_const_double:
5213 unsigned HOST_WIDE_INT first, second;
5215 if (WORDS_BIG_ENDIAN)
5217 first = val2->v.val_double.high;
5218 second = val2->v.val_double.low;
5222 first = val2->v.val_double.low;
5223 second = val2->v.val_double.high;
5225 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5227 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5231 case dw_val_class_addr:
5232 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5233 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5248 case DW_OP_implicit_value:
5249 /* We currently don't make any attempt to make sure these are
5250 aligned properly like we do for the main unwind info, so
5251 don't support emitting things larger than a byte if we're
5252 only doing unwinding. */
5257 dw2_asm_output_data (1, val1->v.val_int, NULL);
5260 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5263 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5266 dw2_asm_output_data (1, val1->v.val_int, NULL);
5268 case DW_OP_plus_uconst:
5269 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5303 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5307 unsigned r = val1->v.val_unsigned;
5308 if (for_eh_or_skip >= 0)
5309 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5310 gcc_assert (size_of_uleb128 (r)
5311 == size_of_uleb128 (val1->v.val_unsigned));
5312 dw2_asm_output_data_uleb128 (r, NULL);
5316 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5320 unsigned r = val1->v.val_unsigned;
5321 if (for_eh_or_skip >= 0)
5322 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5323 gcc_assert (size_of_uleb128 (r)
5324 == size_of_uleb128 (val1->v.val_unsigned));
5325 dw2_asm_output_data_uleb128 (r, NULL);
5326 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5330 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5332 case DW_OP_bit_piece:
5333 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5334 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5336 case DW_OP_deref_size:
5337 case DW_OP_xderef_size:
5338 dw2_asm_output_data (1, val1->v.val_int, NULL);
5344 if (targetm.asm_out.output_dwarf_dtprel)
5346 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5349 fputc ('\n', asm_out_file);
5356 #ifdef DWARF2_DEBUGGING_INFO
5357 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5364 case DW_OP_GNU_implicit_pointer:
5366 char label[MAX_ARTIFICIAL_LABEL_BYTES
5367 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5368 gcc_assert (val1->val_class == dw_val_class_die_ref);
5369 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5370 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5371 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5375 case DW_OP_GNU_entry_value:
5376 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5377 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5380 case DW_OP_GNU_const_type:
5382 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
5384 dw2_asm_output_data_uleb128 (o, NULL);
5385 switch (val2->val_class)
5387 case dw_val_class_const:
5388 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5389 dw2_asm_output_data (1, l, NULL);
5390 dw2_asm_output_data (l, val2->v.val_int, NULL);
5392 case dw_val_class_vec:
5394 unsigned int elt_size = val2->v.val_vec.elt_size;
5395 unsigned int len = val2->v.val_vec.length;
5400 dw2_asm_output_data (1, l, NULL);
5401 if (elt_size > sizeof (HOST_WIDE_INT))
5406 for (i = 0, p = val2->v.val_vec.array;
5409 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5410 "fp or vector constant word %u", i);
5413 case dw_val_class_const_double:
5415 unsigned HOST_WIDE_INT first, second;
5416 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5418 dw2_asm_output_data (1, 2 * l, NULL);
5419 if (WORDS_BIG_ENDIAN)
5421 first = val2->v.val_double.high;
5422 second = val2->v.val_double.low;
5426 first = val2->v.val_double.low;
5427 second = val2->v.val_double.high;
5429 dw2_asm_output_data (l, first, NULL);
5430 dw2_asm_output_data (l, second, NULL);
5438 case DW_OP_GNU_regval_type:
5440 unsigned r = val1->v.val_unsigned;
5441 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
5443 if (for_eh_or_skip >= 0)
5445 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5446 gcc_assert (size_of_uleb128 (r)
5447 == size_of_uleb128 (val1->v.val_unsigned));
5449 dw2_asm_output_data_uleb128 (r, NULL);
5450 dw2_asm_output_data_uleb128 (o, NULL);
5453 case DW_OP_GNU_deref_type:
5455 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
5457 dw2_asm_output_data (1, val1->v.val_int, NULL);
5458 dw2_asm_output_data_uleb128 (o, NULL);
5461 case DW_OP_GNU_convert:
5462 case DW_OP_GNU_reinterpret:
5464 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
5466 dw2_asm_output_data_uleb128 (o, NULL);
5471 /* Other codes have no operands. */
5476 /* Output a sequence of location operations.
5477 The for_eh_or_skip parameter controls whether register numbers are
5478 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5479 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5480 info). This should be suppressed for the cases that have not been converted
5481 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5484 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5486 for (; loc != NULL; loc = loc->dw_loc_next)
5488 enum dwarf_location_atom opc = loc->dw_loc_opc;
5489 /* Output the opcode. */
5490 if (for_eh_or_skip >= 0
5491 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5493 unsigned r = (opc - DW_OP_breg0);
5494 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5495 gcc_assert (r <= 31);
5496 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5498 else if (for_eh_or_skip >= 0
5499 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5501 unsigned r = (opc - DW_OP_reg0);
5502 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5503 gcc_assert (r <= 31);
5504 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5507 dw2_asm_output_data (1, opc,
5508 "%s", dwarf_stack_op_name (opc));
5510 /* Output the operand(s) (if any). */
5511 output_loc_operands (loc, for_eh_or_skip);
5515 /* Output location description stack opcode's operands (if any).
5516 The output is single bytes on a line, suitable for .cfi_escape. */
5519 output_loc_operands_raw (dw_loc_descr_ref loc)
5521 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5522 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5524 switch (loc->dw_loc_opc)
5527 case DW_OP_implicit_value:
5528 /* We cannot output addresses in .cfi_escape, only bytes. */
5534 case DW_OP_deref_size:
5535 case DW_OP_xderef_size:
5536 fputc (',', asm_out_file);
5537 dw2_asm_output_data_raw (1, val1->v.val_int);
5542 fputc (',', asm_out_file);
5543 dw2_asm_output_data_raw (2, val1->v.val_int);
5548 fputc (',', asm_out_file);
5549 dw2_asm_output_data_raw (4, val1->v.val_int);
5554 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5555 fputc (',', asm_out_file);
5556 dw2_asm_output_data_raw (8, val1->v.val_int);
5564 gcc_assert (val1->val_class == dw_val_class_loc);
5565 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5567 fputc (',', asm_out_file);
5568 dw2_asm_output_data_raw (2, offset);
5574 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5575 gcc_assert (size_of_uleb128 (r)
5576 == size_of_uleb128 (val1->v.val_unsigned));
5577 fputc (',', asm_out_file);
5578 dw2_asm_output_data_uleb128_raw (r);
5583 case DW_OP_plus_uconst:
5585 fputc (',', asm_out_file);
5586 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5589 case DW_OP_bit_piece:
5590 fputc (',', asm_out_file);
5591 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5592 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5629 fputc (',', asm_out_file);
5630 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5635 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5636 gcc_assert (size_of_uleb128 (r)
5637 == size_of_uleb128 (val1->v.val_unsigned));
5638 fputc (',', asm_out_file);
5639 dw2_asm_output_data_uleb128_raw (r);
5640 fputc (',', asm_out_file);
5641 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5645 case DW_OP_GNU_implicit_pointer:
5646 case DW_OP_GNU_entry_value:
5647 case DW_OP_GNU_const_type:
5648 case DW_OP_GNU_regval_type:
5649 case DW_OP_GNU_deref_type:
5650 case DW_OP_GNU_convert:
5651 case DW_OP_GNU_reinterpret:
5656 /* Other codes have no operands. */
5662 output_loc_sequence_raw (dw_loc_descr_ref loc)
5666 enum dwarf_location_atom opc = loc->dw_loc_opc;
5667 /* Output the opcode. */
5668 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5670 unsigned r = (opc - DW_OP_breg0);
5671 r = DWARF2_FRAME_REG_OUT (r, 1);
5672 gcc_assert (r <= 31);
5673 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5675 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5677 unsigned r = (opc - DW_OP_reg0);
5678 r = DWARF2_FRAME_REG_OUT (r, 1);
5679 gcc_assert (r <= 31);
5680 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5682 /* Output the opcode. */
5683 fprintf (asm_out_file, "%#x", opc);
5684 output_loc_operands_raw (loc);
5686 if (!loc->dw_loc_next)
5688 loc = loc->dw_loc_next;
5690 fputc (',', asm_out_file);
5694 /* This routine will generate the correct assembly data for a location
5695 description based on a cfi entry with a complex address. */
5698 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5700 dw_loc_descr_ref loc;
5703 if (cfi->dw_cfi_opc == DW_CFA_expression)
5706 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5707 dw2_asm_output_data (1, r, NULL);
5708 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5711 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5713 /* Output the size of the block. */
5714 size = size_of_locs (loc);
5715 dw2_asm_output_data_uleb128 (size, NULL);
5717 /* Now output the operations themselves. */
5718 output_loc_sequence (loc, for_eh);
5721 /* Similar, but used for .cfi_escape. */
5724 output_cfa_loc_raw (dw_cfi_ref cfi)
5726 dw_loc_descr_ref loc;
5729 if (cfi->dw_cfi_opc == DW_CFA_expression)
5732 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5733 fprintf (asm_out_file, "%#x,", r);
5734 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5737 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5739 /* Output the size of the block. */
5740 size = size_of_locs (loc);
5741 dw2_asm_output_data_uleb128_raw (size);
5742 fputc (',', asm_out_file);
5744 /* Now output the operations themselves. */
5745 output_loc_sequence_raw (loc);
5748 /* This function builds a dwarf location descriptor sequence from a
5749 dw_cfa_location, adding the given OFFSET to the result of the
5752 static struct dw_loc_descr_struct *
5753 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5755 struct dw_loc_descr_struct *head, *tmp;
5757 offset += cfa->offset;
5761 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5762 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5763 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5764 add_loc_descr (&head, tmp);
5767 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5768 add_loc_descr (&head, tmp);
5772 head = new_reg_loc_descr (cfa->reg, offset);
5777 /* This function builds a dwarf location descriptor sequence for
5778 the address at OFFSET from the CFA when stack is aligned to
5781 static struct dw_loc_descr_struct *
5782 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5784 struct dw_loc_descr_struct *head;
5785 unsigned int dwarf_fp
5786 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5788 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5789 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5791 head = new_reg_loc_descr (dwarf_fp, 0);
5792 add_loc_descr (&head, int_loc_descriptor (alignment));
5793 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5794 loc_descr_plus_const (&head, offset);
5797 head = new_reg_loc_descr (dwarf_fp, offset);
5801 /* This function fills in aa dw_cfa_location structure from a dwarf location
5802 descriptor sequence. */
5805 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5807 struct dw_loc_descr_struct *ptr;
5809 cfa->base_offset = 0;
5813 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5815 enum dwarf_location_atom op = ptr->dw_loc_opc;
5851 cfa->reg = op - DW_OP_reg0;
5854 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5888 cfa->reg = op - DW_OP_breg0;
5889 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5892 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5893 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5898 case DW_OP_plus_uconst:
5899 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5902 internal_error ("DW_LOC_OP %s not implemented",
5903 dwarf_stack_op_name (ptr->dw_loc_opc));
5908 /* And now, the support for symbolic debugging information. */
5910 /* .debug_str support. */
5911 static int output_indirect_string (void **, void *);
5913 static void dwarf2out_init (const char *);
5914 static void dwarf2out_finish (const char *);
5915 static void dwarf2out_assembly_start (void);
5916 static void dwarf2out_define (unsigned int, const char *);
5917 static void dwarf2out_undef (unsigned int, const char *);
5918 static void dwarf2out_start_source_file (unsigned, const char *);
5919 static void dwarf2out_end_source_file (unsigned);
5920 static void dwarf2out_function_decl (tree);
5921 static void dwarf2out_begin_block (unsigned, unsigned);
5922 static void dwarf2out_end_block (unsigned, unsigned);
5923 static bool dwarf2out_ignore_block (const_tree);
5924 static void dwarf2out_global_decl (tree);
5925 static void dwarf2out_type_decl (tree, int);
5926 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5927 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5929 static void dwarf2out_abstract_function (tree);
5930 static void dwarf2out_var_location (rtx);
5931 static void dwarf2out_begin_function (tree);
5932 static void dwarf2out_set_name (tree, tree);
5934 /* The debug hooks structure. */
5936 const struct gcc_debug_hooks dwarf2_debug_hooks =
5940 dwarf2out_assembly_start,
5943 dwarf2out_start_source_file,
5944 dwarf2out_end_source_file,
5945 dwarf2out_begin_block,
5946 dwarf2out_end_block,
5947 dwarf2out_ignore_block,
5948 dwarf2out_source_line,
5949 dwarf2out_begin_prologue,
5950 #if VMS_DEBUGGING_INFO
5951 dwarf2out_vms_end_prologue,
5952 dwarf2out_vms_begin_epilogue,
5954 debug_nothing_int_charstar,
5955 debug_nothing_int_charstar,
5957 dwarf2out_end_epilogue,
5958 dwarf2out_begin_function,
5959 debug_nothing_int, /* end_function */
5960 dwarf2out_function_decl, /* function_decl */
5961 dwarf2out_global_decl,
5962 dwarf2out_type_decl, /* type_decl */
5963 dwarf2out_imported_module_or_decl,
5964 debug_nothing_tree, /* deferred_inline_function */
5965 /* The DWARF 2 backend tries to reduce debugging bloat by not
5966 emitting the abstract description of inline functions until
5967 something tries to reference them. */
5968 dwarf2out_abstract_function, /* outlining_inline_function */
5969 debug_nothing_rtx, /* label */
5970 debug_nothing_int, /* handle_pch */
5971 dwarf2out_var_location,
5972 dwarf2out_switch_text_section,
5974 1, /* start_end_main_source_file */
5975 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5978 /* NOTE: In the comments in this file, many references are made to
5979 "Debugging Information Entries". This term is abbreviated as `DIE'
5980 throughout the remainder of this file. */
5982 /* An internal representation of the DWARF output is built, and then
5983 walked to generate the DWARF debugging info. The walk of the internal
5984 representation is done after the entire program has been compiled.
5985 The types below are used to describe the internal representation. */
5987 /* Whether to put type DIEs into their own section .debug_types instead
5988 of making them part of the .debug_info section. Only supported for
5989 Dwarf V4 or higher and the user didn't disable them through
5990 -fno-debug-types-section. It is more efficient to put them in a
5991 separate comdat sections since the linker will then be able to
5992 remove duplicates. But not all tools support .debug_types sections
5995 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
5997 /* Various DIE's use offsets relative to the beginning of the
5998 .debug_info section to refer to each other. */
6000 typedef long int dw_offset;
6002 /* Define typedefs here to avoid circular dependencies. */
6004 typedef struct dw_attr_struct *dw_attr_ref;
6005 typedef struct dw_line_info_struct *dw_line_info_ref;
6006 typedef struct pubname_struct *pubname_ref;
6007 typedef struct dw_ranges_struct *dw_ranges_ref;
6008 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
6009 typedef struct comdat_type_struct *comdat_type_node_ref;
6011 /* The entries in the line_info table more-or-less mirror the opcodes
6012 that are used in the real dwarf line table. Arrays of these entries
6013 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
6016 enum dw_line_info_opcode {
6017 /* Emit DW_LNE_set_address; the operand is the label index. */
6020 /* Emit a row to the matrix with the given line. This may be done
6021 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
6025 /* Emit a DW_LNS_set_file. */
6028 /* Emit a DW_LNS_set_column. */
6031 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
6034 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
6035 LI_set_prologue_end,
6036 LI_set_epilogue_begin,
6038 /* Emit a DW_LNE_set_discriminator. */
6039 LI_set_discriminator
6042 typedef struct GTY(()) dw_line_info_struct {
6043 enum dw_line_info_opcode opcode;
6045 } dw_line_info_entry;
6047 DEF_VEC_O(dw_line_info_entry);
6048 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
6050 typedef struct GTY(()) dw_line_info_table_struct {
6051 /* The label that marks the end of this section. */
6052 const char *end_label;
6054 /* The values for the last row of the matrix, as collected in the table.
6055 These are used to minimize the changes to the next row. */
6056 unsigned int file_num;
6057 unsigned int line_num;
6058 unsigned int column_num;
6063 VEC(dw_line_info_entry, gc) *entries;
6064 } dw_line_info_table;
6066 typedef dw_line_info_table *dw_line_info_table_p;
6068 DEF_VEC_P(dw_line_info_table_p);
6069 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
6071 /* Each DIE attribute has a field specifying the attribute kind,
6072 a link to the next attribute in the chain, and an attribute value.
6073 Attributes are typically linked below the DIE they modify. */
6075 typedef struct GTY(()) dw_attr_struct {
6076 enum dwarf_attribute dw_attr;
6077 dw_val_node dw_attr_val;
6081 DEF_VEC_O(dw_attr_node);
6082 DEF_VEC_ALLOC_O(dw_attr_node,gc);
6084 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
6085 The children of each node form a circular list linked by
6086 die_sib. die_child points to the node *before* the "first" child node. */
6088 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
6089 union die_symbol_or_type_node
6091 char * GTY ((tag ("0"))) die_symbol;
6092 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
6094 GTY ((desc ("use_debug_types"))) die_id;
6095 VEC(dw_attr_node,gc) * die_attr;
6096 dw_die_ref die_parent;
6097 dw_die_ref die_child;
6099 dw_die_ref die_definition; /* ref from a specification to its definition */
6100 dw_offset die_offset;
6101 unsigned long die_abbrev;
6103 /* Die is used and must not be pruned as unused. */
6104 int die_perennial_p;
6105 unsigned int decl_id;
6106 enum dwarf_tag die_tag;
6110 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
6111 #define FOR_EACH_CHILD(die, c, expr) do { \
6112 c = die->die_child; \
6116 } while (c != die->die_child); \
6119 /* The pubname structure */
6121 typedef struct GTY(()) pubname_struct {
6127 DEF_VEC_O(pubname_entry);
6128 DEF_VEC_ALLOC_O(pubname_entry, gc);
6130 struct GTY(()) dw_ranges_struct {
6131 /* If this is positive, it's a block number, otherwise it's a
6132 bitwise-negated index into dw_ranges_by_label. */
6136 /* A structure to hold a macinfo entry. */
6138 typedef struct GTY(()) macinfo_struct {
6139 unsigned HOST_WIDE_INT code;
6140 unsigned HOST_WIDE_INT lineno;
6145 DEF_VEC_O(macinfo_entry);
6146 DEF_VEC_ALLOC_O(macinfo_entry, gc);
6148 struct GTY(()) dw_ranges_by_label_struct {
6153 /* The comdat type node structure. */
6154 typedef struct GTY(()) comdat_type_struct
6156 dw_die_ref root_die;
6157 dw_die_ref type_die;
6158 char signature[DWARF_TYPE_SIGNATURE_SIZE];
6159 struct comdat_type_struct *next;
6163 /* The limbo die list structure. */
6164 typedef struct GTY(()) limbo_die_struct {
6167 struct limbo_die_struct *next;
6171 typedef struct skeleton_chain_struct
6175 struct skeleton_chain_struct *parent;
6177 skeleton_chain_node;
6179 /* How to start an assembler comment. */
6180 #ifndef ASM_COMMENT_START
6181 #define ASM_COMMENT_START ";#"
6184 /* Define a macro which returns nonzero for a TYPE_DECL which was
6185 implicitly generated for a tagged type.
6187 Note that unlike the gcc front end (which generates a NULL named
6188 TYPE_DECL node for each complete tagged type, each array type, and
6189 each function type node created) the g++ front end generates a
6190 _named_ TYPE_DECL node for each tagged type node created.
6191 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
6192 generate a DW_TAG_typedef DIE for them. */
6194 #define TYPE_DECL_IS_STUB(decl) \
6195 (DECL_NAME (decl) == NULL_TREE \
6196 || (DECL_ARTIFICIAL (decl) \
6197 && is_tagged_type (TREE_TYPE (decl)) \
6198 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
6199 /* This is necessary for stub decls that \
6200 appear in nested inline functions. */ \
6201 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6202 && (decl_ultimate_origin (decl) \
6203 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6205 /* Information concerning the compilation unit's programming
6206 language, and compiler version. */
6208 /* Fixed size portion of the DWARF compilation unit header. */
6209 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6210 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6212 /* Fixed size portion of the DWARF comdat type unit header. */
6213 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6214 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6215 + DWARF_OFFSET_SIZE)
6217 /* Fixed size portion of public names info. */
6218 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6220 /* Fixed size portion of the address range info. */
6221 #define DWARF_ARANGES_HEADER_SIZE \
6222 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6223 DWARF2_ADDR_SIZE * 2) \
6224 - DWARF_INITIAL_LENGTH_SIZE)
6226 /* Size of padding portion in the address range info. It must be
6227 aligned to twice the pointer size. */
6228 #define DWARF_ARANGES_PAD_SIZE \
6229 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6230 DWARF2_ADDR_SIZE * 2) \
6231 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6233 /* Use assembler line directives if available. */
6234 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6235 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6236 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6238 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6242 /* Minimum line offset in a special line info. opcode.
6243 This value was chosen to give a reasonable range of values. */
6244 #define DWARF_LINE_BASE -10
6246 /* First special line opcode - leave room for the standard opcodes. */
6247 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
6249 /* Range of line offsets in a special line info. opcode. */
6250 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6252 /* Flag that indicates the initial value of the is_stmt_start flag.
6253 In the present implementation, we do not mark any lines as
6254 the beginning of a source statement, because that information
6255 is not made available by the GCC front-end. */
6256 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6258 /* Maximum number of operations per instruction bundle. */
6259 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6260 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6263 /* This location is used by calc_die_sizes() to keep track
6264 the offset of each DIE within the .debug_info section. */
6265 static unsigned long next_die_offset;
6267 /* Record the root of the DIE's built for the current compilation unit. */
6268 static GTY(()) dw_die_ref single_comp_unit_die;
6270 /* A list of type DIEs that have been separated into comdat sections. */
6271 static GTY(()) comdat_type_node *comdat_type_list;
6273 /* A list of DIEs with a NULL parent waiting to be relocated. */
6274 static GTY(()) limbo_die_node *limbo_die_list;
6276 /* A list of DIEs for which we may have to generate
6277 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6278 static GTY(()) limbo_die_node *deferred_asm_name;
6280 /* Filenames referenced by this compilation unit. */
6281 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6283 /* A hash table of references to DIE's that describe declarations.
6284 The key is a DECL_UID() which is a unique number identifying each decl. */
6285 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6287 /* A hash table of references to DIE's that describe COMMON blocks.
6288 The key is DECL_UID() ^ die_parent. */
6289 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6291 typedef struct GTY(()) die_arg_entry_struct {
6296 DEF_VEC_O(die_arg_entry);
6297 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6299 /* Node of the variable location list. */
6300 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6301 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6302 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6303 in mode of the EXPR_LIST node and first EXPR_LIST operand
6304 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6305 location or NULL for padding. For larger bitsizes,
6306 mode is 0 and first operand is a CONCAT with bitsize
6307 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6308 NULL as second operand. */
6310 const char * GTY (()) label;
6311 struct var_loc_node * GTY (()) next;
6314 /* Variable location list. */
6315 struct GTY (()) var_loc_list_def {
6316 struct var_loc_node * GTY (()) first;
6318 /* Pointer to the last but one or last element of the
6319 chained list. If the list is empty, both first and
6320 last are NULL, if the list contains just one node
6321 or the last node certainly is not redundant, it points
6322 to the last node, otherwise points to the last but one.
6323 Do not mark it for GC because it is marked through the chain. */
6324 struct var_loc_node * GTY ((skip ("%h"))) last;
6326 /* Pointer to the last element before section switch,
6327 if NULL, either sections weren't switched or first
6328 is after section switch. */
6329 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
6331 /* DECL_UID of the variable decl. */
6332 unsigned int decl_id;
6334 typedef struct var_loc_list_def var_loc_list;
6336 /* Call argument location list. */
6337 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6338 rtx GTY (()) call_arg_loc_note;
6339 const char * GTY (()) label;
6340 tree GTY (()) block;
6342 rtx GTY (()) symbol_ref;
6343 struct call_arg_loc_node * GTY (()) next;
6347 /* Table of decl location linked lists. */
6348 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6350 /* Head and tail of call_arg_loc chain. */
6351 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6352 static struct call_arg_loc_node *call_arg_loc_last;
6354 /* Number of call sites in the current function. */
6355 static int call_site_count = -1;
6356 /* Number of tail call sites in the current function. */
6357 static int tail_call_site_count = -1;
6359 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6361 static VEC (dw_die_ref, heap) *block_map;
6363 /* A cached location list. */
6364 struct GTY (()) cached_dw_loc_list_def {
6365 /* The DECL_UID of the decl that this entry describes. */
6366 unsigned int decl_id;
6368 /* The cached location list. */
6369 dw_loc_list_ref loc_list;
6371 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
6373 /* Table of cached location lists. */
6374 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
6376 /* A pointer to the base of a list of references to DIE's that
6377 are uniquely identified by their tag, presence/absence of
6378 children DIE's, and list of attribute/value pairs. */
6379 static GTY((length ("abbrev_die_table_allocated")))
6380 dw_die_ref *abbrev_die_table;
6382 /* Number of elements currently allocated for abbrev_die_table. */
6383 static GTY(()) unsigned abbrev_die_table_allocated;
6385 /* Number of elements in type_die_table currently in use. */
6386 static GTY(()) unsigned abbrev_die_table_in_use;
6388 /* Size (in elements) of increments by which we may expand the
6389 abbrev_die_table. */
6390 #define ABBREV_DIE_TABLE_INCREMENT 256
6392 /* A global counter for generating labels for line number data. */
6393 static unsigned int line_info_label_num;
6395 /* The current table to which we should emit line number information
6396 for the current function. This will be set up at the beginning of
6397 assembly for the function. */
6398 static dw_line_info_table *cur_line_info_table;
6400 /* The two default tables of line number info. */
6401 static GTY(()) dw_line_info_table *text_section_line_info;
6402 static GTY(()) dw_line_info_table *cold_text_section_line_info;
6404 /* The set of all non-default tables of line number info. */
6405 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
6407 /* A flag to tell pubnames/types export if there is an info section to
6409 static bool info_section_emitted;
6411 /* A pointer to the base of a table that contains a list of publicly
6412 accessible names. */
6413 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6415 /* A pointer to the base of a table that contains a list of publicly
6416 accessible types. */
6417 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6419 /* A pointer to the base of a table that contains a list of macro
6420 defines/undefines (and file start/end markers). */
6421 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6423 /* Array of dies for which we should generate .debug_ranges info. */
6424 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6426 /* Number of elements currently allocated for ranges_table. */
6427 static GTY(()) unsigned ranges_table_allocated;
6429 /* Number of elements in ranges_table currently in use. */
6430 static GTY(()) unsigned ranges_table_in_use;
6432 /* Array of pairs of labels referenced in ranges_table. */
6433 static GTY ((length ("ranges_by_label_allocated")))
6434 dw_ranges_by_label_ref ranges_by_label;
6436 /* Number of elements currently allocated for ranges_by_label. */
6437 static GTY(()) unsigned ranges_by_label_allocated;
6439 /* Number of elements in ranges_by_label currently in use. */
6440 static GTY(()) unsigned ranges_by_label_in_use;
6442 /* Size (in elements) of increments by which we may expand the
6444 #define RANGES_TABLE_INCREMENT 64
6446 /* Whether we have location lists that need outputting */
6447 static GTY(()) bool have_location_lists;
6449 /* Unique label counter. */
6450 static GTY(()) unsigned int loclabel_num;
6452 /* Unique label counter for point-of-call tables. */
6453 static GTY(()) unsigned int poc_label_num;
6455 /* Record whether the function being analyzed contains inlined functions. */
6456 static int current_function_has_inlines;
6458 /* The last file entry emitted by maybe_emit_file(). */
6459 static GTY(()) struct dwarf_file_data * last_emitted_file;
6461 /* Number of internal labels generated by gen_internal_sym(). */
6462 static GTY(()) int label_num;
6464 /* Cached result of previous call to lookup_filename. */
6465 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6467 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6469 /* Instances of generic types for which we need to generate debug
6470 info that describe their generic parameters and arguments. That
6471 generation needs to happen once all types are properly laid out so
6472 we do it at the end of compilation. */
6473 static GTY(()) VEC(tree,gc) *generic_type_instances;
6475 /* Offset from the "steady-state frame pointer" to the frame base,
6476 within the current function. */
6477 static HOST_WIDE_INT frame_pointer_fb_offset;
6478 static bool frame_pointer_fb_offset_valid;
6480 static VEC (dw_die_ref, heap) *base_types;
6482 /* Forward declarations for functions defined in this file. */
6484 static int is_pseudo_reg (const_rtx);
6485 static tree type_main_variant (tree);
6486 static int is_tagged_type (const_tree);
6487 static const char *dwarf_tag_name (unsigned);
6488 static const char *dwarf_attr_name (unsigned);
6489 static const char *dwarf_form_name (unsigned);
6490 static tree decl_ultimate_origin (const_tree);
6491 static tree decl_class_context (tree);
6492 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6493 static inline enum dw_val_class AT_class (dw_attr_ref);
6494 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6495 static inline unsigned AT_flag (dw_attr_ref);
6496 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6497 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6498 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6499 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6500 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6501 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6502 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6503 unsigned int, unsigned char *);
6504 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6505 static hashval_t debug_str_do_hash (const void *);
6506 static int debug_str_eq (const void *, const void *);
6507 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6508 static inline const char *AT_string (dw_attr_ref);
6509 static enum dwarf_form AT_string_form (dw_attr_ref);
6510 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6511 static void add_AT_specification (dw_die_ref, dw_die_ref);
6512 static inline dw_die_ref AT_ref (dw_attr_ref);
6513 static inline int AT_ref_external (dw_attr_ref);
6514 static inline void set_AT_ref_external (dw_attr_ref, int);
6515 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6516 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6517 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6518 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6520 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6521 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6522 static inline rtx AT_addr (dw_attr_ref);
6523 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6524 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6525 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6526 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6527 unsigned HOST_WIDE_INT);
6528 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6530 static inline const char *AT_lbl (dw_attr_ref);
6531 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6532 static const char *get_AT_low_pc (dw_die_ref);
6533 static const char *get_AT_hi_pc (dw_die_ref);
6534 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6535 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6536 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6537 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6538 static bool is_cxx (void);
6539 static bool is_fortran (void);
6540 static bool is_ada (void);
6541 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6542 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6543 static void add_child_die (dw_die_ref, dw_die_ref);
6544 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6545 static dw_die_ref lookup_type_die (tree);
6546 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6547 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6548 static void equate_type_number_to_die (tree, dw_die_ref);
6549 static hashval_t decl_die_table_hash (const void *);
6550 static int decl_die_table_eq (const void *, const void *);
6551 static dw_die_ref lookup_decl_die (tree);
6552 static hashval_t common_block_die_table_hash (const void *);
6553 static int common_block_die_table_eq (const void *, const void *);
6554 static hashval_t decl_loc_table_hash (const void *);
6555 static int decl_loc_table_eq (const void *, const void *);
6556 static var_loc_list *lookup_decl_loc (const_tree);
6557 static void equate_decl_number_to_die (tree, dw_die_ref);
6558 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6559 static void print_spaces (FILE *);
6560 static void print_die (dw_die_ref, FILE *);
6561 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6562 static dw_die_ref pop_compile_unit (dw_die_ref);
6563 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6564 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6565 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6566 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6567 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6568 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6569 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6570 struct md5_ctx *, int *);
6571 struct checksum_attributes;
6572 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6573 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6574 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6575 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6576 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6577 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6578 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6579 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6580 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6581 static void compute_section_prefix (dw_die_ref);
6582 static int is_type_die (dw_die_ref);
6583 static int is_comdat_die (dw_die_ref);
6584 static int is_symbol_die (dw_die_ref);
6585 static void assign_symbol_names (dw_die_ref);
6586 static void break_out_includes (dw_die_ref);
6587 static int is_declaration_die (dw_die_ref);
6588 static int should_move_die_to_comdat (dw_die_ref);
6589 static dw_die_ref clone_as_declaration (dw_die_ref);
6590 static dw_die_ref clone_die (dw_die_ref);
6591 static dw_die_ref clone_tree (dw_die_ref);
6592 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6593 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6594 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6595 static dw_die_ref generate_skeleton (dw_die_ref);
6596 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6598 static void break_out_comdat_types (dw_die_ref);
6599 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6600 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6601 static void copy_decls_for_unworthy_types (dw_die_ref);
6603 static hashval_t htab_cu_hash (const void *);
6604 static int htab_cu_eq (const void *, const void *);
6605 static void htab_cu_del (void *);
6606 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6607 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6608 static void add_sibling_attributes (dw_die_ref);
6609 static void build_abbrev_table (dw_die_ref);
6610 static void output_location_lists (dw_die_ref);
6611 static int constant_size (unsigned HOST_WIDE_INT);
6612 static unsigned long size_of_die (dw_die_ref);
6613 static void calc_die_sizes (dw_die_ref);
6614 static void calc_base_type_die_sizes (void);
6615 static void mark_dies (dw_die_ref);
6616 static void unmark_dies (dw_die_ref);
6617 static void unmark_all_dies (dw_die_ref);
6618 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6619 static unsigned long size_of_aranges (void);
6620 static enum dwarf_form value_format (dw_attr_ref);
6621 static void output_value_format (dw_attr_ref);
6622 static void output_abbrev_section (void);
6623 static void output_die_symbol (dw_die_ref);
6624 static void output_die (dw_die_ref);
6625 static void output_compilation_unit_header (void);
6626 static void output_comp_unit (dw_die_ref, int);
6627 static void output_comdat_type_unit (comdat_type_node *);
6628 static const char *dwarf2_name (tree, int);
6629 static void add_pubname (tree, dw_die_ref);
6630 static void add_pubname_string (const char *, dw_die_ref);
6631 static void add_pubtype (tree, dw_die_ref);
6632 static void output_pubnames (VEC (pubname_entry,gc) *);
6633 static void output_aranges (unsigned long);
6634 static unsigned int add_ranges_num (int);
6635 static unsigned int add_ranges (const_tree);
6636 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6638 static void output_ranges (void);
6639 static dw_line_info_table *new_line_info_table (void);
6640 static void output_line_info (void);
6641 static void output_file_names (void);
6642 static dw_die_ref base_type_die (tree);
6643 static int is_base_type (tree);
6644 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6645 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6646 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6647 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6648 static int type_is_enum (const_tree);
6649 static unsigned int dbx_reg_number (const_rtx);
6650 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6651 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6652 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6653 enum var_init_status);
6654 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6655 enum var_init_status);
6656 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6657 enum var_init_status);
6658 static int is_based_loc (const_rtx);
6659 static int resolve_one_addr (rtx *, void *);
6660 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6661 enum var_init_status);
6662 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6663 enum var_init_status);
6664 static dw_loc_list_ref loc_list_from_tree (tree, int);
6665 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6666 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6667 static tree field_type (const_tree);
6668 static unsigned int simple_type_align_in_bits (const_tree);
6669 static unsigned int simple_decl_align_in_bits (const_tree);
6670 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6671 static HOST_WIDE_INT field_byte_offset (const_tree);
6672 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6674 static void add_data_member_location_attribute (dw_die_ref, tree);
6675 static bool add_const_value_attribute (dw_die_ref, rtx);
6676 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6677 static void insert_double (double_int, unsigned char *);
6678 static void insert_float (const_rtx, unsigned char *);
6679 static rtx rtl_for_decl_location (tree);
6680 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
6681 enum dwarf_attribute);
6682 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6683 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6684 static void add_name_attribute (dw_die_ref, const char *);
6685 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
6686 static void add_comp_dir_attribute (dw_die_ref);
6687 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6688 static void add_subscript_info (dw_die_ref, tree, bool);
6689 static void add_byte_size_attribute (dw_die_ref, tree);
6690 static void add_bit_offset_attribute (dw_die_ref, tree);
6691 static void add_bit_size_attribute (dw_die_ref, tree);
6692 static void add_prototyped_attribute (dw_die_ref, tree);
6693 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6694 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6695 static void add_src_coords_attributes (dw_die_ref, tree);
6696 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6697 static void push_decl_scope (tree);
6698 static void pop_decl_scope (void);
6699 static dw_die_ref scope_die_for (tree, dw_die_ref);
6700 static inline int local_scope_p (dw_die_ref);
6701 static inline int class_scope_p (dw_die_ref);
6702 static inline int class_or_namespace_scope_p (dw_die_ref);
6703 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6704 static void add_calling_convention_attribute (dw_die_ref, tree);
6705 static const char *type_tag (const_tree);
6706 static tree member_declared_type (const_tree);
6708 static const char *decl_start_label (tree);
6710 static void gen_array_type_die (tree, dw_die_ref);
6711 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6713 static void gen_entry_point_die (tree, dw_die_ref);
6715 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6716 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6717 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6718 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6719 static void gen_formal_types_die (tree, dw_die_ref);
6720 static void gen_subprogram_die (tree, dw_die_ref);
6721 static void gen_variable_die (tree, tree, dw_die_ref);
6722 static void gen_const_die (tree, dw_die_ref);
6723 static void gen_label_die (tree, dw_die_ref);
6724 static void gen_lexical_block_die (tree, dw_die_ref, int);
6725 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6726 static void gen_field_die (tree, dw_die_ref);
6727 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6728 static dw_die_ref gen_compile_unit_die (const char *);
6729 static void gen_inheritance_die (tree, tree, dw_die_ref);
6730 static void gen_member_die (tree, dw_die_ref);
6731 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6732 enum debug_info_usage);
6733 static void gen_subroutine_type_die (tree, dw_die_ref);
6734 static void gen_typedef_die (tree, dw_die_ref);
6735 static void gen_type_die (tree, dw_die_ref);
6736 static void gen_block_die (tree, dw_die_ref, int);
6737 static void decls_for_scope (tree, dw_die_ref, int);
6738 static inline int is_redundant_typedef (const_tree);
6739 static bool is_naming_typedef_decl (const_tree);
6740 static inline dw_die_ref get_context_die (tree);
6741 static void gen_namespace_die (tree, dw_die_ref);
6742 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6743 static dw_die_ref force_decl_die (tree);
6744 static dw_die_ref force_type_die (tree);
6745 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6746 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6747 static struct dwarf_file_data * lookup_filename (const char *);
6748 static void retry_incomplete_types (void);
6749 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6750 static void gen_generic_params_dies (tree);
6751 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6752 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6753 static void splice_child_die (dw_die_ref, dw_die_ref);
6754 static int file_info_cmp (const void *, const void *);
6755 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6756 const char *, const char *);
6757 static void output_loc_list (dw_loc_list_ref);
6758 static char *gen_internal_sym (const char *);
6760 static void prune_unmark_dies (dw_die_ref);
6761 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6762 static void prune_unused_types_mark (dw_die_ref, int);
6763 static void prune_unused_types_walk (dw_die_ref);
6764 static void prune_unused_types_walk_attribs (dw_die_ref);
6765 static void prune_unused_types_prune (dw_die_ref);
6766 static void prune_unused_types (void);
6767 static int maybe_emit_file (struct dwarf_file_data *fd);
6768 static inline const char *AT_vms_delta1 (dw_attr_ref);
6769 static inline const char *AT_vms_delta2 (dw_attr_ref);
6770 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6771 const char *, const char *);
6772 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6773 static void gen_remaining_tmpl_value_param_die_attribute (void);
6774 static bool generic_type_p (tree);
6775 static void schedule_generic_params_dies_gen (tree t);
6776 static void gen_scheduled_generic_parms_dies (void);
6778 /* Section names used to hold DWARF debugging information. */
6779 #ifndef DEBUG_INFO_SECTION
6780 #define DEBUG_INFO_SECTION ".debug_info"
6782 #ifndef DEBUG_ABBREV_SECTION
6783 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6785 #ifndef DEBUG_ARANGES_SECTION
6786 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6788 #ifndef DEBUG_MACINFO_SECTION
6789 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6791 #ifndef DEBUG_LINE_SECTION
6792 #define DEBUG_LINE_SECTION ".debug_line"
6794 #ifndef DEBUG_LOC_SECTION
6795 #define DEBUG_LOC_SECTION ".debug_loc"
6797 #ifndef DEBUG_PUBNAMES_SECTION
6798 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6800 #ifndef DEBUG_PUBTYPES_SECTION
6801 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6803 #ifndef DEBUG_STR_SECTION
6804 #define DEBUG_STR_SECTION ".debug_str"
6806 #ifndef DEBUG_RANGES_SECTION
6807 #define DEBUG_RANGES_SECTION ".debug_ranges"
6810 /* Standard ELF section names for compiled code and data. */
6811 #ifndef TEXT_SECTION_NAME
6812 #define TEXT_SECTION_NAME ".text"
6815 /* Section flags for .debug_str section. */
6816 #define DEBUG_STR_SECTION_FLAGS \
6817 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6818 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6821 /* Labels we insert at beginning sections we can reference instead of
6822 the section names themselves. */
6824 #ifndef TEXT_SECTION_LABEL
6825 #define TEXT_SECTION_LABEL "Ltext"
6827 #ifndef COLD_TEXT_SECTION_LABEL
6828 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6830 #ifndef DEBUG_LINE_SECTION_LABEL
6831 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6833 #ifndef DEBUG_INFO_SECTION_LABEL
6834 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6836 #ifndef DEBUG_ABBREV_SECTION_LABEL
6837 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6839 #ifndef DEBUG_LOC_SECTION_LABEL
6840 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6842 #ifndef DEBUG_RANGES_SECTION_LABEL
6843 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6845 #ifndef DEBUG_MACINFO_SECTION_LABEL
6846 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6850 /* Definitions of defaults for formats and names of various special
6851 (artificial) labels which may be generated within this file (when the -g
6852 options is used and DWARF2_DEBUGGING_INFO is in effect.
6853 If necessary, these may be overridden from within the tm.h file, but
6854 typically, overriding these defaults is unnecessary. */
6856 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6857 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6858 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6859 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6860 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6861 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6862 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6863 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6864 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6865 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6867 #ifndef TEXT_END_LABEL
6868 #define TEXT_END_LABEL "Letext"
6870 #ifndef COLD_END_LABEL
6871 #define COLD_END_LABEL "Letext_cold"
6873 #ifndef BLOCK_BEGIN_LABEL
6874 #define BLOCK_BEGIN_LABEL "LBB"
6876 #ifndef BLOCK_END_LABEL
6877 #define BLOCK_END_LABEL "LBE"
6879 #ifndef LINE_CODE_LABEL
6880 #define LINE_CODE_LABEL "LM"
6884 /* Return the root of the DIE's built for the current compilation unit. */
6886 comp_unit_die (void)
6888 if (!single_comp_unit_die)
6889 single_comp_unit_die = gen_compile_unit_die (NULL);
6890 return single_comp_unit_die;
6893 /* We allow a language front-end to designate a function that is to be
6894 called to "demangle" any name before it is put into a DIE. */
6896 static const char *(*demangle_name_func) (const char *);
6899 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6901 demangle_name_func = func;
6904 /* Test if rtl node points to a pseudo register. */
6907 is_pseudo_reg (const_rtx rtl)
6909 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6910 || (GET_CODE (rtl) == SUBREG
6911 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6914 /* Return a reference to a type, with its const and volatile qualifiers
6918 type_main_variant (tree type)
6920 type = TYPE_MAIN_VARIANT (type);
6922 /* ??? There really should be only one main variant among any group of
6923 variants of a given type (and all of the MAIN_VARIANT values for all
6924 members of the group should point to that one type) but sometimes the C
6925 front-end messes this up for array types, so we work around that bug
6927 if (TREE_CODE (type) == ARRAY_TYPE)
6928 while (type != TYPE_MAIN_VARIANT (type))
6929 type = TYPE_MAIN_VARIANT (type);
6934 /* Return nonzero if the given type node represents a tagged type. */
6937 is_tagged_type (const_tree type)
6939 enum tree_code code = TREE_CODE (type);
6941 return (code == RECORD_TYPE || code == UNION_TYPE
6942 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6945 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6948 get_ref_die_offset_label (char *label, dw_die_ref ref)
6950 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6953 /* Return die_offset of a DIE reference to a base type. */
6955 static unsigned long int
6956 get_base_type_offset (dw_die_ref ref)
6958 if (ref->die_offset)
6959 return ref->die_offset;
6960 if (comp_unit_die ()->die_abbrev)
6962 calc_base_type_die_sizes ();
6963 gcc_assert (ref->die_offset);
6965 return ref->die_offset;
6968 /* Convert a DIE tag into its string name. */
6971 dwarf_tag_name (unsigned int tag)
6975 case DW_TAG_padding:
6976 return "DW_TAG_padding";
6977 case DW_TAG_array_type:
6978 return "DW_TAG_array_type";
6979 case DW_TAG_class_type:
6980 return "DW_TAG_class_type";
6981 case DW_TAG_entry_point:
6982 return "DW_TAG_entry_point";
6983 case DW_TAG_enumeration_type:
6984 return "DW_TAG_enumeration_type";
6985 case DW_TAG_formal_parameter:
6986 return "DW_TAG_formal_parameter";
6987 case DW_TAG_imported_declaration:
6988 return "DW_TAG_imported_declaration";
6990 return "DW_TAG_label";
6991 case DW_TAG_lexical_block:
6992 return "DW_TAG_lexical_block";
6994 return "DW_TAG_member";
6995 case DW_TAG_pointer_type:
6996 return "DW_TAG_pointer_type";
6997 case DW_TAG_reference_type:
6998 return "DW_TAG_reference_type";
6999 case DW_TAG_compile_unit:
7000 return "DW_TAG_compile_unit";
7001 case DW_TAG_string_type:
7002 return "DW_TAG_string_type";
7003 case DW_TAG_structure_type:
7004 return "DW_TAG_structure_type";
7005 case DW_TAG_subroutine_type:
7006 return "DW_TAG_subroutine_type";
7007 case DW_TAG_typedef:
7008 return "DW_TAG_typedef";
7009 case DW_TAG_union_type:
7010 return "DW_TAG_union_type";
7011 case DW_TAG_unspecified_parameters:
7012 return "DW_TAG_unspecified_parameters";
7013 case DW_TAG_variant:
7014 return "DW_TAG_variant";
7015 case DW_TAG_common_block:
7016 return "DW_TAG_common_block";
7017 case DW_TAG_common_inclusion:
7018 return "DW_TAG_common_inclusion";
7019 case DW_TAG_inheritance:
7020 return "DW_TAG_inheritance";
7021 case DW_TAG_inlined_subroutine:
7022 return "DW_TAG_inlined_subroutine";
7024 return "DW_TAG_module";
7025 case DW_TAG_ptr_to_member_type:
7026 return "DW_TAG_ptr_to_member_type";
7027 case DW_TAG_set_type:
7028 return "DW_TAG_set_type";
7029 case DW_TAG_subrange_type:
7030 return "DW_TAG_subrange_type";
7031 case DW_TAG_with_stmt:
7032 return "DW_TAG_with_stmt";
7033 case DW_TAG_access_declaration:
7034 return "DW_TAG_access_declaration";
7035 case DW_TAG_base_type:
7036 return "DW_TAG_base_type";
7037 case DW_TAG_catch_block:
7038 return "DW_TAG_catch_block";
7039 case DW_TAG_const_type:
7040 return "DW_TAG_const_type";
7041 case DW_TAG_constant:
7042 return "DW_TAG_constant";
7043 case DW_TAG_enumerator:
7044 return "DW_TAG_enumerator";
7045 case DW_TAG_file_type:
7046 return "DW_TAG_file_type";
7048 return "DW_TAG_friend";
7049 case DW_TAG_namelist:
7050 return "DW_TAG_namelist";
7051 case DW_TAG_namelist_item:
7052 return "DW_TAG_namelist_item";
7053 case DW_TAG_packed_type:
7054 return "DW_TAG_packed_type";
7055 case DW_TAG_subprogram:
7056 return "DW_TAG_subprogram";
7057 case DW_TAG_template_type_param:
7058 return "DW_TAG_template_type_param";
7059 case DW_TAG_template_value_param:
7060 return "DW_TAG_template_value_param";
7061 case DW_TAG_thrown_type:
7062 return "DW_TAG_thrown_type";
7063 case DW_TAG_try_block:
7064 return "DW_TAG_try_block";
7065 case DW_TAG_variant_part:
7066 return "DW_TAG_variant_part";
7067 case DW_TAG_variable:
7068 return "DW_TAG_variable";
7069 case DW_TAG_volatile_type:
7070 return "DW_TAG_volatile_type";
7071 case DW_TAG_dwarf_procedure:
7072 return "DW_TAG_dwarf_procedure";
7073 case DW_TAG_restrict_type:
7074 return "DW_TAG_restrict_type";
7075 case DW_TAG_interface_type:
7076 return "DW_TAG_interface_type";
7077 case DW_TAG_namespace:
7078 return "DW_TAG_namespace";
7079 case DW_TAG_imported_module:
7080 return "DW_TAG_imported_module";
7081 case DW_TAG_unspecified_type:
7082 return "DW_TAG_unspecified_type";
7083 case DW_TAG_partial_unit:
7084 return "DW_TAG_partial_unit";
7085 case DW_TAG_imported_unit:
7086 return "DW_TAG_imported_unit";
7087 case DW_TAG_condition:
7088 return "DW_TAG_condition";
7089 case DW_TAG_shared_type:
7090 return "DW_TAG_shared_type";
7091 case DW_TAG_type_unit:
7092 return "DW_TAG_type_unit";
7093 case DW_TAG_rvalue_reference_type:
7094 return "DW_TAG_rvalue_reference_type";
7095 case DW_TAG_template_alias:
7096 return "DW_TAG_template_alias";
7097 case DW_TAG_GNU_template_parameter_pack:
7098 return "DW_TAG_GNU_template_parameter_pack";
7099 case DW_TAG_GNU_formal_parameter_pack:
7100 return "DW_TAG_GNU_formal_parameter_pack";
7101 case DW_TAG_MIPS_loop:
7102 return "DW_TAG_MIPS_loop";
7103 case DW_TAG_format_label:
7104 return "DW_TAG_format_label";
7105 case DW_TAG_function_template:
7106 return "DW_TAG_function_template";
7107 case DW_TAG_class_template:
7108 return "DW_TAG_class_template";
7109 case DW_TAG_GNU_BINCL:
7110 return "DW_TAG_GNU_BINCL";
7111 case DW_TAG_GNU_EINCL:
7112 return "DW_TAG_GNU_EINCL";
7113 case DW_TAG_GNU_template_template_param:
7114 return "DW_TAG_GNU_template_template_param";
7115 case DW_TAG_GNU_call_site:
7116 return "DW_TAG_GNU_call_site";
7117 case DW_TAG_GNU_call_site_parameter:
7118 return "DW_TAG_GNU_call_site_parameter";
7120 return "DW_TAG_<unknown>";
7124 /* Convert a DWARF attribute code into its string name. */
7127 dwarf_attr_name (unsigned int attr)
7132 return "DW_AT_sibling";
7133 case DW_AT_location:
7134 return "DW_AT_location";
7136 return "DW_AT_name";
7137 case DW_AT_ordering:
7138 return "DW_AT_ordering";
7139 case DW_AT_subscr_data:
7140 return "DW_AT_subscr_data";
7141 case DW_AT_byte_size:
7142 return "DW_AT_byte_size";
7143 case DW_AT_bit_offset:
7144 return "DW_AT_bit_offset";
7145 case DW_AT_bit_size:
7146 return "DW_AT_bit_size";
7147 case DW_AT_element_list:
7148 return "DW_AT_element_list";
7149 case DW_AT_stmt_list:
7150 return "DW_AT_stmt_list";
7152 return "DW_AT_low_pc";
7154 return "DW_AT_high_pc";
7155 case DW_AT_language:
7156 return "DW_AT_language";
7158 return "DW_AT_member";
7160 return "DW_AT_discr";
7161 case DW_AT_discr_value:
7162 return "DW_AT_discr_value";
7163 case DW_AT_visibility:
7164 return "DW_AT_visibility";
7166 return "DW_AT_import";
7167 case DW_AT_string_length:
7168 return "DW_AT_string_length";
7169 case DW_AT_common_reference:
7170 return "DW_AT_common_reference";
7171 case DW_AT_comp_dir:
7172 return "DW_AT_comp_dir";
7173 case DW_AT_const_value:
7174 return "DW_AT_const_value";
7175 case DW_AT_containing_type:
7176 return "DW_AT_containing_type";
7177 case DW_AT_default_value:
7178 return "DW_AT_default_value";
7180 return "DW_AT_inline";
7181 case DW_AT_is_optional:
7182 return "DW_AT_is_optional";
7183 case DW_AT_lower_bound:
7184 return "DW_AT_lower_bound";
7185 case DW_AT_producer:
7186 return "DW_AT_producer";
7187 case DW_AT_prototyped:
7188 return "DW_AT_prototyped";
7189 case DW_AT_return_addr:
7190 return "DW_AT_return_addr";
7191 case DW_AT_start_scope:
7192 return "DW_AT_start_scope";
7193 case DW_AT_bit_stride:
7194 return "DW_AT_bit_stride";
7195 case DW_AT_upper_bound:
7196 return "DW_AT_upper_bound";
7197 case DW_AT_abstract_origin:
7198 return "DW_AT_abstract_origin";
7199 case DW_AT_accessibility:
7200 return "DW_AT_accessibility";
7201 case DW_AT_address_class:
7202 return "DW_AT_address_class";
7203 case DW_AT_artificial:
7204 return "DW_AT_artificial";
7205 case DW_AT_base_types:
7206 return "DW_AT_base_types";
7207 case DW_AT_calling_convention:
7208 return "DW_AT_calling_convention";
7210 return "DW_AT_count";
7211 case DW_AT_data_member_location:
7212 return "DW_AT_data_member_location";
7213 case DW_AT_decl_column:
7214 return "DW_AT_decl_column";
7215 case DW_AT_decl_file:
7216 return "DW_AT_decl_file";
7217 case DW_AT_decl_line:
7218 return "DW_AT_decl_line";
7219 case DW_AT_declaration:
7220 return "DW_AT_declaration";
7221 case DW_AT_discr_list:
7222 return "DW_AT_discr_list";
7223 case DW_AT_encoding:
7224 return "DW_AT_encoding";
7225 case DW_AT_external:
7226 return "DW_AT_external";
7227 case DW_AT_explicit:
7228 return "DW_AT_explicit";
7229 case DW_AT_frame_base:
7230 return "DW_AT_frame_base";
7232 return "DW_AT_friend";
7233 case DW_AT_identifier_case:
7234 return "DW_AT_identifier_case";
7235 case DW_AT_macro_info:
7236 return "DW_AT_macro_info";
7237 case DW_AT_namelist_items:
7238 return "DW_AT_namelist_items";
7239 case DW_AT_priority:
7240 return "DW_AT_priority";
7242 return "DW_AT_segment";
7243 case DW_AT_specification:
7244 return "DW_AT_specification";
7245 case DW_AT_static_link:
7246 return "DW_AT_static_link";
7248 return "DW_AT_type";
7249 case DW_AT_use_location:
7250 return "DW_AT_use_location";
7251 case DW_AT_variable_parameter:
7252 return "DW_AT_variable_parameter";
7253 case DW_AT_virtuality:
7254 return "DW_AT_virtuality";
7255 case DW_AT_vtable_elem_location:
7256 return "DW_AT_vtable_elem_location";
7258 case DW_AT_allocated:
7259 return "DW_AT_allocated";
7260 case DW_AT_associated:
7261 return "DW_AT_associated";
7262 case DW_AT_data_location:
7263 return "DW_AT_data_location";
7264 case DW_AT_byte_stride:
7265 return "DW_AT_byte_stride";
7266 case DW_AT_entry_pc:
7267 return "DW_AT_entry_pc";
7268 case DW_AT_use_UTF8:
7269 return "DW_AT_use_UTF8";
7270 case DW_AT_extension:
7271 return "DW_AT_extension";
7273 return "DW_AT_ranges";
7274 case DW_AT_trampoline:
7275 return "DW_AT_trampoline";
7276 case DW_AT_call_column:
7277 return "DW_AT_call_column";
7278 case DW_AT_call_file:
7279 return "DW_AT_call_file";
7280 case DW_AT_call_line:
7281 return "DW_AT_call_line";
7282 case DW_AT_object_pointer:
7283 return "DW_AT_object_pointer";
7285 case DW_AT_signature:
7286 return "DW_AT_signature";
7287 case DW_AT_main_subprogram:
7288 return "DW_AT_main_subprogram";
7289 case DW_AT_data_bit_offset:
7290 return "DW_AT_data_bit_offset";
7291 case DW_AT_const_expr:
7292 return "DW_AT_const_expr";
7293 case DW_AT_enum_class:
7294 return "DW_AT_enum_class";
7295 case DW_AT_linkage_name:
7296 return "DW_AT_linkage_name";
7298 case DW_AT_MIPS_fde:
7299 return "DW_AT_MIPS_fde";
7300 case DW_AT_MIPS_loop_begin:
7301 return "DW_AT_MIPS_loop_begin";
7302 case DW_AT_MIPS_tail_loop_begin:
7303 return "DW_AT_MIPS_tail_loop_begin";
7304 case DW_AT_MIPS_epilog_begin:
7305 return "DW_AT_MIPS_epilog_begin";
7306 #if VMS_DEBUGGING_INFO
7307 case DW_AT_HP_prologue:
7308 return "DW_AT_HP_prologue";
7310 case DW_AT_MIPS_loop_unroll_factor:
7311 return "DW_AT_MIPS_loop_unroll_factor";
7313 case DW_AT_MIPS_software_pipeline_depth:
7314 return "DW_AT_MIPS_software_pipeline_depth";
7315 case DW_AT_MIPS_linkage_name:
7316 return "DW_AT_MIPS_linkage_name";
7317 #if VMS_DEBUGGING_INFO
7318 case DW_AT_HP_epilogue:
7319 return "DW_AT_HP_epilogue";
7321 case DW_AT_MIPS_stride:
7322 return "DW_AT_MIPS_stride";
7324 case DW_AT_MIPS_abstract_name:
7325 return "DW_AT_MIPS_abstract_name";
7326 case DW_AT_MIPS_clone_origin:
7327 return "DW_AT_MIPS_clone_origin";
7328 case DW_AT_MIPS_has_inlines:
7329 return "DW_AT_MIPS_has_inlines";
7331 case DW_AT_sf_names:
7332 return "DW_AT_sf_names";
7333 case DW_AT_src_info:
7334 return "DW_AT_src_info";
7335 case DW_AT_mac_info:
7336 return "DW_AT_mac_info";
7337 case DW_AT_src_coords:
7338 return "DW_AT_src_coords";
7339 case DW_AT_body_begin:
7340 return "DW_AT_body_begin";
7341 case DW_AT_body_end:
7342 return "DW_AT_body_end";
7344 case DW_AT_GNU_vector:
7345 return "DW_AT_GNU_vector";
7346 case DW_AT_GNU_guarded_by:
7347 return "DW_AT_GNU_guarded_by";
7348 case DW_AT_GNU_pt_guarded_by:
7349 return "DW_AT_GNU_pt_guarded_by";
7350 case DW_AT_GNU_guarded:
7351 return "DW_AT_GNU_guarded";
7352 case DW_AT_GNU_pt_guarded:
7353 return "DW_AT_GNU_pt_guarded";
7354 case DW_AT_GNU_locks_excluded:
7355 return "DW_AT_GNU_locks_excluded";
7356 case DW_AT_GNU_exclusive_locks_required:
7357 return "DW_AT_GNU_exclusive_locks_required";
7358 case DW_AT_GNU_shared_locks_required:
7359 return "DW_AT_GNU_shared_locks_required";
7360 case DW_AT_GNU_odr_signature:
7361 return "DW_AT_GNU_odr_signature";
7362 case DW_AT_GNU_template_name:
7363 return "DW_AT_GNU_template_name";
7364 case DW_AT_GNU_call_site_value:
7365 return "DW_AT_GNU_call_site_value";
7366 case DW_AT_GNU_call_site_data_value:
7367 return "DW_AT_GNU_call_site_data_value";
7368 case DW_AT_GNU_call_site_target:
7369 return "DW_AT_GNU_call_site_target";
7370 case DW_AT_GNU_call_site_target_clobbered:
7371 return "DW_AT_GNU_call_site_target_clobbered";
7372 case DW_AT_GNU_tail_call:
7373 return "DW_AT_GNU_tail_call";
7374 case DW_AT_GNU_all_tail_call_sites:
7375 return "DW_AT_GNU_all_tail_call_sites";
7376 case DW_AT_GNU_all_call_sites:
7377 return "DW_AT_GNU_all_call_sites";
7378 case DW_AT_GNU_all_source_call_sites:
7379 return "DW_AT_GNU_all_source_call_sites";
7381 case DW_AT_GNAT_descriptive_type:
7382 return "DW_AT_GNAT_descriptive_type";
7384 case DW_AT_VMS_rtnbeg_pd_address:
7385 return "DW_AT_VMS_rtnbeg_pd_address";
7388 return "DW_AT_<unknown>";
7392 /* Convert a DWARF value form code into its string name. */
7395 dwarf_form_name (unsigned int form)
7400 return "DW_FORM_addr";
7401 case DW_FORM_block2:
7402 return "DW_FORM_block2";
7403 case DW_FORM_block4:
7404 return "DW_FORM_block4";
7406 return "DW_FORM_data2";
7408 return "DW_FORM_data4";
7410 return "DW_FORM_data8";
7411 case DW_FORM_string:
7412 return "DW_FORM_string";
7414 return "DW_FORM_block";
7415 case DW_FORM_block1:
7416 return "DW_FORM_block1";
7418 return "DW_FORM_data1";
7420 return "DW_FORM_flag";
7422 return "DW_FORM_sdata";
7424 return "DW_FORM_strp";
7426 return "DW_FORM_udata";
7427 case DW_FORM_ref_addr:
7428 return "DW_FORM_ref_addr";
7430 return "DW_FORM_ref1";
7432 return "DW_FORM_ref2";
7434 return "DW_FORM_ref4";
7436 return "DW_FORM_ref8";
7437 case DW_FORM_ref_udata:
7438 return "DW_FORM_ref_udata";
7439 case DW_FORM_indirect:
7440 return "DW_FORM_indirect";
7441 case DW_FORM_sec_offset:
7442 return "DW_FORM_sec_offset";
7443 case DW_FORM_exprloc:
7444 return "DW_FORM_exprloc";
7445 case DW_FORM_flag_present:
7446 return "DW_FORM_flag_present";
7447 case DW_FORM_ref_sig8:
7448 return "DW_FORM_ref_sig8";
7450 return "DW_FORM_<unknown>";
7454 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7455 instance of an inlined instance of a decl which is local to an inline
7456 function, so we have to trace all of the way back through the origin chain
7457 to find out what sort of node actually served as the original seed for the
7461 decl_ultimate_origin (const_tree decl)
7463 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7466 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7467 nodes in the function to point to themselves; ignore that if
7468 we're trying to output the abstract instance of this function. */
7469 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7472 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7473 most distant ancestor, this should never happen. */
7474 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7476 return DECL_ABSTRACT_ORIGIN (decl);
7479 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7480 of a virtual function may refer to a base class, so we check the 'this'
7484 decl_class_context (tree decl)
7486 tree context = NULL_TREE;
7488 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7489 context = DECL_CONTEXT (decl);
7491 context = TYPE_MAIN_VARIANT
7492 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7494 if (context && !TYPE_P (context))
7495 context = NULL_TREE;
7500 /* Add an attribute/value pair to a DIE. */
7503 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7505 /* Maybe this should be an assert? */
7509 if (die->die_attr == NULL)
7510 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7511 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7514 static inline enum dw_val_class
7515 AT_class (dw_attr_ref a)
7517 return a->dw_attr_val.val_class;
7520 /* Add a flag value attribute to a DIE. */
7523 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7527 attr.dw_attr = attr_kind;
7528 attr.dw_attr_val.val_class = dw_val_class_flag;
7529 attr.dw_attr_val.v.val_flag = flag;
7530 add_dwarf_attr (die, &attr);
7533 static inline unsigned
7534 AT_flag (dw_attr_ref a)
7536 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7537 return a->dw_attr_val.v.val_flag;
7540 /* Add a signed integer attribute value to a DIE. */
7543 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7547 attr.dw_attr = attr_kind;
7548 attr.dw_attr_val.val_class = dw_val_class_const;
7549 attr.dw_attr_val.v.val_int = int_val;
7550 add_dwarf_attr (die, &attr);
7553 static inline HOST_WIDE_INT
7554 AT_int (dw_attr_ref a)
7556 gcc_assert (a && AT_class (a) == dw_val_class_const);
7557 return a->dw_attr_val.v.val_int;
7560 /* Add an unsigned integer attribute value to a DIE. */
7563 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7564 unsigned HOST_WIDE_INT unsigned_val)
7568 attr.dw_attr = attr_kind;
7569 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7570 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7571 add_dwarf_attr (die, &attr);
7574 static inline unsigned HOST_WIDE_INT
7575 AT_unsigned (dw_attr_ref a)
7577 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7578 return a->dw_attr_val.v.val_unsigned;
7581 /* Add an unsigned double integer attribute value to a DIE. */
7584 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7585 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7589 attr.dw_attr = attr_kind;
7590 attr.dw_attr_val.val_class = dw_val_class_const_double;
7591 attr.dw_attr_val.v.val_double.high = high;
7592 attr.dw_attr_val.v.val_double.low = low;
7593 add_dwarf_attr (die, &attr);
7596 /* Add a floating point attribute value to a DIE and return it. */
7599 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7600 unsigned int length, unsigned int elt_size, unsigned char *array)
7604 attr.dw_attr = attr_kind;
7605 attr.dw_attr_val.val_class = dw_val_class_vec;
7606 attr.dw_attr_val.v.val_vec.length = length;
7607 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7608 attr.dw_attr_val.v.val_vec.array = array;
7609 add_dwarf_attr (die, &attr);
7612 /* Add an 8-byte data attribute value to a DIE. */
7615 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7616 unsigned char data8[8])
7620 attr.dw_attr = attr_kind;
7621 attr.dw_attr_val.val_class = dw_val_class_data8;
7622 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7623 add_dwarf_attr (die, &attr);
7626 /* Hash and equality functions for debug_str_hash. */
7629 debug_str_do_hash (const void *x)
7631 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7635 debug_str_eq (const void *x1, const void *x2)
7637 return strcmp ((((const struct indirect_string_node *)x1)->str),
7638 (const char *)x2) == 0;
7641 /* Add STR to the indirect string hash table. */
7643 static struct indirect_string_node *
7644 find_AT_string (const char *str)
7646 struct indirect_string_node *node;
7649 if (! debug_str_hash)
7650 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7651 debug_str_eq, NULL);
7653 slot = htab_find_slot_with_hash (debug_str_hash, str,
7654 htab_hash_string (str), INSERT);
7657 node = ggc_alloc_cleared_indirect_string_node ();
7658 node->str = ggc_strdup (str);
7662 node = (struct indirect_string_node *) *slot;
7668 /* Add a string attribute value to a DIE. */
7671 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7674 struct indirect_string_node *node;
7676 node = find_AT_string (str);
7678 attr.dw_attr = attr_kind;
7679 attr.dw_attr_val.val_class = dw_val_class_str;
7680 attr.dw_attr_val.v.val_str = node;
7681 add_dwarf_attr (die, &attr);
7684 static inline const char *
7685 AT_string (dw_attr_ref a)
7687 gcc_assert (a && AT_class (a) == dw_val_class_str);
7688 return a->dw_attr_val.v.val_str->str;
7691 /* Find out whether a string should be output inline in DIE
7692 or out-of-line in .debug_str section. */
7694 static enum dwarf_form
7695 AT_string_form (dw_attr_ref a)
7697 struct indirect_string_node *node;
7701 gcc_assert (a && AT_class (a) == dw_val_class_str);
7703 node = a->dw_attr_val.v.val_str;
7707 len = strlen (node->str) + 1;
7709 /* If the string is shorter or equal to the size of the reference, it is
7710 always better to put it inline. */
7711 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7712 return node->form = DW_FORM_string;
7714 /* If we cannot expect the linker to merge strings in .debug_str
7715 section, only put it into .debug_str if it is worth even in this
7717 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7718 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7719 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7720 return node->form = DW_FORM_string;
7722 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7723 ++dw2_string_counter;
7724 node->label = xstrdup (label);
7726 return node->form = DW_FORM_strp;
7729 /* Add a DIE reference attribute value to a DIE. */
7732 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7736 #ifdef ENABLE_CHECKING
7737 gcc_assert (targ_die != NULL);
7739 /* With LTO we can end up trying to reference something we didn't create
7740 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7741 if (targ_die == NULL)
7745 attr.dw_attr = attr_kind;
7746 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7747 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7748 attr.dw_attr_val.v.val_die_ref.external = 0;
7749 add_dwarf_attr (die, &attr);
7752 /* Add an AT_specification attribute to a DIE, and also make the back
7753 pointer from the specification to the definition. */
7756 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7758 add_AT_die_ref (die, DW_AT_specification, targ_die);
7759 gcc_assert (!targ_die->die_definition);
7760 targ_die->die_definition = die;
7763 static inline dw_die_ref
7764 AT_ref (dw_attr_ref a)
7766 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7767 return a->dw_attr_val.v.val_die_ref.die;
7771 AT_ref_external (dw_attr_ref a)
7773 if (a && AT_class (a) == dw_val_class_die_ref)
7774 return a->dw_attr_val.v.val_die_ref.external;
7780 set_AT_ref_external (dw_attr_ref a, int i)
7782 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7783 a->dw_attr_val.v.val_die_ref.external = i;
7786 /* Add an FDE reference attribute value to a DIE. */
7789 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7793 attr.dw_attr = attr_kind;
7794 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7795 attr.dw_attr_val.v.val_fde_index = targ_fde;
7796 add_dwarf_attr (die, &attr);
7799 /* Add a location description attribute value to a DIE. */
7802 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7806 attr.dw_attr = attr_kind;
7807 attr.dw_attr_val.val_class = dw_val_class_loc;
7808 attr.dw_attr_val.v.val_loc = loc;
7809 add_dwarf_attr (die, &attr);
7812 static inline dw_loc_descr_ref
7813 AT_loc (dw_attr_ref a)
7815 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7816 return a->dw_attr_val.v.val_loc;
7820 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7824 attr.dw_attr = attr_kind;
7825 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7826 attr.dw_attr_val.v.val_loc_list = loc_list;
7827 add_dwarf_attr (die, &attr);
7828 have_location_lists = true;
7831 static inline dw_loc_list_ref
7832 AT_loc_list (dw_attr_ref a)
7834 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7835 return a->dw_attr_val.v.val_loc_list;
7838 static inline dw_loc_list_ref *
7839 AT_loc_list_ptr (dw_attr_ref a)
7841 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7842 return &a->dw_attr_val.v.val_loc_list;
7845 /* Add an address constant attribute value to a DIE. */
7848 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7852 attr.dw_attr = attr_kind;
7853 attr.dw_attr_val.val_class = dw_val_class_addr;
7854 attr.dw_attr_val.v.val_addr = addr;
7855 add_dwarf_attr (die, &attr);
7858 /* Get the RTX from to an address DIE attribute. */
7861 AT_addr (dw_attr_ref a)
7863 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7864 return a->dw_attr_val.v.val_addr;
7867 /* Add a file attribute value to a DIE. */
7870 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7871 struct dwarf_file_data *fd)
7875 attr.dw_attr = attr_kind;
7876 attr.dw_attr_val.val_class = dw_val_class_file;
7877 attr.dw_attr_val.v.val_file = fd;
7878 add_dwarf_attr (die, &attr);
7881 /* Get the dwarf_file_data from a file DIE attribute. */
7883 static inline struct dwarf_file_data *
7884 AT_file (dw_attr_ref a)
7886 gcc_assert (a && AT_class (a) == dw_val_class_file);
7887 return a->dw_attr_val.v.val_file;
7890 /* Add a vms delta attribute value to a DIE. */
7893 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7894 const char *lbl1, const char *lbl2)
7898 attr.dw_attr = attr_kind;
7899 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7900 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7901 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7902 add_dwarf_attr (die, &attr);
7905 /* Add a label identifier attribute value to a DIE. */
7908 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7912 attr.dw_attr = attr_kind;
7913 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7914 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7915 add_dwarf_attr (die, &attr);
7918 /* Add a section offset attribute value to a DIE, an offset into the
7919 debug_line section. */
7922 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7927 attr.dw_attr = attr_kind;
7928 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7929 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7930 add_dwarf_attr (die, &attr);
7933 /* Add a section offset attribute value to a DIE, an offset into the
7934 debug_macinfo section. */
7937 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7942 attr.dw_attr = attr_kind;
7943 attr.dw_attr_val.val_class = dw_val_class_macptr;
7944 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7945 add_dwarf_attr (die, &attr);
7948 /* Add an offset attribute value to a DIE. */
7951 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7952 unsigned HOST_WIDE_INT offset)
7956 attr.dw_attr = attr_kind;
7957 attr.dw_attr_val.val_class = dw_val_class_offset;
7958 attr.dw_attr_val.v.val_offset = offset;
7959 add_dwarf_attr (die, &attr);
7962 /* Add an range_list attribute value to a DIE. */
7965 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7966 long unsigned int offset)
7970 attr.dw_attr = attr_kind;
7971 attr.dw_attr_val.val_class = dw_val_class_range_list;
7972 attr.dw_attr_val.v.val_offset = offset;
7973 add_dwarf_attr (die, &attr);
7976 /* Return the start label of a delta attribute. */
7978 static inline const char *
7979 AT_vms_delta1 (dw_attr_ref a)
7981 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7982 return a->dw_attr_val.v.val_vms_delta.lbl1;
7985 /* Return the end label of a delta attribute. */
7987 static inline const char *
7988 AT_vms_delta2 (dw_attr_ref a)
7990 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7991 return a->dw_attr_val.v.val_vms_delta.lbl2;
7994 static inline const char *
7995 AT_lbl (dw_attr_ref a)
7997 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7998 || AT_class (a) == dw_val_class_lineptr
7999 || AT_class (a) == dw_val_class_macptr));
8000 return a->dw_attr_val.v.val_lbl_id;
8003 /* Get the attribute of type attr_kind. */
8006 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
8010 dw_die_ref spec = NULL;
8015 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8016 if (a->dw_attr == attr_kind)
8018 else if (a->dw_attr == DW_AT_specification
8019 || a->dw_attr == DW_AT_abstract_origin)
8023 return get_AT (spec, attr_kind);
8028 /* Return the "low pc" attribute value, typically associated with a subprogram
8029 DIE. Return null if the "low pc" attribute is either not present, or if it
8030 cannot be represented as an assembler label identifier. */
8032 static inline const char *
8033 get_AT_low_pc (dw_die_ref die)
8035 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
8037 return a ? AT_lbl (a) : NULL;
8040 /* Return the "high pc" attribute value, typically associated with a subprogram
8041 DIE. Return null if the "high pc" attribute is either not present, or if it
8042 cannot be represented as an assembler label identifier. */
8044 static inline const char *
8045 get_AT_hi_pc (dw_die_ref die)
8047 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
8049 return a ? AT_lbl (a) : NULL;
8052 /* Return the value of the string attribute designated by ATTR_KIND, or
8053 NULL if it is not present. */
8055 static inline const char *
8056 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
8058 dw_attr_ref a = get_AT (die, attr_kind);
8060 return a ? AT_string (a) : NULL;
8063 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
8064 if it is not present. */
8067 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
8069 dw_attr_ref a = get_AT (die, attr_kind);
8071 return a ? AT_flag (a) : 0;
8074 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
8075 if it is not present. */
8077 static inline unsigned
8078 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
8080 dw_attr_ref a = get_AT (die, attr_kind);
8082 return a ? AT_unsigned (a) : 0;
8085 static inline dw_die_ref
8086 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
8088 dw_attr_ref a = get_AT (die, attr_kind);
8090 return a ? AT_ref (a) : NULL;
8093 static inline struct dwarf_file_data *
8094 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
8096 dw_attr_ref a = get_AT (die, attr_kind);
8098 return a ? AT_file (a) : NULL;
8101 /* Return TRUE if the language is C++. */
8106 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8108 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
8111 /* Return TRUE if the language is Fortran. */
8116 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8118 return (lang == DW_LANG_Fortran77
8119 || lang == DW_LANG_Fortran90
8120 || lang == DW_LANG_Fortran95);
8123 /* Return TRUE if the language is Ada. */
8128 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
8130 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
8133 /* Remove the specified attribute if present. */
8136 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
8144 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8145 if (a->dw_attr == attr_kind)
8147 if (AT_class (a) == dw_val_class_str)
8148 if (a->dw_attr_val.v.val_str->refcount)
8149 a->dw_attr_val.v.val_str->refcount--;
8151 /* VEC_ordered_remove should help reduce the number of abbrevs
8153 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
8158 /* Remove CHILD from its parent. PREV must have the property that
8159 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
8162 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
8164 gcc_assert (child->die_parent == prev->die_parent);
8165 gcc_assert (prev->die_sib == child);
8168 gcc_assert (child->die_parent->die_child == child);
8172 prev->die_sib = child->die_sib;
8173 if (child->die_parent->die_child == child)
8174 child->die_parent->die_child = prev;
8177 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
8178 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
8181 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
8183 dw_die_ref parent = old_child->die_parent;
8185 gcc_assert (parent == prev->die_parent);
8186 gcc_assert (prev->die_sib == old_child);
8188 new_child->die_parent = parent;
8189 if (prev == old_child)
8191 gcc_assert (parent->die_child == old_child);
8192 new_child->die_sib = new_child;
8196 prev->die_sib = new_child;
8197 new_child->die_sib = old_child->die_sib;
8199 if (old_child->die_parent->die_child == old_child)
8200 old_child->die_parent->die_child = new_child;
8203 /* Move all children from OLD_PARENT to NEW_PARENT. */
8206 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
8209 new_parent->die_child = old_parent->die_child;
8210 old_parent->die_child = NULL;
8211 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
8214 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8218 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8224 dw_die_ref prev = c;
8226 while (c->die_tag == tag)
8228 remove_child_with_prev (c, prev);
8229 /* Might have removed every child. */
8230 if (c == c->die_sib)
8234 } while (c != die->die_child);
8237 /* Add a CHILD_DIE as the last child of DIE. */
8240 add_child_die (dw_die_ref die, dw_die_ref child_die)
8242 /* FIXME this should probably be an assert. */
8243 if (! die || ! child_die)
8245 gcc_assert (die != child_die);
8247 child_die->die_parent = die;
8250 child_die->die_sib = die->die_child->die_sib;
8251 die->die_child->die_sib = child_die;
8254 child_die->die_sib = child_die;
8255 die->die_child = child_die;
8258 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8259 is the specification, to the end of PARENT's list of children.
8260 This is done by removing and re-adding it. */
8263 splice_child_die (dw_die_ref parent, dw_die_ref child)
8267 /* We want the declaration DIE from inside the class, not the
8268 specification DIE at toplevel. */
8269 if (child->die_parent != parent)
8271 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8277 gcc_assert (child->die_parent == parent
8278 || (child->die_parent
8279 == get_AT_ref (parent, DW_AT_specification)));
8281 for (p = child->die_parent->die_child; ; p = p->die_sib)
8282 if (p->die_sib == child)
8284 remove_child_with_prev (child, p);
8288 add_child_die (parent, child);
8291 /* Return a pointer to a newly created DIE node. */
8293 static inline dw_die_ref
8294 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8296 dw_die_ref die = ggc_alloc_cleared_die_node ();
8298 die->die_tag = tag_value;
8300 if (parent_die != NULL)
8301 add_child_die (parent_die, die);
8304 limbo_die_node *limbo_node;
8306 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8307 limbo_node->die = die;
8308 limbo_node->created_for = t;
8309 limbo_node->next = limbo_die_list;
8310 limbo_die_list = limbo_node;
8316 /* Return the DIE associated with the given type specifier. */
8318 static inline dw_die_ref
8319 lookup_type_die (tree type)
8321 return TYPE_SYMTAB_DIE (type);
8324 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8325 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8326 anonymous type instead the one of the naming typedef. */
8328 static inline dw_die_ref
8329 strip_naming_typedef (tree type, dw_die_ref type_die)
8332 && TREE_CODE (type) == RECORD_TYPE
8334 && type_die->die_tag == DW_TAG_typedef
8335 && is_naming_typedef_decl (TYPE_NAME (type)))
8336 type_die = get_AT_ref (type_die, DW_AT_type);
8340 /* Like lookup_type_die, but if type is an anonymous type named by a
8341 typedef[1], return the DIE of the anonymous type instead the one of
8342 the naming typedef. This is because in gen_typedef_die, we did
8343 equate the anonymous struct named by the typedef with the DIE of
8344 the naming typedef. So by default, lookup_type_die on an anonymous
8345 struct yields the DIE of the naming typedef.
8347 [1]: Read the comment of is_naming_typedef_decl to learn about what
8348 a naming typedef is. */
8350 static inline dw_die_ref
8351 lookup_type_die_strip_naming_typedef (tree type)
8353 dw_die_ref die = lookup_type_die (type);
8354 return strip_naming_typedef (type, die);
8357 /* Equate a DIE to a given type specifier. */
8360 equate_type_number_to_die (tree type, dw_die_ref type_die)
8362 TYPE_SYMTAB_DIE (type) = type_die;
8365 /* Returns a hash value for X (which really is a die_struct). */
8368 decl_die_table_hash (const void *x)
8370 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8373 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8376 decl_die_table_eq (const void *x, const void *y)
8378 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8381 /* Return the DIE associated with a given declaration. */
8383 static inline dw_die_ref
8384 lookup_decl_die (tree decl)
8386 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8389 /* Returns a hash value for X (which really is a var_loc_list). */
8392 decl_loc_table_hash (const void *x)
8394 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8397 /* Return nonzero if decl_id of var_loc_list X is the same as
8401 decl_loc_table_eq (const void *x, const void *y)
8403 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8406 /* Return the var_loc list associated with a given declaration. */
8408 static inline var_loc_list *
8409 lookup_decl_loc (const_tree decl)
8411 if (!decl_loc_table)
8413 return (var_loc_list *)
8414 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8417 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
8420 cached_dw_loc_list_table_hash (const void *x)
8422 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
8425 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
8429 cached_dw_loc_list_table_eq (const void *x, const void *y)
8431 return (((const cached_dw_loc_list *) x)->decl_id
8432 == DECL_UID ((const_tree) y));
8435 /* Equate a DIE to a particular declaration. */
8438 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8440 unsigned int decl_id = DECL_UID (decl);
8443 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8445 decl_die->decl_id = decl_id;
8448 /* Return how many bits covers PIECE EXPR_LIST. */
8451 decl_piece_bitsize (rtx piece)
8453 int ret = (int) GET_MODE (piece);
8456 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8457 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8458 return INTVAL (XEXP (XEXP (piece, 0), 0));
8461 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8464 decl_piece_varloc_ptr (rtx piece)
8466 if ((int) GET_MODE (piece))
8467 return &XEXP (piece, 0);
8469 return &XEXP (XEXP (piece, 0), 1);
8472 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8473 Next is the chain of following piece nodes. */
8476 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8478 if (bitsize <= (int) MAX_MACHINE_MODE)
8479 return alloc_EXPR_LIST (bitsize, loc_note, next);
8481 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8486 /* Return rtx that should be stored into loc field for
8487 LOC_NOTE and BITPOS/BITSIZE. */
8490 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8491 HOST_WIDE_INT bitsize)
8495 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8497 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8502 /* This function either modifies location piece list *DEST in
8503 place (if SRC and INNER is NULL), or copies location piece list
8504 *SRC to *DEST while modifying it. Location BITPOS is modified
8505 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8506 not copied and if needed some padding around it is added.
8507 When modifying in place, DEST should point to EXPR_LIST where
8508 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8509 to the start of the whole list and INNER points to the EXPR_LIST
8510 where earlier pieces cover PIECE_BITPOS bits. */
8513 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8514 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8515 HOST_WIDE_INT bitsize, rtx loc_note)
8518 bool copy = inner != NULL;
8522 /* First copy all nodes preceeding the current bitpos. */
8523 while (src != inner)
8525 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8526 decl_piece_bitsize (*src), NULL_RTX);
8527 dest = &XEXP (*dest, 1);
8528 src = &XEXP (*src, 1);
8531 /* Add padding if needed. */
8532 if (bitpos != piece_bitpos)
8534 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8535 copy ? NULL_RTX : *dest);
8536 dest = &XEXP (*dest, 1);
8538 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8541 /* A piece with correct bitpos and bitsize already exist,
8542 just update the location for it and return. */
8543 *decl_piece_varloc_ptr (*dest) = loc_note;
8546 /* Add the piece that changed. */
8547 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8548 dest = &XEXP (*dest, 1);
8549 /* Skip over pieces that overlap it. */
8550 diff = bitpos - piece_bitpos + bitsize;
8553 while (diff > 0 && *src)
8556 diff -= decl_piece_bitsize (piece);
8558 src = &XEXP (piece, 1);
8561 *src = XEXP (piece, 1);
8562 free_EXPR_LIST_node (piece);
8565 /* Add padding if needed. */
8566 if (diff < 0 && *src)
8570 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8571 dest = &XEXP (*dest, 1);
8575 /* Finally copy all nodes following it. */
8578 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8579 decl_piece_bitsize (*src), NULL_RTX);
8580 dest = &XEXP (*dest, 1);
8581 src = &XEXP (*src, 1);
8585 /* Add a variable location node to the linked list for DECL. */
8587 static struct var_loc_node *
8588 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8590 unsigned int decl_id;
8593 struct var_loc_node *loc = NULL;
8594 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8596 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8598 tree realdecl = DECL_DEBUG_EXPR (decl);
8599 if (realdecl && handled_component_p (realdecl))
8601 HOST_WIDE_INT maxsize;
8604 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8605 if (!DECL_P (innerdecl)
8606 || DECL_IGNORED_P (innerdecl)
8607 || TREE_STATIC (innerdecl)
8609 || bitpos + bitsize > 256
8610 || bitsize != maxsize)
8616 decl_id = DECL_UID (decl);
8617 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8620 temp = ggc_alloc_cleared_var_loc_list ();
8621 temp->decl_id = decl_id;
8625 temp = (var_loc_list *) *slot;
8627 /* For PARM_DECLs try to keep around the original incoming value,
8628 even if that means we'll emit a zero-range .debug_loc entry. */
8630 && temp->first == temp->last
8631 && TREE_CODE (decl) == PARM_DECL
8632 && GET_CODE (temp->first->loc) == NOTE
8633 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
8634 && DECL_INCOMING_RTL (decl)
8635 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
8636 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
8637 == GET_CODE (DECL_INCOMING_RTL (decl))
8638 && prev_real_insn (temp->first->loc) == NULL_RTX
8640 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
8641 NOTE_VAR_LOCATION_LOC (loc_note))
8642 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
8643 != NOTE_VAR_LOCATION_STATUS (loc_note))))
8645 loc = ggc_alloc_cleared_var_loc_node ();
8646 temp->first->next = loc;
8648 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8650 else if (temp->last)
8652 struct var_loc_node *last = temp->last, *unused = NULL;
8653 rtx *piece_loc = NULL, last_loc_note;
8654 int piece_bitpos = 0;
8658 gcc_assert (last->next == NULL);
8660 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8662 piece_loc = &last->loc;
8665 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8666 if (piece_bitpos + cur_bitsize > bitpos)
8668 piece_bitpos += cur_bitsize;
8669 piece_loc = &XEXP (*piece_loc, 1);
8673 /* TEMP->LAST here is either pointer to the last but one or
8674 last element in the chained list, LAST is pointer to the
8676 if (label && strcmp (last->label, label) == 0)
8678 /* For SRA optimized variables if there weren't any real
8679 insns since last note, just modify the last node. */
8680 if (piece_loc != NULL)
8682 adjust_piece_list (piece_loc, NULL, NULL,
8683 bitpos, piece_bitpos, bitsize, loc_note);
8686 /* If the last note doesn't cover any instructions, remove it. */
8687 if (temp->last != last)
8689 temp->last->next = NULL;
8692 gcc_assert (strcmp (last->label, label) != 0);
8696 gcc_assert (temp->first == temp->last
8697 || (temp->first->next == temp->last
8698 && TREE_CODE (decl) == PARM_DECL));
8699 memset (temp->last, '\0', sizeof (*temp->last));
8700 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8704 if (bitsize == -1 && NOTE_P (last->loc))
8705 last_loc_note = last->loc;
8706 else if (piece_loc != NULL
8707 && *piece_loc != NULL_RTX
8708 && piece_bitpos == bitpos
8709 && decl_piece_bitsize (*piece_loc) == bitsize)
8710 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8712 last_loc_note = NULL_RTX;
8713 /* If the current location is the same as the end of the list,
8714 and either both or neither of the locations is uninitialized,
8715 we have nothing to do. */
8716 if (last_loc_note == NULL_RTX
8717 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8718 NOTE_VAR_LOCATION_LOC (loc_note)))
8719 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8720 != NOTE_VAR_LOCATION_STATUS (loc_note))
8721 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8722 == VAR_INIT_STATUS_UNINITIALIZED)
8723 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8724 == VAR_INIT_STATUS_UNINITIALIZED))))
8726 /* Add LOC to the end of list and update LAST. If the last
8727 element of the list has been removed above, reuse its
8728 memory for the new node, otherwise allocate a new one. */
8732 memset (loc, '\0', sizeof (*loc));
8735 loc = ggc_alloc_cleared_var_loc_node ();
8736 if (bitsize == -1 || piece_loc == NULL)
8737 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8739 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8740 bitpos, piece_bitpos, bitsize, loc_note);
8742 /* Ensure TEMP->LAST will point either to the new last but one
8743 element of the chain, or to the last element in it. */
8744 if (last != temp->last)
8752 loc = ggc_alloc_cleared_var_loc_node ();
8755 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8760 /* Keep track of the number of spaces used to indent the
8761 output of the debugging routines that print the structure of
8762 the DIE internal representation. */
8763 static int print_indent;
8765 /* Indent the line the number of spaces given by print_indent. */
8768 print_spaces (FILE *outfile)
8770 fprintf (outfile, "%*s", print_indent, "");
8773 /* Print a type signature in hex. */
8776 print_signature (FILE *outfile, char *sig)
8780 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8781 fprintf (outfile, "%02x", sig[i] & 0xff);
8784 /* Print the information associated with a given DIE, and its children.
8785 This routine is a debugging aid only. */
8788 print_die (dw_die_ref die, FILE *outfile)
8794 print_spaces (outfile);
8795 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8796 die->die_offset, dwarf_tag_name (die->die_tag),
8798 print_spaces (outfile);
8799 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8800 fprintf (outfile, " offset: %ld", die->die_offset);
8801 fprintf (outfile, " mark: %d\n", die->die_mark);
8803 if (use_debug_types && die->die_id.die_type_node)
8805 print_spaces (outfile);
8806 fprintf (outfile, " signature: ");
8807 print_signature (outfile, die->die_id.die_type_node->signature);
8808 fprintf (outfile, "\n");
8811 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8813 print_spaces (outfile);
8814 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8816 switch (AT_class (a))
8818 case dw_val_class_addr:
8819 fprintf (outfile, "address");
8821 case dw_val_class_offset:
8822 fprintf (outfile, "offset");
8824 case dw_val_class_loc:
8825 fprintf (outfile, "location descriptor");
8827 case dw_val_class_loc_list:
8828 fprintf (outfile, "location list -> label:%s",
8829 AT_loc_list (a)->ll_symbol);
8831 case dw_val_class_range_list:
8832 fprintf (outfile, "range list");
8834 case dw_val_class_const:
8835 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8837 case dw_val_class_unsigned_const:
8838 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8840 case dw_val_class_const_double:
8841 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8842 HOST_WIDE_INT_PRINT_UNSIGNED")",
8843 a->dw_attr_val.v.val_double.high,
8844 a->dw_attr_val.v.val_double.low);
8846 case dw_val_class_vec:
8847 fprintf (outfile, "floating-point or vector constant");
8849 case dw_val_class_flag:
8850 fprintf (outfile, "%u", AT_flag (a));
8852 case dw_val_class_die_ref:
8853 if (AT_ref (a) != NULL)
8855 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
8857 fprintf (outfile, "die -> signature: ");
8858 print_signature (outfile,
8859 AT_ref (a)->die_id.die_type_node->signature);
8861 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
8862 fprintf (outfile, "die -> label: %s",
8863 AT_ref (a)->die_id.die_symbol);
8865 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8866 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8869 fprintf (outfile, "die -> <null>");
8871 case dw_val_class_vms_delta:
8872 fprintf (outfile, "delta: @slotcount(%s-%s)",
8873 AT_vms_delta2 (a), AT_vms_delta1 (a));
8875 case dw_val_class_lbl_id:
8876 case dw_val_class_lineptr:
8877 case dw_val_class_macptr:
8878 fprintf (outfile, "label: %s", AT_lbl (a));
8880 case dw_val_class_str:
8881 if (AT_string (a) != NULL)
8882 fprintf (outfile, "\"%s\"", AT_string (a));
8884 fprintf (outfile, "<null>");
8886 case dw_val_class_file:
8887 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8888 AT_file (a)->emitted_number);
8890 case dw_val_class_data8:
8894 for (i = 0; i < 8; i++)
8895 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8902 fprintf (outfile, "\n");
8905 if (die->die_child != NULL)
8908 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8911 if (print_indent == 0)
8912 fprintf (outfile, "\n");
8915 /* Print the information collected for a given DIE. */
8918 debug_dwarf_die (dw_die_ref die)
8920 print_die (die, stderr);
8923 /* Print all DWARF information collected for the compilation unit.
8924 This routine is a debugging aid only. */
8930 print_die (comp_unit_die (), stderr);
8933 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8934 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8935 DIE that marks the start of the DIEs for this include file. */
8938 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8940 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8941 dw_die_ref new_unit = gen_compile_unit_die (filename);
8943 new_unit->die_sib = old_unit;
8947 /* Close an include-file CU and reopen the enclosing one. */
8950 pop_compile_unit (dw_die_ref old_unit)
8952 dw_die_ref new_unit = old_unit->die_sib;
8954 old_unit->die_sib = NULL;
8958 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8959 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8961 /* Calculate the checksum of a location expression. */
8964 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8968 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8970 CHECKSUM (loc->dw_loc_oprnd1);
8971 CHECKSUM (loc->dw_loc_oprnd2);
8974 /* Calculate the checksum of an attribute. */
8977 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8979 dw_loc_descr_ref loc;
8982 CHECKSUM (at->dw_attr);
8984 /* We don't care that this was compiled with a different compiler
8985 snapshot; if the output is the same, that's what matters. */
8986 if (at->dw_attr == DW_AT_producer)
8989 switch (AT_class (at))
8991 case dw_val_class_const:
8992 CHECKSUM (at->dw_attr_val.v.val_int);
8994 case dw_val_class_unsigned_const:
8995 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8997 case dw_val_class_const_double:
8998 CHECKSUM (at->dw_attr_val.v.val_double);
9000 case dw_val_class_vec:
9001 CHECKSUM (at->dw_attr_val.v.val_vec);
9003 case dw_val_class_flag:
9004 CHECKSUM (at->dw_attr_val.v.val_flag);
9006 case dw_val_class_str:
9007 CHECKSUM_STRING (AT_string (at));
9010 case dw_val_class_addr:
9012 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9013 CHECKSUM_STRING (XSTR (r, 0));
9016 case dw_val_class_offset:
9017 CHECKSUM (at->dw_attr_val.v.val_offset);
9020 case dw_val_class_loc:
9021 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9022 loc_checksum (loc, ctx);
9025 case dw_val_class_die_ref:
9026 die_checksum (AT_ref (at), ctx, mark);
9029 case dw_val_class_fde_ref:
9030 case dw_val_class_vms_delta:
9031 case dw_val_class_lbl_id:
9032 case dw_val_class_lineptr:
9033 case dw_val_class_macptr:
9036 case dw_val_class_file:
9037 CHECKSUM_STRING (AT_file (at)->filename);
9040 case dw_val_class_data8:
9041 CHECKSUM (at->dw_attr_val.v.val_data8);
9049 /* Calculate the checksum of a DIE. */
9052 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9058 /* To avoid infinite recursion. */
9061 CHECKSUM (die->die_mark);
9064 die->die_mark = ++(*mark);
9066 CHECKSUM (die->die_tag);
9068 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9069 attr_checksum (a, ctx, mark);
9071 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
9075 #undef CHECKSUM_STRING
9077 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
9078 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
9079 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
9080 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
9081 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
9082 #define CHECKSUM_ATTR(FOO) \
9083 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
9085 /* Calculate the checksum of a number in signed LEB128 format. */
9088 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
9095 byte = (value & 0x7f);
9097 more = !((value == 0 && (byte & 0x40) == 0)
9098 || (value == -1 && (byte & 0x40) != 0));
9107 /* Calculate the checksum of a number in unsigned LEB128 format. */
9110 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
9114 unsigned char byte = (value & 0x7f);
9117 /* More bytes to follow. */
9125 /* Checksum the context of the DIE. This adds the names of any
9126 surrounding namespaces or structures to the checksum. */
9129 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
9133 int tag = die->die_tag;
9135 if (tag != DW_TAG_namespace
9136 && tag != DW_TAG_structure_type
9137 && tag != DW_TAG_class_type)
9140 name = get_AT_string (die, DW_AT_name);
9142 spec = get_AT_ref (die, DW_AT_specification);
9146 if (die->die_parent != NULL)
9147 checksum_die_context (die->die_parent, ctx);
9149 CHECKSUM_ULEB128 ('C');
9150 CHECKSUM_ULEB128 (tag);
9152 CHECKSUM_STRING (name);
9155 /* Calculate the checksum of a location expression. */
9158 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
9160 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
9161 were emitted as a DW_FORM_sdata instead of a location expression. */
9162 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
9164 CHECKSUM_ULEB128 (DW_FORM_sdata);
9165 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
9169 /* Otherwise, just checksum the raw location expression. */
9172 CHECKSUM_ULEB128 (loc->dw_loc_opc);
9173 CHECKSUM (loc->dw_loc_oprnd1);
9174 CHECKSUM (loc->dw_loc_oprnd2);
9175 loc = loc->dw_loc_next;
9179 /* Calculate the checksum of an attribute. */
9182 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
9183 struct md5_ctx *ctx, int *mark)
9185 dw_loc_descr_ref loc;
9188 if (AT_class (at) == dw_val_class_die_ref)
9190 dw_die_ref target_die = AT_ref (at);
9192 /* For pointer and reference types, we checksum only the (qualified)
9193 name of the target type (if there is a name). For friend entries,
9194 we checksum only the (qualified) name of the target type or function.
9195 This allows the checksum to remain the same whether the target type
9196 is complete or not. */
9197 if ((at->dw_attr == DW_AT_type
9198 && (tag == DW_TAG_pointer_type
9199 || tag == DW_TAG_reference_type
9200 || tag == DW_TAG_rvalue_reference_type
9201 || tag == DW_TAG_ptr_to_member_type))
9202 || (at->dw_attr == DW_AT_friend
9203 && tag == DW_TAG_friend))
9205 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
9207 if (name_attr != NULL)
9209 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9213 CHECKSUM_ULEB128 ('N');
9214 CHECKSUM_ULEB128 (at->dw_attr);
9215 if (decl->die_parent != NULL)
9216 checksum_die_context (decl->die_parent, ctx);
9217 CHECKSUM_ULEB128 ('E');
9218 CHECKSUM_STRING (AT_string (name_attr));
9223 /* For all other references to another DIE, we check to see if the
9224 target DIE has already been visited. If it has, we emit a
9225 backward reference; if not, we descend recursively. */
9226 if (target_die->die_mark > 0)
9228 CHECKSUM_ULEB128 ('R');
9229 CHECKSUM_ULEB128 (at->dw_attr);
9230 CHECKSUM_ULEB128 (target_die->die_mark);
9234 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9238 target_die->die_mark = ++(*mark);
9239 CHECKSUM_ULEB128 ('T');
9240 CHECKSUM_ULEB128 (at->dw_attr);
9241 if (decl->die_parent != NULL)
9242 checksum_die_context (decl->die_parent, ctx);
9243 die_checksum_ordered (target_die, ctx, mark);
9248 CHECKSUM_ULEB128 ('A');
9249 CHECKSUM_ULEB128 (at->dw_attr);
9251 switch (AT_class (at))
9253 case dw_val_class_const:
9254 CHECKSUM_ULEB128 (DW_FORM_sdata);
9255 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9258 case dw_val_class_unsigned_const:
9259 CHECKSUM_ULEB128 (DW_FORM_sdata);
9260 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9263 case dw_val_class_const_double:
9264 CHECKSUM_ULEB128 (DW_FORM_block);
9265 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9266 CHECKSUM (at->dw_attr_val.v.val_double);
9269 case dw_val_class_vec:
9270 CHECKSUM_ULEB128 (DW_FORM_block);
9271 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9272 CHECKSUM (at->dw_attr_val.v.val_vec);
9275 case dw_val_class_flag:
9276 CHECKSUM_ULEB128 (DW_FORM_flag);
9277 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9280 case dw_val_class_str:
9281 CHECKSUM_ULEB128 (DW_FORM_string);
9282 CHECKSUM_STRING (AT_string (at));
9285 case dw_val_class_addr:
9287 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9288 CHECKSUM_ULEB128 (DW_FORM_string);
9289 CHECKSUM_STRING (XSTR (r, 0));
9292 case dw_val_class_offset:
9293 CHECKSUM_ULEB128 (DW_FORM_sdata);
9294 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9297 case dw_val_class_loc:
9298 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9299 loc_checksum_ordered (loc, ctx);
9302 case dw_val_class_fde_ref:
9303 case dw_val_class_lbl_id:
9304 case dw_val_class_lineptr:
9305 case dw_val_class_macptr:
9308 case dw_val_class_file:
9309 CHECKSUM_ULEB128 (DW_FORM_string);
9310 CHECKSUM_STRING (AT_file (at)->filename);
9313 case dw_val_class_data8:
9314 CHECKSUM (at->dw_attr_val.v.val_data8);
9322 struct checksum_attributes
9324 dw_attr_ref at_name;
9325 dw_attr_ref at_type;
9326 dw_attr_ref at_friend;
9327 dw_attr_ref at_accessibility;
9328 dw_attr_ref at_address_class;
9329 dw_attr_ref at_allocated;
9330 dw_attr_ref at_artificial;
9331 dw_attr_ref at_associated;
9332 dw_attr_ref at_binary_scale;
9333 dw_attr_ref at_bit_offset;
9334 dw_attr_ref at_bit_size;
9335 dw_attr_ref at_bit_stride;
9336 dw_attr_ref at_byte_size;
9337 dw_attr_ref at_byte_stride;
9338 dw_attr_ref at_const_value;
9339 dw_attr_ref at_containing_type;
9340 dw_attr_ref at_count;
9341 dw_attr_ref at_data_location;
9342 dw_attr_ref at_data_member_location;
9343 dw_attr_ref at_decimal_scale;
9344 dw_attr_ref at_decimal_sign;
9345 dw_attr_ref at_default_value;
9346 dw_attr_ref at_digit_count;
9347 dw_attr_ref at_discr;
9348 dw_attr_ref at_discr_list;
9349 dw_attr_ref at_discr_value;
9350 dw_attr_ref at_encoding;
9351 dw_attr_ref at_endianity;
9352 dw_attr_ref at_explicit;
9353 dw_attr_ref at_is_optional;
9354 dw_attr_ref at_location;
9355 dw_attr_ref at_lower_bound;
9356 dw_attr_ref at_mutable;
9357 dw_attr_ref at_ordering;
9358 dw_attr_ref at_picture_string;
9359 dw_attr_ref at_prototyped;
9360 dw_attr_ref at_small;
9361 dw_attr_ref at_segment;
9362 dw_attr_ref at_string_length;
9363 dw_attr_ref at_threads_scaled;
9364 dw_attr_ref at_upper_bound;
9365 dw_attr_ref at_use_location;
9366 dw_attr_ref at_use_UTF8;
9367 dw_attr_ref at_variable_parameter;
9368 dw_attr_ref at_virtuality;
9369 dw_attr_ref at_visibility;
9370 dw_attr_ref at_vtable_elem_location;
9373 /* Collect the attributes that we will want to use for the checksum. */
9376 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9381 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9392 attrs->at_friend = a;
9394 case DW_AT_accessibility:
9395 attrs->at_accessibility = a;
9397 case DW_AT_address_class:
9398 attrs->at_address_class = a;
9400 case DW_AT_allocated:
9401 attrs->at_allocated = a;
9403 case DW_AT_artificial:
9404 attrs->at_artificial = a;
9406 case DW_AT_associated:
9407 attrs->at_associated = a;
9409 case DW_AT_binary_scale:
9410 attrs->at_binary_scale = a;
9412 case DW_AT_bit_offset:
9413 attrs->at_bit_offset = a;
9415 case DW_AT_bit_size:
9416 attrs->at_bit_size = a;
9418 case DW_AT_bit_stride:
9419 attrs->at_bit_stride = a;
9421 case DW_AT_byte_size:
9422 attrs->at_byte_size = a;
9424 case DW_AT_byte_stride:
9425 attrs->at_byte_stride = a;
9427 case DW_AT_const_value:
9428 attrs->at_const_value = a;
9430 case DW_AT_containing_type:
9431 attrs->at_containing_type = a;
9434 attrs->at_count = a;
9436 case DW_AT_data_location:
9437 attrs->at_data_location = a;
9439 case DW_AT_data_member_location:
9440 attrs->at_data_member_location = a;
9442 case DW_AT_decimal_scale:
9443 attrs->at_decimal_scale = a;
9445 case DW_AT_decimal_sign:
9446 attrs->at_decimal_sign = a;
9448 case DW_AT_default_value:
9449 attrs->at_default_value = a;
9451 case DW_AT_digit_count:
9452 attrs->at_digit_count = a;
9455 attrs->at_discr = a;
9457 case DW_AT_discr_list:
9458 attrs->at_discr_list = a;
9460 case DW_AT_discr_value:
9461 attrs->at_discr_value = a;
9463 case DW_AT_encoding:
9464 attrs->at_encoding = a;
9466 case DW_AT_endianity:
9467 attrs->at_endianity = a;
9469 case DW_AT_explicit:
9470 attrs->at_explicit = a;
9472 case DW_AT_is_optional:
9473 attrs->at_is_optional = a;
9475 case DW_AT_location:
9476 attrs->at_location = a;
9478 case DW_AT_lower_bound:
9479 attrs->at_lower_bound = a;
9482 attrs->at_mutable = a;
9484 case DW_AT_ordering:
9485 attrs->at_ordering = a;
9487 case DW_AT_picture_string:
9488 attrs->at_picture_string = a;
9490 case DW_AT_prototyped:
9491 attrs->at_prototyped = a;
9494 attrs->at_small = a;
9497 attrs->at_segment = a;
9499 case DW_AT_string_length:
9500 attrs->at_string_length = a;
9502 case DW_AT_threads_scaled:
9503 attrs->at_threads_scaled = a;
9505 case DW_AT_upper_bound:
9506 attrs->at_upper_bound = a;
9508 case DW_AT_use_location:
9509 attrs->at_use_location = a;
9511 case DW_AT_use_UTF8:
9512 attrs->at_use_UTF8 = a;
9514 case DW_AT_variable_parameter:
9515 attrs->at_variable_parameter = a;
9517 case DW_AT_virtuality:
9518 attrs->at_virtuality = a;
9520 case DW_AT_visibility:
9521 attrs->at_visibility = a;
9523 case DW_AT_vtable_elem_location:
9524 attrs->at_vtable_elem_location = a;
9532 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9535 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9539 struct checksum_attributes attrs;
9541 CHECKSUM_ULEB128 ('D');
9542 CHECKSUM_ULEB128 (die->die_tag);
9544 memset (&attrs, 0, sizeof (attrs));
9546 decl = get_AT_ref (die, DW_AT_specification);
9548 collect_checksum_attributes (&attrs, decl);
9549 collect_checksum_attributes (&attrs, die);
9551 CHECKSUM_ATTR (attrs.at_name);
9552 CHECKSUM_ATTR (attrs.at_accessibility);
9553 CHECKSUM_ATTR (attrs.at_address_class);
9554 CHECKSUM_ATTR (attrs.at_allocated);
9555 CHECKSUM_ATTR (attrs.at_artificial);
9556 CHECKSUM_ATTR (attrs.at_associated);
9557 CHECKSUM_ATTR (attrs.at_binary_scale);
9558 CHECKSUM_ATTR (attrs.at_bit_offset);
9559 CHECKSUM_ATTR (attrs.at_bit_size);
9560 CHECKSUM_ATTR (attrs.at_bit_stride);
9561 CHECKSUM_ATTR (attrs.at_byte_size);
9562 CHECKSUM_ATTR (attrs.at_byte_stride);
9563 CHECKSUM_ATTR (attrs.at_const_value);
9564 CHECKSUM_ATTR (attrs.at_containing_type);
9565 CHECKSUM_ATTR (attrs.at_count);
9566 CHECKSUM_ATTR (attrs.at_data_location);
9567 CHECKSUM_ATTR (attrs.at_data_member_location);
9568 CHECKSUM_ATTR (attrs.at_decimal_scale);
9569 CHECKSUM_ATTR (attrs.at_decimal_sign);
9570 CHECKSUM_ATTR (attrs.at_default_value);
9571 CHECKSUM_ATTR (attrs.at_digit_count);
9572 CHECKSUM_ATTR (attrs.at_discr);
9573 CHECKSUM_ATTR (attrs.at_discr_list);
9574 CHECKSUM_ATTR (attrs.at_discr_value);
9575 CHECKSUM_ATTR (attrs.at_encoding);
9576 CHECKSUM_ATTR (attrs.at_endianity);
9577 CHECKSUM_ATTR (attrs.at_explicit);
9578 CHECKSUM_ATTR (attrs.at_is_optional);
9579 CHECKSUM_ATTR (attrs.at_location);
9580 CHECKSUM_ATTR (attrs.at_lower_bound);
9581 CHECKSUM_ATTR (attrs.at_mutable);
9582 CHECKSUM_ATTR (attrs.at_ordering);
9583 CHECKSUM_ATTR (attrs.at_picture_string);
9584 CHECKSUM_ATTR (attrs.at_prototyped);
9585 CHECKSUM_ATTR (attrs.at_small);
9586 CHECKSUM_ATTR (attrs.at_segment);
9587 CHECKSUM_ATTR (attrs.at_string_length);
9588 CHECKSUM_ATTR (attrs.at_threads_scaled);
9589 CHECKSUM_ATTR (attrs.at_upper_bound);
9590 CHECKSUM_ATTR (attrs.at_use_location);
9591 CHECKSUM_ATTR (attrs.at_use_UTF8);
9592 CHECKSUM_ATTR (attrs.at_variable_parameter);
9593 CHECKSUM_ATTR (attrs.at_virtuality);
9594 CHECKSUM_ATTR (attrs.at_visibility);
9595 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9596 CHECKSUM_ATTR (attrs.at_type);
9597 CHECKSUM_ATTR (attrs.at_friend);
9599 /* Checksum the child DIEs, except for nested types and member functions. */
9602 dw_attr_ref name_attr;
9605 name_attr = get_AT (c, DW_AT_name);
9606 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9607 && name_attr != NULL)
9609 CHECKSUM_ULEB128 ('S');
9610 CHECKSUM_ULEB128 (c->die_tag);
9611 CHECKSUM_STRING (AT_string (name_attr));
9615 /* Mark this DIE so it gets processed when unmarking. */
9616 if (c->die_mark == 0)
9618 die_checksum_ordered (c, ctx, mark);
9620 } while (c != die->die_child);
9622 CHECKSUM_ULEB128 (0);
9626 #undef CHECKSUM_STRING
9627 #undef CHECKSUM_ATTR
9628 #undef CHECKSUM_LEB128
9629 #undef CHECKSUM_ULEB128
9631 /* Generate the type signature for DIE. This is computed by generating an
9632 MD5 checksum over the DIE's tag, its relevant attributes, and its
9633 children. Attributes that are references to other DIEs are processed
9634 by recursion, using the MARK field to prevent infinite recursion.
9635 If the DIE is nested inside a namespace or another type, we also
9636 need to include that context in the signature. The lower 64 bits
9637 of the resulting MD5 checksum comprise the signature. */
9640 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9644 unsigned char checksum[16];
9648 name = get_AT_string (die, DW_AT_name);
9649 decl = get_AT_ref (die, DW_AT_specification);
9651 /* First, compute a signature for just the type name (and its surrounding
9652 context, if any. This is stored in the type unit DIE for link-time
9653 ODR (one-definition rule) checking. */
9655 if (is_cxx() && name != NULL)
9657 md5_init_ctx (&ctx);
9659 /* Checksum the names of surrounding namespaces and structures. */
9660 if (decl != NULL && decl->die_parent != NULL)
9661 checksum_die_context (decl->die_parent, &ctx);
9663 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9664 md5_process_bytes (name, strlen (name) + 1, &ctx);
9665 md5_finish_ctx (&ctx, checksum);
9667 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9670 /* Next, compute the complete type signature. */
9672 md5_init_ctx (&ctx);
9674 die->die_mark = mark;
9676 /* Checksum the names of surrounding namespaces and structures. */
9677 if (decl != NULL && decl->die_parent != NULL)
9678 checksum_die_context (decl->die_parent, &ctx);
9680 /* Checksum the DIE and its children. */
9681 die_checksum_ordered (die, &ctx, &mark);
9682 unmark_all_dies (die);
9683 md5_finish_ctx (&ctx, checksum);
9685 /* Store the signature in the type node and link the type DIE and the
9686 type node together. */
9687 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9688 DWARF_TYPE_SIGNATURE_SIZE);
9689 die->die_id.die_type_node = type_node;
9690 type_node->type_die = die;
9692 /* If the DIE is a specification, link its declaration to the type node
9695 decl->die_id.die_type_node = type_node;
9698 /* Do the location expressions look same? */
9700 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9702 return loc1->dw_loc_opc == loc2->dw_loc_opc
9703 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9704 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9707 /* Do the values look the same? */
9709 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9711 dw_loc_descr_ref loc1, loc2;
9714 if (v1->val_class != v2->val_class)
9717 switch (v1->val_class)
9719 case dw_val_class_const:
9720 return v1->v.val_int == v2->v.val_int;
9721 case dw_val_class_unsigned_const:
9722 return v1->v.val_unsigned == v2->v.val_unsigned;
9723 case dw_val_class_const_double:
9724 return v1->v.val_double.high == v2->v.val_double.high
9725 && v1->v.val_double.low == v2->v.val_double.low;
9726 case dw_val_class_vec:
9727 if (v1->v.val_vec.length != v2->v.val_vec.length
9728 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9730 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9731 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9734 case dw_val_class_flag:
9735 return v1->v.val_flag == v2->v.val_flag;
9736 case dw_val_class_str:
9737 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9739 case dw_val_class_addr:
9740 r1 = v1->v.val_addr;
9741 r2 = v2->v.val_addr;
9742 if (GET_CODE (r1) != GET_CODE (r2))
9744 return !rtx_equal_p (r1, r2);
9746 case dw_val_class_offset:
9747 return v1->v.val_offset == v2->v.val_offset;
9749 case dw_val_class_loc:
9750 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9752 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9753 if (!same_loc_p (loc1, loc2, mark))
9755 return !loc1 && !loc2;
9757 case dw_val_class_die_ref:
9758 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9760 case dw_val_class_fde_ref:
9761 case dw_val_class_vms_delta:
9762 case dw_val_class_lbl_id:
9763 case dw_val_class_lineptr:
9764 case dw_val_class_macptr:
9767 case dw_val_class_file:
9768 return v1->v.val_file == v2->v.val_file;
9770 case dw_val_class_data8:
9771 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9778 /* Do the attributes look the same? */
9781 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9783 if (at1->dw_attr != at2->dw_attr)
9786 /* We don't care that this was compiled with a different compiler
9787 snapshot; if the output is the same, that's what matters. */
9788 if (at1->dw_attr == DW_AT_producer)
9791 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9794 /* Do the dies look the same? */
9797 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9803 /* To avoid infinite recursion. */
9805 return die1->die_mark == die2->die_mark;
9806 die1->die_mark = die2->die_mark = ++(*mark);
9808 if (die1->die_tag != die2->die_tag)
9811 if (VEC_length (dw_attr_node, die1->die_attr)
9812 != VEC_length (dw_attr_node, die2->die_attr))
9815 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9816 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9819 c1 = die1->die_child;
9820 c2 = die2->die_child;
9829 if (!same_die_p (c1, c2, mark))
9833 if (c1 == die1->die_child)
9835 if (c2 == die2->die_child)
9845 /* Do the dies look the same? Wrapper around same_die_p. */
9848 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9851 int ret = same_die_p (die1, die2, &mark);
9853 unmark_all_dies (die1);
9854 unmark_all_dies (die2);
9859 /* The prefix to attach to symbols on DIEs in the current comdat debug
9861 static char *comdat_symbol_id;
9863 /* The index of the current symbol within the current comdat CU. */
9864 static unsigned int comdat_symbol_number;
9866 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9867 children, and set comdat_symbol_id accordingly. */
9870 compute_section_prefix (dw_die_ref unit_die)
9872 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9873 const char *base = die_name ? lbasename (die_name) : "anonymous";
9874 char *name = XALLOCAVEC (char, strlen (base) + 64);
9877 unsigned char checksum[16];
9880 /* Compute the checksum of the DIE, then append part of it as hex digits to
9881 the name filename of the unit. */
9883 md5_init_ctx (&ctx);
9885 die_checksum (unit_die, &ctx, &mark);
9886 unmark_all_dies (unit_die);
9887 md5_finish_ctx (&ctx, checksum);
9889 sprintf (name, "%s.", base);
9890 clean_symbol_name (name);
9892 p = name + strlen (name);
9893 for (i = 0; i < 4; i++)
9895 sprintf (p, "%.2x", checksum[i]);
9899 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9900 comdat_symbol_number = 0;
9903 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9906 is_type_die (dw_die_ref die)
9908 switch (die->die_tag)
9910 case DW_TAG_array_type:
9911 case DW_TAG_class_type:
9912 case DW_TAG_interface_type:
9913 case DW_TAG_enumeration_type:
9914 case DW_TAG_pointer_type:
9915 case DW_TAG_reference_type:
9916 case DW_TAG_rvalue_reference_type:
9917 case DW_TAG_string_type:
9918 case DW_TAG_structure_type:
9919 case DW_TAG_subroutine_type:
9920 case DW_TAG_union_type:
9921 case DW_TAG_ptr_to_member_type:
9922 case DW_TAG_set_type:
9923 case DW_TAG_subrange_type:
9924 case DW_TAG_base_type:
9925 case DW_TAG_const_type:
9926 case DW_TAG_file_type:
9927 case DW_TAG_packed_type:
9928 case DW_TAG_volatile_type:
9929 case DW_TAG_typedef:
9936 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9937 Basically, we want to choose the bits that are likely to be shared between
9938 compilations (types) and leave out the bits that are specific to individual
9939 compilations (functions). */
9942 is_comdat_die (dw_die_ref c)
9944 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9945 we do for stabs. The advantage is a greater likelihood of sharing between
9946 objects that don't include headers in the same order (and therefore would
9947 put the base types in a different comdat). jason 8/28/00 */
9949 if (c->die_tag == DW_TAG_base_type)
9952 if (c->die_tag == DW_TAG_pointer_type
9953 || c->die_tag == DW_TAG_reference_type
9954 || c->die_tag == DW_TAG_rvalue_reference_type
9955 || c->die_tag == DW_TAG_const_type
9956 || c->die_tag == DW_TAG_volatile_type)
9958 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9960 return t ? is_comdat_die (t) : 0;
9963 return is_type_die (c);
9966 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9967 compilation unit. */
9970 is_symbol_die (dw_die_ref c)
9972 return (is_type_die (c)
9973 || is_declaration_die (c)
9974 || c->die_tag == DW_TAG_namespace
9975 || c->die_tag == DW_TAG_module);
9978 /* Returns true iff C is a compile-unit DIE. */
9981 is_cu_die (dw_die_ref c)
9983 return c && c->die_tag == DW_TAG_compile_unit;
9987 gen_internal_sym (const char *prefix)
9991 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9992 return xstrdup (buf);
9995 /* Assign symbols to all worthy DIEs under DIE. */
9998 assign_symbol_names (dw_die_ref die)
10002 if (is_symbol_die (die))
10004 if (comdat_symbol_id)
10006 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
10008 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
10009 comdat_symbol_id, comdat_symbol_number++);
10010 die->die_id.die_symbol = xstrdup (p);
10013 die->die_id.die_symbol = gen_internal_sym ("LDIE");
10016 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
10019 struct cu_hash_table_entry
10022 unsigned min_comdat_num, max_comdat_num;
10023 struct cu_hash_table_entry *next;
10026 /* Routines to manipulate hash table of CUs. */
10028 htab_cu_hash (const void *of)
10030 const struct cu_hash_table_entry *const entry =
10031 (const struct cu_hash_table_entry *) of;
10033 return htab_hash_string (entry->cu->die_id.die_symbol);
10037 htab_cu_eq (const void *of1, const void *of2)
10039 const struct cu_hash_table_entry *const entry1 =
10040 (const struct cu_hash_table_entry *) of1;
10041 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10043 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
10047 htab_cu_del (void *what)
10049 struct cu_hash_table_entry *next,
10050 *entry = (struct cu_hash_table_entry *) what;
10054 next = entry->next;
10060 /* Check whether we have already seen this CU and set up SYM_NUM
10063 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
10065 struct cu_hash_table_entry dummy;
10066 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
10068 dummy.max_comdat_num = 0;
10070 slot = (struct cu_hash_table_entry **)
10071 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
10075 for (; entry; last = entry, entry = entry->next)
10077 if (same_die_p_wrap (cu, entry->cu))
10083 *sym_num = entry->min_comdat_num;
10087 entry = XCNEW (struct cu_hash_table_entry);
10089 entry->min_comdat_num = *sym_num = last->max_comdat_num;
10090 entry->next = *slot;
10096 /* Record SYM_NUM to record of CU in HTABLE. */
10098 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
10100 struct cu_hash_table_entry **slot, *entry;
10102 slot = (struct cu_hash_table_entry **)
10103 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
10107 entry->max_comdat_num = sym_num;
10110 /* Traverse the DIE (which is always comp_unit_die), and set up
10111 additional compilation units for each of the include files we see
10112 bracketed by BINCL/EINCL. */
10115 break_out_includes (dw_die_ref die)
10118 dw_die_ref unit = NULL;
10119 limbo_die_node *node, **pnode;
10120 htab_t cu_hash_table;
10122 c = die->die_child;
10124 dw_die_ref prev = c;
10126 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
10127 || (unit && is_comdat_die (c)))
10129 dw_die_ref next = c->die_sib;
10131 /* This DIE is for a secondary CU; remove it from the main one. */
10132 remove_child_with_prev (c, prev);
10134 if (c->die_tag == DW_TAG_GNU_BINCL)
10135 unit = push_new_compile_unit (unit, c);
10136 else if (c->die_tag == DW_TAG_GNU_EINCL)
10137 unit = pop_compile_unit (unit);
10139 add_child_die (unit, c);
10141 if (c == die->die_child)
10144 } while (c != die->die_child);
10147 /* We can only use this in debugging, since the frontend doesn't check
10148 to make sure that we leave every include file we enter. */
10149 gcc_assert (!unit);
10152 assign_symbol_names (die);
10153 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
10154 for (node = limbo_die_list, pnode = &limbo_die_list;
10160 compute_section_prefix (node->die);
10161 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
10162 &comdat_symbol_number);
10163 assign_symbol_names (node->die);
10165 *pnode = node->next;
10168 pnode = &node->next;
10169 record_comdat_symbol_number (node->die, cu_hash_table,
10170 comdat_symbol_number);
10173 htab_delete (cu_hash_table);
10176 /* Return non-zero if this DIE is a declaration. */
10179 is_declaration_die (dw_die_ref die)
10184 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10185 if (a->dw_attr == DW_AT_declaration)
10191 /* Return non-zero if this DIE is nested inside a subprogram. */
10194 is_nested_in_subprogram (dw_die_ref die)
10196 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
10200 return local_scope_p (decl);
10203 /* Return non-zero if this DIE contains a defining declaration of a
10207 contains_subprogram_definition (dw_die_ref die)
10211 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
10213 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
10217 /* Return non-zero if this is a type DIE that should be moved to a
10218 COMDAT .debug_types section. */
10221 should_move_die_to_comdat (dw_die_ref die)
10223 switch (die->die_tag)
10225 case DW_TAG_class_type:
10226 case DW_TAG_structure_type:
10227 case DW_TAG_enumeration_type:
10228 case DW_TAG_union_type:
10229 /* Don't move declarations, inlined instances, or types nested in a
10231 if (is_declaration_die (die)
10232 || get_AT (die, DW_AT_abstract_origin)
10233 || is_nested_in_subprogram (die))
10235 /* A type definition should never contain a subprogram definition. */
10236 gcc_assert (!contains_subprogram_definition (die));
10238 case DW_TAG_array_type:
10239 case DW_TAG_interface_type:
10240 case DW_TAG_pointer_type:
10241 case DW_TAG_reference_type:
10242 case DW_TAG_rvalue_reference_type:
10243 case DW_TAG_string_type:
10244 case DW_TAG_subroutine_type:
10245 case DW_TAG_ptr_to_member_type:
10246 case DW_TAG_set_type:
10247 case DW_TAG_subrange_type:
10248 case DW_TAG_base_type:
10249 case DW_TAG_const_type:
10250 case DW_TAG_file_type:
10251 case DW_TAG_packed_type:
10252 case DW_TAG_volatile_type:
10253 case DW_TAG_typedef:
10259 /* Make a clone of DIE. */
10262 clone_die (dw_die_ref die)
10268 clone = ggc_alloc_cleared_die_node ();
10269 clone->die_tag = die->die_tag;
10271 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10272 add_dwarf_attr (clone, a);
10277 /* Make a clone of the tree rooted at DIE. */
10280 clone_tree (dw_die_ref die)
10283 dw_die_ref clone = clone_die (die);
10285 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10290 /* Make a clone of DIE as a declaration. */
10293 clone_as_declaration (dw_die_ref die)
10300 /* If the DIE is already a declaration, just clone it. */
10301 if (is_declaration_die (die))
10302 return clone_die (die);
10304 /* If the DIE is a specification, just clone its declaration DIE. */
10305 decl = get_AT_ref (die, DW_AT_specification);
10307 return clone_die (decl);
10309 clone = ggc_alloc_cleared_die_node ();
10310 clone->die_tag = die->die_tag;
10312 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10314 /* We don't want to copy over all attributes.
10315 For example we don't want DW_AT_byte_size because otherwise we will no
10316 longer have a declaration and GDB will treat it as a definition. */
10318 switch (a->dw_attr)
10320 case DW_AT_artificial:
10321 case DW_AT_containing_type:
10322 case DW_AT_external:
10325 case DW_AT_virtuality:
10326 case DW_AT_linkage_name:
10327 case DW_AT_MIPS_linkage_name:
10328 add_dwarf_attr (clone, a);
10330 case DW_AT_byte_size:
10336 if (die->die_id.die_type_node)
10337 add_AT_die_ref (clone, DW_AT_signature, die);
10339 add_AT_flag (clone, DW_AT_declaration, 1);
10343 /* Copy the declaration context to the new compile unit DIE. This includes
10344 any surrounding namespace or type declarations. If the DIE has an
10345 AT_specification attribute, it also includes attributes and children
10346 attached to the specification. */
10349 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10352 dw_die_ref new_decl;
10354 decl = get_AT_ref (die, DW_AT_specification);
10363 /* Copy the type node pointer from the new DIE to the original
10364 declaration DIE so we can forward references later. */
10365 decl->die_id.die_type_node = die->die_id.die_type_node;
10367 remove_AT (die, DW_AT_specification);
10369 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10371 if (a->dw_attr != DW_AT_name
10372 && a->dw_attr != DW_AT_declaration
10373 && a->dw_attr != DW_AT_external)
10374 add_dwarf_attr (die, a);
10377 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10380 if (decl->die_parent != NULL
10381 && decl->die_parent->die_tag != DW_TAG_compile_unit
10382 && decl->die_parent->die_tag != DW_TAG_type_unit)
10384 new_decl = copy_ancestor_tree (unit, decl, NULL);
10385 if (new_decl != NULL)
10387 remove_AT (new_decl, DW_AT_signature);
10388 add_AT_specification (die, new_decl);
10393 /* Generate the skeleton ancestor tree for the given NODE, then clone
10394 the DIE and add the clone into the tree. */
10397 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10399 if (node->new_die != NULL)
10402 node->new_die = clone_as_declaration (node->old_die);
10404 if (node->parent != NULL)
10406 generate_skeleton_ancestor_tree (node->parent);
10407 add_child_die (node->parent->new_die, node->new_die);
10411 /* Generate a skeleton tree of DIEs containing any declarations that are
10412 found in the original tree. We traverse the tree looking for declaration
10413 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10416 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10418 skeleton_chain_node node;
10421 dw_die_ref prev = NULL;
10422 dw_die_ref next = NULL;
10424 node.parent = parent;
10426 first = c = parent->old_die->die_child;
10430 if (prev == NULL || prev->die_sib == c)
10433 next = (c == first ? NULL : c->die_sib);
10435 node.new_die = NULL;
10436 if (is_declaration_die (c))
10438 /* Clone the existing DIE, move the original to the skeleton
10439 tree (which is in the main CU), and put the clone, with
10440 all the original's children, where the original came from. */
10441 dw_die_ref clone = clone_die (c);
10442 move_all_children (c, clone);
10444 replace_child (c, clone, prev);
10445 generate_skeleton_ancestor_tree (parent);
10446 add_child_die (parent->new_die, c);
10450 generate_skeleton_bottom_up (&node);
10451 } while (next != NULL);
10454 /* Wrapper function for generate_skeleton_bottom_up. */
10457 generate_skeleton (dw_die_ref die)
10459 skeleton_chain_node node;
10461 node.old_die = die;
10462 node.new_die = NULL;
10463 node.parent = NULL;
10465 /* If this type definition is nested inside another type,
10466 always leave at least a declaration in its place. */
10467 if (die->die_parent != NULL && is_type_die (die->die_parent))
10468 node.new_die = clone_as_declaration (die);
10470 generate_skeleton_bottom_up (&node);
10471 return node.new_die;
10474 /* Remove the DIE from its parent, possibly replacing it with a cloned
10475 declaration. The original DIE will be moved to a new compile unit
10476 so that existing references to it follow it to the new location. If
10477 any of the original DIE's descendants is a declaration, we need to
10478 replace the original DIE with a skeleton tree and move the
10479 declarations back into the skeleton tree. */
10482 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10484 dw_die_ref skeleton;
10486 skeleton = generate_skeleton (child);
10487 if (skeleton == NULL)
10488 remove_child_with_prev (child, prev);
10491 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10492 replace_child (child, skeleton, prev);
10498 /* Traverse the DIE and set up additional .debug_types sections for each
10499 type worthy of being placed in a COMDAT section. */
10502 break_out_comdat_types (dw_die_ref die)
10506 dw_die_ref prev = NULL;
10507 dw_die_ref next = NULL;
10508 dw_die_ref unit = NULL;
10510 first = c = die->die_child;
10514 if (prev == NULL || prev->die_sib == c)
10517 next = (c == first ? NULL : c->die_sib);
10518 if (should_move_die_to_comdat (c))
10520 dw_die_ref replacement;
10521 comdat_type_node_ref type_node;
10523 /* Create a new type unit DIE as the root for the new tree, and
10524 add it to the list of comdat types. */
10525 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10526 add_AT_unsigned (unit, DW_AT_language,
10527 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10528 type_node = ggc_alloc_cleared_comdat_type_node ();
10529 type_node->root_die = unit;
10530 type_node->next = comdat_type_list;
10531 comdat_type_list = type_node;
10533 /* Generate the type signature. */
10534 generate_type_signature (c, type_node);
10536 /* Copy the declaration context, attributes, and children of the
10537 declaration into the new compile unit DIE. */
10538 copy_declaration_context (unit, c);
10540 /* Remove this DIE from the main CU. */
10541 replacement = remove_child_or_replace_with_skeleton (c, prev);
10543 /* Break out nested types into their own type units. */
10544 break_out_comdat_types (c);
10546 /* Add the DIE to the new compunit. */
10547 add_child_die (unit, c);
10549 if (replacement != NULL)
10552 else if (c->die_tag == DW_TAG_namespace
10553 || c->die_tag == DW_TAG_class_type
10554 || c->die_tag == DW_TAG_structure_type
10555 || c->die_tag == DW_TAG_union_type)
10557 /* Look for nested types that can be broken out. */
10558 break_out_comdat_types (c);
10560 } while (next != NULL);
10563 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10565 struct decl_table_entry
10571 /* Routines to manipulate hash table of copied declarations. */
10574 htab_decl_hash (const void *of)
10576 const struct decl_table_entry *const entry =
10577 (const struct decl_table_entry *) of;
10579 return htab_hash_pointer (entry->orig);
10583 htab_decl_eq (const void *of1, const void *of2)
10585 const struct decl_table_entry *const entry1 =
10586 (const struct decl_table_entry *) of1;
10587 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10589 return entry1->orig == entry2;
10593 htab_decl_del (void *what)
10595 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10600 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10601 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10602 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10603 to check if the ancestor has already been copied into UNIT. */
10606 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10608 dw_die_ref parent = die->die_parent;
10609 dw_die_ref new_parent = unit;
10611 void **slot = NULL;
10612 struct decl_table_entry *entry = NULL;
10616 /* Check if the entry has already been copied to UNIT. */
10617 slot = htab_find_slot_with_hash (decl_table, die,
10618 htab_hash_pointer (die), INSERT);
10619 if (*slot != HTAB_EMPTY_ENTRY)
10621 entry = (struct decl_table_entry *) *slot;
10622 return entry->copy;
10625 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10626 entry = XCNEW (struct decl_table_entry);
10628 entry->copy = NULL;
10632 if (parent != NULL)
10634 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10637 if (parent->die_tag != DW_TAG_compile_unit
10638 && parent->die_tag != DW_TAG_type_unit)
10639 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10642 copy = clone_as_declaration (die);
10643 add_child_die (new_parent, copy);
10645 if (decl_table != NULL)
10647 /* Record the pointer to the copy. */
10648 entry->copy = copy;
10654 /* Walk the DIE and its children, looking for references to incomplete
10655 or trivial types that are unmarked (i.e., that are not in the current
10659 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10665 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10667 if (AT_class (a) == dw_val_class_die_ref)
10669 dw_die_ref targ = AT_ref (a);
10670 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10672 struct decl_table_entry *entry;
10674 if (targ->die_mark != 0 || type_node != NULL)
10677 slot = htab_find_slot_with_hash (decl_table, targ,
10678 htab_hash_pointer (targ), INSERT);
10680 if (*slot != HTAB_EMPTY_ENTRY)
10682 /* TARG has already been copied, so we just need to
10683 modify the reference to point to the copy. */
10684 entry = (struct decl_table_entry *) *slot;
10685 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10689 dw_die_ref parent = unit;
10690 dw_die_ref copy = clone_tree (targ);
10692 /* Make sure the cloned tree is marked as part of the
10696 /* Record in DECL_TABLE that TARG has been copied.
10697 Need to do this now, before the recursive call,
10698 because DECL_TABLE may be expanded and SLOT
10699 would no longer be a valid pointer. */
10700 entry = XCNEW (struct decl_table_entry);
10701 entry->orig = targ;
10702 entry->copy = copy;
10705 /* If TARG has surrounding context, copy its ancestor tree
10706 into the new type unit. */
10707 if (targ->die_parent != NULL
10708 && targ->die_parent->die_tag != DW_TAG_compile_unit
10709 && targ->die_parent->die_tag != DW_TAG_type_unit)
10710 parent = copy_ancestor_tree (unit, targ->die_parent,
10713 add_child_die (parent, copy);
10714 a->dw_attr_val.v.val_die_ref.die = copy;
10716 /* Make sure the newly-copied DIE is walked. If it was
10717 installed in a previously-added context, it won't
10718 get visited otherwise. */
10719 if (parent != unit)
10721 /* Find the highest point of the newly-added tree,
10722 mark each node along the way, and walk from there. */
10723 parent->die_mark = 1;
10724 while (parent->die_parent
10725 && parent->die_parent->die_mark == 0)
10727 parent = parent->die_parent;
10728 parent->die_mark = 1;
10730 copy_decls_walk (unit, parent, decl_table);
10736 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10739 /* Copy declarations for "unworthy" types into the new comdat section.
10740 Incomplete types, modified types, and certain other types aren't broken
10741 out into comdat sections of their own, so they don't have a signature,
10742 and we need to copy the declaration into the same section so that we
10743 don't have an external reference. */
10746 copy_decls_for_unworthy_types (dw_die_ref unit)
10751 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10752 copy_decls_walk (unit, unit, decl_table);
10753 htab_delete (decl_table);
10754 unmark_dies (unit);
10757 /* Traverse the DIE and add a sibling attribute if it may have the
10758 effect of speeding up access to siblings. To save some space,
10759 avoid generating sibling attributes for DIE's without children. */
10762 add_sibling_attributes (dw_die_ref die)
10766 if (! die->die_child)
10769 if (die->die_parent && die != die->die_parent->die_child)
10770 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10772 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10775 /* Output all location lists for the DIE and its children. */
10778 output_location_lists (dw_die_ref die)
10784 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10785 if (AT_class (a) == dw_val_class_loc_list)
10786 output_loc_list (AT_loc_list (a));
10788 FOR_EACH_CHILD (die, c, output_location_lists (c));
10791 /* The format of each DIE (and its attribute value pairs) is encoded in an
10792 abbreviation table. This routine builds the abbreviation table and assigns
10793 a unique abbreviation id for each abbreviation entry. The children of each
10794 die are visited recursively. */
10797 build_abbrev_table (dw_die_ref die)
10799 unsigned long abbrev_id;
10800 unsigned int n_alloc;
10805 /* Scan the DIE references, and mark as external any that refer to
10806 DIEs from other CUs (i.e. those which are not marked). */
10807 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10808 if (AT_class (a) == dw_val_class_die_ref
10809 && AT_ref (a)->die_mark == 0)
10811 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
10812 set_AT_ref_external (a, 1);
10815 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10817 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10818 dw_attr_ref die_a, abbrev_a;
10822 if (abbrev->die_tag != die->die_tag)
10824 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10827 if (VEC_length (dw_attr_node, abbrev->die_attr)
10828 != VEC_length (dw_attr_node, die->die_attr))
10831 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10833 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10834 if ((abbrev_a->dw_attr != die_a->dw_attr)
10835 || (value_format (abbrev_a) != value_format (die_a)))
10845 if (abbrev_id >= abbrev_die_table_in_use)
10847 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10849 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10850 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10853 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10854 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10855 abbrev_die_table_allocated = n_alloc;
10858 ++abbrev_die_table_in_use;
10859 abbrev_die_table[abbrev_id] = die;
10862 die->die_abbrev = abbrev_id;
10863 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10866 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10869 constant_size (unsigned HOST_WIDE_INT value)
10876 log = floor_log2 (value);
10879 log = 1 << (floor_log2 (log) + 1);
10884 /* Return the size of a DIE as it is represented in the
10885 .debug_info section. */
10887 static unsigned long
10888 size_of_die (dw_die_ref die)
10890 unsigned long size = 0;
10894 size += size_of_uleb128 (die->die_abbrev);
10895 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10897 switch (AT_class (a))
10899 case dw_val_class_addr:
10900 size += DWARF2_ADDR_SIZE;
10902 case dw_val_class_offset:
10903 size += DWARF_OFFSET_SIZE;
10905 case dw_val_class_loc:
10907 unsigned long lsize = size_of_locs (AT_loc (a));
10909 /* Block length. */
10910 if (dwarf_version >= 4)
10911 size += size_of_uleb128 (lsize);
10913 size += constant_size (lsize);
10917 case dw_val_class_loc_list:
10918 size += DWARF_OFFSET_SIZE;
10920 case dw_val_class_range_list:
10921 size += DWARF_OFFSET_SIZE;
10923 case dw_val_class_const:
10924 size += size_of_sleb128 (AT_int (a));
10926 case dw_val_class_unsigned_const:
10927 size += constant_size (AT_unsigned (a));
10929 case dw_val_class_const_double:
10930 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10931 if (HOST_BITS_PER_WIDE_INT >= 64)
10932 size++; /* block */
10934 case dw_val_class_vec:
10935 size += constant_size (a->dw_attr_val.v.val_vec.length
10936 * a->dw_attr_val.v.val_vec.elt_size)
10937 + a->dw_attr_val.v.val_vec.length
10938 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10940 case dw_val_class_flag:
10941 if (dwarf_version >= 4)
10942 /* Currently all add_AT_flag calls pass in 1 as last argument,
10943 so DW_FORM_flag_present can be used. If that ever changes,
10944 we'll need to use DW_FORM_flag and have some optimization
10945 in build_abbrev_table that will change those to
10946 DW_FORM_flag_present if it is set to 1 in all DIEs using
10947 the same abbrev entry. */
10948 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10952 case dw_val_class_die_ref:
10953 if (AT_ref_external (a))
10955 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
10956 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10957 is sized by target address length, whereas in DWARF3
10958 it's always sized as an offset. */
10959 if (use_debug_types)
10960 size += DWARF_TYPE_SIGNATURE_SIZE;
10961 else if (dwarf_version == 2)
10962 size += DWARF2_ADDR_SIZE;
10964 size += DWARF_OFFSET_SIZE;
10967 size += DWARF_OFFSET_SIZE;
10969 case dw_val_class_fde_ref:
10970 size += DWARF_OFFSET_SIZE;
10972 case dw_val_class_lbl_id:
10973 size += DWARF2_ADDR_SIZE;
10975 case dw_val_class_lineptr:
10976 case dw_val_class_macptr:
10977 size += DWARF_OFFSET_SIZE;
10979 case dw_val_class_str:
10980 if (AT_string_form (a) == DW_FORM_strp)
10981 size += DWARF_OFFSET_SIZE;
10983 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10985 case dw_val_class_file:
10986 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10988 case dw_val_class_data8:
10991 case dw_val_class_vms_delta:
10992 size += DWARF_OFFSET_SIZE;
10995 gcc_unreachable ();
11002 /* Size the debugging information associated with a given DIE. Visits the
11003 DIE's children recursively. Updates the global variable next_die_offset, on
11004 each time through. Uses the current value of next_die_offset to update the
11005 die_offset field in each DIE. */
11008 calc_die_sizes (dw_die_ref die)
11012 gcc_assert (die->die_offset == 0
11013 || (unsigned long int) die->die_offset == next_die_offset);
11014 die->die_offset = next_die_offset;
11015 next_die_offset += size_of_die (die);
11017 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
11019 if (die->die_child != NULL)
11020 /* Count the null byte used to terminate sibling lists. */
11021 next_die_offset += 1;
11024 /* Size just the base type children at the start of the CU.
11025 This is needed because build_abbrev needs to size locs
11026 and sizing of type based stack ops needs to know die_offset
11027 values for the base types. */
11030 calc_base_type_die_sizes (void)
11032 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11034 dw_die_ref base_type;
11035 #if ENABLE_ASSERT_CHECKING
11036 dw_die_ref prev = comp_unit_die ()->die_child;
11039 die_offset += size_of_die (comp_unit_die ());
11040 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
11042 #if ENABLE_ASSERT_CHECKING
11043 gcc_assert (base_type->die_offset == 0
11044 && prev->die_sib == base_type
11045 && base_type->die_child == NULL
11046 && base_type->die_abbrev);
11049 base_type->die_offset = die_offset;
11050 die_offset += size_of_die (base_type);
11054 /* Set the marks for a die and its children. We do this so
11055 that we know whether or not a reference needs to use FORM_ref_addr; only
11056 DIEs in the same CU will be marked. We used to clear out the offset
11057 and use that as the flag, but ran into ordering problems. */
11060 mark_dies (dw_die_ref die)
11064 gcc_assert (!die->die_mark);
11067 FOR_EACH_CHILD (die, c, mark_dies (c));
11070 /* Clear the marks for a die and its children. */
11073 unmark_dies (dw_die_ref die)
11077 if (! use_debug_types)
11078 gcc_assert (die->die_mark);
11081 FOR_EACH_CHILD (die, c, unmark_dies (c));
11084 /* Clear the marks for a die, its children and referred dies. */
11087 unmark_all_dies (dw_die_ref die)
11093 if (!die->die_mark)
11097 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
11099 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11100 if (AT_class (a) == dw_val_class_die_ref)
11101 unmark_all_dies (AT_ref (a));
11104 /* Return the size of the .debug_pubnames or .debug_pubtypes table
11105 generated for the compilation unit. */
11107 static unsigned long
11108 size_of_pubnames (VEC (pubname_entry, gc) * names)
11110 unsigned long size;
11114 size = DWARF_PUBNAMES_HEADER_SIZE;
11115 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
11116 if (names != pubtype_table
11117 || p->die->die_offset != 0
11118 || !flag_eliminate_unused_debug_types)
11119 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
11121 size += DWARF_OFFSET_SIZE;
11125 /* Return the size of the information in the .debug_aranges section. */
11127 static unsigned long
11128 size_of_aranges (void)
11130 unsigned long size;
11132 size = DWARF_ARANGES_HEADER_SIZE;
11134 /* Count the address/length pair for this compilation unit. */
11135 if (text_section_used)
11136 size += 2 * DWARF2_ADDR_SIZE;
11137 if (cold_text_section_used)
11138 size += 2 * DWARF2_ADDR_SIZE;
11139 if (have_multiple_function_sections)
11141 unsigned fde_idx = 0;
11143 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
11145 dw_fde_ref fde = &fde_table[fde_idx];
11147 if (!fde->in_std_section)
11148 size += 2 * DWARF2_ADDR_SIZE;
11149 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11150 size += 2 * DWARF2_ADDR_SIZE;
11154 /* Count the two zero words used to terminated the address range table. */
11155 size += 2 * DWARF2_ADDR_SIZE;
11159 /* Select the encoding of an attribute value. */
11161 static enum dwarf_form
11162 value_format (dw_attr_ref a)
11164 switch (a->dw_attr_val.val_class)
11166 case dw_val_class_addr:
11167 /* Only very few attributes allow DW_FORM_addr. */
11168 switch (a->dw_attr)
11171 case DW_AT_high_pc:
11172 case DW_AT_entry_pc:
11173 case DW_AT_trampoline:
11174 return DW_FORM_addr;
11178 switch (DWARF2_ADDR_SIZE)
11181 return DW_FORM_data1;
11183 return DW_FORM_data2;
11185 return DW_FORM_data4;
11187 return DW_FORM_data8;
11189 gcc_unreachable ();
11191 case dw_val_class_range_list:
11192 case dw_val_class_loc_list:
11193 if (dwarf_version >= 4)
11194 return DW_FORM_sec_offset;
11196 case dw_val_class_vms_delta:
11197 case dw_val_class_offset:
11198 switch (DWARF_OFFSET_SIZE)
11201 return DW_FORM_data4;
11203 return DW_FORM_data8;
11205 gcc_unreachable ();
11207 case dw_val_class_loc:
11208 if (dwarf_version >= 4)
11209 return DW_FORM_exprloc;
11210 switch (constant_size (size_of_locs (AT_loc (a))))
11213 return DW_FORM_block1;
11215 return DW_FORM_block2;
11217 gcc_unreachable ();
11219 case dw_val_class_const:
11220 return DW_FORM_sdata;
11221 case dw_val_class_unsigned_const:
11222 switch (constant_size (AT_unsigned (a)))
11225 return DW_FORM_data1;
11227 return DW_FORM_data2;
11229 return DW_FORM_data4;
11231 return DW_FORM_data8;
11233 gcc_unreachable ();
11235 case dw_val_class_const_double:
11236 switch (HOST_BITS_PER_WIDE_INT)
11239 return DW_FORM_data2;
11241 return DW_FORM_data4;
11243 return DW_FORM_data8;
11246 return DW_FORM_block1;
11248 case dw_val_class_vec:
11249 switch (constant_size (a->dw_attr_val.v.val_vec.length
11250 * a->dw_attr_val.v.val_vec.elt_size))
11253 return DW_FORM_block1;
11255 return DW_FORM_block2;
11257 return DW_FORM_block4;
11259 gcc_unreachable ();
11261 case dw_val_class_flag:
11262 if (dwarf_version >= 4)
11264 /* Currently all add_AT_flag calls pass in 1 as last argument,
11265 so DW_FORM_flag_present can be used. If that ever changes,
11266 we'll need to use DW_FORM_flag and have some optimization
11267 in build_abbrev_table that will change those to
11268 DW_FORM_flag_present if it is set to 1 in all DIEs using
11269 the same abbrev entry. */
11270 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11271 return DW_FORM_flag_present;
11273 return DW_FORM_flag;
11274 case dw_val_class_die_ref:
11275 if (AT_ref_external (a))
11276 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
11278 return DW_FORM_ref;
11279 case dw_val_class_fde_ref:
11280 return DW_FORM_data;
11281 case dw_val_class_lbl_id:
11282 return DW_FORM_addr;
11283 case dw_val_class_lineptr:
11284 case dw_val_class_macptr:
11285 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11286 case dw_val_class_str:
11287 return AT_string_form (a);
11288 case dw_val_class_file:
11289 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11292 return DW_FORM_data1;
11294 return DW_FORM_data2;
11296 return DW_FORM_data4;
11298 gcc_unreachable ();
11301 case dw_val_class_data8:
11302 return DW_FORM_data8;
11305 gcc_unreachable ();
11309 /* Output the encoding of an attribute value. */
11312 output_value_format (dw_attr_ref a)
11314 enum dwarf_form form = value_format (a);
11316 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11319 /* Output the .debug_abbrev section which defines the DIE abbreviation
11323 output_abbrev_section (void)
11325 unsigned long abbrev_id;
11327 if (abbrev_die_table_in_use == 1)
11330 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11332 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11334 dw_attr_ref a_attr;
11336 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11337 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11338 dwarf_tag_name (abbrev->die_tag));
11340 if (abbrev->die_child != NULL)
11341 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11343 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11345 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11348 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11349 dwarf_attr_name (a_attr->dw_attr));
11350 output_value_format (a_attr);
11353 dw2_asm_output_data (1, 0, NULL);
11354 dw2_asm_output_data (1, 0, NULL);
11357 /* Terminate the table. */
11358 dw2_asm_output_data (1, 0, NULL);
11361 /* Output a symbol we can use to refer to this DIE from another CU. */
11364 output_die_symbol (dw_die_ref die)
11366 char *sym = die->die_id.die_symbol;
11371 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11372 /* We make these global, not weak; if the target doesn't support
11373 .linkonce, it doesn't support combining the sections, so debugging
11375 targetm.asm_out.globalize_label (asm_out_file, sym);
11377 ASM_OUTPUT_LABEL (asm_out_file, sym);
11380 /* Return a new location list, given the begin and end range, and the
11383 static inline dw_loc_list_ref
11384 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11385 const char *section)
11387 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11389 retlist->begin = begin;
11390 retlist->end = end;
11391 retlist->expr = expr;
11392 retlist->section = section;
11397 /* Generate a new internal symbol for this location list node, if it
11398 hasn't got one yet. */
11401 gen_llsym (dw_loc_list_ref list)
11403 gcc_assert (!list->ll_symbol);
11404 list->ll_symbol = gen_internal_sym ("LLST");
11407 /* Output the location list given to us. */
11410 output_loc_list (dw_loc_list_ref list_head)
11412 dw_loc_list_ref curr = list_head;
11414 if (list_head->emitted)
11416 list_head->emitted = true;
11418 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11420 /* Walk the location list, and output each range + expression. */
11421 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11423 unsigned long size;
11424 /* Don't output an entry that starts and ends at the same address. */
11425 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
11427 if (!have_multiple_function_sections)
11429 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11430 "Location list begin address (%s)",
11431 list_head->ll_symbol);
11432 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11433 "Location list end address (%s)",
11434 list_head->ll_symbol);
11438 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11439 "Location list begin address (%s)",
11440 list_head->ll_symbol);
11441 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11442 "Location list end address (%s)",
11443 list_head->ll_symbol);
11445 size = size_of_locs (curr->expr);
11447 /* Output the block length for this list of location operations. */
11448 gcc_assert (size <= 0xffff);
11449 dw2_asm_output_data (2, size, "%s", "Location expression size");
11451 output_loc_sequence (curr->expr, -1);
11454 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11455 "Location list terminator begin (%s)",
11456 list_head->ll_symbol);
11457 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11458 "Location list terminator end (%s)",
11459 list_head->ll_symbol);
11462 /* Output a type signature. */
11465 output_signature (const char *sig, const char *name)
11469 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11470 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11473 /* Output the DIE and its attributes. Called recursively to generate
11474 the definitions of each child DIE. */
11477 output_die (dw_die_ref die)
11481 unsigned long size;
11484 /* If someone in another CU might refer to us, set up a symbol for
11485 them to point to. */
11486 if (! use_debug_types && die->die_id.die_symbol)
11487 output_die_symbol (die);
11489 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11490 (unsigned long)die->die_offset,
11491 dwarf_tag_name (die->die_tag));
11493 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11495 const char *name = dwarf_attr_name (a->dw_attr);
11497 switch (AT_class (a))
11499 case dw_val_class_addr:
11500 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11503 case dw_val_class_offset:
11504 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11508 case dw_val_class_range_list:
11510 char *p = strchr (ranges_section_label, '\0');
11512 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11513 a->dw_attr_val.v.val_offset);
11514 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11515 debug_ranges_section, "%s", name);
11520 case dw_val_class_loc:
11521 size = size_of_locs (AT_loc (a));
11523 /* Output the block length for this list of location operations. */
11524 if (dwarf_version >= 4)
11525 dw2_asm_output_data_uleb128 (size, "%s", name);
11527 dw2_asm_output_data (constant_size (size), size, "%s", name);
11529 output_loc_sequence (AT_loc (a), -1);
11532 case dw_val_class_const:
11533 /* ??? It would be slightly more efficient to use a scheme like is
11534 used for unsigned constants below, but gdb 4.x does not sign
11535 extend. Gdb 5.x does sign extend. */
11536 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11539 case dw_val_class_unsigned_const:
11540 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11541 AT_unsigned (a), "%s", name);
11544 case dw_val_class_const_double:
11546 unsigned HOST_WIDE_INT first, second;
11548 if (HOST_BITS_PER_WIDE_INT >= 64)
11549 dw2_asm_output_data (1,
11550 2 * HOST_BITS_PER_WIDE_INT
11551 / HOST_BITS_PER_CHAR,
11554 if (WORDS_BIG_ENDIAN)
11556 first = a->dw_attr_val.v.val_double.high;
11557 second = a->dw_attr_val.v.val_double.low;
11561 first = a->dw_attr_val.v.val_double.low;
11562 second = a->dw_attr_val.v.val_double.high;
11565 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11567 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11572 case dw_val_class_vec:
11574 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11575 unsigned int len = a->dw_attr_val.v.val_vec.length;
11579 dw2_asm_output_data (constant_size (len * elt_size),
11580 len * elt_size, "%s", name);
11581 if (elt_size > sizeof (HOST_WIDE_INT))
11586 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11588 i++, p += elt_size)
11589 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11590 "fp or vector constant word %u", i);
11594 case dw_val_class_flag:
11595 if (dwarf_version >= 4)
11597 /* Currently all add_AT_flag calls pass in 1 as last argument,
11598 so DW_FORM_flag_present can be used. If that ever changes,
11599 we'll need to use DW_FORM_flag and have some optimization
11600 in build_abbrev_table that will change those to
11601 DW_FORM_flag_present if it is set to 1 in all DIEs using
11602 the same abbrev entry. */
11603 gcc_assert (AT_flag (a) == 1);
11604 if (flag_debug_asm)
11605 fprintf (asm_out_file, "\t\t\t%s %s\n",
11606 ASM_COMMENT_START, name);
11609 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11612 case dw_val_class_loc_list:
11614 char *sym = AT_loc_list (a)->ll_symbol;
11617 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11622 case dw_val_class_die_ref:
11623 if (AT_ref_external (a))
11625 if (use_debug_types)
11627 comdat_type_node_ref type_node =
11628 AT_ref (a)->die_id.die_type_node;
11630 gcc_assert (type_node);
11631 output_signature (type_node->signature, name);
11635 char *sym = AT_ref (a)->die_id.die_symbol;
11639 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11640 length, whereas in DWARF3 it's always sized as an
11642 if (dwarf_version == 2)
11643 size = DWARF2_ADDR_SIZE;
11645 size = DWARF_OFFSET_SIZE;
11646 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11652 gcc_assert (AT_ref (a)->die_offset);
11653 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11658 case dw_val_class_fde_ref:
11662 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11663 a->dw_attr_val.v.val_fde_index * 2);
11664 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11669 case dw_val_class_vms_delta:
11670 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11671 AT_vms_delta2 (a), AT_vms_delta1 (a),
11675 case dw_val_class_lbl_id:
11676 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11679 case dw_val_class_lineptr:
11680 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11681 debug_line_section, "%s", name);
11684 case dw_val_class_macptr:
11685 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11686 debug_macinfo_section, "%s", name);
11689 case dw_val_class_str:
11690 if (AT_string_form (a) == DW_FORM_strp)
11691 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11692 a->dw_attr_val.v.val_str->label,
11694 "%s: \"%s\"", name, AT_string (a));
11696 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11699 case dw_val_class_file:
11701 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11703 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11704 a->dw_attr_val.v.val_file->filename);
11708 case dw_val_class_data8:
11712 for (i = 0; i < 8; i++)
11713 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11714 i == 0 ? "%s" : NULL, name);
11719 gcc_unreachable ();
11723 FOR_EACH_CHILD (die, c, output_die (c));
11725 /* Add null byte to terminate sibling list. */
11726 if (die->die_child != NULL)
11727 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11728 (unsigned long) die->die_offset);
11731 /* Output the compilation unit that appears at the beginning of the
11732 .debug_info section, and precedes the DIE descriptions. */
11735 output_compilation_unit_header (void)
11737 int ver = dwarf_version;
11739 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11740 dw2_asm_output_data (4, 0xffffffff,
11741 "Initial length escape value indicating 64-bit DWARF extension");
11742 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11743 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11744 "Length of Compilation Unit Info");
11745 dw2_asm_output_data (2, ver, "DWARF version number");
11746 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11747 debug_abbrev_section,
11748 "Offset Into Abbrev. Section");
11749 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11752 /* Output the compilation unit DIE and its children. */
11755 output_comp_unit (dw_die_ref die, int output_if_empty)
11757 const char *secname;
11758 char *oldsym, *tmp;
11760 /* Unless we are outputting main CU, we may throw away empty ones. */
11761 if (!output_if_empty && die->die_child == NULL)
11764 /* Even if there are no children of this DIE, we must output the information
11765 about the compilation unit. Otherwise, on an empty translation unit, we
11766 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11767 will then complain when examining the file. First mark all the DIEs in
11768 this CU so we know which get local refs. */
11771 build_abbrev_table (die);
11773 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11774 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11775 calc_die_sizes (die);
11777 oldsym = die->die_id.die_symbol;
11780 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11782 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11784 die->die_id.die_symbol = NULL;
11785 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11789 switch_to_section (debug_info_section);
11790 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11791 info_section_emitted = true;
11794 /* Output debugging information. */
11795 output_compilation_unit_header ();
11798 /* Leave the marks on the main CU, so we can check them in
11799 output_pubnames. */
11803 die->die_id.die_symbol = oldsym;
11807 /* Output a comdat type unit DIE and its children. */
11810 output_comdat_type_unit (comdat_type_node *node)
11812 const char *secname;
11815 #if defined (OBJECT_FORMAT_ELF)
11819 /* First mark all the DIEs in this CU so we know which get local refs. */
11820 mark_dies (node->root_die);
11822 build_abbrev_table (node->root_die);
11824 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11825 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11826 calc_die_sizes (node->root_die);
11828 #if defined (OBJECT_FORMAT_ELF)
11829 secname = ".debug_types";
11830 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11831 sprintf (tmp, "wt.");
11832 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11833 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11834 comdat_key = get_identifier (tmp);
11835 targetm.asm_out.named_section (secname,
11836 SECTION_DEBUG | SECTION_LINKONCE,
11839 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11840 sprintf (tmp, ".gnu.linkonce.wt.");
11841 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11842 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11844 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11847 /* Output debugging information. */
11848 output_compilation_unit_header ();
11849 output_signature (node->signature, "Type Signature");
11850 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11851 "Offset to Type DIE");
11852 output_die (node->root_die);
11854 unmark_dies (node->root_die);
11857 /* Return the DWARF2/3 pubname associated with a decl. */
11859 static const char *
11860 dwarf2_name (tree decl, int scope)
11862 if (DECL_NAMELESS (decl))
11864 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11867 /* Add a new entry to .debug_pubnames if appropriate. */
11870 add_pubname_string (const char *str, dw_die_ref die)
11872 if (targetm.want_debug_pub_sections)
11877 e.name = xstrdup (str);
11878 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11883 add_pubname (tree decl, dw_die_ref die)
11885 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11887 const char *name = dwarf2_name (decl, 1);
11889 add_pubname_string (name, die);
11893 /* Add a new entry to .debug_pubtypes if appropriate. */
11896 add_pubtype (tree decl, dw_die_ref die)
11900 if (!targetm.want_debug_pub_sections)
11904 if ((TREE_PUBLIC (decl)
11905 || is_cu_die (die->die_parent))
11906 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11911 if (TYPE_NAME (decl))
11913 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11914 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11915 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11916 && DECL_NAME (TYPE_NAME (decl)))
11917 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11919 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11924 e.name = dwarf2_name (decl, 1);
11926 e.name = xstrdup (e.name);
11929 /* If we don't have a name for the type, there's no point in adding
11930 it to the table. */
11931 if (e.name && e.name[0] != '\0')
11932 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11936 /* Output the public names table used to speed up access to externally
11937 visible names; or the public types table used to find type definitions. */
11940 output_pubnames (VEC (pubname_entry, gc) * names)
11943 unsigned long pubnames_length = size_of_pubnames (names);
11946 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11947 dw2_asm_output_data (4, 0xffffffff,
11948 "Initial length escape value indicating 64-bit DWARF extension");
11949 if (names == pubname_table)
11950 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11951 "Length of Public Names Info");
11953 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11954 "Length of Public Type Names Info");
11955 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11956 dw2_asm_output_data (2, 2, "DWARF Version");
11957 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11958 debug_info_section,
11959 "Offset of Compilation Unit Info");
11960 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11961 "Compilation Unit Length");
11963 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11965 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11966 if (names == pubname_table)
11967 gcc_assert (pub->die->die_mark);
11969 if (names != pubtype_table
11970 || pub->die->die_offset != 0
11971 || !flag_eliminate_unused_debug_types)
11973 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11976 dw2_asm_output_nstring (pub->name, -1, "external name");
11980 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11983 /* Output the information that goes into the .debug_aranges table.
11984 Namely, define the beginning and ending address range of the
11985 text section generated for this compilation unit. */
11988 output_aranges (unsigned long aranges_length)
11992 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11993 dw2_asm_output_data (4, 0xffffffff,
11994 "Initial length escape value indicating 64-bit DWARF extension");
11995 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11996 "Length of Address Ranges Info");
11997 /* Version number for aranges is still 2, even in DWARF3. */
11998 dw2_asm_output_data (2, 2, "DWARF Version");
11999 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12000 debug_info_section,
12001 "Offset of Compilation Unit Info");
12002 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
12003 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
12005 /* We need to align to twice the pointer size here. */
12006 if (DWARF_ARANGES_PAD_SIZE)
12008 /* Pad using a 2 byte words so that padding is correct for any
12010 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
12011 2 * DWARF2_ADDR_SIZE);
12012 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
12013 dw2_asm_output_data (2, 0, NULL);
12016 /* It is necessary not to output these entries if the sections were
12017 not used; if the sections were not used, the length will be 0 and
12018 the address may end up as 0 if the section is discarded by ld
12019 --gc-sections, leaving an invalid (0, 0) entry that can be
12020 confused with the terminator. */
12021 if (text_section_used)
12023 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
12024 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
12025 text_section_label, "Length");
12027 if (cold_text_section_used)
12029 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
12031 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
12032 cold_text_section_label, "Length");
12035 if (have_multiple_function_sections)
12037 unsigned fde_idx = 0;
12039 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
12041 dw_fde_ref fde = &fde_table[fde_idx];
12043 if (!fde->in_std_section)
12045 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
12047 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
12048 fde->dw_fde_begin, "Length");
12050 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
12052 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
12054 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
12055 fde->dw_fde_second_begin, "Length");
12060 /* Output the terminator words. */
12061 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12062 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12065 /* Add a new entry to .debug_ranges. Return the offset at which it
12068 static unsigned int
12069 add_ranges_num (int num)
12071 unsigned int in_use = ranges_table_in_use;
12073 if (in_use == ranges_table_allocated)
12075 ranges_table_allocated += RANGES_TABLE_INCREMENT;
12076 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
12077 ranges_table_allocated);
12078 memset (ranges_table + ranges_table_in_use, 0,
12079 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
12082 ranges_table[in_use].num = num;
12083 ranges_table_in_use = in_use + 1;
12085 return in_use * 2 * DWARF2_ADDR_SIZE;
12088 /* Add a new entry to .debug_ranges corresponding to a block, or a
12089 range terminator if BLOCK is NULL. */
12091 static unsigned int
12092 add_ranges (const_tree block)
12094 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
12097 /* Add a new entry to .debug_ranges corresponding to a pair of
12101 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
12104 unsigned int in_use = ranges_by_label_in_use;
12105 unsigned int offset;
12107 if (in_use == ranges_by_label_allocated)
12109 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
12110 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
12112 ranges_by_label_allocated);
12113 memset (ranges_by_label + ranges_by_label_in_use, 0,
12114 RANGES_TABLE_INCREMENT
12115 * sizeof (struct dw_ranges_by_label_struct));
12118 ranges_by_label[in_use].begin = begin;
12119 ranges_by_label[in_use].end = end;
12120 ranges_by_label_in_use = in_use + 1;
12122 offset = add_ranges_num (-(int)in_use - 1);
12125 add_AT_range_list (die, DW_AT_ranges, offset);
12131 output_ranges (void)
12134 static const char *const start_fmt = "Offset %#x";
12135 const char *fmt = start_fmt;
12137 for (i = 0; i < ranges_table_in_use; i++)
12139 int block_num = ranges_table[i].num;
12143 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12144 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12146 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12147 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12149 /* If all code is in the text section, then the compilation
12150 unit base address defaults to DW_AT_low_pc, which is the
12151 base of the text section. */
12152 if (!have_multiple_function_sections)
12154 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
12155 text_section_label,
12156 fmt, i * 2 * DWARF2_ADDR_SIZE);
12157 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
12158 text_section_label, NULL);
12161 /* Otherwise, the compilation unit base address is zero,
12162 which allows us to use absolute addresses, and not worry
12163 about whether the target supports cross-section
12167 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12168 fmt, i * 2 * DWARF2_ADDR_SIZE);
12169 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
12175 /* Negative block_num stands for an index into ranges_by_label. */
12176 else if (block_num < 0)
12178 int lab_idx = - block_num - 1;
12180 if (!have_multiple_function_sections)
12182 gcc_unreachable ();
12184 /* If we ever use add_ranges_by_labels () for a single
12185 function section, all we have to do is to take out
12186 the #if 0 above. */
12187 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12188 ranges_by_label[lab_idx].begin,
12189 text_section_label,
12190 fmt, i * 2 * DWARF2_ADDR_SIZE);
12191 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12192 ranges_by_label[lab_idx].end,
12193 text_section_label, NULL);
12198 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12199 ranges_by_label[lab_idx].begin,
12200 fmt, i * 2 * DWARF2_ADDR_SIZE);
12201 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12202 ranges_by_label[lab_idx].end,
12208 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12209 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12215 /* Data structure containing information about input files. */
12218 const char *path; /* Complete file name. */
12219 const char *fname; /* File name part. */
12220 int length; /* Length of entire string. */
12221 struct dwarf_file_data * file_idx; /* Index in input file table. */
12222 int dir_idx; /* Index in directory table. */
12225 /* Data structure containing information about directories with source
12229 const char *path; /* Path including directory name. */
12230 int length; /* Path length. */
12231 int prefix; /* Index of directory entry which is a prefix. */
12232 int count; /* Number of files in this directory. */
12233 int dir_idx; /* Index of directory used as base. */
12236 /* Callback function for file_info comparison. We sort by looking at
12237 the directories in the path. */
12240 file_info_cmp (const void *p1, const void *p2)
12242 const struct file_info *const s1 = (const struct file_info *) p1;
12243 const struct file_info *const s2 = (const struct file_info *) p2;
12244 const unsigned char *cp1;
12245 const unsigned char *cp2;
12247 /* Take care of file names without directories. We need to make sure that
12248 we return consistent values to qsort since some will get confused if
12249 we return the same value when identical operands are passed in opposite
12250 orders. So if neither has a directory, return 0 and otherwise return
12251 1 or -1 depending on which one has the directory. */
12252 if ((s1->path == s1->fname || s2->path == s2->fname))
12253 return (s2->path == s2->fname) - (s1->path == s1->fname);
12255 cp1 = (const unsigned char *) s1->path;
12256 cp2 = (const unsigned char *) s2->path;
12262 /* Reached the end of the first path? If so, handle like above. */
12263 if ((cp1 == (const unsigned char *) s1->fname)
12264 || (cp2 == (const unsigned char *) s2->fname))
12265 return ((cp2 == (const unsigned char *) s2->fname)
12266 - (cp1 == (const unsigned char *) s1->fname));
12268 /* Character of current path component the same? */
12269 else if (*cp1 != *cp2)
12270 return *cp1 - *cp2;
12274 struct file_name_acquire_data
12276 struct file_info *files;
12281 /* Traversal function for the hash table. */
12284 file_name_acquire (void ** slot, void *data)
12286 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12287 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12288 struct file_info *fi;
12291 gcc_assert (fnad->max_files >= d->emitted_number);
12293 if (! d->emitted_number)
12296 gcc_assert (fnad->max_files != fnad->used_files);
12298 fi = fnad->files + fnad->used_files++;
12300 /* Skip all leading "./". */
12302 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12305 /* Create a new array entry. */
12307 fi->length = strlen (f);
12310 /* Search for the file name part. */
12311 f = strrchr (f, DIR_SEPARATOR);
12312 #if defined (DIR_SEPARATOR_2)
12314 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12318 if (f == NULL || f < g)
12324 fi->fname = f == NULL ? fi->path : f + 1;
12328 /* Output the directory table and the file name table. We try to minimize
12329 the total amount of memory needed. A heuristic is used to avoid large
12330 slowdowns with many input files. */
12333 output_file_names (void)
12335 struct file_name_acquire_data fnad;
12337 struct file_info *files;
12338 struct dir_info *dirs;
12346 if (!last_emitted_file)
12348 dw2_asm_output_data (1, 0, "End directory table");
12349 dw2_asm_output_data (1, 0, "End file name table");
12353 numfiles = last_emitted_file->emitted_number;
12355 /* Allocate the various arrays we need. */
12356 files = XALLOCAVEC (struct file_info, numfiles);
12357 dirs = XALLOCAVEC (struct dir_info, numfiles);
12359 fnad.files = files;
12360 fnad.used_files = 0;
12361 fnad.max_files = numfiles;
12362 htab_traverse (file_table, file_name_acquire, &fnad);
12363 gcc_assert (fnad.used_files == fnad.max_files);
12365 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12367 /* Find all the different directories used. */
12368 dirs[0].path = files[0].path;
12369 dirs[0].length = files[0].fname - files[0].path;
12370 dirs[0].prefix = -1;
12372 dirs[0].dir_idx = 0;
12373 files[0].dir_idx = 0;
12376 for (i = 1; i < numfiles; i++)
12377 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12378 && memcmp (dirs[ndirs - 1].path, files[i].path,
12379 dirs[ndirs - 1].length) == 0)
12381 /* Same directory as last entry. */
12382 files[i].dir_idx = ndirs - 1;
12383 ++dirs[ndirs - 1].count;
12389 /* This is a new directory. */
12390 dirs[ndirs].path = files[i].path;
12391 dirs[ndirs].length = files[i].fname - files[i].path;
12392 dirs[ndirs].count = 1;
12393 dirs[ndirs].dir_idx = ndirs;
12394 files[i].dir_idx = ndirs;
12396 /* Search for a prefix. */
12397 dirs[ndirs].prefix = -1;
12398 for (j = 0; j < ndirs; j++)
12399 if (dirs[j].length < dirs[ndirs].length
12400 && dirs[j].length > 1
12401 && (dirs[ndirs].prefix == -1
12402 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12403 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12404 dirs[ndirs].prefix = j;
12409 /* Now to the actual work. We have to find a subset of the directories which
12410 allow expressing the file name using references to the directory table
12411 with the least amount of characters. We do not do an exhaustive search
12412 where we would have to check out every combination of every single
12413 possible prefix. Instead we use a heuristic which provides nearly optimal
12414 results in most cases and never is much off. */
12415 saved = XALLOCAVEC (int, ndirs);
12416 savehere = XALLOCAVEC (int, ndirs);
12418 memset (saved, '\0', ndirs * sizeof (saved[0]));
12419 for (i = 0; i < ndirs; i++)
12424 /* We can always save some space for the current directory. But this
12425 does not mean it will be enough to justify adding the directory. */
12426 savehere[i] = dirs[i].length;
12427 total = (savehere[i] - saved[i]) * dirs[i].count;
12429 for (j = i + 1; j < ndirs; j++)
12432 if (saved[j] < dirs[i].length)
12434 /* Determine whether the dirs[i] path is a prefix of the
12438 k = dirs[j].prefix;
12439 while (k != -1 && k != (int) i)
12440 k = dirs[k].prefix;
12444 /* Yes it is. We can possibly save some memory by
12445 writing the filenames in dirs[j] relative to
12447 savehere[j] = dirs[i].length;
12448 total += (savehere[j] - saved[j]) * dirs[j].count;
12453 /* Check whether we can save enough to justify adding the dirs[i]
12455 if (total > dirs[i].length + 1)
12457 /* It's worthwhile adding. */
12458 for (j = i; j < ndirs; j++)
12459 if (savehere[j] > 0)
12461 /* Remember how much we saved for this directory so far. */
12462 saved[j] = savehere[j];
12464 /* Remember the prefix directory. */
12465 dirs[j].dir_idx = i;
12470 /* Emit the directory name table. */
12471 idx_offset = dirs[0].length > 0 ? 1 : 0;
12472 for (i = 1 - idx_offset; i < ndirs; i++)
12473 dw2_asm_output_nstring (dirs[i].path,
12475 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12476 "Directory Entry: %#x", i + idx_offset);
12478 dw2_asm_output_data (1, 0, "End directory table");
12480 /* We have to emit them in the order of emitted_number since that's
12481 used in the debug info generation. To do this efficiently we
12482 generate a back-mapping of the indices first. */
12483 backmap = XALLOCAVEC (int, numfiles);
12484 for (i = 0; i < numfiles; i++)
12485 backmap[files[i].file_idx->emitted_number - 1] = i;
12487 /* Now write all the file names. */
12488 for (i = 0; i < numfiles; i++)
12490 int file_idx = backmap[i];
12491 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12493 #ifdef VMS_DEBUGGING_INFO
12494 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12496 /* Setting these fields can lead to debugger miscomparisons,
12497 but VMS Debug requires them to be set correctly. */
12502 int maxfilelen = strlen (files[file_idx].path)
12503 + dirs[dir_idx].length
12504 + MAX_VMS_VERSION_LEN + 1;
12505 char *filebuf = XALLOCAVEC (char, maxfilelen);
12507 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12508 snprintf (filebuf, maxfilelen, "%s;%d",
12509 files[file_idx].path + dirs[dir_idx].length, ver);
12511 dw2_asm_output_nstring
12512 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12514 /* Include directory index. */
12515 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12517 /* Modification time. */
12518 dw2_asm_output_data_uleb128
12519 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12523 /* File length in bytes. */
12524 dw2_asm_output_data_uleb128
12525 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12529 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12530 "File Entry: %#x", (unsigned) i + 1);
12532 /* Include directory index. */
12533 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12535 /* Modification time. */
12536 dw2_asm_output_data_uleb128 (0, NULL);
12538 /* File length in bytes. */
12539 dw2_asm_output_data_uleb128 (0, NULL);
12540 #endif /* VMS_DEBUGGING_INFO */
12543 dw2_asm_output_data (1, 0, "End file name table");
12547 /* Output one line number table into the .debug_line section. */
12550 output_one_line_info_table (dw_line_info_table *table)
12552 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12553 unsigned int current_line = 1;
12554 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
12555 dw_line_info_entry *ent;
12558 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
12560 switch (ent->opcode)
12562 case LI_set_address:
12563 /* ??? Unfortunately, we have little choice here currently, and
12564 must always use the most general form. GCC does not know the
12565 address delta itself, so we can't use DW_LNS_advance_pc. Many
12566 ports do have length attributes which will give an upper bound
12567 on the address range. We could perhaps use length attributes
12568 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12569 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
12571 /* This can handle any delta. This takes
12572 4+DWARF2_ADDR_SIZE bytes. */
12573 dw2_asm_output_data (1, 0, "set address %s", line_label);
12574 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12575 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12576 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12580 if (ent->val == current_line)
12582 /* We still need to start a new row, so output a copy insn. */
12583 dw2_asm_output_data (1, DW_LNS_copy,
12584 "copy line %u", current_line);
12588 int line_offset = ent->val - current_line;
12589 int line_delta = line_offset - DWARF_LINE_BASE;
12591 current_line = ent->val;
12592 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12594 /* This can handle deltas from -10 to 234, using the current
12595 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
12596 This takes 1 byte. */
12597 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12598 "line %u", current_line);
12602 /* This can handle any delta. This takes at least 4 bytes,
12603 depending on the value being encoded. */
12604 dw2_asm_output_data (1, DW_LNS_advance_line,
12605 "advance to line %u", current_line);
12606 dw2_asm_output_data_sleb128 (line_offset, NULL);
12607 dw2_asm_output_data (1, DW_LNS_copy, NULL);
12613 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
12614 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12617 case LI_set_column:
12618 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
12619 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12622 case LI_negate_stmt:
12623 current_is_stmt = !current_is_stmt;
12624 dw2_asm_output_data (1, DW_LNS_negate_stmt,
12625 "is_stmt %d", current_is_stmt);
12628 case LI_set_prologue_end:
12629 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
12630 "set prologue end");
12633 case LI_set_epilogue_begin:
12634 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
12635 "set epilogue begin");
12638 case LI_set_discriminator:
12639 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
12640 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
12641 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
12642 dw2_asm_output_data_uleb128 (ent->val, NULL);
12647 /* Emit debug info for the address of the end of the table. */
12648 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
12649 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12650 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12651 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
12653 dw2_asm_output_data (1, 0, "end sequence");
12654 dw2_asm_output_data_uleb128 (1, NULL);
12655 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12658 /* Output the source line number correspondence information. This
12659 information goes into the .debug_line section. */
12662 output_line_info (void)
12664 char l1[20], l2[20], p1[20], p2[20];
12665 int ver = dwarf_version;
12666 bool saw_one = false;
12669 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12670 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12671 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12672 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12674 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12675 dw2_asm_output_data (4, 0xffffffff,
12676 "Initial length escape value indicating 64-bit DWARF extension");
12677 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12678 "Length of Source Line Info");
12679 ASM_OUTPUT_LABEL (asm_out_file, l1);
12681 dw2_asm_output_data (2, ver, "DWARF Version");
12682 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12683 ASM_OUTPUT_LABEL (asm_out_file, p1);
12685 /* Define the architecture-dependent minimum instruction length (in bytes).
12686 In this implementation of DWARF, this field is used for information
12687 purposes only. Since GCC generates assembly language, we have no
12688 a priori knowledge of how many instruction bytes are generated for each
12689 source line, and therefore can use only the DW_LNE_set_address and
12690 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12691 this as '1', which is "correct enough" for all architectures,
12692 and don't let the target override. */
12693 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12696 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12697 "Maximum Operations Per Instruction");
12698 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12699 "Default is_stmt_start flag");
12700 dw2_asm_output_data (1, DWARF_LINE_BASE,
12701 "Line Base Value (Special Opcodes)");
12702 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12703 "Line Range Value (Special Opcodes)");
12704 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12705 "Special Opcode Base");
12707 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12712 case DW_LNS_advance_pc:
12713 case DW_LNS_advance_line:
12714 case DW_LNS_set_file:
12715 case DW_LNS_set_column:
12716 case DW_LNS_fixed_advance_pc:
12717 case DW_LNS_set_isa:
12725 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12729 /* Write out the information about the files we use. */
12730 output_file_names ();
12731 ASM_OUTPUT_LABEL (asm_out_file, p2);
12733 if (separate_line_info)
12735 dw_line_info_table *table;
12738 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
12741 output_one_line_info_table (table);
12745 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
12747 output_one_line_info_table (cold_text_section_line_info);
12751 /* ??? Some Darwin linkers crash on a .debug_line section with no
12752 sequences. Further, merely a DW_LNE_end_sequence entry is not
12753 sufficient -- the address column must also be initialized.
12754 Make sure to output at least one set_address/end_sequence pair,
12755 choosing .text since that section is always present. */
12756 if (text_section_line_info->in_use || !saw_one)
12757 output_one_line_info_table (text_section_line_info);
12759 /* Output the marker for the end of the line number info. */
12760 ASM_OUTPUT_LABEL (asm_out_file, l2);
12763 /* Given a pointer to a tree node for some base type, return a pointer to
12764 a DIE that describes the given type.
12766 This routine must only be called for GCC type nodes that correspond to
12767 Dwarf base (fundamental) types. */
12770 base_type_die (tree type)
12772 dw_die_ref base_type_result;
12773 enum dwarf_type encoding;
12775 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12778 /* If this is a subtype that should not be emitted as a subrange type,
12779 use the base type. See subrange_type_for_debug_p. */
12780 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12781 type = TREE_TYPE (type);
12783 switch (TREE_CODE (type))
12786 if ((dwarf_version >= 4 || !dwarf_strict)
12787 && TYPE_NAME (type)
12788 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12789 && DECL_IS_BUILTIN (TYPE_NAME (type))
12790 && DECL_NAME (TYPE_NAME (type)))
12792 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12793 if (strcmp (name, "char16_t") == 0
12794 || strcmp (name, "char32_t") == 0)
12796 encoding = DW_ATE_UTF;
12800 if (TYPE_STRING_FLAG (type))
12802 if (TYPE_UNSIGNED (type))
12803 encoding = DW_ATE_unsigned_char;
12805 encoding = DW_ATE_signed_char;
12807 else if (TYPE_UNSIGNED (type))
12808 encoding = DW_ATE_unsigned;
12810 encoding = DW_ATE_signed;
12814 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12816 if (dwarf_version >= 3 || !dwarf_strict)
12817 encoding = DW_ATE_decimal_float;
12819 encoding = DW_ATE_lo_user;
12822 encoding = DW_ATE_float;
12825 case FIXED_POINT_TYPE:
12826 if (!(dwarf_version >= 3 || !dwarf_strict))
12827 encoding = DW_ATE_lo_user;
12828 else if (TYPE_UNSIGNED (type))
12829 encoding = DW_ATE_unsigned_fixed;
12831 encoding = DW_ATE_signed_fixed;
12834 /* Dwarf2 doesn't know anything about complex ints, so use
12835 a user defined type for it. */
12837 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12838 encoding = DW_ATE_complex_float;
12840 encoding = DW_ATE_lo_user;
12844 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12845 encoding = DW_ATE_boolean;
12849 /* No other TREE_CODEs are Dwarf fundamental types. */
12850 gcc_unreachable ();
12853 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12855 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12856 int_size_in_bytes (type));
12857 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12859 return base_type_result;
12862 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12863 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12866 is_base_type (tree type)
12868 switch (TREE_CODE (type))
12874 case FIXED_POINT_TYPE:
12882 case QUAL_UNION_TYPE:
12883 case ENUMERAL_TYPE:
12884 case FUNCTION_TYPE:
12887 case REFERENCE_TYPE:
12895 gcc_unreachable ();
12901 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12902 node, return the size in bits for the type if it is a constant, or else
12903 return the alignment for the type if the type's size is not constant, or
12904 else return BITS_PER_WORD if the type actually turns out to be an
12905 ERROR_MARK node. */
12907 static inline unsigned HOST_WIDE_INT
12908 simple_type_size_in_bits (const_tree type)
12910 if (TREE_CODE (type) == ERROR_MARK)
12911 return BITS_PER_WORD;
12912 else if (TYPE_SIZE (type) == NULL_TREE)
12914 else if (host_integerp (TYPE_SIZE (type), 1))
12915 return tree_low_cst (TYPE_SIZE (type), 1);
12917 return TYPE_ALIGN (type);
12920 /* Similarly, but return a double_int instead of UHWI. */
12922 static inline double_int
12923 double_int_type_size_in_bits (const_tree type)
12925 if (TREE_CODE (type) == ERROR_MARK)
12926 return uhwi_to_double_int (BITS_PER_WORD);
12927 else if (TYPE_SIZE (type) == NULL_TREE)
12928 return double_int_zero;
12929 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12930 return tree_to_double_int (TYPE_SIZE (type));
12932 return uhwi_to_double_int (TYPE_ALIGN (type));
12935 /* Given a pointer to a tree node for a subrange type, return a pointer
12936 to a DIE that describes the given type. */
12939 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12941 dw_die_ref subrange_die;
12942 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12944 if (context_die == NULL)
12945 context_die = comp_unit_die ();
12947 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12949 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12951 /* The size of the subrange type and its base type do not match,
12952 so we need to generate a size attribute for the subrange type. */
12953 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12957 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12959 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12961 return subrange_die;
12964 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12965 entry that chains various modifiers in front of the given type. */
12968 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12969 dw_die_ref context_die)
12971 enum tree_code code = TREE_CODE (type);
12972 dw_die_ref mod_type_die;
12973 dw_die_ref sub_die = NULL;
12974 tree item_type = NULL;
12975 tree qualified_type;
12976 tree name, low, high;
12978 if (code == ERROR_MARK)
12981 /* See if we already have the appropriately qualified variant of
12984 = get_qualified_type (type,
12985 ((is_const_type ? TYPE_QUAL_CONST : 0)
12986 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12988 if (qualified_type == sizetype
12989 && TYPE_NAME (qualified_type)
12990 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12992 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
12994 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
12995 && TYPE_PRECISION (t)
12996 == TYPE_PRECISION (qualified_type)
12997 && TYPE_UNSIGNED (t)
12998 == TYPE_UNSIGNED (qualified_type));
12999 qualified_type = t;
13002 /* If we do, then we can just use its DIE, if it exists. */
13003 if (qualified_type)
13005 mod_type_die = lookup_type_die (qualified_type);
13007 return mod_type_die;
13010 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
13012 /* Handle C typedef types. */
13013 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
13014 && !DECL_ARTIFICIAL (name))
13016 tree dtype = TREE_TYPE (name);
13018 if (qualified_type == dtype)
13020 /* For a named type, use the typedef. */
13021 gen_type_die (qualified_type, context_die);
13022 return lookup_type_die (qualified_type);
13024 else if (is_const_type < TYPE_READONLY (dtype)
13025 || is_volatile_type < TYPE_VOLATILE (dtype)
13026 || (is_const_type <= TYPE_READONLY (dtype)
13027 && is_volatile_type <= TYPE_VOLATILE (dtype)
13028 && DECL_ORIGINAL_TYPE (name) != type))
13029 /* cv-unqualified version of named type. Just use the unnamed
13030 type to which it refers. */
13031 return modified_type_die (DECL_ORIGINAL_TYPE (name),
13032 is_const_type, is_volatile_type,
13034 /* Else cv-qualified version of named type; fall through. */
13038 /* If both is_const_type and is_volatile_type, prefer the path
13039 which leads to a qualified type. */
13040 && (!is_volatile_type
13041 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
13042 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
13044 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
13045 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
13047 else if (is_volatile_type)
13049 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
13050 sub_die = modified_type_die (type, is_const_type, 0, context_die);
13052 else if (code == POINTER_TYPE)
13054 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
13055 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13056 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13057 item_type = TREE_TYPE (type);
13058 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13059 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13060 TYPE_ADDR_SPACE (item_type));
13062 else if (code == REFERENCE_TYPE)
13064 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
13065 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
13068 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
13069 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13070 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13071 item_type = TREE_TYPE (type);
13072 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13073 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13074 TYPE_ADDR_SPACE (item_type));
13076 else if (code == INTEGER_TYPE
13077 && TREE_TYPE (type) != NULL_TREE
13078 && subrange_type_for_debug_p (type, &low, &high))
13080 mod_type_die = subrange_type_die (type, low, high, context_die);
13081 item_type = TREE_TYPE (type);
13083 else if (is_base_type (type))
13084 mod_type_die = base_type_die (type);
13087 gen_type_die (type, context_die);
13089 /* We have to get the type_main_variant here (and pass that to the
13090 `lookup_type_die' routine) because the ..._TYPE node we have
13091 might simply be a *copy* of some original type node (where the
13092 copy was created to help us keep track of typedef names) and
13093 that copy might have a different TYPE_UID from the original
13095 if (TREE_CODE (type) != VECTOR_TYPE)
13096 return lookup_type_die (type_main_variant (type));
13098 /* Vectors have the debugging information in the type,
13099 not the main variant. */
13100 return lookup_type_die (type);
13103 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
13104 don't output a DW_TAG_typedef, since there isn't one in the
13105 user's program; just attach a DW_AT_name to the type.
13106 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
13107 if the base type already has the same name. */
13109 && ((TREE_CODE (name) != TYPE_DECL
13110 && (qualified_type == TYPE_MAIN_VARIANT (type)
13111 || (!is_const_type && !is_volatile_type)))
13112 || (TREE_CODE (name) == TYPE_DECL
13113 && TREE_TYPE (name) == qualified_type
13114 && DECL_NAME (name))))
13116 if (TREE_CODE (name) == TYPE_DECL)
13117 /* Could just call add_name_and_src_coords_attributes here,
13118 but since this is a builtin type it doesn't have any
13119 useful source coordinates anyway. */
13120 name = DECL_NAME (name);
13121 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
13122 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
13124 /* This probably indicates a bug. */
13125 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
13126 add_name_attribute (mod_type_die, "__unknown__");
13128 if (qualified_type)
13129 equate_type_number_to_die (qualified_type, mod_type_die);
13132 /* We must do this after the equate_type_number_to_die call, in case
13133 this is a recursive type. This ensures that the modified_type_die
13134 recursion will terminate even if the type is recursive. Recursive
13135 types are possible in Ada. */
13136 sub_die = modified_type_die (item_type,
13137 TYPE_READONLY (item_type),
13138 TYPE_VOLATILE (item_type),
13141 if (sub_die != NULL)
13142 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
13144 return mod_type_die;
13147 /* Generate DIEs for the generic parameters of T.
13148 T must be either a generic type or a generic function.
13149 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13152 gen_generic_params_dies (tree t)
13156 dw_die_ref die = NULL;
13158 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13162 die = lookup_type_die (t);
13163 else if (DECL_P (t))
13164 die = lookup_decl_die (t);
13168 parms = lang_hooks.get_innermost_generic_parms (t);
13170 /* T has no generic parameter. It means T is neither a generic type
13171 or function. End of story. */
13174 parms_num = TREE_VEC_LENGTH (parms);
13175 args = lang_hooks.get_innermost_generic_args (t);
13176 for (i = 0; i < parms_num; i++)
13178 tree parm, arg, arg_pack_elems;
13180 parm = TREE_VEC_ELT (parms, i);
13181 arg = TREE_VEC_ELT (args, i);
13182 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13183 gcc_assert (parm && TREE_VALUE (parm) && arg);
13185 if (parm && TREE_VALUE (parm) && arg)
13187 /* If PARM represents a template parameter pack,
13188 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13189 by DW_TAG_template_*_parameter DIEs for the argument
13190 pack elements of ARG. Note that ARG would then be
13191 an argument pack. */
13192 if (arg_pack_elems)
13193 template_parameter_pack_die (TREE_VALUE (parm),
13197 generic_parameter_die (TREE_VALUE (parm), arg,
13198 true /* Emit DW_AT_name */, die);
13203 /* Create and return a DIE for PARM which should be
13204 the representation of a generic type parameter.
13205 For instance, in the C++ front end, PARM would be a template parameter.
13206 ARG is the argument to PARM.
13207 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13209 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13210 as a child node. */
13213 generic_parameter_die (tree parm, tree arg,
13215 dw_die_ref parent_die)
13217 dw_die_ref tmpl_die = NULL;
13218 const char *name = NULL;
13220 if (!parm || !DECL_NAME (parm) || !arg)
13223 /* We support non-type generic parameters and arguments,
13224 type generic parameters and arguments, as well as
13225 generic generic parameters (a.k.a. template template parameters in C++)
13227 if (TREE_CODE (parm) == PARM_DECL)
13228 /* PARM is a nontype generic parameter */
13229 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13230 else if (TREE_CODE (parm) == TYPE_DECL)
13231 /* PARM is a type generic parameter. */
13232 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13233 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13234 /* PARM is a generic generic parameter.
13235 Its DIE is a GNU extension. It shall have a
13236 DW_AT_name attribute to represent the name of the template template
13237 parameter, and a DW_AT_GNU_template_name attribute to represent the
13238 name of the template template argument. */
13239 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13242 gcc_unreachable ();
13248 /* If PARM is a generic parameter pack, it means we are
13249 emitting debug info for a template argument pack element.
13250 In other terms, ARG is a template argument pack element.
13251 In that case, we don't emit any DW_AT_name attribute for
13255 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13257 add_AT_string (tmpl_die, DW_AT_name, name);
13260 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13262 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13263 TMPL_DIE should have a child DW_AT_type attribute that is set
13264 to the type of the argument to PARM, which is ARG.
13265 If PARM is a type generic parameter, TMPL_DIE should have a
13266 child DW_AT_type that is set to ARG. */
13267 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13268 add_type_attribute (tmpl_die, tmpl_type, 0,
13269 TREE_THIS_VOLATILE (tmpl_type),
13274 /* So TMPL_DIE is a DIE representing a
13275 a generic generic template parameter, a.k.a template template
13276 parameter in C++ and arg is a template. */
13278 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13279 to the name of the argument. */
13280 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13282 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13285 if (TREE_CODE (parm) == PARM_DECL)
13286 /* So PARM is a non-type generic parameter.
13287 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13288 attribute of TMPL_DIE which value represents the value
13290 We must be careful here:
13291 The value of ARG might reference some function decls.
13292 We might currently be emitting debug info for a generic
13293 type and types are emitted before function decls, we don't
13294 know if the function decls referenced by ARG will actually be
13295 emitted after cgraph computations.
13296 So must defer the generation of the DW_AT_const_value to
13297 after cgraph is ready. */
13298 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13304 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13305 PARM_PACK must be a template parameter pack. The returned DIE
13306 will be child DIE of PARENT_DIE. */
13309 template_parameter_pack_die (tree parm_pack,
13310 tree parm_pack_args,
13311 dw_die_ref parent_die)
13316 gcc_assert (parent_die && parm_pack);
13318 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13319 add_name_and_src_coords_attributes (die, parm_pack);
13320 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13321 generic_parameter_die (parm_pack,
13322 TREE_VEC_ELT (parm_pack_args, j),
13323 false /* Don't emit DW_AT_name */,
13328 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13329 an enumerated type. */
13332 type_is_enum (const_tree type)
13334 return TREE_CODE (type) == ENUMERAL_TYPE;
13337 /* Return the DBX register number described by a given RTL node. */
13339 static unsigned int
13340 dbx_reg_number (const_rtx rtl)
13342 unsigned regno = REGNO (rtl);
13344 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13346 #ifdef LEAF_REG_REMAP
13347 if (current_function_uses_only_leaf_regs)
13349 int leaf_reg = LEAF_REG_REMAP (regno);
13350 if (leaf_reg != -1)
13351 regno = (unsigned) leaf_reg;
13355 return DBX_REGISTER_NUMBER (regno);
13358 /* Optionally add a DW_OP_piece term to a location description expression.
13359 DW_OP_piece is only added if the location description expression already
13360 doesn't end with DW_OP_piece. */
13363 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13365 dw_loc_descr_ref loc;
13367 if (*list_head != NULL)
13369 /* Find the end of the chain. */
13370 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13373 if (loc->dw_loc_opc != DW_OP_piece)
13374 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13378 /* Return a location descriptor that designates a machine register or
13379 zero if there is none. */
13381 static dw_loc_descr_ref
13382 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13386 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13389 /* We only use "frame base" when we're sure we're talking about the
13390 post-prologue local stack frame. We do this by *not* running
13391 register elimination until this point, and recognizing the special
13392 argument pointer and soft frame pointer rtx's.
13393 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13394 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13395 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13397 dw_loc_descr_ref result = NULL;
13399 if (dwarf_version >= 4 || !dwarf_strict)
13401 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
13404 add_loc_descr (&result,
13405 new_loc_descr (DW_OP_stack_value, 0, 0));
13410 regs = targetm.dwarf_register_span (rtl);
13412 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13413 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13415 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13418 /* Return a location descriptor that designates a machine register for
13419 a given hard register number. */
13421 static dw_loc_descr_ref
13422 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13424 dw_loc_descr_ref reg_loc_descr;
13428 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13430 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13432 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13433 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13435 return reg_loc_descr;
13438 /* Given an RTL of a register, return a location descriptor that
13439 designates a value that spans more than one register. */
13441 static dw_loc_descr_ref
13442 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13443 enum var_init_status initialized)
13445 int nregs, size, i;
13447 dw_loc_descr_ref loc_result = NULL;
13450 #ifdef LEAF_REG_REMAP
13451 if (current_function_uses_only_leaf_regs)
13453 int leaf_reg = LEAF_REG_REMAP (reg);
13454 if (leaf_reg != -1)
13455 reg = (unsigned) leaf_reg;
13458 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13459 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13461 /* Simple, contiguous registers. */
13462 if (regs == NULL_RTX)
13464 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13469 dw_loc_descr_ref t;
13471 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13472 VAR_INIT_STATUS_INITIALIZED);
13473 add_loc_descr (&loc_result, t);
13474 add_loc_descr_op_piece (&loc_result, size);
13480 /* Now onto stupid register sets in non contiguous locations. */
13482 gcc_assert (GET_CODE (regs) == PARALLEL);
13484 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13487 for (i = 0; i < XVECLEN (regs, 0); ++i)
13489 dw_loc_descr_ref t;
13491 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13492 VAR_INIT_STATUS_INITIALIZED);
13493 add_loc_descr (&loc_result, t);
13494 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13495 add_loc_descr_op_piece (&loc_result, size);
13498 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13499 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13503 /* Return a location descriptor that designates a constant. */
13505 static dw_loc_descr_ref
13506 int_loc_descriptor (HOST_WIDE_INT i)
13508 enum dwarf_location_atom op;
13510 /* Pick the smallest representation of a constant, rather than just
13511 defaulting to the LEB encoding. */
13515 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13516 else if (i <= 0xff)
13517 op = DW_OP_const1u;
13518 else if (i <= 0xffff)
13519 op = DW_OP_const2u;
13520 else if (HOST_BITS_PER_WIDE_INT == 32
13521 || i <= 0xffffffff)
13522 op = DW_OP_const4u;
13529 op = DW_OP_const1s;
13530 else if (i >= -0x8000)
13531 op = DW_OP_const2s;
13532 else if (HOST_BITS_PER_WIDE_INT == 32
13533 || i >= -0x80000000)
13534 op = DW_OP_const4s;
13539 return new_loc_descr (op, i, 0);
13542 /* Return loc description representing "address" of integer value.
13543 This can appear only as toplevel expression. */
13545 static dw_loc_descr_ref
13546 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13549 dw_loc_descr_ref loc_result = NULL;
13551 if (!(dwarf_version >= 4 || !dwarf_strict))
13558 else if (i <= 0xff)
13560 else if (i <= 0xffff)
13562 else if (HOST_BITS_PER_WIDE_INT == 32
13563 || i <= 0xffffffff)
13566 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13572 else if (i >= -0x8000)
13574 else if (HOST_BITS_PER_WIDE_INT == 32
13575 || i >= -0x80000000)
13578 litsize = 1 + size_of_sleb128 (i);
13580 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13581 is more compact. For DW_OP_stack_value we need:
13582 litsize + 1 (DW_OP_stack_value)
13583 and for DW_OP_implicit_value:
13584 1 (DW_OP_implicit_value) + 1 (length) + size. */
13585 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13587 loc_result = int_loc_descriptor (i);
13588 add_loc_descr (&loc_result,
13589 new_loc_descr (DW_OP_stack_value, 0, 0));
13593 loc_result = new_loc_descr (DW_OP_implicit_value,
13595 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13596 loc_result->dw_loc_oprnd2.v.val_int = i;
13600 /* Return a location descriptor that designates a base+offset location. */
13602 static dw_loc_descr_ref
13603 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13604 enum var_init_status initialized)
13606 unsigned int regno;
13607 dw_loc_descr_ref result;
13608 dw_fde_ref fde = current_fde ();
13610 /* We only use "frame base" when we're sure we're talking about the
13611 post-prologue local stack frame. We do this by *not* running
13612 register elimination until this point, and recognizing the special
13613 argument pointer and soft frame pointer rtx's. */
13614 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13616 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13620 if (GET_CODE (elim) == PLUS)
13622 offset += INTVAL (XEXP (elim, 1));
13623 elim = XEXP (elim, 0);
13625 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13626 && (elim == hard_frame_pointer_rtx
13627 || elim == stack_pointer_rtx))
13628 || elim == (frame_pointer_needed
13629 ? hard_frame_pointer_rtx
13630 : stack_pointer_rtx));
13632 /* If drap register is used to align stack, use frame
13633 pointer + offset to access stack variables. If stack
13634 is aligned without drap, use stack pointer + offset to
13635 access stack variables. */
13636 if (crtl->stack_realign_tried
13637 && reg == frame_pointer_rtx)
13640 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13641 ? HARD_FRAME_POINTER_REGNUM
13643 return new_reg_loc_descr (base_reg, offset);
13646 gcc_assert (frame_pointer_fb_offset_valid);
13647 offset += frame_pointer_fb_offset;
13648 return new_loc_descr (DW_OP_fbreg, offset, 0);
13653 && (fde->drap_reg == REGNO (reg)
13654 || fde->vdrap_reg == REGNO (reg)))
13656 /* Use cfa+offset to represent the location of arguments passed
13657 on the stack when drap is used to align stack.
13658 Only do this when not optimizing, for optimized code var-tracking
13659 is supposed to track where the arguments live and the register
13660 used as vdrap or drap in some spot might be used for something
13661 else in other part of the routine. */
13662 return new_loc_descr (DW_OP_fbreg, offset, 0);
13665 regno = dbx_reg_number (reg);
13667 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13670 result = new_loc_descr (DW_OP_bregx, regno, offset);
13672 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13673 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13678 /* Return true if this RTL expression describes a base+offset calculation. */
13681 is_based_loc (const_rtx rtl)
13683 return (GET_CODE (rtl) == PLUS
13684 && ((REG_P (XEXP (rtl, 0))
13685 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13686 && CONST_INT_P (XEXP (rtl, 1)))));
13689 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13692 static dw_loc_descr_ref
13693 tls_mem_loc_descriptor (rtx mem)
13696 dw_loc_descr_ref loc_result;
13698 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13701 base = get_base_address (MEM_EXPR (mem));
13703 || TREE_CODE (base) != VAR_DECL
13704 || !DECL_THREAD_LOCAL_P (base))
13707 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13708 if (loc_result == NULL)
13711 if (INTVAL (MEM_OFFSET (mem)))
13712 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13717 /* Output debug info about reason why we failed to expand expression as dwarf
13721 expansion_failed (tree expr, rtx rtl, char const *reason)
13723 if (dump_file && (dump_flags & TDF_DETAILS))
13725 fprintf (dump_file, "Failed to expand as dwarf: ");
13727 print_generic_expr (dump_file, expr, dump_flags);
13730 fprintf (dump_file, "\n");
13731 print_rtl (dump_file, rtl);
13733 fprintf (dump_file, "\nReason: %s\n", reason);
13737 /* Helper function for const_ok_for_output, called either directly
13738 or via for_each_rtx. */
13741 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13745 if (GET_CODE (rtl) == UNSPEC)
13747 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13748 we can't express it in the debug info. */
13749 #ifdef ENABLE_CHECKING
13750 /* Don't complain about TLS UNSPECs, those are just too hard to
13752 if (XVECLEN (rtl, 0) != 1
13753 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13754 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13755 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13756 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13757 inform (current_function_decl
13758 ? DECL_SOURCE_LOCATION (current_function_decl)
13759 : UNKNOWN_LOCATION,
13760 #if NUM_UNSPEC_VALUES > 0
13761 "non-delegitimized UNSPEC %s (%d) found in variable location",
13762 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
13763 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
13766 "non-delegitimized UNSPEC %d found in variable location",
13770 expansion_failed (NULL_TREE, rtl,
13771 "UNSPEC hasn't been delegitimized.\n");
13775 if (GET_CODE (rtl) != SYMBOL_REF)
13778 if (CONSTANT_POOL_ADDRESS_P (rtl))
13781 get_pool_constant_mark (rtl, &marked);
13782 /* If all references to this pool constant were optimized away,
13783 it was not output and thus we can't represent it. */
13786 expansion_failed (NULL_TREE, rtl,
13787 "Constant was removed from constant pool.\n");
13792 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13795 /* Avoid references to external symbols in debug info, on several targets
13796 the linker might even refuse to link when linking a shared library,
13797 and in many other cases the relocations for .debug_info/.debug_loc are
13798 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13799 to be defined within the same shared library or executable are fine. */
13800 if (SYMBOL_REF_EXTERNAL_P (rtl))
13802 tree decl = SYMBOL_REF_DECL (rtl);
13804 if (decl == NULL || !targetm.binds_local_p (decl))
13806 expansion_failed (NULL_TREE, rtl,
13807 "Symbol not defined in current TU.\n");
13815 /* Return true if constant RTL can be emitted in DW_OP_addr or
13816 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13817 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13820 const_ok_for_output (rtx rtl)
13822 if (GET_CODE (rtl) == SYMBOL_REF)
13823 return const_ok_for_output_1 (&rtl, NULL) == 0;
13825 if (GET_CODE (rtl) == CONST)
13826 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13831 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13832 if possible, NULL otherwise. */
13835 base_type_for_mode (enum machine_mode mode, bool unsignedp)
13837 dw_die_ref type_die;
13838 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
13842 switch (TREE_CODE (type))
13850 type_die = lookup_type_die (type);
13852 type_die = modified_type_die (type, false, false, comp_unit_die ());
13853 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
13858 /* For OP descriptor assumed to be in unsigned MODE, convert it to a signed
13859 type matching MODE, or, if MODE is narrower than DWARF2_ADDR_SIZE, signed
13860 type matching DWARF2_ADDR_SIZE. Return NULL if the conversion is not
13863 static dw_loc_descr_ref
13864 convert_descriptor_to_signed (enum machine_mode mode, dw_loc_descr_ref op)
13866 enum machine_mode outer_mode = mode;
13867 dw_die_ref type_die;
13868 dw_loc_descr_ref cvt;
13870 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
13872 outer_mode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
13874 if (outer_mode == BLKmode
13875 || GET_MODE_SIZE (outer_mode) != DWARF2_ADDR_SIZE)
13878 type_die = base_type_for_mode (outer_mode, 0);
13879 if (type_die == NULL)
13881 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13882 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13883 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13884 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13885 add_loc_descr (&op, cvt);
13889 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13891 static dw_loc_descr_ref
13892 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
13893 dw_loc_descr_ref op1)
13895 dw_loc_descr_ref ret = op0;
13896 add_loc_descr (&ret, op1);
13897 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
13898 if (STORE_FLAG_VALUE != 1)
13900 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
13901 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
13906 /* Return location descriptor for signed comparison OP RTL. */
13908 static dw_loc_descr_ref
13909 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
13910 enum machine_mode mem_mode)
13912 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13913 dw_loc_descr_ref op0, op1;
13916 if (op_mode == VOIDmode)
13917 op_mode = GET_MODE (XEXP (rtl, 1));
13918 if (op_mode == VOIDmode)
13922 && (GET_MODE_CLASS (op_mode) != MODE_INT
13923 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
13926 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
13927 VAR_INIT_STATUS_INITIALIZED);
13928 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
13929 VAR_INIT_STATUS_INITIALIZED);
13931 if (op0 == NULL || op1 == NULL)
13934 if (GET_MODE_CLASS (op_mode) != MODE_INT
13935 || GET_MODE_SIZE (op_mode) >= DWARF2_ADDR_SIZE)
13936 return compare_loc_descriptor (op, op0, op1);
13938 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
13939 /* For eq/ne, if the operands are known to be zero-extended,
13940 there is no need to do the fancy shifting up. */
13941 if (op == DW_OP_eq || op == DW_OP_ne)
13943 dw_loc_descr_ref last0, last1;
13944 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
13946 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
13948 /* deref_size zero extends, and for constants we can check
13949 whether they are zero extended or not. */
13950 if (((last0->dw_loc_opc == DW_OP_deref_size
13951 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
13952 || (CONST_INT_P (XEXP (rtl, 0))
13953 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
13954 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
13955 && ((last1->dw_loc_opc == DW_OP_deref_size
13956 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
13957 || (CONST_INT_P (XEXP (rtl, 1))
13958 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
13959 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
13960 return compare_loc_descriptor (op, op0, op1);
13962 add_loc_descr (&op0, int_loc_descriptor (shift));
13963 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
13964 if (CONST_INT_P (XEXP (rtl, 1)))
13965 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
13968 add_loc_descr (&op1, int_loc_descriptor (shift));
13969 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
13971 return compare_loc_descriptor (op, op0, op1);
13974 /* Return location descriptor for unsigned comparison OP RTL. */
13976 static dw_loc_descr_ref
13977 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
13978 enum machine_mode mem_mode)
13980 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13981 dw_loc_descr_ref op0, op1;
13983 if (op_mode == VOIDmode)
13984 op_mode = GET_MODE (XEXP (rtl, 1));
13985 if (op_mode == VOIDmode)
13987 if (GET_MODE_CLASS (op_mode) != MODE_INT)
13990 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
13993 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
13996 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
13997 VAR_INIT_STATUS_INITIALIZED);
13998 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
13999 VAR_INIT_STATUS_INITIALIZED);
14001 if (op0 == NULL || op1 == NULL)
14004 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14006 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14007 dw_loc_descr_ref last0, last1;
14008 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
14010 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
14012 if (CONST_INT_P (XEXP (rtl, 0)))
14013 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14014 /* deref_size zero extends, so no need to mask it again. */
14015 else if (last0->dw_loc_opc != DW_OP_deref_size
14016 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
14018 add_loc_descr (&op0, int_loc_descriptor (mask));
14019 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14021 if (CONST_INT_P (XEXP (rtl, 1)))
14022 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14023 /* deref_size zero extends, so no need to mask it again. */
14024 else if (last1->dw_loc_opc != DW_OP_deref_size
14025 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
14027 add_loc_descr (&op1, int_loc_descriptor (mask));
14028 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14031 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
14033 HOST_WIDE_INT bias = 1;
14034 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14035 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14036 if (CONST_INT_P (XEXP (rtl, 1)))
14037 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14038 + INTVAL (XEXP (rtl, 1)));
14040 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14045 dw_die_ref type_die = base_type_for_mode (op_mode, 1);
14046 dw_loc_descr_ref cvt;
14048 if (type_die == NULL)
14050 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14051 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14052 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14053 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14054 add_loc_descr (&op0, cvt);
14055 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14056 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14057 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14058 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14059 add_loc_descr (&op1, cvt);
14061 return compare_loc_descriptor (op, op0, op1);
14064 /* Return location descriptor for {U,S}{MIN,MAX}. */
14066 static dw_loc_descr_ref
14067 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
14068 enum machine_mode mem_mode)
14070 enum dwarf_location_atom op;
14071 dw_loc_descr_ref op0, op1, ret;
14072 dw_loc_descr_ref bra_node, drop_node;
14075 && (GET_MODE_CLASS (mode) != MODE_INT
14076 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
14079 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14080 VAR_INIT_STATUS_INITIALIZED);
14081 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14082 VAR_INIT_STATUS_INITIALIZED);
14084 if (op0 == NULL || op1 == NULL)
14087 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14088 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14089 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14090 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14092 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14094 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
14095 add_loc_descr (&op0, int_loc_descriptor (mask));
14096 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14097 add_loc_descr (&op1, int_loc_descriptor (mask));
14098 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14100 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
14102 HOST_WIDE_INT bias = 1;
14103 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14104 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14105 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14109 dw_die_ref type_die = base_type_for_mode (mode, 1);
14110 dw_loc_descr_ref cvt;
14111 if (type_die == NULL)
14113 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14114 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14115 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14116 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14117 add_loc_descr (&op0, cvt);
14118 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14119 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14120 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14121 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14122 add_loc_descr (&op1, cvt);
14125 else if (GET_MODE_CLASS (mode) == MODE_INT
14126 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14128 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
14129 add_loc_descr (&op0, int_loc_descriptor (shift));
14130 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14131 add_loc_descr (&op1, int_loc_descriptor (shift));
14132 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14135 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14140 add_loc_descr (&ret, op1);
14141 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
14142 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14143 add_loc_descr (&ret, bra_node);
14144 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14145 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14146 add_loc_descr (&ret, drop_node);
14147 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14148 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14152 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14153 const0 is DW_OP_lit0 or corresponding typed constant,
14154 const1 is DW_OP_lit1 or corresponding typed constant
14155 and constMSB is constant with just the MSB bit set
14157 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14158 L1: const0 DW_OP_swap
14159 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14160 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14165 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14166 L1: const0 DW_OP_swap
14167 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14168 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14173 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14174 L1: const1 DW_OP_swap
14175 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14176 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14180 static dw_loc_descr_ref
14181 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
14182 enum machine_mode mem_mode)
14184 dw_loc_descr_ref op0, ret, tmp;
14185 HOST_WIDE_INT valv;
14186 dw_loc_descr_ref l1jump, l1label;
14187 dw_loc_descr_ref l2jump, l2label;
14188 dw_loc_descr_ref l3jump, l3label;
14189 dw_loc_descr_ref l4jump, l4label;
14192 if (GET_MODE_CLASS (mode) != MODE_INT
14193 || GET_MODE (XEXP (rtl, 0)) != mode
14194 || (GET_CODE (rtl) == CLZ
14195 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
14198 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14199 VAR_INIT_STATUS_INITIALIZED);
14203 if (GET_CODE (rtl) == CLZ)
14205 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
14206 valv = GET_MODE_BITSIZE (mode);
14208 else if (GET_CODE (rtl) == FFS)
14210 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
14211 valv = GET_MODE_BITSIZE (mode);
14212 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
14213 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
14214 add_loc_descr (&ret, l1jump);
14215 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
14216 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
14217 VAR_INIT_STATUS_INITIALIZED);
14220 add_loc_descr (&ret, tmp);
14221 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
14222 add_loc_descr (&ret, l4jump);
14223 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
14224 ? const1_rtx : const0_rtx,
14226 VAR_INIT_STATUS_INITIALIZED);
14227 if (l1label == NULL)
14229 add_loc_descr (&ret, l1label);
14230 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14231 l2label = new_loc_descr (DW_OP_dup, 0, 0);
14232 add_loc_descr (&ret, l2label);
14233 if (GET_CODE (rtl) != CLZ)
14235 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
14236 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
14237 << (GET_MODE_BITSIZE (mode) - 1));
14239 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
14240 << (GET_MODE_BITSIZE (mode)
14241 - HOST_BITS_PER_WIDE_INT - 1), mode);
14242 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
14243 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
14244 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
14245 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
14247 tmp = mem_loc_descriptor (msb, mode, mem_mode,
14248 VAR_INIT_STATUS_INITIALIZED);
14251 add_loc_descr (&ret, tmp);
14252 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
14253 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
14254 add_loc_descr (&ret, l3jump);
14255 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
14256 VAR_INIT_STATUS_INITIALIZED);
14259 add_loc_descr (&ret, tmp);
14260 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
14261 ? DW_OP_shl : DW_OP_shr, 0, 0));
14262 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14263 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
14264 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14265 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
14266 add_loc_descr (&ret, l2jump);
14267 l3label = new_loc_descr (DW_OP_drop, 0, 0);
14268 add_loc_descr (&ret, l3label);
14269 l4label = new_loc_descr (DW_OP_nop, 0, 0);
14270 add_loc_descr (&ret, l4label);
14271 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14272 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
14273 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14274 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
14275 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14276 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
14277 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14278 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
14282 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14283 const1 is DW_OP_lit1 or corresponding typed constant):
14285 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14286 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14290 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14291 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14294 static dw_loc_descr_ref
14295 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
14296 enum machine_mode mem_mode)
14298 dw_loc_descr_ref op0, ret, tmp;
14299 dw_loc_descr_ref l1jump, l1label;
14300 dw_loc_descr_ref l2jump, l2label;
14302 if (GET_MODE_CLASS (mode) != MODE_INT
14303 || GET_MODE (XEXP (rtl, 0)) != mode)
14306 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14307 VAR_INIT_STATUS_INITIALIZED);
14311 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
14312 VAR_INIT_STATUS_INITIALIZED);
14315 add_loc_descr (&ret, tmp);
14316 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14317 l1label = new_loc_descr (DW_OP_dup, 0, 0);
14318 add_loc_descr (&ret, l1label);
14319 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
14320 add_loc_descr (&ret, l2jump);
14321 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
14322 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
14323 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
14324 VAR_INIT_STATUS_INITIALIZED);
14327 add_loc_descr (&ret, tmp);
14328 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
14329 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
14330 ? DW_OP_plus : DW_OP_xor, 0, 0));
14331 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14332 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
14333 VAR_INIT_STATUS_INITIALIZED);
14334 add_loc_descr (&ret, tmp);
14335 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14336 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
14337 add_loc_descr (&ret, l1jump);
14338 l2label = new_loc_descr (DW_OP_drop, 0, 0);
14339 add_loc_descr (&ret, l2label);
14340 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14341 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
14342 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14343 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
14347 /* BSWAP (constS is initial shift count, either 56 or 24):
14349 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14350 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14351 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14352 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14353 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14355 static dw_loc_descr_ref
14356 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
14357 enum machine_mode mem_mode)
14359 dw_loc_descr_ref op0, ret, tmp;
14360 dw_loc_descr_ref l1jump, l1label;
14361 dw_loc_descr_ref l2jump, l2label;
14363 if (GET_MODE_CLASS (mode) != MODE_INT
14364 || BITS_PER_UNIT != 8
14365 || (GET_MODE_BITSIZE (mode) != 32
14366 && GET_MODE_BITSIZE (mode) != 64))
14369 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14370 VAR_INIT_STATUS_INITIALIZED);
14375 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
14377 VAR_INIT_STATUS_INITIALIZED);
14380 add_loc_descr (&ret, tmp);
14381 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
14382 VAR_INIT_STATUS_INITIALIZED);
14385 add_loc_descr (&ret, tmp);
14386 l1label = new_loc_descr (DW_OP_pick, 2, 0);
14387 add_loc_descr (&ret, l1label);
14388 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
14390 VAR_INIT_STATUS_INITIALIZED);
14391 add_loc_descr (&ret, tmp);
14392 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
14393 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
14394 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14395 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
14396 VAR_INIT_STATUS_INITIALIZED);
14399 add_loc_descr (&ret, tmp);
14400 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
14401 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
14402 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
14403 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
14404 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14405 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
14406 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
14407 VAR_INIT_STATUS_INITIALIZED);
14408 add_loc_descr (&ret, tmp);
14409 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
14410 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
14411 add_loc_descr (&ret, l2jump);
14412 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
14413 VAR_INIT_STATUS_INITIALIZED);
14414 add_loc_descr (&ret, tmp);
14415 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
14416 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14417 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
14418 add_loc_descr (&ret, l1jump);
14419 l2label = new_loc_descr (DW_OP_drop, 0, 0);
14420 add_loc_descr (&ret, l2label);
14421 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14422 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
14423 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14424 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
14425 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
14426 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
14430 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14431 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14432 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14433 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14435 ROTATERT is similar:
14436 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14437 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14438 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14440 static dw_loc_descr_ref
14441 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
14442 enum machine_mode mem_mode)
14444 rtx rtlop1 = XEXP (rtl, 1);
14445 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
14448 if (GET_MODE_CLASS (mode) != MODE_INT)
14451 if (GET_MODE (rtlop1) != VOIDmode
14452 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
14453 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
14454 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14455 VAR_INIT_STATUS_INITIALIZED);
14456 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
14457 VAR_INIT_STATUS_INITIALIZED);
14458 if (op0 == NULL || op1 == NULL)
14460 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
14461 for (i = 0; i < 2; i++)
14463 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
14464 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
14466 VAR_INIT_STATUS_INITIALIZED);
14467 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
14468 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
14470 : HOST_BITS_PER_WIDE_INT == 64
14471 ? DW_OP_const8u : DW_OP_constu,
14472 GET_MODE_MASK (mode), 0);
14475 if (mask[i] == NULL)
14477 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
14480 add_loc_descr (&ret, op1);
14481 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
14482 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
14483 if (GET_CODE (rtl) == ROTATERT)
14485 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14486 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
14487 GET_MODE_BITSIZE (mode), 0));
14489 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
14490 if (mask[0] != NULL)
14491 add_loc_descr (&ret, mask[0]);
14492 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
14493 if (mask[1] != NULL)
14495 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14496 add_loc_descr (&ret, mask[1]);
14497 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
14499 if (GET_CODE (rtl) == ROTATE)
14501 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14502 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
14503 GET_MODE_BITSIZE (mode), 0));
14505 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14506 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
14510 /* The following routine converts the RTL for a variable or parameter
14511 (resident in memory) into an equivalent Dwarf representation of a
14512 mechanism for getting the address of that same variable onto the top of a
14513 hypothetical "address evaluation" stack.
14515 When creating memory location descriptors, we are effectively transforming
14516 the RTL for a memory-resident object into its Dwarf postfix expression
14517 equivalent. This routine recursively descends an RTL tree, turning
14518 it into Dwarf postfix code as it goes.
14520 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14522 MEM_MODE is the mode of the memory reference, needed to handle some
14523 autoincrement addressing modes.
14525 Return 0 if we can't represent the location. */
14527 static dw_loc_descr_ref
14528 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
14529 enum machine_mode mem_mode,
14530 enum var_init_status initialized)
14532 dw_loc_descr_ref mem_loc_result = NULL;
14533 enum dwarf_location_atom op;
14534 dw_loc_descr_ref op0, op1;
14536 if (mode == VOIDmode)
14537 mode = GET_MODE (rtl);
14539 /* Note that for a dynamically sized array, the location we will generate a
14540 description of here will be the lowest numbered location which is
14541 actually within the array. That's *not* necessarily the same as the
14542 zeroth element of the array. */
14544 rtl = targetm.delegitimize_address (rtl);
14546 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
14549 switch (GET_CODE (rtl))
14554 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
14557 /* The case of a subreg may arise when we have a local (register)
14558 variable or a formal (register) parameter which doesn't quite fill
14559 up an entire register. For now, just assume that it is
14560 legitimate to make the Dwarf info refer to the whole register which
14561 contains the given subreg. */
14562 if (!subreg_lowpart_p (rtl))
14564 if (GET_MODE_CLASS (mode) == MODE_INT
14565 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
14566 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14567 #ifdef POINTERS_EXTEND_UNSIGNED
14568 || (mode == Pmode && mem_mode != VOIDmode)
14571 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
14573 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
14574 GET_MODE (SUBREG_REG (rtl)),
14575 mem_mode, initialized);
14580 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
14582 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
14583 && (GET_MODE_CLASS (mode) != MODE_INT
14584 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
14588 dw_die_ref type_die;
14589 dw_loc_descr_ref cvt;
14591 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
14592 GET_MODE (SUBREG_REG (rtl)),
14593 mem_mode, initialized);
14594 if (mem_loc_result == NULL)
14596 type_die = base_type_for_mode (mode, 0);
14597 if (type_die == NULL)
14599 mem_loc_result = NULL;
14602 if (GET_MODE_SIZE (mode)
14603 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
14604 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14606 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
14607 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14608 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
14609 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14610 add_loc_descr (&mem_loc_result, cvt);
14615 if (GET_MODE_CLASS (mode) != MODE_INT
14616 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14617 #ifdef POINTERS_EXTEND_UNSIGNED
14618 && (mode != Pmode || mem_mode == VOIDmode)
14622 dw_die_ref type_die;
14626 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
14628 type_die = base_type_for_mode (mode, 0);
14629 if (type_die == NULL)
14631 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
14632 dbx_reg_number (rtl), 0);
14633 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
14634 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
14635 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
14638 /* Whenever a register number forms a part of the description of the
14639 method for calculating the (dynamic) address of a memory resident
14640 object, DWARF rules require the register number be referred to as
14641 a "base register". This distinction is not based in any way upon
14642 what category of register the hardware believes the given register
14643 belongs to. This is strictly DWARF terminology we're dealing with
14644 here. Note that in cases where the location of a memory-resident
14645 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14646 OP_CONST (0)) the actual DWARF location descriptor that we generate
14647 may just be OP_BASEREG (basereg). This may look deceptively like
14648 the object in question was allocated to a register (rather than in
14649 memory) so DWARF consumers need to be aware of the subtle
14650 distinction between OP_REG and OP_BASEREG. */
14651 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
14652 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
14653 else if (stack_realign_drap
14655 && crtl->args.internal_arg_pointer == rtl
14656 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
14658 /* If RTL is internal_arg_pointer, which has been optimized
14659 out, use DRAP instead. */
14660 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
14661 VAR_INIT_STATUS_INITIALIZED);
14667 gcc_assert (GET_MODE_CLASS (mode) == MODE_INT);
14668 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
14669 mem_mode, VAR_INIT_STATUS_INITIALIZED);
14672 else if (GET_CODE (rtl) == ZERO_EXTEND
14673 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14674 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14675 < HOST_BITS_PER_WIDE_INT
14676 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14677 to expand zero extend as two shifts instead of
14679 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
14681 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
14682 mem_loc_result = op0;
14683 add_loc_descr (&mem_loc_result,
14684 int_loc_descriptor (GET_MODE_MASK (imode)));
14685 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
14687 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
14689 int shift = DWARF2_ADDR_SIZE
14690 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14691 shift *= BITS_PER_UNIT;
14692 if (GET_CODE (rtl) == SIGN_EXTEND)
14696 mem_loc_result = op0;
14697 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
14698 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14699 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
14700 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14702 else if (!dwarf_strict)
14704 dw_die_ref type_die1, type_die2;
14705 dw_loc_descr_ref cvt;
14707 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
14708 GET_CODE (rtl) == ZERO_EXTEND);
14709 if (type_die1 == NULL)
14711 type_die2 = base_type_for_mode (mode, 0);
14712 if (type_die2 == NULL)
14714 mem_loc_result = op0;
14715 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14716 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14717 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
14718 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14719 add_loc_descr (&mem_loc_result, cvt);
14720 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
14721 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14722 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
14723 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
14724 add_loc_descr (&mem_loc_result, cvt);
14729 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
14730 get_address_mode (rtl), mode,
14731 VAR_INIT_STATUS_INITIALIZED);
14732 if (mem_loc_result == NULL)
14733 mem_loc_result = tls_mem_loc_descriptor (rtl);
14734 if (mem_loc_result != 0)
14736 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14737 || GET_MODE_CLASS (mode) != MODE_INT)
14739 dw_die_ref type_die;
14740 dw_loc_descr_ref deref;
14744 type_die = base_type_for_mode (mode, 0);
14745 if (type_die == NULL)
14747 deref = new_loc_descr (DW_OP_GNU_deref_type,
14748 GET_MODE_SIZE (mode), 0);
14749 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
14750 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
14751 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
14752 add_loc_descr (&mem_loc_result, deref);
14754 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
14755 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
14757 add_loc_descr (&mem_loc_result,
14758 new_loc_descr (DW_OP_deref_size,
14759 GET_MODE_SIZE (mode), 0));
14763 rtx new_rtl = avoid_constant_pool_reference (rtl);
14764 if (new_rtl != rtl)
14765 return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
14770 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
14773 /* Some ports can transform a symbol ref into a label ref, because
14774 the symbol ref is too far away and has to be dumped into a constant
14778 if (GET_MODE_CLASS (mode) != MODE_INT
14779 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
14780 #ifdef POINTERS_EXTEND_UNSIGNED
14781 && (mode != Pmode || mem_mode == VOIDmode)
14785 if (GET_CODE (rtl) == SYMBOL_REF
14786 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
14788 dw_loc_descr_ref temp;
14790 /* If this is not defined, we have no way to emit the data. */
14791 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
14794 /* We used to emit DW_OP_addr here, but that's wrong, since
14795 DW_OP_addr should be relocated by the debug info consumer,
14796 while DW_OP_GNU_push_tls_address operand should not. */
14797 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
14798 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
14799 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
14800 temp->dw_loc_oprnd1.v.val_addr = rtl;
14801 temp->dtprel = true;
14803 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
14804 add_loc_descr (&mem_loc_result, temp);
14809 if (!const_ok_for_output (rtl))
14813 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14814 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14815 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14816 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14822 case DEBUG_IMPLICIT_PTR:
14823 expansion_failed (NULL_TREE, rtl,
14824 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14830 if (REG_P (ENTRY_VALUE_EXP (rtl)))
14832 if (GET_MODE_CLASS (mode) != MODE_INT
14833 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
14834 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
14835 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14838 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
14839 VAR_INIT_STATUS_INITIALIZED);
14841 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
14842 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
14844 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
14845 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14846 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
14850 gcc_unreachable ();
14853 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
14854 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
14855 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
14856 return mem_loc_result;
14859 /* Extract the PLUS expression nested inside and fall into
14860 PLUS code below. */
14861 rtl = XEXP (rtl, 1);
14866 /* Turn these into a PLUS expression and fall into the PLUS code
14868 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
14869 GEN_INT (GET_CODE (rtl) == PRE_INC
14870 ? GET_MODE_UNIT_SIZE (mem_mode)
14871 : -GET_MODE_UNIT_SIZE (mem_mode)));
14873 /* ... fall through ... */
14877 if (is_based_loc (rtl)
14878 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
14879 && GET_MODE_CLASS (mode) == MODE_INT)
14880 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
14881 INTVAL (XEXP (rtl, 1)),
14882 VAR_INIT_STATUS_INITIALIZED);
14885 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14886 VAR_INIT_STATUS_INITIALIZED);
14887 if (mem_loc_result == 0)
14890 if (CONST_INT_P (XEXP (rtl, 1))
14891 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
14892 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
14895 dw_loc_descr_ref mem_loc_result2
14896 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14897 VAR_INIT_STATUS_INITIALIZED);
14898 if (mem_loc_result2 == 0)
14900 add_loc_descr (&mem_loc_result, mem_loc_result2);
14901 add_loc_descr (&mem_loc_result,
14902 new_loc_descr (DW_OP_plus, 0, 0));
14907 /* If a pseudo-reg is optimized away, it is possible for it to
14908 be replaced with a MEM containing a multiply or shift. */
14938 if (GET_MODE_CLASS (mode) != MODE_INT)
14940 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14941 VAR_INIT_STATUS_INITIALIZED);
14943 rtx rtlop1 = XEXP (rtl, 1);
14944 if (GET_MODE (rtlop1) != VOIDmode
14945 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
14946 < GET_MODE_BITSIZE (mode))
14947 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
14948 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
14949 VAR_INIT_STATUS_INITIALIZED);
14952 if (op0 == 0 || op1 == 0)
14955 mem_loc_result = op0;
14956 add_loc_descr (&mem_loc_result, op1);
14957 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14973 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14974 VAR_INIT_STATUS_INITIALIZED);
14975 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
14976 VAR_INIT_STATUS_INITIALIZED);
14978 if (op0 == 0 || op1 == 0)
14981 mem_loc_result = op0;
14982 add_loc_descr (&mem_loc_result, op1);
14983 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14987 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
14989 /* If MODE is wider than DWARF2_ADDR_SIZE, mem_loc_descriptor
14990 should return signed typed values and therefore DW_OP_mod
14991 won't be unsigned as it defaults for untyped stack values,
14997 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
14998 VAR_INIT_STATUS_INITIALIZED);
14999 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15000 VAR_INIT_STATUS_INITIALIZED);
15002 if (op0 == 0 || op1 == 0)
15005 mem_loc_result = op0;
15006 add_loc_descr (&mem_loc_result, op1);
15007 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
15008 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
15009 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
15010 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
15011 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
15015 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
15017 dw_die_ref type_die;
15018 dw_loc_descr_ref cvt;
15020 type_die = base_type_for_mode (mode, 1);
15021 if (type_die == NULL)
15023 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15024 VAR_INIT_STATUS_INITIALIZED);
15025 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15026 VAR_INIT_STATUS_INITIALIZED);
15027 if (op0 == 0 || op1 == 0)
15029 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
15030 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15031 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15032 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15033 add_loc_descr (&op0, cvt);
15034 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
15035 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15036 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15037 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15038 add_loc_descr (&op1, cvt);
15039 mem_loc_result = op0;
15040 add_loc_descr (&mem_loc_result, op1);
15041 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
15042 mem_loc_result = convert_descriptor_to_signed (mode, mem_loc_result);
15059 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15060 VAR_INIT_STATUS_INITIALIZED);
15065 mem_loc_result = op0;
15066 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15070 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
15071 #ifdef POINTERS_EXTEND_UNSIGNED
15073 && mem_mode != VOIDmode
15074 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
15078 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
15082 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
15083 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
15085 dw_die_ref type_die = base_type_for_mode (mode, 0);
15086 if (type_die == NULL)
15088 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
15090 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15091 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15092 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
15093 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
15094 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
15097 mem_loc_result->dw_loc_oprnd2.val_class
15098 = dw_val_class_const_double;
15099 mem_loc_result->dw_loc_oprnd2.v.val_double
15100 = shwi_to_double_int (INTVAL (rtl));
15108 dw_die_ref type_die;
15110 /* Note that a CONST_DOUBLE rtx could represent either an integer
15111 or a floating-point constant. A CONST_DOUBLE is used whenever
15112 the constant requires more than one word in order to be
15113 adequately represented. We output CONST_DOUBLEs as blocks. */
15114 if (mode == VOIDmode
15115 || (GET_MODE (rtl) == VOIDmode
15116 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
15118 type_die = base_type_for_mode (mode, 0);
15119 if (type_die == NULL)
15121 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
15122 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15123 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15124 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
15125 if (SCALAR_FLOAT_MODE_P (mode))
15127 unsigned int length = GET_MODE_SIZE (mode);
15128 unsigned char *array
15129 = (unsigned char*) ggc_alloc_atomic (length);
15131 insert_float (rtl, array);
15132 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15133 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
15134 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
15135 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15139 mem_loc_result->dw_loc_oprnd2.val_class
15140 = dw_val_class_const_double;
15141 mem_loc_result->dw_loc_oprnd2.v.val_double
15142 = rtx_to_double_int (rtl);
15148 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
15152 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
15156 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
15160 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
15164 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
15168 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
15172 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
15176 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
15180 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
15184 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
15189 if (GET_MODE_CLASS (mode) != MODE_INT)
15194 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
15199 if (CONST_INT_P (XEXP (rtl, 1))
15200 && CONST_INT_P (XEXP (rtl, 2))
15201 && ((unsigned) INTVAL (XEXP (rtl, 1))
15202 + (unsigned) INTVAL (XEXP (rtl, 2))
15203 <= GET_MODE_BITSIZE (mode))
15204 && GET_MODE_CLASS (mode) == MODE_INT
15205 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
15206 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
15209 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
15210 mem_mode, VAR_INIT_STATUS_INITIALIZED);
15213 if (GET_CODE (rtl) == SIGN_EXTRACT)
15217 mem_loc_result = op0;
15218 size = INTVAL (XEXP (rtl, 1));
15219 shift = INTVAL (XEXP (rtl, 2));
15220 if (BITS_BIG_ENDIAN)
15221 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
15223 if (shift + size != (int) DWARF2_ADDR_SIZE)
15225 add_loc_descr (&mem_loc_result,
15226 int_loc_descriptor (DWARF2_ADDR_SIZE
15228 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
15230 if (size != (int) DWARF2_ADDR_SIZE)
15232 add_loc_descr (&mem_loc_result,
15233 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
15234 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
15241 dw_loc_descr_ref op2, bra_node, drop_node;
15242 op0 = mem_loc_descriptor (XEXP (rtl, 0),
15243 GET_MODE (XEXP (rtl, 0)) == VOIDmode
15244 ? word_mode : GET_MODE (XEXP (rtl, 0)),
15245 mem_mode, VAR_INIT_STATUS_INITIALIZED);
15246 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15247 VAR_INIT_STATUS_INITIALIZED);
15248 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
15249 VAR_INIT_STATUS_INITIALIZED);
15250 if (op0 == NULL || op1 == NULL || op2 == NULL)
15253 mem_loc_result = op1;
15254 add_loc_descr (&mem_loc_result, op2);
15255 add_loc_descr (&mem_loc_result, op0);
15256 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15257 add_loc_descr (&mem_loc_result, bra_node);
15258 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
15259 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
15260 add_loc_descr (&mem_loc_result, drop_node);
15261 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15262 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
15267 case FLOAT_TRUNCATE:
15269 case UNSIGNED_FLOAT:
15274 dw_die_ref type_die;
15275 dw_loc_descr_ref cvt;
15277 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
15278 mem_mode, VAR_INIT_STATUS_INITIALIZED);
15281 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
15282 && (GET_CODE (rtl) == UNSIGNED_FLOAT
15283 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
15284 <= DWARF2_ADDR_SIZE))
15286 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
15287 GET_CODE (rtl) == UNSIGNED_FLOAT);
15288 if (type_die == NULL)
15290 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
15291 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15292 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15293 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15294 add_loc_descr (&op0, cvt);
15296 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
15297 if (type_die == NULL)
15299 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
15300 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15301 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15302 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15303 add_loc_descr (&op0, cvt);
15304 if (GET_MODE_CLASS (mode) == MODE_INT
15305 && (GET_CODE (rtl) == UNSIGNED_FIX
15306 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
15308 op0 = convert_descriptor_to_signed (mode, op0);
15312 mem_loc_result = op0;
15319 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
15324 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
15328 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
15333 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
15338 /* In theory, we could implement the above. */
15339 /* DWARF cannot represent the unsigned compare operations
15364 case FRACT_CONVERT:
15365 case UNSIGNED_FRACT_CONVERT:
15367 case UNSIGNED_SAT_FRACT:
15373 case VEC_DUPLICATE:
15377 case STRICT_LOW_PART:
15380 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15381 can't express it in the debug info. This can happen e.g. with some
15386 resolve_one_addr (&rtl, NULL);
15390 #ifdef ENABLE_CHECKING
15391 print_rtl (stderr, rtl);
15392 gcc_unreachable ();
15398 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
15399 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15401 return mem_loc_result;
15404 /* Return a descriptor that describes the concatenation of two locations.
15405 This is typically a complex variable. */
15407 static dw_loc_descr_ref
15408 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
15410 dw_loc_descr_ref cc_loc_result = NULL;
15411 dw_loc_descr_ref x0_ref
15412 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
15413 dw_loc_descr_ref x1_ref
15414 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
15416 if (x0_ref == 0 || x1_ref == 0)
15419 cc_loc_result = x0_ref;
15420 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
15422 add_loc_descr (&cc_loc_result, x1_ref);
15423 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
15425 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
15426 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15428 return cc_loc_result;
15431 /* Return a descriptor that describes the concatenation of N
15434 static dw_loc_descr_ref
15435 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
15438 dw_loc_descr_ref cc_loc_result = NULL;
15439 unsigned int n = XVECLEN (concatn, 0);
15441 for (i = 0; i < n; ++i)
15443 dw_loc_descr_ref ref;
15444 rtx x = XVECEXP (concatn, 0, i);
15446 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
15450 add_loc_descr (&cc_loc_result, ref);
15451 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
15454 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
15455 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15457 return cc_loc_result;
15460 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
15461 for DEBUG_IMPLICIT_PTR RTL. */
15463 static dw_loc_descr_ref
15464 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
15466 dw_loc_descr_ref ret;
15471 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
15472 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
15473 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
15474 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
15475 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
15476 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
15479 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15480 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
15481 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
15485 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
15486 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
15491 /* Output a proper Dwarf location descriptor for a variable or parameter
15492 which is either allocated in a register or in a memory location. For a
15493 register, we just generate an OP_REG and the register number. For a
15494 memory location we provide a Dwarf postfix expression describing how to
15495 generate the (dynamic) address of the object onto the address stack.
15497 MODE is mode of the decl if this loc_descriptor is going to be used in
15498 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15499 allowed, VOIDmode otherwise.
15501 If we don't know how to describe it, return 0. */
15503 static dw_loc_descr_ref
15504 loc_descriptor (rtx rtl, enum machine_mode mode,
15505 enum var_init_status initialized)
15507 dw_loc_descr_ref loc_result = NULL;
15509 switch (GET_CODE (rtl))
15512 /* The case of a subreg may arise when we have a local (register)
15513 variable or a formal (register) parameter which doesn't quite fill
15514 up an entire register. For now, just assume that it is
15515 legitimate to make the Dwarf info refer to the whole register which
15516 contains the given subreg. */
15517 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
15518 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
15524 loc_result = reg_loc_descriptor (rtl, initialized);
15528 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
15529 GET_MODE (rtl), initialized);
15530 if (loc_result == NULL)
15531 loc_result = tls_mem_loc_descriptor (rtl);
15532 if (loc_result == NULL)
15534 rtx new_rtl = avoid_constant_pool_reference (rtl);
15535 if (new_rtl != rtl)
15536 loc_result = loc_descriptor (new_rtl, mode, initialized);
15541 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
15546 loc_result = concatn_loc_descriptor (rtl, initialized);
15551 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
15553 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
15554 if (GET_CODE (loc) == EXPR_LIST)
15555 loc = XEXP (loc, 0);
15556 loc_result = loc_descriptor (loc, mode, initialized);
15560 rtl = XEXP (rtl, 1);
15565 rtvec par_elems = XVEC (rtl, 0);
15566 int num_elem = GET_NUM_ELEM (par_elems);
15567 enum machine_mode mode;
15570 /* Create the first one, so we have something to add to. */
15571 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
15572 VOIDmode, initialized);
15573 if (loc_result == NULL)
15575 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
15576 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
15577 for (i = 1; i < num_elem; i++)
15579 dw_loc_descr_ref temp;
15581 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
15582 VOIDmode, initialized);
15585 add_loc_descr (&loc_result, temp);
15586 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
15587 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
15593 if (mode != VOIDmode && mode != BLKmode)
15594 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
15599 if (mode == VOIDmode)
15600 mode = GET_MODE (rtl);
15602 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
15604 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
15606 /* Note that a CONST_DOUBLE rtx could represent either an integer
15607 or a floating-point constant. A CONST_DOUBLE is used whenever
15608 the constant requires more than one word in order to be
15609 adequately represented. We output CONST_DOUBLEs as blocks. */
15610 loc_result = new_loc_descr (DW_OP_implicit_value,
15611 GET_MODE_SIZE (mode), 0);
15612 if (SCALAR_FLOAT_MODE_P (mode))
15614 unsigned int length = GET_MODE_SIZE (mode);
15615 unsigned char *array
15616 = (unsigned char*) ggc_alloc_atomic (length);
15618 insert_float (rtl, array);
15619 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15620 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
15621 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
15622 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15626 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
15627 loc_result->dw_loc_oprnd2.v.val_double
15628 = rtx_to_double_int (rtl);
15634 if (mode == VOIDmode)
15635 mode = GET_MODE (rtl);
15637 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
15639 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
15640 unsigned int length = CONST_VECTOR_NUNITS (rtl);
15641 unsigned char *array = (unsigned char *)
15642 ggc_alloc_atomic (length * elt_size);
15646 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
15647 switch (GET_MODE_CLASS (mode))
15649 case MODE_VECTOR_INT:
15650 for (i = 0, p = array; i < length; i++, p += elt_size)
15652 rtx elt = CONST_VECTOR_ELT (rtl, i);
15653 double_int val = rtx_to_double_int (elt);
15655 if (elt_size <= sizeof (HOST_WIDE_INT))
15656 insert_int (double_int_to_shwi (val), elt_size, p);
15659 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
15660 insert_double (val, p);
15665 case MODE_VECTOR_FLOAT:
15666 for (i = 0, p = array; i < length; i++, p += elt_size)
15668 rtx elt = CONST_VECTOR_ELT (rtl, i);
15669 insert_float (elt, p);
15674 gcc_unreachable ();
15677 loc_result = new_loc_descr (DW_OP_implicit_value,
15678 length * elt_size, 0);
15679 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
15680 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
15681 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
15682 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
15687 if (mode == VOIDmode
15688 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
15689 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
15690 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
15692 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
15697 if (!const_ok_for_output (rtl))
15700 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
15701 && (dwarf_version >= 4 || !dwarf_strict))
15703 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
15704 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
15705 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
15706 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
15707 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
15711 case DEBUG_IMPLICIT_PTR:
15712 loc_result = implicit_ptr_descriptor (rtl, 0);
15716 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
15717 && CONST_INT_P (XEXP (rtl, 1)))
15720 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
15726 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
15727 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
15728 && dwarf_version >= 4)
15729 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
15731 /* Value expression. */
15732 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
15734 add_loc_descr (&loc_result,
15735 new_loc_descr (DW_OP_stack_value, 0, 0));
15743 /* We need to figure out what section we should use as the base for the
15744 address ranges where a given location is valid.
15745 1. If this particular DECL has a section associated with it, use that.
15746 2. If this function has a section associated with it, use that.
15747 3. Otherwise, use the text section.
15748 XXX: If you split a variable across multiple sections, we won't notice. */
15750 static const char *
15751 secname_for_decl (const_tree decl)
15753 const char *secname;
15755 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
15757 tree sectree = DECL_SECTION_NAME (decl);
15758 secname = TREE_STRING_POINTER (sectree);
15760 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
15762 tree sectree = DECL_SECTION_NAME (current_function_decl);
15763 secname = TREE_STRING_POINTER (sectree);
15765 else if (cfun && in_cold_section_p)
15766 secname = crtl->subsections.cold_section_label;
15768 secname = text_section_label;
15773 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
15776 decl_by_reference_p (tree decl)
15778 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
15779 || TREE_CODE (decl) == VAR_DECL)
15780 && DECL_BY_REFERENCE (decl));
15783 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15786 static dw_loc_descr_ref
15787 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
15788 enum var_init_status initialized)
15790 int have_address = 0;
15791 dw_loc_descr_ref descr;
15792 enum machine_mode mode;
15794 if (want_address != 2)
15796 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
15798 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15800 varloc = PAT_VAR_LOCATION_LOC (varloc);
15801 if (GET_CODE (varloc) == EXPR_LIST)
15802 varloc = XEXP (varloc, 0);
15803 mode = GET_MODE (varloc);
15804 if (MEM_P (varloc))
15806 rtx addr = XEXP (varloc, 0);
15807 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
15808 mode, initialized);
15813 rtx x = avoid_constant_pool_reference (varloc);
15815 descr = mem_loc_descriptor (x, mode, VOIDmode,
15820 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
15827 if (GET_CODE (varloc) == VAR_LOCATION)
15828 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
15830 mode = DECL_MODE (loc);
15831 descr = loc_descriptor (varloc, mode, initialized);
15838 if (want_address == 2 && !have_address
15839 && (dwarf_version >= 4 || !dwarf_strict))
15841 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15843 expansion_failed (loc, NULL_RTX,
15844 "DWARF address size mismatch");
15847 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
15850 /* Show if we can't fill the request for an address. */
15851 if (want_address && !have_address)
15853 expansion_failed (loc, NULL_RTX,
15854 "Want address and only have value");
15858 /* If we've got an address and don't want one, dereference. */
15859 if (!want_address && have_address)
15861 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15862 enum dwarf_location_atom op;
15864 if (size > DWARF2_ADDR_SIZE || size == -1)
15866 expansion_failed (loc, NULL_RTX,
15867 "DWARF address size mismatch");
15870 else if (size == DWARF2_ADDR_SIZE)
15873 op = DW_OP_deref_size;
15875 add_loc_descr (&descr, new_loc_descr (op, size, 0));
15881 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
15882 if it is not possible. */
15884 static dw_loc_descr_ref
15885 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
15887 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
15888 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
15889 else if (dwarf_version >= 3 || !dwarf_strict)
15890 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
15895 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15896 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
15898 static dw_loc_descr_ref
15899 dw_sra_loc_expr (tree decl, rtx loc)
15902 unsigned int padsize = 0;
15903 dw_loc_descr_ref descr, *descr_tail;
15904 unsigned HOST_WIDE_INT decl_size;
15906 enum var_init_status initialized;
15908 if (DECL_SIZE (decl) == NULL
15909 || !host_integerp (DECL_SIZE (decl), 1))
15912 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
15914 descr_tail = &descr;
15916 for (p = loc; p; p = XEXP (p, 1))
15918 unsigned int bitsize = decl_piece_bitsize (p);
15919 rtx loc_note = *decl_piece_varloc_ptr (p);
15920 dw_loc_descr_ref cur_descr;
15921 dw_loc_descr_ref *tail, last = NULL;
15922 unsigned int opsize = 0;
15924 if (loc_note == NULL_RTX
15925 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
15927 padsize += bitsize;
15930 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
15931 varloc = NOTE_VAR_LOCATION (loc_note);
15932 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
15933 if (cur_descr == NULL)
15935 padsize += bitsize;
15939 /* Check that cur_descr either doesn't use
15940 DW_OP_*piece operations, or their sum is equal
15941 to bitsize. Otherwise we can't embed it. */
15942 for (tail = &cur_descr; *tail != NULL;
15943 tail = &(*tail)->dw_loc_next)
15944 if ((*tail)->dw_loc_opc == DW_OP_piece)
15946 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
15950 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
15952 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
15956 if (last != NULL && opsize != bitsize)
15958 padsize += bitsize;
15962 /* If there is a hole, add DW_OP_*piece after empty DWARF
15963 expression, which means that those bits are optimized out. */
15966 if (padsize > decl_size)
15968 decl_size -= padsize;
15969 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
15970 if (*descr_tail == NULL)
15972 descr_tail = &(*descr_tail)->dw_loc_next;
15975 *descr_tail = cur_descr;
15977 if (bitsize > decl_size)
15979 decl_size -= bitsize;
15982 HOST_WIDE_INT offset = 0;
15983 if (GET_CODE (varloc) == VAR_LOCATION
15984 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15986 varloc = PAT_VAR_LOCATION_LOC (varloc);
15987 if (GET_CODE (varloc) == EXPR_LIST)
15988 varloc = XEXP (varloc, 0);
15992 if (GET_CODE (varloc) == CONST
15993 || GET_CODE (varloc) == SIGN_EXTEND
15994 || GET_CODE (varloc) == ZERO_EXTEND)
15995 varloc = XEXP (varloc, 0);
15996 else if (GET_CODE (varloc) == SUBREG)
15997 varloc = SUBREG_REG (varloc);
16002 /* DW_OP_bit_size offset should be zero for register
16003 or implicit location descriptions and empty location
16004 descriptions, but for memory addresses needs big endian
16006 if (MEM_P (varloc))
16008 unsigned HOST_WIDE_INT memsize
16009 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
16010 if (memsize != bitsize)
16012 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
16013 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
16015 if (memsize < bitsize)
16017 if (BITS_BIG_ENDIAN)
16018 offset = memsize - bitsize;
16022 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
16023 if (*descr_tail == NULL)
16025 descr_tail = &(*descr_tail)->dw_loc_next;
16029 /* If there were any non-empty expressions, add padding till the end of
16031 if (descr != NULL && decl_size != 0)
16033 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
16034 if (*descr_tail == NULL)
16040 /* Return the dwarf representation of the location list LOC_LIST of
16041 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16044 static dw_loc_list_ref
16045 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
16047 const char *endname, *secname;
16049 enum var_init_status initialized;
16050 struct var_loc_node *node;
16051 dw_loc_descr_ref descr;
16052 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
16053 dw_loc_list_ref list = NULL;
16054 dw_loc_list_ref *listp = &list;
16056 /* Now that we know what section we are using for a base,
16057 actually construct the list of locations.
16058 The first location information is what is passed to the
16059 function that creates the location list, and the remaining
16060 locations just get added on to that list.
16061 Note that we only know the start address for a location
16062 (IE location changes), so to build the range, we use
16063 the range [current location start, next location start].
16064 This means we have to special case the last node, and generate
16065 a range of [last location start, end of function label]. */
16067 secname = secname_for_decl (decl);
16069 for (node = loc_list->first; node; node = node->next)
16070 if (GET_CODE (node->loc) == EXPR_LIST
16071 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
16073 if (GET_CODE (node->loc) == EXPR_LIST)
16075 /* This requires DW_OP_{,bit_}piece, which is not usable
16076 inside DWARF expressions. */
16077 if (want_address != 2)
16079 descr = dw_sra_loc_expr (decl, node->loc);
16085 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
16086 varloc = NOTE_VAR_LOCATION (node->loc);
16087 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
16091 bool range_across_switch = false;
16092 /* If section switch happens in between node->label
16093 and node->next->label (or end of function) and
16094 we can't emit it as a single entry list,
16095 emit two ranges, first one ending at the end
16096 of first partition and second one starting at the
16097 beginning of second partition. */
16098 if (node == loc_list->last_before_switch
16099 && (node != loc_list->first || loc_list->first->next)
16100 && current_function_decl)
16102 endname = current_fde ()->dw_fde_end;
16103 range_across_switch = true;
16105 /* The variable has a location between NODE->LABEL and
16106 NODE->NEXT->LABEL. */
16107 else if (node->next)
16108 endname = node->next->label;
16109 /* If the variable has a location at the last label
16110 it keeps its location until the end of function. */
16111 else if (!current_function_decl)
16112 endname = text_end_label;
16115 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
16116 current_function_funcdef_no);
16117 endname = ggc_strdup (label_id);
16120 *listp = new_loc_list (descr, node->label, endname, secname);
16121 if (TREE_CODE (decl) == PARM_DECL
16122 && node == loc_list->first
16123 && GET_CODE (node->loc) == NOTE
16124 && strcmp (node->label, endname) == 0)
16125 (*listp)->force = true;
16126 listp = &(*listp)->dw_loc_next;
16128 if (range_across_switch)
16130 if (GET_CODE (node->loc) == EXPR_LIST)
16131 descr = dw_sra_loc_expr (decl, node->loc);
16134 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
16135 varloc = NOTE_VAR_LOCATION (node->loc);
16136 descr = dw_loc_list_1 (decl, varloc, want_address,
16139 gcc_assert (descr);
16140 /* The variable has a location between NODE->LABEL and
16141 NODE->NEXT->LABEL. */
16143 endname = node->next->label;
16145 endname = current_fde ()->dw_fde_second_end;
16146 *listp = new_loc_list (descr,
16147 current_fde ()->dw_fde_second_begin,
16149 listp = &(*listp)->dw_loc_next;
16154 /* Try to avoid the overhead of a location list emitting a location
16155 expression instead, but only if we didn't have more than one
16156 location entry in the first place. If some entries were not
16157 representable, we don't want to pretend a single entry that was
16158 applies to the entire scope in which the variable is
16160 if (list && loc_list->first->next)
16166 /* Return if the loc_list has only single element and thus can be represented
16167 as location description. */
16170 single_element_loc_list_p (dw_loc_list_ref list)
16172 gcc_assert (!list->dw_loc_next || list->ll_symbol);
16173 return !list->ll_symbol;
16176 /* To each location in list LIST add loc descr REF. */
16179 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
16181 dw_loc_descr_ref copy;
16182 add_loc_descr (&list->expr, ref);
16183 list = list->dw_loc_next;
16186 copy = ggc_alloc_dw_loc_descr_node ();
16187 memcpy (copy, ref, sizeof (dw_loc_descr_node));
16188 add_loc_descr (&list->expr, copy);
16189 while (copy->dw_loc_next)
16191 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
16192 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
16193 copy->dw_loc_next = new_copy;
16196 list = list->dw_loc_next;
16200 /* Given two lists RET and LIST
16201 produce location list that is result of adding expression in LIST
16202 to expression in RET on each possition in program.
16203 Might be destructive on both RET and LIST.
16205 TODO: We handle only simple cases of RET or LIST having at most one
16206 element. General case would inolve sorting the lists in program order
16207 and merging them that will need some additional work.
16208 Adding that will improve quality of debug info especially for SRA-ed
16212 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
16221 if (!list->dw_loc_next)
16223 add_loc_descr_to_each (*ret, list->expr);
16226 if (!(*ret)->dw_loc_next)
16228 add_loc_descr_to_each (list, (*ret)->expr);
16232 expansion_failed (NULL_TREE, NULL_RTX,
16233 "Don't know how to merge two non-trivial"
16234 " location lists.\n");
16239 /* LOC is constant expression. Try a luck, look it up in constant
16240 pool and return its loc_descr of its address. */
16242 static dw_loc_descr_ref
16243 cst_pool_loc_descr (tree loc)
16245 /* Get an RTL for this, if something has been emitted. */
16246 rtx rtl = lookup_constant_def (loc);
16248 if (!rtl || !MEM_P (rtl))
16253 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
16255 /* TODO: We might get more coverage if we was actually delaying expansion
16256 of all expressions till end of compilation when constant pools are fully
16258 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
16260 expansion_failed (loc, NULL_RTX,
16261 "CST value in contant pool but not marked.");
16264 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
16265 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
16268 /* Return dw_loc_list representing address of addr_expr LOC
16269 by looking for innder INDIRECT_REF expression and turing it
16270 into simple arithmetics. */
16272 static dw_loc_list_ref
16273 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
16276 HOST_WIDE_INT bitsize, bitpos, bytepos;
16277 enum machine_mode mode;
16279 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
16280 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
16282 obj = get_inner_reference (TREE_OPERAND (loc, 0),
16283 &bitsize, &bitpos, &offset, &mode,
16284 &unsignedp, &volatilep, false);
16286 if (bitpos % BITS_PER_UNIT)
16288 expansion_failed (loc, NULL_RTX, "bitfield access");
16291 if (!INDIRECT_REF_P (obj))
16293 expansion_failed (obj,
16294 NULL_RTX, "no indirect ref in inner refrence");
16297 if (!offset && !bitpos)
16298 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
16300 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
16301 && (dwarf_version >= 4 || !dwarf_strict))
16303 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
16308 /* Variable offset. */
16309 list_ret1 = loc_list_from_tree (offset, 0);
16310 if (list_ret1 == 0)
16312 add_loc_list (&list_ret, list_ret1);
16315 add_loc_descr_to_each (list_ret,
16316 new_loc_descr (DW_OP_plus, 0, 0));
16318 bytepos = bitpos / BITS_PER_UNIT;
16320 add_loc_descr_to_each (list_ret,
16321 new_loc_descr (DW_OP_plus_uconst,
16323 else if (bytepos < 0)
16324 loc_list_plus_const (list_ret, bytepos);
16325 add_loc_descr_to_each (list_ret,
16326 new_loc_descr (DW_OP_stack_value, 0, 0));
16332 /* Generate Dwarf location list representing LOC.
16333 If WANT_ADDRESS is false, expression computing LOC will be computed
16334 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
16335 if WANT_ADDRESS is 2, expression computing address useable in location
16336 will be returned (i.e. DW_OP_reg can be used
16337 to refer to register values). */
16339 static dw_loc_list_ref
16340 loc_list_from_tree (tree loc, int want_address)
16342 dw_loc_descr_ref ret = NULL, ret1 = NULL;
16343 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
16344 int have_address = 0;
16345 enum dwarf_location_atom op;
16347 /* ??? Most of the time we do not take proper care for sign/zero
16348 extending the values properly. Hopefully this won't be a real
16351 switch (TREE_CODE (loc))
16354 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
16357 case PLACEHOLDER_EXPR:
16358 /* This case involves extracting fields from an object to determine the
16359 position of other fields. We don't try to encode this here. The
16360 only user of this is Ada, which encodes the needed information using
16361 the names of types. */
16362 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
16366 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
16367 /* There are no opcodes for these operations. */
16370 case PREINCREMENT_EXPR:
16371 case PREDECREMENT_EXPR:
16372 case POSTINCREMENT_EXPR:
16373 case POSTDECREMENT_EXPR:
16374 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
16375 /* There are no opcodes for these operations. */
16379 /* If we already want an address, see if there is INDIRECT_REF inside
16380 e.g. for &this->field. */
16383 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
16384 (loc, want_address == 2);
16387 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
16388 && (ret = cst_pool_loc_descr (loc)))
16391 /* Otherwise, process the argument and look for the address. */
16392 if (!list_ret && !ret)
16393 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
16397 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
16403 if (DECL_THREAD_LOCAL_P (loc))
16406 enum dwarf_location_atom first_op;
16407 enum dwarf_location_atom second_op;
16408 bool dtprel = false;
16410 if (targetm.have_tls)
16412 /* If this is not defined, we have no way to emit the
16414 if (!targetm.asm_out.output_dwarf_dtprel)
16417 /* The way DW_OP_GNU_push_tls_address is specified, we
16418 can only look up addresses of objects in the current
16419 module. We used DW_OP_addr as first op, but that's
16420 wrong, because DW_OP_addr is relocated by the debug
16421 info consumer, while DW_OP_GNU_push_tls_address
16422 operand shouldn't be. */
16423 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
16425 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
16427 second_op = DW_OP_GNU_push_tls_address;
16431 if (!targetm.emutls.debug_form_tls_address
16432 || !(dwarf_version >= 3 || !dwarf_strict))
16434 /* We stuffed the control variable into the DECL_VALUE_EXPR
16435 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
16436 no longer appear in gimple code. We used the control
16437 variable in specific so that we could pick it up here. */
16438 loc = DECL_VALUE_EXPR (loc);
16439 first_op = DW_OP_addr;
16440 second_op = DW_OP_form_tls_address;
16443 rtl = rtl_for_decl_location (loc);
16444 if (rtl == NULL_RTX)
16449 rtl = XEXP (rtl, 0);
16450 if (! CONSTANT_P (rtl))
16453 ret = new_loc_descr (first_op, 0, 0);
16454 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
16455 ret->dw_loc_oprnd1.v.val_addr = rtl;
16456 ret->dtprel = dtprel;
16458 ret1 = new_loc_descr (second_op, 0, 0);
16459 add_loc_descr (&ret, ret1);
16468 if (DECL_HAS_VALUE_EXPR_P (loc))
16469 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
16473 case FUNCTION_DECL:
16476 var_loc_list *loc_list = lookup_decl_loc (loc);
16478 if (loc_list && loc_list->first)
16480 list_ret = dw_loc_list (loc_list, loc, want_address);
16481 have_address = want_address != 0;
16484 rtl = rtl_for_decl_location (loc);
16485 if (rtl == NULL_RTX)
16487 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
16490 else if (CONST_INT_P (rtl))
16492 HOST_WIDE_INT val = INTVAL (rtl);
16493 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16494 val &= GET_MODE_MASK (DECL_MODE (loc));
16495 ret = int_loc_descriptor (val);
16497 else if (GET_CODE (rtl) == CONST_STRING)
16499 expansion_failed (loc, NULL_RTX, "CONST_STRING");
16502 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
16504 ret = new_loc_descr (DW_OP_addr, 0, 0);
16505 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
16506 ret->dw_loc_oprnd1.v.val_addr = rtl;
16510 enum machine_mode mode, mem_mode;
16512 /* Certain constructs can only be represented at top-level. */
16513 if (want_address == 2)
16515 ret = loc_descriptor (rtl, VOIDmode,
16516 VAR_INIT_STATUS_INITIALIZED);
16521 mode = GET_MODE (rtl);
16522 mem_mode = VOIDmode;
16526 mode = get_address_mode (rtl);
16527 rtl = XEXP (rtl, 0);
16530 ret = mem_loc_descriptor (rtl, mode, mem_mode,
16531 VAR_INIT_STATUS_INITIALIZED);
16534 expansion_failed (loc, rtl,
16535 "failed to produce loc descriptor for rtl");
16542 if (!integer_zerop (TREE_OPERAND (loc, 1)))
16546 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16550 case COMPOUND_EXPR:
16551 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
16554 case VIEW_CONVERT_EXPR:
16557 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
16559 case COMPONENT_REF:
16560 case BIT_FIELD_REF:
16562 case ARRAY_RANGE_REF:
16563 case REALPART_EXPR:
16564 case IMAGPART_EXPR:
16567 HOST_WIDE_INT bitsize, bitpos, bytepos;
16568 enum machine_mode mode;
16570 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
16572 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
16573 &unsignedp, &volatilep, false);
16575 gcc_assert (obj != loc);
16577 list_ret = loc_list_from_tree (obj,
16579 && !bitpos && !offset ? 2 : 1);
16580 /* TODO: We can extract value of the small expression via shifting even
16581 for nonzero bitpos. */
16584 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
16586 expansion_failed (loc, NULL_RTX,
16587 "bitfield access");
16591 if (offset != NULL_TREE)
16593 /* Variable offset. */
16594 list_ret1 = loc_list_from_tree (offset, 0);
16595 if (list_ret1 == 0)
16597 add_loc_list (&list_ret, list_ret1);
16600 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
16603 bytepos = bitpos / BITS_PER_UNIT;
16605 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
16606 else if (bytepos < 0)
16607 loc_list_plus_const (list_ret, bytepos);
16614 if ((want_address || !host_integerp (loc, 0))
16615 && (ret = cst_pool_loc_descr (loc)))
16617 else if (want_address == 2
16618 && host_integerp (loc, 0)
16619 && (ret = address_of_int_loc_descriptor
16620 (int_size_in_bytes (TREE_TYPE (loc)),
16621 tree_low_cst (loc, 0))))
16623 else if (host_integerp (loc, 0))
16624 ret = int_loc_descriptor (tree_low_cst (loc, 0));
16627 expansion_failed (loc, NULL_RTX,
16628 "Integer operand is not host integer");
16637 if ((ret = cst_pool_loc_descr (loc)))
16640 /* We can construct small constants here using int_loc_descriptor. */
16641 expansion_failed (loc, NULL_RTX,
16642 "constructor or constant not in constant pool");
16645 case TRUTH_AND_EXPR:
16646 case TRUTH_ANDIF_EXPR:
16651 case TRUTH_XOR_EXPR:
16656 case TRUTH_OR_EXPR:
16657 case TRUTH_ORIF_EXPR:
16662 case FLOOR_DIV_EXPR:
16663 case CEIL_DIV_EXPR:
16664 case ROUND_DIV_EXPR:
16665 case TRUNC_DIV_EXPR:
16666 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16675 case FLOOR_MOD_EXPR:
16676 case CEIL_MOD_EXPR:
16677 case ROUND_MOD_EXPR:
16678 case TRUNC_MOD_EXPR:
16679 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
16684 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16685 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
16686 if (list_ret == 0 || list_ret1 == 0)
16689 add_loc_list (&list_ret, list_ret1);
16692 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16693 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
16694 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
16695 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
16696 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
16708 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
16711 case POINTER_PLUS_EXPR:
16713 if (host_integerp (TREE_OPERAND (loc, 1), 0))
16715 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16719 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
16727 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16734 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16741 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16748 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
16763 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16764 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
16765 if (list_ret == 0 || list_ret1 == 0)
16768 add_loc_list (&list_ret, list_ret1);
16771 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16774 case TRUTH_NOT_EXPR:
16788 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16792 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
16798 const enum tree_code code =
16799 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
16801 loc = build3 (COND_EXPR, TREE_TYPE (loc),
16802 build2 (code, integer_type_node,
16803 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
16804 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
16807 /* ... fall through ... */
16811 dw_loc_descr_ref lhs
16812 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
16813 dw_loc_list_ref rhs
16814 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
16815 dw_loc_descr_ref bra_node, jump_node, tmp;
16817 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
16818 if (list_ret == 0 || lhs == 0 || rhs == 0)
16821 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
16822 add_loc_descr_to_each (list_ret, bra_node);
16824 add_loc_list (&list_ret, rhs);
16825 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
16826 add_loc_descr_to_each (list_ret, jump_node);
16828 add_loc_descr_to_each (list_ret, lhs);
16829 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16830 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
16832 /* ??? Need a node to point the skip at. Use a nop. */
16833 tmp = new_loc_descr (DW_OP_nop, 0, 0);
16834 add_loc_descr_to_each (list_ret, tmp);
16835 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16836 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
16840 case FIX_TRUNC_EXPR:
16844 /* Leave front-end specific codes as simply unknown. This comes
16845 up, for instance, with the C STMT_EXPR. */
16846 if ((unsigned int) TREE_CODE (loc)
16847 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
16849 expansion_failed (loc, NULL_RTX,
16850 "language specific tree node");
16854 #ifdef ENABLE_CHECKING
16855 /* Otherwise this is a generic code; we should just lists all of
16856 these explicitly. We forgot one. */
16857 gcc_unreachable ();
16859 /* In a release build, we want to degrade gracefully: better to
16860 generate incomplete debugging information than to crash. */
16865 if (!ret && !list_ret)
16868 if (want_address == 2 && !have_address
16869 && (dwarf_version >= 4 || !dwarf_strict))
16871 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
16873 expansion_failed (loc, NULL_RTX,
16874 "DWARF address size mismatch");
16878 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
16880 add_loc_descr_to_each (list_ret,
16881 new_loc_descr (DW_OP_stack_value, 0, 0));
16884 /* Show if we can't fill the request for an address. */
16885 if (want_address && !have_address)
16887 expansion_failed (loc, NULL_RTX,
16888 "Want address and only have value");
16892 gcc_assert (!ret || !list_ret);
16894 /* If we've got an address and don't want one, dereference. */
16895 if (!want_address && have_address)
16897 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
16899 if (size > DWARF2_ADDR_SIZE || size == -1)
16901 expansion_failed (loc, NULL_RTX,
16902 "DWARF address size mismatch");
16905 else if (size == DWARF2_ADDR_SIZE)
16908 op = DW_OP_deref_size;
16911 add_loc_descr (&ret, new_loc_descr (op, size, 0));
16913 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
16916 list_ret = new_loc_list (ret, NULL, NULL, NULL);
16921 /* Same as above but return only single location expression. */
16922 static dw_loc_descr_ref
16923 loc_descriptor_from_tree (tree loc, int want_address)
16925 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
16928 if (ret->dw_loc_next)
16930 expansion_failed (loc, NULL_RTX,
16931 "Location list where only loc descriptor needed");
16937 /* Given a value, round it up to the lowest multiple of `boundary'
16938 which is not less than the value itself. */
16940 static inline HOST_WIDE_INT
16941 ceiling (HOST_WIDE_INT value, unsigned int boundary)
16943 return (((value + boundary - 1) / boundary) * boundary);
16946 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
16947 pointer to the declared type for the relevant field variable, or return
16948 `integer_type_node' if the given node turns out to be an
16949 ERROR_MARK node. */
16952 field_type (const_tree decl)
16956 if (TREE_CODE (decl) == ERROR_MARK)
16957 return integer_type_node;
16959 type = DECL_BIT_FIELD_TYPE (decl);
16960 if (type == NULL_TREE)
16961 type = TREE_TYPE (decl);
16966 /* Given a pointer to a tree node, return the alignment in bits for
16967 it, or else return BITS_PER_WORD if the node actually turns out to
16968 be an ERROR_MARK node. */
16970 static inline unsigned
16971 simple_type_align_in_bits (const_tree type)
16973 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
16976 static inline unsigned
16977 simple_decl_align_in_bits (const_tree decl)
16979 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
16982 /* Return the result of rounding T up to ALIGN. */
16984 static inline double_int
16985 round_up_to_align (double_int t, unsigned int align)
16987 double_int alignd = uhwi_to_double_int (align);
16988 t = double_int_add (t, alignd);
16989 t = double_int_add (t, double_int_minus_one);
16990 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
16991 t = double_int_mul (t, alignd);
16995 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
16996 lowest addressed byte of the "containing object" for the given FIELD_DECL,
16997 or return 0 if we are unable to determine what that offset is, either
16998 because the argument turns out to be a pointer to an ERROR_MARK node, or
16999 because the offset is actually variable. (We can't handle the latter case
17002 static HOST_WIDE_INT
17003 field_byte_offset (const_tree decl)
17005 double_int object_offset_in_bits;
17006 double_int object_offset_in_bytes;
17007 double_int bitpos_int;
17009 if (TREE_CODE (decl) == ERROR_MARK)
17012 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
17014 /* We cannot yet cope with fields whose positions are variable, so
17015 for now, when we see such things, we simply return 0. Someday, we may
17016 be able to handle such cases, but it will be damn difficult. */
17017 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
17020 bitpos_int = tree_to_double_int (bit_position (decl));
17022 #ifdef PCC_BITFIELD_TYPE_MATTERS
17023 if (PCC_BITFIELD_TYPE_MATTERS)
17026 tree field_size_tree;
17027 double_int deepest_bitpos;
17028 double_int field_size_in_bits;
17029 unsigned int type_align_in_bits;
17030 unsigned int decl_align_in_bits;
17031 double_int type_size_in_bits;
17033 type = field_type (decl);
17034 type_size_in_bits = double_int_type_size_in_bits (type);
17035 type_align_in_bits = simple_type_align_in_bits (type);
17037 field_size_tree = DECL_SIZE (decl);
17039 /* The size could be unspecified if there was an error, or for
17040 a flexible array member. */
17041 if (!field_size_tree)
17042 field_size_tree = bitsize_zero_node;
17044 /* If the size of the field is not constant, use the type size. */
17045 if (TREE_CODE (field_size_tree) == INTEGER_CST)
17046 field_size_in_bits = tree_to_double_int (field_size_tree);
17048 field_size_in_bits = type_size_in_bits;
17050 decl_align_in_bits = simple_decl_align_in_bits (decl);
17052 /* The GCC front-end doesn't make any attempt to keep track of the
17053 starting bit offset (relative to the start of the containing
17054 structure type) of the hypothetical "containing object" for a
17055 bit-field. Thus, when computing the byte offset value for the
17056 start of the "containing object" of a bit-field, we must deduce
17057 this information on our own. This can be rather tricky to do in
17058 some cases. For example, handling the following structure type
17059 definition when compiling for an i386/i486 target (which only
17060 aligns long long's to 32-bit boundaries) can be very tricky:
17062 struct S { int field1; long long field2:31; };
17064 Fortunately, there is a simple rule-of-thumb which can be used
17065 in such cases. When compiling for an i386/i486, GCC will
17066 allocate 8 bytes for the structure shown above. It decides to
17067 do this based upon one simple rule for bit-field allocation.
17068 GCC allocates each "containing object" for each bit-field at
17069 the first (i.e. lowest addressed) legitimate alignment boundary
17070 (based upon the required minimum alignment for the declared
17071 type of the field) which it can possibly use, subject to the
17072 condition that there is still enough available space remaining
17073 in the containing object (when allocated at the selected point)
17074 to fully accommodate all of the bits of the bit-field itself.
17076 This simple rule makes it obvious why GCC allocates 8 bytes for
17077 each object of the structure type shown above. When looking
17078 for a place to allocate the "containing object" for `field2',
17079 the compiler simply tries to allocate a 64-bit "containing
17080 object" at each successive 32-bit boundary (starting at zero)
17081 until it finds a place to allocate that 64- bit field such that
17082 at least 31 contiguous (and previously unallocated) bits remain
17083 within that selected 64 bit field. (As it turns out, for the
17084 example above, the compiler finds it is OK to allocate the
17085 "containing object" 64-bit field at bit-offset zero within the
17088 Here we attempt to work backwards from the limited set of facts
17089 we're given, and we try to deduce from those facts, where GCC
17090 must have believed that the containing object started (within
17091 the structure type). The value we deduce is then used (by the
17092 callers of this routine) to generate DW_AT_location and
17093 DW_AT_bit_offset attributes for fields (both bit-fields and, in
17094 the case of DW_AT_location, regular fields as well). */
17096 /* Figure out the bit-distance from the start of the structure to
17097 the "deepest" bit of the bit-field. */
17098 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
17100 /* This is the tricky part. Use some fancy footwork to deduce
17101 where the lowest addressed bit of the containing object must
17103 object_offset_in_bits
17104 = double_int_sub (deepest_bitpos, type_size_in_bits);
17106 /* Round up to type_align by default. This works best for
17108 object_offset_in_bits
17109 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
17111 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
17113 object_offset_in_bits
17114 = double_int_sub (deepest_bitpos, type_size_in_bits);
17116 /* Round up to decl_align instead. */
17117 object_offset_in_bits
17118 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
17122 #endif /* PCC_BITFIELD_TYPE_MATTERS */
17123 object_offset_in_bits = bitpos_int;
17125 object_offset_in_bytes
17126 = double_int_div (object_offset_in_bits,
17127 uhwi_to_double_int (BITS_PER_UNIT), true,
17129 return double_int_to_shwi (object_offset_in_bytes);
17132 /* The following routines define various Dwarf attributes and any data
17133 associated with them. */
17135 /* Add a location description attribute value to a DIE.
17137 This emits location attributes suitable for whole variables and
17138 whole parameters. Note that the location attributes for struct fields are
17139 generated by the routine `data_member_location_attribute' below. */
17142 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
17143 dw_loc_list_ref descr)
17147 if (single_element_loc_list_p (descr))
17148 add_AT_loc (die, attr_kind, descr->expr);
17150 add_AT_loc_list (die, attr_kind, descr);
17153 /* Add DW_AT_accessibility attribute to DIE if needed. */
17156 add_accessibility_attribute (dw_die_ref die, tree decl)
17158 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
17159 children, otherwise the default is DW_ACCESS_public. In DWARF2
17160 the default has always been DW_ACCESS_public. */
17161 if (TREE_PROTECTED (decl))
17162 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
17163 else if (TREE_PRIVATE (decl))
17165 if (dwarf_version == 2
17166 || die->die_parent == NULL
17167 || die->die_parent->die_tag != DW_TAG_class_type)
17168 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
17170 else if (dwarf_version > 2
17172 && die->die_parent->die_tag == DW_TAG_class_type)
17173 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
17176 /* Attach the specialized form of location attribute used for data members of
17177 struct and union types. In the special case of a FIELD_DECL node which
17178 represents a bit-field, the "offset" part of this special location
17179 descriptor must indicate the distance in bytes from the lowest-addressed
17180 byte of the containing struct or union type to the lowest-addressed byte of
17181 the "containing object" for the bit-field. (See the `field_byte_offset'
17184 For any given bit-field, the "containing object" is a hypothetical object
17185 (of some integral or enum type) within which the given bit-field lives. The
17186 type of this hypothetical "containing object" is always the same as the
17187 declared type of the individual bit-field itself (for GCC anyway... the
17188 DWARF spec doesn't actually mandate this). Note that it is the size (in
17189 bytes) of the hypothetical "containing object" which will be given in the
17190 DW_AT_byte_size attribute for this bit-field. (See the
17191 `byte_size_attribute' function below.) It is also used when calculating the
17192 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
17193 function below.) */
17196 add_data_member_location_attribute (dw_die_ref die, tree decl)
17198 HOST_WIDE_INT offset;
17199 dw_loc_descr_ref loc_descr = 0;
17201 if (TREE_CODE (decl) == TREE_BINFO)
17203 /* We're working on the TAG_inheritance for a base class. */
17204 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
17206 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
17207 aren't at a fixed offset from all (sub)objects of the same
17208 type. We need to extract the appropriate offset from our
17209 vtable. The following dwarf expression means
17211 BaseAddr = ObAddr + *((*ObAddr) - Offset)
17213 This is specific to the V3 ABI, of course. */
17215 dw_loc_descr_ref tmp;
17217 /* Make a copy of the object address. */
17218 tmp = new_loc_descr (DW_OP_dup, 0, 0);
17219 add_loc_descr (&loc_descr, tmp);
17221 /* Extract the vtable address. */
17222 tmp = new_loc_descr (DW_OP_deref, 0, 0);
17223 add_loc_descr (&loc_descr, tmp);
17225 /* Calculate the address of the offset. */
17226 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
17227 gcc_assert (offset < 0);
17229 tmp = int_loc_descriptor (-offset);
17230 add_loc_descr (&loc_descr, tmp);
17231 tmp = new_loc_descr (DW_OP_minus, 0, 0);
17232 add_loc_descr (&loc_descr, tmp);
17234 /* Extract the offset. */
17235 tmp = new_loc_descr (DW_OP_deref, 0, 0);
17236 add_loc_descr (&loc_descr, tmp);
17238 /* Add it to the object address. */
17239 tmp = new_loc_descr (DW_OP_plus, 0, 0);
17240 add_loc_descr (&loc_descr, tmp);
17243 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
17246 offset = field_byte_offset (decl);
17250 if (dwarf_version > 2)
17252 /* Don't need to output a location expression, just the constant. */
17254 add_AT_int (die, DW_AT_data_member_location, offset);
17256 add_AT_unsigned (die, DW_AT_data_member_location, offset);
17261 enum dwarf_location_atom op;
17263 /* The DWARF2 standard says that we should assume that the structure
17264 address is already on the stack, so we can specify a structure
17265 field address by using DW_OP_plus_uconst. */
17267 #ifdef MIPS_DEBUGGING_INFO
17268 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
17269 operator correctly. It works only if we leave the offset on the
17273 op = DW_OP_plus_uconst;
17276 loc_descr = new_loc_descr (op, offset, 0);
17280 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
17283 /* Writes integer values to dw_vec_const array. */
17286 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
17290 *dest++ = val & 0xff;
17296 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
17298 static HOST_WIDE_INT
17299 extract_int (const unsigned char *src, unsigned int size)
17301 HOST_WIDE_INT val = 0;
17307 val |= *--src & 0xff;
17313 /* Writes double_int values to dw_vec_const array. */
17316 insert_double (double_int val, unsigned char *dest)
17318 unsigned char *p0 = dest;
17319 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
17321 if (WORDS_BIG_ENDIAN)
17327 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
17328 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
17331 /* Writes floating point values to dw_vec_const array. */
17334 insert_float (const_rtx rtl, unsigned char *array)
17336 REAL_VALUE_TYPE rv;
17340 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
17341 real_to_target (val, &rv, GET_MODE (rtl));
17343 /* real_to_target puts 32-bit pieces in each long. Pack them. */
17344 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
17346 insert_int (val[i], 4, array);
17351 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
17352 does not have a "location" either in memory or in a register. These
17353 things can arise in GNU C when a constant is passed as an actual parameter
17354 to an inlined function. They can also arise in C++ where declared
17355 constants do not necessarily get memory "homes". */
17358 add_const_value_attribute (dw_die_ref die, rtx rtl)
17360 switch (GET_CODE (rtl))
17364 HOST_WIDE_INT val = INTVAL (rtl);
17367 add_AT_int (die, DW_AT_const_value, val);
17369 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
17374 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
17375 floating-point constant. A CONST_DOUBLE is used whenever the
17376 constant requires more than one word in order to be adequately
17379 enum machine_mode mode = GET_MODE (rtl);
17381 if (SCALAR_FLOAT_MODE_P (mode))
17383 unsigned int length = GET_MODE_SIZE (mode);
17384 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
17386 insert_float (rtl, array);
17387 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
17390 add_AT_double (die, DW_AT_const_value,
17391 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
17397 enum machine_mode mode = GET_MODE (rtl);
17398 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
17399 unsigned int length = CONST_VECTOR_NUNITS (rtl);
17400 unsigned char *array = (unsigned char *) ggc_alloc_atomic
17401 (length * elt_size);
17405 switch (GET_MODE_CLASS (mode))
17407 case MODE_VECTOR_INT:
17408 for (i = 0, p = array; i < length; i++, p += elt_size)
17410 rtx elt = CONST_VECTOR_ELT (rtl, i);
17411 double_int val = rtx_to_double_int (elt);
17413 if (elt_size <= sizeof (HOST_WIDE_INT))
17414 insert_int (double_int_to_shwi (val), elt_size, p);
17417 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
17418 insert_double (val, p);
17423 case MODE_VECTOR_FLOAT:
17424 for (i = 0, p = array; i < length; i++, p += elt_size)
17426 rtx elt = CONST_VECTOR_ELT (rtl, i);
17427 insert_float (elt, p);
17432 gcc_unreachable ();
17435 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
17440 if (dwarf_version >= 4 || !dwarf_strict)
17442 dw_loc_descr_ref loc_result;
17443 resolve_one_addr (&rtl, NULL);
17445 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
17446 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
17447 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
17448 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
17449 add_AT_loc (die, DW_AT_location, loc_result);
17450 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
17456 if (CONSTANT_P (XEXP (rtl, 0)))
17457 return add_const_value_attribute (die, XEXP (rtl, 0));
17460 if (!const_ok_for_output (rtl))
17463 if (dwarf_version >= 4 || !dwarf_strict)
17468 /* In cases where an inlined instance of an inline function is passed
17469 the address of an `auto' variable (which is local to the caller) we
17470 can get a situation where the DECL_RTL of the artificial local
17471 variable (for the inlining) which acts as a stand-in for the
17472 corresponding formal parameter (of the inline function) will look
17473 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
17474 exactly a compile-time constant expression, but it isn't the address
17475 of the (artificial) local variable either. Rather, it represents the
17476 *value* which the artificial local variable always has during its
17477 lifetime. We currently have no way to represent such quasi-constant
17478 values in Dwarf, so for now we just punt and generate nothing. */
17486 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
17487 && MEM_READONLY_P (rtl)
17488 && GET_MODE (rtl) == BLKmode)
17490 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
17496 /* No other kinds of rtx should be possible here. */
17497 gcc_unreachable ();
17502 /* Determine whether the evaluation of EXPR references any variables
17503 or functions which aren't otherwise used (and therefore may not be
17506 reference_to_unused (tree * tp, int * walk_subtrees,
17507 void * data ATTRIBUTE_UNUSED)
17509 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
17510 *walk_subtrees = 0;
17512 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
17513 && ! TREE_ASM_WRITTEN (*tp))
17515 /* ??? The C++ FE emits debug information for using decls, so
17516 putting gcc_unreachable here falls over. See PR31899. For now
17517 be conservative. */
17518 else if (!cgraph_global_info_ready
17519 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
17521 else if (TREE_CODE (*tp) == VAR_DECL)
17523 struct varpool_node *node = varpool_get_node (*tp);
17524 if (!node || !node->needed)
17527 else if (TREE_CODE (*tp) == FUNCTION_DECL
17528 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
17530 /* The call graph machinery must have finished analyzing,
17531 optimizing and gimplifying the CU by now.
17532 So if *TP has no call graph node associated
17533 to it, it means *TP will not be emitted. */
17534 if (!cgraph_get_node (*tp))
17537 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
17543 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
17544 for use in a later add_const_value_attribute call. */
17547 rtl_for_decl_init (tree init, tree type)
17549 rtx rtl = NULL_RTX;
17553 /* If a variable is initialized with a string constant without embedded
17554 zeros, build CONST_STRING. */
17555 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
17557 tree enttype = TREE_TYPE (type);
17558 tree domain = TYPE_DOMAIN (type);
17559 enum machine_mode mode = TYPE_MODE (enttype);
17561 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
17563 && integer_zerop (TYPE_MIN_VALUE (domain))
17564 && compare_tree_int (TYPE_MAX_VALUE (domain),
17565 TREE_STRING_LENGTH (init) - 1) == 0
17566 && ((size_t) TREE_STRING_LENGTH (init)
17567 == strlen (TREE_STRING_POINTER (init)) + 1))
17569 rtl = gen_rtx_CONST_STRING (VOIDmode,
17570 ggc_strdup (TREE_STRING_POINTER (init)));
17571 rtl = gen_rtx_MEM (BLKmode, rtl);
17572 MEM_READONLY_P (rtl) = 1;
17575 /* Other aggregates, and complex values, could be represented using
17577 else if (AGGREGATE_TYPE_P (type)
17578 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
17579 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
17580 || TREE_CODE (type) == COMPLEX_TYPE)
17582 /* Vectors only work if their mode is supported by the target.
17583 FIXME: generic vectors ought to work too. */
17584 else if (TREE_CODE (type) == VECTOR_TYPE
17585 && !VECTOR_MODE_P (TYPE_MODE (type)))
17587 /* If the initializer is something that we know will expand into an
17588 immediate RTL constant, expand it now. We must be careful not to
17589 reference variables which won't be output. */
17590 else if (initializer_constant_valid_p (init, type)
17591 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
17593 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
17595 if (TREE_CODE (type) == VECTOR_TYPE)
17596 switch (TREE_CODE (init))
17601 if (TREE_CONSTANT (init))
17603 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
17604 bool constant_p = true;
17606 unsigned HOST_WIDE_INT ix;
17608 /* Even when ctor is constant, it might contain non-*_CST
17609 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
17610 belong into VECTOR_CST nodes. */
17611 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
17612 if (!CONSTANT_CLASS_P (value))
17614 constant_p = false;
17620 init = build_vector_from_ctor (type, elts);
17630 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
17632 /* If expand_expr returns a MEM, it wasn't immediate. */
17633 gcc_assert (!rtl || !MEM_P (rtl));
17639 /* Generate RTL for the variable DECL to represent its location. */
17642 rtl_for_decl_location (tree decl)
17646 /* Here we have to decide where we are going to say the parameter "lives"
17647 (as far as the debugger is concerned). We only have a couple of
17648 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
17650 DECL_RTL normally indicates where the parameter lives during most of the
17651 activation of the function. If optimization is enabled however, this
17652 could be either NULL or else a pseudo-reg. Both of those cases indicate
17653 that the parameter doesn't really live anywhere (as far as the code
17654 generation parts of GCC are concerned) during most of the function's
17655 activation. That will happen (for example) if the parameter is never
17656 referenced within the function.
17658 We could just generate a location descriptor here for all non-NULL
17659 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
17660 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
17661 where DECL_RTL is NULL or is a pseudo-reg.
17663 Note however that we can only get away with using DECL_INCOMING_RTL as
17664 a backup substitute for DECL_RTL in certain limited cases. In cases
17665 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
17666 we can be sure that the parameter was passed using the same type as it is
17667 declared to have within the function, and that its DECL_INCOMING_RTL
17668 points us to a place where a value of that type is passed.
17670 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
17671 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
17672 because in these cases DECL_INCOMING_RTL points us to a value of some
17673 type which is *different* from the type of the parameter itself. Thus,
17674 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
17675 such cases, the debugger would end up (for example) trying to fetch a
17676 `float' from a place which actually contains the first part of a
17677 `double'. That would lead to really incorrect and confusing
17678 output at debug-time.
17680 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
17681 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
17682 are a couple of exceptions however. On little-endian machines we can
17683 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
17684 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
17685 an integral type that is smaller than TREE_TYPE (decl). These cases arise
17686 when (on a little-endian machine) a non-prototyped function has a
17687 parameter declared to be of type `short' or `char'. In such cases,
17688 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
17689 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
17690 passed `int' value. If the debugger then uses that address to fetch
17691 a `short' or a `char' (on a little-endian machine) the result will be
17692 the correct data, so we allow for such exceptional cases below.
17694 Note that our goal here is to describe the place where the given formal
17695 parameter lives during most of the function's activation (i.e. between the
17696 end of the prologue and the start of the epilogue). We'll do that as best
17697 as we can. Note however that if the given formal parameter is modified
17698 sometime during the execution of the function, then a stack backtrace (at
17699 debug-time) will show the function as having been called with the *new*
17700 value rather than the value which was originally passed in. This happens
17701 rarely enough that it is not a major problem, but it *is* a problem, and
17702 I'd like to fix it.
17704 A future version of dwarf2out.c may generate two additional attributes for
17705 any given DW_TAG_formal_parameter DIE which will describe the "passed
17706 type" and the "passed location" for the given formal parameter in addition
17707 to the attributes we now generate to indicate the "declared type" and the
17708 "active location" for each parameter. This additional set of attributes
17709 could be used by debuggers for stack backtraces. Separately, note that
17710 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
17711 This happens (for example) for inlined-instances of inline function formal
17712 parameters which are never referenced. This really shouldn't be
17713 happening. All PARM_DECL nodes should get valid non-NULL
17714 DECL_INCOMING_RTL values. FIXME. */
17716 /* Use DECL_RTL as the "location" unless we find something better. */
17717 rtl = DECL_RTL_IF_SET (decl);
17719 /* When generating abstract instances, ignore everything except
17720 constants, symbols living in memory, and symbols living in
17721 fixed registers. */
17722 if (! reload_completed)
17725 && (CONSTANT_P (rtl)
17727 && CONSTANT_P (XEXP (rtl, 0)))
17729 && TREE_CODE (decl) == VAR_DECL
17730 && TREE_STATIC (decl))))
17732 rtl = targetm.delegitimize_address (rtl);
17737 else if (TREE_CODE (decl) == PARM_DECL)
17739 if (rtl == NULL_RTX
17740 || is_pseudo_reg (rtl)
17742 && is_pseudo_reg (XEXP (rtl, 0))
17743 && DECL_INCOMING_RTL (decl)
17744 && MEM_P (DECL_INCOMING_RTL (decl))
17745 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
17747 tree declared_type = TREE_TYPE (decl);
17748 tree passed_type = DECL_ARG_TYPE (decl);
17749 enum machine_mode dmode = TYPE_MODE (declared_type);
17750 enum machine_mode pmode = TYPE_MODE (passed_type);
17752 /* This decl represents a formal parameter which was optimized out.
17753 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
17754 all cases where (rtl == NULL_RTX) just below. */
17755 if (dmode == pmode)
17756 rtl = DECL_INCOMING_RTL (decl);
17757 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
17758 && SCALAR_INT_MODE_P (dmode)
17759 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
17760 && DECL_INCOMING_RTL (decl))
17762 rtx inc = DECL_INCOMING_RTL (decl);
17765 else if (MEM_P (inc))
17767 if (BYTES_BIG_ENDIAN)
17768 rtl = adjust_address_nv (inc, dmode,
17769 GET_MODE_SIZE (pmode)
17770 - GET_MODE_SIZE (dmode));
17777 /* If the parm was passed in registers, but lives on the stack, then
17778 make a big endian correction if the mode of the type of the
17779 parameter is not the same as the mode of the rtl. */
17780 /* ??? This is the same series of checks that are made in dbxout.c before
17781 we reach the big endian correction code there. It isn't clear if all
17782 of these checks are necessary here, but keeping them all is the safe
17784 else if (MEM_P (rtl)
17785 && XEXP (rtl, 0) != const0_rtx
17786 && ! CONSTANT_P (XEXP (rtl, 0))
17787 /* Not passed in memory. */
17788 && !MEM_P (DECL_INCOMING_RTL (decl))
17789 /* Not passed by invisible reference. */
17790 && (!REG_P (XEXP (rtl, 0))
17791 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
17792 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
17793 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
17794 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
17797 /* Big endian correction check. */
17798 && BYTES_BIG_ENDIAN
17799 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
17800 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
17803 int offset = (UNITS_PER_WORD
17804 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
17806 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17807 plus_constant (XEXP (rtl, 0), offset));
17810 else if (TREE_CODE (decl) == VAR_DECL
17813 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
17814 && BYTES_BIG_ENDIAN)
17816 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
17817 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
17819 /* If a variable is declared "register" yet is smaller than
17820 a register, then if we store the variable to memory, it
17821 looks like we're storing a register-sized value, when in
17822 fact we are not. We need to adjust the offset of the
17823 storage location to reflect the actual value's bytes,
17824 else gdb will not be able to display it. */
17826 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
17827 plus_constant (XEXP (rtl, 0), rsize-dsize));
17830 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
17831 and will have been substituted directly into all expressions that use it.
17832 C does not have such a concept, but C++ and other languages do. */
17833 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
17834 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
17837 rtl = targetm.delegitimize_address (rtl);
17839 /* If we don't look past the constant pool, we risk emitting a
17840 reference to a constant pool entry that isn't referenced from
17841 code, and thus is not emitted. */
17843 rtl = avoid_constant_pool_reference (rtl);
17845 /* Try harder to get a rtl. If this symbol ends up not being emitted
17846 in the current CU, resolve_addr will remove the expression referencing
17848 if (rtl == NULL_RTX
17849 && TREE_CODE (decl) == VAR_DECL
17850 && !DECL_EXTERNAL (decl)
17851 && TREE_STATIC (decl)
17852 && DECL_NAME (decl)
17853 && !DECL_HARD_REGISTER (decl)
17854 && DECL_MODE (decl) != VOIDmode)
17856 rtl = make_decl_rtl_for_debug (decl);
17858 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
17859 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
17866 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17867 returned. If so, the decl for the COMMON block is returned, and the
17868 value is the offset into the common block for the symbol. */
17871 fortran_common (tree decl, HOST_WIDE_INT *value)
17873 tree val_expr, cvar;
17874 enum machine_mode mode;
17875 HOST_WIDE_INT bitsize, bitpos;
17877 int volatilep = 0, unsignedp = 0;
17879 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
17880 it does not have a value (the offset into the common area), or if it
17881 is thread local (as opposed to global) then it isn't common, and shouldn't
17882 be handled as such. */
17883 if (TREE_CODE (decl) != VAR_DECL
17884 || !TREE_STATIC (decl)
17885 || !DECL_HAS_VALUE_EXPR_P (decl)
17889 val_expr = DECL_VALUE_EXPR (decl);
17890 if (TREE_CODE (val_expr) != COMPONENT_REF)
17893 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
17894 &mode, &unsignedp, &volatilep, true);
17896 if (cvar == NULL_TREE
17897 || TREE_CODE (cvar) != VAR_DECL
17898 || DECL_ARTIFICIAL (cvar)
17899 || !TREE_PUBLIC (cvar))
17903 if (offset != NULL)
17905 if (!host_integerp (offset, 0))
17907 *value = tree_low_cst (offset, 0);
17910 *value += bitpos / BITS_PER_UNIT;
17915 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
17916 data attribute for a variable or a parameter. We generate the
17917 DW_AT_const_value attribute only in those cases where the given variable
17918 or parameter does not have a true "location" either in memory or in a
17919 register. This can happen (for example) when a constant is passed as an
17920 actual argument in a call to an inline function. (It's possible that
17921 these things can crop up in other ways also.) Note that one type of
17922 constant value which can be passed into an inlined function is a constant
17923 pointer. This can happen for example if an actual argument in an inlined
17924 function call evaluates to a compile-time constant address.
17926 CACHE_P is true if it is worth caching the location list for DECL,
17927 so that future calls can reuse it rather than regenerate it from scratch.
17928 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
17929 since we will need to refer to them each time the function is inlined. */
17932 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
17933 enum dwarf_attribute attr)
17936 dw_loc_list_ref list;
17937 var_loc_list *loc_list;
17938 cached_dw_loc_list *cache;
17941 if (TREE_CODE (decl) == ERROR_MARK)
17944 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
17945 || TREE_CODE (decl) == RESULT_DECL);
17947 /* Try to get some constant RTL for this decl, and use that as the value of
17950 rtl = rtl_for_decl_location (decl);
17951 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17952 && add_const_value_attribute (die, rtl))
17955 /* See if we have single element location list that is equivalent to
17956 a constant value. That way we are better to use add_const_value_attribute
17957 rather than expanding constant value equivalent. */
17958 loc_list = lookup_decl_loc (decl);
17961 && loc_list->first->next == NULL
17962 && NOTE_P (loc_list->first->loc)
17963 && NOTE_VAR_LOCATION (loc_list->first->loc)
17964 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
17966 struct var_loc_node *node;
17968 node = loc_list->first;
17969 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
17970 if (GET_CODE (rtl) == EXPR_LIST)
17971 rtl = XEXP (rtl, 0);
17972 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17973 && add_const_value_attribute (die, rtl))
17976 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
17977 list several times. See if we've already cached the contents. */
17979 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
17983 cache = (cached_dw_loc_list *)
17984 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
17986 list = cache->loc_list;
17990 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
17991 /* It is usually worth caching this result if the decl is from
17992 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
17993 if (cache_p && list && list->dw_loc_next)
17995 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
17996 DECL_UID (decl), INSERT);
17997 cache = ggc_alloc_cleared_cached_dw_loc_list ();
17998 cache->decl_id = DECL_UID (decl);
17999 cache->loc_list = list;
18005 add_AT_location_description (die, attr, list);
18008 /* None of that worked, so it must not really have a location;
18009 try adding a constant value attribute from the DECL_INITIAL. */
18010 return tree_add_const_value_attribute_for_decl (die, decl);
18013 /* Add VARIABLE and DIE into deferred locations list. */
18016 defer_location (tree variable, dw_die_ref die)
18018 deferred_locations entry;
18019 entry.variable = variable;
18021 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
18024 /* Helper function for tree_add_const_value_attribute. Natively encode
18025 initializer INIT into an array. Return true if successful. */
18028 native_encode_initializer (tree init, unsigned char *array, int size)
18032 if (init == NULL_TREE)
18036 switch (TREE_CODE (init))
18039 type = TREE_TYPE (init);
18040 if (TREE_CODE (type) == ARRAY_TYPE)
18042 tree enttype = TREE_TYPE (type);
18043 enum machine_mode mode = TYPE_MODE (enttype);
18045 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
18047 if (int_size_in_bytes (type) != size)
18049 if (size > TREE_STRING_LENGTH (init))
18051 memcpy (array, TREE_STRING_POINTER (init),
18052 TREE_STRING_LENGTH (init));
18053 memset (array + TREE_STRING_LENGTH (init),
18054 '\0', size - TREE_STRING_LENGTH (init));
18057 memcpy (array, TREE_STRING_POINTER (init), size);
18062 type = TREE_TYPE (init);
18063 if (int_size_in_bytes (type) != size)
18065 if (TREE_CODE (type) == ARRAY_TYPE)
18067 HOST_WIDE_INT min_index;
18068 unsigned HOST_WIDE_INT cnt;
18069 int curpos = 0, fieldsize;
18070 constructor_elt *ce;
18072 if (TYPE_DOMAIN (type) == NULL_TREE
18073 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
18076 fieldsize = int_size_in_bytes (TREE_TYPE (type));
18077 if (fieldsize <= 0)
18080 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
18081 memset (array, '\0', size);
18082 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
18084 tree val = ce->value;
18085 tree index = ce->index;
18087 if (index && TREE_CODE (index) == RANGE_EXPR)
18088 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
18091 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
18096 if (!native_encode_initializer (val, array + pos, fieldsize))
18099 curpos = pos + fieldsize;
18100 if (index && TREE_CODE (index) == RANGE_EXPR)
18102 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
18103 - tree_low_cst (TREE_OPERAND (index, 0), 0);
18104 while (count-- > 0)
18107 memcpy (array + curpos, array + pos, fieldsize);
18108 curpos += fieldsize;
18111 gcc_assert (curpos <= size);
18115 else if (TREE_CODE (type) == RECORD_TYPE
18116 || TREE_CODE (type) == UNION_TYPE)
18118 tree field = NULL_TREE;
18119 unsigned HOST_WIDE_INT cnt;
18120 constructor_elt *ce;
18122 if (int_size_in_bytes (type) != size)
18125 if (TREE_CODE (type) == RECORD_TYPE)
18126 field = TYPE_FIELDS (type);
18128 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
18130 tree val = ce->value;
18131 int pos, fieldsize;
18133 if (ce->index != 0)
18139 if (field == NULL_TREE || DECL_BIT_FIELD (field))
18142 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
18143 && TYPE_DOMAIN (TREE_TYPE (field))
18144 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
18146 else if (DECL_SIZE_UNIT (field) == NULL_TREE
18147 || !host_integerp (DECL_SIZE_UNIT (field), 0))
18149 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
18150 pos = int_byte_position (field);
18151 gcc_assert (pos + fieldsize <= size);
18153 && !native_encode_initializer (val, array + pos, fieldsize))
18159 case VIEW_CONVERT_EXPR:
18160 case NON_LVALUE_EXPR:
18161 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
18163 return native_encode_expr (init, array, size) == size;
18167 /* Attach a DW_AT_const_value attribute to DIE. The value of the
18168 attribute is the const value T. */
18171 tree_add_const_value_attribute (dw_die_ref die, tree t)
18174 tree type = TREE_TYPE (t);
18177 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
18181 gcc_assert (!DECL_P (init));
18183 rtl = rtl_for_decl_init (init, type);
18185 return add_const_value_attribute (die, rtl);
18186 /* If the host and target are sane, try harder. */
18187 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
18188 && initializer_constant_valid_p (init, type))
18190 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
18191 if (size > 0 && (int) size == size)
18193 unsigned char *array = (unsigned char *)
18194 ggc_alloc_cleared_atomic (size);
18196 if (native_encode_initializer (init, array, size))
18198 add_AT_vec (die, DW_AT_const_value, size, 1, array);
18206 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
18207 attribute is the const value of T, where T is an integral constant
18208 variable with static storage duration
18209 (so it can't be a PARM_DECL or a RESULT_DECL). */
18212 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
18216 || (TREE_CODE (decl) != VAR_DECL
18217 && TREE_CODE (decl) != CONST_DECL)
18218 || (TREE_CODE (decl) == VAR_DECL
18219 && !TREE_STATIC (decl)))
18222 if (TREE_READONLY (decl)
18223 && ! TREE_THIS_VOLATILE (decl)
18224 && DECL_INITIAL (decl))
18229 /* Don't add DW_AT_const_value if abstract origin already has one. */
18230 if (get_AT (var_die, DW_AT_const_value))
18233 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
18236 /* Convert the CFI instructions for the current function into a
18237 location list. This is used for DW_AT_frame_base when we targeting
18238 a dwarf2 consumer that does not support the dwarf3
18239 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
18242 static dw_loc_list_ref
18243 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
18247 dw_loc_list_ref list, *list_tail;
18249 dw_cfa_location last_cfa, next_cfa;
18250 const char *start_label, *last_label, *section;
18251 dw_cfa_location remember;
18253 fde = current_fde ();
18254 gcc_assert (fde != NULL);
18256 section = secname_for_decl (current_function_decl);
18260 memset (&next_cfa, 0, sizeof (next_cfa));
18261 next_cfa.reg = INVALID_REGNUM;
18262 remember = next_cfa;
18264 start_label = fde->dw_fde_begin;
18266 /* ??? Bald assumption that the CIE opcode list does not contain
18267 advance opcodes. */
18268 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
18269 lookup_cfa_1 (cfi, &next_cfa, &remember);
18271 last_cfa = next_cfa;
18272 last_label = start_label;
18274 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
18276 /* If the first partition contained no CFI adjustments, the
18277 CIE opcodes apply to the whole first partition. */
18278 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18279 fde->dw_fde_begin, fde->dw_fde_end, section);
18280 list_tail =&(*list_tail)->dw_loc_next;
18281 start_label = last_label = fde->dw_fde_second_begin;
18284 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
18286 switch (cfi->dw_cfi_opc)
18288 case DW_CFA_set_loc:
18289 case DW_CFA_advance_loc1:
18290 case DW_CFA_advance_loc2:
18291 case DW_CFA_advance_loc4:
18292 if (!cfa_equal_p (&last_cfa, &next_cfa))
18294 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18295 start_label, last_label, section);
18297 list_tail = &(*list_tail)->dw_loc_next;
18298 last_cfa = next_cfa;
18299 start_label = last_label;
18301 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
18304 case DW_CFA_advance_loc:
18305 /* The encoding is complex enough that we should never emit this. */
18306 gcc_unreachable ();
18309 lookup_cfa_1 (cfi, &next_cfa, &remember);
18312 if (ix + 1 == fde->dw_fde_switch_cfi_index)
18314 if (!cfa_equal_p (&last_cfa, &next_cfa))
18316 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18317 start_label, last_label, section);
18319 list_tail = &(*list_tail)->dw_loc_next;
18320 last_cfa = next_cfa;
18321 start_label = last_label;
18323 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18324 start_label, fde->dw_fde_end, section);
18325 list_tail = &(*list_tail)->dw_loc_next;
18326 start_label = last_label = fde->dw_fde_second_begin;
18330 if (!cfa_equal_p (&last_cfa, &next_cfa))
18332 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
18333 start_label, last_label, section);
18334 list_tail = &(*list_tail)->dw_loc_next;
18335 start_label = last_label;
18338 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
18340 fde->dw_fde_second_begin
18341 ? fde->dw_fde_second_end : fde->dw_fde_end,
18344 if (list && list->dw_loc_next)
18350 /* Compute a displacement from the "steady-state frame pointer" to the
18351 frame base (often the same as the CFA), and store it in
18352 frame_pointer_fb_offset. OFFSET is added to the displacement
18353 before the latter is negated. */
18356 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
18360 #ifdef FRAME_POINTER_CFA_OFFSET
18361 reg = frame_pointer_rtx;
18362 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
18364 reg = arg_pointer_rtx;
18365 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
18368 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
18369 if (GET_CODE (elim) == PLUS)
18371 offset += INTVAL (XEXP (elim, 1));
18372 elim = XEXP (elim, 0);
18375 frame_pointer_fb_offset = -offset;
18377 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
18378 in which to eliminate. This is because it's stack pointer isn't
18379 directly accessible as a register within the ISA. To work around
18380 this, assume that while we cannot provide a proper value for
18381 frame_pointer_fb_offset, we won't need one either. */
18382 frame_pointer_fb_offset_valid
18383 = ((SUPPORTS_STACK_ALIGNMENT
18384 && (elim == hard_frame_pointer_rtx
18385 || elim == stack_pointer_rtx))
18386 || elim == (frame_pointer_needed
18387 ? hard_frame_pointer_rtx
18388 : stack_pointer_rtx));
18391 /* Generate a DW_AT_name attribute given some string value to be included as
18392 the value of the attribute. */
18395 add_name_attribute (dw_die_ref die, const char *name_string)
18397 if (name_string != NULL && *name_string != 0)
18399 if (demangle_name_func)
18400 name_string = (*demangle_name_func) (name_string);
18402 add_AT_string (die, DW_AT_name, name_string);
18406 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
18407 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
18408 of TYPE accordingly.
18410 ??? This is a temporary measure until after we're able to generate
18411 regular DWARF for the complex Ada type system. */
18414 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
18415 dw_die_ref context_die)
18418 dw_die_ref dtype_die;
18420 if (!lang_hooks.types.descriptive_type)
18423 dtype = lang_hooks.types.descriptive_type (type);
18427 dtype_die = lookup_type_die (dtype);
18430 gen_type_die (dtype, context_die);
18431 dtype_die = lookup_type_die (dtype);
18432 gcc_assert (dtype_die);
18435 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
18438 /* Generate a DW_AT_comp_dir attribute for DIE. */
18441 add_comp_dir_attribute (dw_die_ref die)
18443 const char *wd = get_src_pwd ();
18449 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
18453 wdlen = strlen (wd);
18454 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
18456 wd1 [wdlen] = DIR_SEPARATOR;
18457 wd1 [wdlen + 1] = 0;
18461 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
18464 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
18468 lower_bound_default (void)
18470 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
18475 case DW_LANG_C_plus_plus:
18477 case DW_LANG_ObjC_plus_plus:
18480 case DW_LANG_Fortran77:
18481 case DW_LANG_Fortran90:
18482 case DW_LANG_Fortran95:
18486 case DW_LANG_Python:
18487 return dwarf_version >= 4 ? 0 : -1;
18488 case DW_LANG_Ada95:
18489 case DW_LANG_Ada83:
18490 case DW_LANG_Cobol74:
18491 case DW_LANG_Cobol85:
18492 case DW_LANG_Pascal83:
18493 case DW_LANG_Modula2:
18495 return dwarf_version >= 4 ? 1 : -1;
18501 /* Given a tree node describing an array bound (either lower or upper) output
18502 a representation for that bound. */
18505 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
18507 switch (TREE_CODE (bound))
18512 /* All fixed-bounds are represented by INTEGER_CST nodes. */
18515 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
18518 /* Use the default if possible. */
18519 if (bound_attr == DW_AT_lower_bound
18520 && host_integerp (bound, 0)
18521 && (dflt = lower_bound_default ()) != -1
18522 && tree_low_cst (bound, 0) == dflt)
18525 /* Otherwise represent the bound as an unsigned value with the
18526 precision of its type. The precision and signedness of the
18527 type will be necessary to re-interpret it unambiguously. */
18528 else if (prec < HOST_BITS_PER_WIDE_INT)
18530 unsigned HOST_WIDE_INT mask
18531 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
18532 add_AT_unsigned (subrange_die, bound_attr,
18533 TREE_INT_CST_LOW (bound) & mask);
18535 else if (prec == HOST_BITS_PER_WIDE_INT
18536 || TREE_INT_CST_HIGH (bound) == 0)
18537 add_AT_unsigned (subrange_die, bound_attr,
18538 TREE_INT_CST_LOW (bound));
18540 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
18541 TREE_INT_CST_LOW (bound));
18546 case VIEW_CONVERT_EXPR:
18547 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
18557 dw_die_ref decl_die = lookup_decl_die (bound);
18559 /* ??? Can this happen, or should the variable have been bound
18560 first? Probably it can, since I imagine that we try to create
18561 the types of parameters in the order in which they exist in
18562 the list, and won't have created a forward reference to a
18563 later parameter. */
18564 if (decl_die != NULL)
18566 add_AT_die_ref (subrange_die, bound_attr, decl_die);
18574 /* Otherwise try to create a stack operation procedure to
18575 evaluate the value of the array bound. */
18577 dw_die_ref ctx, decl_die;
18578 dw_loc_list_ref list;
18580 list = loc_list_from_tree (bound, 2);
18581 if (list == NULL || single_element_loc_list_p (list))
18583 /* If DW_AT_*bound is not a reference nor constant, it is
18584 a DWARF expression rather than location description.
18585 For that loc_list_from_tree (bound, 0) is needed.
18586 If that fails to give a single element list,
18587 fall back to outputting this as a reference anyway. */
18588 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
18589 if (list2 && single_element_loc_list_p (list2))
18591 add_AT_loc (subrange_die, bound_attr, list2->expr);
18598 if (current_function_decl == 0)
18599 ctx = comp_unit_die ();
18601 ctx = lookup_decl_die (current_function_decl);
18603 decl_die = new_die (DW_TAG_variable, ctx, bound);
18604 add_AT_flag (decl_die, DW_AT_artificial, 1);
18605 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
18606 add_AT_location_description (decl_die, DW_AT_location, list);
18607 add_AT_die_ref (subrange_die, bound_attr, decl_die);
18613 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
18614 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
18615 Note that the block of subscript information for an array type also
18616 includes information about the element type of the given array type. */
18619 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
18621 unsigned dimension_number;
18623 dw_die_ref subrange_die;
18625 for (dimension_number = 0;
18626 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
18627 type = TREE_TYPE (type), dimension_number++)
18629 tree domain = TYPE_DOMAIN (type);
18631 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
18634 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
18635 and (in GNU C only) variable bounds. Handle all three forms
18637 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
18640 /* We have an array type with specified bounds. */
18641 lower = TYPE_MIN_VALUE (domain);
18642 upper = TYPE_MAX_VALUE (domain);
18644 /* Define the index type. */
18645 if (TREE_TYPE (domain))
18647 /* ??? This is probably an Ada unnamed subrange type. Ignore the
18648 TREE_TYPE field. We can't emit debug info for this
18649 because it is an unnamed integral type. */
18650 if (TREE_CODE (domain) == INTEGER_TYPE
18651 && TYPE_NAME (domain) == NULL_TREE
18652 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
18653 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
18656 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
18660 /* ??? If upper is NULL, the array has unspecified length,
18661 but it does have a lower bound. This happens with Fortran
18663 Since the debugger is definitely going to need to know N
18664 to produce useful results, go ahead and output the lower
18665 bound solo, and hope the debugger can cope. */
18667 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
18669 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
18672 /* Otherwise we have an array type with an unspecified length. The
18673 DWARF-2 spec does not say how to handle this; let's just leave out the
18679 add_byte_size_attribute (dw_die_ref die, tree tree_node)
18683 switch (TREE_CODE (tree_node))
18688 case ENUMERAL_TYPE:
18691 case QUAL_UNION_TYPE:
18692 size = int_size_in_bytes (tree_node);
18695 /* For a data member of a struct or union, the DW_AT_byte_size is
18696 generally given as the number of bytes normally allocated for an
18697 object of the *declared* type of the member itself. This is true
18698 even for bit-fields. */
18699 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
18702 gcc_unreachable ();
18705 /* Note that `size' might be -1 when we get to this point. If it is, that
18706 indicates that the byte size of the entity in question is variable. We
18707 have no good way of expressing this fact in Dwarf at the present time,
18708 so just let the -1 pass on through. */
18709 add_AT_unsigned (die, DW_AT_byte_size, size);
18712 /* For a FIELD_DECL node which represents a bit-field, output an attribute
18713 which specifies the distance in bits from the highest order bit of the
18714 "containing object" for the bit-field to the highest order bit of the
18717 For any given bit-field, the "containing object" is a hypothetical object
18718 (of some integral or enum type) within which the given bit-field lives. The
18719 type of this hypothetical "containing object" is always the same as the
18720 declared type of the individual bit-field itself. The determination of the
18721 exact location of the "containing object" for a bit-field is rather
18722 complicated. It's handled by the `field_byte_offset' function (above).
18724 Note that it is the size (in bytes) of the hypothetical "containing object"
18725 which will be given in the DW_AT_byte_size attribute for this bit-field.
18726 (See `byte_size_attribute' above). */
18729 add_bit_offset_attribute (dw_die_ref die, tree decl)
18731 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
18732 tree type = DECL_BIT_FIELD_TYPE (decl);
18733 HOST_WIDE_INT bitpos_int;
18734 HOST_WIDE_INT highest_order_object_bit_offset;
18735 HOST_WIDE_INT highest_order_field_bit_offset;
18736 HOST_WIDE_INT bit_offset;
18738 /* Must be a field and a bit field. */
18739 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
18741 /* We can't yet handle bit-fields whose offsets are variable, so if we
18742 encounter such things, just return without generating any attribute
18743 whatsoever. Likewise for variable or too large size. */
18744 if (! host_integerp (bit_position (decl), 0)
18745 || ! host_integerp (DECL_SIZE (decl), 1))
18748 bitpos_int = int_bit_position (decl);
18750 /* Note that the bit offset is always the distance (in bits) from the
18751 highest-order bit of the "containing object" to the highest-order bit of
18752 the bit-field itself. Since the "high-order end" of any object or field
18753 is different on big-endian and little-endian machines, the computation
18754 below must take account of these differences. */
18755 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
18756 highest_order_field_bit_offset = bitpos_int;
18758 if (! BYTES_BIG_ENDIAN)
18760 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
18761 highest_order_object_bit_offset += simple_type_size_in_bits (type);
18765 = (! BYTES_BIG_ENDIAN
18766 ? highest_order_object_bit_offset - highest_order_field_bit_offset
18767 : highest_order_field_bit_offset - highest_order_object_bit_offset);
18769 if (bit_offset < 0)
18770 add_AT_int (die, DW_AT_bit_offset, bit_offset);
18772 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
18775 /* For a FIELD_DECL node which represents a bit field, output an attribute
18776 which specifies the length in bits of the given field. */
18779 add_bit_size_attribute (dw_die_ref die, tree decl)
18781 /* Must be a field and a bit field. */
18782 gcc_assert (TREE_CODE (decl) == FIELD_DECL
18783 && DECL_BIT_FIELD_TYPE (decl));
18785 if (host_integerp (DECL_SIZE (decl), 1))
18786 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
18789 /* If the compiled language is ANSI C, then add a 'prototyped'
18790 attribute, if arg types are given for the parameters of a function. */
18793 add_prototyped_attribute (dw_die_ref die, tree func_type)
18795 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
18796 && prototype_p (func_type))
18797 add_AT_flag (die, DW_AT_prototyped, 1);
18800 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
18801 by looking in either the type declaration or object declaration
18804 static inline dw_die_ref
18805 add_abstract_origin_attribute (dw_die_ref die, tree origin)
18807 dw_die_ref origin_die = NULL;
18809 if (TREE_CODE (origin) != FUNCTION_DECL)
18811 /* We may have gotten separated from the block for the inlined
18812 function, if we're in an exception handler or some such; make
18813 sure that the abstract function has been written out.
18815 Doing this for nested functions is wrong, however; functions are
18816 distinct units, and our context might not even be inline. */
18820 fn = TYPE_STUB_DECL (fn);
18822 fn = decl_function_context (fn);
18824 dwarf2out_abstract_function (fn);
18827 if (DECL_P (origin))
18828 origin_die = lookup_decl_die (origin);
18829 else if (TYPE_P (origin))
18830 origin_die = lookup_type_die (origin);
18832 /* XXX: Functions that are never lowered don't always have correct block
18833 trees (in the case of java, they simply have no block tree, in some other
18834 languages). For these functions, there is nothing we can really do to
18835 output correct debug info for inlined functions in all cases. Rather
18836 than die, we'll just produce deficient debug info now, in that we will
18837 have variables without a proper abstract origin. In the future, when all
18838 functions are lowered, we should re-add a gcc_assert (origin_die)
18842 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
18846 /* We do not currently support the pure_virtual attribute. */
18849 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
18851 if (DECL_VINDEX (func_decl))
18853 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18855 if (host_integerp (DECL_VINDEX (func_decl), 0))
18856 add_AT_loc (die, DW_AT_vtable_elem_location,
18857 new_loc_descr (DW_OP_constu,
18858 tree_low_cst (DECL_VINDEX (func_decl), 0),
18861 /* GNU extension: Record what type this method came from originally. */
18862 if (debug_info_level > DINFO_LEVEL_TERSE
18863 && DECL_CONTEXT (func_decl))
18864 add_AT_die_ref (die, DW_AT_containing_type,
18865 lookup_type_die (DECL_CONTEXT (func_decl)));
18869 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
18870 given decl. This used to be a vendor extension until after DWARF 4
18871 standardized it. */
18874 add_linkage_attr (dw_die_ref die, tree decl)
18876 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
18878 /* Mimic what assemble_name_raw does with a leading '*'. */
18879 if (name[0] == '*')
18882 if (dwarf_version >= 4)
18883 add_AT_string (die, DW_AT_linkage_name, name);
18885 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
18888 /* Add source coordinate attributes for the given decl. */
18891 add_src_coords_attributes (dw_die_ref die, tree decl)
18893 expanded_location s;
18895 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
18897 s = expand_location (DECL_SOURCE_LOCATION (decl));
18898 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
18899 add_AT_unsigned (die, DW_AT_decl_line, s.line);
18902 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
18905 add_linkage_name (dw_die_ref die, tree decl)
18907 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
18908 && TREE_PUBLIC (decl)
18909 && !DECL_ABSTRACT (decl)
18910 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
18911 && die->die_tag != DW_TAG_member)
18913 /* Defer until we have an assembler name set. */
18914 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
18916 limbo_die_node *asm_name;
18918 asm_name = ggc_alloc_cleared_limbo_die_node ();
18919 asm_name->die = die;
18920 asm_name->created_for = decl;
18921 asm_name->next = deferred_asm_name;
18922 deferred_asm_name = asm_name;
18924 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
18925 add_linkage_attr (die, decl);
18929 /* Add a DW_AT_name attribute and source coordinate attribute for the
18930 given decl, but only if it actually has a name. */
18933 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
18937 decl_name = DECL_NAME (decl);
18938 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
18940 const char *name = dwarf2_name (decl, 0);
18942 add_name_attribute (die, name);
18943 if (! DECL_ARTIFICIAL (decl))
18944 add_src_coords_attributes (die, decl);
18946 add_linkage_name (die, decl);
18949 #ifdef VMS_DEBUGGING_INFO
18950 /* Get the function's name, as described by its RTL. This may be different
18951 from the DECL_NAME name used in the source file. */
18952 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
18954 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
18955 XEXP (DECL_RTL (decl), 0));
18956 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
18958 #endif /* VMS_DEBUGGING_INFO */
18961 #ifdef VMS_DEBUGGING_INFO
18962 /* Output the debug main pointer die for VMS */
18965 dwarf2out_vms_debug_main_pointer (void)
18967 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18970 /* Allocate the VMS debug main subprogram die. */
18971 die = ggc_alloc_cleared_die_node ();
18972 die->die_tag = DW_TAG_subprogram;
18973 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
18974 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
18975 current_function_funcdef_no);
18976 add_AT_lbl_id (die, DW_AT_entry_pc, label);
18978 /* Make it the first child of comp_unit_die (). */
18979 die->die_parent = comp_unit_die ();
18980 if (comp_unit_die ()->die_child)
18982 die->die_sib = comp_unit_die ()->die_child->die_sib;
18983 comp_unit_die ()->die_child->die_sib = die;
18987 die->die_sib = die;
18988 comp_unit_die ()->die_child = die;
18991 #endif /* VMS_DEBUGGING_INFO */
18993 /* Push a new declaration scope. */
18996 push_decl_scope (tree scope)
18998 VEC_safe_push (tree, gc, decl_scope_table, scope);
19001 /* Pop a declaration scope. */
19004 pop_decl_scope (void)
19006 VEC_pop (tree, decl_scope_table);
19009 /* Return the DIE for the scope that immediately contains this type.
19010 Non-named types get global scope. Named types nested in other
19011 types get their containing scope if it's open, or global scope
19012 otherwise. All other types (i.e. function-local named types) get
19013 the current active scope. */
19016 scope_die_for (tree t, dw_die_ref context_die)
19018 dw_die_ref scope_die = NULL;
19019 tree containing_scope;
19022 /* Non-types always go in the current scope. */
19023 gcc_assert (TYPE_P (t));
19025 containing_scope = TYPE_CONTEXT (t);
19027 /* Use the containing namespace if it was passed in (for a declaration). */
19028 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
19030 if (context_die == lookup_decl_die (containing_scope))
19033 containing_scope = NULL_TREE;
19036 /* Ignore function type "scopes" from the C frontend. They mean that
19037 a tagged type is local to a parmlist of a function declarator, but
19038 that isn't useful to DWARF. */
19039 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
19040 containing_scope = NULL_TREE;
19042 if (SCOPE_FILE_SCOPE_P (containing_scope))
19043 scope_die = comp_unit_die ();
19044 else if (TYPE_P (containing_scope))
19046 /* For types, we can just look up the appropriate DIE. But
19047 first we check to see if we're in the middle of emitting it
19048 so we know where the new DIE should go. */
19049 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
19050 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
19055 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
19056 || TREE_ASM_WRITTEN (containing_scope));
19057 /*We are not in the middle of emitting the type
19058 CONTAINING_SCOPE. Let's see if it's emitted already. */
19059 scope_die = lookup_type_die (containing_scope);
19061 /* If none of the current dies are suitable, we get file scope. */
19062 if (scope_die == NULL)
19063 scope_die = comp_unit_die ();
19066 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
19069 scope_die = context_die;
19074 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
19077 local_scope_p (dw_die_ref context_die)
19079 for (; context_die; context_die = context_die->die_parent)
19080 if (context_die->die_tag == DW_TAG_inlined_subroutine
19081 || context_die->die_tag == DW_TAG_subprogram)
19087 /* Returns nonzero if CONTEXT_DIE is a class. */
19090 class_scope_p (dw_die_ref context_die)
19092 return (context_die
19093 && (context_die->die_tag == DW_TAG_structure_type
19094 || context_die->die_tag == DW_TAG_class_type
19095 || context_die->die_tag == DW_TAG_interface_type
19096 || context_die->die_tag == DW_TAG_union_type));
19099 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
19100 whether or not to treat a DIE in this context as a declaration. */
19103 class_or_namespace_scope_p (dw_die_ref context_die)
19105 return (class_scope_p (context_die)
19106 || (context_die && context_die->die_tag == DW_TAG_namespace));
19109 /* Many forms of DIEs require a "type description" attribute. This
19110 routine locates the proper "type descriptor" die for the type given
19111 by 'type', and adds a DW_AT_type attribute below the given die. */
19114 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
19115 int decl_volatile, dw_die_ref context_die)
19117 enum tree_code code = TREE_CODE (type);
19118 dw_die_ref type_die = NULL;
19120 /* ??? If this type is an unnamed subrange type of an integral, floating-point
19121 or fixed-point type, use the inner type. This is because we have no
19122 support for unnamed types in base_type_die. This can happen if this is
19123 an Ada subrange type. Correct solution is emit a subrange type die. */
19124 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
19125 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
19126 type = TREE_TYPE (type), code = TREE_CODE (type);
19128 if (code == ERROR_MARK
19129 /* Handle a special case. For functions whose return type is void, we
19130 generate *no* type attribute. (Note that no object may have type
19131 `void', so this only applies to function return types). */
19132 || code == VOID_TYPE)
19135 type_die = modified_type_die (type,
19136 decl_const || TYPE_READONLY (type),
19137 decl_volatile || TYPE_VOLATILE (type),
19140 if (type_die != NULL)
19141 add_AT_die_ref (object_die, DW_AT_type, type_die);
19144 /* Given an object die, add the calling convention attribute for the
19145 function call type. */
19147 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
19149 enum dwarf_calling_convention value = DW_CC_normal;
19151 value = ((enum dwarf_calling_convention)
19152 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
19155 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
19157 /* DWARF 2 doesn't provide a way to identify a program's source-level
19158 entry point. DW_AT_calling_convention attributes are only meant
19159 to describe functions' calling conventions. However, lacking a
19160 better way to signal the Fortran main program, we used this for
19161 a long time, following existing custom. Now, DWARF 4 has
19162 DW_AT_main_subprogram, which we add below, but some tools still
19163 rely on the old way, which we thus keep. */
19164 value = DW_CC_program;
19166 if (dwarf_version >= 4 || !dwarf_strict)
19167 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
19170 /* Only add the attribute if the backend requests it, and
19171 is not DW_CC_normal. */
19172 if (value && (value != DW_CC_normal))
19173 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
19176 /* Given a tree pointer to a struct, class, union, or enum type node, return
19177 a pointer to the (string) tag name for the given type, or zero if the type
19178 was declared without a tag. */
19180 static const char *
19181 type_tag (const_tree type)
19183 const char *name = 0;
19185 if (TYPE_NAME (type) != 0)
19189 /* Find the IDENTIFIER_NODE for the type name. */
19190 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
19191 && !TYPE_NAMELESS (type))
19192 t = TYPE_NAME (type);
19194 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
19195 a TYPE_DECL node, regardless of whether or not a `typedef' was
19197 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
19198 && ! DECL_IGNORED_P (TYPE_NAME (type)))
19200 /* We want to be extra verbose. Don't call dwarf_name if
19201 DECL_NAME isn't set. The default hook for decl_printable_name
19202 doesn't like that, and in this context it's correct to return
19203 0, instead of "<anonymous>" or the like. */
19204 if (DECL_NAME (TYPE_NAME (type))
19205 && !DECL_NAMELESS (TYPE_NAME (type)))
19206 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
19209 /* Now get the name as a string, or invent one. */
19210 if (!name && t != 0)
19211 name = IDENTIFIER_POINTER (t);
19214 return (name == 0 || *name == '\0') ? 0 : name;
19217 /* Return the type associated with a data member, make a special check
19218 for bit field types. */
19221 member_declared_type (const_tree member)
19223 return (DECL_BIT_FIELD_TYPE (member)
19224 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
19227 /* Get the decl's label, as described by its RTL. This may be different
19228 from the DECL_NAME name used in the source file. */
19231 static const char *
19232 decl_start_label (tree decl)
19235 const char *fnname;
19237 x = DECL_RTL (decl);
19238 gcc_assert (MEM_P (x));
19241 gcc_assert (GET_CODE (x) == SYMBOL_REF);
19243 fnname = XSTR (x, 0);
19248 /* These routines generate the internal representation of the DIE's for
19249 the compilation unit. Debugging information is collected by walking
19250 the declaration trees passed in from dwarf2out_decl(). */
19253 gen_array_type_die (tree type, dw_die_ref context_die)
19255 dw_die_ref scope_die = scope_die_for (type, context_die);
19256 dw_die_ref array_die;
19258 /* GNU compilers represent multidimensional array types as sequences of one
19259 dimensional array types whose element types are themselves array types.
19260 We sometimes squish that down to a single array_type DIE with multiple
19261 subscripts in the Dwarf debugging info. The draft Dwarf specification
19262 say that we are allowed to do this kind of compression in C, because
19263 there is no difference between an array of arrays and a multidimensional
19264 array. We don't do this for Ada to remain as close as possible to the
19265 actual representation, which is especially important against the language
19266 flexibilty wrt arrays of variable size. */
19268 bool collapse_nested_arrays = !is_ada ();
19271 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
19272 DW_TAG_string_type doesn't have DW_AT_type attribute). */
19273 if (TYPE_STRING_FLAG (type)
19274 && TREE_CODE (type) == ARRAY_TYPE
19276 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
19278 HOST_WIDE_INT size;
19280 array_die = new_die (DW_TAG_string_type, scope_die, type);
19281 add_name_attribute (array_die, type_tag (type));
19282 equate_type_number_to_die (type, array_die);
19283 size = int_size_in_bytes (type);
19285 add_AT_unsigned (array_die, DW_AT_byte_size, size);
19286 else if (TYPE_DOMAIN (type) != NULL_TREE
19287 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
19288 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
19290 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
19291 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
19293 size = int_size_in_bytes (TREE_TYPE (szdecl));
19294 if (loc && size > 0)
19296 add_AT_location_description (array_die, DW_AT_string_length, loc);
19297 if (size != DWARF2_ADDR_SIZE)
19298 add_AT_unsigned (array_die, DW_AT_byte_size, size);
19304 /* ??? The SGI dwarf reader fails for array of array of enum types
19305 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
19306 array type comes before the outer array type. We thus call gen_type_die
19307 before we new_die and must prevent nested array types collapsing for this
19310 #ifdef MIPS_DEBUGGING_INFO
19311 gen_type_die (TREE_TYPE (type), context_die);
19312 collapse_nested_arrays = false;
19315 array_die = new_die (DW_TAG_array_type, scope_die, type);
19316 add_name_attribute (array_die, type_tag (type));
19317 add_gnat_descriptive_type_attribute (array_die, type, context_die);
19318 equate_type_number_to_die (type, array_die);
19320 if (TREE_CODE (type) == VECTOR_TYPE)
19321 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
19323 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19325 && TREE_CODE (type) == ARRAY_TYPE
19326 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
19327 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
19328 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
19331 /* We default the array ordering. SDB will probably do
19332 the right things even if DW_AT_ordering is not present. It's not even
19333 an issue until we start to get into multidimensional arrays anyway. If
19334 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
19335 then we'll have to put the DW_AT_ordering attribute back in. (But if
19336 and when we find out that we need to put these in, we will only do so
19337 for multidimensional arrays. */
19338 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
19341 #ifdef MIPS_DEBUGGING_INFO
19342 /* The SGI compilers handle arrays of unknown bound by setting
19343 AT_declaration and not emitting any subrange DIEs. */
19344 if (TREE_CODE (type) == ARRAY_TYPE
19345 && ! TYPE_DOMAIN (type))
19346 add_AT_flag (array_die, DW_AT_declaration, 1);
19349 if (TREE_CODE (type) == VECTOR_TYPE)
19351 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
19352 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
19353 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
19354 add_bound_info (subrange_die, DW_AT_upper_bound,
19355 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
19358 add_subscript_info (array_die, type, collapse_nested_arrays);
19360 /* Add representation of the type of the elements of this array type and
19361 emit the corresponding DIE if we haven't done it already. */
19362 element_type = TREE_TYPE (type);
19363 if (collapse_nested_arrays)
19364 while (TREE_CODE (element_type) == ARRAY_TYPE)
19366 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
19368 element_type = TREE_TYPE (element_type);
19371 #ifndef MIPS_DEBUGGING_INFO
19372 gen_type_die (element_type, context_die);
19375 add_type_attribute (array_die, element_type, 0, 0, context_die);
19377 if (get_AT (array_die, DW_AT_name))
19378 add_pubtype (type, array_die);
19381 static dw_loc_descr_ref
19382 descr_info_loc (tree val, tree base_decl)
19384 HOST_WIDE_INT size;
19385 dw_loc_descr_ref loc, loc2;
19386 enum dwarf_location_atom op;
19388 if (val == base_decl)
19389 return new_loc_descr (DW_OP_push_object_address, 0, 0);
19391 switch (TREE_CODE (val))
19394 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19396 return loc_descriptor_from_tree (val, 0);
19398 if (host_integerp (val, 0))
19399 return int_loc_descriptor (tree_low_cst (val, 0));
19402 size = int_size_in_bytes (TREE_TYPE (val));
19405 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19408 if (size == DWARF2_ADDR_SIZE)
19409 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
19411 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
19413 case POINTER_PLUS_EXPR:
19415 if (host_integerp (TREE_OPERAND (val, 1), 1)
19416 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
19419 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19422 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
19428 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
19431 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
19434 add_loc_descr (&loc, loc2);
19435 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
19457 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
19458 tree val, tree base_decl)
19460 dw_loc_descr_ref loc;
19462 if (host_integerp (val, 0))
19464 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
19468 loc = descr_info_loc (val, base_decl);
19472 add_AT_loc (die, attr, loc);
19475 /* This routine generates DIE for array with hidden descriptor, details
19476 are filled into *info by a langhook. */
19479 gen_descr_array_type_die (tree type, struct array_descr_info *info,
19480 dw_die_ref context_die)
19482 dw_die_ref scope_die = scope_die_for (type, context_die);
19483 dw_die_ref array_die;
19486 array_die = new_die (DW_TAG_array_type, scope_die, type);
19487 add_name_attribute (array_die, type_tag (type));
19488 equate_type_number_to_die (type, array_die);
19490 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19492 && info->ndimensions >= 2)
19493 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
19495 if (info->data_location)
19496 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
19498 if (info->associated)
19499 add_descr_info_field (array_die, DW_AT_associated, info->associated,
19501 if (info->allocated)
19502 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
19505 for (dim = 0; dim < info->ndimensions; dim++)
19507 dw_die_ref subrange_die
19508 = new_die (DW_TAG_subrange_type, array_die, NULL);
19510 if (info->dimen[dim].lower_bound)
19512 /* If it is the default value, omit it. */
19515 if (host_integerp (info->dimen[dim].lower_bound, 0)
19516 && (dflt = lower_bound_default ()) != -1
19517 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
19520 add_descr_info_field (subrange_die, DW_AT_lower_bound,
19521 info->dimen[dim].lower_bound,
19524 if (info->dimen[dim].upper_bound)
19525 add_descr_info_field (subrange_die, DW_AT_upper_bound,
19526 info->dimen[dim].upper_bound,
19528 if (info->dimen[dim].stride)
19529 add_descr_info_field (subrange_die, DW_AT_byte_stride,
19530 info->dimen[dim].stride,
19534 gen_type_die (info->element_type, context_die);
19535 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
19537 if (get_AT (array_die, DW_AT_name))
19538 add_pubtype (type, array_die);
19543 gen_entry_point_die (tree decl, dw_die_ref context_die)
19545 tree origin = decl_ultimate_origin (decl);
19546 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
19548 if (origin != NULL)
19549 add_abstract_origin_attribute (decl_die, origin);
19552 add_name_and_src_coords_attributes (decl_die, decl);
19553 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
19554 0, 0, context_die);
19557 if (DECL_ABSTRACT (decl))
19558 equate_decl_number_to_die (decl, decl_die);
19560 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
19564 /* Walk through the list of incomplete types again, trying once more to
19565 emit full debugging info for them. */
19568 retry_incomplete_types (void)
19572 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
19573 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
19574 DINFO_USAGE_DIR_USE))
19575 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
19578 /* Determine what tag to use for a record type. */
19580 static enum dwarf_tag
19581 record_type_tag (tree type)
19583 if (! lang_hooks.types.classify_record)
19584 return DW_TAG_structure_type;
19586 switch (lang_hooks.types.classify_record (type))
19588 case RECORD_IS_STRUCT:
19589 return DW_TAG_structure_type;
19591 case RECORD_IS_CLASS:
19592 return DW_TAG_class_type;
19594 case RECORD_IS_INTERFACE:
19595 if (dwarf_version >= 3 || !dwarf_strict)
19596 return DW_TAG_interface_type;
19597 return DW_TAG_structure_type;
19600 gcc_unreachable ();
19604 /* Generate a DIE to represent an enumeration type. Note that these DIEs
19605 include all of the information about the enumeration values also. Each
19606 enumerated type name/value is listed as a child of the enumerated type
19610 gen_enumeration_type_die (tree type, dw_die_ref context_die)
19612 dw_die_ref type_die = lookup_type_die (type);
19614 if (type_die == NULL)
19616 type_die = new_die (DW_TAG_enumeration_type,
19617 scope_die_for (type, context_die), type);
19618 equate_type_number_to_die (type, type_die);
19619 add_name_attribute (type_die, type_tag (type));
19620 add_gnat_descriptive_type_attribute (type_die, type, context_die);
19621 if (dwarf_version >= 4 || !dwarf_strict)
19623 if (ENUM_IS_SCOPED (type))
19624 add_AT_flag (type_die, DW_AT_enum_class, 1);
19625 if (ENUM_IS_OPAQUE (type))
19626 add_AT_flag (type_die, DW_AT_declaration, 1);
19629 else if (! TYPE_SIZE (type))
19632 remove_AT (type_die, DW_AT_declaration);
19634 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
19635 given enum type is incomplete, do not generate the DW_AT_byte_size
19636 attribute or the DW_AT_element_list attribute. */
19637 if (TYPE_SIZE (type))
19641 TREE_ASM_WRITTEN (type) = 1;
19642 add_byte_size_attribute (type_die, type);
19643 if (TYPE_STUB_DECL (type) != NULL_TREE)
19645 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
19646 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
19649 /* If the first reference to this type was as the return type of an
19650 inline function, then it may not have a parent. Fix this now. */
19651 if (type_die->die_parent == NULL)
19652 add_child_die (scope_die_for (type, context_die), type_die);
19654 for (link = TYPE_VALUES (type);
19655 link != NULL; link = TREE_CHAIN (link))
19657 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
19658 tree value = TREE_VALUE (link);
19660 add_name_attribute (enum_die,
19661 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
19663 if (TREE_CODE (value) == CONST_DECL)
19664 value = DECL_INITIAL (value);
19666 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
19667 /* DWARF2 does not provide a way of indicating whether or
19668 not enumeration constants are signed or unsigned. GDB
19669 always assumes the values are signed, so we output all
19670 values as if they were signed. That means that
19671 enumeration constants with very large unsigned values
19672 will appear to have negative values in the debugger. */
19673 add_AT_int (enum_die, DW_AT_const_value,
19674 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
19678 add_AT_flag (type_die, DW_AT_declaration, 1);
19680 if (get_AT (type_die, DW_AT_name))
19681 add_pubtype (type, type_die);
19686 /* Generate a DIE to represent either a real live formal parameter decl or to
19687 represent just the type of some formal parameter position in some function
19690 Note that this routine is a bit unusual because its argument may be a
19691 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
19692 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
19693 node. If it's the former then this function is being called to output a
19694 DIE to represent a formal parameter object (or some inlining thereof). If
19695 it's the latter, then this function is only being called to output a
19696 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
19697 argument type of some subprogram type.
19698 If EMIT_NAME_P is true, name and source coordinate attributes
19702 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
19703 dw_die_ref context_die)
19705 tree node_or_origin = node ? node : origin;
19706 tree ultimate_origin;
19707 dw_die_ref parm_die
19708 = new_die (DW_TAG_formal_parameter, context_die, node);
19710 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
19712 case tcc_declaration:
19713 ultimate_origin = decl_ultimate_origin (node_or_origin);
19714 if (node || ultimate_origin)
19715 origin = ultimate_origin;
19716 if (origin != NULL)
19717 add_abstract_origin_attribute (parm_die, origin);
19718 else if (emit_name_p)
19719 add_name_and_src_coords_attributes (parm_die, node);
19721 || (! DECL_ABSTRACT (node_or_origin)
19722 && variably_modified_type_p (TREE_TYPE (node_or_origin),
19723 decl_function_context
19724 (node_or_origin))))
19726 tree type = TREE_TYPE (node_or_origin);
19727 if (decl_by_reference_p (node_or_origin))
19728 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
19731 add_type_attribute (parm_die, type,
19732 TREE_READONLY (node_or_origin),
19733 TREE_THIS_VOLATILE (node_or_origin),
19736 if (origin == NULL && DECL_ARTIFICIAL (node))
19737 add_AT_flag (parm_die, DW_AT_artificial, 1);
19739 if (node && node != origin)
19740 equate_decl_number_to_die (node, parm_die);
19741 if (! DECL_ABSTRACT (node_or_origin))
19742 add_location_or_const_value_attribute (parm_die, node_or_origin,
19743 node == NULL, DW_AT_location);
19748 /* We were called with some kind of a ..._TYPE node. */
19749 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
19753 gcc_unreachable ();
19759 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
19760 children DW_TAG_formal_parameter DIEs representing the arguments of the
19763 PARM_PACK must be a function parameter pack.
19764 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
19765 must point to the subsequent arguments of the function PACK_ARG belongs to.
19766 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
19767 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
19768 following the last one for which a DIE was generated. */
19771 gen_formal_parameter_pack_die (tree parm_pack,
19773 dw_die_ref subr_die,
19777 dw_die_ref parm_pack_die;
19779 gcc_assert (parm_pack
19780 && lang_hooks.function_parameter_pack_p (parm_pack)
19783 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
19784 add_src_coords_attributes (parm_pack_die, parm_pack);
19786 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
19788 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
19791 gen_formal_parameter_die (arg, NULL,
19792 false /* Don't emit name attribute. */,
19797 return parm_pack_die;
19800 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
19801 at the end of an (ANSI prototyped) formal parameters list. */
19804 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
19806 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
19809 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
19810 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
19811 parameters as specified in some function type specification (except for
19812 those which appear as part of a function *definition*). */
19815 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
19818 tree formal_type = NULL;
19819 tree first_parm_type;
19822 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
19824 arg = DECL_ARGUMENTS (function_or_method_type);
19825 function_or_method_type = TREE_TYPE (function_or_method_type);
19830 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
19832 /* Make our first pass over the list of formal parameter types and output a
19833 DW_TAG_formal_parameter DIE for each one. */
19834 for (link = first_parm_type; link; )
19836 dw_die_ref parm_die;
19838 formal_type = TREE_VALUE (link);
19839 if (formal_type == void_type_node)
19842 /* Output a (nameless) DIE to represent the formal parameter itself. */
19843 parm_die = gen_formal_parameter_die (formal_type, NULL,
19844 true /* Emit name attribute. */,
19846 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
19847 && link == first_parm_type)
19849 add_AT_flag (parm_die, DW_AT_artificial, 1);
19850 if (dwarf_version >= 3 || !dwarf_strict)
19851 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
19853 else if (arg && DECL_ARTIFICIAL (arg))
19854 add_AT_flag (parm_die, DW_AT_artificial, 1);
19856 link = TREE_CHAIN (link);
19858 arg = DECL_CHAIN (arg);
19861 /* If this function type has an ellipsis, add a
19862 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
19863 if (formal_type != void_type_node)
19864 gen_unspecified_parameters_die (function_or_method_type, context_die);
19866 /* Make our second (and final) pass over the list of formal parameter types
19867 and output DIEs to represent those types (as necessary). */
19868 for (link = TYPE_ARG_TYPES (function_or_method_type);
19869 link && TREE_VALUE (link);
19870 link = TREE_CHAIN (link))
19871 gen_type_die (TREE_VALUE (link), context_die);
19874 /* We want to generate the DIE for TYPE so that we can generate the
19875 die for MEMBER, which has been defined; we will need to refer back
19876 to the member declaration nested within TYPE. If we're trying to
19877 generate minimal debug info for TYPE, processing TYPE won't do the
19878 trick; we need to attach the member declaration by hand. */
19881 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
19883 gen_type_die (type, context_die);
19885 /* If we're trying to avoid duplicate debug info, we may not have
19886 emitted the member decl for this function. Emit it now. */
19887 if (TYPE_STUB_DECL (type)
19888 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
19889 && ! lookup_decl_die (member))
19891 dw_die_ref type_die;
19892 gcc_assert (!decl_ultimate_origin (member));
19894 push_decl_scope (type);
19895 type_die = lookup_type_die_strip_naming_typedef (type);
19896 if (TREE_CODE (member) == FUNCTION_DECL)
19897 gen_subprogram_die (member, type_die);
19898 else if (TREE_CODE (member) == FIELD_DECL)
19900 /* Ignore the nameless fields that are used to skip bits but handle
19901 C++ anonymous unions and structs. */
19902 if (DECL_NAME (member) != NULL_TREE
19903 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
19904 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
19906 gen_type_die (member_declared_type (member), type_die);
19907 gen_field_die (member, type_die);
19911 gen_variable_die (member, NULL_TREE, type_die);
19917 /* Generate the DWARF2 info for the "abstract" instance of a function which we
19918 may later generate inlined and/or out-of-line instances of. */
19921 dwarf2out_abstract_function (tree decl)
19923 dw_die_ref old_die;
19927 htab_t old_decl_loc_table;
19928 htab_t old_cached_dw_loc_list_table;
19929 int old_call_site_count, old_tail_call_site_count;
19930 struct call_arg_loc_node *old_call_arg_locations;
19932 /* Make sure we have the actual abstract inline, not a clone. */
19933 decl = DECL_ORIGIN (decl);
19935 old_die = lookup_decl_die (decl);
19936 if (old_die && get_AT (old_die, DW_AT_inline))
19937 /* We've already generated the abstract instance. */
19940 /* We can be called while recursively when seeing block defining inlined subroutine
19941 DIE. Be sure to not clobber the outer location table nor use it or we would
19942 get locations in abstract instantces. */
19943 old_decl_loc_table = decl_loc_table;
19944 decl_loc_table = NULL;
19945 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
19946 cached_dw_loc_list_table = NULL;
19947 old_call_arg_locations = call_arg_locations;
19948 call_arg_locations = NULL;
19949 old_call_site_count = call_site_count;
19950 call_site_count = -1;
19951 old_tail_call_site_count = tail_call_site_count;
19952 tail_call_site_count = -1;
19954 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
19955 we don't get confused by DECL_ABSTRACT. */
19956 if (debug_info_level > DINFO_LEVEL_TERSE)
19958 context = decl_class_context (decl);
19960 gen_type_die_for_member
19961 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
19964 /* Pretend we've just finished compiling this function. */
19965 save_fn = current_function_decl;
19966 current_function_decl = decl;
19967 push_cfun (DECL_STRUCT_FUNCTION (decl));
19969 was_abstract = DECL_ABSTRACT (decl);
19970 set_decl_abstract_flags (decl, 1);
19971 dwarf2out_decl (decl);
19972 if (! was_abstract)
19973 set_decl_abstract_flags (decl, 0);
19975 current_function_decl = save_fn;
19976 decl_loc_table = old_decl_loc_table;
19977 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
19978 call_arg_locations = old_call_arg_locations;
19979 call_site_count = old_call_site_count;
19980 tail_call_site_count = old_tail_call_site_count;
19984 /* Helper function of premark_used_types() which gets called through
19987 Marks the DIE of a given type in *SLOT as perennial, so it never gets
19988 marked as unused by prune_unused_types. */
19991 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
19996 type = (tree) *slot;
19997 die = lookup_type_die (type);
19999 die->die_perennial_p = 1;
20003 /* Helper function of premark_types_used_by_global_vars which gets called
20004 through htab_traverse.
20006 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20007 marked as unused by prune_unused_types. The DIE of the type is marked
20008 only if the global variable using the type will actually be emitted. */
20011 premark_types_used_by_global_vars_helper (void **slot,
20012 void *data ATTRIBUTE_UNUSED)
20014 struct types_used_by_vars_entry *entry;
20017 entry = (struct types_used_by_vars_entry *) *slot;
20018 gcc_assert (entry->type != NULL
20019 && entry->var_decl != NULL);
20020 die = lookup_type_die (entry->type);
20023 /* Ask cgraph if the global variable really is to be emitted.
20024 If yes, then we'll keep the DIE of ENTRY->TYPE. */
20025 struct varpool_node *node = varpool_get_node (entry->var_decl);
20026 if (node && node->needed)
20028 die->die_perennial_p = 1;
20029 /* Keep the parent DIEs as well. */
20030 while ((die = die->die_parent) && die->die_perennial_p == 0)
20031 die->die_perennial_p = 1;
20037 /* Mark all members of used_types_hash as perennial. */
20040 premark_used_types (void)
20042 if (cfun && cfun->used_types_hash)
20043 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
20046 /* Mark all members of types_used_by_vars_entry as perennial. */
20049 premark_types_used_by_global_vars (void)
20051 if (types_used_by_vars_hash)
20052 htab_traverse (types_used_by_vars_hash,
20053 premark_types_used_by_global_vars_helper, NULL);
20056 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
20057 for CA_LOC call arg loc node. */
20060 gen_call_site_die (tree decl, dw_die_ref subr_die,
20061 struct call_arg_loc_node *ca_loc)
20063 dw_die_ref stmt_die = NULL, die;
20064 tree block = ca_loc->block;
20067 && block != DECL_INITIAL (decl)
20068 && TREE_CODE (block) == BLOCK)
20070 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
20071 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
20074 block = BLOCK_SUPERCONTEXT (block);
20076 if (stmt_die == NULL)
20077 stmt_die = subr_die;
20078 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
20079 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
20080 if (ca_loc->tail_call_p)
20081 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
20082 if (ca_loc->symbol_ref)
20084 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
20086 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
20088 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
20093 /* Generate a DIE to represent a declared function (either file-scope or
20097 gen_subprogram_die (tree decl, dw_die_ref context_die)
20099 tree origin = decl_ultimate_origin (decl);
20100 dw_die_ref subr_die;
20102 dw_die_ref old_die = lookup_decl_die (decl);
20103 int declaration = (current_function_decl != decl
20104 || class_or_namespace_scope_p (context_die));
20106 premark_used_types ();
20108 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
20109 started to generate the abstract instance of an inline, decided to output
20110 its containing class, and proceeded to emit the declaration of the inline
20111 from the member list for the class. If so, DECLARATION takes priority;
20112 we'll get back to the abstract instance when done with the class. */
20114 /* The class-scope declaration DIE must be the primary DIE. */
20115 if (origin && declaration && class_or_namespace_scope_p (context_die))
20118 gcc_assert (!old_die);
20121 /* Now that the C++ front end lazily declares artificial member fns, we
20122 might need to retrofit the declaration into its class. */
20123 if (!declaration && !origin && !old_die
20124 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
20125 && !class_or_namespace_scope_p (context_die)
20126 && debug_info_level > DINFO_LEVEL_TERSE)
20127 old_die = force_decl_die (decl);
20129 if (origin != NULL)
20131 gcc_assert (!declaration || local_scope_p (context_die));
20133 /* Fixup die_parent for the abstract instance of a nested
20134 inline function. */
20135 if (old_die && old_die->die_parent == NULL)
20136 add_child_die (context_die, old_die);
20138 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20139 add_abstract_origin_attribute (subr_die, origin);
20140 /* This is where the actual code for a cloned function is.
20141 Let's emit linkage name attribute for it. This helps
20142 debuggers to e.g, set breakpoints into
20143 constructors/destructors when the user asks "break
20145 add_linkage_name (subr_die, decl);
20149 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
20150 struct dwarf_file_data * file_index = lookup_filename (s.file);
20152 if (!get_AT_flag (old_die, DW_AT_declaration)
20153 /* We can have a normal definition following an inline one in the
20154 case of redefinition of GNU C extern inlines.
20155 It seems reasonable to use AT_specification in this case. */
20156 && !get_AT (old_die, DW_AT_inline))
20158 /* Detect and ignore this case, where we are trying to output
20159 something we have already output. */
20163 /* If the definition comes from the same place as the declaration,
20164 maybe use the old DIE. We always want the DIE for this function
20165 that has the *_pc attributes to be under comp_unit_die so the
20166 debugger can find it. We also need to do this for abstract
20167 instances of inlines, since the spec requires the out-of-line copy
20168 to have the same parent. For local class methods, this doesn't
20169 apply; we just use the old DIE. */
20170 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
20171 && (DECL_ARTIFICIAL (decl)
20172 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
20173 && (get_AT_unsigned (old_die, DW_AT_decl_line)
20174 == (unsigned) s.line))))
20176 subr_die = old_die;
20178 /* Clear out the declaration attribute and the formal parameters.
20179 Do not remove all children, because it is possible that this
20180 declaration die was forced using force_decl_die(). In such
20181 cases die that forced declaration die (e.g. TAG_imported_module)
20182 is one of the children that we do not want to remove. */
20183 remove_AT (subr_die, DW_AT_declaration);
20184 remove_AT (subr_die, DW_AT_object_pointer);
20185 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
20189 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20190 add_AT_specification (subr_die, old_die);
20191 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
20192 add_AT_file (subr_die, DW_AT_decl_file, file_index);
20193 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
20194 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
20199 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
20201 if (TREE_PUBLIC (decl))
20202 add_AT_flag (subr_die, DW_AT_external, 1);
20204 add_name_and_src_coords_attributes (subr_die, decl);
20205 if (debug_info_level > DINFO_LEVEL_TERSE)
20207 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
20208 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
20209 0, 0, context_die);
20212 add_pure_or_virtual_attribute (subr_die, decl);
20213 if (DECL_ARTIFICIAL (decl))
20214 add_AT_flag (subr_die, DW_AT_artificial, 1);
20216 add_accessibility_attribute (subr_die, decl);
20221 if (!old_die || !get_AT (old_die, DW_AT_inline))
20223 add_AT_flag (subr_die, DW_AT_declaration, 1);
20225 /* If this is an explicit function declaration then generate
20226 a DW_AT_explicit attribute. */
20227 if (lang_hooks.decls.function_decl_explicit_p (decl)
20228 && (dwarf_version >= 3 || !dwarf_strict))
20229 add_AT_flag (subr_die, DW_AT_explicit, 1);
20231 /* The first time we see a member function, it is in the context of
20232 the class to which it belongs. We make sure of this by emitting
20233 the class first. The next time is the definition, which is
20234 handled above. The two may come from the same source text.
20236 Note that force_decl_die() forces function declaration die. It is
20237 later reused to represent definition. */
20238 equate_decl_number_to_die (decl, subr_die);
20241 else if (DECL_ABSTRACT (decl))
20243 if (DECL_DECLARED_INLINE_P (decl))
20245 if (cgraph_function_possibly_inlined_p (decl))
20246 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
20248 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
20252 if (cgraph_function_possibly_inlined_p (decl))
20253 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
20255 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
20258 if (DECL_DECLARED_INLINE_P (decl)
20259 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
20260 add_AT_flag (subr_die, DW_AT_artificial, 1);
20262 equate_decl_number_to_die (decl, subr_die);
20264 else if (!DECL_EXTERNAL (decl))
20266 HOST_WIDE_INT cfa_fb_offset;
20268 if (!old_die || !get_AT (old_die, DW_AT_inline))
20269 equate_decl_number_to_die (decl, subr_die);
20271 if (!flag_reorder_blocks_and_partition)
20273 dw_fde_ref fde = &fde_table[current_funcdef_fde];
20274 if (fde->dw_fde_begin)
20276 /* We have already generated the labels. */
20277 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
20278 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
20282 /* Create start/end labels and add the range. */
20283 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
20284 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
20285 current_function_funcdef_no);
20286 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
20287 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
20288 current_function_funcdef_no);
20289 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
20292 #if VMS_DEBUGGING_INFO
20293 /* HP OpenVMS Industry Standard 64: DWARF Extensions
20294 Section 2.3 Prologue and Epilogue Attributes:
20295 When a breakpoint is set on entry to a function, it is generally
20296 desirable for execution to be suspended, not on the very first
20297 instruction of the function, but rather at a point after the
20298 function's frame has been set up, after any language defined local
20299 declaration processing has been completed, and before execution of
20300 the first statement of the function begins. Debuggers generally
20301 cannot properly determine where this point is. Similarly for a
20302 breakpoint set on exit from a function. The prologue and epilogue
20303 attributes allow a compiler to communicate the location(s) to use. */
20306 if (fde->dw_fde_vms_end_prologue)
20307 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
20308 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
20310 if (fde->dw_fde_vms_begin_epilogue)
20311 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
20312 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
20316 add_pubname (decl, subr_die);
20319 { /* Generate pubnames entries for the split function code
20321 dw_fde_ref fde = &fde_table[current_funcdef_fde];
20323 if (fde->dw_fde_second_begin)
20325 if (dwarf_version >= 3 || !dwarf_strict)
20327 /* We should use ranges for non-contiguous code section
20328 addresses. Use the actual code range for the initial
20329 section, since the HOT/COLD labels might precede an
20330 alignment offset. */
20331 bool range_list_added = false;
20332 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
20333 fde->dw_fde_end, &range_list_added);
20334 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
20335 fde->dw_fde_second_end,
20336 &range_list_added);
20337 add_pubname (decl, subr_die);
20338 if (range_list_added)
20343 /* There is no real support in DW2 for this .. so we make
20344 a work-around. First, emit the pub name for the segment
20345 containing the function label. Then make and emit a
20346 simplified subprogram DIE for the second segment with the
20347 name pre-fixed by __hot/cold_sect_of_. We use the same
20348 linkage name for the second die so that gdb will find both
20349 sections when given "b foo". */
20350 const char *name = NULL;
20351 tree decl_name = DECL_NAME (decl);
20352 dw_die_ref seg_die;
20354 /* Do the 'primary' section. */
20355 add_AT_lbl_id (subr_die, DW_AT_low_pc,
20356 fde->dw_fde_begin);
20357 add_AT_lbl_id (subr_die, DW_AT_high_pc,
20360 add_pubname (decl, subr_die);
20362 /* Build a minimal DIE for the secondary section. */
20363 seg_die = new_die (DW_TAG_subprogram,
20364 subr_die->die_parent, decl);
20366 if (TREE_PUBLIC (decl))
20367 add_AT_flag (seg_die, DW_AT_external, 1);
20369 if (decl_name != NULL
20370 && IDENTIFIER_POINTER (decl_name) != NULL)
20372 name = dwarf2_name (decl, 1);
20373 if (! DECL_ARTIFICIAL (decl))
20374 add_src_coords_attributes (seg_die, decl);
20376 add_linkage_name (seg_die, decl);
20378 gcc_assert (name != NULL);
20379 add_pure_or_virtual_attribute (seg_die, decl);
20380 if (DECL_ARTIFICIAL (decl))
20381 add_AT_flag (seg_die, DW_AT_artificial, 1);
20383 name = concat ("__second_sect_of_", name, NULL);
20384 add_AT_lbl_id (seg_die, DW_AT_low_pc,
20385 fde->dw_fde_second_begin);
20386 add_AT_lbl_id (seg_die, DW_AT_high_pc,
20387 fde->dw_fde_second_end);
20388 add_name_attribute (seg_die, name);
20389 add_pubname_string (name, seg_die);
20394 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
20395 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
20396 add_pubname (decl, subr_die);
20400 #ifdef MIPS_DEBUGGING_INFO
20401 /* Add a reference to the FDE for this routine. */
20402 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
20405 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
20407 /* We define the "frame base" as the function's CFA. This is more
20408 convenient for several reasons: (1) It's stable across the prologue
20409 and epilogue, which makes it better than just a frame pointer,
20410 (2) With dwarf3, there exists a one-byte encoding that allows us
20411 to reference the .debug_frame data by proxy, but failing that,
20412 (3) We can at least reuse the code inspection and interpretation
20413 code that determines the CFA position at various points in the
20415 if (dwarf_version >= 3)
20417 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
20418 add_AT_loc (subr_die, DW_AT_frame_base, op);
20422 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
20423 if (list->dw_loc_next)
20424 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
20426 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
20429 /* Compute a displacement from the "steady-state frame pointer" to
20430 the CFA. The former is what all stack slots and argument slots
20431 will reference in the rtl; the later is what we've told the
20432 debugger about. We'll need to adjust all frame_base references
20433 by this displacement. */
20434 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
20436 if (cfun->static_chain_decl)
20437 add_AT_location_description (subr_die, DW_AT_static_link,
20438 loc_list_from_tree (cfun->static_chain_decl, 2));
20441 /* Generate child dies for template paramaters. */
20442 if (debug_info_level > DINFO_LEVEL_TERSE)
20443 gen_generic_params_dies (decl);
20445 /* Now output descriptions of the arguments for this function. This gets
20446 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
20447 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
20448 `...' at the end of the formal parameter list. In order to find out if
20449 there was a trailing ellipsis or not, we must instead look at the type
20450 associated with the FUNCTION_DECL. This will be a node of type
20451 FUNCTION_TYPE. If the chain of type nodes hanging off of this
20452 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
20453 an ellipsis at the end. */
20455 /* In the case where we are describing a mere function declaration, all we
20456 need to do here (and all we *can* do here) is to describe the *types* of
20457 its formal parameters. */
20458 if (debug_info_level <= DINFO_LEVEL_TERSE)
20460 else if (declaration)
20461 gen_formal_types_die (decl, subr_die);
20464 /* Generate DIEs to represent all known formal parameters. */
20465 tree parm = DECL_ARGUMENTS (decl);
20466 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
20467 tree generic_decl_parm = generic_decl
20468 ? DECL_ARGUMENTS (generic_decl)
20471 /* Now we want to walk the list of parameters of the function and
20472 emit their relevant DIEs.
20474 We consider the case of DECL being an instance of a generic function
20475 as well as it being a normal function.
20477 If DECL is an instance of a generic function we walk the
20478 parameters of the generic function declaration _and_ the parameters of
20479 DECL itself. This is useful because we want to emit specific DIEs for
20480 function parameter packs and those are declared as part of the
20481 generic function declaration. In that particular case,
20482 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
20483 That DIE has children DIEs representing the set of arguments
20484 of the pack. Note that the set of pack arguments can be empty.
20485 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
20488 Otherwise, we just consider the parameters of DECL. */
20489 while (generic_decl_parm || parm)
20491 if (generic_decl_parm
20492 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
20493 gen_formal_parameter_pack_die (generic_decl_parm,
20498 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
20500 if (parm == DECL_ARGUMENTS (decl)
20501 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
20503 && (dwarf_version >= 3 || !dwarf_strict))
20504 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
20506 parm = DECL_CHAIN (parm);
20509 if (generic_decl_parm)
20510 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
20513 /* Decide whether we need an unspecified_parameters DIE at the end.
20514 There are 2 more cases to do this for: 1) the ansi ... declaration -
20515 this is detectable when the end of the arg list is not a
20516 void_type_node 2) an unprototyped function declaration (not a
20517 definition). This just means that we have no info about the
20518 parameters at all. */
20519 if (prototype_p (TREE_TYPE (decl)))
20521 /* This is the prototyped case, check for.... */
20522 if (stdarg_p (TREE_TYPE (decl)))
20523 gen_unspecified_parameters_die (decl, subr_die);
20525 else if (DECL_INITIAL (decl) == NULL_TREE)
20526 gen_unspecified_parameters_die (decl, subr_die);
20529 /* Output Dwarf info for all of the stuff within the body of the function
20530 (if it has one - it may be just a declaration). */
20531 outer_scope = DECL_INITIAL (decl);
20533 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
20534 a function. This BLOCK actually represents the outermost binding contour
20535 for the function, i.e. the contour in which the function's formal
20536 parameters and labels get declared. Curiously, it appears that the front
20537 end doesn't actually put the PARM_DECL nodes for the current function onto
20538 the BLOCK_VARS list for this outer scope, but are strung off of the
20539 DECL_ARGUMENTS list for the function instead.
20541 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
20542 the LABEL_DECL nodes for the function however, and we output DWARF info
20543 for those in decls_for_scope. Just within the `outer_scope' there will be
20544 a BLOCK node representing the function's outermost pair of curly braces,
20545 and any blocks used for the base and member initializers of a C++
20546 constructor function. */
20547 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
20549 int call_site_note_count = 0;
20550 int tail_call_site_note_count = 0;
20552 /* Emit a DW_TAG_variable DIE for a named return value. */
20553 if (DECL_NAME (DECL_RESULT (decl)))
20554 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
20556 current_function_has_inlines = 0;
20557 decls_for_scope (outer_scope, subr_die, 0);
20559 if (call_arg_locations && !dwarf_strict)
20561 struct call_arg_loc_node *ca_loc;
20562 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
20564 dw_die_ref die = NULL;
20565 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
20568 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
20569 arg; arg = next_arg)
20571 dw_loc_descr_ref reg, val;
20572 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
20575 next_arg = XEXP (arg, 1);
20576 if (REG_P (XEXP (XEXP (arg, 0), 0))
20578 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
20579 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
20580 && REGNO (XEXP (XEXP (arg, 0), 0))
20581 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
20582 next_arg = XEXP (next_arg, 1);
20583 if (mode == VOIDmode)
20585 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
20586 if (mode == VOIDmode)
20587 mode = GET_MODE (XEXP (arg, 0));
20589 if (mode == VOIDmode || mode == BLKmode)
20591 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
20593 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
20594 tloc = XEXP (XEXP (arg, 0), 1);
20597 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
20598 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
20600 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
20601 tlocc = XEXP (XEXP (arg, 0), 1);
20604 if (REG_P (XEXP (XEXP (arg, 0), 0)))
20605 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
20606 VAR_INIT_STATUS_INITIALIZED);
20607 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
20609 rtx mem = XEXP (XEXP (arg, 0), 0);
20610 reg = mem_loc_descriptor (XEXP (mem, 0),
20611 get_address_mode (mem),
20613 VAR_INIT_STATUS_INITIALIZED);
20619 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
20621 VAR_INIT_STATUS_INITIALIZED);
20625 die = gen_call_site_die (decl, subr_die, ca_loc);
20626 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
20628 add_AT_loc (cdie, DW_AT_location, reg);
20629 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
20630 if (next_arg != XEXP (arg, 1))
20632 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
20633 if (mode == VOIDmode)
20634 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
20635 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
20638 VAR_INIT_STATUS_INITIALIZED);
20640 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
20644 && (ca_loc->symbol_ref || tloc))
20645 die = gen_call_site_die (decl, subr_die, ca_loc);
20646 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
20648 dw_loc_descr_ref tval = NULL;
20650 if (tloc != NULL_RTX)
20651 tval = mem_loc_descriptor (tloc,
20652 GET_MODE (tloc) == VOIDmode
20653 ? Pmode : GET_MODE (tloc),
20655 VAR_INIT_STATUS_INITIALIZED);
20657 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
20658 else if (tlocc != NULL_RTX)
20660 tval = mem_loc_descriptor (tlocc,
20661 GET_MODE (tlocc) == VOIDmode
20662 ? Pmode : GET_MODE (tlocc),
20664 VAR_INIT_STATUS_INITIALIZED);
20666 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
20672 call_site_note_count++;
20673 if (ca_loc->tail_call_p)
20674 tail_call_site_note_count++;
20678 call_arg_locations = NULL;
20679 call_arg_loc_last = NULL;
20680 if (tail_call_site_count >= 0
20681 && tail_call_site_count == tail_call_site_note_count
20684 if (call_site_count >= 0
20685 && call_site_count == call_site_note_count)
20686 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
20688 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
20690 call_site_count = -1;
20691 tail_call_site_count = -1;
20693 /* Add the calling convention attribute if requested. */
20694 add_calling_convention_attribute (subr_die, decl);
20698 /* Returns a hash value for X (which really is a die_struct). */
20701 common_block_die_table_hash (const void *x)
20703 const_dw_die_ref d = (const_dw_die_ref) x;
20704 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
20707 /* Return nonzero if decl_id and die_parent of die_struct X is the same
20708 as decl_id and die_parent of die_struct Y. */
20711 common_block_die_table_eq (const void *x, const void *y)
20713 const_dw_die_ref d = (const_dw_die_ref) x;
20714 const_dw_die_ref e = (const_dw_die_ref) y;
20715 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
20718 /* Generate a DIE to represent a declared data object.
20719 Either DECL or ORIGIN must be non-null. */
20722 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
20726 tree decl_or_origin = decl ? decl : origin;
20727 tree ultimate_origin;
20728 dw_die_ref var_die;
20729 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
20730 dw_die_ref origin_die;
20731 bool declaration = (DECL_EXTERNAL (decl_or_origin)
20732 || class_or_namespace_scope_p (context_die));
20733 bool specialization_p = false;
20735 ultimate_origin = decl_ultimate_origin (decl_or_origin);
20736 if (decl || ultimate_origin)
20737 origin = ultimate_origin;
20738 com_decl = fortran_common (decl_or_origin, &off);
20740 /* Symbol in common gets emitted as a child of the common block, in the form
20741 of a data member. */
20744 dw_die_ref com_die;
20745 dw_loc_list_ref loc;
20746 die_node com_die_arg;
20748 var_die = lookup_decl_die (decl_or_origin);
20751 if (get_AT (var_die, DW_AT_location) == NULL)
20753 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
20758 /* Optimize the common case. */
20759 if (single_element_loc_list_p (loc)
20760 && loc->expr->dw_loc_opc == DW_OP_addr
20761 && loc->expr->dw_loc_next == NULL
20762 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
20764 loc->expr->dw_loc_oprnd1.v.val_addr
20765 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
20767 loc_list_plus_const (loc, off);
20769 add_AT_location_description (var_die, DW_AT_location, loc);
20770 remove_AT (var_die, DW_AT_declaration);
20776 if (common_block_die_table == NULL)
20777 common_block_die_table
20778 = htab_create_ggc (10, common_block_die_table_hash,
20779 common_block_die_table_eq, NULL);
20781 com_die_arg.decl_id = DECL_UID (com_decl);
20782 com_die_arg.die_parent = context_die;
20783 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
20784 loc = loc_list_from_tree (com_decl, 2);
20785 if (com_die == NULL)
20788 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
20791 com_die = new_die (DW_TAG_common_block, context_die, decl);
20792 add_name_and_src_coords_attributes (com_die, com_decl);
20795 add_AT_location_description (com_die, DW_AT_location, loc);
20796 /* Avoid sharing the same loc descriptor between
20797 DW_TAG_common_block and DW_TAG_variable. */
20798 loc = loc_list_from_tree (com_decl, 2);
20800 else if (DECL_EXTERNAL (decl))
20801 add_AT_flag (com_die, DW_AT_declaration, 1);
20802 add_pubname_string (cnam, com_die); /* ??? needed? */
20803 com_die->decl_id = DECL_UID (com_decl);
20804 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
20805 *slot = (void *) com_die;
20807 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
20809 add_AT_location_description (com_die, DW_AT_location, loc);
20810 loc = loc_list_from_tree (com_decl, 2);
20811 remove_AT (com_die, DW_AT_declaration);
20813 var_die = new_die (DW_TAG_variable, com_die, decl);
20814 add_name_and_src_coords_attributes (var_die, decl);
20815 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
20816 TREE_THIS_VOLATILE (decl), context_die);
20817 add_AT_flag (var_die, DW_AT_external, 1);
20822 /* Optimize the common case. */
20823 if (single_element_loc_list_p (loc)
20824 && loc->expr->dw_loc_opc == DW_OP_addr
20825 && loc->expr->dw_loc_next == NULL
20826 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
20827 loc->expr->dw_loc_oprnd1.v.val_addr
20828 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
20830 loc_list_plus_const (loc, off);
20832 add_AT_location_description (var_die, DW_AT_location, loc);
20834 else if (DECL_EXTERNAL (decl))
20835 add_AT_flag (var_die, DW_AT_declaration, 1);
20836 equate_decl_number_to_die (decl, var_die);
20840 /* If the compiler emitted a definition for the DECL declaration
20841 and if we already emitted a DIE for it, don't emit a second
20842 DIE for it again. Allow re-declarations of DECLs that are
20843 inside functions, though. */
20844 if (old_die && declaration && !local_scope_p (context_die))
20847 /* For static data members, the declaration in the class is supposed
20848 to have DW_TAG_member tag; the specification should still be
20849 DW_TAG_variable referencing the DW_TAG_member DIE. */
20850 if (declaration && class_scope_p (context_die))
20851 var_die = new_die (DW_TAG_member, context_die, decl);
20853 var_die = new_die (DW_TAG_variable, context_die, decl);
20856 if (origin != NULL)
20857 origin_die = add_abstract_origin_attribute (var_die, origin);
20859 /* Loop unrolling can create multiple blocks that refer to the same
20860 static variable, so we must test for the DW_AT_declaration flag.
20862 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
20863 copy decls and set the DECL_ABSTRACT flag on them instead of
20866 ??? Duplicated blocks have been rewritten to use .debug_ranges.
20868 ??? The declare_in_namespace support causes us to get two DIEs for one
20869 variable, both of which are declarations. We want to avoid considering
20870 one to be a specification, so we must test that this DIE is not a
20872 else if (old_die && TREE_STATIC (decl) && ! declaration
20873 && get_AT_flag (old_die, DW_AT_declaration) == 1)
20875 /* This is a definition of a C++ class level static. */
20876 add_AT_specification (var_die, old_die);
20877 specialization_p = true;
20878 if (DECL_NAME (decl))
20880 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
20881 struct dwarf_file_data * file_index = lookup_filename (s.file);
20883 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
20884 add_AT_file (var_die, DW_AT_decl_file, file_index);
20886 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
20887 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
20889 if (old_die->die_tag == DW_TAG_member)
20890 add_linkage_name (var_die, decl);
20894 add_name_and_src_coords_attributes (var_die, decl);
20896 if ((origin == NULL && !specialization_p)
20898 && !DECL_ABSTRACT (decl_or_origin)
20899 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
20900 decl_function_context
20901 (decl_or_origin))))
20903 tree type = TREE_TYPE (decl_or_origin);
20905 if (decl_by_reference_p (decl_or_origin))
20906 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
20908 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
20909 TREE_THIS_VOLATILE (decl_or_origin), context_die);
20912 if (origin == NULL && !specialization_p)
20914 if (TREE_PUBLIC (decl))
20915 add_AT_flag (var_die, DW_AT_external, 1);
20917 if (DECL_ARTIFICIAL (decl))
20918 add_AT_flag (var_die, DW_AT_artificial, 1);
20920 add_accessibility_attribute (var_die, decl);
20924 add_AT_flag (var_die, DW_AT_declaration, 1);
20926 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
20927 equate_decl_number_to_die (decl, var_die);
20930 && (! DECL_ABSTRACT (decl_or_origin)
20931 /* Local static vars are shared between all clones/inlines,
20932 so emit DW_AT_location on the abstract DIE if DECL_RTL is
20934 || (TREE_CODE (decl_or_origin) == VAR_DECL
20935 && TREE_STATIC (decl_or_origin)
20936 && DECL_RTL_SET_P (decl_or_origin)))
20937 /* When abstract origin already has DW_AT_location attribute, no need
20938 to add it again. */
20939 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
20941 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
20942 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
20943 defer_location (decl_or_origin, var_die);
20945 add_location_or_const_value_attribute (var_die, decl_or_origin,
20946 decl == NULL, DW_AT_location);
20947 add_pubname (decl_or_origin, var_die);
20950 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
20953 /* Generate a DIE to represent a named constant. */
20956 gen_const_die (tree decl, dw_die_ref context_die)
20958 dw_die_ref const_die;
20959 tree type = TREE_TYPE (decl);
20961 const_die = new_die (DW_TAG_constant, context_die, decl);
20962 add_name_and_src_coords_attributes (const_die, decl);
20963 add_type_attribute (const_die, type, 1, 0, context_die);
20964 if (TREE_PUBLIC (decl))
20965 add_AT_flag (const_die, DW_AT_external, 1);
20966 if (DECL_ARTIFICIAL (decl))
20967 add_AT_flag (const_die, DW_AT_artificial, 1);
20968 tree_add_const_value_attribute_for_decl (const_die, decl);
20971 /* Generate a DIE to represent a label identifier. */
20974 gen_label_die (tree decl, dw_die_ref context_die)
20976 tree origin = decl_ultimate_origin (decl);
20977 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
20979 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20981 if (origin != NULL)
20982 add_abstract_origin_attribute (lbl_die, origin);
20984 add_name_and_src_coords_attributes (lbl_die, decl);
20986 if (DECL_ABSTRACT (decl))
20987 equate_decl_number_to_die (decl, lbl_die);
20990 insn = DECL_RTL_IF_SET (decl);
20992 /* Deleted labels are programmer specified labels which have been
20993 eliminated because of various optimizations. We still emit them
20994 here so that it is possible to put breakpoints on them. */
20998 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
21000 /* When optimization is enabled (via -O) some parts of the compiler
21001 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
21002 represent source-level labels which were explicitly declared by
21003 the user. This really shouldn't be happening though, so catch
21004 it if it ever does happen. */
21005 gcc_assert (!INSN_DELETED_P (insn));
21007 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
21008 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
21013 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
21014 attributes to the DIE for a block STMT, to describe where the inlined
21015 function was called from. This is similar to add_src_coords_attributes. */
21018 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
21020 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
21022 if (dwarf_version >= 3 || !dwarf_strict)
21024 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
21025 add_AT_unsigned (die, DW_AT_call_line, s.line);
21030 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
21031 Add low_pc and high_pc attributes to the DIE for a block STMT. */
21034 add_high_low_attributes (tree stmt, dw_die_ref die)
21036 char label[MAX_ARTIFICIAL_LABEL_BYTES];
21038 if (BLOCK_FRAGMENT_CHAIN (stmt)
21039 && (dwarf_version >= 3 || !dwarf_strict))
21043 if (inlined_function_outer_scope_p (stmt))
21045 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
21046 BLOCK_NUMBER (stmt));
21047 add_AT_lbl_id (die, DW_AT_entry_pc, label);
21050 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
21052 chain = BLOCK_FRAGMENT_CHAIN (stmt);
21055 add_ranges (chain);
21056 chain = BLOCK_FRAGMENT_CHAIN (chain);
21063 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
21064 BLOCK_NUMBER (stmt));
21065 add_AT_lbl_id (die, DW_AT_low_pc, label);
21066 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
21067 BLOCK_NUMBER (stmt));
21068 add_AT_lbl_id (die, DW_AT_high_pc, label);
21072 /* Generate a DIE for a lexical block. */
21075 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
21077 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
21079 if (call_arg_locations)
21081 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
21082 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
21083 BLOCK_NUMBER (stmt) + 1);
21084 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
21087 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
21088 add_high_low_attributes (stmt, stmt_die);
21090 decls_for_scope (stmt, stmt_die, depth);
21093 /* Generate a DIE for an inlined subprogram. */
21096 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
21100 /* The instance of function that is effectively being inlined shall not
21102 gcc_assert (! BLOCK_ABSTRACT (stmt));
21104 decl = block_ultimate_origin (stmt);
21106 /* Emit info for the abstract instance first, if we haven't yet. We
21107 must emit this even if the block is abstract, otherwise when we
21108 emit the block below (or elsewhere), we may end up trying to emit
21109 a die whose origin die hasn't been emitted, and crashing. */
21110 dwarf2out_abstract_function (decl);
21112 if (! BLOCK_ABSTRACT (stmt))
21114 dw_die_ref subr_die
21115 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
21117 if (call_arg_locations)
21119 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
21120 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
21121 BLOCK_NUMBER (stmt) + 1);
21122 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
21124 add_abstract_origin_attribute (subr_die, decl);
21125 if (TREE_ASM_WRITTEN (stmt))
21126 add_high_low_attributes (stmt, subr_die);
21127 add_call_src_coords_attributes (stmt, subr_die);
21129 decls_for_scope (stmt, subr_die, depth);
21130 current_function_has_inlines = 1;
21134 /* Generate a DIE for a field in a record, or structure. */
21137 gen_field_die (tree decl, dw_die_ref context_die)
21139 dw_die_ref decl_die;
21141 if (TREE_TYPE (decl) == error_mark_node)
21144 decl_die = new_die (DW_TAG_member, context_die, decl);
21145 add_name_and_src_coords_attributes (decl_die, decl);
21146 add_type_attribute (decl_die, member_declared_type (decl),
21147 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
21150 if (DECL_BIT_FIELD_TYPE (decl))
21152 add_byte_size_attribute (decl_die, decl);
21153 add_bit_size_attribute (decl_die, decl);
21154 add_bit_offset_attribute (decl_die, decl);
21157 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
21158 add_data_member_location_attribute (decl_die, decl);
21160 if (DECL_ARTIFICIAL (decl))
21161 add_AT_flag (decl_die, DW_AT_artificial, 1);
21163 add_accessibility_attribute (decl_die, decl);
21165 /* Equate decl number to die, so that we can look up this decl later on. */
21166 equate_decl_number_to_die (decl, decl_die);
21170 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21171 Use modified_type_die instead.
21172 We keep this code here just in case these types of DIEs may be needed to
21173 represent certain things in other languages (e.g. Pascal) someday. */
21176 gen_pointer_type_die (tree type, dw_die_ref context_die)
21179 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
21181 equate_type_number_to_die (type, ptr_die);
21182 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
21183 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
21186 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21187 Use modified_type_die instead.
21188 We keep this code here just in case these types of DIEs may be needed to
21189 represent certain things in other languages (e.g. Pascal) someday. */
21192 gen_reference_type_die (tree type, dw_die_ref context_die)
21194 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
21196 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
21197 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
21199 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
21201 equate_type_number_to_die (type, ref_die);
21202 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
21203 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
21207 /* Generate a DIE for a pointer to a member type. */
21210 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
21213 = new_die (DW_TAG_ptr_to_member_type,
21214 scope_die_for (type, context_die), type);
21216 equate_type_number_to_die (type, ptr_die);
21217 add_AT_die_ref (ptr_die, DW_AT_containing_type,
21218 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
21219 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
21222 /* Generate the DIE for the compilation unit. */
21225 gen_compile_unit_die (const char *filename)
21228 char producer[250];
21229 const char *language_string = lang_hooks.name;
21232 die = new_die (DW_TAG_compile_unit, NULL, NULL);
21236 add_name_attribute (die, filename);
21237 /* Don't add cwd for <built-in>. */
21238 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
21239 add_comp_dir_attribute (die);
21242 sprintf (producer, "%s %s", language_string, version_string);
21244 #ifdef MIPS_DEBUGGING_INFO
21245 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
21246 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
21247 not appear in the producer string, the debugger reaches the conclusion
21248 that the object file is stripped and has no debugging information.
21249 To get the MIPS/SGI debugger to believe that there is debugging
21250 information in the object file, we add a -g to the producer string. */
21251 if (debug_info_level > DINFO_LEVEL_TERSE)
21252 strcat (producer, " -g");
21255 add_AT_string (die, DW_AT_producer, producer);
21257 /* If our producer is LTO try to figure out a common language to use
21258 from the global list of translation units. */
21259 if (strcmp (language_string, "GNU GIMPLE") == 0)
21263 const char *common_lang = NULL;
21265 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
21267 if (!TRANSLATION_UNIT_LANGUAGE (t))
21270 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
21271 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
21273 else if (strncmp (common_lang, "GNU C", 5) == 0
21274 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
21275 /* Mixing C and C++ is ok, use C++ in that case. */
21276 common_lang = "GNU C++";
21279 /* Fall back to C. */
21280 common_lang = NULL;
21286 language_string = common_lang;
21289 language = DW_LANG_C89;
21290 if (strcmp (language_string, "GNU C++") == 0)
21291 language = DW_LANG_C_plus_plus;
21292 else if (strcmp (language_string, "GNU F77") == 0)
21293 language = DW_LANG_Fortran77;
21294 else if (strcmp (language_string, "GNU Pascal") == 0)
21295 language = DW_LANG_Pascal83;
21296 else if (dwarf_version >= 3 || !dwarf_strict)
21298 if (strcmp (language_string, "GNU Ada") == 0)
21299 language = DW_LANG_Ada95;
21300 else if (strcmp (language_string, "GNU Fortran") == 0)
21301 language = DW_LANG_Fortran95;
21302 else if (strcmp (language_string, "GNU Java") == 0)
21303 language = DW_LANG_Java;
21304 else if (strcmp (language_string, "GNU Objective-C") == 0)
21305 language = DW_LANG_ObjC;
21306 else if (strcmp (language_string, "GNU Objective-C++") == 0)
21307 language = DW_LANG_ObjC_plus_plus;
21310 add_AT_unsigned (die, DW_AT_language, language);
21314 case DW_LANG_Fortran77:
21315 case DW_LANG_Fortran90:
21316 case DW_LANG_Fortran95:
21317 /* Fortran has case insensitive identifiers and the front-end
21318 lowercases everything. */
21319 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
21322 /* The default DW_ID_case_sensitive doesn't need to be specified. */
21328 /* Generate the DIE for a base class. */
21331 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
21333 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
21335 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
21336 add_data_member_location_attribute (die, binfo);
21338 if (BINFO_VIRTUAL_P (binfo))
21339 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
21341 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
21342 children, otherwise the default is DW_ACCESS_public. In DWARF2
21343 the default has always been DW_ACCESS_private. */
21344 if (access == access_public_node)
21346 if (dwarf_version == 2
21347 || context_die->die_tag == DW_TAG_class_type)
21348 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
21350 else if (access == access_protected_node)
21351 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
21352 else if (dwarf_version > 2
21353 && context_die->die_tag != DW_TAG_class_type)
21354 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
21357 /* Generate a DIE for a class member. */
21360 gen_member_die (tree type, dw_die_ref context_die)
21363 tree binfo = TYPE_BINFO (type);
21366 /* If this is not an incomplete type, output descriptions of each of its
21367 members. Note that as we output the DIEs necessary to represent the
21368 members of this record or union type, we will also be trying to output
21369 DIEs to represent the *types* of those members. However the `type'
21370 function (above) will specifically avoid generating type DIEs for member
21371 types *within* the list of member DIEs for this (containing) type except
21372 for those types (of members) which are explicitly marked as also being
21373 members of this (containing) type themselves. The g++ front- end can
21374 force any given type to be treated as a member of some other (containing)
21375 type by setting the TYPE_CONTEXT of the given (member) type to point to
21376 the TREE node representing the appropriate (containing) type. */
21378 /* First output info about the base classes. */
21381 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
21385 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
21386 gen_inheritance_die (base,
21387 (accesses ? VEC_index (tree, accesses, i)
21388 : access_public_node), context_die);
21391 /* Now output info about the data members and type members. */
21392 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
21394 /* If we thought we were generating minimal debug info for TYPE
21395 and then changed our minds, some of the member declarations
21396 may have already been defined. Don't define them again, but
21397 do put them in the right order. */
21399 child = lookup_decl_die (member);
21401 splice_child_die (context_die, child);
21403 gen_decl_die (member, NULL, context_die);
21406 /* Now output info about the function members (if any). */
21407 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
21409 /* Don't include clones in the member list. */
21410 if (DECL_ABSTRACT_ORIGIN (member))
21413 child = lookup_decl_die (member);
21415 splice_child_die (context_die, child);
21417 gen_decl_die (member, NULL, context_die);
21421 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
21422 is set, we pretend that the type was never defined, so we only get the
21423 member DIEs needed by later specification DIEs. */
21426 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
21427 enum debug_info_usage usage)
21429 dw_die_ref type_die = lookup_type_die (type);
21430 dw_die_ref scope_die = 0;
21432 int complete = (TYPE_SIZE (type)
21433 && (! TYPE_STUB_DECL (type)
21434 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
21435 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
21436 complete = complete && should_emit_struct_debug (type, usage);
21438 if (type_die && ! complete)
21441 if (TYPE_CONTEXT (type) != NULL_TREE
21442 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
21443 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
21446 scope_die = scope_die_for (type, context_die);
21448 if (! type_die || (nested && is_cu_die (scope_die)))
21449 /* First occurrence of type or toplevel definition of nested class. */
21451 dw_die_ref old_die = type_die;
21453 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
21454 ? record_type_tag (type) : DW_TAG_union_type,
21456 equate_type_number_to_die (type, type_die);
21458 add_AT_specification (type_die, old_die);
21461 add_name_attribute (type_die, type_tag (type));
21462 add_gnat_descriptive_type_attribute (type_die, type, context_die);
21466 remove_AT (type_die, DW_AT_declaration);
21468 /* Generate child dies for template paramaters. */
21469 if (debug_info_level > DINFO_LEVEL_TERSE
21470 && COMPLETE_TYPE_P (type))
21471 schedule_generic_params_dies_gen (type);
21473 /* If this type has been completed, then give it a byte_size attribute and
21474 then give a list of members. */
21475 if (complete && !ns_decl)
21477 /* Prevent infinite recursion in cases where the type of some member of
21478 this type is expressed in terms of this type itself. */
21479 TREE_ASM_WRITTEN (type) = 1;
21480 add_byte_size_attribute (type_die, type);
21481 if (TYPE_STUB_DECL (type) != NULL_TREE)
21483 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
21484 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
21487 /* If the first reference to this type was as the return type of an
21488 inline function, then it may not have a parent. Fix this now. */
21489 if (type_die->die_parent == NULL)
21490 add_child_die (scope_die, type_die);
21492 push_decl_scope (type);
21493 gen_member_die (type, type_die);
21496 /* GNU extension: Record what type our vtable lives in. */
21497 if (TYPE_VFIELD (type))
21499 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
21501 gen_type_die (vtype, context_die);
21502 add_AT_die_ref (type_die, DW_AT_containing_type,
21503 lookup_type_die (vtype));
21508 add_AT_flag (type_die, DW_AT_declaration, 1);
21510 /* We don't need to do this for function-local types. */
21511 if (TYPE_STUB_DECL (type)
21512 && ! decl_function_context (TYPE_STUB_DECL (type)))
21513 VEC_safe_push (tree, gc, incomplete_types, type);
21516 if (get_AT (type_die, DW_AT_name))
21517 add_pubtype (type, type_die);
21520 /* Generate a DIE for a subroutine _type_. */
21523 gen_subroutine_type_die (tree type, dw_die_ref context_die)
21525 tree return_type = TREE_TYPE (type);
21526 dw_die_ref subr_die
21527 = new_die (DW_TAG_subroutine_type,
21528 scope_die_for (type, context_die), type);
21530 equate_type_number_to_die (type, subr_die);
21531 add_prototyped_attribute (subr_die, type);
21532 add_type_attribute (subr_die, return_type, 0, 0, context_die);
21533 gen_formal_types_die (type, subr_die);
21535 if (get_AT (subr_die, DW_AT_name))
21536 add_pubtype (type, subr_die);
21539 /* Generate a DIE for a type definition. */
21542 gen_typedef_die (tree decl, dw_die_ref context_die)
21544 dw_die_ref type_die;
21547 if (TREE_ASM_WRITTEN (decl))
21550 TREE_ASM_WRITTEN (decl) = 1;
21551 type_die = new_die (DW_TAG_typedef, context_die, decl);
21552 origin = decl_ultimate_origin (decl);
21553 if (origin != NULL)
21554 add_abstract_origin_attribute (type_die, origin);
21559 add_name_and_src_coords_attributes (type_die, decl);
21560 if (DECL_ORIGINAL_TYPE (decl))
21562 type = DECL_ORIGINAL_TYPE (decl);
21564 gcc_assert (type != TREE_TYPE (decl));
21565 equate_type_number_to_die (TREE_TYPE (decl), type_die);
21569 type = TREE_TYPE (decl);
21571 if (is_naming_typedef_decl (TYPE_NAME (type)))
21573 /* Here, we are in the case of decl being a typedef naming
21574 an anonymous type, e.g:
21575 typedef struct {...} foo;
21576 In that case TREE_TYPE (decl) is not a typedef variant
21577 type and TYPE_NAME of the anonymous type is set to the
21578 TYPE_DECL of the typedef. This construct is emitted by
21581 TYPE is the anonymous struct named by the typedef
21582 DECL. As we need the DW_AT_type attribute of the
21583 DW_TAG_typedef to point to the DIE of TYPE, let's
21584 generate that DIE right away. add_type_attribute
21585 called below will then pick (via lookup_type_die) that
21586 anonymous struct DIE. */
21587 if (!TREE_ASM_WRITTEN (type))
21588 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
21590 /* This is a GNU Extension. We are adding a
21591 DW_AT_linkage_name attribute to the DIE of the
21592 anonymous struct TYPE. The value of that attribute
21593 is the name of the typedef decl naming the anonymous
21594 struct. This greatly eases the work of consumers of
21595 this debug info. */
21596 add_linkage_attr (lookup_type_die (type), decl);
21600 add_type_attribute (type_die, type, TREE_READONLY (decl),
21601 TREE_THIS_VOLATILE (decl), context_die);
21603 if (is_naming_typedef_decl (decl))
21604 /* We want that all subsequent calls to lookup_type_die with
21605 TYPE in argument yield the DW_TAG_typedef we have just
21607 equate_type_number_to_die (type, type_die);
21609 add_accessibility_attribute (type_die, decl);
21612 if (DECL_ABSTRACT (decl))
21613 equate_decl_number_to_die (decl, type_die);
21615 if (get_AT (type_die, DW_AT_name))
21616 add_pubtype (decl, type_die);
21619 /* Generate a DIE for a struct, class, enum or union type. */
21622 gen_tagged_type_die (tree type,
21623 dw_die_ref context_die,
21624 enum debug_info_usage usage)
21628 if (type == NULL_TREE
21629 || !is_tagged_type (type))
21632 /* If this is a nested type whose containing class hasn't been written
21633 out yet, writing it out will cover this one, too. This does not apply
21634 to instantiations of member class templates; they need to be added to
21635 the containing class as they are generated. FIXME: This hurts the
21636 idea of combining type decls from multiple TUs, since we can't predict
21637 what set of template instantiations we'll get. */
21638 if (TYPE_CONTEXT (type)
21639 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
21640 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
21642 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
21644 if (TREE_ASM_WRITTEN (type))
21647 /* If that failed, attach ourselves to the stub. */
21648 push_decl_scope (TYPE_CONTEXT (type));
21649 context_die = lookup_type_die (TYPE_CONTEXT (type));
21652 else if (TYPE_CONTEXT (type) != NULL_TREE
21653 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
21655 /* If this type is local to a function that hasn't been written
21656 out yet, use a NULL context for now; it will be fixed up in
21657 decls_for_scope. */
21658 context_die = lookup_decl_die (TYPE_CONTEXT (type));
21659 /* A declaration DIE doesn't count; nested types need to go in the
21661 if (context_die && is_declaration_die (context_die))
21662 context_die = NULL;
21667 context_die = declare_in_namespace (type, context_die);
21671 if (TREE_CODE (type) == ENUMERAL_TYPE)
21673 /* This might have been written out by the call to
21674 declare_in_namespace. */
21675 if (!TREE_ASM_WRITTEN (type))
21676 gen_enumeration_type_die (type, context_die);
21679 gen_struct_or_union_type_die (type, context_die, usage);
21684 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
21685 it up if it is ever completed. gen_*_type_die will set it for us
21686 when appropriate. */
21689 /* Generate a type description DIE. */
21692 gen_type_die_with_usage (tree type, dw_die_ref context_die,
21693 enum debug_info_usage usage)
21695 struct array_descr_info info;
21697 if (type == NULL_TREE || type == error_mark_node)
21700 if (TYPE_NAME (type) != NULL_TREE
21701 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
21702 && is_redundant_typedef (TYPE_NAME (type))
21703 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
21704 /* The DECL of this type is a typedef we don't want to emit debug
21705 info for but we want debug info for its underlying typedef.
21706 This can happen for e.g, the injected-class-name of a C++
21708 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
21710 /* If TYPE is a typedef type variant, let's generate debug info
21711 for the parent typedef which TYPE is a type of. */
21712 if (typedef_variant_p (type))
21714 if (TREE_ASM_WRITTEN (type))
21717 /* Prevent broken recursion; we can't hand off to the same type. */
21718 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
21720 /* Use the DIE of the containing namespace as the parent DIE of
21721 the type description DIE we want to generate. */
21722 if (DECL_CONTEXT (TYPE_NAME (type))
21723 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
21724 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
21726 TREE_ASM_WRITTEN (type) = 1;
21728 gen_decl_die (TYPE_NAME (type), NULL, context_die);
21732 /* If type is an anonymous tagged type named by a typedef, let's
21733 generate debug info for the typedef. */
21734 if (is_naming_typedef_decl (TYPE_NAME (type)))
21736 /* Use the DIE of the containing namespace as the parent DIE of
21737 the type description DIE we want to generate. */
21738 if (DECL_CONTEXT (TYPE_NAME (type))
21739 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
21740 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
21742 gen_decl_die (TYPE_NAME (type), NULL, context_die);
21746 /* If this is an array type with hidden descriptor, handle it first. */
21747 if (!TREE_ASM_WRITTEN (type)
21748 && lang_hooks.types.get_array_descr_info
21749 && lang_hooks.types.get_array_descr_info (type, &info)
21750 && (dwarf_version >= 3 || !dwarf_strict))
21752 gen_descr_array_type_die (type, &info, context_die);
21753 TREE_ASM_WRITTEN (type) = 1;
21757 /* We are going to output a DIE to represent the unqualified version
21758 of this type (i.e. without any const or volatile qualifiers) so
21759 get the main variant (i.e. the unqualified version) of this type
21760 now. (Vectors are special because the debugging info is in the
21761 cloned type itself). */
21762 if (TREE_CODE (type) != VECTOR_TYPE)
21763 type = type_main_variant (type);
21765 if (TREE_ASM_WRITTEN (type))
21768 switch (TREE_CODE (type))
21774 case REFERENCE_TYPE:
21775 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
21776 ensures that the gen_type_die recursion will terminate even if the
21777 type is recursive. Recursive types are possible in Ada. */
21778 /* ??? We could perhaps do this for all types before the switch
21780 TREE_ASM_WRITTEN (type) = 1;
21782 /* For these types, all that is required is that we output a DIE (or a
21783 set of DIEs) to represent the "basis" type. */
21784 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21785 DINFO_USAGE_IND_USE);
21789 /* This code is used for C++ pointer-to-data-member types.
21790 Output a description of the relevant class type. */
21791 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
21792 DINFO_USAGE_IND_USE);
21794 /* Output a description of the type of the object pointed to. */
21795 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21796 DINFO_USAGE_IND_USE);
21798 /* Now output a DIE to represent this pointer-to-data-member type
21800 gen_ptr_to_mbr_type_die (type, context_die);
21803 case FUNCTION_TYPE:
21804 /* Force out return type (in case it wasn't forced out already). */
21805 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21806 DINFO_USAGE_DIR_USE);
21807 gen_subroutine_type_die (type, context_die);
21811 /* Force out return type (in case it wasn't forced out already). */
21812 gen_type_die_with_usage (TREE_TYPE (type), context_die,
21813 DINFO_USAGE_DIR_USE);
21814 gen_subroutine_type_die (type, context_die);
21818 gen_array_type_die (type, context_die);
21822 gen_array_type_die (type, context_die);
21825 case ENUMERAL_TYPE:
21828 case QUAL_UNION_TYPE:
21829 gen_tagged_type_die (type, context_die, usage);
21835 case FIXED_POINT_TYPE:
21838 /* No DIEs needed for fundamental types. */
21843 /* Just use DW_TAG_unspecified_type. */
21845 dw_die_ref type_die = lookup_type_die (type);
21846 if (type_die == NULL)
21848 tree name = TYPE_NAME (type);
21849 if (TREE_CODE (name) == TYPE_DECL)
21850 name = DECL_NAME (name);
21851 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
21852 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
21853 equate_type_number_to_die (type, type_die);
21859 gcc_unreachable ();
21862 TREE_ASM_WRITTEN (type) = 1;
21866 gen_type_die (tree type, dw_die_ref context_die)
21868 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
21871 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
21872 things which are local to the given block. */
21875 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
21877 int must_output_die = 0;
21880 /* Ignore blocks that are NULL. */
21881 if (stmt == NULL_TREE)
21884 inlined_func = inlined_function_outer_scope_p (stmt);
21886 /* If the block is one fragment of a non-contiguous block, do not
21887 process the variables, since they will have been done by the
21888 origin block. Do process subblocks. */
21889 if (BLOCK_FRAGMENT_ORIGIN (stmt))
21893 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
21894 gen_block_die (sub, context_die, depth + 1);
21899 /* Determine if we need to output any Dwarf DIEs at all to represent this
21902 /* The outer scopes for inlinings *must* always be represented. We
21903 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
21904 must_output_die = 1;
21907 /* Determine if this block directly contains any "significant"
21908 local declarations which we will need to output DIEs for. */
21909 if (debug_info_level > DINFO_LEVEL_TERSE)
21910 /* We are not in terse mode so *any* local declaration counts
21911 as being a "significant" one. */
21912 must_output_die = ((BLOCK_VARS (stmt) != NULL
21913 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
21914 && (TREE_USED (stmt)
21915 || TREE_ASM_WRITTEN (stmt)
21916 || BLOCK_ABSTRACT (stmt)));
21917 else if ((TREE_USED (stmt)
21918 || TREE_ASM_WRITTEN (stmt)
21919 || BLOCK_ABSTRACT (stmt))
21920 && !dwarf2out_ignore_block (stmt))
21921 must_output_die = 1;
21924 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
21925 DIE for any block which contains no significant local declarations at
21926 all. Rather, in such cases we just call `decls_for_scope' so that any
21927 needed Dwarf info for any sub-blocks will get properly generated. Note
21928 that in terse mode, our definition of what constitutes a "significant"
21929 local declaration gets restricted to include only inlined function
21930 instances and local (nested) function definitions. */
21931 if (must_output_die)
21935 /* If STMT block is abstract, that means we have been called
21936 indirectly from dwarf2out_abstract_function.
21937 That function rightfully marks the descendent blocks (of
21938 the abstract function it is dealing with) as being abstract,
21939 precisely to prevent us from emitting any
21940 DW_TAG_inlined_subroutine DIE as a descendent
21941 of an abstract function instance. So in that case, we should
21942 not call gen_inlined_subroutine_die.
21944 Later though, when cgraph asks dwarf2out to emit info
21945 for the concrete instance of the function decl into which
21946 the concrete instance of STMT got inlined, the later will lead
21947 to the generation of a DW_TAG_inlined_subroutine DIE. */
21948 if (! BLOCK_ABSTRACT (stmt))
21949 gen_inlined_subroutine_die (stmt, context_die, depth);
21952 gen_lexical_block_die (stmt, context_die, depth);
21955 decls_for_scope (stmt, context_die, depth);
21958 /* Process variable DECL (or variable with origin ORIGIN) within
21959 block STMT and add it to CONTEXT_DIE. */
21961 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
21964 tree decl_or_origin = decl ? decl : origin;
21966 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
21967 die = lookup_decl_die (decl_or_origin);
21968 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
21969 && TYPE_DECL_IS_STUB (decl_or_origin))
21970 die = lookup_type_die (TREE_TYPE (decl_or_origin));
21974 if (die != NULL && die->die_parent == NULL)
21975 add_child_die (context_die, die);
21976 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
21977 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
21978 stmt, context_die);
21980 gen_decl_die (decl, origin, context_die);
21983 /* Generate all of the decls declared within a given scope and (recursively)
21984 all of its sub-blocks. */
21987 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
21993 /* Ignore NULL blocks. */
21994 if (stmt == NULL_TREE)
21997 /* Output the DIEs to represent all of the data objects and typedefs
21998 declared directly within this block but not within any nested
21999 sub-blocks. Also, nested function and tag DIEs have been
22000 generated with a parent of NULL; fix that up now. */
22001 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
22002 process_scope_var (stmt, decl, NULL_TREE, context_die);
22003 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
22004 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
22007 /* If we're at -g1, we're not interested in subblocks. */
22008 if (debug_info_level <= DINFO_LEVEL_TERSE)
22011 /* Output the DIEs to represent all sub-blocks (and the items declared
22012 therein) of this block. */
22013 for (subblocks = BLOCK_SUBBLOCKS (stmt);
22015 subblocks = BLOCK_CHAIN (subblocks))
22016 gen_block_die (subblocks, context_die, depth + 1);
22019 /* Is this a typedef we can avoid emitting? */
22022 is_redundant_typedef (const_tree decl)
22024 if (TYPE_DECL_IS_STUB (decl))
22027 if (DECL_ARTIFICIAL (decl)
22028 && DECL_CONTEXT (decl)
22029 && is_tagged_type (DECL_CONTEXT (decl))
22030 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
22031 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
22032 /* Also ignore the artificial member typedef for the class name. */
22038 /* Return TRUE if TYPE is a typedef that names a type for linkage
22039 purposes. This kind of typedefs is produced by the C++ FE for
22042 typedef struct {...} foo;
22044 In that case, there is no typedef variant type produced for foo.
22045 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
22049 is_naming_typedef_decl (const_tree decl)
22051 if (decl == NULL_TREE
22052 || TREE_CODE (decl) != TYPE_DECL
22053 || !is_tagged_type (TREE_TYPE (decl))
22054 || DECL_IS_BUILTIN (decl)
22055 || is_redundant_typedef (decl)
22056 /* It looks like Ada produces TYPE_DECLs that are very similar
22057 to C++ naming typedefs but that have different
22058 semantics. Let's be specific to c++ for now. */
22062 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
22063 && TYPE_NAME (TREE_TYPE (decl)) == decl
22064 && (TYPE_STUB_DECL (TREE_TYPE (decl))
22065 != TYPE_NAME (TREE_TYPE (decl))));
22068 /* Returns the DIE for a context. */
22070 static inline dw_die_ref
22071 get_context_die (tree context)
22075 /* Find die that represents this context. */
22076 if (TYPE_P (context))
22078 context = TYPE_MAIN_VARIANT (context);
22079 return strip_naming_typedef (context, force_type_die (context));
22082 return force_decl_die (context);
22084 return comp_unit_die ();
22087 /* Returns the DIE for decl. A DIE will always be returned. */
22090 force_decl_die (tree decl)
22092 dw_die_ref decl_die;
22093 unsigned saved_external_flag;
22094 tree save_fn = NULL_TREE;
22095 decl_die = lookup_decl_die (decl);
22098 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
22100 decl_die = lookup_decl_die (decl);
22104 switch (TREE_CODE (decl))
22106 case FUNCTION_DECL:
22107 /* Clear current_function_decl, so that gen_subprogram_die thinks
22108 that this is a declaration. At this point, we just want to force
22109 declaration die. */
22110 save_fn = current_function_decl;
22111 current_function_decl = NULL_TREE;
22112 gen_subprogram_die (decl, context_die);
22113 current_function_decl = save_fn;
22117 /* Set external flag to force declaration die. Restore it after
22118 gen_decl_die() call. */
22119 saved_external_flag = DECL_EXTERNAL (decl);
22120 DECL_EXTERNAL (decl) = 1;
22121 gen_decl_die (decl, NULL, context_die);
22122 DECL_EXTERNAL (decl) = saved_external_flag;
22125 case NAMESPACE_DECL:
22126 if (dwarf_version >= 3 || !dwarf_strict)
22127 dwarf2out_decl (decl);
22129 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
22130 decl_die = comp_unit_die ();
22133 case TRANSLATION_UNIT_DECL:
22134 decl_die = comp_unit_die ();
22138 gcc_unreachable ();
22141 /* We should be able to find the DIE now. */
22143 decl_die = lookup_decl_die (decl);
22144 gcc_assert (decl_die);
22150 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
22151 always returned. */
22154 force_type_die (tree type)
22156 dw_die_ref type_die;
22158 type_die = lookup_type_die (type);
22161 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
22163 type_die = modified_type_die (type, TYPE_READONLY (type),
22164 TYPE_VOLATILE (type), context_die);
22165 gcc_assert (type_die);
22170 /* Force out any required namespaces to be able to output DECL,
22171 and return the new context_die for it, if it's changed. */
22174 setup_namespace_context (tree thing, dw_die_ref context_die)
22176 tree context = (DECL_P (thing)
22177 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
22178 if (context && TREE_CODE (context) == NAMESPACE_DECL)
22179 /* Force out the namespace. */
22180 context_die = force_decl_die (context);
22182 return context_die;
22185 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
22186 type) within its namespace, if appropriate.
22188 For compatibility with older debuggers, namespace DIEs only contain
22189 declarations; all definitions are emitted at CU scope. */
22192 declare_in_namespace (tree thing, dw_die_ref context_die)
22194 dw_die_ref ns_context;
22196 if (debug_info_level <= DINFO_LEVEL_TERSE)
22197 return context_die;
22199 /* If this decl is from an inlined function, then don't try to emit it in its
22200 namespace, as we will get confused. It would have already been emitted
22201 when the abstract instance of the inline function was emitted anyways. */
22202 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
22203 return context_die;
22205 ns_context = setup_namespace_context (thing, context_die);
22207 if (ns_context != context_die)
22211 if (DECL_P (thing))
22212 gen_decl_die (thing, NULL, ns_context);
22214 gen_type_die (thing, ns_context);
22216 return context_die;
22219 /* Generate a DIE for a namespace or namespace alias. */
22222 gen_namespace_die (tree decl, dw_die_ref context_die)
22224 dw_die_ref namespace_die;
22226 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
22227 they are an alias of. */
22228 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
22230 /* Output a real namespace or module. */
22231 context_die = setup_namespace_context (decl, comp_unit_die ());
22232 namespace_die = new_die (is_fortran ()
22233 ? DW_TAG_module : DW_TAG_namespace,
22234 context_die, decl);
22235 /* For Fortran modules defined in different CU don't add src coords. */
22236 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
22238 const char *name = dwarf2_name (decl, 0);
22240 add_name_attribute (namespace_die, name);
22243 add_name_and_src_coords_attributes (namespace_die, decl);
22244 if (DECL_EXTERNAL (decl))
22245 add_AT_flag (namespace_die, DW_AT_declaration, 1);
22246 equate_decl_number_to_die (decl, namespace_die);
22250 /* Output a namespace alias. */
22252 /* Force out the namespace we are an alias of, if necessary. */
22253 dw_die_ref origin_die
22254 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
22256 if (DECL_FILE_SCOPE_P (decl)
22257 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
22258 context_die = setup_namespace_context (decl, comp_unit_die ());
22259 /* Now create the namespace alias DIE. */
22260 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
22261 add_name_and_src_coords_attributes (namespace_die, decl);
22262 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
22263 equate_decl_number_to_die (decl, namespace_die);
22267 /* Generate Dwarf debug information for a decl described by DECL.
22268 The return value is currently only meaningful for PARM_DECLs,
22269 for all other decls it returns NULL. */
22272 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
22274 tree decl_or_origin = decl ? decl : origin;
22275 tree class_origin = NULL, ultimate_origin;
22277 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
22280 switch (TREE_CODE (decl_or_origin))
22286 if (!is_fortran () && !is_ada ())
22288 /* The individual enumerators of an enum type get output when we output
22289 the Dwarf representation of the relevant enum type itself. */
22293 /* Emit its type. */
22294 gen_type_die (TREE_TYPE (decl), context_die);
22296 /* And its containing namespace. */
22297 context_die = declare_in_namespace (decl, context_die);
22299 gen_const_die (decl, context_die);
22302 case FUNCTION_DECL:
22303 /* Don't output any DIEs to represent mere function declarations,
22304 unless they are class members or explicit block externs. */
22305 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
22306 && DECL_FILE_SCOPE_P (decl_or_origin)
22307 && (current_function_decl == NULL_TREE
22308 || DECL_ARTIFICIAL (decl_or_origin)))
22313 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
22314 on local redeclarations of global functions. That seems broken. */
22315 if (current_function_decl != decl)
22316 /* This is only a declaration. */;
22319 /* If we're emitting a clone, emit info for the abstract instance. */
22320 if (origin || DECL_ORIGIN (decl) != decl)
22321 dwarf2out_abstract_function (origin
22322 ? DECL_ORIGIN (origin)
22323 : DECL_ABSTRACT_ORIGIN (decl));
22325 /* If we're emitting an out-of-line copy of an inline function,
22326 emit info for the abstract instance and set up to refer to it. */
22327 else if (cgraph_function_possibly_inlined_p (decl)
22328 && ! DECL_ABSTRACT (decl)
22329 && ! class_or_namespace_scope_p (context_die)
22330 /* dwarf2out_abstract_function won't emit a die if this is just
22331 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
22332 that case, because that works only if we have a die. */
22333 && DECL_INITIAL (decl) != NULL_TREE)
22335 dwarf2out_abstract_function (decl);
22336 set_decl_origin_self (decl);
22339 /* Otherwise we're emitting the primary DIE for this decl. */
22340 else if (debug_info_level > DINFO_LEVEL_TERSE)
22342 /* Before we describe the FUNCTION_DECL itself, make sure that we
22343 have its containing type. */
22345 origin = decl_class_context (decl);
22346 if (origin != NULL_TREE)
22347 gen_type_die (origin, context_die);
22349 /* And its return type. */
22350 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
22352 /* And its virtual context. */
22353 if (DECL_VINDEX (decl) != NULL_TREE)
22354 gen_type_die (DECL_CONTEXT (decl), context_die);
22356 /* Make sure we have a member DIE for decl. */
22357 if (origin != NULL_TREE)
22358 gen_type_die_for_member (origin, decl, context_die);
22360 /* And its containing namespace. */
22361 context_die = declare_in_namespace (decl, context_die);
22364 /* Now output a DIE to represent the function itself. */
22366 gen_subprogram_die (decl, context_die);
22370 /* If we are in terse mode, don't generate any DIEs to represent any
22371 actual typedefs. */
22372 if (debug_info_level <= DINFO_LEVEL_TERSE)
22375 /* In the special case of a TYPE_DECL node representing the declaration
22376 of some type tag, if the given TYPE_DECL is marked as having been
22377 instantiated from some other (original) TYPE_DECL node (e.g. one which
22378 was generated within the original definition of an inline function) we
22379 used to generate a special (abbreviated) DW_TAG_structure_type,
22380 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
22381 should be actually referencing those DIEs, as variable DIEs with that
22382 type would be emitted already in the abstract origin, so it was always
22383 removed during unused type prunning. Don't add anything in this
22385 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
22388 if (is_redundant_typedef (decl))
22389 gen_type_die (TREE_TYPE (decl), context_die);
22391 /* Output a DIE to represent the typedef itself. */
22392 gen_typedef_die (decl, context_die);
22396 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22397 gen_label_die (decl, context_die);
22402 /* If we are in terse mode, don't generate any DIEs to represent any
22403 variable declarations or definitions. */
22404 if (debug_info_level <= DINFO_LEVEL_TERSE)
22407 /* Output any DIEs that are needed to specify the type of this data
22409 if (decl_by_reference_p (decl_or_origin))
22410 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
22412 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
22414 /* And its containing type. */
22415 class_origin = decl_class_context (decl_or_origin);
22416 if (class_origin != NULL_TREE)
22417 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
22419 /* And its containing namespace. */
22420 context_die = declare_in_namespace (decl_or_origin, context_die);
22422 /* Now output the DIE to represent the data object itself. This gets
22423 complicated because of the possibility that the VAR_DECL really
22424 represents an inlined instance of a formal parameter for an inline
22426 ultimate_origin = decl_ultimate_origin (decl_or_origin);
22427 if (ultimate_origin != NULL_TREE
22428 && TREE_CODE (ultimate_origin) == PARM_DECL)
22429 gen_formal_parameter_die (decl, origin,
22430 true /* Emit name attribute. */,
22433 gen_variable_die (decl, origin, context_die);
22437 /* Ignore the nameless fields that are used to skip bits but handle C++
22438 anonymous unions and structs. */
22439 if (DECL_NAME (decl) != NULL_TREE
22440 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
22441 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
22443 gen_type_die (member_declared_type (decl), context_die);
22444 gen_field_die (decl, context_die);
22449 if (DECL_BY_REFERENCE (decl_or_origin))
22450 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
22452 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
22453 return gen_formal_parameter_die (decl, origin,
22454 true /* Emit name attribute. */,
22457 case NAMESPACE_DECL:
22458 case IMPORTED_DECL:
22459 if (dwarf_version >= 3 || !dwarf_strict)
22460 gen_namespace_die (decl, context_die);
22464 /* Probably some frontend-internal decl. Assume we don't care. */
22465 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
22472 /* Output debug information for global decl DECL. Called from toplev.c after
22473 compilation proper has finished. */
22476 dwarf2out_global_decl (tree decl)
22478 /* Output DWARF2 information for file-scope tentative data object
22479 declarations, file-scope (extern) function declarations (which
22480 had no corresponding body) and file-scope tagged type declarations
22481 and definitions which have not yet been forced out. */
22482 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
22483 dwarf2out_decl (decl);
22486 /* Output debug information for type decl DECL. Called from toplev.c
22487 and from language front ends (to record built-in types). */
22489 dwarf2out_type_decl (tree decl, int local)
22492 dwarf2out_decl (decl);
22495 /* Output debug information for imported module or decl DECL.
22496 NAME is non-NULL name in the lexical block if the decl has been renamed.
22497 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
22498 that DECL belongs to.
22499 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
22501 dwarf2out_imported_module_or_decl_1 (tree decl,
22503 tree lexical_block,
22504 dw_die_ref lexical_block_die)
22506 expanded_location xloc;
22507 dw_die_ref imported_die = NULL;
22508 dw_die_ref at_import_die;
22510 if (TREE_CODE (decl) == IMPORTED_DECL)
22512 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
22513 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
22517 xloc = expand_location (input_location);
22519 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
22521 at_import_die = force_type_die (TREE_TYPE (decl));
22522 /* For namespace N { typedef void T; } using N::T; base_type_die
22523 returns NULL, but DW_TAG_imported_declaration requires
22524 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
22525 if (!at_import_die)
22527 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
22528 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
22529 at_import_die = lookup_type_die (TREE_TYPE (decl));
22530 gcc_assert (at_import_die);
22535 at_import_die = lookup_decl_die (decl);
22536 if (!at_import_die)
22538 /* If we're trying to avoid duplicate debug info, we may not have
22539 emitted the member decl for this field. Emit it now. */
22540 if (TREE_CODE (decl) == FIELD_DECL)
22542 tree type = DECL_CONTEXT (decl);
22544 if (TYPE_CONTEXT (type)
22545 && TYPE_P (TYPE_CONTEXT (type))
22546 && !should_emit_struct_debug (TYPE_CONTEXT (type),
22547 DINFO_USAGE_DIR_USE))
22549 gen_type_die_for_member (type, decl,
22550 get_context_die (TYPE_CONTEXT (type)));
22552 at_import_die = force_decl_die (decl);
22556 if (TREE_CODE (decl) == NAMESPACE_DECL)
22558 if (dwarf_version >= 3 || !dwarf_strict)
22559 imported_die = new_die (DW_TAG_imported_module,
22566 imported_die = new_die (DW_TAG_imported_declaration,
22570 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
22571 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
22573 add_AT_string (imported_die, DW_AT_name,
22574 IDENTIFIER_POINTER (name));
22575 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
22578 /* Output debug information for imported module or decl DECL.
22579 NAME is non-NULL name in context if the decl has been renamed.
22580 CHILD is true if decl is one of the renamed decls as part of
22581 importing whole module. */
22584 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
22587 /* dw_die_ref at_import_die; */
22588 dw_die_ref scope_die;
22590 if (debug_info_level <= DINFO_LEVEL_TERSE)
22595 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
22596 We need decl DIE for reference and scope die. First, get DIE for the decl
22599 /* Get the scope die for decl context. Use comp_unit_die for global module
22600 or decl. If die is not found for non globals, force new die. */
22602 && TYPE_P (context)
22603 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
22606 if (!(dwarf_version >= 3 || !dwarf_strict))
22609 scope_die = get_context_die (context);
22613 gcc_assert (scope_die->die_child);
22614 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
22615 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
22616 scope_die = scope_die->die_child;
22619 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
22620 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
22624 /* Write the debugging output for DECL. */
22627 dwarf2out_decl (tree decl)
22629 dw_die_ref context_die = comp_unit_die ();
22631 switch (TREE_CODE (decl))
22636 case FUNCTION_DECL:
22637 /* What we would really like to do here is to filter out all mere
22638 file-scope declarations of file-scope functions which are never
22639 referenced later within this translation unit (and keep all of ones
22640 that *are* referenced later on) but we aren't clairvoyant, so we have
22641 no idea which functions will be referenced in the future (i.e. later
22642 on within the current translation unit). So here we just ignore all
22643 file-scope function declarations which are not also definitions. If
22644 and when the debugger needs to know something about these functions,
22645 it will have to hunt around and find the DWARF information associated
22646 with the definition of the function.
22648 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
22649 nodes represent definitions and which ones represent mere
22650 declarations. We have to check DECL_INITIAL instead. That's because
22651 the C front-end supports some weird semantics for "extern inline"
22652 function definitions. These can get inlined within the current
22653 translation unit (and thus, we need to generate Dwarf info for their
22654 abstract instances so that the Dwarf info for the concrete inlined
22655 instances can have something to refer to) but the compiler never
22656 generates any out-of-lines instances of such things (despite the fact
22657 that they *are* definitions).
22659 The important point is that the C front-end marks these "extern
22660 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
22661 them anyway. Note that the C++ front-end also plays some similar games
22662 for inline function definitions appearing within include files which
22663 also contain `#pragma interface' pragmas. */
22664 if (DECL_INITIAL (decl) == NULL_TREE)
22667 /* If we're a nested function, initially use a parent of NULL; if we're
22668 a plain function, this will be fixed up in decls_for_scope. If
22669 we're a method, it will be ignored, since we already have a DIE. */
22670 if (decl_function_context (decl)
22671 /* But if we're in terse mode, we don't care about scope. */
22672 && debug_info_level > DINFO_LEVEL_TERSE)
22673 context_die = NULL;
22677 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
22678 declaration and if the declaration was never even referenced from
22679 within this entire compilation unit. We suppress these DIEs in
22680 order to save space in the .debug section (by eliminating entries
22681 which are probably useless). Note that we must not suppress
22682 block-local extern declarations (whether used or not) because that
22683 would screw-up the debugger's name lookup mechanism and cause it to
22684 miss things which really ought to be in scope at a given point. */
22685 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
22688 /* For local statics lookup proper context die. */
22689 if (TREE_STATIC (decl) && decl_function_context (decl))
22690 context_die = lookup_decl_die (DECL_CONTEXT (decl));
22692 /* If we are in terse mode, don't generate any DIEs to represent any
22693 variable declarations or definitions. */
22694 if (debug_info_level <= DINFO_LEVEL_TERSE)
22699 if (debug_info_level <= DINFO_LEVEL_TERSE)
22701 if (!is_fortran () && !is_ada ())
22703 if (TREE_STATIC (decl) && decl_function_context (decl))
22704 context_die = lookup_decl_die (DECL_CONTEXT (decl));
22707 case NAMESPACE_DECL:
22708 case IMPORTED_DECL:
22709 if (debug_info_level <= DINFO_LEVEL_TERSE)
22711 if (lookup_decl_die (decl) != NULL)
22716 /* Don't emit stubs for types unless they are needed by other DIEs. */
22717 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
22720 /* Don't bother trying to generate any DIEs to represent any of the
22721 normal built-in types for the language we are compiling. */
22722 if (DECL_IS_BUILTIN (decl))
22725 /* If we are in terse mode, don't generate any DIEs for types. */
22726 if (debug_info_level <= DINFO_LEVEL_TERSE)
22729 /* If we're a function-scope tag, initially use a parent of NULL;
22730 this will be fixed up in decls_for_scope. */
22731 if (decl_function_context (decl))
22732 context_die = NULL;
22740 gen_decl_die (decl, NULL, context_die);
22743 /* Write the debugging output for DECL. */
22746 dwarf2out_function_decl (tree decl)
22748 dwarf2out_decl (decl);
22749 call_arg_locations = NULL;
22750 call_arg_loc_last = NULL;
22751 call_site_count = -1;
22752 tail_call_site_count = -1;
22753 VEC_free (dw_die_ref, heap, block_map);
22754 htab_empty (decl_loc_table);
22755 htab_empty (cached_dw_loc_list_table);
22758 /* Output a marker (i.e. a label) for the beginning of the generated code for
22759 a lexical block. */
22762 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
22763 unsigned int blocknum)
22765 switch_to_section (current_function_section ());
22766 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
22769 /* Output a marker (i.e. a label) for the end of the generated code for a
22773 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
22775 switch_to_section (current_function_section ());
22776 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
22779 /* Returns nonzero if it is appropriate not to emit any debugging
22780 information for BLOCK, because it doesn't contain any instructions.
22782 Don't allow this for blocks with nested functions or local classes
22783 as we would end up with orphans, and in the presence of scheduling
22784 we may end up calling them anyway. */
22787 dwarf2out_ignore_block (const_tree block)
22792 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
22793 if (TREE_CODE (decl) == FUNCTION_DECL
22794 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22796 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
22798 decl = BLOCK_NONLOCALIZED_VAR (block, i);
22799 if (TREE_CODE (decl) == FUNCTION_DECL
22800 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22807 /* Hash table routines for file_hash. */
22810 file_table_eq (const void *p1_p, const void *p2_p)
22812 const struct dwarf_file_data *const p1 =
22813 (const struct dwarf_file_data *) p1_p;
22814 const char *const p2 = (const char *) p2_p;
22815 return filename_cmp (p1->filename, p2) == 0;
22819 file_table_hash (const void *p_p)
22821 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
22822 return htab_hash_string (p->filename);
22825 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22826 dwarf2out.c) and return its "index". The index of each (known) filename is
22827 just a unique number which is associated with only that one filename. We
22828 need such numbers for the sake of generating labels (in the .debug_sfnames
22829 section) and references to those files numbers (in the .debug_srcinfo
22830 and.debug_macinfo sections). If the filename given as an argument is not
22831 found in our current list, add it to the list and assign it the next
22832 available unique index number. In order to speed up searches, we remember
22833 the index of the filename was looked up last. This handles the majority of
22836 static struct dwarf_file_data *
22837 lookup_filename (const char *file_name)
22840 struct dwarf_file_data * created;
22842 /* Check to see if the file name that was searched on the previous
22843 call matches this file name. If so, return the index. */
22844 if (file_table_last_lookup
22845 && (file_name == file_table_last_lookup->filename
22846 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
22847 return file_table_last_lookup;
22849 /* Didn't match the previous lookup, search the table. */
22850 slot = htab_find_slot_with_hash (file_table, file_name,
22851 htab_hash_string (file_name), INSERT);
22853 return (struct dwarf_file_data *) *slot;
22855 created = ggc_alloc_dwarf_file_data ();
22856 created->filename = file_name;
22857 created->emitted_number = 0;
22862 /* If the assembler will construct the file table, then translate the compiler
22863 internal file table number into the assembler file table number, and emit
22864 a .file directive if we haven't already emitted one yet. The file table
22865 numbers are different because we prune debug info for unused variables and
22866 types, which may include filenames. */
22869 maybe_emit_file (struct dwarf_file_data * fd)
22871 if (! fd->emitted_number)
22873 if (last_emitted_file)
22874 fd->emitted_number = last_emitted_file->emitted_number + 1;
22876 fd->emitted_number = 1;
22877 last_emitted_file = fd;
22879 if (DWARF2_ASM_LINE_DEBUG_INFO)
22881 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
22882 output_quoted_string (asm_out_file,
22883 remap_debug_filename (fd->filename));
22884 fputc ('\n', asm_out_file);
22888 return fd->emitted_number;
22891 /* Schedule generation of a DW_AT_const_value attribute to DIE.
22892 That generation should happen after function debug info has been
22893 generated. The value of the attribute is the constant value of ARG. */
22896 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
22898 die_arg_entry entry;
22903 if (!tmpl_value_parm_die_table)
22904 tmpl_value_parm_die_table
22905 = VEC_alloc (die_arg_entry, gc, 32);
22909 VEC_safe_push (die_arg_entry, gc,
22910 tmpl_value_parm_die_table,
22914 /* Return TRUE if T is an instance of generic type, FALSE
22918 generic_type_p (tree t)
22920 if (t == NULL_TREE || !TYPE_P (t))
22922 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
22925 /* Schedule the generation of the generic parameter dies for the
22926 instance of generic type T. The proper generation itself is later
22927 done by gen_scheduled_generic_parms_dies. */
22930 schedule_generic_params_dies_gen (tree t)
22932 if (!generic_type_p (t))
22935 if (generic_type_instances == NULL)
22936 generic_type_instances = VEC_alloc (tree, gc, 256);
22938 VEC_safe_push (tree, gc, generic_type_instances, t);
22941 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
22942 by append_entry_to_tmpl_value_parm_die_table. This function must
22943 be called after function DIEs have been generated. */
22946 gen_remaining_tmpl_value_param_die_attribute (void)
22948 if (tmpl_value_parm_die_table)
22953 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
22954 tree_add_const_value_attribute (e->die, e->arg);
22958 /* Generate generic parameters DIEs for instances of generic types
22959 that have been previously scheduled by
22960 schedule_generic_params_dies_gen. This function must be called
22961 after all the types of the CU have been laid out. */
22964 gen_scheduled_generic_parms_dies (void)
22969 if (generic_type_instances == NULL)
22972 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
22973 gen_generic_params_dies (t);
22977 /* Replace DW_AT_name for the decl with name. */
22980 dwarf2out_set_name (tree decl, tree name)
22986 die = TYPE_SYMTAB_DIE (decl);
22990 dname = dwarf2_name (name, 0);
22994 attr = get_AT (die, DW_AT_name);
22997 struct indirect_string_node *node;
22999 node = find_AT_string (dname);
23000 /* replace the string. */
23001 attr->dw_attr_val.v.val_str = node;
23005 add_name_attribute (die, dname);
23008 /* Called by the final INSN scan whenever we see a var location. We
23009 use it to drop labels in the right places, and throw the location in
23010 our lookup table. */
23013 dwarf2out_var_location (rtx loc_note)
23015 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
23016 struct var_loc_node *newloc;
23018 static const char *last_label;
23019 static const char *last_postcall_label;
23020 static bool last_in_cold_section_p;
23024 if (!NOTE_P (loc_note))
23026 if (CALL_P (loc_note))
23029 if (SIBLING_CALL_P (loc_note))
23030 tail_call_site_count++;
23035 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
23036 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
23039 next_real = next_real_insn (loc_note);
23041 /* If there are no instructions which would be affected by this note,
23042 don't do anything. */
23044 && next_real == NULL_RTX
23045 && !NOTE_DURING_CALL_P (loc_note))
23048 if (next_real == NULL_RTX)
23049 next_real = get_last_insn ();
23051 /* If there were any real insns between note we processed last time
23052 and this note (or if it is the first note), clear
23053 last_{,postcall_}label so that they are not reused this time. */
23054 if (last_var_location_insn == NULL_RTX
23055 || last_var_location_insn != next_real
23056 || last_in_cold_section_p != in_cold_section_p)
23059 last_postcall_label = NULL;
23064 decl = NOTE_VAR_LOCATION_DECL (loc_note);
23065 newloc = add_var_loc_to_decl (decl, loc_note,
23066 NOTE_DURING_CALL_P (loc_note)
23067 ? last_postcall_label : last_label);
23068 if (newloc == NULL)
23077 /* If there were no real insns between note we processed last time
23078 and this note, use the label we emitted last time. Otherwise
23079 create a new label and emit it. */
23080 if (last_label == NULL)
23082 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
23083 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
23085 last_label = ggc_strdup (loclabel);
23090 struct call_arg_loc_node *ca_loc
23091 = ggc_alloc_cleared_call_arg_loc_node ();
23092 rtx prev = prev_real_insn (loc_note), x;
23093 ca_loc->call_arg_loc_note = loc_note;
23094 ca_loc->next = NULL;
23095 ca_loc->label = last_label;
23098 || (NONJUMP_INSN_P (prev)
23099 && GET_CODE (PATTERN (prev)) == SEQUENCE
23100 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
23101 if (!CALL_P (prev))
23102 prev = XVECEXP (PATTERN (prev), 0, 0);
23103 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
23104 x = PATTERN (prev);
23105 if (GET_CODE (x) == PARALLEL)
23106 x = XVECEXP (x, 0, 0);
23107 if (GET_CODE (x) == SET)
23109 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
23111 x = XEXP (XEXP (x, 0), 0);
23112 if (GET_CODE (x) == SYMBOL_REF
23113 && SYMBOL_REF_DECL (x)
23114 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
23115 ca_loc->symbol_ref = x;
23117 ca_loc->block = insn_scope (prev);
23118 if (call_arg_locations)
23119 call_arg_loc_last->next = ca_loc;
23121 call_arg_locations = ca_loc;
23122 call_arg_loc_last = ca_loc;
23124 else if (!NOTE_DURING_CALL_P (loc_note))
23125 newloc->label = last_label;
23128 if (!last_postcall_label)
23130 sprintf (loclabel, "%s-1", last_label);
23131 last_postcall_label = ggc_strdup (loclabel);
23133 newloc->label = last_postcall_label;
23136 last_var_location_insn = next_real;
23137 last_in_cold_section_p = in_cold_section_p;
23140 /* Note in one location list that text section has changed. */
23143 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
23145 var_loc_list *list = (var_loc_list *) *slot;
23147 list->last_before_switch
23148 = list->last->next ? list->last->next : list->last;
23152 /* Note in all location lists that text section has changed. */
23155 var_location_switch_text_section (void)
23157 if (decl_loc_table == NULL)
23160 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
23163 /* Create a new line number table. */
23165 static dw_line_info_table *
23166 new_line_info_table (void)
23168 dw_line_info_table *table;
23170 table = ggc_alloc_cleared_dw_line_info_table_struct ();
23171 table->file_num = 1;
23172 table->line_num = 1;
23173 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
23178 /* Lookup the "current" table into which we emit line info, so
23179 that we don't have to do it for every source line. */
23182 set_cur_line_info_table (section *sec)
23184 dw_line_info_table *table;
23186 if (sec == text_section)
23187 table = text_section_line_info;
23188 else if (sec == cold_text_section)
23190 table = cold_text_section_line_info;
23193 cold_text_section_line_info = table = new_line_info_table ();
23194 table->end_label = cold_end_label;
23199 const char *end_label;
23201 if (flag_reorder_blocks_and_partition)
23203 if (in_cold_section_p)
23204 end_label = crtl->subsections.cold_section_end_label;
23206 end_label = crtl->subsections.hot_section_end_label;
23210 char label[MAX_ARTIFICIAL_LABEL_BYTES];
23211 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
23212 current_function_funcdef_no);
23213 end_label = ggc_strdup (label);
23216 table = new_line_info_table ();
23217 table->end_label = end_label;
23219 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
23222 cur_line_info_table = table;
23226 /* We need to reset the locations at the beginning of each
23227 function. We can't do this in the end_function hook, because the
23228 declarations that use the locations won't have been output when
23229 that hook is called. Also compute have_multiple_function_sections here. */
23232 dwarf2out_begin_function (tree fun)
23234 section *sec = function_section (fun);
23236 if (sec != text_section)
23237 have_multiple_function_sections = true;
23239 if (flag_reorder_blocks_and_partition && !cold_text_section)
23241 gcc_assert (current_function_decl == fun);
23242 cold_text_section = unlikely_text_section ();
23243 switch_to_section (cold_text_section);
23244 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
23245 switch_to_section (sec);
23248 dwarf2out_note_section_used ();
23249 call_site_count = 0;
23250 tail_call_site_count = 0;
23252 set_cur_line_info_table (sec);
23255 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
23258 push_dw_line_info_entry (dw_line_info_table *table,
23259 enum dw_line_info_opcode opcode, unsigned int val)
23261 dw_line_info_entry e;
23264 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
23267 /* Output a label to mark the beginning of a source code line entry
23268 and record information relating to this source line, in
23269 'line_info_table' for later output of the .debug_line section. */
23270 /* ??? The discriminator parameter ought to be unsigned. */
23273 dwarf2out_source_line (unsigned int line, const char *filename,
23274 int discriminator, bool is_stmt)
23276 unsigned int file_num;
23277 dw_line_info_table *table;
23279 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
23282 /* The discriminator column was added in dwarf4. Simplify the below
23283 by simply removing it if we're not supposed to output it. */
23284 if (dwarf_version < 4 && dwarf_strict)
23287 table = cur_line_info_table;
23288 file_num = maybe_emit_file (lookup_filename (filename));
23290 /* ??? TODO: Elide duplicate line number entries. Traditionally,
23291 the debugger has used the second (possibly duplicate) line number
23292 at the beginning of the function to mark the end of the prologue.
23293 We could eliminate any other duplicates within the function. For
23294 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
23295 that second line number entry. */
23296 /* Recall that this end-of-prologue indication is *not* the same thing
23297 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
23298 to which the hook corresponds, follows the last insn that was
23299 emitted by gen_prologue. What we need is to preceed the first insn
23300 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
23301 insn that corresponds to something the user wrote. These may be
23302 very different locations once scheduling is enabled. */
23304 if (0 && file_num == table->file_num
23305 && line == table->line_num
23306 && discriminator == table->discrim_num
23307 && is_stmt == table->is_stmt)
23310 switch_to_section (current_function_section ());
23312 /* If requested, emit something human-readable. */
23313 if (flag_debug_asm)
23314 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
23316 if (DWARF2_ASM_LINE_DEBUG_INFO)
23318 /* Emit the .loc directive understood by GNU as. */
23319 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
23320 if (is_stmt != table->is_stmt)
23321 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
23322 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
23323 fprintf (asm_out_file, " discriminator %d", discriminator);
23324 fputc ('\n', asm_out_file);
23328 unsigned int label_num = ++line_info_label_num;
23330 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
23332 push_dw_line_info_entry (table, LI_set_address, label_num);
23333 if (file_num != table->file_num)
23334 push_dw_line_info_entry (table, LI_set_file, file_num);
23335 if (discriminator != table->discrim_num)
23336 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
23337 if (is_stmt != table->is_stmt)
23338 push_dw_line_info_entry (table, LI_negate_stmt, 0);
23339 push_dw_line_info_entry (table, LI_set_line, line);
23342 table->file_num = file_num;
23343 table->line_num = line;
23344 table->discrim_num = discriminator;
23345 table->is_stmt = is_stmt;
23346 table->in_use = true;
23349 /* Record the beginning of a new source file. */
23352 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
23354 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
23356 /* Record the beginning of the file for break_out_includes. */
23357 dw_die_ref bincl_die;
23359 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
23360 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
23363 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23366 e.code = DW_MACINFO_start_file;
23368 e.info = xstrdup (filename);
23369 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23373 /* Record the end of a source file. */
23376 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
23378 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
23379 /* Record the end of the file for break_out_includes. */
23380 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
23382 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23385 e.code = DW_MACINFO_end_file;
23388 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23392 /* Called from debug_define in toplev.c. The `buffer' parameter contains
23393 the tail part of the directive line, i.e. the part which is past the
23394 initial whitespace, #, whitespace, directive-name, whitespace part. */
23397 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
23398 const char *buffer ATTRIBUTE_UNUSED)
23400 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23403 e.code = DW_MACINFO_define;
23405 e.info = xstrdup (buffer);;
23406 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23410 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
23411 the tail part of the directive line, i.e. the part which is past the
23412 initial whitespace, #, whitespace, directive-name, whitespace part. */
23415 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
23416 const char *buffer ATTRIBUTE_UNUSED)
23418 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23421 e.code = DW_MACINFO_undef;
23423 e.info = xstrdup (buffer);;
23424 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
23429 output_macinfo (void)
23432 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
23433 macinfo_entry *ref;
23438 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
23442 case DW_MACINFO_start_file:
23444 int file_num = maybe_emit_file (lookup_filename (ref->info));
23445 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
23446 dw2_asm_output_data_uleb128
23447 (ref->lineno, "Included from line number %lu",
23448 (unsigned long)ref->lineno);
23449 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
23452 case DW_MACINFO_end_file:
23453 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
23455 case DW_MACINFO_define:
23456 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
23457 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
23458 (unsigned long)ref->lineno);
23459 dw2_asm_output_nstring (ref->info, -1, "The macro");
23461 case DW_MACINFO_undef:
23462 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
23463 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
23464 (unsigned long)ref->lineno);
23465 dw2_asm_output_nstring (ref->info, -1, "The macro");
23468 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
23469 ASM_COMMENT_START, (unsigned long)ref->code);
23475 /* Set up for Dwarf output at the start of compilation. */
23478 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
23480 /* Allocate the file_table. */
23481 file_table = htab_create_ggc (50, file_table_hash,
23482 file_table_eq, NULL);
23484 /* Allocate the decl_die_table. */
23485 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
23486 decl_die_table_eq, NULL);
23488 /* Allocate the decl_loc_table. */
23489 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
23490 decl_loc_table_eq, NULL);
23492 /* Allocate the cached_dw_loc_list_table. */
23493 cached_dw_loc_list_table
23494 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
23495 cached_dw_loc_list_table_eq, NULL);
23497 /* Allocate the initial hunk of the decl_scope_table. */
23498 decl_scope_table = VEC_alloc (tree, gc, 256);
23500 /* Allocate the initial hunk of the abbrev_die_table. */
23501 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
23502 (ABBREV_DIE_TABLE_INCREMENT);
23503 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
23504 /* Zero-th entry is allocated, but unused. */
23505 abbrev_die_table_in_use = 1;
23507 /* Allocate the pubtypes and pubnames vectors. */
23508 pubname_table = VEC_alloc (pubname_entry, gc, 32);
23509 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
23511 incomplete_types = VEC_alloc (tree, gc, 64);
23513 used_rtx_array = VEC_alloc (rtx, gc, 32);
23515 debug_info_section = get_section (DEBUG_INFO_SECTION,
23516 SECTION_DEBUG, NULL);
23517 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
23518 SECTION_DEBUG, NULL);
23519 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
23520 SECTION_DEBUG, NULL);
23521 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
23522 SECTION_DEBUG, NULL);
23523 debug_line_section = get_section (DEBUG_LINE_SECTION,
23524 SECTION_DEBUG, NULL);
23525 debug_loc_section = get_section (DEBUG_LOC_SECTION,
23526 SECTION_DEBUG, NULL);
23527 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
23528 SECTION_DEBUG, NULL);
23529 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
23530 SECTION_DEBUG, NULL);
23531 debug_str_section = get_section (DEBUG_STR_SECTION,
23532 DEBUG_STR_SECTION_FLAGS, NULL);
23533 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
23534 SECTION_DEBUG, NULL);
23535 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
23536 SECTION_DEBUG, NULL);
23538 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
23539 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
23540 DEBUG_ABBREV_SECTION_LABEL, 0);
23541 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
23542 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
23543 COLD_TEXT_SECTION_LABEL, 0);
23544 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
23546 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
23547 DEBUG_INFO_SECTION_LABEL, 0);
23548 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
23549 DEBUG_LINE_SECTION_LABEL, 0);
23550 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
23551 DEBUG_RANGES_SECTION_LABEL, 0);
23552 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
23553 DEBUG_MACINFO_SECTION_LABEL, 0);
23555 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23556 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
23558 switch_to_section (text_section);
23559 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
23561 /* Make sure the line number table for .text always exists. */
23562 text_section_line_info = new_line_info_table ();
23563 text_section_line_info->end_label = text_end_label;
23566 /* Called before cgraph_optimize starts outputtting functions, variables
23567 and toplevel asms into assembly. */
23570 dwarf2out_assembly_start (void)
23572 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23573 && dwarf2out_do_cfi_asm ()
23574 && (!(flag_unwind_tables || flag_exceptions)
23575 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
23576 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
23579 /* A helper function for dwarf2out_finish called through
23580 htab_traverse. Emit one queued .debug_str string. */
23583 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
23585 struct indirect_string_node *node = (struct indirect_string_node *) *h;
23587 if (node->form == DW_FORM_strp)
23589 switch_to_section (debug_str_section);
23590 ASM_OUTPUT_LABEL (asm_out_file, node->label);
23591 assemble_string (node->str, strlen (node->str) + 1);
23597 #if ENABLE_ASSERT_CHECKING
23598 /* Verify that all marks are clear. */
23601 verify_marks_clear (dw_die_ref die)
23605 gcc_assert (! die->die_mark);
23606 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
23608 #endif /* ENABLE_ASSERT_CHECKING */
23610 /* Clear the marks for a die and its children.
23611 Be cool if the mark isn't set. */
23614 prune_unmark_dies (dw_die_ref die)
23620 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
23623 /* Given DIE that we're marking as used, find any other dies
23624 it references as attributes and mark them as used. */
23627 prune_unused_types_walk_attribs (dw_die_ref die)
23632 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23634 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
23636 /* A reference to another DIE.
23637 Make sure that it will get emitted.
23638 If it was broken out into a comdat group, don't follow it. */
23639 if (! use_debug_types
23640 || a->dw_attr == DW_AT_specification
23641 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
23642 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
23644 /* Set the string's refcount to 0 so that prune_unused_types_mark
23645 accounts properly for it. */
23646 if (AT_class (a) == dw_val_class_str)
23647 a->dw_attr_val.v.val_str->refcount = 0;
23651 /* Mark the generic parameters and arguments children DIEs of DIE. */
23654 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
23658 if (die == NULL || die->die_child == NULL)
23660 c = die->die_child;
23663 switch (c->die_tag)
23665 case DW_TAG_template_type_param:
23666 case DW_TAG_template_value_param:
23667 case DW_TAG_GNU_template_template_param:
23668 case DW_TAG_GNU_template_parameter_pack:
23669 prune_unused_types_mark (c, 1);
23675 } while (c && c != die->die_child);
23678 /* Mark DIE as being used. If DOKIDS is true, then walk down
23679 to DIE's children. */
23682 prune_unused_types_mark (dw_die_ref die, int dokids)
23686 if (die->die_mark == 0)
23688 /* We haven't done this node yet. Mark it as used. */
23690 /* If this is the DIE of a generic type instantiation,
23691 mark the children DIEs that describe its generic parms and
23693 prune_unused_types_mark_generic_parms_dies (die);
23695 /* We also have to mark its parents as used.
23696 (But we don't want to mark our parents' kids due to this.) */
23697 if (die->die_parent)
23698 prune_unused_types_mark (die->die_parent, 0);
23700 /* Mark any referenced nodes. */
23701 prune_unused_types_walk_attribs (die);
23703 /* If this node is a specification,
23704 also mark the definition, if it exists. */
23705 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
23706 prune_unused_types_mark (die->die_definition, 1);
23709 if (dokids && die->die_mark != 2)
23711 /* We need to walk the children, but haven't done so yet.
23712 Remember that we've walked the kids. */
23715 /* If this is an array type, we need to make sure our
23716 kids get marked, even if they're types. If we're
23717 breaking out types into comdat sections, do this
23718 for all type definitions. */
23719 if (die->die_tag == DW_TAG_array_type
23720 || (use_debug_types
23721 && is_type_die (die) && ! is_declaration_die (die)))
23722 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
23724 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23728 /* For local classes, look if any static member functions were emitted
23729 and if so, mark them. */
23732 prune_unused_types_walk_local_classes (dw_die_ref die)
23736 if (die->die_mark == 2)
23739 switch (die->die_tag)
23741 case DW_TAG_structure_type:
23742 case DW_TAG_union_type:
23743 case DW_TAG_class_type:
23746 case DW_TAG_subprogram:
23747 if (!get_AT_flag (die, DW_AT_declaration)
23748 || die->die_definition != NULL)
23749 prune_unused_types_mark (die, 1);
23756 /* Mark children. */
23757 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
23760 /* Walk the tree DIE and mark types that we actually use. */
23763 prune_unused_types_walk (dw_die_ref die)
23767 /* Don't do anything if this node is already marked and
23768 children have been marked as well. */
23769 if (die->die_mark == 2)
23772 switch (die->die_tag)
23774 case DW_TAG_structure_type:
23775 case DW_TAG_union_type:
23776 case DW_TAG_class_type:
23777 if (die->die_perennial_p)
23780 for (c = die->die_parent; c; c = c->die_parent)
23781 if (c->die_tag == DW_TAG_subprogram)
23784 /* Finding used static member functions inside of classes
23785 is needed just for local classes, because for other classes
23786 static member function DIEs with DW_AT_specification
23787 are emitted outside of the DW_TAG_*_type. If we ever change
23788 it, we'd need to call this even for non-local classes. */
23790 prune_unused_types_walk_local_classes (die);
23792 /* It's a type node --- don't mark it. */
23795 case DW_TAG_const_type:
23796 case DW_TAG_packed_type:
23797 case DW_TAG_pointer_type:
23798 case DW_TAG_reference_type:
23799 case DW_TAG_rvalue_reference_type:
23800 case DW_TAG_volatile_type:
23801 case DW_TAG_typedef:
23802 case DW_TAG_array_type:
23803 case DW_TAG_interface_type:
23804 case DW_TAG_friend:
23805 case DW_TAG_variant_part:
23806 case DW_TAG_enumeration_type:
23807 case DW_TAG_subroutine_type:
23808 case DW_TAG_string_type:
23809 case DW_TAG_set_type:
23810 case DW_TAG_subrange_type:
23811 case DW_TAG_ptr_to_member_type:
23812 case DW_TAG_file_type:
23813 if (die->die_perennial_p)
23816 /* It's a type node --- don't mark it. */
23820 /* Mark everything else. */
23824 if (die->die_mark == 0)
23828 /* Now, mark any dies referenced from here. */
23829 prune_unused_types_walk_attribs (die);
23834 /* Mark children. */
23835 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23838 /* Increment the string counts on strings referred to from DIE's
23842 prune_unused_types_update_strings (dw_die_ref die)
23847 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23848 if (AT_class (a) == dw_val_class_str)
23850 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
23852 /* Avoid unnecessarily putting strings that are used less than
23853 twice in the hash table. */
23855 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
23858 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
23859 htab_hash_string (s->str),
23861 gcc_assert (*slot == NULL);
23867 /* Remove from the tree DIE any dies that aren't marked. */
23870 prune_unused_types_prune (dw_die_ref die)
23874 gcc_assert (die->die_mark);
23875 prune_unused_types_update_strings (die);
23877 if (! die->die_child)
23880 c = die->die_child;
23882 dw_die_ref prev = c;
23883 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
23884 if (c == die->die_child)
23886 /* No marked children between 'prev' and the end of the list. */
23888 /* No marked children at all. */
23889 die->die_child = NULL;
23892 prev->die_sib = c->die_sib;
23893 die->die_child = prev;
23898 if (c != prev->die_sib)
23900 prune_unused_types_prune (c);
23901 } while (c != die->die_child);
23904 /* Remove dies representing declarations that we never use. */
23907 prune_unused_types (void)
23910 limbo_die_node *node;
23911 comdat_type_node *ctnode;
23913 dw_die_ref base_type;
23915 #if ENABLE_ASSERT_CHECKING
23916 /* All the marks should already be clear. */
23917 verify_marks_clear (comp_unit_die ());
23918 for (node = limbo_die_list; node; node = node->next)
23919 verify_marks_clear (node->die);
23920 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23921 verify_marks_clear (ctnode->root_die);
23922 #endif /* ENABLE_ASSERT_CHECKING */
23924 /* Mark types that are used in global variables. */
23925 premark_types_used_by_global_vars ();
23927 /* Set the mark on nodes that are actually used. */
23928 prune_unused_types_walk (comp_unit_die ());
23929 for (node = limbo_die_list; node; node = node->next)
23930 prune_unused_types_walk (node->die);
23931 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23933 prune_unused_types_walk (ctnode->root_die);
23934 prune_unused_types_mark (ctnode->type_die, 1);
23937 /* Also set the mark on nodes referenced from the
23939 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
23940 prune_unused_types_mark (pub->die, 1);
23941 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
23942 prune_unused_types_mark (base_type, 1);
23944 if (debug_str_hash)
23945 htab_empty (debug_str_hash);
23946 prune_unused_types_prune (comp_unit_die ());
23947 for (node = limbo_die_list; node; node = node->next)
23948 prune_unused_types_prune (node->die);
23949 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23950 prune_unused_types_prune (ctnode->root_die);
23952 /* Leave the marks clear. */
23953 prune_unmark_dies (comp_unit_die ());
23954 for (node = limbo_die_list; node; node = node->next)
23955 prune_unmark_dies (node->die);
23956 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23957 prune_unmark_dies (ctnode->root_die);
23960 /* Set the parameter to true if there are any relative pathnames in
23963 file_table_relative_p (void ** slot, void *param)
23965 bool *p = (bool *) param;
23966 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
23967 if (!IS_ABSOLUTE_PATH (d->filename))
23975 /* Routines to manipulate hash table of comdat type units. */
23978 htab_ct_hash (const void *of)
23981 const comdat_type_node *const type_node = (const comdat_type_node *) of;
23983 memcpy (&h, type_node->signature, sizeof (h));
23988 htab_ct_eq (const void *of1, const void *of2)
23990 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
23991 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
23993 return (! memcmp (type_node_1->signature, type_node_2->signature,
23994 DWARF_TYPE_SIGNATURE_SIZE));
23997 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23998 to the location it would have been added, should we know its
23999 DECL_ASSEMBLER_NAME when we added other attributes. This will
24000 probably improve compactness of debug info, removing equivalent
24001 abbrevs, and hide any differences caused by deferring the
24002 computation of the assembler name, triggered by e.g. PCH. */
24005 move_linkage_attr (dw_die_ref die)
24007 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
24008 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
24010 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
24011 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
24015 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
24017 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
24021 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
24023 VEC_pop (dw_attr_node, die->die_attr);
24024 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
24028 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
24029 referenced from typed stack ops and count how often they are used. */
24032 mark_base_types (dw_loc_descr_ref loc)
24034 dw_die_ref base_type = NULL;
24036 for (; loc; loc = loc->dw_loc_next)
24038 switch (loc->dw_loc_opc)
24040 case DW_OP_GNU_regval_type:
24041 case DW_OP_GNU_deref_type:
24042 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
24044 case DW_OP_GNU_const_type:
24045 case DW_OP_GNU_convert:
24046 case DW_OP_GNU_reinterpret:
24047 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
24049 case DW_OP_GNU_entry_value:
24050 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
24055 gcc_assert (base_type->die_parent == comp_unit_die ());
24056 if (base_type->die_mark)
24057 base_type->die_mark++;
24060 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
24061 base_type->die_mark = 1;
24066 /* Comparison function for sorting marked base types. */
24069 base_type_cmp (const void *x, const void *y)
24071 dw_die_ref dx = *(const dw_die_ref *) x;
24072 dw_die_ref dy = *(const dw_die_ref *) y;
24073 unsigned int byte_size1, byte_size2;
24074 unsigned int encoding1, encoding2;
24075 if (dx->die_mark > dy->die_mark)
24077 if (dx->die_mark < dy->die_mark)
24079 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
24080 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
24081 if (byte_size1 < byte_size2)
24083 if (byte_size1 > byte_size2)
24085 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
24086 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
24087 if (encoding1 < encoding2)
24089 if (encoding1 > encoding2)
24094 /* Move base types marked by mark_base_types as early as possible
24095 in the CU, sorted by decreasing usage count both to make the
24096 uleb128 references as small as possible and to make sure they
24097 will have die_offset already computed by calc_die_sizes when
24098 sizes of typed stack loc ops is computed. */
24101 move_marked_base_types (void)
24104 dw_die_ref base_type, die, c;
24106 if (VEC_empty (dw_die_ref, base_types))
24109 /* Sort by decreasing usage count, they will be added again in that
24111 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
24112 die = comp_unit_die ();
24113 c = die->die_child;
24116 dw_die_ref prev = c;
24118 while (c->die_mark)
24120 remove_child_with_prev (c, prev);
24121 /* As base types got marked, there must be at least
24122 one node other than DW_TAG_base_type. */
24123 gcc_assert (c != c->die_sib);
24127 while (c != die->die_child);
24128 gcc_assert (die->die_child);
24129 c = die->die_child;
24130 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
24132 base_type->die_mark = 0;
24133 base_type->die_sib = c->die_sib;
24134 c->die_sib = base_type;
24139 /* Helper function for resolve_addr, attempt to resolve
24140 one CONST_STRING, return non-zero if not successful. Similarly verify that
24141 SYMBOL_REFs refer to variables emitted in the current CU. */
24144 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
24148 if (GET_CODE (rtl) == CONST_STRING)
24150 size_t len = strlen (XSTR (rtl, 0)) + 1;
24151 tree t = build_string (len, XSTR (rtl, 0));
24152 tree tlen = size_int (len - 1);
24154 = build_array_type (char_type_node, build_index_type (tlen));
24155 rtl = lookup_constant_def (t);
24156 if (!rtl || !MEM_P (rtl))
24158 rtl = XEXP (rtl, 0);
24159 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
24164 if (GET_CODE (rtl) == SYMBOL_REF
24165 && SYMBOL_REF_DECL (rtl))
24167 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
24169 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
24172 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
24176 if (GET_CODE (rtl) == CONST
24177 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
24183 /* Helper function for resolve_addr, handle one location
24184 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24185 the location list couldn't be resolved. */
24188 resolve_addr_in_expr (dw_loc_descr_ref loc)
24190 dw_loc_descr_ref keep = NULL;
24191 for (; loc; loc = loc->dw_loc_next)
24192 switch (loc->dw_loc_opc)
24195 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
24198 case DW_OP_const4u:
24199 case DW_OP_const8u:
24201 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
24204 case DW_OP_implicit_value:
24205 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
24206 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
24209 case DW_OP_GNU_implicit_pointer:
24210 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
24213 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
24216 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
24217 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
24218 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
24221 case DW_OP_GNU_const_type:
24222 case DW_OP_GNU_regval_type:
24223 case DW_OP_GNU_deref_type:
24224 case DW_OP_GNU_convert:
24225 case DW_OP_GNU_reinterpret:
24226 while (loc->dw_loc_next
24227 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
24229 dw_die_ref base1, base2;
24230 unsigned enc1, enc2, size1, size2;
24231 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24232 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24233 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
24235 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
24236 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
24237 gcc_assert (base1->die_tag == DW_TAG_base_type
24238 && base2->die_tag == DW_TAG_base_type);
24239 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
24240 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
24241 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
24242 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
24244 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
24245 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
24249 /* Optimize away next DW_OP_GNU_convert after
24250 adjusting LOC's base type die reference. */
24251 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24252 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24253 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
24255 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
24256 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
24259 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24260 point typed stack entry. */
24261 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
24272 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24273 an address in .rodata section if the string literal is emitted there,
24274 or remove the containing location list or replace DW_AT_const_value
24275 with DW_AT_location and empty location expression, if it isn't found
24276 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24277 to something that has been emitted in the current CU. */
24280 resolve_addr (dw_die_ref die)
24284 dw_loc_list_ref *curr, *start, loc;
24287 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
24288 switch (AT_class (a))
24290 case dw_val_class_loc_list:
24291 start = curr = AT_loc_list_ptr (a);
24294 /* The same list can be referenced more than once. See if we have
24295 already recorded the result from a previous pass. */
24297 *curr = loc->dw_loc_next;
24298 else if (!loc->resolved_addr)
24300 /* As things stand, we do not expect or allow one die to
24301 reference a suffix of another die's location list chain.
24302 References must be identical or completely separate.
24303 There is therefore no need to cache the result of this
24304 pass on any list other than the first; doing so
24305 would lead to unnecessary writes. */
24308 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
24309 if (!resolve_addr_in_expr ((*curr)->expr))
24311 dw_loc_list_ref next = (*curr)->dw_loc_next;
24312 if (next && (*curr)->ll_symbol)
24314 gcc_assert (!next->ll_symbol);
24315 next->ll_symbol = (*curr)->ll_symbol;
24321 mark_base_types ((*curr)->expr);
24322 curr = &(*curr)->dw_loc_next;
24326 loc->resolved_addr = 1;
24330 loc->dw_loc_next = *start;
24335 remove_AT (die, a->dw_attr);
24339 case dw_val_class_loc:
24340 if (!resolve_addr_in_expr (AT_loc (a)))
24342 remove_AT (die, a->dw_attr);
24346 mark_base_types (AT_loc (a));
24348 case dw_val_class_addr:
24349 if (a->dw_attr == DW_AT_const_value
24350 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
24352 remove_AT (die, a->dw_attr);
24355 if (die->die_tag == DW_TAG_GNU_call_site
24356 && a->dw_attr == DW_AT_abstract_origin)
24358 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
24359 dw_die_ref tdie = lookup_decl_die (tdecl);
24361 && DECL_EXTERNAL (tdecl)
24362 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
24364 force_decl_die (tdecl);
24365 tdie = lookup_decl_die (tdecl);
24369 a->dw_attr_val.val_class = dw_val_class_die_ref;
24370 a->dw_attr_val.v.val_die_ref.die = tdie;
24371 a->dw_attr_val.v.val_die_ref.external = 0;
24375 remove_AT (die, a->dw_attr);
24384 FOR_EACH_CHILD (die, c, resolve_addr (c));
24387 /* Helper routines for optimize_location_lists.
24388 This pass tries to share identical local lists in .debug_loc
24391 /* Iteratively hash operands of LOC opcode. */
24393 static inline hashval_t
24394 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
24396 dw_val_ref val1 = &loc->dw_loc_oprnd1;
24397 dw_val_ref val2 = &loc->dw_loc_oprnd2;
24399 switch (loc->dw_loc_opc)
24401 case DW_OP_const4u:
24402 case DW_OP_const8u:
24406 case DW_OP_const1u:
24407 case DW_OP_const1s:
24408 case DW_OP_const2u:
24409 case DW_OP_const2s:
24410 case DW_OP_const4s:
24411 case DW_OP_const8s:
24415 case DW_OP_plus_uconst:
24451 case DW_OP_deref_size:
24452 case DW_OP_xderef_size:
24453 hash = iterative_hash_object (val1->v.val_int, hash);
24460 gcc_assert (val1->val_class == dw_val_class_loc);
24461 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
24462 hash = iterative_hash_object (offset, hash);
24465 case DW_OP_implicit_value:
24466 hash = iterative_hash_object (val1->v.val_unsigned, hash);
24467 switch (val2->val_class)
24469 case dw_val_class_const:
24470 hash = iterative_hash_object (val2->v.val_int, hash);
24472 case dw_val_class_vec:
24474 unsigned int elt_size = val2->v.val_vec.elt_size;
24475 unsigned int len = val2->v.val_vec.length;
24477 hash = iterative_hash_object (elt_size, hash);
24478 hash = iterative_hash_object (len, hash);
24479 hash = iterative_hash (val2->v.val_vec.array,
24480 len * elt_size, hash);
24483 case dw_val_class_const_double:
24484 hash = iterative_hash_object (val2->v.val_double.low, hash);
24485 hash = iterative_hash_object (val2->v.val_double.high, hash);
24487 case dw_val_class_addr:
24488 hash = iterative_hash_rtx (val2->v.val_addr, hash);
24491 gcc_unreachable ();
24495 case DW_OP_bit_piece:
24496 hash = iterative_hash_object (val1->v.val_int, hash);
24497 hash = iterative_hash_object (val2->v.val_int, hash);
24503 unsigned char dtprel = 0xd1;
24504 hash = iterative_hash_object (dtprel, hash);
24506 hash = iterative_hash_rtx (val1->v.val_addr, hash);
24508 case DW_OP_GNU_implicit_pointer:
24509 hash = iterative_hash_object (val2->v.val_int, hash);
24511 case DW_OP_GNU_entry_value:
24512 hash = hash_loc_operands (val1->v.val_loc, hash);
24514 case DW_OP_GNU_regval_type:
24515 case DW_OP_GNU_deref_type:
24517 unsigned int byte_size
24518 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
24519 unsigned int encoding
24520 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
24521 hash = iterative_hash_object (val1->v.val_int, hash);
24522 hash = iterative_hash_object (byte_size, hash);
24523 hash = iterative_hash_object (encoding, hash);
24526 case DW_OP_GNU_convert:
24527 case DW_OP_GNU_reinterpret:
24528 case DW_OP_GNU_const_type:
24530 unsigned int byte_size
24531 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
24532 unsigned int encoding
24533 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
24534 hash = iterative_hash_object (byte_size, hash);
24535 hash = iterative_hash_object (encoding, hash);
24536 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
24538 hash = iterative_hash_object (val2->val_class, hash);
24539 switch (val2->val_class)
24541 case dw_val_class_const:
24542 hash = iterative_hash_object (val2->v.val_int, hash);
24544 case dw_val_class_vec:
24546 unsigned int elt_size = val2->v.val_vec.elt_size;
24547 unsigned int len = val2->v.val_vec.length;
24549 hash = iterative_hash_object (elt_size, hash);
24550 hash = iterative_hash_object (len, hash);
24551 hash = iterative_hash (val2->v.val_vec.array,
24552 len * elt_size, hash);
24555 case dw_val_class_const_double:
24556 hash = iterative_hash_object (val2->v.val_double.low, hash);
24557 hash = iterative_hash_object (val2->v.val_double.high, hash);
24560 gcc_unreachable ();
24566 /* Other codes have no operands. */
24572 /* Iteratively hash the whole DWARF location expression LOC. */
24574 static inline hashval_t
24575 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
24577 dw_loc_descr_ref l;
24578 bool sizes_computed = false;
24579 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24580 size_of_locs (loc);
24582 for (l = loc; l != NULL; l = l->dw_loc_next)
24584 enum dwarf_location_atom opc = l->dw_loc_opc;
24585 hash = iterative_hash_object (opc, hash);
24586 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
24588 size_of_locs (loc);
24589 sizes_computed = true;
24591 hash = hash_loc_operands (l, hash);
24596 /* Compute hash of the whole location list LIST_HEAD. */
24599 hash_loc_list (dw_loc_list_ref list_head)
24601 dw_loc_list_ref curr = list_head;
24602 hashval_t hash = 0;
24604 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
24606 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
24607 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
24609 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
24611 hash = hash_locs (curr->expr, hash);
24613 list_head->hash = hash;
24616 /* Return true if X and Y opcodes have the same operands. */
24619 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
24621 dw_val_ref valx1 = &x->dw_loc_oprnd1;
24622 dw_val_ref valx2 = &x->dw_loc_oprnd2;
24623 dw_val_ref valy1 = &y->dw_loc_oprnd1;
24624 dw_val_ref valy2 = &y->dw_loc_oprnd2;
24626 switch (x->dw_loc_opc)
24628 case DW_OP_const4u:
24629 case DW_OP_const8u:
24633 case DW_OP_const1u:
24634 case DW_OP_const1s:
24635 case DW_OP_const2u:
24636 case DW_OP_const2s:
24637 case DW_OP_const4s:
24638 case DW_OP_const8s:
24642 case DW_OP_plus_uconst:
24678 case DW_OP_deref_size:
24679 case DW_OP_xderef_size:
24680 return valx1->v.val_int == valy1->v.val_int;
24683 gcc_assert (valx1->val_class == dw_val_class_loc
24684 && valy1->val_class == dw_val_class_loc
24685 && x->dw_loc_addr == y->dw_loc_addr);
24686 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
24687 case DW_OP_implicit_value:
24688 if (valx1->v.val_unsigned != valy1->v.val_unsigned
24689 || valx2->val_class != valy2->val_class)
24691 switch (valx2->val_class)
24693 case dw_val_class_const:
24694 return valx2->v.val_int == valy2->v.val_int;
24695 case dw_val_class_vec:
24696 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24697 && valx2->v.val_vec.length == valy2->v.val_vec.length
24698 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24699 valx2->v.val_vec.elt_size
24700 * valx2->v.val_vec.length) == 0;
24701 case dw_val_class_const_double:
24702 return valx2->v.val_double.low == valy2->v.val_double.low
24703 && valx2->v.val_double.high == valy2->v.val_double.high;
24704 case dw_val_class_addr:
24705 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
24707 gcc_unreachable ();
24710 case DW_OP_bit_piece:
24711 return valx1->v.val_int == valy1->v.val_int
24712 && valx2->v.val_int == valy2->v.val_int;
24715 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
24716 case DW_OP_GNU_implicit_pointer:
24717 return valx1->val_class == dw_val_class_die_ref
24718 && valx1->val_class == valy1->val_class
24719 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
24720 && valx2->v.val_int == valy2->v.val_int;
24721 case DW_OP_GNU_entry_value:
24722 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
24723 case DW_OP_GNU_const_type:
24724 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
24725 || valx2->val_class != valy2->val_class)
24727 switch (valx2->val_class)
24729 case dw_val_class_const:
24730 return valx2->v.val_int == valy2->v.val_int;
24731 case dw_val_class_vec:
24732 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24733 && valx2->v.val_vec.length == valy2->v.val_vec.length
24734 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24735 valx2->v.val_vec.elt_size
24736 * valx2->v.val_vec.length) == 0;
24737 case dw_val_class_const_double:
24738 return valx2->v.val_double.low == valy2->v.val_double.low
24739 && valx2->v.val_double.high == valy2->v.val_double.high;
24741 gcc_unreachable ();
24743 case DW_OP_GNU_regval_type:
24744 case DW_OP_GNU_deref_type:
24745 return valx1->v.val_int == valy1->v.val_int
24746 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
24747 case DW_OP_GNU_convert:
24748 case DW_OP_GNU_reinterpret:
24749 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
24751 /* Other codes have no operands. */
24756 /* Return true if DWARF location expressions X and Y are the same. */
24759 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
24761 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
24762 if (x->dw_loc_opc != y->dw_loc_opc
24763 || x->dtprel != y->dtprel
24764 || !compare_loc_operands (x, y))
24766 return x == NULL && y == NULL;
24769 /* Return precomputed hash of location list X. */
24772 loc_list_hash (const void *x)
24774 return ((const struct dw_loc_list_struct *) x)->hash;
24777 /* Return 1 if location lists X and Y are the same. */
24780 loc_list_eq (const void *x, const void *y)
24782 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
24783 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
24786 if (a->hash != b->hash)
24788 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
24789 if (strcmp (a->begin, b->begin) != 0
24790 || strcmp (a->end, b->end) != 0
24791 || (a->section == NULL) != (b->section == NULL)
24792 || (a->section && strcmp (a->section, b->section) != 0)
24793 || !compare_locs (a->expr, b->expr))
24795 return a == NULL && b == NULL;
24798 /* Recursively optimize location lists referenced from DIE
24799 children and share them whenever possible. */
24802 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
24809 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
24810 if (AT_class (a) == dw_val_class_loc_list)
24812 dw_loc_list_ref list = AT_loc_list (a);
24813 /* TODO: perform some optimizations here, before hashing
24814 it and storing into the hash table. */
24815 hash_loc_list (list);
24816 slot = htab_find_slot_with_hash (htab, list, list->hash,
24819 *slot = (void *) list;
24821 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
24824 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
24827 /* Optimize location lists referenced from DIE
24828 children and share them whenever possible. */
24831 optimize_location_lists (dw_die_ref die)
24833 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
24834 optimize_location_lists_1 (die, htab);
24835 htab_delete (htab);
24838 /* Output stuff that dwarf requires at the end of every file,
24839 and generate the DWARF-2 debugging info. */
24842 dwarf2out_finish (const char *filename)
24844 limbo_die_node *node, *next_node;
24845 comdat_type_node *ctnode;
24846 htab_t comdat_type_table;
24849 gen_scheduled_generic_parms_dies ();
24850 gen_remaining_tmpl_value_param_die_attribute ();
24852 /* Add the name for the main input file now. We delayed this from
24853 dwarf2out_init to avoid complications with PCH. */
24854 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
24855 if (!IS_ABSOLUTE_PATH (filename))
24856 add_comp_dir_attribute (comp_unit_die ());
24857 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
24860 htab_traverse (file_table, file_table_relative_p, &p);
24862 add_comp_dir_attribute (comp_unit_die ());
24865 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
24867 add_location_or_const_value_attribute (
24868 VEC_index (deferred_locations, deferred_locations_list, i)->die,
24869 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
24874 /* Traverse the limbo die list, and add parent/child links. The only
24875 dies without parents that should be here are concrete instances of
24876 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
24877 For concrete instances, we can get the parent die from the abstract
24879 for (node = limbo_die_list; node; node = next_node)
24881 dw_die_ref die = node->die;
24882 next_node = node->next;
24884 if (die->die_parent == NULL)
24886 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
24889 add_child_die (origin->die_parent, die);
24890 else if (is_cu_die (die))
24892 else if (seen_error ())
24893 /* It's OK to be confused by errors in the input. */
24894 add_child_die (comp_unit_die (), die);
24897 /* In certain situations, the lexical block containing a
24898 nested function can be optimized away, which results
24899 in the nested function die being orphaned. Likewise
24900 with the return type of that nested function. Force
24901 this to be a child of the containing function.
24903 It may happen that even the containing function got fully
24904 inlined and optimized out. In that case we are lost and
24905 assign the empty child. This should not be big issue as
24906 the function is likely unreachable too. */
24907 tree context = NULL_TREE;
24909 gcc_assert (node->created_for);
24911 if (DECL_P (node->created_for))
24912 context = DECL_CONTEXT (node->created_for);
24913 else if (TYPE_P (node->created_for))
24914 context = TYPE_CONTEXT (node->created_for);
24916 gcc_assert (context
24917 && (TREE_CODE (context) == FUNCTION_DECL
24918 || TREE_CODE (context) == NAMESPACE_DECL));
24920 origin = lookup_decl_die (context);
24922 add_child_die (origin, die);
24924 add_child_die (comp_unit_die (), die);
24929 limbo_die_list = NULL;
24931 #if ENABLE_ASSERT_CHECKING
24933 dw_die_ref die = comp_unit_die (), c;
24934 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
24937 resolve_addr (comp_unit_die ());
24938 move_marked_base_types ();
24940 for (node = deferred_asm_name; node; node = node->next)
24942 tree decl = node->created_for;
24943 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
24945 add_linkage_attr (node->die, decl);
24946 move_linkage_attr (node->die);
24950 deferred_asm_name = NULL;
24952 /* Walk through the list of incomplete types again, trying once more to
24953 emit full debugging info for them. */
24954 retry_incomplete_types ();
24956 if (flag_eliminate_unused_debug_types)
24957 prune_unused_types ();
24959 /* Generate separate CUs for each of the include files we've seen.
24960 They will go into limbo_die_list. */
24961 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
24962 break_out_includes (comp_unit_die ());
24964 /* Generate separate COMDAT sections for type DIEs. */
24965 if (use_debug_types)
24967 break_out_comdat_types (comp_unit_die ());
24969 /* Each new type_unit DIE was added to the limbo die list when created.
24970 Since these have all been added to comdat_type_list, clear the
24972 limbo_die_list = NULL;
24974 /* For each new comdat type unit, copy declarations for incomplete
24975 types to make the new unit self-contained (i.e., no direct
24976 references to the main compile unit). */
24977 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
24978 copy_decls_for_unworthy_types (ctnode->root_die);
24979 copy_decls_for_unworthy_types (comp_unit_die ());
24981 /* In the process of copying declarations from one unit to another,
24982 we may have left some declarations behind that are no longer
24983 referenced. Prune them. */
24984 prune_unused_types ();
24987 /* Traverse the DIE's and add add sibling attributes to those DIE's
24988 that have children. */
24989 add_sibling_attributes (comp_unit_die ());
24990 for (node = limbo_die_list; node; node = node->next)
24991 add_sibling_attributes (node->die);
24992 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
24993 add_sibling_attributes (ctnode->root_die);
24995 /* Output a terminator label for the .text section. */
24996 switch_to_section (text_section);
24997 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
24998 if (cold_text_section)
25000 switch_to_section (cold_text_section);
25001 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
25004 /* We can only use the low/high_pc attributes if all of the code was
25006 if (!have_multiple_function_sections
25007 || (dwarf_version < 3 && dwarf_strict))
25009 /* Don't add if the CU has no associated code. */
25010 if (text_section_used)
25012 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
25013 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
25018 unsigned fde_idx = 0;
25019 bool range_list_added = false;
25021 if (text_section_used)
25022 add_ranges_by_labels (comp_unit_die (), text_section_label,
25023 text_end_label, &range_list_added);
25024 if (cold_text_section_used)
25025 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
25026 cold_end_label, &range_list_added);
25028 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
25030 dw_fde_ref fde = &fde_table[fde_idx];
25032 if (!fde->in_std_section)
25033 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
25034 fde->dw_fde_end, &range_list_added);
25035 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
25036 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
25037 fde->dw_fde_second_end, &range_list_added);
25040 if (range_list_added)
25042 /* We need to give .debug_loc and .debug_ranges an appropriate
25043 "base address". Use zero so that these addresses become
25044 absolute. Historically, we've emitted the unexpected
25045 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25046 Emit both to give time for other tools to adapt. */
25047 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
25048 if (! dwarf_strict && dwarf_version < 4)
25049 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
25055 if (debug_info_level >= DINFO_LEVEL_NORMAL)
25056 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
25057 debug_line_section_label);
25059 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
25060 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
25062 if (have_location_lists)
25063 optimize_location_lists (comp_unit_die ());
25065 /* Output all of the compilation units. We put the main one last so that
25066 the offsets are available to output_pubnames. */
25067 for (node = limbo_die_list; node; node = node->next)
25068 output_comp_unit (node->die, 0);
25070 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
25071 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25073 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
25075 /* Don't output duplicate types. */
25076 if (*slot != HTAB_EMPTY_ENTRY)
25079 /* Add a pointer to the line table for the main compilation unit
25080 so that the debugger can make sense of DW_AT_decl_file
25082 if (debug_info_level >= DINFO_LEVEL_NORMAL)
25083 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
25084 debug_line_section_label);
25086 output_comdat_type_unit (ctnode);
25089 htab_delete (comdat_type_table);
25091 /* Output the main compilation unit if non-empty or if .debug_macinfo
25092 will be emitted. */
25093 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
25095 /* Output the abbreviation table. */
25096 switch_to_section (debug_abbrev_section);
25097 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
25098 output_abbrev_section ();
25100 /* Output location list section if necessary. */
25101 if (have_location_lists)
25103 /* Output the location lists info. */
25104 switch_to_section (debug_loc_section);
25105 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
25106 DEBUG_LOC_SECTION_LABEL, 0);
25107 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
25108 output_location_lists (comp_unit_die ());
25111 /* Output public names table if necessary. */
25112 if (!VEC_empty (pubname_entry, pubname_table))
25114 gcc_assert (info_section_emitted);
25115 switch_to_section (debug_pubnames_section);
25116 output_pubnames (pubname_table);
25119 /* Output public types table if necessary. */
25120 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
25121 It shouldn't hurt to emit it always, since pure DWARF2 consumers
25122 simply won't look for the section. */
25123 if (!VEC_empty (pubname_entry, pubtype_table))
25125 bool empty = false;
25127 if (flag_eliminate_unused_debug_types)
25129 /* The pubtypes table might be emptied by pruning unused items. */
25133 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
25134 if (p->die->die_offset != 0)
25142 gcc_assert (info_section_emitted);
25143 switch_to_section (debug_pubtypes_section);
25144 output_pubnames (pubtype_table);
25148 /* Output the address range information if a CU (.debug_info section)
25149 was emitted. We output an empty table even if we had no functions
25150 to put in it. This because the consumer has no way to tell the
25151 difference between an empty table that we omitted and failure to
25152 generate a table that would have contained data. */
25153 if (info_section_emitted)
25155 unsigned long aranges_length = size_of_aranges ();
25157 switch_to_section (debug_aranges_section);
25158 output_aranges (aranges_length);
25161 /* Output ranges section if necessary. */
25162 if (ranges_table_in_use)
25164 switch_to_section (debug_ranges_section);
25165 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
25169 /* Output the source line correspondence table. We must do this
25170 even if there is no line information. Otherwise, on an empty
25171 translation unit, we will generate a present, but empty,
25172 .debug_info section. IRIX 6.5 `nm' will then complain when
25173 examining the file. This is done late so that any filenames
25174 used by the debug_info section are marked as 'used'. */
25175 switch_to_section (debug_line_section);
25176 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
25177 if (! DWARF2_ASM_LINE_DEBUG_INFO)
25178 output_line_info ();
25180 /* Have to end the macro section. */
25181 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
25183 switch_to_section (debug_macinfo_section);
25184 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
25185 if (!VEC_empty (macinfo_entry, macinfo_table))
25187 dw2_asm_output_data (1, 0, "End compilation unit");
25190 /* If we emitted any DW_FORM_strp form attribute, output the string
25192 if (debug_str_hash)
25193 htab_traverse (debug_str_hash, output_indirect_string, NULL);
25196 #include "gt-dwarf2out.h"