1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "langhooks.h"
93 #include "tree-pass.h"
94 #include "tree-flow.h"
95 #include "cfglayout.h"
97 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
98 static rtx last_var_location_insn;
100 #ifdef VMS_DEBUGGING_INFO
101 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
103 /* Define this macro to be a nonzero value if the directory specifications
104 which are output in the debug info should end with a separator. */
105 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
106 /* Define this macro to evaluate to a nonzero value if GCC should refrain
107 from generating indirect strings in DWARF2 debug information, for instance
108 if your target is stuck with an old version of GDB that is unable to
109 process them properly or uses VMS Debug. */
110 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
116 /* ??? Poison these here until it can be done generically. They've been
117 totally replaced in this file; make sure it stays that way. */
118 #undef DWARF2_UNWIND_INFO
119 #undef DWARF2_FRAME_INFO
120 #if (GCC_VERSION >= 3000)
121 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
124 #ifndef INCOMING_RETURN_ADDR_RTX
125 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
128 /* Map register numbers held in the call frame info that gcc has
129 collected using DWARF_FRAME_REGNUM to those that should be output in
130 .debug_frame and .eh_frame. */
131 #ifndef DWARF2_FRAME_REG_OUT
132 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
135 /* Save the result of dwarf2out_do_frame across PCH. */
136 static GTY(()) bool saved_do_cfi_asm = 0;
138 /* Decide whether we want to emit frame unwind information for the current
142 dwarf2out_do_frame (void)
144 /* We want to emit correct CFA location expressions or lists, so we
145 have to return true if we're going to output debug info, even if
146 we're not going to output frame or unwind info. */
147 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
150 if (saved_do_cfi_asm)
153 if (targetm.debug_unwind_info () == UI_DWARF2)
156 if ((flag_unwind_tables || flag_exceptions)
157 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
163 /* Decide whether to emit frame unwind via assembler directives. */
166 dwarf2out_do_cfi_asm (void)
170 #ifdef MIPS_DEBUGGING_INFO
173 if (saved_do_cfi_asm)
175 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
177 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
180 /* Make sure the personality encoding is one the assembler can support.
181 In particular, aligned addresses can't be handled. */
182 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
183 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
185 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
186 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
189 /* If we can't get the assembler to emit only .debug_frame, and we don't need
190 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
191 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
192 && !flag_unwind_tables && !flag_exceptions
193 && targetm.except_unwind_info (&global_options) != UI_DWARF2)
196 saved_do_cfi_asm = true;
200 /* The size of the target's pointer type. */
202 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
205 /* Array of RTXes referenced by the debugging information, which therefore
206 must be kept around forever. */
207 static GTY(()) VEC(rtx,gc) *used_rtx_array;
209 /* A pointer to the base of a list of incomplete types which might be
210 completed at some later time. incomplete_types_list needs to be a
211 VEC(tree,gc) because we want to tell the garbage collector about
213 static GTY(()) VEC(tree,gc) *incomplete_types;
215 /* A pointer to the base of a table of references to declaration
216 scopes. This table is a display which tracks the nesting
217 of declaration scopes at the current scope and containing
218 scopes. This table is used to find the proper place to
219 define type declaration DIE's. */
220 static GTY(()) VEC(tree,gc) *decl_scope_table;
222 /* Pointers to various DWARF2 sections. */
223 static GTY(()) section *debug_info_section;
224 static GTY(()) section *debug_abbrev_section;
225 static GTY(()) section *debug_aranges_section;
226 static GTY(()) section *debug_macinfo_section;
227 static GTY(()) section *debug_line_section;
228 static GTY(()) section *debug_loc_section;
229 static GTY(()) section *debug_pubnames_section;
230 static GTY(()) section *debug_pubtypes_section;
231 static GTY(()) section *debug_str_section;
232 static GTY(()) section *debug_ranges_section;
233 static GTY(()) section *debug_frame_section;
235 /* Personality decl of current unit. Used only when assembler does not support
237 static GTY(()) rtx current_unit_personality;
239 /* How to start an assembler comment. */
240 #ifndef ASM_COMMENT_START
241 #define ASM_COMMENT_START ";#"
244 typedef struct dw_cfi_struct *dw_cfi_ref;
245 typedef struct dw_fde_struct *dw_fde_ref;
246 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
248 /* Call frames are described using a sequence of Call Frame
249 Information instructions. The register number, offset
250 and address fields are provided as possible operands;
251 their use is selected by the opcode field. */
253 enum dw_cfi_oprnd_type {
255 dw_cfi_oprnd_reg_num,
261 typedef union GTY(()) dw_cfi_oprnd_struct {
262 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
263 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
264 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
265 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
269 typedef struct GTY(()) dw_cfi_struct {
270 dw_cfi_ref dw_cfi_next;
271 enum dwarf_call_frame_info dw_cfi_opc;
272 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
274 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
279 /* This is how we define the location of the CFA. We use to handle it
280 as REG + OFFSET all the time, but now it can be more complex.
281 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
282 Instead of passing around REG and OFFSET, we pass a copy
283 of this structure. */
284 typedef struct cfa_loc {
285 HOST_WIDE_INT offset;
286 HOST_WIDE_INT base_offset;
288 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
289 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
292 /* All call frame descriptions (FDE's) in the GCC generated DWARF
293 refer to a single Common Information Entry (CIE), defined at
294 the beginning of the .debug_frame section. This use of a single
295 CIE obviates the need to keep track of multiple CIE's
296 in the DWARF generation routines below. */
298 typedef struct GTY(()) dw_fde_struct {
300 const char *dw_fde_begin;
301 const char *dw_fde_current_label;
302 const char *dw_fde_end;
303 const char *dw_fde_vms_end_prologue;
304 const char *dw_fde_vms_begin_epilogue;
305 const char *dw_fde_second_begin;
306 const char *dw_fde_second_end;
307 dw_cfi_ref dw_fde_cfi;
308 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
309 HOST_WIDE_INT stack_realignment;
310 unsigned funcdef_number;
311 /* Dynamic realign argument pointer register. */
312 unsigned int drap_reg;
313 /* Virtual dynamic realign argument pointer register. */
314 unsigned int vdrap_reg;
315 /* These 3 flags are copied from rtl_data in function.h. */
316 unsigned all_throwers_are_sibcalls : 1;
317 unsigned uses_eh_lsda : 1;
318 unsigned nothrow : 1;
319 /* Whether we did stack realign in this call frame. */
320 unsigned stack_realign : 1;
321 /* Whether dynamic realign argument pointer register has been saved. */
322 unsigned drap_reg_saved: 1;
323 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
324 unsigned in_std_section : 1;
325 /* True iff dw_fde_second_begin label is in text_section or
326 cold_text_section. */
327 unsigned second_in_std_section : 1;
331 /* Maximum size (in bytes) of an artificially generated label. */
332 #define MAX_ARTIFICIAL_LABEL_BYTES 30
334 /* The size of addresses as they appear in the Dwarf 2 data.
335 Some architectures use word addresses to refer to code locations,
336 but Dwarf 2 info always uses byte addresses. On such machines,
337 Dwarf 2 addresses need to be larger than the architecture's
339 #ifndef DWARF2_ADDR_SIZE
340 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
343 /* The size in bytes of a DWARF field indicating an offset or length
344 relative to a debug info section, specified to be 4 bytes in the
345 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
348 #ifndef DWARF_OFFSET_SIZE
349 #define DWARF_OFFSET_SIZE 4
352 /* The size in bytes of a DWARF 4 type signature. */
354 #ifndef DWARF_TYPE_SIGNATURE_SIZE
355 #define DWARF_TYPE_SIGNATURE_SIZE 8
358 /* According to the (draft) DWARF 3 specification, the initial length
359 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
360 bytes are 0xffffffff, followed by the length stored in the next 8
363 However, the SGI/MIPS ABI uses an initial length which is equal to
364 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
366 #ifndef DWARF_INITIAL_LENGTH_SIZE
367 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
370 /* Round SIZE up to the nearest BOUNDARY. */
371 #define DWARF_ROUND(SIZE,BOUNDARY) \
372 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
374 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
375 #ifndef DWARF_CIE_DATA_ALIGNMENT
376 #ifdef STACK_GROWS_DOWNWARD
377 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
379 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
383 /* CIE identifier. */
384 #if HOST_BITS_PER_WIDE_INT >= 64
385 #define DWARF_CIE_ID \
386 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
388 #define DWARF_CIE_ID DW_CIE_ID
391 /* A pointer to the base of a table that contains frame description
392 information for each routine. */
393 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
395 /* Number of elements currently allocated for fde_table. */
396 static GTY(()) unsigned fde_table_allocated;
398 /* Number of elements in fde_table currently in use. */
399 static GTY(()) unsigned fde_table_in_use;
401 /* Size (in elements) of increments by which we may expand the
403 #define FDE_TABLE_INCREMENT 256
405 /* Get the current fde_table entry we should use. */
407 static inline dw_fde_ref
410 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
413 /* A list of call frame insns for the CIE. */
414 static GTY(()) dw_cfi_ref cie_cfi_head;
416 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
417 attribute that accelerates the lookup of the FDE associated
418 with the subprogram. This variable holds the table index of the FDE
419 associated with the current function (body) definition. */
420 static unsigned current_funcdef_fde;
422 struct GTY(()) indirect_string_node {
424 unsigned int refcount;
425 enum dwarf_form form;
429 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
431 /* True if the compilation unit has location entries that reference
433 static GTY(()) bool debug_str_hash_forced = false;
435 static GTY(()) int dw2_string_counter;
436 static GTY(()) unsigned long dwarf2out_cfi_label_num;
438 /* True if the compilation unit places functions in more than one section. */
439 static GTY(()) bool have_multiple_function_sections = false;
441 /* Whether the default text and cold text sections have been used at all. */
443 static GTY(()) bool text_section_used = false;
444 static GTY(()) bool cold_text_section_used = false;
446 /* The default cold text section. */
447 static GTY(()) section *cold_text_section;
449 /* Forward declarations for functions defined in this file. */
451 static char *stripattributes (const char *);
452 static const char *dwarf_cfi_name (unsigned);
453 static dw_cfi_ref new_cfi (void);
454 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
455 static void add_fde_cfi (const char *, dw_cfi_ref);
456 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
457 static void lookup_cfa (dw_cfa_location *);
458 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
459 static void initial_return_save (rtx);
460 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
462 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
463 static void output_cfi_directive (dw_cfi_ref);
464 static void output_call_frame_info (int);
465 static void dwarf2out_note_section_used (void);
466 static bool clobbers_queued_reg_save (const_rtx);
467 static void dwarf2out_frame_debug_expr (rtx, const char *);
469 /* Support for complex CFA locations. */
470 static void output_cfa_loc (dw_cfi_ref, int);
471 static void output_cfa_loc_raw (dw_cfi_ref);
472 static void get_cfa_from_loc_descr (dw_cfa_location *,
473 struct dw_loc_descr_struct *);
474 static struct dw_loc_descr_struct *build_cfa_loc
475 (dw_cfa_location *, HOST_WIDE_INT);
476 static struct dw_loc_descr_struct *build_cfa_aligned_loc
477 (HOST_WIDE_INT, HOST_WIDE_INT);
478 static void def_cfa_1 (const char *, dw_cfa_location *);
479 static struct dw_loc_descr_struct *mem_loc_descriptor
480 (rtx, enum machine_mode mode, enum var_init_status);
482 /* How to start an assembler comment. */
483 #ifndef ASM_COMMENT_START
484 #define ASM_COMMENT_START ";#"
487 /* Data and reference forms for relocatable data. */
488 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
489 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
491 #ifndef DEBUG_FRAME_SECTION
492 #define DEBUG_FRAME_SECTION ".debug_frame"
495 #ifndef FUNC_BEGIN_LABEL
496 #define FUNC_BEGIN_LABEL "LFB"
499 #ifndef FUNC_END_LABEL
500 #define FUNC_END_LABEL "LFE"
503 #ifndef PROLOGUE_END_LABEL
504 #define PROLOGUE_END_LABEL "LPE"
507 #ifndef EPILOGUE_BEGIN_LABEL
508 #define EPILOGUE_BEGIN_LABEL "LEB"
511 #ifndef FRAME_BEGIN_LABEL
512 #define FRAME_BEGIN_LABEL "Lframe"
514 #define CIE_AFTER_SIZE_LABEL "LSCIE"
515 #define CIE_END_LABEL "LECIE"
516 #define FDE_LABEL "LSFDE"
517 #define FDE_AFTER_SIZE_LABEL "LASFDE"
518 #define FDE_END_LABEL "LEFDE"
519 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
520 #define LINE_NUMBER_END_LABEL "LELT"
521 #define LN_PROLOG_AS_LABEL "LASLTP"
522 #define LN_PROLOG_END_LABEL "LELTP"
523 #define DIE_LABEL_PREFIX "DW"
525 /* The DWARF 2 CFA column which tracks the return address. Normally this
526 is the column for PC, or the first column after all of the hard
528 #ifndef DWARF_FRAME_RETURN_COLUMN
530 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
532 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
536 /* The mapping from gcc register number to DWARF 2 CFA column number. By
537 default, we just provide columns for all registers. */
538 #ifndef DWARF_FRAME_REGNUM
539 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
542 /* Match the base name of a file to the base name of a compilation unit. */
545 matches_main_base (const char *path)
547 /* Cache the last query. */
548 static const char *last_path = NULL;
549 static int last_match = 0;
550 if (path != last_path)
553 int length = base_of_path (path, &base);
555 last_match = (length == main_input_baselength
556 && memcmp (base, main_input_basename, length) == 0);
561 #ifdef DEBUG_DEBUG_STRUCT
564 dump_struct_debug (tree type, enum debug_info_usage usage,
565 enum debug_struct_file criterion, int generic,
566 int matches, int result)
568 /* Find the type name. */
569 tree type_decl = TYPE_STUB_DECL (type);
571 const char *name = 0;
572 if (TREE_CODE (t) == TYPE_DECL)
575 name = IDENTIFIER_POINTER (t);
577 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
579 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
580 matches ? "bas" : "hdr",
581 generic ? "gen" : "ord",
582 usage == DINFO_USAGE_DFN ? ";" :
583 usage == DINFO_USAGE_DIR_USE ? "." : "*",
585 (void*) type_decl, name);
588 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
589 dump_struct_debug (type, usage, criterion, generic, matches, result)
593 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
599 should_emit_struct_debug (tree type, enum debug_info_usage usage)
601 enum debug_struct_file criterion;
603 bool generic = lang_hooks.types.generic_p (type);
606 criterion = debug_struct_generic[usage];
608 criterion = debug_struct_ordinary[usage];
610 if (criterion == DINFO_STRUCT_FILE_NONE)
611 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
612 if (criterion == DINFO_STRUCT_FILE_ANY)
613 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
615 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
617 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
618 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
620 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
621 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
622 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
625 /* Hook used by __throw. */
628 expand_builtin_dwarf_sp_column (void)
630 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
631 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
634 /* Return a pointer to a copy of the section string name S with all
635 attributes stripped off, and an asterisk prepended (for assemble_name). */
638 stripattributes (const char *s)
640 char *stripped = XNEWVEC (char, strlen (s) + 2);
645 while (*s && *s != ',')
652 /* MEM is a memory reference for the register size table, each element of
653 which has mode MODE. Initialize column C as a return address column. */
656 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
658 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
659 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
660 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
663 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
665 static inline HOST_WIDE_INT
666 div_data_align (HOST_WIDE_INT off)
668 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
669 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
673 /* Return true if we need a signed version of a given opcode
674 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
677 need_data_align_sf_opcode (HOST_WIDE_INT off)
679 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
682 /* Generate code to initialize the register size table. */
685 expand_builtin_init_dwarf_reg_sizes (tree address)
688 enum machine_mode mode = TYPE_MODE (char_type_node);
689 rtx addr = expand_normal (address);
690 rtx mem = gen_rtx_MEM (BLKmode, addr);
691 bool wrote_return_column = false;
693 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
695 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
697 if (rnum < DWARF_FRAME_REGISTERS)
699 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
700 enum machine_mode save_mode = reg_raw_mode[i];
703 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
704 save_mode = choose_hard_reg_mode (i, 1, true);
705 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
707 if (save_mode == VOIDmode)
709 wrote_return_column = true;
711 size = GET_MODE_SIZE (save_mode);
715 emit_move_insn (adjust_address (mem, mode, offset),
716 gen_int_mode (size, mode));
720 if (!wrote_return_column)
721 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
723 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
724 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
727 targetm.init_dwarf_reg_sizes_extra (address);
730 /* Convert a DWARF call frame info. operation to its string name */
733 dwarf_cfi_name (unsigned int cfi_opc)
737 case DW_CFA_advance_loc:
738 return "DW_CFA_advance_loc";
740 return "DW_CFA_offset";
742 return "DW_CFA_restore";
746 return "DW_CFA_set_loc";
747 case DW_CFA_advance_loc1:
748 return "DW_CFA_advance_loc1";
749 case DW_CFA_advance_loc2:
750 return "DW_CFA_advance_loc2";
751 case DW_CFA_advance_loc4:
752 return "DW_CFA_advance_loc4";
753 case DW_CFA_offset_extended:
754 return "DW_CFA_offset_extended";
755 case DW_CFA_restore_extended:
756 return "DW_CFA_restore_extended";
757 case DW_CFA_undefined:
758 return "DW_CFA_undefined";
759 case DW_CFA_same_value:
760 return "DW_CFA_same_value";
761 case DW_CFA_register:
762 return "DW_CFA_register";
763 case DW_CFA_remember_state:
764 return "DW_CFA_remember_state";
765 case DW_CFA_restore_state:
766 return "DW_CFA_restore_state";
768 return "DW_CFA_def_cfa";
769 case DW_CFA_def_cfa_register:
770 return "DW_CFA_def_cfa_register";
771 case DW_CFA_def_cfa_offset:
772 return "DW_CFA_def_cfa_offset";
775 case DW_CFA_def_cfa_expression:
776 return "DW_CFA_def_cfa_expression";
777 case DW_CFA_expression:
778 return "DW_CFA_expression";
779 case DW_CFA_offset_extended_sf:
780 return "DW_CFA_offset_extended_sf";
781 case DW_CFA_def_cfa_sf:
782 return "DW_CFA_def_cfa_sf";
783 case DW_CFA_def_cfa_offset_sf:
784 return "DW_CFA_def_cfa_offset_sf";
786 /* SGI/MIPS specific */
787 case DW_CFA_MIPS_advance_loc8:
788 return "DW_CFA_MIPS_advance_loc8";
791 case DW_CFA_GNU_window_save:
792 return "DW_CFA_GNU_window_save";
793 case DW_CFA_GNU_args_size:
794 return "DW_CFA_GNU_args_size";
795 case DW_CFA_GNU_negative_offset_extended:
796 return "DW_CFA_GNU_negative_offset_extended";
799 return "DW_CFA_<unknown>";
803 /* Return a pointer to a newly allocated Call Frame Instruction. */
805 static inline dw_cfi_ref
808 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
810 cfi->dw_cfi_next = NULL;
811 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
812 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
817 /* Add a Call Frame Instruction to list of instructions. */
820 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
823 dw_fde_ref fde = current_fde ();
825 /* When DRAP is used, CFA is defined with an expression. Redefine
826 CFA may lead to a different CFA value. */
827 /* ??? Of course, this heuristic fails when we're annotating epilogues,
828 because of course we'll always want to redefine the CFA back to the
829 stack pointer on the way out. Where should we move this check? */
830 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
831 switch (cfi->dw_cfi_opc)
833 case DW_CFA_def_cfa_register:
834 case DW_CFA_def_cfa_offset:
835 case DW_CFA_def_cfa_offset_sf:
837 case DW_CFA_def_cfa_sf:
844 /* Find the end of the chain. */
845 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
851 /* Generate a new label for the CFI info to refer to. FORCE is true
852 if a label needs to be output even when using .cfi_* directives. */
855 dwarf2out_cfi_label (bool force)
857 static char label[20];
859 if (!force && dwarf2out_do_cfi_asm ())
861 /* In this case, we will be emitting the asm directive instead of
862 the label, so just return a placeholder to keep the rest of the
864 strcpy (label, "<do not output>");
868 int num = dwarf2out_cfi_label_num++;
869 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
870 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
876 /* True if remember_state should be emitted before following CFI directive. */
877 static bool emit_cfa_remember;
879 /* True if any CFI directives were emitted at the current insn. */
880 static bool any_cfis_emitted;
882 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
883 or to the CIE if LABEL is NULL. */
886 add_fde_cfi (const char *label, dw_cfi_ref cfi)
888 dw_cfi_ref *list_head;
890 if (emit_cfa_remember)
892 dw_cfi_ref cfi_remember;
894 /* Emit the state save. */
895 emit_cfa_remember = false;
896 cfi_remember = new_cfi ();
897 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
898 add_fde_cfi (label, cfi_remember);
901 list_head = &cie_cfi_head;
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 list_head = &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 list_head = &fde->dw_fde_cfi;
999 any_cfis_emitted = true;
1002 add_cfi (list_head, cfi);
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)
1051 dw_cfa_location remember;
1053 memset (loc, 0, sizeof (*loc));
1054 loc->reg = INVALID_REGNUM;
1057 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
1058 lookup_cfa_1 (cfi, loc, &remember);
1060 fde = current_fde ();
1062 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
1063 lookup_cfa_1 (cfi, loc, &remember);
1066 /* The current rule for calculating the DWARF2 canonical frame address. */
1067 static dw_cfa_location cfa;
1069 /* The register used for saving registers to the stack, and its offset
1071 static dw_cfa_location cfa_store;
1073 /* The current save location around an epilogue. */
1074 static dw_cfa_location cfa_remember;
1076 /* The running total of the size of arguments pushed onto the stack. */
1077 static HOST_WIDE_INT args_size;
1079 /* The last args_size we actually output. */
1080 static HOST_WIDE_INT old_args_size;
1082 /* Entry point to update the canonical frame address (CFA).
1083 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1084 calculated from REG+OFFSET. */
1087 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1089 dw_cfa_location loc;
1091 loc.base_offset = 0;
1093 loc.offset = offset;
1094 def_cfa_1 (label, &loc);
1097 /* Determine if two dw_cfa_location structures define the same data. */
1100 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1102 return (loc1->reg == loc2->reg
1103 && loc1->offset == loc2->offset
1104 && loc1->indirect == loc2->indirect
1105 && (loc1->indirect == 0
1106 || loc1->base_offset == loc2->base_offset));
1109 /* This routine does the actual work. The CFA is now calculated from
1110 the dw_cfa_location structure. */
1113 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1116 dw_cfa_location old_cfa, loc;
1121 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1122 cfa_store.offset = loc.offset;
1124 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1125 lookup_cfa (&old_cfa);
1127 /* If nothing changed, no need to issue any call frame instructions. */
1128 if (cfa_equal_p (&loc, &old_cfa))
1133 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1135 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1136 the CFA register did not change but the offset did. The data
1137 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1138 in the assembler via the .cfi_def_cfa_offset directive. */
1140 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1142 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1143 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1146 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1147 else if (loc.offset == old_cfa.offset
1148 && old_cfa.reg != INVALID_REGNUM
1150 && !old_cfa.indirect)
1152 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1153 indicating the CFA register has changed to <register> but the
1154 offset has not changed. */
1155 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1156 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1160 else if (loc.indirect == 0)
1162 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1163 indicating the CFA register has changed to <register> with
1164 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1165 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1168 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1170 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1171 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1172 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1176 /* Construct a DW_CFA_def_cfa_expression instruction to
1177 calculate the CFA using a full location expression since no
1178 register-offset pair is available. */
1179 struct dw_loc_descr_struct *loc_list;
1181 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1182 loc_list = build_cfa_loc (&loc, 0);
1183 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1186 add_fde_cfi (label, cfi);
1189 /* Add the CFI for saving a register. REG is the CFA column number.
1190 LABEL is passed to add_fde_cfi.
1191 If SREG is -1, the register is saved at OFFSET from the CFA;
1192 otherwise it is saved in SREG. */
1195 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1197 dw_cfi_ref cfi = new_cfi ();
1198 dw_fde_ref fde = current_fde ();
1200 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1202 /* When stack is aligned, store REG using DW_CFA_expression with
1205 && fde->stack_realign
1206 && sreg == INVALID_REGNUM)
1208 cfi->dw_cfi_opc = DW_CFA_expression;
1209 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1210 cfi->dw_cfi_oprnd2.dw_cfi_loc
1211 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1213 else if (sreg == INVALID_REGNUM)
1215 if (need_data_align_sf_opcode (offset))
1216 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1217 else if (reg & ~0x3f)
1218 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1220 cfi->dw_cfi_opc = DW_CFA_offset;
1221 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1223 else if (sreg == reg)
1224 cfi->dw_cfi_opc = DW_CFA_same_value;
1227 cfi->dw_cfi_opc = DW_CFA_register;
1228 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1231 add_fde_cfi (label, cfi);
1234 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1235 This CFI tells the unwinder that it needs to restore the window registers
1236 from the previous frame's window save area.
1238 ??? Perhaps we should note in the CIE where windows are saved (instead of
1239 assuming 0(cfa)) and what registers are in the window. */
1242 dwarf2out_window_save (const char *label)
1244 dw_cfi_ref cfi = new_cfi ();
1246 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1247 add_fde_cfi (label, cfi);
1250 /* Entry point for saving a register to the stack. REG is the GCC register
1251 number. LABEL and OFFSET are passed to reg_save. */
1254 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1256 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1259 /* Entry point for saving the return address in the stack.
1260 LABEL and OFFSET are passed to reg_save. */
1263 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1265 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1268 /* Entry point for saving the return address in a register.
1269 LABEL and SREG are passed to reg_save. */
1272 dwarf2out_return_reg (const char *label, unsigned int sreg)
1274 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1277 /* Record the initial position of the return address. RTL is
1278 INCOMING_RETURN_ADDR_RTX. */
1281 initial_return_save (rtx rtl)
1283 unsigned int reg = INVALID_REGNUM;
1284 HOST_WIDE_INT offset = 0;
1286 switch (GET_CODE (rtl))
1289 /* RA is in a register. */
1290 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1294 /* RA is on the stack. */
1295 rtl = XEXP (rtl, 0);
1296 switch (GET_CODE (rtl))
1299 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1304 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1305 offset = INTVAL (XEXP (rtl, 1));
1309 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1310 offset = -INTVAL (XEXP (rtl, 1));
1320 /* The return address is at some offset from any value we can
1321 actually load. For instance, on the SPARC it is in %i7+8. Just
1322 ignore the offset for now; it doesn't matter for unwinding frames. */
1323 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1324 initial_return_save (XEXP (rtl, 0));
1331 if (reg != DWARF_FRAME_RETURN_COLUMN)
1332 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1335 /* Given a SET, calculate the amount of stack adjustment it
1338 static HOST_WIDE_INT
1339 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1340 HOST_WIDE_INT cur_offset)
1342 const_rtx src = SET_SRC (pattern);
1343 const_rtx dest = SET_DEST (pattern);
1344 HOST_WIDE_INT offset = 0;
1347 if (dest == stack_pointer_rtx)
1349 code = GET_CODE (src);
1351 /* Assume (set (reg sp) (reg whatever)) sets args_size
1353 if (code == REG && src != stack_pointer_rtx)
1355 offset = -cur_args_size;
1356 #ifndef STACK_GROWS_DOWNWARD
1359 return offset - cur_offset;
1362 if (! (code == PLUS || code == MINUS)
1363 || XEXP (src, 0) != stack_pointer_rtx
1364 || !CONST_INT_P (XEXP (src, 1)))
1367 /* (set (reg sp) (plus (reg sp) (const_int))) */
1368 offset = INTVAL (XEXP (src, 1));
1374 if (MEM_P (src) && !MEM_P (dest))
1378 /* (set (mem (pre_dec (reg sp))) (foo)) */
1379 src = XEXP (dest, 0);
1380 code = GET_CODE (src);
1386 if (XEXP (src, 0) == stack_pointer_rtx)
1388 rtx val = XEXP (XEXP (src, 1), 1);
1389 /* We handle only adjustments by constant amount. */
1390 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1391 && CONST_INT_P (val));
1392 offset = -INTVAL (val);
1399 if (XEXP (src, 0) == stack_pointer_rtx)
1401 offset = GET_MODE_SIZE (GET_MODE (dest));
1408 if (XEXP (src, 0) == stack_pointer_rtx)
1410 offset = -GET_MODE_SIZE (GET_MODE (dest));
1425 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1426 indexed by INSN_UID. */
1428 static HOST_WIDE_INT *barrier_args_size;
1430 /* Helper function for compute_barrier_args_size. Handle one insn. */
1432 static HOST_WIDE_INT
1433 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1434 VEC (rtx, heap) **next)
1436 HOST_WIDE_INT offset = 0;
1439 if (! RTX_FRAME_RELATED_P (insn))
1441 if (prologue_epilogue_contains (insn))
1443 else if (GET_CODE (PATTERN (insn)) == SET)
1444 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1445 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1446 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1448 /* There may be stack adjustments inside compound insns. Search
1450 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1451 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1452 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1453 cur_args_size, offset);
1458 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1462 expr = XEXP (expr, 0);
1463 if (GET_CODE (expr) == PARALLEL
1464 || GET_CODE (expr) == SEQUENCE)
1465 for (i = 1; i < XVECLEN (expr, 0); i++)
1467 rtx elem = XVECEXP (expr, 0, i);
1469 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1470 offset += stack_adjust_offset (elem, cur_args_size, offset);
1475 #ifndef STACK_GROWS_DOWNWARD
1479 cur_args_size += offset;
1480 if (cur_args_size < 0)
1485 rtx dest = JUMP_LABEL (insn);
1489 if (barrier_args_size [INSN_UID (dest)] < 0)
1491 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1492 VEC_safe_push (rtx, heap, *next, dest);
1497 return cur_args_size;
1500 /* Walk the whole function and compute args_size on BARRIERs. */
1503 compute_barrier_args_size (void)
1505 int max_uid = get_max_uid (), i;
1507 VEC (rtx, heap) *worklist, *next, *tmp;
1509 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1510 for (i = 0; i < max_uid; i++)
1511 barrier_args_size[i] = -1;
1513 worklist = VEC_alloc (rtx, heap, 20);
1514 next = VEC_alloc (rtx, heap, 20);
1515 insn = get_insns ();
1516 barrier_args_size[INSN_UID (insn)] = 0;
1517 VEC_quick_push (rtx, worklist, insn);
1520 while (!VEC_empty (rtx, worklist))
1522 rtx prev, body, first_insn;
1523 HOST_WIDE_INT cur_args_size;
1525 first_insn = insn = VEC_pop (rtx, worklist);
1526 cur_args_size = barrier_args_size[INSN_UID (insn)];
1527 prev = prev_nonnote_insn (insn);
1528 if (prev && BARRIER_P (prev))
1529 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1531 for (; insn; insn = NEXT_INSN (insn))
1533 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1535 if (BARRIER_P (insn))
1540 if (insn == first_insn)
1542 else if (barrier_args_size[INSN_UID (insn)] < 0)
1544 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1549 /* The insns starting with this label have been
1550 already scanned or are in the worklist. */
1555 body = PATTERN (insn);
1556 if (GET_CODE (body) == SEQUENCE)
1558 HOST_WIDE_INT dest_args_size = cur_args_size;
1559 for (i = 1; i < XVECLEN (body, 0); i++)
1560 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1561 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1563 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1564 dest_args_size, &next);
1567 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1568 cur_args_size, &next);
1570 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1571 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1572 dest_args_size, &next);
1575 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1576 cur_args_size, &next);
1580 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1584 if (VEC_empty (rtx, next))
1587 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1591 VEC_truncate (rtx, next, 0);
1594 VEC_free (rtx, heap, worklist);
1595 VEC_free (rtx, heap, next);
1598 /* Add a CFI to update the running total of the size of arguments
1599 pushed onto the stack. */
1602 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1606 if (size == old_args_size)
1609 old_args_size = size;
1612 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1613 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1614 add_fde_cfi (label, cfi);
1617 /* Record a stack adjustment of OFFSET bytes. */
1620 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1622 if (cfa.reg == STACK_POINTER_REGNUM)
1623 cfa.offset += offset;
1625 if (cfa_store.reg == STACK_POINTER_REGNUM)
1626 cfa_store.offset += offset;
1628 if (ACCUMULATE_OUTGOING_ARGS)
1631 #ifndef STACK_GROWS_DOWNWARD
1635 args_size += offset;
1639 def_cfa_1 (label, &cfa);
1640 if (flag_asynchronous_unwind_tables)
1641 dwarf2out_args_size (label, args_size);
1644 /* Check INSN to see if it looks like a push or a stack adjustment, and
1645 make a note of it if it does. EH uses this information to find out
1646 how much extra space it needs to pop off the stack. */
1649 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1651 HOST_WIDE_INT offset;
1655 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1656 with this function. Proper support would require all frame-related
1657 insns to be marked, and to be able to handle saving state around
1658 epilogues textually in the middle of the function. */
1659 if (prologue_epilogue_contains (insn))
1662 /* If INSN is an instruction from target of an annulled branch, the
1663 effects are for the target only and so current argument size
1664 shouldn't change at all. */
1666 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1667 && INSN_FROM_TARGET_P (insn))
1670 /* If only calls can throw, and we have a frame pointer,
1671 save up adjustments until we see the CALL_INSN. */
1672 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1674 if (CALL_P (insn) && !after_p)
1676 /* Extract the size of the args from the CALL rtx itself. */
1677 insn = PATTERN (insn);
1678 if (GET_CODE (insn) == PARALLEL)
1679 insn = XVECEXP (insn, 0, 0);
1680 if (GET_CODE (insn) == SET)
1681 insn = SET_SRC (insn);
1682 gcc_assert (GET_CODE (insn) == CALL);
1683 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1688 if (CALL_P (insn) && !after_p)
1690 if (!flag_asynchronous_unwind_tables)
1691 dwarf2out_args_size ("", args_size);
1694 else if (BARRIER_P (insn))
1696 /* Don't call compute_barrier_args_size () if the only
1697 BARRIER is at the end of function. */
1698 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1699 compute_barrier_args_size ();
1700 if (barrier_args_size == NULL)
1704 offset = barrier_args_size[INSN_UID (insn)];
1709 offset -= args_size;
1710 #ifndef STACK_GROWS_DOWNWARD
1714 else if (GET_CODE (PATTERN (insn)) == SET)
1715 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1716 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1717 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1719 /* There may be stack adjustments inside compound insns. Search
1721 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1722 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1723 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1732 label = dwarf2out_cfi_label (false);
1733 dwarf2out_stack_adjust (offset, label);
1736 /* We delay emitting a register save until either (a) we reach the end
1737 of the prologue or (b) the register is clobbered. This clusters
1738 register saves so that there are fewer pc advances. */
1740 struct GTY(()) queued_reg_save {
1741 struct queued_reg_save *next;
1743 HOST_WIDE_INT cfa_offset;
1747 static GTY(()) struct queued_reg_save *queued_reg_saves;
1749 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1750 struct GTY(()) reg_saved_in_data {
1755 /* A list of registers saved in other registers.
1756 The list intentionally has a small maximum capacity of 4; if your
1757 port needs more than that, you might consider implementing a
1758 more efficient data structure. */
1759 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1760 static GTY(()) size_t num_regs_saved_in_regs;
1762 static const char *last_reg_save_label;
1764 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1765 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1768 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1770 struct queued_reg_save *q;
1772 /* Duplicates waste space, but it's also necessary to remove them
1773 for correctness, since the queue gets output in reverse
1775 for (q = queued_reg_saves; q != NULL; q = q->next)
1776 if (REGNO (q->reg) == REGNO (reg))
1781 q = ggc_alloc_queued_reg_save ();
1782 q->next = queued_reg_saves;
1783 queued_reg_saves = q;
1787 q->cfa_offset = offset;
1788 q->saved_reg = sreg;
1790 last_reg_save_label = label;
1793 /* Output all the entries in QUEUED_REG_SAVES. */
1796 dwarf2out_flush_queued_reg_saves (void)
1798 struct queued_reg_save *q;
1800 for (q = queued_reg_saves; q; q = q->next)
1803 unsigned int reg, sreg;
1805 for (i = 0; i < num_regs_saved_in_regs; i++)
1806 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1808 if (q->saved_reg && i == num_regs_saved_in_regs)
1810 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1811 num_regs_saved_in_regs++;
1813 if (i != num_regs_saved_in_regs)
1815 regs_saved_in_regs[i].orig_reg = q->reg;
1816 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1819 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1821 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1823 sreg = INVALID_REGNUM;
1824 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1827 queued_reg_saves = NULL;
1828 last_reg_save_label = NULL;
1831 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1832 location for? Or, does it clobber a register which we've previously
1833 said that some other register is saved in, and for which we now
1834 have a new location for? */
1837 clobbers_queued_reg_save (const_rtx insn)
1839 struct queued_reg_save *q;
1841 for (q = queued_reg_saves; q; q = q->next)
1844 if (modified_in_p (q->reg, insn))
1846 for (i = 0; i < num_regs_saved_in_regs; i++)
1847 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1848 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1855 /* Entry point for saving the first register into the second. */
1858 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1861 unsigned int regno, sregno;
1863 for (i = 0; i < num_regs_saved_in_regs; i++)
1864 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1866 if (i == num_regs_saved_in_regs)
1868 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1869 num_regs_saved_in_regs++;
1871 regs_saved_in_regs[i].orig_reg = reg;
1872 regs_saved_in_regs[i].saved_in_reg = sreg;
1874 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1875 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1876 reg_save (label, regno, sregno, 0);
1879 /* What register, if any, is currently saved in REG? */
1882 reg_saved_in (rtx reg)
1884 unsigned int regn = REGNO (reg);
1886 struct queued_reg_save *q;
1888 for (q = queued_reg_saves; q; q = q->next)
1889 if (q->saved_reg && regn == REGNO (q->saved_reg))
1892 for (i = 0; i < num_regs_saved_in_regs; i++)
1893 if (regs_saved_in_regs[i].saved_in_reg
1894 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1895 return regs_saved_in_regs[i].orig_reg;
1901 /* A temporary register holding an integral value used in adjusting SP
1902 or setting up the store_reg. The "offset" field holds the integer
1903 value, not an offset. */
1904 static dw_cfa_location cfa_temp;
1906 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1909 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1911 memset (&cfa, 0, sizeof (cfa));
1913 switch (GET_CODE (pat))
1916 cfa.reg = REGNO (XEXP (pat, 0));
1917 cfa.offset = INTVAL (XEXP (pat, 1));
1921 cfa.reg = REGNO (pat);
1926 pat = XEXP (pat, 0);
1927 if (GET_CODE (pat) == PLUS)
1929 cfa.base_offset = INTVAL (XEXP (pat, 1));
1930 pat = XEXP (pat, 0);
1932 cfa.reg = REGNO (pat);
1936 /* Recurse and define an expression. */
1940 def_cfa_1 (label, &cfa);
1943 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1946 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1950 gcc_assert (GET_CODE (pat) == SET);
1951 dest = XEXP (pat, 0);
1952 src = XEXP (pat, 1);
1954 switch (GET_CODE (src))
1957 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1958 cfa.offset -= INTVAL (XEXP (src, 1));
1968 cfa.reg = REGNO (dest);
1969 gcc_assert (cfa.indirect == 0);
1971 def_cfa_1 (label, &cfa);
1974 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1977 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1979 HOST_WIDE_INT offset;
1980 rtx src, addr, span;
1982 src = XEXP (set, 1);
1983 addr = XEXP (set, 0);
1984 gcc_assert (MEM_P (addr));
1985 addr = XEXP (addr, 0);
1987 /* As documented, only consider extremely simple addresses. */
1988 switch (GET_CODE (addr))
1991 gcc_assert (REGNO (addr) == cfa.reg);
1992 offset = -cfa.offset;
1995 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1996 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2002 span = targetm.dwarf_register_span (src);
2004 /* ??? We'd like to use queue_reg_save, but we need to come up with
2005 a different flushing heuristic for epilogues. */
2007 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2010 /* We have a PARALLEL describing where the contents of SRC live.
2011 Queue register saves for each piece of the PARALLEL. */
2014 HOST_WIDE_INT span_offset = offset;
2016 gcc_assert (GET_CODE (span) == PARALLEL);
2018 limit = XVECLEN (span, 0);
2019 for (par_index = 0; par_index < limit; par_index++)
2021 rtx elem = XVECEXP (span, 0, par_index);
2023 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2024 INVALID_REGNUM, span_offset);
2025 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2030 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2033 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2036 unsigned sregno, dregno;
2038 src = XEXP (set, 1);
2039 dest = XEXP (set, 0);
2042 sregno = DWARF_FRAME_RETURN_COLUMN;
2044 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2046 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2048 /* ??? We'd like to use queue_reg_save, but we need to come up with
2049 a different flushing heuristic for epilogues. */
2050 reg_save (label, sregno, dregno, 0);
2053 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2056 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2058 rtx src, dest, span;
2059 dw_cfi_ref cfi = new_cfi ();
2061 dest = SET_DEST (set);
2062 src = SET_SRC (set);
2064 gcc_assert (REG_P (src));
2065 gcc_assert (MEM_P (dest));
2067 span = targetm.dwarf_register_span (src);
2070 cfi->dw_cfi_opc = DW_CFA_expression;
2071 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2072 cfi->dw_cfi_oprnd2.dw_cfi_loc
2073 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
2074 VAR_INIT_STATUS_INITIALIZED);
2076 /* ??? We'd like to use queue_reg_save, were the interface different,
2077 and, as above, we could manage flushing for epilogues. */
2078 add_fde_cfi (label, cfi);
2081 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2084 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2086 dw_cfi_ref cfi = new_cfi ();
2087 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2089 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2090 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2092 add_fde_cfi (label, cfi);
2095 /* Record call frame debugging information for an expression EXPR,
2096 which either sets SP or FP (adjusting how we calculate the frame
2097 address) or saves a register to the stack or another register.
2098 LABEL indicates the address of EXPR.
2100 This function encodes a state machine mapping rtxes to actions on
2101 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2102 users need not read the source code.
2104 The High-Level Picture
2106 Changes in the register we use to calculate the CFA: Currently we
2107 assume that if you copy the CFA register into another register, we
2108 should take the other one as the new CFA register; this seems to
2109 work pretty well. If it's wrong for some target, it's simple
2110 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2112 Changes in the register we use for saving registers to the stack:
2113 This is usually SP, but not always. Again, we deduce that if you
2114 copy SP into another register (and SP is not the CFA register),
2115 then the new register is the one we will be using for register
2116 saves. This also seems to work.
2118 Register saves: There's not much guesswork about this one; if
2119 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2120 register save, and the register used to calculate the destination
2121 had better be the one we think we're using for this purpose.
2122 It's also assumed that a copy from a call-saved register to another
2123 register is saving that register if RTX_FRAME_RELATED_P is set on
2124 that instruction. If the copy is from a call-saved register to
2125 the *same* register, that means that the register is now the same
2126 value as in the caller.
2128 Except: If the register being saved is the CFA register, and the
2129 offset is nonzero, we are saving the CFA, so we assume we have to
2130 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2131 the intent is to save the value of SP from the previous frame.
2133 In addition, if a register has previously been saved to a different
2136 Invariants / Summaries of Rules
2138 cfa current rule for calculating the CFA. It usually
2139 consists of a register and an offset.
2140 cfa_store register used by prologue code to save things to the stack
2141 cfa_store.offset is the offset from the value of
2142 cfa_store.reg to the actual CFA
2143 cfa_temp register holding an integral value. cfa_temp.offset
2144 stores the value, which will be used to adjust the
2145 stack pointer. cfa_temp is also used like cfa_store,
2146 to track stores to the stack via fp or a temp reg.
2148 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2149 with cfa.reg as the first operand changes the cfa.reg and its
2150 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2153 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2154 expression yielding a constant. This sets cfa_temp.reg
2155 and cfa_temp.offset.
2157 Rule 5: Create a new register cfa_store used to save items to the
2160 Rules 10-14: Save a register to the stack. Define offset as the
2161 difference of the original location and cfa_store's
2162 location (or cfa_temp's location if cfa_temp is used).
2164 Rules 16-20: If AND operation happens on sp in prologue, we assume
2165 stack is realigned. We will use a group of DW_OP_XXX
2166 expressions to represent the location of the stored
2167 register instead of CFA+offset.
2171 "{a,b}" indicates a choice of a xor b.
2172 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2175 (set <reg1> <reg2>:cfa.reg)
2176 effects: cfa.reg = <reg1>
2177 cfa.offset unchanged
2178 cfa_temp.reg = <reg1>
2179 cfa_temp.offset = cfa.offset
2182 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2183 {<const_int>,<reg>:cfa_temp.reg}))
2184 effects: cfa.reg = sp if fp used
2185 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2186 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2187 if cfa_store.reg==sp
2190 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2191 effects: cfa.reg = fp
2192 cfa_offset += +/- <const_int>
2195 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2196 constraints: <reg1> != fp
2198 effects: cfa.reg = <reg1>
2199 cfa_temp.reg = <reg1>
2200 cfa_temp.offset = cfa.offset
2203 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2204 constraints: <reg1> != fp
2206 effects: cfa_store.reg = <reg1>
2207 cfa_store.offset = cfa.offset - cfa_temp.offset
2210 (set <reg> <const_int>)
2211 effects: cfa_temp.reg = <reg>
2212 cfa_temp.offset = <const_int>
2215 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2216 effects: cfa_temp.reg = <reg1>
2217 cfa_temp.offset |= <const_int>
2220 (set <reg> (high <exp>))
2224 (set <reg> (lo_sum <exp> <const_int>))
2225 effects: cfa_temp.reg = <reg>
2226 cfa_temp.offset = <const_int>
2229 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2230 effects: cfa_store.offset -= <const_int>
2231 cfa.offset = cfa_store.offset if cfa.reg == sp
2233 cfa.base_offset = -cfa_store.offset
2236 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2237 effects: cfa_store.offset += -/+ mode_size(mem)
2238 cfa.offset = cfa_store.offset if cfa.reg == sp
2240 cfa.base_offset = -cfa_store.offset
2243 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2246 effects: cfa.reg = <reg1>
2247 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2250 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2251 effects: cfa.reg = <reg1>
2252 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2255 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2256 effects: cfa.reg = <reg1>
2257 cfa.base_offset = -cfa_temp.offset
2258 cfa_temp.offset -= mode_size(mem)
2261 (set <reg> {unspec, unspec_volatile})
2262 effects: target-dependent
2265 (set sp (and: sp <const_int>))
2266 constraints: cfa_store.reg == sp
2267 effects: current_fde.stack_realign = 1
2268 cfa_store.offset = 0
2269 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2272 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2273 effects: cfa_store.offset += -/+ mode_size(mem)
2276 (set (mem ({pre_inc, pre_dec} sp)) fp)
2277 constraints: fde->stack_realign == 1
2278 effects: cfa_store.offset = 0
2279 cfa.reg != HARD_FRAME_POINTER_REGNUM
2282 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2283 constraints: fde->stack_realign == 1
2285 && cfa.indirect == 0
2286 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2287 effects: Use DW_CFA_def_cfa_expression to define cfa
2288 cfa.reg == fde->drap_reg */
2291 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2293 rtx src, dest, span;
2294 HOST_WIDE_INT offset;
2297 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2298 the PARALLEL independently. The first element is always processed if
2299 it is a SET. This is for backward compatibility. Other elements
2300 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2301 flag is set in them. */
2302 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2305 int limit = XVECLEN (expr, 0);
2308 /* PARALLELs have strict read-modify-write semantics, so we
2309 ought to evaluate every rvalue before changing any lvalue.
2310 It's cumbersome to do that in general, but there's an
2311 easy approximation that is enough for all current users:
2312 handle register saves before register assignments. */
2313 if (GET_CODE (expr) == PARALLEL)
2314 for (par_index = 0; par_index < limit; par_index++)
2316 elem = XVECEXP (expr, 0, par_index);
2317 if (GET_CODE (elem) == SET
2318 && MEM_P (SET_DEST (elem))
2319 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2320 dwarf2out_frame_debug_expr (elem, label);
2323 for (par_index = 0; par_index < limit; par_index++)
2325 elem = XVECEXP (expr, 0, par_index);
2326 if (GET_CODE (elem) == SET
2327 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2328 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2329 dwarf2out_frame_debug_expr (elem, label);
2330 else if (GET_CODE (elem) == SET
2332 && !RTX_FRAME_RELATED_P (elem))
2334 /* Stack adjustment combining might combine some post-prologue
2335 stack adjustment into a prologue stack adjustment. */
2336 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2339 dwarf2out_stack_adjust (offset, label);
2345 gcc_assert (GET_CODE (expr) == SET);
2347 src = SET_SRC (expr);
2348 dest = SET_DEST (expr);
2352 rtx rsi = reg_saved_in (src);
2357 fde = current_fde ();
2359 switch (GET_CODE (dest))
2362 switch (GET_CODE (src))
2364 /* Setting FP from SP. */
2366 if (cfa.reg == (unsigned) REGNO (src))
2369 /* Update the CFA rule wrt SP or FP. Make sure src is
2370 relative to the current CFA register.
2372 We used to require that dest be either SP or FP, but the
2373 ARM copies SP to a temporary register, and from there to
2374 FP. So we just rely on the backends to only set
2375 RTX_FRAME_RELATED_P on appropriate insns. */
2376 cfa.reg = REGNO (dest);
2377 cfa_temp.reg = cfa.reg;
2378 cfa_temp.offset = cfa.offset;
2382 /* Saving a register in a register. */
2383 gcc_assert (!fixed_regs [REGNO (dest)]
2384 /* For the SPARC and its register window. */
2385 || (DWARF_FRAME_REGNUM (REGNO (src))
2386 == DWARF_FRAME_RETURN_COLUMN));
2388 /* After stack is aligned, we can only save SP in FP
2389 if drap register is used. In this case, we have
2390 to restore stack pointer with the CFA value and we
2391 don't generate this DWARF information. */
2393 && fde->stack_realign
2394 && REGNO (src) == STACK_POINTER_REGNUM)
2395 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2396 && fde->drap_reg != INVALID_REGNUM
2397 && cfa.reg != REGNO (src));
2399 queue_reg_save (label, src, dest, 0);
2406 if (dest == stack_pointer_rtx)
2410 switch (GET_CODE (XEXP (src, 1)))
2413 offset = INTVAL (XEXP (src, 1));
2416 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2418 offset = cfa_temp.offset;
2424 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2426 /* Restoring SP from FP in the epilogue. */
2427 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2428 cfa.reg = STACK_POINTER_REGNUM;
2430 else if (GET_CODE (src) == LO_SUM)
2431 /* Assume we've set the source reg of the LO_SUM from sp. */
2434 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2436 if (GET_CODE (src) != MINUS)
2438 if (cfa.reg == STACK_POINTER_REGNUM)
2439 cfa.offset += offset;
2440 if (cfa_store.reg == STACK_POINTER_REGNUM)
2441 cfa_store.offset += offset;
2443 else if (dest == hard_frame_pointer_rtx)
2446 /* Either setting the FP from an offset of the SP,
2447 or adjusting the FP */
2448 gcc_assert (frame_pointer_needed);
2450 gcc_assert (REG_P (XEXP (src, 0))
2451 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2452 && CONST_INT_P (XEXP (src, 1)));
2453 offset = INTVAL (XEXP (src, 1));
2454 if (GET_CODE (src) != MINUS)
2456 cfa.offset += offset;
2457 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2461 gcc_assert (GET_CODE (src) != MINUS);
2464 if (REG_P (XEXP (src, 0))
2465 && REGNO (XEXP (src, 0)) == cfa.reg
2466 && CONST_INT_P (XEXP (src, 1)))
2468 /* Setting a temporary CFA register that will be copied
2469 into the FP later on. */
2470 offset = - INTVAL (XEXP (src, 1));
2471 cfa.offset += offset;
2472 cfa.reg = REGNO (dest);
2473 /* Or used to save regs to the stack. */
2474 cfa_temp.reg = cfa.reg;
2475 cfa_temp.offset = cfa.offset;
2479 else if (REG_P (XEXP (src, 0))
2480 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2481 && XEXP (src, 1) == stack_pointer_rtx)
2483 /* Setting a scratch register that we will use instead
2484 of SP for saving registers to the stack. */
2485 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2486 cfa_store.reg = REGNO (dest);
2487 cfa_store.offset = cfa.offset - cfa_temp.offset;
2491 else if (GET_CODE (src) == LO_SUM
2492 && CONST_INT_P (XEXP (src, 1)))
2494 cfa_temp.reg = REGNO (dest);
2495 cfa_temp.offset = INTVAL (XEXP (src, 1));
2504 cfa_temp.reg = REGNO (dest);
2505 cfa_temp.offset = INTVAL (src);
2510 gcc_assert (REG_P (XEXP (src, 0))
2511 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2512 && CONST_INT_P (XEXP (src, 1)));
2514 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2515 cfa_temp.reg = REGNO (dest);
2516 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2519 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2520 which will fill in all of the bits. */
2527 case UNSPEC_VOLATILE:
2528 gcc_assert (targetm.dwarf_handle_frame_unspec);
2529 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2534 /* If this AND operation happens on stack pointer in prologue,
2535 we assume the stack is realigned and we extract the
2537 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2539 /* We interpret reg_save differently with stack_realign set.
2540 Thus we must flush whatever we have queued first. */
2541 dwarf2out_flush_queued_reg_saves ();
2543 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2544 fde->stack_realign = 1;
2545 fde->stack_realignment = INTVAL (XEXP (src, 1));
2546 cfa_store.offset = 0;
2548 if (cfa.reg != STACK_POINTER_REGNUM
2549 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2550 fde->drap_reg = cfa.reg;
2558 def_cfa_1 (label, &cfa);
2563 /* Saving a register to the stack. Make sure dest is relative to the
2565 switch (GET_CODE (XEXP (dest, 0)))
2570 /* We can't handle variable size modifications. */
2571 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2573 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2575 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2576 && cfa_store.reg == STACK_POINTER_REGNUM);
2578 cfa_store.offset += offset;
2579 if (cfa.reg == STACK_POINTER_REGNUM)
2580 cfa.offset = cfa_store.offset;
2582 offset = -cfa_store.offset;
2589 offset = GET_MODE_SIZE (GET_MODE (dest));
2590 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2593 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2594 == STACK_POINTER_REGNUM)
2595 && cfa_store.reg == STACK_POINTER_REGNUM);
2597 cfa_store.offset += offset;
2599 /* Rule 18: If stack is aligned, we will use FP as a
2600 reference to represent the address of the stored
2603 && fde->stack_realign
2604 && src == hard_frame_pointer_rtx)
2606 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2607 cfa_store.offset = 0;
2610 if (cfa.reg == STACK_POINTER_REGNUM)
2611 cfa.offset = cfa_store.offset;
2613 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
2614 offset += -cfa_store.offset;
2616 offset = -cfa_store.offset;
2620 /* With an offset. */
2627 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2628 && REG_P (XEXP (XEXP (dest, 0), 0)));
2629 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2630 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2633 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2635 if (cfa.reg == (unsigned) regno)
2636 offset -= cfa.offset;
2637 else if (cfa_store.reg == (unsigned) regno)
2638 offset -= cfa_store.offset;
2641 gcc_assert (cfa_temp.reg == (unsigned) regno);
2642 offset -= cfa_temp.offset;
2648 /* Without an offset. */
2651 int regno = REGNO (XEXP (dest, 0));
2653 if (cfa.reg == (unsigned) regno)
2654 offset = -cfa.offset;
2655 else if (cfa_store.reg == (unsigned) regno)
2656 offset = -cfa_store.offset;
2659 gcc_assert (cfa_temp.reg == (unsigned) regno);
2660 offset = -cfa_temp.offset;
2667 gcc_assert (cfa_temp.reg
2668 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2669 offset = -cfa_temp.offset;
2670 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2678 /* If the source operand of this MEM operation is not a
2679 register, basically the source is return address. Here
2680 we only care how much stack grew and we don't save it. */
2684 if (REGNO (src) != STACK_POINTER_REGNUM
2685 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2686 && (unsigned) REGNO (src) == cfa.reg)
2688 /* We're storing the current CFA reg into the stack. */
2690 if (cfa.offset == 0)
2693 /* If stack is aligned, putting CFA reg into stack means
2694 we can no longer use reg + offset to represent CFA.
2695 Here we use DW_CFA_def_cfa_expression instead. The
2696 result of this expression equals to the original CFA
2699 && fde->stack_realign
2700 && cfa.indirect == 0
2701 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2703 dw_cfa_location cfa_exp;
2705 gcc_assert (fde->drap_reg == cfa.reg);
2707 cfa_exp.indirect = 1;
2708 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2709 cfa_exp.base_offset = offset;
2712 fde->drap_reg_saved = 1;
2714 def_cfa_1 (label, &cfa_exp);
2718 /* If the source register is exactly the CFA, assume
2719 we're saving SP like any other register; this happens
2721 def_cfa_1 (label, &cfa);
2722 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2727 /* Otherwise, we'll need to look in the stack to
2728 calculate the CFA. */
2729 rtx x = XEXP (dest, 0);
2733 gcc_assert (REG_P (x));
2735 cfa.reg = REGNO (x);
2736 cfa.base_offset = offset;
2738 def_cfa_1 (label, &cfa);
2743 def_cfa_1 (label, &cfa);
2745 span = targetm.dwarf_register_span (src);
2748 queue_reg_save (label, src, NULL_RTX, offset);
2751 /* We have a PARALLEL describing where the contents of SRC
2752 live. Queue register saves for each piece of the
2756 HOST_WIDE_INT span_offset = offset;
2758 gcc_assert (GET_CODE (span) == PARALLEL);
2760 limit = XVECLEN (span, 0);
2761 for (par_index = 0; par_index < limit; par_index++)
2763 rtx elem = XVECEXP (span, 0, par_index);
2765 queue_reg_save (label, elem, NULL_RTX, span_offset);
2766 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2777 /* Record call frame debugging information for INSN, which either
2778 sets SP or FP (adjusting how we calculate the frame address) or saves a
2779 register to the stack. If INSN is NULL_RTX, initialize our state.
2781 If AFTER_P is false, we're being called before the insn is emitted,
2782 otherwise after. Call instructions get invoked twice. */
2785 dwarf2out_frame_debug (rtx insn, bool after_p)
2789 bool handled_one = false;
2791 if (insn == NULL_RTX)
2795 /* Flush any queued register saves. */
2796 dwarf2out_flush_queued_reg_saves ();
2798 /* Set up state for generating call frame debug info. */
2801 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2803 cfa.reg = STACK_POINTER_REGNUM;
2806 cfa_temp.offset = 0;
2808 for (i = 0; i < num_regs_saved_in_regs; i++)
2810 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2811 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2813 num_regs_saved_in_regs = 0;
2815 if (barrier_args_size)
2817 XDELETEVEC (barrier_args_size);
2818 barrier_args_size = NULL;
2823 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2824 dwarf2out_flush_queued_reg_saves ();
2826 if (!RTX_FRAME_RELATED_P (insn))
2828 /* ??? This should be done unconditionally since stack adjustments
2829 matter if the stack pointer is not the CFA register anymore but
2830 is still used to save registers. */
2831 if (!ACCUMULATE_OUTGOING_ARGS)
2832 dwarf2out_notice_stack_adjust (insn, after_p);
2836 label = dwarf2out_cfi_label (false);
2837 any_cfis_emitted = false;
2839 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2840 switch (REG_NOTE_KIND (note))
2842 case REG_FRAME_RELATED_EXPR:
2843 insn = XEXP (note, 0);
2846 case REG_CFA_DEF_CFA:
2847 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2851 case REG_CFA_ADJUST_CFA:
2856 if (GET_CODE (n) == PARALLEL)
2857 n = XVECEXP (n, 0, 0);
2859 dwarf2out_frame_debug_adjust_cfa (n, label);
2863 case REG_CFA_OFFSET:
2866 n = single_set (insn);
2867 dwarf2out_frame_debug_cfa_offset (n, label);
2871 case REG_CFA_REGISTER:
2876 if (GET_CODE (n) == PARALLEL)
2877 n = XVECEXP (n, 0, 0);
2879 dwarf2out_frame_debug_cfa_register (n, label);
2883 case REG_CFA_EXPRESSION:
2886 n = single_set (insn);
2887 dwarf2out_frame_debug_cfa_expression (n, label);
2891 case REG_CFA_RESTORE:
2896 if (GET_CODE (n) == PARALLEL)
2897 n = XVECEXP (n, 0, 0);
2900 dwarf2out_frame_debug_cfa_restore (n, label);
2904 case REG_CFA_SET_VDRAP:
2908 dw_fde_ref fde = current_fde ();
2911 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2913 fde->vdrap_reg = REGNO (n);
2924 if (any_cfis_emitted)
2925 dwarf2out_flush_queued_reg_saves ();
2929 insn = PATTERN (insn);
2931 dwarf2out_frame_debug_expr (insn, label);
2933 /* Check again. A parallel can save and update the same register.
2934 We could probably check just once, here, but this is safer than
2935 removing the check above. */
2936 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2937 dwarf2out_flush_queued_reg_saves ();
2940 /* Determine if we need to save and restore CFI information around this
2941 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2942 we do need to save/restore, then emit the save now, and insert a
2943 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2946 dwarf2out_cfi_begin_epilogue (rtx insn)
2948 bool saw_frp = false;
2951 /* Scan forward to the return insn, noticing if there are possible
2952 frame related insns. */
2953 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2958 /* Look for both regular and sibcalls to end the block. */
2959 if (returnjump_p (i))
2961 if (CALL_P (i) && SIBLING_CALL_P (i))
2964 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2967 rtx seq = PATTERN (i);
2969 if (returnjump_p (XVECEXP (seq, 0, 0)))
2971 if (CALL_P (XVECEXP (seq, 0, 0))
2972 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2975 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2976 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2980 if (RTX_FRAME_RELATED_P (i))
2984 /* If the port doesn't emit epilogue unwind info, we don't need a
2985 save/restore pair. */
2989 /* Otherwise, search forward to see if the return insn was the last
2990 basic block of the function. If so, we don't need save/restore. */
2991 gcc_assert (i != NULL);
2992 i = next_real_insn (i);
2996 /* Insert the restore before that next real insn in the stream, and before
2997 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2998 properly nested. This should be after any label or alignment. This
2999 will be pushed into the CFI stream by the function below. */
3002 rtx p = PREV_INSN (i);
3005 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3009 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3011 emit_cfa_remember = true;
3013 /* And emulate the state save. */
3014 gcc_assert (!cfa_remember.in_use);
3016 cfa_remember.in_use = 1;
3019 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3023 dwarf2out_frame_debug_restore_state (void)
3025 dw_cfi_ref cfi = new_cfi ();
3026 const char *label = dwarf2out_cfi_label (false);
3028 cfi->dw_cfi_opc = DW_CFA_restore_state;
3029 add_fde_cfi (label, cfi);
3031 gcc_assert (cfa_remember.in_use);
3033 cfa_remember.in_use = 0;
3036 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3037 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3038 (enum dwarf_call_frame_info cfi);
3040 static enum dw_cfi_oprnd_type
3041 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3046 case DW_CFA_GNU_window_save:
3047 case DW_CFA_remember_state:
3048 case DW_CFA_restore_state:
3049 return dw_cfi_oprnd_unused;
3051 case DW_CFA_set_loc:
3052 case DW_CFA_advance_loc1:
3053 case DW_CFA_advance_loc2:
3054 case DW_CFA_advance_loc4:
3055 case DW_CFA_MIPS_advance_loc8:
3056 return dw_cfi_oprnd_addr;
3059 case DW_CFA_offset_extended:
3060 case DW_CFA_def_cfa:
3061 case DW_CFA_offset_extended_sf:
3062 case DW_CFA_def_cfa_sf:
3063 case DW_CFA_restore:
3064 case DW_CFA_restore_extended:
3065 case DW_CFA_undefined:
3066 case DW_CFA_same_value:
3067 case DW_CFA_def_cfa_register:
3068 case DW_CFA_register:
3069 case DW_CFA_expression:
3070 return dw_cfi_oprnd_reg_num;
3072 case DW_CFA_def_cfa_offset:
3073 case DW_CFA_GNU_args_size:
3074 case DW_CFA_def_cfa_offset_sf:
3075 return dw_cfi_oprnd_offset;
3077 case DW_CFA_def_cfa_expression:
3078 return dw_cfi_oprnd_loc;
3085 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3086 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3087 (enum dwarf_call_frame_info cfi);
3089 static enum dw_cfi_oprnd_type
3090 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3094 case DW_CFA_def_cfa:
3095 case DW_CFA_def_cfa_sf:
3097 case DW_CFA_offset_extended_sf:
3098 case DW_CFA_offset_extended:
3099 return dw_cfi_oprnd_offset;
3101 case DW_CFA_register:
3102 return dw_cfi_oprnd_reg_num;
3104 case DW_CFA_expression:
3105 return dw_cfi_oprnd_loc;
3108 return dw_cfi_oprnd_unused;
3112 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3113 switch to the data section instead, and write out a synthetic start label
3114 for collect2 the first time around. */
3117 switch_to_eh_frame_section (bool back)
3121 #ifdef EH_FRAME_SECTION_NAME
3122 if (eh_frame_section == 0)
3126 if (EH_TABLES_CAN_BE_READ_ONLY)
3132 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3134 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3136 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3138 flags = ((! flag_pic
3139 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3140 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3141 && (per_encoding & 0x70) != DW_EH_PE_absptr
3142 && (per_encoding & 0x70) != DW_EH_PE_aligned
3143 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3144 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3145 ? 0 : SECTION_WRITE);
3148 flags = SECTION_WRITE;
3149 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3151 #endif /* EH_FRAME_SECTION_NAME */
3153 if (eh_frame_section)
3154 switch_to_section (eh_frame_section);
3157 /* We have no special eh_frame section. Put the information in
3158 the data section and emit special labels to guide collect2. */
3159 switch_to_section (data_section);
3163 label = get_file_function_name ("F");
3164 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3165 targetm.asm_out.globalize_label (asm_out_file,
3166 IDENTIFIER_POINTER (label));
3167 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3172 /* Switch [BACK] to the eh or debug frame table section, depending on
3176 switch_to_frame_table_section (int for_eh, bool back)
3179 switch_to_eh_frame_section (back);
3182 if (!debug_frame_section)
3183 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3184 SECTION_DEBUG, NULL);
3185 switch_to_section (debug_frame_section);
3189 /* Output a Call Frame Information opcode and its operand(s). */
3192 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3197 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3198 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3199 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3200 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3201 ((unsigned HOST_WIDE_INT)
3202 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3203 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3205 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3206 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3207 "DW_CFA_offset, column %#lx", r);
3208 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3209 dw2_asm_output_data_uleb128 (off, NULL);
3211 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3213 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3214 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3215 "DW_CFA_restore, column %#lx", r);
3219 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3220 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3222 switch (cfi->dw_cfi_opc)
3224 case DW_CFA_set_loc:
3226 dw2_asm_output_encoded_addr_rtx (
3227 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3228 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3231 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3232 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3233 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3236 case DW_CFA_advance_loc1:
3237 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3238 fde->dw_fde_current_label, NULL);
3239 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3242 case DW_CFA_advance_loc2:
3243 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3244 fde->dw_fde_current_label, NULL);
3245 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3248 case DW_CFA_advance_loc4:
3249 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3250 fde->dw_fde_current_label, NULL);
3251 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3254 case DW_CFA_MIPS_advance_loc8:
3255 dw2_asm_output_delta (8, 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_offset_extended:
3261 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3262 dw2_asm_output_data_uleb128 (r, NULL);
3263 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3264 dw2_asm_output_data_uleb128 (off, NULL);
3267 case DW_CFA_def_cfa:
3268 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3269 dw2_asm_output_data_uleb128 (r, NULL);
3270 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3273 case DW_CFA_offset_extended_sf:
3274 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3275 dw2_asm_output_data_uleb128 (r, NULL);
3276 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3277 dw2_asm_output_data_sleb128 (off, NULL);
3280 case DW_CFA_def_cfa_sf:
3281 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3282 dw2_asm_output_data_uleb128 (r, NULL);
3283 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3284 dw2_asm_output_data_sleb128 (off, NULL);
3287 case DW_CFA_restore_extended:
3288 case DW_CFA_undefined:
3289 case DW_CFA_same_value:
3290 case DW_CFA_def_cfa_register:
3291 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3292 dw2_asm_output_data_uleb128 (r, NULL);
3295 case DW_CFA_register:
3296 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3297 dw2_asm_output_data_uleb128 (r, NULL);
3298 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3299 dw2_asm_output_data_uleb128 (r, NULL);
3302 case DW_CFA_def_cfa_offset:
3303 case DW_CFA_GNU_args_size:
3304 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3307 case DW_CFA_def_cfa_offset_sf:
3308 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3309 dw2_asm_output_data_sleb128 (off, NULL);
3312 case DW_CFA_GNU_window_save:
3315 case DW_CFA_def_cfa_expression:
3316 case DW_CFA_expression:
3317 output_cfa_loc (cfi, for_eh);
3320 case DW_CFA_GNU_negative_offset_extended:
3321 /* Obsoleted by DW_CFA_offset_extended_sf. */
3330 /* Similar, but do it via assembler directives instead. */
3333 output_cfi_directive (dw_cfi_ref cfi)
3335 unsigned long r, r2;
3337 switch (cfi->dw_cfi_opc)
3339 case DW_CFA_advance_loc:
3340 case DW_CFA_advance_loc1:
3341 case DW_CFA_advance_loc2:
3342 case DW_CFA_advance_loc4:
3343 case DW_CFA_MIPS_advance_loc8:
3344 case DW_CFA_set_loc:
3345 /* Should only be created by add_fde_cfi in a code path not
3346 followed when emitting via directives. The assembler is
3347 going to take care of this for us. */
3351 case DW_CFA_offset_extended:
3352 case DW_CFA_offset_extended_sf:
3353 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3354 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3355 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3358 case DW_CFA_restore:
3359 case DW_CFA_restore_extended:
3360 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3361 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3364 case DW_CFA_undefined:
3365 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3366 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3369 case DW_CFA_same_value:
3370 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3371 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3374 case DW_CFA_def_cfa:
3375 case DW_CFA_def_cfa_sf:
3376 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3377 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3378 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3381 case DW_CFA_def_cfa_register:
3382 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3383 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3386 case DW_CFA_register:
3387 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3388 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3389 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3392 case DW_CFA_def_cfa_offset:
3393 case DW_CFA_def_cfa_offset_sf:
3394 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3395 HOST_WIDE_INT_PRINT_DEC"\n",
3396 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3399 case DW_CFA_remember_state:
3400 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3402 case DW_CFA_restore_state:
3403 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3406 case DW_CFA_GNU_args_size:
3407 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3408 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3410 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3411 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3412 fputc ('\n', asm_out_file);
3415 case DW_CFA_GNU_window_save:
3416 fprintf (asm_out_file, "\t.cfi_window_save\n");
3419 case DW_CFA_def_cfa_expression:
3420 case DW_CFA_expression:
3421 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3422 output_cfa_loc_raw (cfi);
3423 fputc ('\n', asm_out_file);
3431 DEF_VEC_P (dw_cfi_ref);
3432 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3434 /* Output CFIs to bring current FDE to the same state as after executing
3435 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3436 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3437 other arguments to pass to output_cfi. */
3440 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3442 struct dw_cfi_struct cfi_buf;
3444 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3445 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3446 unsigned int len, idx;
3448 for (;; cfi = cfi->dw_cfi_next)
3449 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3451 case DW_CFA_advance_loc:
3452 case DW_CFA_advance_loc1:
3453 case DW_CFA_advance_loc2:
3454 case DW_CFA_advance_loc4:
3455 case DW_CFA_MIPS_advance_loc8:
3456 case DW_CFA_set_loc:
3457 /* All advances should be ignored. */
3459 case DW_CFA_remember_state:
3461 dw_cfi_ref args_size = cfi_args_size;
3463 /* Skip everything between .cfi_remember_state and
3464 .cfi_restore_state. */
3465 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3466 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3468 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3471 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3478 cfi_args_size = args_size;
3482 case DW_CFA_GNU_args_size:
3483 cfi_args_size = cfi;
3485 case DW_CFA_GNU_window_save:
3488 case DW_CFA_offset_extended:
3489 case DW_CFA_offset_extended_sf:
3490 case DW_CFA_restore:
3491 case DW_CFA_restore_extended:
3492 case DW_CFA_undefined:
3493 case DW_CFA_same_value:
3494 case DW_CFA_register:
3495 case DW_CFA_val_offset:
3496 case DW_CFA_val_offset_sf:
3497 case DW_CFA_expression:
3498 case DW_CFA_val_expression:
3499 case DW_CFA_GNU_negative_offset_extended:
3500 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3501 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3502 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3503 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3505 case DW_CFA_def_cfa:
3506 case DW_CFA_def_cfa_sf:
3507 case DW_CFA_def_cfa_expression:
3509 cfi_cfa_offset = cfi;
3511 case DW_CFA_def_cfa_register:
3514 case DW_CFA_def_cfa_offset:
3515 case DW_CFA_def_cfa_offset_sf:
3516 cfi_cfa_offset = cfi;
3519 gcc_assert (cfi == NULL);
3521 len = VEC_length (dw_cfi_ref, regs);
3522 for (idx = 0; idx < len; idx++)
3524 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3526 && cfi2->dw_cfi_opc != DW_CFA_restore
3527 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3530 output_cfi_directive (cfi2);
3532 output_cfi (cfi2, fde, for_eh);
3535 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3537 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3539 switch (cfi_cfa_offset->dw_cfi_opc)
3541 case DW_CFA_def_cfa_offset:
3542 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3543 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3545 case DW_CFA_def_cfa_offset_sf:
3546 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3547 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3549 case DW_CFA_def_cfa:
3550 case DW_CFA_def_cfa_sf:
3551 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3552 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3559 else if (cfi_cfa_offset)
3560 cfi_cfa = cfi_cfa_offset;
3564 output_cfi_directive (cfi_cfa);
3566 output_cfi (cfi_cfa, fde, for_eh);
3569 cfi_cfa_offset = NULL;
3571 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3574 output_cfi_directive (cfi_args_size);
3576 output_cfi (cfi_args_size, fde, for_eh);
3578 cfi_args_size = NULL;
3581 VEC_free (dw_cfi_ref, heap, regs);
3584 else if (do_cfi_asm)
3585 output_cfi_directive (cfi);
3587 output_cfi (cfi, fde, for_eh);
3594 /* Output one FDE. */
3597 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3598 char *section_start_label, int fde_encoding, char *augmentation,
3599 bool any_lsda_needed, int lsda_encoding)
3601 const char *begin, *end;
3602 static unsigned int j;
3603 char l1[20], l2[20];
3606 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3608 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3610 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3611 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3612 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3613 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3614 " indicating 64-bit DWARF extension");
3615 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3617 ASM_OUTPUT_LABEL (asm_out_file, l1);
3620 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3622 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3623 debug_frame_section, "FDE CIE offset");
3625 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
3626 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
3630 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3631 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3632 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3633 "FDE initial location");
3634 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3635 end, begin, "FDE address range");
3639 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3640 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3643 if (augmentation[0])
3645 if (any_lsda_needed)
3647 int size = size_of_encoded_value (lsda_encoding);
3649 if (lsda_encoding == DW_EH_PE_aligned)
3651 int offset = ( 4 /* Length */
3652 + 4 /* CIE offset */
3653 + 2 * size_of_encoded_value (fde_encoding)
3654 + 1 /* Augmentation size */ );
3655 int pad = -offset & (PTR_SIZE - 1);
3658 gcc_assert (size_of_uleb128 (size) == 1);
3661 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3663 if (fde->uses_eh_lsda)
3665 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3666 fde->funcdef_number);
3667 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3668 gen_rtx_SYMBOL_REF (Pmode, l1),
3670 "Language Specific Data Area");
3674 if (lsda_encoding == DW_EH_PE_aligned)
3675 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3676 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3677 "Language Specific Data Area (none)");
3681 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3684 /* Loop through the Call Frame Instructions associated with
3686 fde->dw_fde_current_label = begin;
3687 if (fde->dw_fde_second_begin == NULL)
3688 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3689 output_cfi (cfi, fde, for_eh);
3692 if (fde->dw_fde_switch_cfi)
3693 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3695 output_cfi (cfi, fde, for_eh);
3696 if (cfi == fde->dw_fde_switch_cfi)
3702 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3704 if (fde->dw_fde_switch_cfi)
3706 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3707 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3708 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3709 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3711 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3712 output_cfi (cfi, fde, for_eh);
3715 /* If we are to emit a ref/link from function bodies to their frame tables,
3716 do it now. This is typically performed to make sure that tables
3717 associated with functions are dragged with them and not discarded in
3718 garbage collecting links. We need to do this on a per function basis to
3719 cope with -ffunction-sections. */
3721 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3722 /* Switch to the function section, emit the ref to the tables, and
3723 switch *back* into the table section. */
3724 switch_to_section (function_section (fde->decl));
3725 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3726 switch_to_frame_table_section (for_eh, true);
3729 /* Pad the FDE out to an address sized boundary. */
3730 ASM_OUTPUT_ALIGN (asm_out_file,
3731 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3732 ASM_OUTPUT_LABEL (asm_out_file, l2);
3737 /* Return true if frame description entry FDE is needed for EH. */
3740 fde_needed_for_eh_p (dw_fde_ref fde)
3742 if (flag_asynchronous_unwind_tables)
3745 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3748 if (fde->uses_eh_lsda)
3751 /* If exceptions are enabled, we have collected nothrow info. */
3752 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3758 /* Output the call frame information used to record information
3759 that relates to calculating the frame pointer, and records the
3760 location of saved registers. */
3763 output_call_frame_info (int for_eh)
3768 char l1[20], l2[20], section_start_label[20];
3769 bool any_lsda_needed = false;
3770 char augmentation[6];
3771 int augmentation_size;
3772 int fde_encoding = DW_EH_PE_absptr;
3773 int per_encoding = DW_EH_PE_absptr;
3774 int lsda_encoding = DW_EH_PE_absptr;
3776 rtx personality = NULL;
3779 /* Don't emit a CIE if there won't be any FDEs. */
3780 if (fde_table_in_use == 0)
3783 /* Nothing to do if the assembler's doing it all. */
3784 if (dwarf2out_do_cfi_asm ())
3787 /* If we don't have any functions we'll want to unwind out of, don't emit
3788 any EH unwind information. If we make FDEs linkonce, we may have to
3789 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3790 want to avoid having an FDE kept around when the function it refers to
3791 is discarded. Example where this matters: a primary function template
3792 in C++ requires EH information, an explicit specialization doesn't. */
3795 bool any_eh_needed = false;
3797 for (i = 0; i < fde_table_in_use; i++)
3798 if (fde_table[i].uses_eh_lsda)
3799 any_eh_needed = any_lsda_needed = true;
3800 else if (fde_needed_for_eh_p (&fde_table[i]))
3801 any_eh_needed = true;
3802 else if (TARGET_USES_WEAK_UNWIND_INFO)
3803 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3810 /* We're going to be generating comments, so turn on app. */
3814 /* Switch to the proper frame section, first time. */
3815 switch_to_frame_table_section (for_eh, false);
3817 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3818 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3820 /* Output the CIE. */
3821 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3822 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3823 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3824 dw2_asm_output_data (4, 0xffffffff,
3825 "Initial length escape value indicating 64-bit DWARF extension");
3826 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3827 "Length of Common Information Entry");
3828 ASM_OUTPUT_LABEL (asm_out_file, l1);
3830 /* Now that the CIE pointer is PC-relative for EH,
3831 use 0 to identify the CIE. */
3832 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3833 (for_eh ? 0 : DWARF_CIE_ID),
3834 "CIE Identifier Tag");
3836 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3837 use CIE version 1, unless that would produce incorrect results
3838 due to overflowing the return register column. */
3839 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3841 if (return_reg >= 256 || dwarf_version > 2)
3843 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3845 augmentation[0] = 0;
3846 augmentation_size = 0;
3848 personality = current_unit_personality;
3854 z Indicates that a uleb128 is present to size the
3855 augmentation section.
3856 L Indicates the encoding (and thus presence) of
3857 an LSDA pointer in the FDE augmentation.
3858 R Indicates a non-default pointer encoding for
3860 P Indicates the presence of an encoding + language
3861 personality routine in the CIE augmentation. */
3863 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3864 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3865 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3867 p = augmentation + 1;
3871 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3872 assemble_external_libcall (personality);
3874 if (any_lsda_needed)
3877 augmentation_size += 1;
3879 if (fde_encoding != DW_EH_PE_absptr)
3882 augmentation_size += 1;
3884 if (p > augmentation + 1)
3886 augmentation[0] = 'z';
3890 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3891 if (personality && per_encoding == DW_EH_PE_aligned)
3893 int offset = ( 4 /* Length */
3895 + 1 /* CIE version */
3896 + strlen (augmentation) + 1 /* Augmentation */
3897 + size_of_uleb128 (1) /* Code alignment */
3898 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3900 + 1 /* Augmentation size */
3901 + 1 /* Personality encoding */ );
3902 int pad = -offset & (PTR_SIZE - 1);
3904 augmentation_size += pad;
3906 /* Augmentations should be small, so there's scarce need to
3907 iterate for a solution. Die if we exceed one uleb128 byte. */
3908 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3912 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3913 if (dw_cie_version >= 4)
3915 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3916 dw2_asm_output_data (1, 0, "CIE Segment Size");
3918 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3919 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3920 "CIE Data Alignment Factor");
3922 if (dw_cie_version == 1)
3923 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3925 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3927 if (augmentation[0])
3929 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3932 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3933 eh_data_format_name (per_encoding));
3934 dw2_asm_output_encoded_addr_rtx (per_encoding,
3939 if (any_lsda_needed)
3940 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3941 eh_data_format_name (lsda_encoding));
3943 if (fde_encoding != DW_EH_PE_absptr)
3944 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3945 eh_data_format_name (fde_encoding));
3948 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3949 output_cfi (cfi, NULL, for_eh);
3951 /* Pad the CIE out to an address sized boundary. */
3952 ASM_OUTPUT_ALIGN (asm_out_file,
3953 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3954 ASM_OUTPUT_LABEL (asm_out_file, l2);
3956 /* Loop through all of the FDE's. */
3957 for (i = 0; i < fde_table_in_use; i++)
3960 fde = &fde_table[i];
3962 /* Don't emit EH unwind info for leaf functions that don't need it. */
3963 if (for_eh && !fde_needed_for_eh_p (fde))
3966 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
3967 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3968 augmentation, any_lsda_needed, lsda_encoding);
3971 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3972 dw2_asm_output_data (4, 0, "End of Table");
3973 #ifdef MIPS_DEBUGGING_INFO
3974 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3975 get a value of 0. Putting .align 0 after the label fixes it. */
3976 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3979 /* Turn off app to make assembly quicker. */
3984 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3987 dwarf2out_do_cfi_startproc (bool second)
3991 rtx personality = get_personality_function (current_function_decl);
3993 fprintf (asm_out_file, "\t.cfi_startproc\n");
3997 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4000 /* ??? The GAS support isn't entirely consistent. We have to
4001 handle indirect support ourselves, but PC-relative is done
4002 in the assembler. Further, the assembler can't handle any
4003 of the weirder relocation types. */
4004 if (enc & DW_EH_PE_indirect)
4005 ref = dw2_force_const_mem (ref, true);
4007 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4008 output_addr_const (asm_out_file, ref);
4009 fputc ('\n', asm_out_file);
4012 if (crtl->uses_eh_lsda)
4016 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4017 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4018 current_function_funcdef_no);
4019 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4020 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4022 if (enc & DW_EH_PE_indirect)
4023 ref = dw2_force_const_mem (ref, true);
4025 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4026 output_addr_const (asm_out_file, ref);
4027 fputc ('\n', asm_out_file);
4031 /* Output a marker (i.e. a label) for the beginning of a function, before
4035 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4036 const char *file ATTRIBUTE_UNUSED)
4038 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4044 current_function_func_begin_label = NULL;
4046 do_frame = dwarf2out_do_frame ();
4048 /* ??? current_function_func_begin_label is also used by except.c for
4049 call-site information. We must emit this label if it might be used. */
4051 && (!flag_exceptions
4052 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4055 fnsec = function_section (current_function_decl);
4056 switch_to_section (fnsec);
4057 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4058 current_function_funcdef_no);
4059 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4060 current_function_funcdef_no);
4061 dup_label = xstrdup (label);
4062 current_function_func_begin_label = dup_label;
4064 /* We can elide the fde allocation if we're not emitting debug info. */
4068 /* Expand the fde table if necessary. */
4069 if (fde_table_in_use == fde_table_allocated)
4071 fde_table_allocated += FDE_TABLE_INCREMENT;
4072 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4073 memset (fde_table + fde_table_in_use, 0,
4074 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4077 /* Record the FDE associated with this function. */
4078 current_funcdef_fde = fde_table_in_use;
4080 /* Add the new FDE at the end of the fde_table. */
4081 fde = &fde_table[fde_table_in_use++];
4082 fde->decl = current_function_decl;
4083 fde->dw_fde_begin = dup_label;
4084 fde->dw_fde_end = NULL;
4085 fde->dw_fde_current_label = dup_label;
4086 fde->dw_fde_second_begin = NULL;
4087 fde->dw_fde_second_end = NULL;
4088 fde->dw_fde_vms_end_prologue = NULL;
4089 fde->dw_fde_vms_begin_epilogue = NULL;
4090 fde->dw_fde_cfi = NULL;
4091 fde->dw_fde_switch_cfi = NULL;
4092 fde->funcdef_number = current_function_funcdef_no;
4093 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4094 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4095 fde->nothrow = crtl->nothrow;
4096 fde->drap_reg = INVALID_REGNUM;
4097 fde->vdrap_reg = INVALID_REGNUM;
4098 fde->in_std_section = (fnsec == text_section
4099 || (cold_text_section && fnsec == cold_text_section));
4100 fde->second_in_std_section = 0;
4102 args_size = old_args_size = 0;
4104 /* We only want to output line number information for the genuine dwarf2
4105 prologue case, not the eh frame case. */
4106 #ifdef DWARF2_DEBUGGING_INFO
4108 dwarf2out_source_line (line, file, 0, true);
4111 if (dwarf2out_do_cfi_asm ())
4112 dwarf2out_do_cfi_startproc (false);
4115 rtx personality = get_personality_function (current_function_decl);
4116 if (!current_unit_personality)
4117 current_unit_personality = personality;
4119 /* We cannot keep a current personality per function as without CFI
4120 asm, at the point where we emit the CFI data, there is no current
4121 function anymore. */
4122 if (personality && current_unit_personality != personality)
4123 sorry ("multiple EH personalities are supported only with assemblers "
4124 "supporting .cfi_personality directive");
4128 /* Output a marker (i.e. a label) for the end of the generated code
4129 for a function prologue. This gets called *after* the prologue code has
4133 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4134 const char *file ATTRIBUTE_UNUSED)
4137 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4139 /* Output a label to mark the endpoint of the code generated for this
4141 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4142 current_function_funcdef_no);
4143 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4144 current_function_funcdef_no);
4145 fde = &fde_table[fde_table_in_use - 1];
4146 fde->dw_fde_vms_end_prologue = xstrdup (label);
4149 /* Output a marker (i.e. a label) for the beginning of the generated code
4150 for a function epilogue. This gets called *before* the prologue code has
4154 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4155 const char *file ATTRIBUTE_UNUSED)
4158 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4160 fde = &fde_table[fde_table_in_use - 1];
4161 if (fde->dw_fde_vms_begin_epilogue)
4164 /* Output a label to mark the endpoint of the code generated for this
4166 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4167 current_function_funcdef_no);
4168 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4169 current_function_funcdef_no);
4170 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4173 /* Output a marker (i.e. a label) for the absolute end of the generated code
4174 for a function definition. This gets called *after* the epilogue code has
4178 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4179 const char *file ATTRIBUTE_UNUSED)
4182 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4184 last_var_location_insn = NULL_RTX;
4186 if (dwarf2out_do_cfi_asm ())
4187 fprintf (asm_out_file, "\t.cfi_endproc\n");
4189 /* Output a label to mark the endpoint of the code generated for this
4191 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4192 current_function_funcdef_no);
4193 ASM_OUTPUT_LABEL (asm_out_file, label);
4194 fde = current_fde ();
4195 gcc_assert (fde != NULL);
4196 if (fde->dw_fde_second_begin == NULL)
4197 fde->dw_fde_end = xstrdup (label);
4201 dwarf2out_frame_init (void)
4203 /* Allocate the initial hunk of the fde_table. */
4204 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4205 fde_table_allocated = FDE_TABLE_INCREMENT;
4206 fde_table_in_use = 0;
4208 /* Generate the CFA instructions common to all FDE's. Do it now for the
4209 sake of lookup_cfa. */
4211 /* On entry, the Canonical Frame Address is at SP. */
4212 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4214 if (targetm.debug_unwind_info () == UI_DWARF2
4215 || targetm.except_unwind_info (&global_options) == UI_DWARF2)
4216 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4220 dwarf2out_frame_finish (void)
4222 /* Output call frame information. */
4223 if (targetm.debug_unwind_info () == UI_DWARF2)
4224 output_call_frame_info (0);
4226 /* Output another copy for the unwinder. */
4227 if ((flag_unwind_tables || flag_exceptions)
4228 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
4229 output_call_frame_info (1);
4232 /* Note that the current function section is being used for code. */
4235 dwarf2out_note_section_used (void)
4237 section *sec = current_function_section ();
4238 if (sec == text_section)
4239 text_section_used = true;
4240 else if (sec == cold_text_section)
4241 cold_text_section_used = true;
4244 static void var_location_switch_text_section (void);
4247 dwarf2out_switch_text_section (void)
4250 dw_fde_ref fde = current_fde ();
4253 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
4255 if (!in_cold_section_p)
4257 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
4258 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
4259 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
4263 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
4264 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
4265 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
4267 have_multiple_function_sections = true;
4269 /* Reset the current label on switching text sections, so that we
4270 don't attempt to advance_loc4 between labels in different sections. */
4271 fde->dw_fde_current_label = NULL;
4273 /* There is no need to mark used sections when not debugging. */
4274 if (cold_text_section != NULL)
4275 dwarf2out_note_section_used ();
4277 if (dwarf2out_do_cfi_asm ())
4278 fprintf (asm_out_file, "\t.cfi_endproc\n");
4280 /* Now do the real section switch. */
4281 sect = current_function_section ();
4282 switch_to_section (sect);
4284 fde->second_in_std_section
4285 = (sect == text_section
4286 || (cold_text_section && sect == cold_text_section));
4288 if (dwarf2out_do_cfi_asm ())
4290 dwarf2out_do_cfi_startproc (true);
4291 /* As this is a different FDE, insert all current CFI instructions
4293 output_cfis (fde->dw_fde_cfi, true, fde, true);
4295 cfi = fde->dw_fde_cfi;
4297 while (cfi->dw_cfi_next != NULL)
4298 cfi = cfi->dw_cfi_next;
4299 fde->dw_fde_switch_cfi = cfi;
4300 var_location_switch_text_section ();
4303 /* And now, the subset of the debugging information support code necessary
4304 for emitting location expressions. */
4306 /* Data about a single source file. */
4307 struct GTY(()) dwarf_file_data {
4308 const char * filename;
4312 typedef struct dw_val_struct *dw_val_ref;
4313 typedef struct die_struct *dw_die_ref;
4314 typedef const struct die_struct *const_dw_die_ref;
4315 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4316 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4318 typedef struct GTY(()) deferred_locations_struct
4322 } deferred_locations;
4324 DEF_VEC_O(deferred_locations);
4325 DEF_VEC_ALLOC_O(deferred_locations,gc);
4327 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4329 DEF_VEC_P(dw_die_ref);
4330 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4332 /* Each DIE may have a series of attribute/value pairs. Values
4333 can take on several forms. The forms that are used in this
4334 implementation are listed below. */
4339 dw_val_class_offset,
4341 dw_val_class_loc_list,
4342 dw_val_class_range_list,
4344 dw_val_class_unsigned_const,
4345 dw_val_class_const_double,
4348 dw_val_class_die_ref,
4349 dw_val_class_fde_ref,
4350 dw_val_class_lbl_id,
4351 dw_val_class_lineptr,
4353 dw_val_class_macptr,
4356 dw_val_class_decl_ref,
4357 dw_val_class_vms_delta
4360 /* Describe a floating point constant value, or a vector constant value. */
4362 typedef struct GTY(()) dw_vec_struct {
4363 unsigned char * GTY((length ("%h.length"))) array;
4369 /* The dw_val_node describes an attribute's value, as it is
4370 represented internally. */
4372 typedef struct GTY(()) dw_val_struct {
4373 enum dw_val_class val_class;
4374 union dw_val_struct_union
4376 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4377 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4378 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4379 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4380 HOST_WIDE_INT GTY ((default)) val_int;
4381 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4382 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4383 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4384 struct dw_val_die_union
4388 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4389 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4390 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4391 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4392 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4393 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4394 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4395 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4396 struct dw_val_vms_delta_union
4400 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4402 GTY ((desc ("%1.val_class"))) v;
4406 /* Locations in memory are described using a sequence of stack machine
4409 typedef struct GTY(()) dw_loc_descr_struct {
4410 dw_loc_descr_ref dw_loc_next;
4411 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4412 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4413 from DW_OP_addr with a dtp-relative symbol relocation. */
4414 unsigned int dtprel : 1;
4416 dw_val_node dw_loc_oprnd1;
4417 dw_val_node dw_loc_oprnd2;
4421 /* Location lists are ranges + location descriptions for that range,
4422 so you can track variables that are in different places over
4423 their entire life. */
4424 typedef struct GTY(()) dw_loc_list_struct {
4425 dw_loc_list_ref dw_loc_next;
4426 const char *begin; /* Label for begin address of range */
4427 const char *end; /* Label for end address of range */
4428 char *ll_symbol; /* Label for beginning of location list.
4429 Only on head of list */
4430 const char *section; /* Section this loclist is relative to */
4431 dw_loc_descr_ref expr;
4433 /* True if all addresses in this and subsequent lists are known to be
4436 /* True if this list has been replaced by dw_loc_next. */
4441 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4443 /* Convert a DWARF stack opcode into its string name. */
4446 dwarf_stack_op_name (unsigned int op)
4451 return "DW_OP_addr";
4453 return "DW_OP_deref";
4455 return "DW_OP_const1u";
4457 return "DW_OP_const1s";
4459 return "DW_OP_const2u";
4461 return "DW_OP_const2s";
4463 return "DW_OP_const4u";
4465 return "DW_OP_const4s";
4467 return "DW_OP_const8u";
4469 return "DW_OP_const8s";
4471 return "DW_OP_constu";
4473 return "DW_OP_consts";
4477 return "DW_OP_drop";
4479 return "DW_OP_over";
4481 return "DW_OP_pick";
4483 return "DW_OP_swap";
4487 return "DW_OP_xderef";
4495 return "DW_OP_minus";
4507 return "DW_OP_plus";
4508 case DW_OP_plus_uconst:
4509 return "DW_OP_plus_uconst";
4515 return "DW_OP_shra";
4533 return "DW_OP_skip";
4535 return "DW_OP_lit0";
4537 return "DW_OP_lit1";
4539 return "DW_OP_lit2";
4541 return "DW_OP_lit3";
4543 return "DW_OP_lit4";
4545 return "DW_OP_lit5";
4547 return "DW_OP_lit6";
4549 return "DW_OP_lit7";
4551 return "DW_OP_lit8";
4553 return "DW_OP_lit9";
4555 return "DW_OP_lit10";
4557 return "DW_OP_lit11";
4559 return "DW_OP_lit12";
4561 return "DW_OP_lit13";
4563 return "DW_OP_lit14";
4565 return "DW_OP_lit15";
4567 return "DW_OP_lit16";
4569 return "DW_OP_lit17";
4571 return "DW_OP_lit18";
4573 return "DW_OP_lit19";
4575 return "DW_OP_lit20";
4577 return "DW_OP_lit21";
4579 return "DW_OP_lit22";
4581 return "DW_OP_lit23";
4583 return "DW_OP_lit24";
4585 return "DW_OP_lit25";
4587 return "DW_OP_lit26";
4589 return "DW_OP_lit27";
4591 return "DW_OP_lit28";
4593 return "DW_OP_lit29";
4595 return "DW_OP_lit30";
4597 return "DW_OP_lit31";
4599 return "DW_OP_reg0";
4601 return "DW_OP_reg1";
4603 return "DW_OP_reg2";
4605 return "DW_OP_reg3";
4607 return "DW_OP_reg4";
4609 return "DW_OP_reg5";
4611 return "DW_OP_reg6";
4613 return "DW_OP_reg7";
4615 return "DW_OP_reg8";
4617 return "DW_OP_reg9";
4619 return "DW_OP_reg10";
4621 return "DW_OP_reg11";
4623 return "DW_OP_reg12";
4625 return "DW_OP_reg13";
4627 return "DW_OP_reg14";
4629 return "DW_OP_reg15";
4631 return "DW_OP_reg16";
4633 return "DW_OP_reg17";
4635 return "DW_OP_reg18";
4637 return "DW_OP_reg19";
4639 return "DW_OP_reg20";
4641 return "DW_OP_reg21";
4643 return "DW_OP_reg22";
4645 return "DW_OP_reg23";
4647 return "DW_OP_reg24";
4649 return "DW_OP_reg25";
4651 return "DW_OP_reg26";
4653 return "DW_OP_reg27";
4655 return "DW_OP_reg28";
4657 return "DW_OP_reg29";
4659 return "DW_OP_reg30";
4661 return "DW_OP_reg31";
4663 return "DW_OP_breg0";
4665 return "DW_OP_breg1";
4667 return "DW_OP_breg2";
4669 return "DW_OP_breg3";
4671 return "DW_OP_breg4";
4673 return "DW_OP_breg5";
4675 return "DW_OP_breg6";
4677 return "DW_OP_breg7";
4679 return "DW_OP_breg8";
4681 return "DW_OP_breg9";
4683 return "DW_OP_breg10";
4685 return "DW_OP_breg11";
4687 return "DW_OP_breg12";
4689 return "DW_OP_breg13";
4691 return "DW_OP_breg14";
4693 return "DW_OP_breg15";
4695 return "DW_OP_breg16";
4697 return "DW_OP_breg17";
4699 return "DW_OP_breg18";
4701 return "DW_OP_breg19";
4703 return "DW_OP_breg20";
4705 return "DW_OP_breg21";
4707 return "DW_OP_breg22";
4709 return "DW_OP_breg23";
4711 return "DW_OP_breg24";
4713 return "DW_OP_breg25";
4715 return "DW_OP_breg26";
4717 return "DW_OP_breg27";
4719 return "DW_OP_breg28";
4721 return "DW_OP_breg29";
4723 return "DW_OP_breg30";
4725 return "DW_OP_breg31";
4727 return "DW_OP_regx";
4729 return "DW_OP_fbreg";
4731 return "DW_OP_bregx";
4733 return "DW_OP_piece";
4734 case DW_OP_deref_size:
4735 return "DW_OP_deref_size";
4736 case DW_OP_xderef_size:
4737 return "DW_OP_xderef_size";
4741 case DW_OP_push_object_address:
4742 return "DW_OP_push_object_address";
4744 return "DW_OP_call2";
4746 return "DW_OP_call4";
4747 case DW_OP_call_ref:
4748 return "DW_OP_call_ref";
4749 case DW_OP_implicit_value:
4750 return "DW_OP_implicit_value";
4751 case DW_OP_stack_value:
4752 return "DW_OP_stack_value";
4753 case DW_OP_form_tls_address:
4754 return "DW_OP_form_tls_address";
4755 case DW_OP_call_frame_cfa:
4756 return "DW_OP_call_frame_cfa";
4757 case DW_OP_bit_piece:
4758 return "DW_OP_bit_piece";
4760 case DW_OP_GNU_push_tls_address:
4761 return "DW_OP_GNU_push_tls_address";
4762 case DW_OP_GNU_uninit:
4763 return "DW_OP_GNU_uninit";
4764 case DW_OP_GNU_encoded_addr:
4765 return "DW_OP_GNU_encoded_addr";
4766 case DW_OP_GNU_implicit_pointer:
4767 return "DW_OP_GNU_implicit_pointer";
4768 case DW_OP_GNU_entry_value:
4769 return "DW_OP_GNU_entry_value";
4772 return "OP_<unknown>";
4776 /* Return a pointer to a newly allocated location description. Location
4777 descriptions are simple expression terms that can be strung
4778 together to form more complicated location (address) descriptions. */
4780 static inline dw_loc_descr_ref
4781 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4782 unsigned HOST_WIDE_INT oprnd2)
4784 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4786 descr->dw_loc_opc = op;
4787 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4788 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4789 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4790 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4795 /* Return a pointer to a newly allocated location description for
4798 static inline dw_loc_descr_ref
4799 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4802 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4805 return new_loc_descr (DW_OP_bregx, reg, offset);
4808 /* Add a location description term to a location description expression. */
4811 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4813 dw_loc_descr_ref *d;
4815 /* Find the end of the chain. */
4816 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4822 /* Add a constant OFFSET to a location expression. */
4825 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4827 dw_loc_descr_ref loc;
4830 gcc_assert (*list_head != NULL);
4835 /* Find the end of the chain. */
4836 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4840 if (loc->dw_loc_opc == DW_OP_fbreg
4841 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4842 p = &loc->dw_loc_oprnd1.v.val_int;
4843 else if (loc->dw_loc_opc == DW_OP_bregx)
4844 p = &loc->dw_loc_oprnd2.v.val_int;
4846 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4847 offset. Don't optimize if an signed integer overflow would happen. */
4849 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4850 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4853 else if (offset > 0)
4854 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4858 loc->dw_loc_next = int_loc_descriptor (-offset);
4859 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4863 /* Add a constant OFFSET to a location list. */
4866 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4869 for (d = list_head; d != NULL; d = d->dw_loc_next)
4870 loc_descr_plus_const (&d->expr, offset);
4873 #define DWARF_REF_SIZE \
4874 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4876 static unsigned long size_of_locs (dw_loc_descr_ref);
4878 /* Return the size of a location descriptor. */
4880 static unsigned long
4881 size_of_loc_descr (dw_loc_descr_ref loc)
4883 unsigned long size = 1;
4885 switch (loc->dw_loc_opc)
4888 size += DWARF2_ADDR_SIZE;
4907 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4910 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4915 case DW_OP_plus_uconst:
4916 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4954 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4957 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4960 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4963 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4964 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4967 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4969 case DW_OP_bit_piece:
4970 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4971 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
4973 case DW_OP_deref_size:
4974 case DW_OP_xderef_size:
4983 case DW_OP_call_ref:
4984 size += DWARF_REF_SIZE;
4986 case DW_OP_implicit_value:
4987 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4988 + loc->dw_loc_oprnd1.v.val_unsigned;
4990 case DW_OP_GNU_implicit_pointer:
4991 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4993 case DW_OP_GNU_entry_value:
4995 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
4996 size += size_of_uleb128 (op_size) + op_size;
5006 /* Return the size of a series of location descriptors. */
5008 static unsigned long
5009 size_of_locs (dw_loc_descr_ref loc)
5014 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5015 field, to avoid writing to a PCH file. */
5016 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5018 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5020 size += size_of_loc_descr (l);
5025 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5027 l->dw_loc_addr = size;
5028 size += size_of_loc_descr (l);
5034 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5035 static void get_ref_die_offset_label (char *, dw_die_ref);
5036 static void output_loc_sequence (dw_loc_descr_ref, int);
5038 /* Output location description stack opcode's operands (if any).
5039 The for_eh_or_skip parameter controls whether register numbers are
5040 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5041 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5042 info). This should be suppressed for the cases that have not been converted
5043 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5046 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5048 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5049 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5051 switch (loc->dw_loc_opc)
5053 #ifdef DWARF2_DEBUGGING_INFO
5056 dw2_asm_output_data (2, val1->v.val_int, NULL);
5061 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5062 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5064 fputc ('\n', asm_out_file);
5069 dw2_asm_output_data (4, val1->v.val_int, NULL);
5074 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5075 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5077 fputc ('\n', asm_out_file);
5082 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5083 dw2_asm_output_data (8, val1->v.val_int, NULL);
5090 gcc_assert (val1->val_class == dw_val_class_loc);
5091 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5093 dw2_asm_output_data (2, offset, NULL);
5096 case DW_OP_implicit_value:
5097 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5098 switch (val2->val_class)
5100 case dw_val_class_const:
5101 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5103 case dw_val_class_vec:
5105 unsigned int elt_size = val2->v.val_vec.elt_size;
5106 unsigned int len = val2->v.val_vec.length;
5110 if (elt_size > sizeof (HOST_WIDE_INT))
5115 for (i = 0, p = val2->v.val_vec.array;
5118 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5119 "fp or vector constant word %u", i);
5122 case dw_val_class_const_double:
5124 unsigned HOST_WIDE_INT first, second;
5126 if (WORDS_BIG_ENDIAN)
5128 first = val2->v.val_double.high;
5129 second = val2->v.val_double.low;
5133 first = val2->v.val_double.low;
5134 second = val2->v.val_double.high;
5136 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5138 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5142 case dw_val_class_addr:
5143 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5144 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5159 case DW_OP_implicit_value:
5160 /* We currently don't make any attempt to make sure these are
5161 aligned properly like we do for the main unwind info, so
5162 don't support emitting things larger than a byte if we're
5163 only doing unwinding. */
5168 dw2_asm_output_data (1, val1->v.val_int, NULL);
5171 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5174 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5177 dw2_asm_output_data (1, val1->v.val_int, NULL);
5179 case DW_OP_plus_uconst:
5180 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5214 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5218 unsigned r = val1->v.val_unsigned;
5219 if (for_eh_or_skip >= 0)
5220 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5221 gcc_assert (size_of_uleb128 (r)
5222 == size_of_uleb128 (val1->v.val_unsigned));
5223 dw2_asm_output_data_uleb128 (r, NULL);
5227 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5231 unsigned r = val1->v.val_unsigned;
5232 if (for_eh_or_skip >= 0)
5233 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5234 gcc_assert (size_of_uleb128 (r)
5235 == size_of_uleb128 (val1->v.val_unsigned));
5236 dw2_asm_output_data_uleb128 (r, NULL);
5237 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5241 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5243 case DW_OP_bit_piece:
5244 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5245 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5247 case DW_OP_deref_size:
5248 case DW_OP_xderef_size:
5249 dw2_asm_output_data (1, val1->v.val_int, NULL);
5255 if (targetm.asm_out.output_dwarf_dtprel)
5257 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5260 fputc ('\n', asm_out_file);
5267 #ifdef DWARF2_DEBUGGING_INFO
5268 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5275 case DW_OP_GNU_implicit_pointer:
5277 char label[MAX_ARTIFICIAL_LABEL_BYTES
5278 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5279 gcc_assert (val1->val_class == dw_val_class_die_ref);
5280 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5281 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5282 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5286 case DW_OP_GNU_entry_value:
5287 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5288 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5292 /* Other codes have no operands. */
5297 /* Output a sequence of location operations.
5298 The for_eh_or_skip parameter controls whether register numbers are
5299 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5300 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5301 info). This should be suppressed for the cases that have not been converted
5302 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5305 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5307 for (; loc != NULL; loc = loc->dw_loc_next)
5309 enum dwarf_location_atom opc = loc->dw_loc_opc;
5310 /* Output the opcode. */
5311 if (for_eh_or_skip >= 0
5312 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5314 unsigned r = (opc - DW_OP_breg0);
5315 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5316 gcc_assert (r <= 31);
5317 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5319 else if (for_eh_or_skip >= 0
5320 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5322 unsigned r = (opc - DW_OP_reg0);
5323 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5324 gcc_assert (r <= 31);
5325 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5328 dw2_asm_output_data (1, opc,
5329 "%s", dwarf_stack_op_name (opc));
5331 /* Output the operand(s) (if any). */
5332 output_loc_operands (loc, for_eh_or_skip);
5336 /* Output location description stack opcode's operands (if any).
5337 The output is single bytes on a line, suitable for .cfi_escape. */
5340 output_loc_operands_raw (dw_loc_descr_ref loc)
5342 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5343 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5345 switch (loc->dw_loc_opc)
5348 case DW_OP_implicit_value:
5349 /* We cannot output addresses in .cfi_escape, only bytes. */
5355 case DW_OP_deref_size:
5356 case DW_OP_xderef_size:
5357 fputc (',', asm_out_file);
5358 dw2_asm_output_data_raw (1, val1->v.val_int);
5363 fputc (',', asm_out_file);
5364 dw2_asm_output_data_raw (2, val1->v.val_int);
5369 fputc (',', asm_out_file);
5370 dw2_asm_output_data_raw (4, val1->v.val_int);
5375 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5376 fputc (',', asm_out_file);
5377 dw2_asm_output_data_raw (8, val1->v.val_int);
5385 gcc_assert (val1->val_class == dw_val_class_loc);
5386 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5388 fputc (',', asm_out_file);
5389 dw2_asm_output_data_raw (2, offset);
5395 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5396 gcc_assert (size_of_uleb128 (r)
5397 == size_of_uleb128 (val1->v.val_unsigned));
5398 fputc (',', asm_out_file);
5399 dw2_asm_output_data_uleb128_raw (r);
5404 case DW_OP_plus_uconst:
5406 fputc (',', asm_out_file);
5407 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5410 case DW_OP_bit_piece:
5411 fputc (',', asm_out_file);
5412 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5413 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5450 fputc (',', asm_out_file);
5451 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5456 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5457 gcc_assert (size_of_uleb128 (r)
5458 == size_of_uleb128 (val1->v.val_unsigned));
5459 fputc (',', asm_out_file);
5460 dw2_asm_output_data_uleb128_raw (r);
5461 fputc (',', asm_out_file);
5462 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5466 case DW_OP_GNU_implicit_pointer:
5467 case DW_OP_GNU_entry_value:
5472 /* Other codes have no operands. */
5478 output_loc_sequence_raw (dw_loc_descr_ref loc)
5482 enum dwarf_location_atom opc = loc->dw_loc_opc;
5483 /* Output the opcode. */
5484 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5486 unsigned r = (opc - DW_OP_breg0);
5487 r = DWARF2_FRAME_REG_OUT (r, 1);
5488 gcc_assert (r <= 31);
5489 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5491 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5493 unsigned r = (opc - DW_OP_reg0);
5494 r = DWARF2_FRAME_REG_OUT (r, 1);
5495 gcc_assert (r <= 31);
5496 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5498 /* Output the opcode. */
5499 fprintf (asm_out_file, "%#x", opc);
5500 output_loc_operands_raw (loc);
5502 if (!loc->dw_loc_next)
5504 loc = loc->dw_loc_next;
5506 fputc (',', asm_out_file);
5510 /* This routine will generate the correct assembly data for a location
5511 description based on a cfi entry with a complex address. */
5514 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5516 dw_loc_descr_ref loc;
5519 if (cfi->dw_cfi_opc == DW_CFA_expression)
5522 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5523 dw2_asm_output_data (1, r, NULL);
5524 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5527 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5529 /* Output the size of the block. */
5530 size = size_of_locs (loc);
5531 dw2_asm_output_data_uleb128 (size, NULL);
5533 /* Now output the operations themselves. */
5534 output_loc_sequence (loc, for_eh);
5537 /* Similar, but used for .cfi_escape. */
5540 output_cfa_loc_raw (dw_cfi_ref cfi)
5542 dw_loc_descr_ref loc;
5545 if (cfi->dw_cfi_opc == DW_CFA_expression)
5548 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5549 fprintf (asm_out_file, "%#x,", r);
5550 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5553 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5555 /* Output the size of the block. */
5556 size = size_of_locs (loc);
5557 dw2_asm_output_data_uleb128_raw (size);
5558 fputc (',', asm_out_file);
5560 /* Now output the operations themselves. */
5561 output_loc_sequence_raw (loc);
5564 /* This function builds a dwarf location descriptor sequence from a
5565 dw_cfa_location, adding the given OFFSET to the result of the
5568 static struct dw_loc_descr_struct *
5569 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5571 struct dw_loc_descr_struct *head, *tmp;
5573 offset += cfa->offset;
5577 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5578 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5579 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5580 add_loc_descr (&head, tmp);
5583 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5584 add_loc_descr (&head, tmp);
5588 head = new_reg_loc_descr (cfa->reg, offset);
5593 /* This function builds a dwarf location descriptor sequence for
5594 the address at OFFSET from the CFA when stack is aligned to
5597 static struct dw_loc_descr_struct *
5598 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5600 struct dw_loc_descr_struct *head;
5601 unsigned int dwarf_fp
5602 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5604 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5605 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5607 head = new_reg_loc_descr (dwarf_fp, 0);
5608 add_loc_descr (&head, int_loc_descriptor (alignment));
5609 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5610 loc_descr_plus_const (&head, offset);
5613 head = new_reg_loc_descr (dwarf_fp, offset);
5617 /* This function fills in aa dw_cfa_location structure from a dwarf location
5618 descriptor sequence. */
5621 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5623 struct dw_loc_descr_struct *ptr;
5625 cfa->base_offset = 0;
5629 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5631 enum dwarf_location_atom op = ptr->dw_loc_opc;
5667 cfa->reg = op - DW_OP_reg0;
5670 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5704 cfa->reg = op - DW_OP_breg0;
5705 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5708 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5709 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5714 case DW_OP_plus_uconst:
5715 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5718 internal_error ("DW_LOC_OP %s not implemented",
5719 dwarf_stack_op_name (ptr->dw_loc_opc));
5724 /* And now, the support for symbolic debugging information. */
5726 /* .debug_str support. */
5727 static int output_indirect_string (void **, void *);
5729 static void dwarf2out_init (const char *);
5730 static void dwarf2out_finish (const char *);
5731 static void dwarf2out_assembly_start (void);
5732 static void dwarf2out_define (unsigned int, const char *);
5733 static void dwarf2out_undef (unsigned int, const char *);
5734 static void dwarf2out_start_source_file (unsigned, const char *);
5735 static void dwarf2out_end_source_file (unsigned);
5736 static void dwarf2out_function_decl (tree);
5737 static void dwarf2out_begin_block (unsigned, unsigned);
5738 static void dwarf2out_end_block (unsigned, unsigned);
5739 static bool dwarf2out_ignore_block (const_tree);
5740 static void dwarf2out_global_decl (tree);
5741 static void dwarf2out_type_decl (tree, int);
5742 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5743 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5745 static void dwarf2out_abstract_function (tree);
5746 static void dwarf2out_var_location (rtx);
5747 static void dwarf2out_begin_function (tree);
5748 static void dwarf2out_set_name (tree, tree);
5750 /* The debug hooks structure. */
5752 const struct gcc_debug_hooks dwarf2_debug_hooks =
5756 dwarf2out_assembly_start,
5759 dwarf2out_start_source_file,
5760 dwarf2out_end_source_file,
5761 dwarf2out_begin_block,
5762 dwarf2out_end_block,
5763 dwarf2out_ignore_block,
5764 dwarf2out_source_line,
5765 dwarf2out_begin_prologue,
5766 #if VMS_DEBUGGING_INFO
5767 dwarf2out_vms_end_prologue,
5768 dwarf2out_vms_begin_epilogue,
5770 debug_nothing_int_charstar,
5771 debug_nothing_int_charstar,
5773 dwarf2out_end_epilogue,
5774 dwarf2out_begin_function,
5775 debug_nothing_int, /* end_function */
5776 dwarf2out_function_decl, /* function_decl */
5777 dwarf2out_global_decl,
5778 dwarf2out_type_decl, /* type_decl */
5779 dwarf2out_imported_module_or_decl,
5780 debug_nothing_tree, /* deferred_inline_function */
5781 /* The DWARF 2 backend tries to reduce debugging bloat by not
5782 emitting the abstract description of inline functions until
5783 something tries to reference them. */
5784 dwarf2out_abstract_function, /* outlining_inline_function */
5785 debug_nothing_rtx, /* label */
5786 debug_nothing_int, /* handle_pch */
5787 dwarf2out_var_location,
5788 dwarf2out_switch_text_section,
5790 1, /* start_end_main_source_file */
5791 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5794 /* NOTE: In the comments in this file, many references are made to
5795 "Debugging Information Entries". This term is abbreviated as `DIE'
5796 throughout the remainder of this file. */
5798 /* An internal representation of the DWARF output is built, and then
5799 walked to generate the DWARF debugging info. The walk of the internal
5800 representation is done after the entire program has been compiled.
5801 The types below are used to describe the internal representation. */
5803 /* Various DIE's use offsets relative to the beginning of the
5804 .debug_info section to refer to each other. */
5806 typedef long int dw_offset;
5808 /* Define typedefs here to avoid circular dependencies. */
5810 typedef struct dw_attr_struct *dw_attr_ref;
5811 typedef struct dw_line_info_struct *dw_line_info_ref;
5812 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5813 typedef struct pubname_struct *pubname_ref;
5814 typedef struct dw_ranges_struct *dw_ranges_ref;
5815 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5816 typedef struct comdat_type_struct *comdat_type_node_ref;
5818 /* Each entry in the line_info_table maintains the file and
5819 line number associated with the label generated for that
5820 entry. The label gives the PC value associated with
5821 the line number entry. */
5823 typedef struct GTY(()) dw_line_info_struct {
5824 unsigned long dw_file_num;
5825 unsigned long dw_line_num;
5829 /* Line information for functions in separate sections; each one gets its
5831 typedef struct GTY(()) dw_separate_line_info_struct {
5832 unsigned long dw_file_num;
5833 unsigned long dw_line_num;
5834 unsigned long function;
5836 dw_separate_line_info_entry;
5838 /* Each DIE attribute has a field specifying the attribute kind,
5839 a link to the next attribute in the chain, and an attribute value.
5840 Attributes are typically linked below the DIE they modify. */
5842 typedef struct GTY(()) dw_attr_struct {
5843 enum dwarf_attribute dw_attr;
5844 dw_val_node dw_attr_val;
5848 DEF_VEC_O(dw_attr_node);
5849 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5851 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5852 The children of each node form a circular list linked by
5853 die_sib. die_child points to the node *before* the "first" child node. */
5855 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5856 union die_symbol_or_type_node
5858 char * GTY ((tag ("0"))) die_symbol;
5859 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5861 GTY ((desc ("dwarf_version >= 4"))) die_id;
5862 VEC(dw_attr_node,gc) * die_attr;
5863 dw_die_ref die_parent;
5864 dw_die_ref die_child;
5866 dw_die_ref die_definition; /* ref from a specification to its definition */
5867 dw_offset die_offset;
5868 unsigned long die_abbrev;
5870 /* Die is used and must not be pruned as unused. */
5871 int die_perennial_p;
5872 unsigned int decl_id;
5873 enum dwarf_tag die_tag;
5877 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5878 #define FOR_EACH_CHILD(die, c, expr) do { \
5879 c = die->die_child; \
5883 } while (c != die->die_child); \
5886 /* The pubname structure */
5888 typedef struct GTY(()) pubname_struct {
5894 DEF_VEC_O(pubname_entry);
5895 DEF_VEC_ALLOC_O(pubname_entry, gc);
5897 struct GTY(()) dw_ranges_struct {
5898 /* If this is positive, it's a block number, otherwise it's a
5899 bitwise-negated index into dw_ranges_by_label. */
5903 /* A structure to hold a macinfo entry. */
5905 typedef struct GTY(()) macinfo_struct {
5906 unsigned HOST_WIDE_INT code;
5907 unsigned HOST_WIDE_INT lineno;
5912 DEF_VEC_O(macinfo_entry);
5913 DEF_VEC_ALLOC_O(macinfo_entry, gc);
5915 struct GTY(()) dw_ranges_by_label_struct {
5920 /* The comdat type node structure. */
5921 typedef struct GTY(()) comdat_type_struct
5923 dw_die_ref root_die;
5924 dw_die_ref type_die;
5925 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5926 struct comdat_type_struct *next;
5930 /* The limbo die list structure. */
5931 typedef struct GTY(()) limbo_die_struct {
5934 struct limbo_die_struct *next;
5938 typedef struct skeleton_chain_struct
5942 struct skeleton_chain_struct *parent;
5944 skeleton_chain_node;
5946 /* How to start an assembler comment. */
5947 #ifndef ASM_COMMENT_START
5948 #define ASM_COMMENT_START ";#"
5951 /* Define a macro which returns nonzero for a TYPE_DECL which was
5952 implicitly generated for a tagged type.
5954 Note that unlike the gcc front end (which generates a NULL named
5955 TYPE_DECL node for each complete tagged type, each array type, and
5956 each function type node created) the g++ front end generates a
5957 _named_ TYPE_DECL node for each tagged type node created.
5958 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5959 generate a DW_TAG_typedef DIE for them. */
5961 #define TYPE_DECL_IS_STUB(decl) \
5962 (DECL_NAME (decl) == NULL_TREE \
5963 || (DECL_ARTIFICIAL (decl) \
5964 && is_tagged_type (TREE_TYPE (decl)) \
5965 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5966 /* This is necessary for stub decls that \
5967 appear in nested inline functions. */ \
5968 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5969 && (decl_ultimate_origin (decl) \
5970 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5972 /* Information concerning the compilation unit's programming
5973 language, and compiler version. */
5975 /* Fixed size portion of the DWARF compilation unit header. */
5976 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5977 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5979 /* Fixed size portion of the DWARF comdat type unit header. */
5980 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
5981 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
5982 + DWARF_OFFSET_SIZE)
5984 /* Fixed size portion of public names info. */
5985 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5987 /* Fixed size portion of the address range info. */
5988 #define DWARF_ARANGES_HEADER_SIZE \
5989 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5990 DWARF2_ADDR_SIZE * 2) \
5991 - DWARF_INITIAL_LENGTH_SIZE)
5993 /* Size of padding portion in the address range info. It must be
5994 aligned to twice the pointer size. */
5995 #define DWARF_ARANGES_PAD_SIZE \
5996 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5997 DWARF2_ADDR_SIZE * 2) \
5998 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6000 /* Use assembler line directives if available. */
6001 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6002 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6003 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6005 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6009 /* Minimum line offset in a special line info. opcode.
6010 This value was chosen to give a reasonable range of values. */
6011 #define DWARF_LINE_BASE -10
6013 /* First special line opcode - leave room for the standard opcodes. */
6014 #define DWARF_LINE_OPCODE_BASE 10
6016 /* Range of line offsets in a special line info. opcode. */
6017 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6019 /* Flag that indicates the initial value of the is_stmt_start flag.
6020 In the present implementation, we do not mark any lines as
6021 the beginning of a source statement, because that information
6022 is not made available by the GCC front-end. */
6023 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6025 /* Maximum number of operations per instruction bundle. */
6026 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6027 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6030 /* This location is used by calc_die_sizes() to keep track
6031 the offset of each DIE within the .debug_info section. */
6032 static unsigned long next_die_offset;
6034 /* Record the root of the DIE's built for the current compilation unit. */
6035 static GTY(()) dw_die_ref single_comp_unit_die;
6037 /* A list of type DIEs that have been separated into comdat sections. */
6038 static GTY(()) comdat_type_node *comdat_type_list;
6040 /* A list of DIEs with a NULL parent waiting to be relocated. */
6041 static GTY(()) limbo_die_node *limbo_die_list;
6043 /* A list of DIEs for which we may have to generate
6044 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6045 static GTY(()) limbo_die_node *deferred_asm_name;
6047 /* Filenames referenced by this compilation unit. */
6048 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6050 /* A hash table of references to DIE's that describe declarations.
6051 The key is a DECL_UID() which is a unique number identifying each decl. */
6052 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6054 /* A hash table of references to DIE's that describe COMMON blocks.
6055 The key is DECL_UID() ^ die_parent. */
6056 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6058 typedef struct GTY(()) die_arg_entry_struct {
6063 DEF_VEC_O(die_arg_entry);
6064 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6066 /* Node of the variable location list. */
6067 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6068 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6069 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6070 in mode of the EXPR_LIST node and first EXPR_LIST operand
6071 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6072 location or NULL for padding. For larger bitsizes,
6073 mode is 0 and first operand is a CONCAT with bitsize
6074 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6075 NULL as second operand. */
6077 const char * GTY (()) label;
6078 struct var_loc_node * GTY (()) next;
6081 /* Variable location list. */
6082 struct GTY (()) var_loc_list_def {
6083 struct var_loc_node * GTY (()) first;
6085 /* Pointer to the last but one or last element of the
6086 chained list. If the list is empty, both first and
6087 last are NULL, if the list contains just one node
6088 or the last node certainly is not redundant, it points
6089 to the last node, otherwise points to the last but one.
6090 Do not mark it for GC because it is marked through the chain. */
6091 struct var_loc_node * GTY ((skip ("%h"))) last;
6093 /* Pointer to the last element before section switch,
6094 if NULL, either sections weren't switched or first
6095 is after section switch. */
6096 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
6098 /* DECL_UID of the variable decl. */
6099 unsigned int decl_id;
6101 typedef struct var_loc_list_def var_loc_list;
6103 /* Call argument location list. */
6104 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6105 rtx GTY (()) call_arg_loc_note;
6106 const char * GTY (()) label;
6107 tree GTY (()) block;
6109 rtx GTY (()) symbol_ref;
6110 struct call_arg_loc_node * GTY (()) next;
6114 /* Table of decl location linked lists. */
6115 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6117 /* Head and tail of call_arg_loc chain. */
6118 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6119 static struct call_arg_loc_node *call_arg_loc_last;
6121 /* Number of call sites in the current function. */
6122 static int call_site_count = -1;
6123 /* Number of tail call sites in the current function. */
6124 static int tail_call_site_count = -1;
6126 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6128 static VEC (dw_die_ref, heap) *block_map;
6130 /* A cached location list. */
6131 struct GTY (()) cached_dw_loc_list_def {
6132 /* The DECL_UID of the decl that this entry describes. */
6133 unsigned int decl_id;
6135 /* The cached location list. */
6136 dw_loc_list_ref loc_list;
6138 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
6140 /* Table of cached location lists. */
6141 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
6143 /* A pointer to the base of a list of references to DIE's that
6144 are uniquely identified by their tag, presence/absence of
6145 children DIE's, and list of attribute/value pairs. */
6146 static GTY((length ("abbrev_die_table_allocated")))
6147 dw_die_ref *abbrev_die_table;
6149 /* Number of elements currently allocated for abbrev_die_table. */
6150 static GTY(()) unsigned abbrev_die_table_allocated;
6152 /* Number of elements in type_die_table currently in use. */
6153 static GTY(()) unsigned abbrev_die_table_in_use;
6155 /* Size (in elements) of increments by which we may expand the
6156 abbrev_die_table. */
6157 #define ABBREV_DIE_TABLE_INCREMENT 256
6159 /* A pointer to the base of a table that contains line information
6160 for each source code line in .text in the compilation unit. */
6161 static GTY((length ("line_info_table_allocated")))
6162 dw_line_info_ref line_info_table;
6164 /* Number of elements currently allocated for line_info_table. */
6165 static GTY(()) unsigned line_info_table_allocated;
6167 /* Number of elements in line_info_table currently in use. */
6168 static GTY(()) unsigned line_info_table_in_use;
6170 /* A pointer to the base of a table that contains line information
6171 for each source code line outside of .text in the compilation unit. */
6172 static GTY ((length ("separate_line_info_table_allocated")))
6173 dw_separate_line_info_ref separate_line_info_table;
6175 /* Number of elements currently allocated for separate_line_info_table. */
6176 static GTY(()) unsigned separate_line_info_table_allocated;
6178 /* Number of elements in separate_line_info_table currently in use. */
6179 static GTY(()) unsigned separate_line_info_table_in_use;
6181 /* Size (in elements) of increments by which we may expand the
6183 #define LINE_INFO_TABLE_INCREMENT 1024
6185 /* A flag to tell pubnames/types export if there is an info section to
6187 static bool info_section_emitted;
6189 /* A pointer to the base of a table that contains a list of publicly
6190 accessible names. */
6191 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6193 /* A pointer to the base of a table that contains a list of publicly
6194 accessible types. */
6195 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6197 /* A pointer to the base of a table that contains a list of macro
6198 defines/undefines (and file start/end markers). */
6199 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6201 /* Array of dies for which we should generate .debug_ranges info. */
6202 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6204 /* Number of elements currently allocated for ranges_table. */
6205 static GTY(()) unsigned ranges_table_allocated;
6207 /* Number of elements in ranges_table currently in use. */
6208 static GTY(()) unsigned ranges_table_in_use;
6210 /* Array of pairs of labels referenced in ranges_table. */
6211 static GTY ((length ("ranges_by_label_allocated")))
6212 dw_ranges_by_label_ref ranges_by_label;
6214 /* Number of elements currently allocated for ranges_by_label. */
6215 static GTY(()) unsigned ranges_by_label_allocated;
6217 /* Number of elements in ranges_by_label currently in use. */
6218 static GTY(()) unsigned ranges_by_label_in_use;
6220 /* Size (in elements) of increments by which we may expand the
6222 #define RANGES_TABLE_INCREMENT 64
6224 /* Whether we have location lists that need outputting */
6225 static GTY(()) bool have_location_lists;
6227 /* Unique label counter. */
6228 static GTY(()) unsigned int loclabel_num;
6230 /* Unique label counter for point-of-call tables. */
6231 static GTY(()) unsigned int poc_label_num;
6233 /* Record whether the function being analyzed contains inlined functions. */
6234 static int current_function_has_inlines;
6236 /* The last file entry emitted by maybe_emit_file(). */
6237 static GTY(()) struct dwarf_file_data * last_emitted_file;
6239 /* Number of internal labels generated by gen_internal_sym(). */
6240 static GTY(()) int label_num;
6242 /* Cached result of previous call to lookup_filename. */
6243 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6245 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6247 /* Instances of generic types for which we need to generate debug
6248 info that describe their generic parameters and arguments. That
6249 generation needs to happen once all types are properly laid out so
6250 we do it at the end of compilation. */
6251 static GTY(()) VEC(tree,gc) *generic_type_instances;
6253 /* Offset from the "steady-state frame pointer" to the frame base,
6254 within the current function. */
6255 static HOST_WIDE_INT frame_pointer_fb_offset;
6257 /* Forward declarations for functions defined in this file. */
6259 static int is_pseudo_reg (const_rtx);
6260 static tree type_main_variant (tree);
6261 static int is_tagged_type (const_tree);
6262 static const char *dwarf_tag_name (unsigned);
6263 static const char *dwarf_attr_name (unsigned);
6264 static const char *dwarf_form_name (unsigned);
6265 static tree decl_ultimate_origin (const_tree);
6266 static tree decl_class_context (tree);
6267 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6268 static inline enum dw_val_class AT_class (dw_attr_ref);
6269 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6270 static inline unsigned AT_flag (dw_attr_ref);
6271 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6272 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6273 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6274 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6275 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6276 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6277 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6278 unsigned int, unsigned char *);
6279 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6280 static hashval_t debug_str_do_hash (const void *);
6281 static int debug_str_eq (const void *, const void *);
6282 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6283 static inline const char *AT_string (dw_attr_ref);
6284 static enum dwarf_form AT_string_form (dw_attr_ref);
6285 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6286 static void add_AT_specification (dw_die_ref, dw_die_ref);
6287 static inline dw_die_ref AT_ref (dw_attr_ref);
6288 static inline int AT_ref_external (dw_attr_ref);
6289 static inline void set_AT_ref_external (dw_attr_ref, int);
6290 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6291 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6292 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6293 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6295 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6296 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6297 static inline rtx AT_addr (dw_attr_ref);
6298 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6299 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6300 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6301 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6302 unsigned HOST_WIDE_INT);
6303 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6305 static inline const char *AT_lbl (dw_attr_ref);
6306 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6307 static const char *get_AT_low_pc (dw_die_ref);
6308 static const char *get_AT_hi_pc (dw_die_ref);
6309 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6310 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6311 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6312 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6313 static bool is_cxx (void);
6314 static bool is_fortran (void);
6315 static bool is_ada (void);
6316 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6317 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6318 static void add_child_die (dw_die_ref, dw_die_ref);
6319 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6320 static dw_die_ref lookup_type_die (tree);
6321 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6322 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6323 static void equate_type_number_to_die (tree, dw_die_ref);
6324 static hashval_t decl_die_table_hash (const void *);
6325 static int decl_die_table_eq (const void *, const void *);
6326 static dw_die_ref lookup_decl_die (tree);
6327 static hashval_t common_block_die_table_hash (const void *);
6328 static int common_block_die_table_eq (const void *, const void *);
6329 static hashval_t decl_loc_table_hash (const void *);
6330 static int decl_loc_table_eq (const void *, const void *);
6331 static var_loc_list *lookup_decl_loc (const_tree);
6332 static void equate_decl_number_to_die (tree, dw_die_ref);
6333 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6334 static void print_spaces (FILE *);
6335 static void print_die (dw_die_ref, FILE *);
6336 static void print_dwarf_line_table (FILE *);
6337 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6338 static dw_die_ref pop_compile_unit (dw_die_ref);
6339 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6340 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6341 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6342 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6343 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6344 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6345 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6346 struct md5_ctx *, int *);
6347 struct checksum_attributes;
6348 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6349 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6350 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6351 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6352 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6353 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6354 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6355 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6356 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6357 static void compute_section_prefix (dw_die_ref);
6358 static int is_type_die (dw_die_ref);
6359 static int is_comdat_die (dw_die_ref);
6360 static int is_symbol_die (dw_die_ref);
6361 static void assign_symbol_names (dw_die_ref);
6362 static void break_out_includes (dw_die_ref);
6363 static int is_declaration_die (dw_die_ref);
6364 static int should_move_die_to_comdat (dw_die_ref);
6365 static dw_die_ref clone_as_declaration (dw_die_ref);
6366 static dw_die_ref clone_die (dw_die_ref);
6367 static dw_die_ref clone_tree (dw_die_ref);
6368 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6369 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6370 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6371 static dw_die_ref generate_skeleton (dw_die_ref);
6372 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6374 static void break_out_comdat_types (dw_die_ref);
6375 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6376 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6377 static void copy_decls_for_unworthy_types (dw_die_ref);
6379 static hashval_t htab_cu_hash (const void *);
6380 static int htab_cu_eq (const void *, const void *);
6381 static void htab_cu_del (void *);
6382 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6383 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6384 static void add_sibling_attributes (dw_die_ref);
6385 static void build_abbrev_table (dw_die_ref);
6386 static void output_location_lists (dw_die_ref);
6387 static int constant_size (unsigned HOST_WIDE_INT);
6388 static unsigned long size_of_die (dw_die_ref);
6389 static void calc_die_sizes (dw_die_ref);
6390 static void mark_dies (dw_die_ref);
6391 static void unmark_dies (dw_die_ref);
6392 static void unmark_all_dies (dw_die_ref);
6393 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6394 static unsigned long size_of_aranges (void);
6395 static enum dwarf_form value_format (dw_attr_ref);
6396 static void output_value_format (dw_attr_ref);
6397 static void output_abbrev_section (void);
6398 static void output_die_symbol (dw_die_ref);
6399 static void output_die (dw_die_ref);
6400 static void output_compilation_unit_header (void);
6401 static void output_comp_unit (dw_die_ref, int);
6402 static void output_comdat_type_unit (comdat_type_node *);
6403 static const char *dwarf2_name (tree, int);
6404 static void add_pubname (tree, dw_die_ref);
6405 static void add_pubname_string (const char *, dw_die_ref);
6406 static void add_pubtype (tree, dw_die_ref);
6407 static void output_pubnames (VEC (pubname_entry,gc) *);
6408 static void output_aranges (unsigned long);
6409 static unsigned int add_ranges_num (int);
6410 static unsigned int add_ranges (const_tree);
6411 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6413 static void output_ranges (void);
6414 static void output_line_info (void);
6415 static void output_file_names (void);
6416 static dw_die_ref base_type_die (tree);
6417 static int is_base_type (tree);
6418 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6419 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6420 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6421 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6422 static int type_is_enum (const_tree);
6423 static unsigned int dbx_reg_number (const_rtx);
6424 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6425 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6426 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6427 enum var_init_status);
6428 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6429 enum var_init_status);
6430 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6431 enum var_init_status);
6432 static int is_based_loc (const_rtx);
6433 static int resolve_one_addr (rtx *, void *);
6434 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6435 enum var_init_status);
6436 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6437 enum var_init_status);
6438 static dw_loc_list_ref loc_list_from_tree (tree, int);
6439 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6440 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6441 static tree field_type (const_tree);
6442 static unsigned int simple_type_align_in_bits (const_tree);
6443 static unsigned int simple_decl_align_in_bits (const_tree);
6444 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6445 static HOST_WIDE_INT field_byte_offset (const_tree);
6446 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6448 static void add_data_member_location_attribute (dw_die_ref, tree);
6449 static bool add_const_value_attribute (dw_die_ref, rtx);
6450 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6451 static void insert_double (double_int, unsigned char *);
6452 static void insert_float (const_rtx, unsigned char *);
6453 static rtx rtl_for_decl_location (tree);
6454 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
6455 enum dwarf_attribute);
6456 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6457 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6458 static void add_name_attribute (dw_die_ref, const char *);
6459 static void add_comp_dir_attribute (dw_die_ref);
6460 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6461 static void add_subscript_info (dw_die_ref, tree, bool);
6462 static void add_byte_size_attribute (dw_die_ref, tree);
6463 static void add_bit_offset_attribute (dw_die_ref, tree);
6464 static void add_bit_size_attribute (dw_die_ref, tree);
6465 static void add_prototyped_attribute (dw_die_ref, tree);
6466 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6467 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6468 static void add_src_coords_attributes (dw_die_ref, tree);
6469 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6470 static void push_decl_scope (tree);
6471 static void pop_decl_scope (void);
6472 static dw_die_ref scope_die_for (tree, dw_die_ref);
6473 static inline int local_scope_p (dw_die_ref);
6474 static inline int class_scope_p (dw_die_ref);
6475 static inline int class_or_namespace_scope_p (dw_die_ref);
6476 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6477 static void add_calling_convention_attribute (dw_die_ref, tree);
6478 static const char *type_tag (const_tree);
6479 static tree member_declared_type (const_tree);
6481 static const char *decl_start_label (tree);
6483 static void gen_array_type_die (tree, dw_die_ref);
6484 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6486 static void gen_entry_point_die (tree, dw_die_ref);
6488 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6489 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6490 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6491 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6492 static void gen_formal_types_die (tree, dw_die_ref);
6493 static void gen_subprogram_die (tree, dw_die_ref);
6494 static void gen_variable_die (tree, tree, dw_die_ref);
6495 static void gen_const_die (tree, dw_die_ref);
6496 static void gen_label_die (tree, dw_die_ref);
6497 static void gen_lexical_block_die (tree, dw_die_ref, int);
6498 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6499 static void gen_field_die (tree, dw_die_ref);
6500 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6501 static dw_die_ref gen_compile_unit_die (const char *);
6502 static void gen_inheritance_die (tree, tree, dw_die_ref);
6503 static void gen_member_die (tree, dw_die_ref);
6504 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6505 enum debug_info_usage);
6506 static void gen_subroutine_type_die (tree, dw_die_ref);
6507 static void gen_typedef_die (tree, dw_die_ref);
6508 static void gen_type_die (tree, dw_die_ref);
6509 static void gen_block_die (tree, dw_die_ref, int);
6510 static void decls_for_scope (tree, dw_die_ref, int);
6511 static int is_redundant_typedef (const_tree);
6512 static bool is_naming_typedef_decl (const_tree);
6513 static inline dw_die_ref get_context_die (tree);
6514 static void gen_namespace_die (tree, dw_die_ref);
6515 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6516 static dw_die_ref force_decl_die (tree);
6517 static dw_die_ref force_type_die (tree);
6518 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6519 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6520 static struct dwarf_file_data * lookup_filename (const char *);
6521 static void retry_incomplete_types (void);
6522 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6523 static void gen_generic_params_dies (tree);
6524 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6525 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6526 static void splice_child_die (dw_die_ref, dw_die_ref);
6527 static int file_info_cmp (const void *, const void *);
6528 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6529 const char *, const char *);
6530 static void output_loc_list (dw_loc_list_ref);
6531 static char *gen_internal_sym (const char *);
6533 static void prune_unmark_dies (dw_die_ref);
6534 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6535 static void prune_unused_types_mark (dw_die_ref, int);
6536 static void prune_unused_types_walk (dw_die_ref);
6537 static void prune_unused_types_walk_attribs (dw_die_ref);
6538 static void prune_unused_types_prune (dw_die_ref);
6539 static void prune_unused_types (void);
6540 static int maybe_emit_file (struct dwarf_file_data *fd);
6541 static inline const char *AT_vms_delta1 (dw_attr_ref);
6542 static inline const char *AT_vms_delta2 (dw_attr_ref);
6543 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6544 const char *, const char *);
6545 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6546 static void gen_remaining_tmpl_value_param_die_attribute (void);
6547 static bool generic_type_p (tree);
6548 static void schedule_generic_params_dies_gen (tree t);
6549 static void gen_scheduled_generic_parms_dies (void);
6551 /* Section names used to hold DWARF debugging information. */
6552 #ifndef DEBUG_INFO_SECTION
6553 #define DEBUG_INFO_SECTION ".debug_info"
6555 #ifndef DEBUG_ABBREV_SECTION
6556 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6558 #ifndef DEBUG_ARANGES_SECTION
6559 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6561 #ifndef DEBUG_MACINFO_SECTION
6562 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6564 #ifndef DEBUG_LINE_SECTION
6565 #define DEBUG_LINE_SECTION ".debug_line"
6567 #ifndef DEBUG_LOC_SECTION
6568 #define DEBUG_LOC_SECTION ".debug_loc"
6570 #ifndef DEBUG_PUBNAMES_SECTION
6571 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6573 #ifndef DEBUG_PUBTYPES_SECTION
6574 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6576 #ifndef DEBUG_STR_SECTION
6577 #define DEBUG_STR_SECTION ".debug_str"
6579 #ifndef DEBUG_RANGES_SECTION
6580 #define DEBUG_RANGES_SECTION ".debug_ranges"
6583 /* Standard ELF section names for compiled code and data. */
6584 #ifndef TEXT_SECTION_NAME
6585 #define TEXT_SECTION_NAME ".text"
6588 /* Section flags for .debug_str section. */
6589 #define DEBUG_STR_SECTION_FLAGS \
6590 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6591 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6594 /* Labels we insert at beginning sections we can reference instead of
6595 the section names themselves. */
6597 #ifndef TEXT_SECTION_LABEL
6598 #define TEXT_SECTION_LABEL "Ltext"
6600 #ifndef COLD_TEXT_SECTION_LABEL
6601 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6603 #ifndef DEBUG_LINE_SECTION_LABEL
6604 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6606 #ifndef DEBUG_INFO_SECTION_LABEL
6607 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6609 #ifndef DEBUG_ABBREV_SECTION_LABEL
6610 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6612 #ifndef DEBUG_LOC_SECTION_LABEL
6613 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6615 #ifndef DEBUG_RANGES_SECTION_LABEL
6616 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6618 #ifndef DEBUG_MACINFO_SECTION_LABEL
6619 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6623 /* Definitions of defaults for formats and names of various special
6624 (artificial) labels which may be generated within this file (when the -g
6625 options is used and DWARF2_DEBUGGING_INFO is in effect.
6626 If necessary, these may be overridden from within the tm.h file, but
6627 typically, overriding these defaults is unnecessary. */
6629 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6630 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6631 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6632 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6633 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6634 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6635 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6636 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6637 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6638 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6640 #ifndef TEXT_END_LABEL
6641 #define TEXT_END_LABEL "Letext"
6643 #ifndef COLD_END_LABEL
6644 #define COLD_END_LABEL "Letext_cold"
6646 #ifndef BLOCK_BEGIN_LABEL
6647 #define BLOCK_BEGIN_LABEL "LBB"
6649 #ifndef BLOCK_END_LABEL
6650 #define BLOCK_END_LABEL "LBE"
6652 #ifndef LINE_CODE_LABEL
6653 #define LINE_CODE_LABEL "LM"
6655 #ifndef SEPARATE_LINE_CODE_LABEL
6656 #define SEPARATE_LINE_CODE_LABEL "LSM"
6660 /* Return the root of the DIE's built for the current compilation unit. */
6662 comp_unit_die (void)
6664 if (!single_comp_unit_die)
6665 single_comp_unit_die = gen_compile_unit_die (NULL);
6666 return single_comp_unit_die;
6669 /* We allow a language front-end to designate a function that is to be
6670 called to "demangle" any name before it is put into a DIE. */
6672 static const char *(*demangle_name_func) (const char *);
6675 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6677 demangle_name_func = func;
6680 /* Test if rtl node points to a pseudo register. */
6683 is_pseudo_reg (const_rtx rtl)
6685 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6686 || (GET_CODE (rtl) == SUBREG
6687 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6690 /* Return a reference to a type, with its const and volatile qualifiers
6694 type_main_variant (tree type)
6696 type = TYPE_MAIN_VARIANT (type);
6698 /* ??? There really should be only one main variant among any group of
6699 variants of a given type (and all of the MAIN_VARIANT values for all
6700 members of the group should point to that one type) but sometimes the C
6701 front-end messes this up for array types, so we work around that bug
6703 if (TREE_CODE (type) == ARRAY_TYPE)
6704 while (type != TYPE_MAIN_VARIANT (type))
6705 type = TYPE_MAIN_VARIANT (type);
6710 /* Return nonzero if the given type node represents a tagged type. */
6713 is_tagged_type (const_tree type)
6715 enum tree_code code = TREE_CODE (type);
6717 return (code == RECORD_TYPE || code == UNION_TYPE
6718 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6721 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6724 get_ref_die_offset_label (char *label, dw_die_ref ref)
6726 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6729 /* Convert a DIE tag into its string name. */
6732 dwarf_tag_name (unsigned int tag)
6736 case DW_TAG_padding:
6737 return "DW_TAG_padding";
6738 case DW_TAG_array_type:
6739 return "DW_TAG_array_type";
6740 case DW_TAG_class_type:
6741 return "DW_TAG_class_type";
6742 case DW_TAG_entry_point:
6743 return "DW_TAG_entry_point";
6744 case DW_TAG_enumeration_type:
6745 return "DW_TAG_enumeration_type";
6746 case DW_TAG_formal_parameter:
6747 return "DW_TAG_formal_parameter";
6748 case DW_TAG_imported_declaration:
6749 return "DW_TAG_imported_declaration";
6751 return "DW_TAG_label";
6752 case DW_TAG_lexical_block:
6753 return "DW_TAG_lexical_block";
6755 return "DW_TAG_member";
6756 case DW_TAG_pointer_type:
6757 return "DW_TAG_pointer_type";
6758 case DW_TAG_reference_type:
6759 return "DW_TAG_reference_type";
6760 case DW_TAG_compile_unit:
6761 return "DW_TAG_compile_unit";
6762 case DW_TAG_string_type:
6763 return "DW_TAG_string_type";
6764 case DW_TAG_structure_type:
6765 return "DW_TAG_structure_type";
6766 case DW_TAG_subroutine_type:
6767 return "DW_TAG_subroutine_type";
6768 case DW_TAG_typedef:
6769 return "DW_TAG_typedef";
6770 case DW_TAG_union_type:
6771 return "DW_TAG_union_type";
6772 case DW_TAG_unspecified_parameters:
6773 return "DW_TAG_unspecified_parameters";
6774 case DW_TAG_variant:
6775 return "DW_TAG_variant";
6776 case DW_TAG_common_block:
6777 return "DW_TAG_common_block";
6778 case DW_TAG_common_inclusion:
6779 return "DW_TAG_common_inclusion";
6780 case DW_TAG_inheritance:
6781 return "DW_TAG_inheritance";
6782 case DW_TAG_inlined_subroutine:
6783 return "DW_TAG_inlined_subroutine";
6785 return "DW_TAG_module";
6786 case DW_TAG_ptr_to_member_type:
6787 return "DW_TAG_ptr_to_member_type";
6788 case DW_TAG_set_type:
6789 return "DW_TAG_set_type";
6790 case DW_TAG_subrange_type:
6791 return "DW_TAG_subrange_type";
6792 case DW_TAG_with_stmt:
6793 return "DW_TAG_with_stmt";
6794 case DW_TAG_access_declaration:
6795 return "DW_TAG_access_declaration";
6796 case DW_TAG_base_type:
6797 return "DW_TAG_base_type";
6798 case DW_TAG_catch_block:
6799 return "DW_TAG_catch_block";
6800 case DW_TAG_const_type:
6801 return "DW_TAG_const_type";
6802 case DW_TAG_constant:
6803 return "DW_TAG_constant";
6804 case DW_TAG_enumerator:
6805 return "DW_TAG_enumerator";
6806 case DW_TAG_file_type:
6807 return "DW_TAG_file_type";
6809 return "DW_TAG_friend";
6810 case DW_TAG_namelist:
6811 return "DW_TAG_namelist";
6812 case DW_TAG_namelist_item:
6813 return "DW_TAG_namelist_item";
6814 case DW_TAG_packed_type:
6815 return "DW_TAG_packed_type";
6816 case DW_TAG_subprogram:
6817 return "DW_TAG_subprogram";
6818 case DW_TAG_template_type_param:
6819 return "DW_TAG_template_type_param";
6820 case DW_TAG_template_value_param:
6821 return "DW_TAG_template_value_param";
6822 case DW_TAG_thrown_type:
6823 return "DW_TAG_thrown_type";
6824 case DW_TAG_try_block:
6825 return "DW_TAG_try_block";
6826 case DW_TAG_variant_part:
6827 return "DW_TAG_variant_part";
6828 case DW_TAG_variable:
6829 return "DW_TAG_variable";
6830 case DW_TAG_volatile_type:
6831 return "DW_TAG_volatile_type";
6832 case DW_TAG_dwarf_procedure:
6833 return "DW_TAG_dwarf_procedure";
6834 case DW_TAG_restrict_type:
6835 return "DW_TAG_restrict_type";
6836 case DW_TAG_interface_type:
6837 return "DW_TAG_interface_type";
6838 case DW_TAG_namespace:
6839 return "DW_TAG_namespace";
6840 case DW_TAG_imported_module:
6841 return "DW_TAG_imported_module";
6842 case DW_TAG_unspecified_type:
6843 return "DW_TAG_unspecified_type";
6844 case DW_TAG_partial_unit:
6845 return "DW_TAG_partial_unit";
6846 case DW_TAG_imported_unit:
6847 return "DW_TAG_imported_unit";
6848 case DW_TAG_condition:
6849 return "DW_TAG_condition";
6850 case DW_TAG_shared_type:
6851 return "DW_TAG_shared_type";
6852 case DW_TAG_type_unit:
6853 return "DW_TAG_type_unit";
6854 case DW_TAG_rvalue_reference_type:
6855 return "DW_TAG_rvalue_reference_type";
6856 case DW_TAG_template_alias:
6857 return "DW_TAG_template_alias";
6858 case DW_TAG_GNU_template_parameter_pack:
6859 return "DW_TAG_GNU_template_parameter_pack";
6860 case DW_TAG_GNU_formal_parameter_pack:
6861 return "DW_TAG_GNU_formal_parameter_pack";
6862 case DW_TAG_MIPS_loop:
6863 return "DW_TAG_MIPS_loop";
6864 case DW_TAG_format_label:
6865 return "DW_TAG_format_label";
6866 case DW_TAG_function_template:
6867 return "DW_TAG_function_template";
6868 case DW_TAG_class_template:
6869 return "DW_TAG_class_template";
6870 case DW_TAG_GNU_BINCL:
6871 return "DW_TAG_GNU_BINCL";
6872 case DW_TAG_GNU_EINCL:
6873 return "DW_TAG_GNU_EINCL";
6874 case DW_TAG_GNU_template_template_param:
6875 return "DW_TAG_GNU_template_template_param";
6876 case DW_TAG_GNU_call_site:
6877 return "DW_TAG_GNU_call_site";
6878 case DW_TAG_GNU_call_site_parameter:
6879 return "DW_TAG_GNU_call_site_parameter";
6881 return "DW_TAG_<unknown>";
6885 /* Convert a DWARF attribute code into its string name. */
6888 dwarf_attr_name (unsigned int attr)
6893 return "DW_AT_sibling";
6894 case DW_AT_location:
6895 return "DW_AT_location";
6897 return "DW_AT_name";
6898 case DW_AT_ordering:
6899 return "DW_AT_ordering";
6900 case DW_AT_subscr_data:
6901 return "DW_AT_subscr_data";
6902 case DW_AT_byte_size:
6903 return "DW_AT_byte_size";
6904 case DW_AT_bit_offset:
6905 return "DW_AT_bit_offset";
6906 case DW_AT_bit_size:
6907 return "DW_AT_bit_size";
6908 case DW_AT_element_list:
6909 return "DW_AT_element_list";
6910 case DW_AT_stmt_list:
6911 return "DW_AT_stmt_list";
6913 return "DW_AT_low_pc";
6915 return "DW_AT_high_pc";
6916 case DW_AT_language:
6917 return "DW_AT_language";
6919 return "DW_AT_member";
6921 return "DW_AT_discr";
6922 case DW_AT_discr_value:
6923 return "DW_AT_discr_value";
6924 case DW_AT_visibility:
6925 return "DW_AT_visibility";
6927 return "DW_AT_import";
6928 case DW_AT_string_length:
6929 return "DW_AT_string_length";
6930 case DW_AT_common_reference:
6931 return "DW_AT_common_reference";
6932 case DW_AT_comp_dir:
6933 return "DW_AT_comp_dir";
6934 case DW_AT_const_value:
6935 return "DW_AT_const_value";
6936 case DW_AT_containing_type:
6937 return "DW_AT_containing_type";
6938 case DW_AT_default_value:
6939 return "DW_AT_default_value";
6941 return "DW_AT_inline";
6942 case DW_AT_is_optional:
6943 return "DW_AT_is_optional";
6944 case DW_AT_lower_bound:
6945 return "DW_AT_lower_bound";
6946 case DW_AT_producer:
6947 return "DW_AT_producer";
6948 case DW_AT_prototyped:
6949 return "DW_AT_prototyped";
6950 case DW_AT_return_addr:
6951 return "DW_AT_return_addr";
6952 case DW_AT_start_scope:
6953 return "DW_AT_start_scope";
6954 case DW_AT_bit_stride:
6955 return "DW_AT_bit_stride";
6956 case DW_AT_upper_bound:
6957 return "DW_AT_upper_bound";
6958 case DW_AT_abstract_origin:
6959 return "DW_AT_abstract_origin";
6960 case DW_AT_accessibility:
6961 return "DW_AT_accessibility";
6962 case DW_AT_address_class:
6963 return "DW_AT_address_class";
6964 case DW_AT_artificial:
6965 return "DW_AT_artificial";
6966 case DW_AT_base_types:
6967 return "DW_AT_base_types";
6968 case DW_AT_calling_convention:
6969 return "DW_AT_calling_convention";
6971 return "DW_AT_count";
6972 case DW_AT_data_member_location:
6973 return "DW_AT_data_member_location";
6974 case DW_AT_decl_column:
6975 return "DW_AT_decl_column";
6976 case DW_AT_decl_file:
6977 return "DW_AT_decl_file";
6978 case DW_AT_decl_line:
6979 return "DW_AT_decl_line";
6980 case DW_AT_declaration:
6981 return "DW_AT_declaration";
6982 case DW_AT_discr_list:
6983 return "DW_AT_discr_list";
6984 case DW_AT_encoding:
6985 return "DW_AT_encoding";
6986 case DW_AT_external:
6987 return "DW_AT_external";
6988 case DW_AT_explicit:
6989 return "DW_AT_explicit";
6990 case DW_AT_frame_base:
6991 return "DW_AT_frame_base";
6993 return "DW_AT_friend";
6994 case DW_AT_identifier_case:
6995 return "DW_AT_identifier_case";
6996 case DW_AT_macro_info:
6997 return "DW_AT_macro_info";
6998 case DW_AT_namelist_items:
6999 return "DW_AT_namelist_items";
7000 case DW_AT_priority:
7001 return "DW_AT_priority";
7003 return "DW_AT_segment";
7004 case DW_AT_specification:
7005 return "DW_AT_specification";
7006 case DW_AT_static_link:
7007 return "DW_AT_static_link";
7009 return "DW_AT_type";
7010 case DW_AT_use_location:
7011 return "DW_AT_use_location";
7012 case DW_AT_variable_parameter:
7013 return "DW_AT_variable_parameter";
7014 case DW_AT_virtuality:
7015 return "DW_AT_virtuality";
7016 case DW_AT_vtable_elem_location:
7017 return "DW_AT_vtable_elem_location";
7019 case DW_AT_allocated:
7020 return "DW_AT_allocated";
7021 case DW_AT_associated:
7022 return "DW_AT_associated";
7023 case DW_AT_data_location:
7024 return "DW_AT_data_location";
7025 case DW_AT_byte_stride:
7026 return "DW_AT_byte_stride";
7027 case DW_AT_entry_pc:
7028 return "DW_AT_entry_pc";
7029 case DW_AT_use_UTF8:
7030 return "DW_AT_use_UTF8";
7031 case DW_AT_extension:
7032 return "DW_AT_extension";
7034 return "DW_AT_ranges";
7035 case DW_AT_trampoline:
7036 return "DW_AT_trampoline";
7037 case DW_AT_call_column:
7038 return "DW_AT_call_column";
7039 case DW_AT_call_file:
7040 return "DW_AT_call_file";
7041 case DW_AT_call_line:
7042 return "DW_AT_call_line";
7043 case DW_AT_object_pointer:
7044 return "DW_AT_object_pointer";
7046 case DW_AT_signature:
7047 return "DW_AT_signature";
7048 case DW_AT_main_subprogram:
7049 return "DW_AT_main_subprogram";
7050 case DW_AT_data_bit_offset:
7051 return "DW_AT_data_bit_offset";
7052 case DW_AT_const_expr:
7053 return "DW_AT_const_expr";
7054 case DW_AT_enum_class:
7055 return "DW_AT_enum_class";
7056 case DW_AT_linkage_name:
7057 return "DW_AT_linkage_name";
7059 case DW_AT_MIPS_fde:
7060 return "DW_AT_MIPS_fde";
7061 case DW_AT_MIPS_loop_begin:
7062 return "DW_AT_MIPS_loop_begin";
7063 case DW_AT_MIPS_tail_loop_begin:
7064 return "DW_AT_MIPS_tail_loop_begin";
7065 case DW_AT_MIPS_epilog_begin:
7066 return "DW_AT_MIPS_epilog_begin";
7067 #if VMS_DEBUGGING_INFO
7068 case DW_AT_HP_prologue:
7069 return "DW_AT_HP_prologue";
7071 case DW_AT_MIPS_loop_unroll_factor:
7072 return "DW_AT_MIPS_loop_unroll_factor";
7074 case DW_AT_MIPS_software_pipeline_depth:
7075 return "DW_AT_MIPS_software_pipeline_depth";
7076 case DW_AT_MIPS_linkage_name:
7077 return "DW_AT_MIPS_linkage_name";
7078 #if VMS_DEBUGGING_INFO
7079 case DW_AT_HP_epilogue:
7080 return "DW_AT_HP_epilogue";
7082 case DW_AT_MIPS_stride:
7083 return "DW_AT_MIPS_stride";
7085 case DW_AT_MIPS_abstract_name:
7086 return "DW_AT_MIPS_abstract_name";
7087 case DW_AT_MIPS_clone_origin:
7088 return "DW_AT_MIPS_clone_origin";
7089 case DW_AT_MIPS_has_inlines:
7090 return "DW_AT_MIPS_has_inlines";
7092 case DW_AT_sf_names:
7093 return "DW_AT_sf_names";
7094 case DW_AT_src_info:
7095 return "DW_AT_src_info";
7096 case DW_AT_mac_info:
7097 return "DW_AT_mac_info";
7098 case DW_AT_src_coords:
7099 return "DW_AT_src_coords";
7100 case DW_AT_body_begin:
7101 return "DW_AT_body_begin";
7102 case DW_AT_body_end:
7103 return "DW_AT_body_end";
7104 case DW_AT_GNU_vector:
7105 return "DW_AT_GNU_vector";
7106 case DW_AT_GNU_guarded_by:
7107 return "DW_AT_GNU_guarded_by";
7108 case DW_AT_GNU_pt_guarded_by:
7109 return "DW_AT_GNU_pt_guarded_by";
7110 case DW_AT_GNU_guarded:
7111 return "DW_AT_GNU_guarded";
7112 case DW_AT_GNU_pt_guarded:
7113 return "DW_AT_GNU_pt_guarded";
7114 case DW_AT_GNU_locks_excluded:
7115 return "DW_AT_GNU_locks_excluded";
7116 case DW_AT_GNU_exclusive_locks_required:
7117 return "DW_AT_GNU_exclusive_locks_required";
7118 case DW_AT_GNU_shared_locks_required:
7119 return "DW_AT_GNU_shared_locks_required";
7120 case DW_AT_GNU_odr_signature:
7121 return "DW_AT_GNU_odr_signature";
7122 case DW_AT_GNU_template_name:
7123 return "DW_AT_GNU_template_name";
7124 case DW_AT_GNU_call_site_value:
7125 return "DW_AT_GNU_call_site_value";
7126 case DW_AT_GNU_call_site_data_value:
7127 return "DW_AT_GNU_call_site_data_value";
7128 case DW_AT_GNU_call_site_target:
7129 return "DW_AT_GNU_call_site_target";
7130 case DW_AT_GNU_call_site_target_clobbered:
7131 return "DW_AT_GNU_call_site_target_clobbered";
7132 case DW_AT_GNU_tail_call:
7133 return "DW_AT_GNU_tail_call";
7134 case DW_AT_GNU_all_tail_call_sites:
7135 return "DW_AT_GNU_all_tail_call_sites";
7136 case DW_AT_GNU_all_call_sites:
7137 return "DW_AT_GNU_all_call_sites";
7138 case DW_AT_GNU_all_source_call_sites:
7139 return "DW_AT_GNU_all_source_call_sites";
7141 case DW_AT_VMS_rtnbeg_pd_address:
7142 return "DW_AT_VMS_rtnbeg_pd_address";
7145 return "DW_AT_<unknown>";
7149 /* Convert a DWARF value form code into its string name. */
7152 dwarf_form_name (unsigned int form)
7157 return "DW_FORM_addr";
7158 case DW_FORM_block2:
7159 return "DW_FORM_block2";
7160 case DW_FORM_block4:
7161 return "DW_FORM_block4";
7163 return "DW_FORM_data2";
7165 return "DW_FORM_data4";
7167 return "DW_FORM_data8";
7168 case DW_FORM_string:
7169 return "DW_FORM_string";
7171 return "DW_FORM_block";
7172 case DW_FORM_block1:
7173 return "DW_FORM_block1";
7175 return "DW_FORM_data1";
7177 return "DW_FORM_flag";
7179 return "DW_FORM_sdata";
7181 return "DW_FORM_strp";
7183 return "DW_FORM_udata";
7184 case DW_FORM_ref_addr:
7185 return "DW_FORM_ref_addr";
7187 return "DW_FORM_ref1";
7189 return "DW_FORM_ref2";
7191 return "DW_FORM_ref4";
7193 return "DW_FORM_ref8";
7194 case DW_FORM_ref_udata:
7195 return "DW_FORM_ref_udata";
7196 case DW_FORM_indirect:
7197 return "DW_FORM_indirect";
7198 case DW_FORM_sec_offset:
7199 return "DW_FORM_sec_offset";
7200 case DW_FORM_exprloc:
7201 return "DW_FORM_exprloc";
7202 case DW_FORM_flag_present:
7203 return "DW_FORM_flag_present";
7204 case DW_FORM_ref_sig8:
7205 return "DW_FORM_ref_sig8";
7207 return "DW_FORM_<unknown>";
7211 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7212 instance of an inlined instance of a decl which is local to an inline
7213 function, so we have to trace all of the way back through the origin chain
7214 to find out what sort of node actually served as the original seed for the
7218 decl_ultimate_origin (const_tree decl)
7220 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7223 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7224 nodes in the function to point to themselves; ignore that if
7225 we're trying to output the abstract instance of this function. */
7226 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7229 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7230 most distant ancestor, this should never happen. */
7231 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7233 return DECL_ABSTRACT_ORIGIN (decl);
7236 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7237 of a virtual function may refer to a base class, so we check the 'this'
7241 decl_class_context (tree decl)
7243 tree context = NULL_TREE;
7245 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7246 context = DECL_CONTEXT (decl);
7248 context = TYPE_MAIN_VARIANT
7249 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7251 if (context && !TYPE_P (context))
7252 context = NULL_TREE;
7257 /* Add an attribute/value pair to a DIE. */
7260 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7262 /* Maybe this should be an assert? */
7266 if (die->die_attr == NULL)
7267 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7268 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7271 static inline enum dw_val_class
7272 AT_class (dw_attr_ref a)
7274 return a->dw_attr_val.val_class;
7277 /* Add a flag value attribute to a DIE. */
7280 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7284 attr.dw_attr = attr_kind;
7285 attr.dw_attr_val.val_class = dw_val_class_flag;
7286 attr.dw_attr_val.v.val_flag = flag;
7287 add_dwarf_attr (die, &attr);
7290 static inline unsigned
7291 AT_flag (dw_attr_ref a)
7293 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7294 return a->dw_attr_val.v.val_flag;
7297 /* Add a signed integer attribute value to a DIE. */
7300 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7304 attr.dw_attr = attr_kind;
7305 attr.dw_attr_val.val_class = dw_val_class_const;
7306 attr.dw_attr_val.v.val_int = int_val;
7307 add_dwarf_attr (die, &attr);
7310 static inline HOST_WIDE_INT
7311 AT_int (dw_attr_ref a)
7313 gcc_assert (a && AT_class (a) == dw_val_class_const);
7314 return a->dw_attr_val.v.val_int;
7317 /* Add an unsigned integer attribute value to a DIE. */
7320 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7321 unsigned HOST_WIDE_INT unsigned_val)
7325 attr.dw_attr = attr_kind;
7326 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7327 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7328 add_dwarf_attr (die, &attr);
7331 static inline unsigned HOST_WIDE_INT
7332 AT_unsigned (dw_attr_ref a)
7334 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7335 return a->dw_attr_val.v.val_unsigned;
7338 /* Add an unsigned double integer attribute value to a DIE. */
7341 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7342 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7346 attr.dw_attr = attr_kind;
7347 attr.dw_attr_val.val_class = dw_val_class_const_double;
7348 attr.dw_attr_val.v.val_double.high = high;
7349 attr.dw_attr_val.v.val_double.low = low;
7350 add_dwarf_attr (die, &attr);
7353 /* Add a floating point attribute value to a DIE and return it. */
7356 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7357 unsigned int length, unsigned int elt_size, unsigned char *array)
7361 attr.dw_attr = attr_kind;
7362 attr.dw_attr_val.val_class = dw_val_class_vec;
7363 attr.dw_attr_val.v.val_vec.length = length;
7364 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7365 attr.dw_attr_val.v.val_vec.array = array;
7366 add_dwarf_attr (die, &attr);
7369 /* Add an 8-byte data attribute value to a DIE. */
7372 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7373 unsigned char data8[8])
7377 attr.dw_attr = attr_kind;
7378 attr.dw_attr_val.val_class = dw_val_class_data8;
7379 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7380 add_dwarf_attr (die, &attr);
7383 /* Hash and equality functions for debug_str_hash. */
7386 debug_str_do_hash (const void *x)
7388 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7392 debug_str_eq (const void *x1, const void *x2)
7394 return strcmp ((((const struct indirect_string_node *)x1)->str),
7395 (const char *)x2) == 0;
7398 /* Add STR to the indirect string hash table. */
7400 static struct indirect_string_node *
7401 find_AT_string (const char *str)
7403 struct indirect_string_node *node;
7406 if (! debug_str_hash)
7407 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7408 debug_str_eq, NULL);
7410 slot = htab_find_slot_with_hash (debug_str_hash, str,
7411 htab_hash_string (str), INSERT);
7414 node = ggc_alloc_cleared_indirect_string_node ();
7415 node->str = ggc_strdup (str);
7419 node = (struct indirect_string_node *) *slot;
7425 /* Add a string attribute value to a DIE. */
7428 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7431 struct indirect_string_node *node;
7433 node = find_AT_string (str);
7435 attr.dw_attr = attr_kind;
7436 attr.dw_attr_val.val_class = dw_val_class_str;
7437 attr.dw_attr_val.v.val_str = node;
7438 add_dwarf_attr (die, &attr);
7441 /* Create a label for an indirect string node, ensuring it is going to
7442 be output, unless its reference count goes down to zero. */
7445 gen_label_for_indirect_string (struct indirect_string_node *node)
7452 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7453 ++dw2_string_counter;
7454 node->label = xstrdup (label);
7457 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7458 debug string STR. */
7461 get_debug_string_label (const char *str)
7463 struct indirect_string_node *node = find_AT_string (str);
7465 debug_str_hash_forced = true;
7467 gen_label_for_indirect_string (node);
7469 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7472 static inline const char *
7473 AT_string (dw_attr_ref a)
7475 gcc_assert (a && AT_class (a) == dw_val_class_str);
7476 return a->dw_attr_val.v.val_str->str;
7479 /* Find out whether a string should be output inline in DIE
7480 or out-of-line in .debug_str section. */
7482 static enum dwarf_form
7483 AT_string_form (dw_attr_ref a)
7485 struct indirect_string_node *node;
7488 gcc_assert (a && AT_class (a) == dw_val_class_str);
7490 node = a->dw_attr_val.v.val_str;
7494 len = strlen (node->str) + 1;
7496 /* If the string is shorter or equal to the size of the reference, it is
7497 always better to put it inline. */
7498 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7499 return node->form = DW_FORM_string;
7501 /* If we cannot expect the linker to merge strings in .debug_str
7502 section, only put it into .debug_str if it is worth even in this
7504 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7505 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7506 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7507 return node->form = DW_FORM_string;
7509 gen_label_for_indirect_string (node);
7511 return node->form = DW_FORM_strp;
7514 /* Add a DIE reference attribute value to a DIE. */
7517 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7521 #ifdef ENABLE_CHECKING
7522 gcc_assert (targ_die != NULL);
7524 /* With LTO we can end up trying to reference something we didn't create
7525 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7526 if (targ_die == NULL)
7530 attr.dw_attr = attr_kind;
7531 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7532 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7533 attr.dw_attr_val.v.val_die_ref.external = 0;
7534 add_dwarf_attr (die, &attr);
7537 /* Add an AT_specification attribute to a DIE, and also make the back
7538 pointer from the specification to the definition. */
7541 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7543 add_AT_die_ref (die, DW_AT_specification, targ_die);
7544 gcc_assert (!targ_die->die_definition);
7545 targ_die->die_definition = die;
7548 static inline dw_die_ref
7549 AT_ref (dw_attr_ref a)
7551 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7552 return a->dw_attr_val.v.val_die_ref.die;
7556 AT_ref_external (dw_attr_ref a)
7558 if (a && AT_class (a) == dw_val_class_die_ref)
7559 return a->dw_attr_val.v.val_die_ref.external;
7565 set_AT_ref_external (dw_attr_ref a, int i)
7567 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7568 a->dw_attr_val.v.val_die_ref.external = i;
7571 /* Add an FDE reference attribute value to a DIE. */
7574 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7578 attr.dw_attr = attr_kind;
7579 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7580 attr.dw_attr_val.v.val_fde_index = targ_fde;
7581 add_dwarf_attr (die, &attr);
7584 /* Add a location description attribute value to a DIE. */
7587 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7591 attr.dw_attr = attr_kind;
7592 attr.dw_attr_val.val_class = dw_val_class_loc;
7593 attr.dw_attr_val.v.val_loc = loc;
7594 add_dwarf_attr (die, &attr);
7597 static inline dw_loc_descr_ref
7598 AT_loc (dw_attr_ref a)
7600 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7601 return a->dw_attr_val.v.val_loc;
7605 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7609 attr.dw_attr = attr_kind;
7610 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7611 attr.dw_attr_val.v.val_loc_list = loc_list;
7612 add_dwarf_attr (die, &attr);
7613 have_location_lists = true;
7616 static inline dw_loc_list_ref
7617 AT_loc_list (dw_attr_ref a)
7619 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7620 return a->dw_attr_val.v.val_loc_list;
7623 static inline dw_loc_list_ref *
7624 AT_loc_list_ptr (dw_attr_ref a)
7626 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7627 return &a->dw_attr_val.v.val_loc_list;
7630 /* Add an address constant attribute value to a DIE. */
7633 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7637 attr.dw_attr = attr_kind;
7638 attr.dw_attr_val.val_class = dw_val_class_addr;
7639 attr.dw_attr_val.v.val_addr = addr;
7640 add_dwarf_attr (die, &attr);
7643 /* Get the RTX from to an address DIE attribute. */
7646 AT_addr (dw_attr_ref a)
7648 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7649 return a->dw_attr_val.v.val_addr;
7652 /* Add a file attribute value to a DIE. */
7655 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7656 struct dwarf_file_data *fd)
7660 attr.dw_attr = attr_kind;
7661 attr.dw_attr_val.val_class = dw_val_class_file;
7662 attr.dw_attr_val.v.val_file = fd;
7663 add_dwarf_attr (die, &attr);
7666 /* Get the dwarf_file_data from a file DIE attribute. */
7668 static inline struct dwarf_file_data *
7669 AT_file (dw_attr_ref a)
7671 gcc_assert (a && AT_class (a) == dw_val_class_file);
7672 return a->dw_attr_val.v.val_file;
7675 /* Add a vms delta attribute value to a DIE. */
7678 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7679 const char *lbl1, const char *lbl2)
7683 attr.dw_attr = attr_kind;
7684 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7685 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7686 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7687 add_dwarf_attr (die, &attr);
7690 /* Add a label identifier attribute value to a DIE. */
7693 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7697 attr.dw_attr = attr_kind;
7698 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7699 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7700 add_dwarf_attr (die, &attr);
7703 /* Add a section offset attribute value to a DIE, an offset into the
7704 debug_line section. */
7707 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7712 attr.dw_attr = attr_kind;
7713 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7714 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7715 add_dwarf_attr (die, &attr);
7718 /* Add a section offset attribute value to a DIE, an offset into the
7719 debug_macinfo section. */
7722 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7727 attr.dw_attr = attr_kind;
7728 attr.dw_attr_val.val_class = dw_val_class_macptr;
7729 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7730 add_dwarf_attr (die, &attr);
7733 /* Add an offset attribute value to a DIE. */
7736 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7737 unsigned HOST_WIDE_INT offset)
7741 attr.dw_attr = attr_kind;
7742 attr.dw_attr_val.val_class = dw_val_class_offset;
7743 attr.dw_attr_val.v.val_offset = offset;
7744 add_dwarf_attr (die, &attr);
7747 /* Add an range_list attribute value to a DIE. */
7750 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7751 long unsigned int offset)
7755 attr.dw_attr = attr_kind;
7756 attr.dw_attr_val.val_class = dw_val_class_range_list;
7757 attr.dw_attr_val.v.val_offset = offset;
7758 add_dwarf_attr (die, &attr);
7761 /* Return the start label of a delta attribute. */
7763 static inline const char *
7764 AT_vms_delta1 (dw_attr_ref a)
7766 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7767 return a->dw_attr_val.v.val_vms_delta.lbl1;
7770 /* Return the end label of a delta attribute. */
7772 static inline const char *
7773 AT_vms_delta2 (dw_attr_ref a)
7775 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7776 return a->dw_attr_val.v.val_vms_delta.lbl2;
7779 static inline const char *
7780 AT_lbl (dw_attr_ref a)
7782 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7783 || AT_class (a) == dw_val_class_lineptr
7784 || AT_class (a) == dw_val_class_macptr));
7785 return a->dw_attr_val.v.val_lbl_id;
7788 /* Get the attribute of type attr_kind. */
7791 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7795 dw_die_ref spec = NULL;
7800 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7801 if (a->dw_attr == attr_kind)
7803 else if (a->dw_attr == DW_AT_specification
7804 || a->dw_attr == DW_AT_abstract_origin)
7808 return get_AT (spec, attr_kind);
7813 /* Return the "low pc" attribute value, typically associated with a subprogram
7814 DIE. Return null if the "low pc" attribute is either not present, or if it
7815 cannot be represented as an assembler label identifier. */
7817 static inline const char *
7818 get_AT_low_pc (dw_die_ref die)
7820 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7822 return a ? AT_lbl (a) : NULL;
7825 /* Return the "high pc" attribute value, typically associated with a subprogram
7826 DIE. Return null if the "high pc" attribute is either not present, or if it
7827 cannot be represented as an assembler label identifier. */
7829 static inline const char *
7830 get_AT_hi_pc (dw_die_ref die)
7832 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7834 return a ? AT_lbl (a) : NULL;
7837 /* Return the value of the string attribute designated by ATTR_KIND, or
7838 NULL if it is not present. */
7840 static inline const char *
7841 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7843 dw_attr_ref a = get_AT (die, attr_kind);
7845 return a ? AT_string (a) : NULL;
7848 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7849 if it is not present. */
7852 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7854 dw_attr_ref a = get_AT (die, attr_kind);
7856 return a ? AT_flag (a) : 0;
7859 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7860 if it is not present. */
7862 static inline unsigned
7863 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7865 dw_attr_ref a = get_AT (die, attr_kind);
7867 return a ? AT_unsigned (a) : 0;
7870 static inline dw_die_ref
7871 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7873 dw_attr_ref a = get_AT (die, attr_kind);
7875 return a ? AT_ref (a) : NULL;
7878 static inline struct dwarf_file_data *
7879 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7881 dw_attr_ref a = get_AT (die, attr_kind);
7883 return a ? AT_file (a) : NULL;
7886 /* Return TRUE if the language is C++. */
7891 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7893 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7896 /* Return TRUE if the language is Fortran. */
7901 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7903 return (lang == DW_LANG_Fortran77
7904 || lang == DW_LANG_Fortran90
7905 || lang == DW_LANG_Fortran95);
7908 /* Return TRUE if the language is Ada. */
7913 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7915 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7918 /* Remove the specified attribute if present. */
7921 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7929 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7930 if (a->dw_attr == attr_kind)
7932 if (AT_class (a) == dw_val_class_str)
7933 if (a->dw_attr_val.v.val_str->refcount)
7934 a->dw_attr_val.v.val_str->refcount--;
7936 /* VEC_ordered_remove should help reduce the number of abbrevs
7938 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7943 /* Remove CHILD from its parent. PREV must have the property that
7944 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7947 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7949 gcc_assert (child->die_parent == prev->die_parent);
7950 gcc_assert (prev->die_sib == child);
7953 gcc_assert (child->die_parent->die_child == child);
7957 prev->die_sib = child->die_sib;
7958 if (child->die_parent->die_child == child)
7959 child->die_parent->die_child = prev;
7962 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7963 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7966 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
7968 dw_die_ref parent = old_child->die_parent;
7970 gcc_assert (parent == prev->die_parent);
7971 gcc_assert (prev->die_sib == old_child);
7973 new_child->die_parent = parent;
7974 if (prev == old_child)
7976 gcc_assert (parent->die_child == old_child);
7977 new_child->die_sib = new_child;
7981 prev->die_sib = new_child;
7982 new_child->die_sib = old_child->die_sib;
7984 if (old_child->die_parent->die_child == old_child)
7985 old_child->die_parent->die_child = new_child;
7988 /* Move all children from OLD_PARENT to NEW_PARENT. */
7991 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
7994 new_parent->die_child = old_parent->die_child;
7995 old_parent->die_child = NULL;
7996 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
7999 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8003 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8009 dw_die_ref prev = c;
8011 while (c->die_tag == tag)
8013 remove_child_with_prev (c, prev);
8014 /* Might have removed every child. */
8015 if (c == c->die_sib)
8019 } while (c != die->die_child);
8022 /* Add a CHILD_DIE as the last child of DIE. */
8025 add_child_die (dw_die_ref die, dw_die_ref child_die)
8027 /* FIXME this should probably be an assert. */
8028 if (! die || ! child_die)
8030 gcc_assert (die != child_die);
8032 child_die->die_parent = die;
8035 child_die->die_sib = die->die_child->die_sib;
8036 die->die_child->die_sib = child_die;
8039 child_die->die_sib = child_die;
8040 die->die_child = child_die;
8043 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8044 is the specification, to the end of PARENT's list of children.
8045 This is done by removing and re-adding it. */
8048 splice_child_die (dw_die_ref parent, dw_die_ref child)
8052 /* We want the declaration DIE from inside the class, not the
8053 specification DIE at toplevel. */
8054 if (child->die_parent != parent)
8056 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8062 gcc_assert (child->die_parent == parent
8063 || (child->die_parent
8064 == get_AT_ref (parent, DW_AT_specification)));
8066 for (p = child->die_parent->die_child; ; p = p->die_sib)
8067 if (p->die_sib == child)
8069 remove_child_with_prev (child, p);
8073 add_child_die (parent, child);
8076 /* Return a pointer to a newly created DIE node. */
8078 static inline dw_die_ref
8079 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8081 dw_die_ref die = ggc_alloc_cleared_die_node ();
8083 die->die_tag = tag_value;
8085 if (parent_die != NULL)
8086 add_child_die (parent_die, die);
8089 limbo_die_node *limbo_node;
8091 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8092 limbo_node->die = die;
8093 limbo_node->created_for = t;
8094 limbo_node->next = limbo_die_list;
8095 limbo_die_list = limbo_node;
8101 /* Return the DIE associated with the given type specifier. */
8103 static inline dw_die_ref
8104 lookup_type_die (tree type)
8106 return TYPE_SYMTAB_DIE (type);
8109 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8110 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8111 anonymous type instead the one of the naming typedef. */
8113 static inline dw_die_ref
8114 strip_naming_typedef (tree type, dw_die_ref type_die)
8117 && TREE_CODE (type) == RECORD_TYPE
8119 && type_die->die_tag == DW_TAG_typedef
8120 && is_naming_typedef_decl (TYPE_NAME (type)))
8121 type_die = get_AT_ref (type_die, DW_AT_type);
8125 /* Like lookup_type_die, but if type is an anonymous type named by a
8126 typedef[1], return the DIE of the anonymous type instead the one of
8127 the naming typedef. This is because in gen_typedef_die, we did
8128 equate the anonymous struct named by the typedef with the DIE of
8129 the naming typedef. So by default, lookup_type_die on an anonymous
8130 struct yields the DIE of the naming typedef.
8132 [1]: Read the comment of is_naming_typedef_decl to learn about what
8133 a naming typedef is. */
8135 static inline dw_die_ref
8136 lookup_type_die_strip_naming_typedef (tree type)
8138 dw_die_ref die = lookup_type_die (type);
8139 return strip_naming_typedef (type, die);
8142 /* Equate a DIE to a given type specifier. */
8145 equate_type_number_to_die (tree type, dw_die_ref type_die)
8147 TYPE_SYMTAB_DIE (type) = type_die;
8150 /* Returns a hash value for X (which really is a die_struct). */
8153 decl_die_table_hash (const void *x)
8155 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8158 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8161 decl_die_table_eq (const void *x, const void *y)
8163 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8166 /* Return the DIE associated with a given declaration. */
8168 static inline dw_die_ref
8169 lookup_decl_die (tree decl)
8171 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8174 /* Returns a hash value for X (which really is a var_loc_list). */
8177 decl_loc_table_hash (const void *x)
8179 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8182 /* Return nonzero if decl_id of var_loc_list X is the same as
8186 decl_loc_table_eq (const void *x, const void *y)
8188 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8191 /* Return the var_loc list associated with a given declaration. */
8193 static inline var_loc_list *
8194 lookup_decl_loc (const_tree decl)
8196 if (!decl_loc_table)
8198 return (var_loc_list *)
8199 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8202 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
8205 cached_dw_loc_list_table_hash (const void *x)
8207 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
8210 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
8214 cached_dw_loc_list_table_eq (const void *x, const void *y)
8216 return (((const cached_dw_loc_list *) x)->decl_id
8217 == DECL_UID ((const_tree) y));
8220 /* Equate a DIE to a particular declaration. */
8223 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8225 unsigned int decl_id = DECL_UID (decl);
8228 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8230 decl_die->decl_id = decl_id;
8233 /* Return how many bits covers PIECE EXPR_LIST. */
8236 decl_piece_bitsize (rtx piece)
8238 int ret = (int) GET_MODE (piece);
8241 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8242 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8243 return INTVAL (XEXP (XEXP (piece, 0), 0));
8246 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8249 decl_piece_varloc_ptr (rtx piece)
8251 if ((int) GET_MODE (piece))
8252 return &XEXP (piece, 0);
8254 return &XEXP (XEXP (piece, 0), 1);
8257 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8258 Next is the chain of following piece nodes. */
8261 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8263 if (bitsize <= (int) MAX_MACHINE_MODE)
8264 return alloc_EXPR_LIST (bitsize, loc_note, next);
8266 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8271 /* Return rtx that should be stored into loc field for
8272 LOC_NOTE and BITPOS/BITSIZE. */
8275 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8276 HOST_WIDE_INT bitsize)
8280 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8282 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8287 /* This function either modifies location piece list *DEST in
8288 place (if SRC and INNER is NULL), or copies location piece list
8289 *SRC to *DEST while modifying it. Location BITPOS is modified
8290 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8291 not copied and if needed some padding around it is added.
8292 When modifying in place, DEST should point to EXPR_LIST where
8293 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8294 to the start of the whole list and INNER points to the EXPR_LIST
8295 where earlier pieces cover PIECE_BITPOS bits. */
8298 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8299 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8300 HOST_WIDE_INT bitsize, rtx loc_note)
8303 bool copy = inner != NULL;
8307 /* First copy all nodes preceeding the current bitpos. */
8308 while (src != inner)
8310 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8311 decl_piece_bitsize (*src), NULL_RTX);
8312 dest = &XEXP (*dest, 1);
8313 src = &XEXP (*src, 1);
8316 /* Add padding if needed. */
8317 if (bitpos != piece_bitpos)
8319 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8320 copy ? NULL_RTX : *dest);
8321 dest = &XEXP (*dest, 1);
8323 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8326 /* A piece with correct bitpos and bitsize already exist,
8327 just update the location for it and return. */
8328 *decl_piece_varloc_ptr (*dest) = loc_note;
8331 /* Add the piece that changed. */
8332 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8333 dest = &XEXP (*dest, 1);
8334 /* Skip over pieces that overlap it. */
8335 diff = bitpos - piece_bitpos + bitsize;
8338 while (diff > 0 && *src)
8341 diff -= decl_piece_bitsize (piece);
8343 src = &XEXP (piece, 1);
8346 *src = XEXP (piece, 1);
8347 free_EXPR_LIST_node (piece);
8350 /* Add padding if needed. */
8351 if (diff < 0 && *src)
8355 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8356 dest = &XEXP (*dest, 1);
8360 /* Finally copy all nodes following it. */
8363 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8364 decl_piece_bitsize (*src), NULL_RTX);
8365 dest = &XEXP (*dest, 1);
8366 src = &XEXP (*src, 1);
8370 /* Add a variable location node to the linked list for DECL. */
8372 static struct var_loc_node *
8373 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8375 unsigned int decl_id;
8378 struct var_loc_node *loc = NULL;
8379 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8381 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8383 tree realdecl = DECL_DEBUG_EXPR (decl);
8384 if (realdecl && handled_component_p (realdecl))
8386 HOST_WIDE_INT maxsize;
8389 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8390 if (!DECL_P (innerdecl)
8391 || DECL_IGNORED_P (innerdecl)
8392 || TREE_STATIC (innerdecl)
8394 || bitpos + bitsize > 256
8395 || bitsize != maxsize)
8401 decl_id = DECL_UID (decl);
8402 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8405 temp = ggc_alloc_cleared_var_loc_list ();
8406 temp->decl_id = decl_id;
8410 temp = (var_loc_list *) *slot;
8414 struct var_loc_node *last = temp->last, *unused = NULL;
8415 rtx *piece_loc = NULL, last_loc_note;
8416 int piece_bitpos = 0;
8420 gcc_assert (last->next == NULL);
8422 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8424 piece_loc = &last->loc;
8427 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8428 if (piece_bitpos + cur_bitsize > bitpos)
8430 piece_bitpos += cur_bitsize;
8431 piece_loc = &XEXP (*piece_loc, 1);
8435 /* TEMP->LAST here is either pointer to the last but one or
8436 last element in the chained list, LAST is pointer to the
8438 if (label && strcmp (last->label, label) == 0)
8440 /* For SRA optimized variables if there weren't any real
8441 insns since last note, just modify the last node. */
8442 if (piece_loc != NULL)
8444 adjust_piece_list (piece_loc, NULL, NULL,
8445 bitpos, piece_bitpos, bitsize, loc_note);
8448 /* If the last note doesn't cover any instructions, remove it. */
8449 if (temp->last != last)
8451 temp->last->next = NULL;
8454 gcc_assert (strcmp (last->label, label) != 0);
8458 gcc_assert (temp->first == temp->last);
8459 memset (temp->last, '\0', sizeof (*temp->last));
8460 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8464 if (bitsize == -1 && NOTE_P (last->loc))
8465 last_loc_note = last->loc;
8466 else if (piece_loc != NULL
8467 && *piece_loc != NULL_RTX
8468 && piece_bitpos == bitpos
8469 && decl_piece_bitsize (*piece_loc) == bitsize)
8470 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8472 last_loc_note = NULL_RTX;
8473 /* If the current location is the same as the end of the list,
8474 and either both or neither of the locations is uninitialized,
8475 we have nothing to do. */
8476 if (last_loc_note == NULL_RTX
8477 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8478 NOTE_VAR_LOCATION_LOC (loc_note)))
8479 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8480 != NOTE_VAR_LOCATION_STATUS (loc_note))
8481 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8482 == VAR_INIT_STATUS_UNINITIALIZED)
8483 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8484 == VAR_INIT_STATUS_UNINITIALIZED))))
8486 /* Add LOC to the end of list and update LAST. If the last
8487 element of the list has been removed above, reuse its
8488 memory for the new node, otherwise allocate a new one. */
8492 memset (loc, '\0', sizeof (*loc));
8495 loc = ggc_alloc_cleared_var_loc_node ();
8496 if (bitsize == -1 || piece_loc == NULL)
8497 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8499 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8500 bitpos, piece_bitpos, bitsize, loc_note);
8502 /* Ensure TEMP->LAST will point either to the new last but one
8503 element of the chain, or to the last element in it. */
8504 if (last != temp->last)
8512 loc = ggc_alloc_cleared_var_loc_node ();
8515 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8520 /* Keep track of the number of spaces used to indent the
8521 output of the debugging routines that print the structure of
8522 the DIE internal representation. */
8523 static int print_indent;
8525 /* Indent the line the number of spaces given by print_indent. */
8528 print_spaces (FILE *outfile)
8530 fprintf (outfile, "%*s", print_indent, "");
8533 /* Print a type signature in hex. */
8536 print_signature (FILE *outfile, char *sig)
8540 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8541 fprintf (outfile, "%02x", sig[i] & 0xff);
8544 /* Print the information associated with a given DIE, and its children.
8545 This routine is a debugging aid only. */
8548 print_die (dw_die_ref die, FILE *outfile)
8554 print_spaces (outfile);
8555 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8556 die->die_offset, dwarf_tag_name (die->die_tag),
8558 print_spaces (outfile);
8559 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8560 fprintf (outfile, " offset: %ld", die->die_offset);
8561 fprintf (outfile, " mark: %d\n", die->die_mark);
8563 if (dwarf_version >= 4 && die->die_id.die_type_node)
8565 print_spaces (outfile);
8566 fprintf (outfile, " signature: ");
8567 print_signature (outfile, die->die_id.die_type_node->signature);
8568 fprintf (outfile, "\n");
8571 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8573 print_spaces (outfile);
8574 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8576 switch (AT_class (a))
8578 case dw_val_class_addr:
8579 fprintf (outfile, "address");
8581 case dw_val_class_offset:
8582 fprintf (outfile, "offset");
8584 case dw_val_class_loc:
8585 fprintf (outfile, "location descriptor");
8587 case dw_val_class_loc_list:
8588 fprintf (outfile, "location list -> label:%s",
8589 AT_loc_list (a)->ll_symbol);
8591 case dw_val_class_range_list:
8592 fprintf (outfile, "range list");
8594 case dw_val_class_const:
8595 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8597 case dw_val_class_unsigned_const:
8598 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8600 case dw_val_class_const_double:
8601 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8602 HOST_WIDE_INT_PRINT_UNSIGNED")",
8603 a->dw_attr_val.v.val_double.high,
8604 a->dw_attr_val.v.val_double.low);
8606 case dw_val_class_vec:
8607 fprintf (outfile, "floating-point or vector constant");
8609 case dw_val_class_flag:
8610 fprintf (outfile, "%u", AT_flag (a));
8612 case dw_val_class_die_ref:
8613 if (AT_ref (a) != NULL)
8615 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8617 fprintf (outfile, "die -> signature: ");
8618 print_signature (outfile,
8619 AT_ref (a)->die_id.die_type_node->signature);
8621 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8622 fprintf (outfile, "die -> label: %s",
8623 AT_ref (a)->die_id.die_symbol);
8625 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8626 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8629 fprintf (outfile, "die -> <null>");
8631 case dw_val_class_vms_delta:
8632 fprintf (outfile, "delta: @slotcount(%s-%s)",
8633 AT_vms_delta2 (a), AT_vms_delta1 (a));
8635 case dw_val_class_lbl_id:
8636 case dw_val_class_lineptr:
8637 case dw_val_class_macptr:
8638 fprintf (outfile, "label: %s", AT_lbl (a));
8640 case dw_val_class_str:
8641 if (AT_string (a) != NULL)
8642 fprintf (outfile, "\"%s\"", AT_string (a));
8644 fprintf (outfile, "<null>");
8646 case dw_val_class_file:
8647 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8648 AT_file (a)->emitted_number);
8650 case dw_val_class_data8:
8654 for (i = 0; i < 8; i++)
8655 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8662 fprintf (outfile, "\n");
8665 if (die->die_child != NULL)
8668 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8671 if (print_indent == 0)
8672 fprintf (outfile, "\n");
8675 /* Print the contents of the source code line number correspondence table.
8676 This routine is a debugging aid only. */
8679 print_dwarf_line_table (FILE *outfile)
8682 dw_line_info_ref line_info;
8684 fprintf (outfile, "\n\nDWARF source line information\n");
8685 for (i = 1; i < line_info_table_in_use; i++)
8687 line_info = &line_info_table[i];
8688 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8689 line_info->dw_file_num,
8690 line_info->dw_line_num);
8693 fprintf (outfile, "\n\n");
8696 /* Print the information collected for a given DIE. */
8699 debug_dwarf_die (dw_die_ref die)
8701 print_die (die, stderr);
8704 /* Print all DWARF information collected for the compilation unit.
8705 This routine is a debugging aid only. */
8711 print_die (comp_unit_die (), stderr);
8712 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8713 print_dwarf_line_table (stderr);
8716 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8717 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8718 DIE that marks the start of the DIEs for this include file. */
8721 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8723 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8724 dw_die_ref new_unit = gen_compile_unit_die (filename);
8726 new_unit->die_sib = old_unit;
8730 /* Close an include-file CU and reopen the enclosing one. */
8733 pop_compile_unit (dw_die_ref old_unit)
8735 dw_die_ref new_unit = old_unit->die_sib;
8737 old_unit->die_sib = NULL;
8741 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8742 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8744 /* Calculate the checksum of a location expression. */
8747 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8751 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8753 CHECKSUM (loc->dw_loc_oprnd1);
8754 CHECKSUM (loc->dw_loc_oprnd2);
8757 /* Calculate the checksum of an attribute. */
8760 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8762 dw_loc_descr_ref loc;
8765 CHECKSUM (at->dw_attr);
8767 /* We don't care that this was compiled with a different compiler
8768 snapshot; if the output is the same, that's what matters. */
8769 if (at->dw_attr == DW_AT_producer)
8772 switch (AT_class (at))
8774 case dw_val_class_const:
8775 CHECKSUM (at->dw_attr_val.v.val_int);
8777 case dw_val_class_unsigned_const:
8778 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8780 case dw_val_class_const_double:
8781 CHECKSUM (at->dw_attr_val.v.val_double);
8783 case dw_val_class_vec:
8784 CHECKSUM (at->dw_attr_val.v.val_vec);
8786 case dw_val_class_flag:
8787 CHECKSUM (at->dw_attr_val.v.val_flag);
8789 case dw_val_class_str:
8790 CHECKSUM_STRING (AT_string (at));
8793 case dw_val_class_addr:
8795 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8796 CHECKSUM_STRING (XSTR (r, 0));
8799 case dw_val_class_offset:
8800 CHECKSUM (at->dw_attr_val.v.val_offset);
8803 case dw_val_class_loc:
8804 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8805 loc_checksum (loc, ctx);
8808 case dw_val_class_die_ref:
8809 die_checksum (AT_ref (at), ctx, mark);
8812 case dw_val_class_fde_ref:
8813 case dw_val_class_vms_delta:
8814 case dw_val_class_lbl_id:
8815 case dw_val_class_lineptr:
8816 case dw_val_class_macptr:
8819 case dw_val_class_file:
8820 CHECKSUM_STRING (AT_file (at)->filename);
8823 case dw_val_class_data8:
8824 CHECKSUM (at->dw_attr_val.v.val_data8);
8832 /* Calculate the checksum of a DIE. */
8835 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8841 /* To avoid infinite recursion. */
8844 CHECKSUM (die->die_mark);
8847 die->die_mark = ++(*mark);
8849 CHECKSUM (die->die_tag);
8851 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8852 attr_checksum (a, ctx, mark);
8854 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8858 #undef CHECKSUM_STRING
8860 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8861 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8862 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8863 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8864 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8865 #define CHECKSUM_ATTR(FOO) \
8866 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8868 /* Calculate the checksum of a number in signed LEB128 format. */
8871 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8878 byte = (value & 0x7f);
8880 more = !((value == 0 && (byte & 0x40) == 0)
8881 || (value == -1 && (byte & 0x40) != 0));
8890 /* Calculate the checksum of a number in unsigned LEB128 format. */
8893 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8897 unsigned char byte = (value & 0x7f);
8900 /* More bytes to follow. */
8908 /* Checksum the context of the DIE. This adds the names of any
8909 surrounding namespaces or structures to the checksum. */
8912 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8916 int tag = die->die_tag;
8918 if (tag != DW_TAG_namespace
8919 && tag != DW_TAG_structure_type
8920 && tag != DW_TAG_class_type)
8923 name = get_AT_string (die, DW_AT_name);
8925 spec = get_AT_ref (die, DW_AT_specification);
8929 if (die->die_parent != NULL)
8930 checksum_die_context (die->die_parent, ctx);
8932 CHECKSUM_ULEB128 ('C');
8933 CHECKSUM_ULEB128 (tag);
8935 CHECKSUM_STRING (name);
8938 /* Calculate the checksum of a location expression. */
8941 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8943 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8944 were emitted as a DW_FORM_sdata instead of a location expression. */
8945 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8947 CHECKSUM_ULEB128 (DW_FORM_sdata);
8948 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8952 /* Otherwise, just checksum the raw location expression. */
8955 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8956 CHECKSUM (loc->dw_loc_oprnd1);
8957 CHECKSUM (loc->dw_loc_oprnd2);
8958 loc = loc->dw_loc_next;
8962 /* Calculate the checksum of an attribute. */
8965 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8966 struct md5_ctx *ctx, int *mark)
8968 dw_loc_descr_ref loc;
8971 if (AT_class (at) == dw_val_class_die_ref)
8973 dw_die_ref target_die = AT_ref (at);
8975 /* For pointer and reference types, we checksum only the (qualified)
8976 name of the target type (if there is a name). For friend entries,
8977 we checksum only the (qualified) name of the target type or function.
8978 This allows the checksum to remain the same whether the target type
8979 is complete or not. */
8980 if ((at->dw_attr == DW_AT_type
8981 && (tag == DW_TAG_pointer_type
8982 || tag == DW_TAG_reference_type
8983 || tag == DW_TAG_rvalue_reference_type
8984 || tag == DW_TAG_ptr_to_member_type))
8985 || (at->dw_attr == DW_AT_friend
8986 && tag == DW_TAG_friend))
8988 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
8990 if (name_attr != NULL)
8992 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8996 CHECKSUM_ULEB128 ('N');
8997 CHECKSUM_ULEB128 (at->dw_attr);
8998 if (decl->die_parent != NULL)
8999 checksum_die_context (decl->die_parent, ctx);
9000 CHECKSUM_ULEB128 ('E');
9001 CHECKSUM_STRING (AT_string (name_attr));
9006 /* For all other references to another DIE, we check to see if the
9007 target DIE has already been visited. If it has, we emit a
9008 backward reference; if not, we descend recursively. */
9009 if (target_die->die_mark > 0)
9011 CHECKSUM_ULEB128 ('R');
9012 CHECKSUM_ULEB128 (at->dw_attr);
9013 CHECKSUM_ULEB128 (target_die->die_mark);
9017 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9021 target_die->die_mark = ++(*mark);
9022 CHECKSUM_ULEB128 ('T');
9023 CHECKSUM_ULEB128 (at->dw_attr);
9024 if (decl->die_parent != NULL)
9025 checksum_die_context (decl->die_parent, ctx);
9026 die_checksum_ordered (target_die, ctx, mark);
9031 CHECKSUM_ULEB128 ('A');
9032 CHECKSUM_ULEB128 (at->dw_attr);
9034 switch (AT_class (at))
9036 case dw_val_class_const:
9037 CHECKSUM_ULEB128 (DW_FORM_sdata);
9038 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9041 case dw_val_class_unsigned_const:
9042 CHECKSUM_ULEB128 (DW_FORM_sdata);
9043 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9046 case dw_val_class_const_double:
9047 CHECKSUM_ULEB128 (DW_FORM_block);
9048 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9049 CHECKSUM (at->dw_attr_val.v.val_double);
9052 case dw_val_class_vec:
9053 CHECKSUM_ULEB128 (DW_FORM_block);
9054 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9055 CHECKSUM (at->dw_attr_val.v.val_vec);
9058 case dw_val_class_flag:
9059 CHECKSUM_ULEB128 (DW_FORM_flag);
9060 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9063 case dw_val_class_str:
9064 CHECKSUM_ULEB128 (DW_FORM_string);
9065 CHECKSUM_STRING (AT_string (at));
9068 case dw_val_class_addr:
9070 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9071 CHECKSUM_ULEB128 (DW_FORM_string);
9072 CHECKSUM_STRING (XSTR (r, 0));
9075 case dw_val_class_offset:
9076 CHECKSUM_ULEB128 (DW_FORM_sdata);
9077 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9080 case dw_val_class_loc:
9081 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9082 loc_checksum_ordered (loc, ctx);
9085 case dw_val_class_fde_ref:
9086 case dw_val_class_lbl_id:
9087 case dw_val_class_lineptr:
9088 case dw_val_class_macptr:
9091 case dw_val_class_file:
9092 CHECKSUM_ULEB128 (DW_FORM_string);
9093 CHECKSUM_STRING (AT_file (at)->filename);
9096 case dw_val_class_data8:
9097 CHECKSUM (at->dw_attr_val.v.val_data8);
9105 struct checksum_attributes
9107 dw_attr_ref at_name;
9108 dw_attr_ref at_type;
9109 dw_attr_ref at_friend;
9110 dw_attr_ref at_accessibility;
9111 dw_attr_ref at_address_class;
9112 dw_attr_ref at_allocated;
9113 dw_attr_ref at_artificial;
9114 dw_attr_ref at_associated;
9115 dw_attr_ref at_binary_scale;
9116 dw_attr_ref at_bit_offset;
9117 dw_attr_ref at_bit_size;
9118 dw_attr_ref at_bit_stride;
9119 dw_attr_ref at_byte_size;
9120 dw_attr_ref at_byte_stride;
9121 dw_attr_ref at_const_value;
9122 dw_attr_ref at_containing_type;
9123 dw_attr_ref at_count;
9124 dw_attr_ref at_data_location;
9125 dw_attr_ref at_data_member_location;
9126 dw_attr_ref at_decimal_scale;
9127 dw_attr_ref at_decimal_sign;
9128 dw_attr_ref at_default_value;
9129 dw_attr_ref at_digit_count;
9130 dw_attr_ref at_discr;
9131 dw_attr_ref at_discr_list;
9132 dw_attr_ref at_discr_value;
9133 dw_attr_ref at_encoding;
9134 dw_attr_ref at_endianity;
9135 dw_attr_ref at_explicit;
9136 dw_attr_ref at_is_optional;
9137 dw_attr_ref at_location;
9138 dw_attr_ref at_lower_bound;
9139 dw_attr_ref at_mutable;
9140 dw_attr_ref at_ordering;
9141 dw_attr_ref at_picture_string;
9142 dw_attr_ref at_prototyped;
9143 dw_attr_ref at_small;
9144 dw_attr_ref at_segment;
9145 dw_attr_ref at_string_length;
9146 dw_attr_ref at_threads_scaled;
9147 dw_attr_ref at_upper_bound;
9148 dw_attr_ref at_use_location;
9149 dw_attr_ref at_use_UTF8;
9150 dw_attr_ref at_variable_parameter;
9151 dw_attr_ref at_virtuality;
9152 dw_attr_ref at_visibility;
9153 dw_attr_ref at_vtable_elem_location;
9156 /* Collect the attributes that we will want to use for the checksum. */
9159 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9164 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9175 attrs->at_friend = a;
9177 case DW_AT_accessibility:
9178 attrs->at_accessibility = a;
9180 case DW_AT_address_class:
9181 attrs->at_address_class = a;
9183 case DW_AT_allocated:
9184 attrs->at_allocated = a;
9186 case DW_AT_artificial:
9187 attrs->at_artificial = a;
9189 case DW_AT_associated:
9190 attrs->at_associated = a;
9192 case DW_AT_binary_scale:
9193 attrs->at_binary_scale = a;
9195 case DW_AT_bit_offset:
9196 attrs->at_bit_offset = a;
9198 case DW_AT_bit_size:
9199 attrs->at_bit_size = a;
9201 case DW_AT_bit_stride:
9202 attrs->at_bit_stride = a;
9204 case DW_AT_byte_size:
9205 attrs->at_byte_size = a;
9207 case DW_AT_byte_stride:
9208 attrs->at_byte_stride = a;
9210 case DW_AT_const_value:
9211 attrs->at_const_value = a;
9213 case DW_AT_containing_type:
9214 attrs->at_containing_type = a;
9217 attrs->at_count = a;
9219 case DW_AT_data_location:
9220 attrs->at_data_location = a;
9222 case DW_AT_data_member_location:
9223 attrs->at_data_member_location = a;
9225 case DW_AT_decimal_scale:
9226 attrs->at_decimal_scale = a;
9228 case DW_AT_decimal_sign:
9229 attrs->at_decimal_sign = a;
9231 case DW_AT_default_value:
9232 attrs->at_default_value = a;
9234 case DW_AT_digit_count:
9235 attrs->at_digit_count = a;
9238 attrs->at_discr = a;
9240 case DW_AT_discr_list:
9241 attrs->at_discr_list = a;
9243 case DW_AT_discr_value:
9244 attrs->at_discr_value = a;
9246 case DW_AT_encoding:
9247 attrs->at_encoding = a;
9249 case DW_AT_endianity:
9250 attrs->at_endianity = a;
9252 case DW_AT_explicit:
9253 attrs->at_explicit = a;
9255 case DW_AT_is_optional:
9256 attrs->at_is_optional = a;
9258 case DW_AT_location:
9259 attrs->at_location = a;
9261 case DW_AT_lower_bound:
9262 attrs->at_lower_bound = a;
9265 attrs->at_mutable = a;
9267 case DW_AT_ordering:
9268 attrs->at_ordering = a;
9270 case DW_AT_picture_string:
9271 attrs->at_picture_string = a;
9273 case DW_AT_prototyped:
9274 attrs->at_prototyped = a;
9277 attrs->at_small = a;
9280 attrs->at_segment = a;
9282 case DW_AT_string_length:
9283 attrs->at_string_length = a;
9285 case DW_AT_threads_scaled:
9286 attrs->at_threads_scaled = a;
9288 case DW_AT_upper_bound:
9289 attrs->at_upper_bound = a;
9291 case DW_AT_use_location:
9292 attrs->at_use_location = a;
9294 case DW_AT_use_UTF8:
9295 attrs->at_use_UTF8 = a;
9297 case DW_AT_variable_parameter:
9298 attrs->at_variable_parameter = a;
9300 case DW_AT_virtuality:
9301 attrs->at_virtuality = a;
9303 case DW_AT_visibility:
9304 attrs->at_visibility = a;
9306 case DW_AT_vtable_elem_location:
9307 attrs->at_vtable_elem_location = a;
9315 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9318 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9322 struct checksum_attributes attrs;
9324 CHECKSUM_ULEB128 ('D');
9325 CHECKSUM_ULEB128 (die->die_tag);
9327 memset (&attrs, 0, sizeof (attrs));
9329 decl = get_AT_ref (die, DW_AT_specification);
9331 collect_checksum_attributes (&attrs, decl);
9332 collect_checksum_attributes (&attrs, die);
9334 CHECKSUM_ATTR (attrs.at_name);
9335 CHECKSUM_ATTR (attrs.at_accessibility);
9336 CHECKSUM_ATTR (attrs.at_address_class);
9337 CHECKSUM_ATTR (attrs.at_allocated);
9338 CHECKSUM_ATTR (attrs.at_artificial);
9339 CHECKSUM_ATTR (attrs.at_associated);
9340 CHECKSUM_ATTR (attrs.at_binary_scale);
9341 CHECKSUM_ATTR (attrs.at_bit_offset);
9342 CHECKSUM_ATTR (attrs.at_bit_size);
9343 CHECKSUM_ATTR (attrs.at_bit_stride);
9344 CHECKSUM_ATTR (attrs.at_byte_size);
9345 CHECKSUM_ATTR (attrs.at_byte_stride);
9346 CHECKSUM_ATTR (attrs.at_const_value);
9347 CHECKSUM_ATTR (attrs.at_containing_type);
9348 CHECKSUM_ATTR (attrs.at_count);
9349 CHECKSUM_ATTR (attrs.at_data_location);
9350 CHECKSUM_ATTR (attrs.at_data_member_location);
9351 CHECKSUM_ATTR (attrs.at_decimal_scale);
9352 CHECKSUM_ATTR (attrs.at_decimal_sign);
9353 CHECKSUM_ATTR (attrs.at_default_value);
9354 CHECKSUM_ATTR (attrs.at_digit_count);
9355 CHECKSUM_ATTR (attrs.at_discr);
9356 CHECKSUM_ATTR (attrs.at_discr_list);
9357 CHECKSUM_ATTR (attrs.at_discr_value);
9358 CHECKSUM_ATTR (attrs.at_encoding);
9359 CHECKSUM_ATTR (attrs.at_endianity);
9360 CHECKSUM_ATTR (attrs.at_explicit);
9361 CHECKSUM_ATTR (attrs.at_is_optional);
9362 CHECKSUM_ATTR (attrs.at_location);
9363 CHECKSUM_ATTR (attrs.at_lower_bound);
9364 CHECKSUM_ATTR (attrs.at_mutable);
9365 CHECKSUM_ATTR (attrs.at_ordering);
9366 CHECKSUM_ATTR (attrs.at_picture_string);
9367 CHECKSUM_ATTR (attrs.at_prototyped);
9368 CHECKSUM_ATTR (attrs.at_small);
9369 CHECKSUM_ATTR (attrs.at_segment);
9370 CHECKSUM_ATTR (attrs.at_string_length);
9371 CHECKSUM_ATTR (attrs.at_threads_scaled);
9372 CHECKSUM_ATTR (attrs.at_upper_bound);
9373 CHECKSUM_ATTR (attrs.at_use_location);
9374 CHECKSUM_ATTR (attrs.at_use_UTF8);
9375 CHECKSUM_ATTR (attrs.at_variable_parameter);
9376 CHECKSUM_ATTR (attrs.at_virtuality);
9377 CHECKSUM_ATTR (attrs.at_visibility);
9378 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9379 CHECKSUM_ATTR (attrs.at_type);
9380 CHECKSUM_ATTR (attrs.at_friend);
9382 /* Checksum the child DIEs, except for nested types and member functions. */
9385 dw_attr_ref name_attr;
9388 name_attr = get_AT (c, DW_AT_name);
9389 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9390 && name_attr != NULL)
9392 CHECKSUM_ULEB128 ('S');
9393 CHECKSUM_ULEB128 (c->die_tag);
9394 CHECKSUM_STRING (AT_string (name_attr));
9398 /* Mark this DIE so it gets processed when unmarking. */
9399 if (c->die_mark == 0)
9401 die_checksum_ordered (c, ctx, mark);
9403 } while (c != die->die_child);
9405 CHECKSUM_ULEB128 (0);
9409 #undef CHECKSUM_STRING
9410 #undef CHECKSUM_ATTR
9411 #undef CHECKSUM_LEB128
9412 #undef CHECKSUM_ULEB128
9414 /* Generate the type signature for DIE. This is computed by generating an
9415 MD5 checksum over the DIE's tag, its relevant attributes, and its
9416 children. Attributes that are references to other DIEs are processed
9417 by recursion, using the MARK field to prevent infinite recursion.
9418 If the DIE is nested inside a namespace or another type, we also
9419 need to include that context in the signature. The lower 64 bits
9420 of the resulting MD5 checksum comprise the signature. */
9423 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9427 unsigned char checksum[16];
9431 name = get_AT_string (die, DW_AT_name);
9432 decl = get_AT_ref (die, DW_AT_specification);
9434 /* First, compute a signature for just the type name (and its surrounding
9435 context, if any. This is stored in the type unit DIE for link-time
9436 ODR (one-definition rule) checking. */
9438 if (is_cxx() && name != NULL)
9440 md5_init_ctx (&ctx);
9442 /* Checksum the names of surrounding namespaces and structures. */
9443 if (decl != NULL && decl->die_parent != NULL)
9444 checksum_die_context (decl->die_parent, &ctx);
9446 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9447 md5_process_bytes (name, strlen (name) + 1, &ctx);
9448 md5_finish_ctx (&ctx, checksum);
9450 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9453 /* Next, compute the complete type signature. */
9455 md5_init_ctx (&ctx);
9457 die->die_mark = mark;
9459 /* Checksum the names of surrounding namespaces and structures. */
9460 if (decl != NULL && decl->die_parent != NULL)
9461 checksum_die_context (decl->die_parent, &ctx);
9463 /* Checksum the DIE and its children. */
9464 die_checksum_ordered (die, &ctx, &mark);
9465 unmark_all_dies (die);
9466 md5_finish_ctx (&ctx, checksum);
9468 /* Store the signature in the type node and link the type DIE and the
9469 type node together. */
9470 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9471 DWARF_TYPE_SIGNATURE_SIZE);
9472 die->die_id.die_type_node = type_node;
9473 type_node->type_die = die;
9475 /* If the DIE is a specification, link its declaration to the type node
9478 decl->die_id.die_type_node = type_node;
9481 /* Do the location expressions look same? */
9483 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9485 return loc1->dw_loc_opc == loc2->dw_loc_opc
9486 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9487 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9490 /* Do the values look the same? */
9492 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9494 dw_loc_descr_ref loc1, loc2;
9497 if (v1->val_class != v2->val_class)
9500 switch (v1->val_class)
9502 case dw_val_class_const:
9503 return v1->v.val_int == v2->v.val_int;
9504 case dw_val_class_unsigned_const:
9505 return v1->v.val_unsigned == v2->v.val_unsigned;
9506 case dw_val_class_const_double:
9507 return v1->v.val_double.high == v2->v.val_double.high
9508 && v1->v.val_double.low == v2->v.val_double.low;
9509 case dw_val_class_vec:
9510 if (v1->v.val_vec.length != v2->v.val_vec.length
9511 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9513 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9514 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9517 case dw_val_class_flag:
9518 return v1->v.val_flag == v2->v.val_flag;
9519 case dw_val_class_str:
9520 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9522 case dw_val_class_addr:
9523 r1 = v1->v.val_addr;
9524 r2 = v2->v.val_addr;
9525 if (GET_CODE (r1) != GET_CODE (r2))
9527 return !rtx_equal_p (r1, r2);
9529 case dw_val_class_offset:
9530 return v1->v.val_offset == v2->v.val_offset;
9532 case dw_val_class_loc:
9533 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9535 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9536 if (!same_loc_p (loc1, loc2, mark))
9538 return !loc1 && !loc2;
9540 case dw_val_class_die_ref:
9541 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9543 case dw_val_class_fde_ref:
9544 case dw_val_class_vms_delta:
9545 case dw_val_class_lbl_id:
9546 case dw_val_class_lineptr:
9547 case dw_val_class_macptr:
9550 case dw_val_class_file:
9551 return v1->v.val_file == v2->v.val_file;
9553 case dw_val_class_data8:
9554 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9561 /* Do the attributes look the same? */
9564 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9566 if (at1->dw_attr != at2->dw_attr)
9569 /* We don't care that this was compiled with a different compiler
9570 snapshot; if the output is the same, that's what matters. */
9571 if (at1->dw_attr == DW_AT_producer)
9574 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9577 /* Do the dies look the same? */
9580 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9586 /* To avoid infinite recursion. */
9588 return die1->die_mark == die2->die_mark;
9589 die1->die_mark = die2->die_mark = ++(*mark);
9591 if (die1->die_tag != die2->die_tag)
9594 if (VEC_length (dw_attr_node, die1->die_attr)
9595 != VEC_length (dw_attr_node, die2->die_attr))
9598 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9599 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9602 c1 = die1->die_child;
9603 c2 = die2->die_child;
9612 if (!same_die_p (c1, c2, mark))
9616 if (c1 == die1->die_child)
9618 if (c2 == die2->die_child)
9628 /* Do the dies look the same? Wrapper around same_die_p. */
9631 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9634 int ret = same_die_p (die1, die2, &mark);
9636 unmark_all_dies (die1);
9637 unmark_all_dies (die2);
9642 /* The prefix to attach to symbols on DIEs in the current comdat debug
9644 static char *comdat_symbol_id;
9646 /* The index of the current symbol within the current comdat CU. */
9647 static unsigned int comdat_symbol_number;
9649 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9650 children, and set comdat_symbol_id accordingly. */
9653 compute_section_prefix (dw_die_ref unit_die)
9655 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9656 const char *base = die_name ? lbasename (die_name) : "anonymous";
9657 char *name = XALLOCAVEC (char, strlen (base) + 64);
9660 unsigned char checksum[16];
9663 /* Compute the checksum of the DIE, then append part of it as hex digits to
9664 the name filename of the unit. */
9666 md5_init_ctx (&ctx);
9668 die_checksum (unit_die, &ctx, &mark);
9669 unmark_all_dies (unit_die);
9670 md5_finish_ctx (&ctx, checksum);
9672 sprintf (name, "%s.", base);
9673 clean_symbol_name (name);
9675 p = name + strlen (name);
9676 for (i = 0; i < 4; i++)
9678 sprintf (p, "%.2x", checksum[i]);
9682 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9683 comdat_symbol_number = 0;
9686 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9689 is_type_die (dw_die_ref die)
9691 switch (die->die_tag)
9693 case DW_TAG_array_type:
9694 case DW_TAG_class_type:
9695 case DW_TAG_interface_type:
9696 case DW_TAG_enumeration_type:
9697 case DW_TAG_pointer_type:
9698 case DW_TAG_reference_type:
9699 case DW_TAG_rvalue_reference_type:
9700 case DW_TAG_string_type:
9701 case DW_TAG_structure_type:
9702 case DW_TAG_subroutine_type:
9703 case DW_TAG_union_type:
9704 case DW_TAG_ptr_to_member_type:
9705 case DW_TAG_set_type:
9706 case DW_TAG_subrange_type:
9707 case DW_TAG_base_type:
9708 case DW_TAG_const_type:
9709 case DW_TAG_file_type:
9710 case DW_TAG_packed_type:
9711 case DW_TAG_volatile_type:
9712 case DW_TAG_typedef:
9719 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9720 Basically, we want to choose the bits that are likely to be shared between
9721 compilations (types) and leave out the bits that are specific to individual
9722 compilations (functions). */
9725 is_comdat_die (dw_die_ref c)
9727 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9728 we do for stabs. The advantage is a greater likelihood of sharing between
9729 objects that don't include headers in the same order (and therefore would
9730 put the base types in a different comdat). jason 8/28/00 */
9732 if (c->die_tag == DW_TAG_base_type)
9735 if (c->die_tag == DW_TAG_pointer_type
9736 || c->die_tag == DW_TAG_reference_type
9737 || c->die_tag == DW_TAG_rvalue_reference_type
9738 || c->die_tag == DW_TAG_const_type
9739 || c->die_tag == DW_TAG_volatile_type)
9741 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9743 return t ? is_comdat_die (t) : 0;
9746 return is_type_die (c);
9749 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9750 compilation unit. */
9753 is_symbol_die (dw_die_ref c)
9755 return (is_type_die (c)
9756 || is_declaration_die (c)
9757 || c->die_tag == DW_TAG_namespace
9758 || c->die_tag == DW_TAG_module);
9761 /* Returns true iff C is a compile-unit DIE. */
9764 is_cu_die (dw_die_ref c)
9766 return c && c->die_tag == DW_TAG_compile_unit;
9770 gen_internal_sym (const char *prefix)
9774 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9775 return xstrdup (buf);
9778 /* Assign symbols to all worthy DIEs under DIE. */
9781 assign_symbol_names (dw_die_ref die)
9785 if (is_symbol_die (die))
9787 if (comdat_symbol_id)
9789 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9791 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9792 comdat_symbol_id, comdat_symbol_number++);
9793 die->die_id.die_symbol = xstrdup (p);
9796 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9799 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9802 struct cu_hash_table_entry
9805 unsigned min_comdat_num, max_comdat_num;
9806 struct cu_hash_table_entry *next;
9809 /* Routines to manipulate hash table of CUs. */
9811 htab_cu_hash (const void *of)
9813 const struct cu_hash_table_entry *const entry =
9814 (const struct cu_hash_table_entry *) of;
9816 return htab_hash_string (entry->cu->die_id.die_symbol);
9820 htab_cu_eq (const void *of1, const void *of2)
9822 const struct cu_hash_table_entry *const entry1 =
9823 (const struct cu_hash_table_entry *) of1;
9824 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9826 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9830 htab_cu_del (void *what)
9832 struct cu_hash_table_entry *next,
9833 *entry = (struct cu_hash_table_entry *) what;
9843 /* Check whether we have already seen this CU and set up SYM_NUM
9846 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9848 struct cu_hash_table_entry dummy;
9849 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9851 dummy.max_comdat_num = 0;
9853 slot = (struct cu_hash_table_entry **)
9854 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9858 for (; entry; last = entry, entry = entry->next)
9860 if (same_die_p_wrap (cu, entry->cu))
9866 *sym_num = entry->min_comdat_num;
9870 entry = XCNEW (struct cu_hash_table_entry);
9872 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9873 entry->next = *slot;
9879 /* Record SYM_NUM to record of CU in HTABLE. */
9881 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9883 struct cu_hash_table_entry **slot, *entry;
9885 slot = (struct cu_hash_table_entry **)
9886 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9890 entry->max_comdat_num = sym_num;
9893 /* Traverse the DIE (which is always comp_unit_die), and set up
9894 additional compilation units for each of the include files we see
9895 bracketed by BINCL/EINCL. */
9898 break_out_includes (dw_die_ref die)
9901 dw_die_ref unit = NULL;
9902 limbo_die_node *node, **pnode;
9903 htab_t cu_hash_table;
9907 dw_die_ref prev = c;
9909 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9910 || (unit && is_comdat_die (c)))
9912 dw_die_ref next = c->die_sib;
9914 /* This DIE is for a secondary CU; remove it from the main one. */
9915 remove_child_with_prev (c, prev);
9917 if (c->die_tag == DW_TAG_GNU_BINCL)
9918 unit = push_new_compile_unit (unit, c);
9919 else if (c->die_tag == DW_TAG_GNU_EINCL)
9920 unit = pop_compile_unit (unit);
9922 add_child_die (unit, c);
9924 if (c == die->die_child)
9927 } while (c != die->die_child);
9930 /* We can only use this in debugging, since the frontend doesn't check
9931 to make sure that we leave every include file we enter. */
9935 assign_symbol_names (die);
9936 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9937 for (node = limbo_die_list, pnode = &limbo_die_list;
9943 compute_section_prefix (node->die);
9944 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9945 &comdat_symbol_number);
9946 assign_symbol_names (node->die);
9948 *pnode = node->next;
9951 pnode = &node->next;
9952 record_comdat_symbol_number (node->die, cu_hash_table,
9953 comdat_symbol_number);
9956 htab_delete (cu_hash_table);
9959 /* Return non-zero if this DIE is a declaration. */
9962 is_declaration_die (dw_die_ref die)
9967 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9968 if (a->dw_attr == DW_AT_declaration)
9974 /* Return non-zero if this DIE is nested inside a subprogram. */
9977 is_nested_in_subprogram (dw_die_ref die)
9979 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
9983 return local_scope_p (decl);
9986 /* Return non-zero if this is a type DIE that should be moved to a
9987 COMDAT .debug_types section. */
9990 should_move_die_to_comdat (dw_die_ref die)
9992 switch (die->die_tag)
9994 case DW_TAG_class_type:
9995 case DW_TAG_structure_type:
9996 case DW_TAG_enumeration_type:
9997 case DW_TAG_union_type:
9998 /* Don't move declarations, inlined instances, or types nested in a
10000 if (is_declaration_die (die)
10001 || get_AT (die, DW_AT_abstract_origin)
10002 || is_nested_in_subprogram (die))
10005 case DW_TAG_array_type:
10006 case DW_TAG_interface_type:
10007 case DW_TAG_pointer_type:
10008 case DW_TAG_reference_type:
10009 case DW_TAG_rvalue_reference_type:
10010 case DW_TAG_string_type:
10011 case DW_TAG_subroutine_type:
10012 case DW_TAG_ptr_to_member_type:
10013 case DW_TAG_set_type:
10014 case DW_TAG_subrange_type:
10015 case DW_TAG_base_type:
10016 case DW_TAG_const_type:
10017 case DW_TAG_file_type:
10018 case DW_TAG_packed_type:
10019 case DW_TAG_volatile_type:
10020 case DW_TAG_typedef:
10026 /* Make a clone of DIE. */
10029 clone_die (dw_die_ref die)
10035 clone = ggc_alloc_cleared_die_node ();
10036 clone->die_tag = die->die_tag;
10038 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10039 add_dwarf_attr (clone, a);
10044 /* Make a clone of the tree rooted at DIE. */
10047 clone_tree (dw_die_ref die)
10050 dw_die_ref clone = clone_die (die);
10052 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10057 /* Make a clone of DIE as a declaration. */
10060 clone_as_declaration (dw_die_ref die)
10067 /* If the DIE is already a declaration, just clone it. */
10068 if (is_declaration_die (die))
10069 return clone_die (die);
10071 /* If the DIE is a specification, just clone its declaration DIE. */
10072 decl = get_AT_ref (die, DW_AT_specification);
10074 return clone_die (decl);
10076 clone = ggc_alloc_cleared_die_node ();
10077 clone->die_tag = die->die_tag;
10079 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10081 /* We don't want to copy over all attributes.
10082 For example we don't want DW_AT_byte_size because otherwise we will no
10083 longer have a declaration and GDB will treat it as a definition. */
10085 switch (a->dw_attr)
10087 case DW_AT_artificial:
10088 case DW_AT_containing_type:
10089 case DW_AT_external:
10092 case DW_AT_virtuality:
10093 case DW_AT_linkage_name:
10094 case DW_AT_MIPS_linkage_name:
10095 add_dwarf_attr (clone, a);
10097 case DW_AT_byte_size:
10103 if (die->die_id.die_type_node)
10104 add_AT_die_ref (clone, DW_AT_signature, die);
10106 add_AT_flag (clone, DW_AT_declaration, 1);
10110 /* Copy the declaration context to the new compile unit DIE. This includes
10111 any surrounding namespace or type declarations. If the DIE has an
10112 AT_specification attribute, it also includes attributes and children
10113 attached to the specification. */
10116 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10119 dw_die_ref new_decl;
10121 decl = get_AT_ref (die, DW_AT_specification);
10130 /* Copy the type node pointer from the new DIE to the original
10131 declaration DIE so we can forward references later. */
10132 decl->die_id.die_type_node = die->die_id.die_type_node;
10134 remove_AT (die, DW_AT_specification);
10136 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10138 if (a->dw_attr != DW_AT_name
10139 && a->dw_attr != DW_AT_declaration
10140 && a->dw_attr != DW_AT_external)
10141 add_dwarf_attr (die, a);
10144 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10147 if (decl->die_parent != NULL
10148 && decl->die_parent->die_tag != DW_TAG_compile_unit
10149 && decl->die_parent->die_tag != DW_TAG_type_unit)
10151 new_decl = copy_ancestor_tree (unit, decl, NULL);
10152 if (new_decl != NULL)
10154 remove_AT (new_decl, DW_AT_signature);
10155 add_AT_specification (die, new_decl);
10160 /* Generate the skeleton ancestor tree for the given NODE, then clone
10161 the DIE and add the clone into the tree. */
10164 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10166 if (node->new_die != NULL)
10169 node->new_die = clone_as_declaration (node->old_die);
10171 if (node->parent != NULL)
10173 generate_skeleton_ancestor_tree (node->parent);
10174 add_child_die (node->parent->new_die, node->new_die);
10178 /* Generate a skeleton tree of DIEs containing any declarations that are
10179 found in the original tree. We traverse the tree looking for declaration
10180 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10183 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10185 skeleton_chain_node node;
10188 dw_die_ref prev = NULL;
10189 dw_die_ref next = NULL;
10191 node.parent = parent;
10193 first = c = parent->old_die->die_child;
10197 if (prev == NULL || prev->die_sib == c)
10200 next = (c == first ? NULL : c->die_sib);
10202 node.new_die = NULL;
10203 if (is_declaration_die (c))
10205 /* Clone the existing DIE, move the original to the skeleton
10206 tree (which is in the main CU), and put the clone, with
10207 all the original's children, where the original came from. */
10208 dw_die_ref clone = clone_die (c);
10209 move_all_children (c, clone);
10211 replace_child (c, clone, prev);
10212 generate_skeleton_ancestor_tree (parent);
10213 add_child_die (parent->new_die, c);
10217 generate_skeleton_bottom_up (&node);
10218 } while (next != NULL);
10221 /* Wrapper function for generate_skeleton_bottom_up. */
10224 generate_skeleton (dw_die_ref die)
10226 skeleton_chain_node node;
10228 node.old_die = die;
10229 node.new_die = NULL;
10230 node.parent = NULL;
10232 /* If this type definition is nested inside another type,
10233 always leave at least a declaration in its place. */
10234 if (die->die_parent != NULL && is_type_die (die->die_parent))
10235 node.new_die = clone_as_declaration (die);
10237 generate_skeleton_bottom_up (&node);
10238 return node.new_die;
10241 /* Remove the DIE from its parent, possibly replacing it with a cloned
10242 declaration. The original DIE will be moved to a new compile unit
10243 so that existing references to it follow it to the new location. If
10244 any of the original DIE's descendants is a declaration, we need to
10245 replace the original DIE with a skeleton tree and move the
10246 declarations back into the skeleton tree. */
10249 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10251 dw_die_ref skeleton;
10253 skeleton = generate_skeleton (child);
10254 if (skeleton == NULL)
10255 remove_child_with_prev (child, prev);
10258 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10259 replace_child (child, skeleton, prev);
10265 /* Traverse the DIE and set up additional .debug_types sections for each
10266 type worthy of being placed in a COMDAT section. */
10269 break_out_comdat_types (dw_die_ref die)
10273 dw_die_ref prev = NULL;
10274 dw_die_ref next = NULL;
10275 dw_die_ref unit = NULL;
10277 first = c = die->die_child;
10281 if (prev == NULL || prev->die_sib == c)
10284 next = (c == first ? NULL : c->die_sib);
10285 if (should_move_die_to_comdat (c))
10287 dw_die_ref replacement;
10288 comdat_type_node_ref type_node;
10290 /* Create a new type unit DIE as the root for the new tree, and
10291 add it to the list of comdat types. */
10292 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10293 add_AT_unsigned (unit, DW_AT_language,
10294 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10295 type_node = ggc_alloc_cleared_comdat_type_node ();
10296 type_node->root_die = unit;
10297 type_node->next = comdat_type_list;
10298 comdat_type_list = type_node;
10300 /* Generate the type signature. */
10301 generate_type_signature (c, type_node);
10303 /* Copy the declaration context, attributes, and children of the
10304 declaration into the new compile unit DIE. */
10305 copy_declaration_context (unit, c);
10307 /* Remove this DIE from the main CU. */
10308 replacement = remove_child_or_replace_with_skeleton (c, prev);
10310 /* Break out nested types into their own type units. */
10311 break_out_comdat_types (c);
10313 /* Add the DIE to the new compunit. */
10314 add_child_die (unit, c);
10316 if (replacement != NULL)
10319 else if (c->die_tag == DW_TAG_namespace
10320 || c->die_tag == DW_TAG_class_type
10321 || c->die_tag == DW_TAG_structure_type
10322 || c->die_tag == DW_TAG_union_type)
10324 /* Look for nested types that can be broken out. */
10325 break_out_comdat_types (c);
10327 } while (next != NULL);
10330 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10332 struct decl_table_entry
10338 /* Routines to manipulate hash table of copied declarations. */
10341 htab_decl_hash (const void *of)
10343 const struct decl_table_entry *const entry =
10344 (const struct decl_table_entry *) of;
10346 return htab_hash_pointer (entry->orig);
10350 htab_decl_eq (const void *of1, const void *of2)
10352 const struct decl_table_entry *const entry1 =
10353 (const struct decl_table_entry *) of1;
10354 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10356 return entry1->orig == entry2;
10360 htab_decl_del (void *what)
10362 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10367 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10368 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10369 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10370 to check if the ancestor has already been copied into UNIT. */
10373 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10375 dw_die_ref parent = die->die_parent;
10376 dw_die_ref new_parent = unit;
10378 void **slot = NULL;
10379 struct decl_table_entry *entry = NULL;
10383 /* Check if the entry has already been copied to UNIT. */
10384 slot = htab_find_slot_with_hash (decl_table, die,
10385 htab_hash_pointer (die), INSERT);
10386 if (*slot != HTAB_EMPTY_ENTRY)
10388 entry = (struct decl_table_entry *) *slot;
10389 return entry->copy;
10392 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10393 entry = XCNEW (struct decl_table_entry);
10395 entry->copy = NULL;
10399 if (parent != NULL)
10401 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10404 if (parent->die_tag != DW_TAG_compile_unit
10405 && parent->die_tag != DW_TAG_type_unit)
10406 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10409 copy = clone_as_declaration (die);
10410 add_child_die (new_parent, copy);
10412 if (decl_table != NULL)
10414 /* Record the pointer to the copy. */
10415 entry->copy = copy;
10421 /* Walk the DIE and its children, looking for references to incomplete
10422 or trivial types that are unmarked (i.e., that are not in the current
10426 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10432 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10434 if (AT_class (a) == dw_val_class_die_ref)
10436 dw_die_ref targ = AT_ref (a);
10437 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10439 struct decl_table_entry *entry;
10441 if (targ->die_mark != 0 || type_node != NULL)
10444 slot = htab_find_slot_with_hash (decl_table, targ,
10445 htab_hash_pointer (targ), INSERT);
10447 if (*slot != HTAB_EMPTY_ENTRY)
10449 /* TARG has already been copied, so we just need to
10450 modify the reference to point to the copy. */
10451 entry = (struct decl_table_entry *) *slot;
10452 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10456 dw_die_ref parent = unit;
10457 dw_die_ref copy = clone_tree (targ);
10459 /* Make sure the cloned tree is marked as part of the
10463 /* Record in DECL_TABLE that TARG has been copied.
10464 Need to do this now, before the recursive call,
10465 because DECL_TABLE may be expanded and SLOT
10466 would no longer be a valid pointer. */
10467 entry = XCNEW (struct decl_table_entry);
10468 entry->orig = targ;
10469 entry->copy = copy;
10472 /* If TARG has surrounding context, copy its ancestor tree
10473 into the new type unit. */
10474 if (targ->die_parent != NULL
10475 && targ->die_parent->die_tag != DW_TAG_compile_unit
10476 && targ->die_parent->die_tag != DW_TAG_type_unit)
10477 parent = copy_ancestor_tree (unit, targ->die_parent,
10480 add_child_die (parent, copy);
10481 a->dw_attr_val.v.val_die_ref.die = copy;
10483 /* Make sure the newly-copied DIE is walked. If it was
10484 installed in a previously-added context, it won't
10485 get visited otherwise. */
10486 if (parent != unit)
10488 /* Find the highest point of the newly-added tree,
10489 mark each node along the way, and walk from there. */
10490 parent->die_mark = 1;
10491 while (parent->die_parent
10492 && parent->die_parent->die_mark == 0)
10494 parent = parent->die_parent;
10495 parent->die_mark = 1;
10497 copy_decls_walk (unit, parent, decl_table);
10503 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10506 /* Copy declarations for "unworthy" types into the new comdat section.
10507 Incomplete types, modified types, and certain other types aren't broken
10508 out into comdat sections of their own, so they don't have a signature,
10509 and we need to copy the declaration into the same section so that we
10510 don't have an external reference. */
10513 copy_decls_for_unworthy_types (dw_die_ref unit)
10518 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10519 copy_decls_walk (unit, unit, decl_table);
10520 htab_delete (decl_table);
10521 unmark_dies (unit);
10524 /* Traverse the DIE and add a sibling attribute if it may have the
10525 effect of speeding up access to siblings. To save some space,
10526 avoid generating sibling attributes for DIE's without children. */
10529 add_sibling_attributes (dw_die_ref die)
10533 if (! die->die_child)
10536 if (die->die_parent && die != die->die_parent->die_child)
10537 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10539 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10542 /* Output all location lists for the DIE and its children. */
10545 output_location_lists (dw_die_ref die)
10551 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10552 if (AT_class (a) == dw_val_class_loc_list)
10553 output_loc_list (AT_loc_list (a));
10555 FOR_EACH_CHILD (die, c, output_location_lists (c));
10558 /* The format of each DIE (and its attribute value pairs) is encoded in an
10559 abbreviation table. This routine builds the abbreviation table and assigns
10560 a unique abbreviation id for each abbreviation entry. The children of each
10561 die are visited recursively. */
10564 build_abbrev_table (dw_die_ref die)
10566 unsigned long abbrev_id;
10567 unsigned int n_alloc;
10572 /* Scan the DIE references, and mark as external any that refer to
10573 DIEs from other CUs (i.e. those which are not marked). */
10574 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10575 if (AT_class (a) == dw_val_class_die_ref
10576 && AT_ref (a)->die_mark == 0)
10578 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10579 set_AT_ref_external (a, 1);
10582 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10584 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10585 dw_attr_ref die_a, abbrev_a;
10589 if (abbrev->die_tag != die->die_tag)
10591 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10594 if (VEC_length (dw_attr_node, abbrev->die_attr)
10595 != VEC_length (dw_attr_node, die->die_attr))
10598 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10600 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10601 if ((abbrev_a->dw_attr != die_a->dw_attr)
10602 || (value_format (abbrev_a) != value_format (die_a)))
10612 if (abbrev_id >= abbrev_die_table_in_use)
10614 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10616 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10617 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10620 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10621 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10622 abbrev_die_table_allocated = n_alloc;
10625 ++abbrev_die_table_in_use;
10626 abbrev_die_table[abbrev_id] = die;
10629 die->die_abbrev = abbrev_id;
10630 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10633 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10636 constant_size (unsigned HOST_WIDE_INT value)
10643 log = floor_log2 (value);
10646 log = 1 << (floor_log2 (log) + 1);
10651 /* Return the size of a DIE as it is represented in the
10652 .debug_info section. */
10654 static unsigned long
10655 size_of_die (dw_die_ref die)
10657 unsigned long size = 0;
10661 size += size_of_uleb128 (die->die_abbrev);
10662 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10664 switch (AT_class (a))
10666 case dw_val_class_addr:
10667 size += DWARF2_ADDR_SIZE;
10669 case dw_val_class_offset:
10670 size += DWARF_OFFSET_SIZE;
10672 case dw_val_class_loc:
10674 unsigned long lsize = size_of_locs (AT_loc (a));
10676 /* Block length. */
10677 if (dwarf_version >= 4)
10678 size += size_of_uleb128 (lsize);
10680 size += constant_size (lsize);
10684 case dw_val_class_loc_list:
10685 size += DWARF_OFFSET_SIZE;
10687 case dw_val_class_range_list:
10688 size += DWARF_OFFSET_SIZE;
10690 case dw_val_class_const:
10691 size += size_of_sleb128 (AT_int (a));
10693 case dw_val_class_unsigned_const:
10694 size += constant_size (AT_unsigned (a));
10696 case dw_val_class_const_double:
10697 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10698 if (HOST_BITS_PER_WIDE_INT >= 64)
10699 size++; /* block */
10701 case dw_val_class_vec:
10702 size += constant_size (a->dw_attr_val.v.val_vec.length
10703 * a->dw_attr_val.v.val_vec.elt_size)
10704 + a->dw_attr_val.v.val_vec.length
10705 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10707 case dw_val_class_flag:
10708 if (dwarf_version >= 4)
10709 /* Currently all add_AT_flag calls pass in 1 as last argument,
10710 so DW_FORM_flag_present can be used. If that ever changes,
10711 we'll need to use DW_FORM_flag and have some optimization
10712 in build_abbrev_table that will change those to
10713 DW_FORM_flag_present if it is set to 1 in all DIEs using
10714 the same abbrev entry. */
10715 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10719 case dw_val_class_die_ref:
10720 if (AT_ref_external (a))
10722 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
10723 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10724 is sized by target address length, whereas in DWARF3
10725 it's always sized as an offset. */
10726 if (dwarf_version >= 4)
10727 size += DWARF_TYPE_SIGNATURE_SIZE;
10728 else if (dwarf_version == 2)
10729 size += DWARF2_ADDR_SIZE;
10731 size += DWARF_OFFSET_SIZE;
10734 size += DWARF_OFFSET_SIZE;
10736 case dw_val_class_fde_ref:
10737 size += DWARF_OFFSET_SIZE;
10739 case dw_val_class_lbl_id:
10740 size += DWARF2_ADDR_SIZE;
10742 case dw_val_class_lineptr:
10743 case dw_val_class_macptr:
10744 size += DWARF_OFFSET_SIZE;
10746 case dw_val_class_str:
10747 if (AT_string_form (a) == DW_FORM_strp)
10748 size += DWARF_OFFSET_SIZE;
10750 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10752 case dw_val_class_file:
10753 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10755 case dw_val_class_data8:
10758 case dw_val_class_vms_delta:
10759 size += DWARF_OFFSET_SIZE;
10762 gcc_unreachable ();
10769 /* Size the debugging information associated with a given DIE. Visits the
10770 DIE's children recursively. Updates the global variable next_die_offset, on
10771 each time through. Uses the current value of next_die_offset to update the
10772 die_offset field in each DIE. */
10775 calc_die_sizes (dw_die_ref die)
10779 die->die_offset = next_die_offset;
10780 next_die_offset += size_of_die (die);
10782 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10784 if (die->die_child != NULL)
10785 /* Count the null byte used to terminate sibling lists. */
10786 next_die_offset += 1;
10789 /* Set the marks for a die and its children. We do this so
10790 that we know whether or not a reference needs to use FORM_ref_addr; only
10791 DIEs in the same CU will be marked. We used to clear out the offset
10792 and use that as the flag, but ran into ordering problems. */
10795 mark_dies (dw_die_ref die)
10799 gcc_assert (!die->die_mark);
10802 FOR_EACH_CHILD (die, c, mark_dies (c));
10805 /* Clear the marks for a die and its children. */
10808 unmark_dies (dw_die_ref die)
10812 if (dwarf_version < 4)
10813 gcc_assert (die->die_mark);
10816 FOR_EACH_CHILD (die, c, unmark_dies (c));
10819 /* Clear the marks for a die, its children and referred dies. */
10822 unmark_all_dies (dw_die_ref die)
10828 if (!die->die_mark)
10832 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10834 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10835 if (AT_class (a) == dw_val_class_die_ref)
10836 unmark_all_dies (AT_ref (a));
10839 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10840 generated for the compilation unit. */
10842 static unsigned long
10843 size_of_pubnames (VEC (pubname_entry, gc) * names)
10845 unsigned long size;
10849 size = DWARF_PUBNAMES_HEADER_SIZE;
10850 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10851 if (names != pubtype_table
10852 || p->die->die_offset != 0
10853 || !flag_eliminate_unused_debug_types)
10854 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10856 size += DWARF_OFFSET_SIZE;
10860 /* Return the size of the information in the .debug_aranges section. */
10862 static unsigned long
10863 size_of_aranges (void)
10865 unsigned long size;
10867 size = DWARF_ARANGES_HEADER_SIZE;
10869 /* Count the address/length pair for this compilation unit. */
10870 if (text_section_used)
10871 size += 2 * DWARF2_ADDR_SIZE;
10872 if (cold_text_section_used)
10873 size += 2 * DWARF2_ADDR_SIZE;
10874 if (have_multiple_function_sections)
10876 unsigned fde_idx = 0;
10878 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
10880 dw_fde_ref fde = &fde_table[fde_idx];
10882 if (!fde->in_std_section)
10883 size += 2 * DWARF2_ADDR_SIZE;
10884 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
10885 size += 2 * DWARF2_ADDR_SIZE;
10889 /* Count the two zero words used to terminated the address range table. */
10890 size += 2 * DWARF2_ADDR_SIZE;
10894 /* Select the encoding of an attribute value. */
10896 static enum dwarf_form
10897 value_format (dw_attr_ref a)
10899 switch (a->dw_attr_val.val_class)
10901 case dw_val_class_addr:
10902 /* Only very few attributes allow DW_FORM_addr. */
10903 switch (a->dw_attr)
10906 case DW_AT_high_pc:
10907 case DW_AT_entry_pc:
10908 case DW_AT_trampoline:
10909 return DW_FORM_addr;
10913 switch (DWARF2_ADDR_SIZE)
10916 return DW_FORM_data1;
10918 return DW_FORM_data2;
10920 return DW_FORM_data4;
10922 return DW_FORM_data8;
10924 gcc_unreachable ();
10926 case dw_val_class_range_list:
10927 case dw_val_class_loc_list:
10928 if (dwarf_version >= 4)
10929 return DW_FORM_sec_offset;
10931 case dw_val_class_vms_delta:
10932 case dw_val_class_offset:
10933 switch (DWARF_OFFSET_SIZE)
10936 return DW_FORM_data4;
10938 return DW_FORM_data8;
10940 gcc_unreachable ();
10942 case dw_val_class_loc:
10943 if (dwarf_version >= 4)
10944 return DW_FORM_exprloc;
10945 switch (constant_size (size_of_locs (AT_loc (a))))
10948 return DW_FORM_block1;
10950 return DW_FORM_block2;
10952 gcc_unreachable ();
10954 case dw_val_class_const:
10955 return DW_FORM_sdata;
10956 case dw_val_class_unsigned_const:
10957 switch (constant_size (AT_unsigned (a)))
10960 return DW_FORM_data1;
10962 return DW_FORM_data2;
10964 return DW_FORM_data4;
10966 return DW_FORM_data8;
10968 gcc_unreachable ();
10970 case dw_val_class_const_double:
10971 switch (HOST_BITS_PER_WIDE_INT)
10974 return DW_FORM_data2;
10976 return DW_FORM_data4;
10978 return DW_FORM_data8;
10981 return DW_FORM_block1;
10983 case dw_val_class_vec:
10984 switch (constant_size (a->dw_attr_val.v.val_vec.length
10985 * a->dw_attr_val.v.val_vec.elt_size))
10988 return DW_FORM_block1;
10990 return DW_FORM_block2;
10992 return DW_FORM_block4;
10994 gcc_unreachable ();
10996 case dw_val_class_flag:
10997 if (dwarf_version >= 4)
10999 /* Currently all add_AT_flag calls pass in 1 as last argument,
11000 so DW_FORM_flag_present can be used. If that ever changes,
11001 we'll need to use DW_FORM_flag and have some optimization
11002 in build_abbrev_table that will change those to
11003 DW_FORM_flag_present if it is set to 1 in all DIEs using
11004 the same abbrev entry. */
11005 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11006 return DW_FORM_flag_present;
11008 return DW_FORM_flag;
11009 case dw_val_class_die_ref:
11010 if (AT_ref_external (a))
11011 return dwarf_version >= 4 ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
11013 return DW_FORM_ref;
11014 case dw_val_class_fde_ref:
11015 return DW_FORM_data;
11016 case dw_val_class_lbl_id:
11017 return DW_FORM_addr;
11018 case dw_val_class_lineptr:
11019 case dw_val_class_macptr:
11020 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11021 case dw_val_class_str:
11022 return AT_string_form (a);
11023 case dw_val_class_file:
11024 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11027 return DW_FORM_data1;
11029 return DW_FORM_data2;
11031 return DW_FORM_data4;
11033 gcc_unreachable ();
11036 case dw_val_class_data8:
11037 return DW_FORM_data8;
11040 gcc_unreachable ();
11044 /* Output the encoding of an attribute value. */
11047 output_value_format (dw_attr_ref a)
11049 enum dwarf_form form = value_format (a);
11051 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11054 /* Output the .debug_abbrev section which defines the DIE abbreviation
11058 output_abbrev_section (void)
11060 unsigned long abbrev_id;
11062 if (abbrev_die_table_in_use == 1)
11065 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11067 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11069 dw_attr_ref a_attr;
11071 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11072 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11073 dwarf_tag_name (abbrev->die_tag));
11075 if (abbrev->die_child != NULL)
11076 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11078 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11080 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11083 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11084 dwarf_attr_name (a_attr->dw_attr));
11085 output_value_format (a_attr);
11088 dw2_asm_output_data (1, 0, NULL);
11089 dw2_asm_output_data (1, 0, NULL);
11092 /* Terminate the table. */
11093 dw2_asm_output_data (1, 0, NULL);
11096 /* Output a symbol we can use to refer to this DIE from another CU. */
11099 output_die_symbol (dw_die_ref die)
11101 char *sym = die->die_id.die_symbol;
11106 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11107 /* We make these global, not weak; if the target doesn't support
11108 .linkonce, it doesn't support combining the sections, so debugging
11110 targetm.asm_out.globalize_label (asm_out_file, sym);
11112 ASM_OUTPUT_LABEL (asm_out_file, sym);
11115 /* Return a new location list, given the begin and end range, and the
11118 static inline dw_loc_list_ref
11119 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11120 const char *section)
11122 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11124 retlist->begin = begin;
11125 retlist->end = end;
11126 retlist->expr = expr;
11127 retlist->section = section;
11132 /* Generate a new internal symbol for this location list node, if it
11133 hasn't got one yet. */
11136 gen_llsym (dw_loc_list_ref list)
11138 gcc_assert (!list->ll_symbol);
11139 list->ll_symbol = gen_internal_sym ("LLST");
11142 /* Output the location list given to us. */
11145 output_loc_list (dw_loc_list_ref list_head)
11147 dw_loc_list_ref curr = list_head;
11149 if (list_head->emitted)
11151 list_head->emitted = true;
11153 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11155 /* Walk the location list, and output each range + expression. */
11156 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11158 unsigned long size;
11159 /* Don't output an entry that starts and ends at the same address. */
11160 if (strcmp (curr->begin, curr->end) == 0)
11162 if (!have_multiple_function_sections)
11164 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11165 "Location list begin address (%s)",
11166 list_head->ll_symbol);
11167 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11168 "Location list end address (%s)",
11169 list_head->ll_symbol);
11173 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11174 "Location list begin address (%s)",
11175 list_head->ll_symbol);
11176 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11177 "Location list end address (%s)",
11178 list_head->ll_symbol);
11180 size = size_of_locs (curr->expr);
11182 /* Output the block length for this list of location operations. */
11183 gcc_assert (size <= 0xffff);
11184 dw2_asm_output_data (2, size, "%s", "Location expression size");
11186 output_loc_sequence (curr->expr, -1);
11189 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11190 "Location list terminator begin (%s)",
11191 list_head->ll_symbol);
11192 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11193 "Location list terminator end (%s)",
11194 list_head->ll_symbol);
11197 /* Output a type signature. */
11200 output_signature (const char *sig, const char *name)
11204 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11205 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11208 /* Output the DIE and its attributes. Called recursively to generate
11209 the definitions of each child DIE. */
11212 output_die (dw_die_ref die)
11216 unsigned long size;
11219 /* If someone in another CU might refer to us, set up a symbol for
11220 them to point to. */
11221 if (dwarf_version < 4 && die->die_id.die_symbol)
11222 output_die_symbol (die);
11224 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11225 (unsigned long)die->die_offset,
11226 dwarf_tag_name (die->die_tag));
11228 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11230 const char *name = dwarf_attr_name (a->dw_attr);
11232 switch (AT_class (a))
11234 case dw_val_class_addr:
11235 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11238 case dw_val_class_offset:
11239 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11243 case dw_val_class_range_list:
11245 char *p = strchr (ranges_section_label, '\0');
11247 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11248 a->dw_attr_val.v.val_offset);
11249 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11250 debug_ranges_section, "%s", name);
11255 case dw_val_class_loc:
11256 size = size_of_locs (AT_loc (a));
11258 /* Output the block length for this list of location operations. */
11259 if (dwarf_version >= 4)
11260 dw2_asm_output_data_uleb128 (size, "%s", name);
11262 dw2_asm_output_data (constant_size (size), size, "%s", name);
11264 output_loc_sequence (AT_loc (a), -1);
11267 case dw_val_class_const:
11268 /* ??? It would be slightly more efficient to use a scheme like is
11269 used for unsigned constants below, but gdb 4.x does not sign
11270 extend. Gdb 5.x does sign extend. */
11271 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11274 case dw_val_class_unsigned_const:
11275 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11276 AT_unsigned (a), "%s", name);
11279 case dw_val_class_const_double:
11281 unsigned HOST_WIDE_INT first, second;
11283 if (HOST_BITS_PER_WIDE_INT >= 64)
11284 dw2_asm_output_data (1,
11285 2 * HOST_BITS_PER_WIDE_INT
11286 / HOST_BITS_PER_CHAR,
11289 if (WORDS_BIG_ENDIAN)
11291 first = a->dw_attr_val.v.val_double.high;
11292 second = a->dw_attr_val.v.val_double.low;
11296 first = a->dw_attr_val.v.val_double.low;
11297 second = a->dw_attr_val.v.val_double.high;
11300 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11302 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11307 case dw_val_class_vec:
11309 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11310 unsigned int len = a->dw_attr_val.v.val_vec.length;
11314 dw2_asm_output_data (constant_size (len * elt_size),
11315 len * elt_size, "%s", name);
11316 if (elt_size > sizeof (HOST_WIDE_INT))
11321 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11323 i++, p += elt_size)
11324 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11325 "fp or vector constant word %u", i);
11329 case dw_val_class_flag:
11330 if (dwarf_version >= 4)
11332 /* Currently all add_AT_flag calls pass in 1 as last argument,
11333 so DW_FORM_flag_present can be used. If that ever changes,
11334 we'll need to use DW_FORM_flag and have some optimization
11335 in build_abbrev_table that will change those to
11336 DW_FORM_flag_present if it is set to 1 in all DIEs using
11337 the same abbrev entry. */
11338 gcc_assert (AT_flag (a) == 1);
11339 if (flag_debug_asm)
11340 fprintf (asm_out_file, "\t\t\t%s %s\n",
11341 ASM_COMMENT_START, name);
11344 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11347 case dw_val_class_loc_list:
11349 char *sym = AT_loc_list (a)->ll_symbol;
11352 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11357 case dw_val_class_die_ref:
11358 if (AT_ref_external (a))
11360 if (dwarf_version >= 4)
11362 comdat_type_node_ref type_node =
11363 AT_ref (a)->die_id.die_type_node;
11365 gcc_assert (type_node);
11366 output_signature (type_node->signature, name);
11370 char *sym = AT_ref (a)->die_id.die_symbol;
11374 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11375 length, whereas in DWARF3 it's always sized as an
11377 if (dwarf_version == 2)
11378 size = DWARF2_ADDR_SIZE;
11380 size = DWARF_OFFSET_SIZE;
11381 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11387 gcc_assert (AT_ref (a)->die_offset);
11388 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11393 case dw_val_class_fde_ref:
11397 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11398 a->dw_attr_val.v.val_fde_index * 2);
11399 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11404 case dw_val_class_vms_delta:
11405 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11406 AT_vms_delta2 (a), AT_vms_delta1 (a),
11410 case dw_val_class_lbl_id:
11411 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11414 case dw_val_class_lineptr:
11415 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11416 debug_line_section, "%s", name);
11419 case dw_val_class_macptr:
11420 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11421 debug_macinfo_section, "%s", name);
11424 case dw_val_class_str:
11425 if (AT_string_form (a) == DW_FORM_strp)
11426 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11427 a->dw_attr_val.v.val_str->label,
11429 "%s: \"%s\"", name, AT_string (a));
11431 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11434 case dw_val_class_file:
11436 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11438 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11439 a->dw_attr_val.v.val_file->filename);
11443 case dw_val_class_data8:
11447 for (i = 0; i < 8; i++)
11448 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11449 i == 0 ? "%s" : NULL, name);
11454 gcc_unreachable ();
11458 FOR_EACH_CHILD (die, c, output_die (c));
11460 /* Add null byte to terminate sibling list. */
11461 if (die->die_child != NULL)
11462 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11463 (unsigned long) die->die_offset);
11466 /* Output the compilation unit that appears at the beginning of the
11467 .debug_info section, and precedes the DIE descriptions. */
11470 output_compilation_unit_header (void)
11472 int ver = dwarf_version;
11474 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11475 dw2_asm_output_data (4, 0xffffffff,
11476 "Initial length escape value indicating 64-bit DWARF extension");
11477 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11478 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11479 "Length of Compilation Unit Info");
11480 dw2_asm_output_data (2, ver, "DWARF version number");
11481 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11482 debug_abbrev_section,
11483 "Offset Into Abbrev. Section");
11484 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11487 /* Output the compilation unit DIE and its children. */
11490 output_comp_unit (dw_die_ref die, int output_if_empty)
11492 const char *secname;
11493 char *oldsym, *tmp;
11495 /* Unless we are outputting main CU, we may throw away empty ones. */
11496 if (!output_if_empty && die->die_child == NULL)
11499 /* Even if there are no children of this DIE, we must output the information
11500 about the compilation unit. Otherwise, on an empty translation unit, we
11501 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11502 will then complain when examining the file. First mark all the DIEs in
11503 this CU so we know which get local refs. */
11506 build_abbrev_table (die);
11508 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11509 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11510 calc_die_sizes (die);
11512 oldsym = die->die_id.die_symbol;
11515 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11517 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11519 die->die_id.die_symbol = NULL;
11520 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11524 switch_to_section (debug_info_section);
11525 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11526 info_section_emitted = true;
11529 /* Output debugging information. */
11530 output_compilation_unit_header ();
11533 /* Leave the marks on the main CU, so we can check them in
11534 output_pubnames. */
11538 die->die_id.die_symbol = oldsym;
11542 /* Output a comdat type unit DIE and its children. */
11545 output_comdat_type_unit (comdat_type_node *node)
11547 const char *secname;
11550 #if defined (OBJECT_FORMAT_ELF)
11554 /* First mark all the DIEs in this CU so we know which get local refs. */
11555 mark_dies (node->root_die);
11557 build_abbrev_table (node->root_die);
11559 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11560 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11561 calc_die_sizes (node->root_die);
11563 #if defined (OBJECT_FORMAT_ELF)
11564 secname = ".debug_types";
11565 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11566 sprintf (tmp, "wt.");
11567 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11568 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11569 comdat_key = get_identifier (tmp);
11570 targetm.asm_out.named_section (secname,
11571 SECTION_DEBUG | SECTION_LINKONCE,
11574 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11575 sprintf (tmp, ".gnu.linkonce.wt.");
11576 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11577 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11579 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11582 /* Output debugging information. */
11583 output_compilation_unit_header ();
11584 output_signature (node->signature, "Type Signature");
11585 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11586 "Offset to Type DIE");
11587 output_die (node->root_die);
11589 unmark_dies (node->root_die);
11592 /* Return the DWARF2/3 pubname associated with a decl. */
11594 static const char *
11595 dwarf2_name (tree decl, int scope)
11597 if (DECL_NAMELESS (decl))
11599 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11602 /* Add a new entry to .debug_pubnames if appropriate. */
11605 add_pubname_string (const char *str, dw_die_ref die)
11607 if (targetm.want_debug_pub_sections)
11612 e.name = xstrdup (str);
11613 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11618 add_pubname (tree decl, dw_die_ref die)
11620 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11622 const char *name = dwarf2_name (decl, 1);
11624 add_pubname_string (name, die);
11628 /* Add a new entry to .debug_pubtypes if appropriate. */
11631 add_pubtype (tree decl, dw_die_ref die)
11635 if (!targetm.want_debug_pub_sections)
11639 if ((TREE_PUBLIC (decl)
11640 || is_cu_die (die->die_parent))
11641 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11646 if (TYPE_NAME (decl))
11648 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11649 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11650 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11651 && DECL_NAME (TYPE_NAME (decl)))
11652 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11654 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11659 e.name = dwarf2_name (decl, 1);
11661 e.name = xstrdup (e.name);
11664 /* If we don't have a name for the type, there's no point in adding
11665 it to the table. */
11666 if (e.name && e.name[0] != '\0')
11667 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11671 /* Output the public names table used to speed up access to externally
11672 visible names; or the public types table used to find type definitions. */
11675 output_pubnames (VEC (pubname_entry, gc) * names)
11678 unsigned long pubnames_length = size_of_pubnames (names);
11681 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11682 dw2_asm_output_data (4, 0xffffffff,
11683 "Initial length escape value indicating 64-bit DWARF extension");
11684 if (names == pubname_table)
11685 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11686 "Length of Public Names Info");
11688 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11689 "Length of Public Type Names Info");
11690 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11691 dw2_asm_output_data (2, 2, "DWARF Version");
11692 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11693 debug_info_section,
11694 "Offset of Compilation Unit Info");
11695 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11696 "Compilation Unit Length");
11698 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11700 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11701 if (names == pubname_table)
11702 gcc_assert (pub->die->die_mark);
11704 if (names != pubtype_table
11705 || pub->die->die_offset != 0
11706 || !flag_eliminate_unused_debug_types)
11708 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11711 dw2_asm_output_nstring (pub->name, -1, "external name");
11715 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11718 /* Output the information that goes into the .debug_aranges table.
11719 Namely, define the beginning and ending address range of the
11720 text section generated for this compilation unit. */
11723 output_aranges (unsigned long aranges_length)
11727 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11728 dw2_asm_output_data (4, 0xffffffff,
11729 "Initial length escape value indicating 64-bit DWARF extension");
11730 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11731 "Length of Address Ranges Info");
11732 /* Version number for aranges is still 2, even in DWARF3. */
11733 dw2_asm_output_data (2, 2, "DWARF Version");
11734 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11735 debug_info_section,
11736 "Offset of Compilation Unit Info");
11737 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11738 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11740 /* We need to align to twice the pointer size here. */
11741 if (DWARF_ARANGES_PAD_SIZE)
11743 /* Pad using a 2 byte words so that padding is correct for any
11745 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11746 2 * DWARF2_ADDR_SIZE);
11747 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11748 dw2_asm_output_data (2, 0, NULL);
11751 /* It is necessary not to output these entries if the sections were
11752 not used; if the sections were not used, the length will be 0 and
11753 the address may end up as 0 if the section is discarded by ld
11754 --gc-sections, leaving an invalid (0, 0) entry that can be
11755 confused with the terminator. */
11756 if (text_section_used)
11758 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11759 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11760 text_section_label, "Length");
11762 if (cold_text_section_used)
11764 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11766 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11767 cold_text_section_label, "Length");
11770 if (have_multiple_function_sections)
11772 unsigned fde_idx = 0;
11774 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
11776 dw_fde_ref fde = &fde_table[fde_idx];
11778 if (!fde->in_std_section)
11780 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
11782 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
11783 fde->dw_fde_begin, "Length");
11785 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11787 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
11789 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
11790 fde->dw_fde_second_begin, "Length");
11795 /* Output the terminator words. */
11796 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11797 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11800 /* Add a new entry to .debug_ranges. Return the offset at which it
11803 static unsigned int
11804 add_ranges_num (int num)
11806 unsigned int in_use = ranges_table_in_use;
11808 if (in_use == ranges_table_allocated)
11810 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11811 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11812 ranges_table_allocated);
11813 memset (ranges_table + ranges_table_in_use, 0,
11814 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11817 ranges_table[in_use].num = num;
11818 ranges_table_in_use = in_use + 1;
11820 return in_use * 2 * DWARF2_ADDR_SIZE;
11823 /* Add a new entry to .debug_ranges corresponding to a block, or a
11824 range terminator if BLOCK is NULL. */
11826 static unsigned int
11827 add_ranges (const_tree block)
11829 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11832 /* Add a new entry to .debug_ranges corresponding to a pair of
11836 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11839 unsigned int in_use = ranges_by_label_in_use;
11840 unsigned int offset;
11842 if (in_use == ranges_by_label_allocated)
11844 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11845 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11847 ranges_by_label_allocated);
11848 memset (ranges_by_label + ranges_by_label_in_use, 0,
11849 RANGES_TABLE_INCREMENT
11850 * sizeof (struct dw_ranges_by_label_struct));
11853 ranges_by_label[in_use].begin = begin;
11854 ranges_by_label[in_use].end = end;
11855 ranges_by_label_in_use = in_use + 1;
11857 offset = add_ranges_num (-(int)in_use - 1);
11860 add_AT_range_list (die, DW_AT_ranges, offset);
11866 output_ranges (void)
11869 static const char *const start_fmt = "Offset %#x";
11870 const char *fmt = start_fmt;
11872 for (i = 0; i < ranges_table_in_use; i++)
11874 int block_num = ranges_table[i].num;
11878 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11879 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11881 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11882 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11884 /* If all code is in the text section, then the compilation
11885 unit base address defaults to DW_AT_low_pc, which is the
11886 base of the text section. */
11887 if (!have_multiple_function_sections)
11889 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11890 text_section_label,
11891 fmt, i * 2 * DWARF2_ADDR_SIZE);
11892 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11893 text_section_label, NULL);
11896 /* Otherwise, the compilation unit base address is zero,
11897 which allows us to use absolute addresses, and not worry
11898 about whether the target supports cross-section
11902 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11903 fmt, i * 2 * DWARF2_ADDR_SIZE);
11904 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11910 /* Negative block_num stands for an index into ranges_by_label. */
11911 else if (block_num < 0)
11913 int lab_idx = - block_num - 1;
11915 if (!have_multiple_function_sections)
11917 gcc_unreachable ();
11919 /* If we ever use add_ranges_by_labels () for a single
11920 function section, all we have to do is to take out
11921 the #if 0 above. */
11922 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11923 ranges_by_label[lab_idx].begin,
11924 text_section_label,
11925 fmt, i * 2 * DWARF2_ADDR_SIZE);
11926 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11927 ranges_by_label[lab_idx].end,
11928 text_section_label, NULL);
11933 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11934 ranges_by_label[lab_idx].begin,
11935 fmt, i * 2 * DWARF2_ADDR_SIZE);
11936 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11937 ranges_by_label[lab_idx].end,
11943 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11944 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11950 /* Data structure containing information about input files. */
11953 const char *path; /* Complete file name. */
11954 const char *fname; /* File name part. */
11955 int length; /* Length of entire string. */
11956 struct dwarf_file_data * file_idx; /* Index in input file table. */
11957 int dir_idx; /* Index in directory table. */
11960 /* Data structure containing information about directories with source
11964 const char *path; /* Path including directory name. */
11965 int length; /* Path length. */
11966 int prefix; /* Index of directory entry which is a prefix. */
11967 int count; /* Number of files in this directory. */
11968 int dir_idx; /* Index of directory used as base. */
11971 /* Callback function for file_info comparison. We sort by looking at
11972 the directories in the path. */
11975 file_info_cmp (const void *p1, const void *p2)
11977 const struct file_info *const s1 = (const struct file_info *) p1;
11978 const struct file_info *const s2 = (const struct file_info *) p2;
11979 const unsigned char *cp1;
11980 const unsigned char *cp2;
11982 /* Take care of file names without directories. We need to make sure that
11983 we return consistent values to qsort since some will get confused if
11984 we return the same value when identical operands are passed in opposite
11985 orders. So if neither has a directory, return 0 and otherwise return
11986 1 or -1 depending on which one has the directory. */
11987 if ((s1->path == s1->fname || s2->path == s2->fname))
11988 return (s2->path == s2->fname) - (s1->path == s1->fname);
11990 cp1 = (const unsigned char *) s1->path;
11991 cp2 = (const unsigned char *) s2->path;
11997 /* Reached the end of the first path? If so, handle like above. */
11998 if ((cp1 == (const unsigned char *) s1->fname)
11999 || (cp2 == (const unsigned char *) s2->fname))
12000 return ((cp2 == (const unsigned char *) s2->fname)
12001 - (cp1 == (const unsigned char *) s1->fname));
12003 /* Character of current path component the same? */
12004 else if (*cp1 != *cp2)
12005 return *cp1 - *cp2;
12009 struct file_name_acquire_data
12011 struct file_info *files;
12016 /* Traversal function for the hash table. */
12019 file_name_acquire (void ** slot, void *data)
12021 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12022 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12023 struct file_info *fi;
12026 gcc_assert (fnad->max_files >= d->emitted_number);
12028 if (! d->emitted_number)
12031 gcc_assert (fnad->max_files != fnad->used_files);
12033 fi = fnad->files + fnad->used_files++;
12035 /* Skip all leading "./". */
12037 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12040 /* Create a new array entry. */
12042 fi->length = strlen (f);
12045 /* Search for the file name part. */
12046 f = strrchr (f, DIR_SEPARATOR);
12047 #if defined (DIR_SEPARATOR_2)
12049 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12053 if (f == NULL || f < g)
12059 fi->fname = f == NULL ? fi->path : f + 1;
12063 /* Output the directory table and the file name table. We try to minimize
12064 the total amount of memory needed. A heuristic is used to avoid large
12065 slowdowns with many input files. */
12068 output_file_names (void)
12070 struct file_name_acquire_data fnad;
12072 struct file_info *files;
12073 struct dir_info *dirs;
12081 if (!last_emitted_file)
12083 dw2_asm_output_data (1, 0, "End directory table");
12084 dw2_asm_output_data (1, 0, "End file name table");
12088 numfiles = last_emitted_file->emitted_number;
12090 /* Allocate the various arrays we need. */
12091 files = XALLOCAVEC (struct file_info, numfiles);
12092 dirs = XALLOCAVEC (struct dir_info, numfiles);
12094 fnad.files = files;
12095 fnad.used_files = 0;
12096 fnad.max_files = numfiles;
12097 htab_traverse (file_table, file_name_acquire, &fnad);
12098 gcc_assert (fnad.used_files == fnad.max_files);
12100 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12102 /* Find all the different directories used. */
12103 dirs[0].path = files[0].path;
12104 dirs[0].length = files[0].fname - files[0].path;
12105 dirs[0].prefix = -1;
12107 dirs[0].dir_idx = 0;
12108 files[0].dir_idx = 0;
12111 for (i = 1; i < numfiles; i++)
12112 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12113 && memcmp (dirs[ndirs - 1].path, files[i].path,
12114 dirs[ndirs - 1].length) == 0)
12116 /* Same directory as last entry. */
12117 files[i].dir_idx = ndirs - 1;
12118 ++dirs[ndirs - 1].count;
12124 /* This is a new directory. */
12125 dirs[ndirs].path = files[i].path;
12126 dirs[ndirs].length = files[i].fname - files[i].path;
12127 dirs[ndirs].count = 1;
12128 dirs[ndirs].dir_idx = ndirs;
12129 files[i].dir_idx = ndirs;
12131 /* Search for a prefix. */
12132 dirs[ndirs].prefix = -1;
12133 for (j = 0; j < ndirs; j++)
12134 if (dirs[j].length < dirs[ndirs].length
12135 && dirs[j].length > 1
12136 && (dirs[ndirs].prefix == -1
12137 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12138 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12139 dirs[ndirs].prefix = j;
12144 /* Now to the actual work. We have to find a subset of the directories which
12145 allow expressing the file name using references to the directory table
12146 with the least amount of characters. We do not do an exhaustive search
12147 where we would have to check out every combination of every single
12148 possible prefix. Instead we use a heuristic which provides nearly optimal
12149 results in most cases and never is much off. */
12150 saved = XALLOCAVEC (int, ndirs);
12151 savehere = XALLOCAVEC (int, ndirs);
12153 memset (saved, '\0', ndirs * sizeof (saved[0]));
12154 for (i = 0; i < ndirs; i++)
12159 /* We can always save some space for the current directory. But this
12160 does not mean it will be enough to justify adding the directory. */
12161 savehere[i] = dirs[i].length;
12162 total = (savehere[i] - saved[i]) * dirs[i].count;
12164 for (j = i + 1; j < ndirs; j++)
12167 if (saved[j] < dirs[i].length)
12169 /* Determine whether the dirs[i] path is a prefix of the
12173 k = dirs[j].prefix;
12174 while (k != -1 && k != (int) i)
12175 k = dirs[k].prefix;
12179 /* Yes it is. We can possibly save some memory by
12180 writing the filenames in dirs[j] relative to
12182 savehere[j] = dirs[i].length;
12183 total += (savehere[j] - saved[j]) * dirs[j].count;
12188 /* Check whether we can save enough to justify adding the dirs[i]
12190 if (total > dirs[i].length + 1)
12192 /* It's worthwhile adding. */
12193 for (j = i; j < ndirs; j++)
12194 if (savehere[j] > 0)
12196 /* Remember how much we saved for this directory so far. */
12197 saved[j] = savehere[j];
12199 /* Remember the prefix directory. */
12200 dirs[j].dir_idx = i;
12205 /* Emit the directory name table. */
12206 idx_offset = dirs[0].length > 0 ? 1 : 0;
12207 for (i = 1 - idx_offset; i < ndirs; i++)
12208 dw2_asm_output_nstring (dirs[i].path,
12210 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12211 "Directory Entry: %#x", i + idx_offset);
12213 dw2_asm_output_data (1, 0, "End directory table");
12215 /* We have to emit them in the order of emitted_number since that's
12216 used in the debug info generation. To do this efficiently we
12217 generate a back-mapping of the indices first. */
12218 backmap = XALLOCAVEC (int, numfiles);
12219 for (i = 0; i < numfiles; i++)
12220 backmap[files[i].file_idx->emitted_number - 1] = i;
12222 /* Now write all the file names. */
12223 for (i = 0; i < numfiles; i++)
12225 int file_idx = backmap[i];
12226 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12228 #ifdef VMS_DEBUGGING_INFO
12229 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12231 /* Setting these fields can lead to debugger miscomparisons,
12232 but VMS Debug requires them to be set correctly. */
12237 int maxfilelen = strlen (files[file_idx].path)
12238 + dirs[dir_idx].length
12239 + MAX_VMS_VERSION_LEN + 1;
12240 char *filebuf = XALLOCAVEC (char, maxfilelen);
12242 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12243 snprintf (filebuf, maxfilelen, "%s;%d",
12244 files[file_idx].path + dirs[dir_idx].length, ver);
12246 dw2_asm_output_nstring
12247 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12249 /* Include directory index. */
12250 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12252 /* Modification time. */
12253 dw2_asm_output_data_uleb128
12254 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12258 /* File length in bytes. */
12259 dw2_asm_output_data_uleb128
12260 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12264 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12265 "File Entry: %#x", (unsigned) i + 1);
12267 /* Include directory index. */
12268 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12270 /* Modification time. */
12271 dw2_asm_output_data_uleb128 (0, NULL);
12273 /* File length in bytes. */
12274 dw2_asm_output_data_uleb128 (0, NULL);
12275 #endif /* VMS_DEBUGGING_INFO */
12278 dw2_asm_output_data (1, 0, "End file name table");
12282 /* Output the source line number correspondence information. This
12283 information goes into the .debug_line section. */
12286 output_line_info (void)
12288 char l1[20], l2[20], p1[20], p2[20];
12289 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12290 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12292 unsigned n_op_args;
12293 unsigned long lt_index;
12294 unsigned long current_line;
12297 unsigned long current_file;
12298 unsigned long function;
12299 int ver = dwarf_version;
12301 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12302 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12303 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12304 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12306 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12307 dw2_asm_output_data (4, 0xffffffff,
12308 "Initial length escape value indicating 64-bit DWARF extension");
12309 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12310 "Length of Source Line Info");
12311 ASM_OUTPUT_LABEL (asm_out_file, l1);
12313 dw2_asm_output_data (2, ver, "DWARF Version");
12314 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12315 ASM_OUTPUT_LABEL (asm_out_file, p1);
12317 /* Define the architecture-dependent minimum instruction length (in
12318 bytes). In this implementation of DWARF, this field is used for
12319 information purposes only. Since GCC generates assembly language,
12320 we have no a priori knowledge of how many instruction bytes are
12321 generated for each source line, and therefore can use only the
12322 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12323 commands. Accordingly, we fix this as `1', which is "correct
12324 enough" for all architectures, and don't let the target override. */
12325 dw2_asm_output_data (1, 1,
12326 "Minimum Instruction Length");
12329 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12330 "Maximum Operations Per Instruction");
12331 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12332 "Default is_stmt_start flag");
12333 dw2_asm_output_data (1, DWARF_LINE_BASE,
12334 "Line Base Value (Special Opcodes)");
12335 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12336 "Line Range Value (Special Opcodes)");
12337 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12338 "Special Opcode Base");
12340 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12344 case DW_LNS_advance_pc:
12345 case DW_LNS_advance_line:
12346 case DW_LNS_set_file:
12347 case DW_LNS_set_column:
12348 case DW_LNS_fixed_advance_pc:
12356 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12360 /* Write out the information about the files we use. */
12361 output_file_names ();
12362 ASM_OUTPUT_LABEL (asm_out_file, p2);
12364 /* We used to set the address register to the first location in the text
12365 section here, but that didn't accomplish anything since we already
12366 have a line note for the opening brace of the first function. */
12368 /* Generate the line number to PC correspondence table, encoded as
12369 a series of state machine operations. */
12373 if (cfun && in_cold_section_p)
12374 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12376 strcpy (prev_line_label, text_section_label);
12377 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12379 dw_line_info_ref line_info = &line_info_table[lt_index];
12382 /* Disable this optimization for now; GDB wants to see two line notes
12383 at the beginning of a function so it can find the end of the
12386 /* Don't emit anything for redundant notes. Just updating the
12387 address doesn't accomplish anything, because we already assume
12388 that anything after the last address is this line. */
12389 if (line_info->dw_line_num == current_line
12390 && line_info->dw_file_num == current_file)
12394 /* Emit debug info for the address of the current line.
12396 Unfortunately, we have little choice here currently, and must always
12397 use the most general form. GCC does not know the address delta
12398 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12399 attributes which will give an upper bound on the address range. We
12400 could perhaps use length attributes to determine when it is safe to
12401 use DW_LNS_fixed_advance_pc. */
12403 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12406 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12407 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12408 "DW_LNS_fixed_advance_pc");
12409 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12413 /* This can handle any delta. This takes
12414 4+DWARF2_ADDR_SIZE bytes. */
12415 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12416 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12417 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12418 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12421 strcpy (prev_line_label, line_label);
12423 /* Emit debug info for the source file of the current line, if
12424 different from the previous line. */
12425 if (line_info->dw_file_num != current_file)
12427 current_file = line_info->dw_file_num;
12428 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12429 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12432 /* Emit debug info for the current line number, choosing the encoding
12433 that uses the least amount of space. */
12434 if (line_info->dw_line_num != current_line)
12436 line_offset = line_info->dw_line_num - current_line;
12437 line_delta = line_offset - DWARF_LINE_BASE;
12438 current_line = line_info->dw_line_num;
12439 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12440 /* This can handle deltas from -10 to 234, using the current
12441 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12443 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12444 "line %lu", current_line);
12447 /* This can handle any delta. This takes at least 4 bytes,
12448 depending on the value being encoded. */
12449 dw2_asm_output_data (1, DW_LNS_advance_line,
12450 "advance to line %lu", current_line);
12451 dw2_asm_output_data_sleb128 (line_offset, NULL);
12452 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12456 /* We still need to start a new row, so output a copy insn. */
12457 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12460 /* Emit debug info for the address of the end of the function. */
12463 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12464 "DW_LNS_fixed_advance_pc");
12465 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12469 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12470 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12471 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12472 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12475 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12476 dw2_asm_output_data_uleb128 (1, NULL);
12477 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12482 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12484 dw_separate_line_info_ref line_info
12485 = &separate_line_info_table[lt_index];
12488 /* Don't emit anything for redundant notes. */
12489 if (line_info->dw_line_num == current_line
12490 && line_info->dw_file_num == current_file
12491 && line_info->function == function)
12495 /* Emit debug info for the address of the current line. If this is
12496 a new function, or the first line of a function, then we need
12497 to handle it differently. */
12498 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12500 if (function != line_info->function)
12502 function = line_info->function;
12504 /* Set the address register to the first line in the function. */
12505 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12506 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12507 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12508 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12512 /* ??? See the DW_LNS_advance_pc comment above. */
12515 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12516 "DW_LNS_fixed_advance_pc");
12517 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12521 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12522 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12523 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12524 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12528 strcpy (prev_line_label, line_label);
12530 /* Emit debug info for the source file of the current line, if
12531 different from the previous line. */
12532 if (line_info->dw_file_num != current_file)
12534 current_file = line_info->dw_file_num;
12535 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12536 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12539 /* Emit debug info for the current line number, choosing the encoding
12540 that uses the least amount of space. */
12541 if (line_info->dw_line_num != current_line)
12543 line_offset = line_info->dw_line_num - current_line;
12544 line_delta = line_offset - DWARF_LINE_BASE;
12545 current_line = line_info->dw_line_num;
12546 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12547 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12548 "line %lu", current_line);
12551 dw2_asm_output_data (1, DW_LNS_advance_line,
12552 "advance to line %lu", current_line);
12553 dw2_asm_output_data_sleb128 (line_offset, NULL);
12554 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12558 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12566 /* If we're done with a function, end its sequence. */
12567 if (lt_index == separate_line_info_table_in_use
12568 || separate_line_info_table[lt_index].function != function)
12573 /* Emit debug info for the address of the end of the function. */
12574 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12577 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12578 "DW_LNS_fixed_advance_pc");
12579 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12583 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12584 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12585 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12586 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12589 /* Output the marker for the end of this sequence. */
12590 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12591 dw2_asm_output_data_uleb128 (1, NULL);
12592 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12596 /* Output the marker for the end of the line number info. */
12597 ASM_OUTPUT_LABEL (asm_out_file, l2);
12600 /* Given a pointer to a tree node for some base type, return a pointer to
12601 a DIE that describes the given type.
12603 This routine must only be called for GCC type nodes that correspond to
12604 Dwarf base (fundamental) types. */
12607 base_type_die (tree type)
12609 dw_die_ref base_type_result;
12610 enum dwarf_type encoding;
12612 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12615 /* If this is a subtype that should not be emitted as a subrange type,
12616 use the base type. See subrange_type_for_debug_p. */
12617 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12618 type = TREE_TYPE (type);
12620 switch (TREE_CODE (type))
12623 if ((dwarf_version >= 4 || !dwarf_strict)
12624 && TYPE_NAME (type)
12625 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12626 && DECL_IS_BUILTIN (TYPE_NAME (type))
12627 && DECL_NAME (TYPE_NAME (type)))
12629 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12630 if (strcmp (name, "char16_t") == 0
12631 || strcmp (name, "char32_t") == 0)
12633 encoding = DW_ATE_UTF;
12637 if (TYPE_STRING_FLAG (type))
12639 if (TYPE_UNSIGNED (type))
12640 encoding = DW_ATE_unsigned_char;
12642 encoding = DW_ATE_signed_char;
12644 else if (TYPE_UNSIGNED (type))
12645 encoding = DW_ATE_unsigned;
12647 encoding = DW_ATE_signed;
12651 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12653 if (dwarf_version >= 3 || !dwarf_strict)
12654 encoding = DW_ATE_decimal_float;
12656 encoding = DW_ATE_lo_user;
12659 encoding = DW_ATE_float;
12662 case FIXED_POINT_TYPE:
12663 if (!(dwarf_version >= 3 || !dwarf_strict))
12664 encoding = DW_ATE_lo_user;
12665 else if (TYPE_UNSIGNED (type))
12666 encoding = DW_ATE_unsigned_fixed;
12668 encoding = DW_ATE_signed_fixed;
12671 /* Dwarf2 doesn't know anything about complex ints, so use
12672 a user defined type for it. */
12674 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12675 encoding = DW_ATE_complex_float;
12677 encoding = DW_ATE_lo_user;
12681 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12682 encoding = DW_ATE_boolean;
12686 /* No other TREE_CODEs are Dwarf fundamental types. */
12687 gcc_unreachable ();
12690 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12692 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12693 int_size_in_bytes (type));
12694 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12696 return base_type_result;
12699 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12700 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12703 is_base_type (tree type)
12705 switch (TREE_CODE (type))
12711 case FIXED_POINT_TYPE:
12719 case QUAL_UNION_TYPE:
12720 case ENUMERAL_TYPE:
12721 case FUNCTION_TYPE:
12724 case REFERENCE_TYPE:
12732 gcc_unreachable ();
12738 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12739 node, return the size in bits for the type if it is a constant, or else
12740 return the alignment for the type if the type's size is not constant, or
12741 else return BITS_PER_WORD if the type actually turns out to be an
12742 ERROR_MARK node. */
12744 static inline unsigned HOST_WIDE_INT
12745 simple_type_size_in_bits (const_tree type)
12747 if (TREE_CODE (type) == ERROR_MARK)
12748 return BITS_PER_WORD;
12749 else if (TYPE_SIZE (type) == NULL_TREE)
12751 else if (host_integerp (TYPE_SIZE (type), 1))
12752 return tree_low_cst (TYPE_SIZE (type), 1);
12754 return TYPE_ALIGN (type);
12757 /* Similarly, but return a double_int instead of UHWI. */
12759 static inline double_int
12760 double_int_type_size_in_bits (const_tree type)
12762 if (TREE_CODE (type) == ERROR_MARK)
12763 return uhwi_to_double_int (BITS_PER_WORD);
12764 else if (TYPE_SIZE (type) == NULL_TREE)
12765 return double_int_zero;
12766 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12767 return tree_to_double_int (TYPE_SIZE (type));
12769 return uhwi_to_double_int (TYPE_ALIGN (type));
12772 /* Given a pointer to a tree node for a subrange type, return a pointer
12773 to a DIE that describes the given type. */
12776 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12778 dw_die_ref subrange_die;
12779 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12781 if (context_die == NULL)
12782 context_die = comp_unit_die ();
12784 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12786 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12788 /* The size of the subrange type and its base type do not match,
12789 so we need to generate a size attribute for the subrange type. */
12790 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12794 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12796 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12798 return subrange_die;
12801 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12802 entry that chains various modifiers in front of the given type. */
12805 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12806 dw_die_ref context_die)
12808 enum tree_code code = TREE_CODE (type);
12809 dw_die_ref mod_type_die;
12810 dw_die_ref sub_die = NULL;
12811 tree item_type = NULL;
12812 tree qualified_type;
12813 tree name, low, high;
12815 if (code == ERROR_MARK)
12818 /* See if we already have the appropriately qualified variant of
12821 = get_qualified_type (type,
12822 ((is_const_type ? TYPE_QUAL_CONST : 0)
12823 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12825 if (qualified_type == sizetype
12826 && TYPE_NAME (qualified_type)
12827 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12829 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
12831 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
12832 && TYPE_PRECISION (t)
12833 == TYPE_PRECISION (qualified_type)
12834 && TYPE_UNSIGNED (t)
12835 == TYPE_UNSIGNED (qualified_type));
12836 qualified_type = t;
12839 /* If we do, then we can just use its DIE, if it exists. */
12840 if (qualified_type)
12842 mod_type_die = lookup_type_die (qualified_type);
12844 return mod_type_die;
12847 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12849 /* Handle C typedef types. */
12850 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12851 && !DECL_ARTIFICIAL (name))
12853 tree dtype = TREE_TYPE (name);
12855 if (qualified_type == dtype)
12857 /* For a named type, use the typedef. */
12858 gen_type_die (qualified_type, context_die);
12859 return lookup_type_die (qualified_type);
12861 else if (is_const_type < TYPE_READONLY (dtype)
12862 || is_volatile_type < TYPE_VOLATILE (dtype)
12863 || (is_const_type <= TYPE_READONLY (dtype)
12864 && is_volatile_type <= TYPE_VOLATILE (dtype)
12865 && DECL_ORIGINAL_TYPE (name) != type))
12866 /* cv-unqualified version of named type. Just use the unnamed
12867 type to which it refers. */
12868 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12869 is_const_type, is_volatile_type,
12871 /* Else cv-qualified version of named type; fall through. */
12875 /* If both is_const_type and is_volatile_type, prefer the path
12876 which leads to a qualified type. */
12877 && (!is_volatile_type
12878 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
12879 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
12881 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
12882 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12884 else if (is_volatile_type)
12886 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
12887 sub_die = modified_type_die (type, is_const_type, 0, context_die);
12889 else if (code == POINTER_TYPE)
12891 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
12892 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12893 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12894 item_type = TREE_TYPE (type);
12895 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12896 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12897 TYPE_ADDR_SPACE (item_type));
12899 else if (code == REFERENCE_TYPE)
12901 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
12902 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
12905 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
12906 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12907 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12908 item_type = TREE_TYPE (type);
12909 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12910 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12911 TYPE_ADDR_SPACE (item_type));
12913 else if (code == INTEGER_TYPE
12914 && TREE_TYPE (type) != NULL_TREE
12915 && subrange_type_for_debug_p (type, &low, &high))
12917 mod_type_die = subrange_type_die (type, low, high, context_die);
12918 item_type = TREE_TYPE (type);
12920 else if (is_base_type (type))
12921 mod_type_die = base_type_die (type);
12924 gen_type_die (type, context_die);
12926 /* We have to get the type_main_variant here (and pass that to the
12927 `lookup_type_die' routine) because the ..._TYPE node we have
12928 might simply be a *copy* of some original type node (where the
12929 copy was created to help us keep track of typedef names) and
12930 that copy might have a different TYPE_UID from the original
12932 if (TREE_CODE (type) != VECTOR_TYPE)
12933 return lookup_type_die (type_main_variant (type));
12935 /* Vectors have the debugging information in the type,
12936 not the main variant. */
12937 return lookup_type_die (type);
12940 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12941 don't output a DW_TAG_typedef, since there isn't one in the
12942 user's program; just attach a DW_AT_name to the type.
12943 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12944 if the base type already has the same name. */
12946 && ((TREE_CODE (name) != TYPE_DECL
12947 && (qualified_type == TYPE_MAIN_VARIANT (type)
12948 || (!is_const_type && !is_volatile_type)))
12949 || (TREE_CODE (name) == TYPE_DECL
12950 && TREE_TYPE (name) == qualified_type
12951 && DECL_NAME (name))))
12953 if (TREE_CODE (name) == TYPE_DECL)
12954 /* Could just call add_name_and_src_coords_attributes here,
12955 but since this is a builtin type it doesn't have any
12956 useful source coordinates anyway. */
12957 name = DECL_NAME (name);
12958 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12960 /* This probably indicates a bug. */
12961 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12962 add_name_attribute (mod_type_die, "__unknown__");
12964 if (qualified_type)
12965 equate_type_number_to_die (qualified_type, mod_type_die);
12968 /* We must do this after the equate_type_number_to_die call, in case
12969 this is a recursive type. This ensures that the modified_type_die
12970 recursion will terminate even if the type is recursive. Recursive
12971 types are possible in Ada. */
12972 sub_die = modified_type_die (item_type,
12973 TYPE_READONLY (item_type),
12974 TYPE_VOLATILE (item_type),
12977 if (sub_die != NULL)
12978 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
12980 return mod_type_die;
12983 /* Generate DIEs for the generic parameters of T.
12984 T must be either a generic type or a generic function.
12985 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12988 gen_generic_params_dies (tree t)
12992 dw_die_ref die = NULL;
12994 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
12998 die = lookup_type_die (t);
12999 else if (DECL_P (t))
13000 die = lookup_decl_die (t);
13004 parms = lang_hooks.get_innermost_generic_parms (t);
13006 /* T has no generic parameter. It means T is neither a generic type
13007 or function. End of story. */
13010 parms_num = TREE_VEC_LENGTH (parms);
13011 args = lang_hooks.get_innermost_generic_args (t);
13012 for (i = 0; i < parms_num; i++)
13014 tree parm, arg, arg_pack_elems;
13016 parm = TREE_VEC_ELT (parms, i);
13017 arg = TREE_VEC_ELT (args, i);
13018 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13019 gcc_assert (parm && TREE_VALUE (parm) && arg);
13021 if (parm && TREE_VALUE (parm) && arg)
13023 /* If PARM represents a template parameter pack,
13024 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13025 by DW_TAG_template_*_parameter DIEs for the argument
13026 pack elements of ARG. Note that ARG would then be
13027 an argument pack. */
13028 if (arg_pack_elems)
13029 template_parameter_pack_die (TREE_VALUE (parm),
13033 generic_parameter_die (TREE_VALUE (parm), arg,
13034 true /* Emit DW_AT_name */, die);
13039 /* Create and return a DIE for PARM which should be
13040 the representation of a generic type parameter.
13041 For instance, in the C++ front end, PARM would be a template parameter.
13042 ARG is the argument to PARM.
13043 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13045 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13046 as a child node. */
13049 generic_parameter_die (tree parm, tree arg,
13051 dw_die_ref parent_die)
13053 dw_die_ref tmpl_die = NULL;
13054 const char *name = NULL;
13056 if (!parm || !DECL_NAME (parm) || !arg)
13059 /* We support non-type generic parameters and arguments,
13060 type generic parameters and arguments, as well as
13061 generic generic parameters (a.k.a. template template parameters in C++)
13063 if (TREE_CODE (parm) == PARM_DECL)
13064 /* PARM is a nontype generic parameter */
13065 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13066 else if (TREE_CODE (parm) == TYPE_DECL)
13067 /* PARM is a type generic parameter. */
13068 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13069 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13070 /* PARM is a generic generic parameter.
13071 Its DIE is a GNU extension. It shall have a
13072 DW_AT_name attribute to represent the name of the template template
13073 parameter, and a DW_AT_GNU_template_name attribute to represent the
13074 name of the template template argument. */
13075 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13078 gcc_unreachable ();
13084 /* If PARM is a generic parameter pack, it means we are
13085 emitting debug info for a template argument pack element.
13086 In other terms, ARG is a template argument pack element.
13087 In that case, we don't emit any DW_AT_name attribute for
13091 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13093 add_AT_string (tmpl_die, DW_AT_name, name);
13096 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13098 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13099 TMPL_DIE should have a child DW_AT_type attribute that is set
13100 to the type of the argument to PARM, which is ARG.
13101 If PARM is a type generic parameter, TMPL_DIE should have a
13102 child DW_AT_type that is set to ARG. */
13103 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13104 add_type_attribute (tmpl_die, tmpl_type, 0,
13105 TREE_THIS_VOLATILE (tmpl_type),
13110 /* So TMPL_DIE is a DIE representing a
13111 a generic generic template parameter, a.k.a template template
13112 parameter in C++ and arg is a template. */
13114 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13115 to the name of the argument. */
13116 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13118 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13121 if (TREE_CODE (parm) == PARM_DECL)
13122 /* So PARM is a non-type generic parameter.
13123 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13124 attribute of TMPL_DIE which value represents the value
13126 We must be careful here:
13127 The value of ARG might reference some function decls.
13128 We might currently be emitting debug info for a generic
13129 type and types are emitted before function decls, we don't
13130 know if the function decls referenced by ARG will actually be
13131 emitted after cgraph computations.
13132 So must defer the generation of the DW_AT_const_value to
13133 after cgraph is ready. */
13134 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13140 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13141 PARM_PACK must be a template parameter pack. The returned DIE
13142 will be child DIE of PARENT_DIE. */
13145 template_parameter_pack_die (tree parm_pack,
13146 tree parm_pack_args,
13147 dw_die_ref parent_die)
13152 gcc_assert (parent_die && parm_pack);
13154 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13155 add_name_and_src_coords_attributes (die, parm_pack);
13156 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13157 generic_parameter_die (parm_pack,
13158 TREE_VEC_ELT (parm_pack_args, j),
13159 false /* Don't emit DW_AT_name */,
13164 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13165 an enumerated type. */
13168 type_is_enum (const_tree type)
13170 return TREE_CODE (type) == ENUMERAL_TYPE;
13173 /* Return the DBX register number described by a given RTL node. */
13175 static unsigned int
13176 dbx_reg_number (const_rtx rtl)
13178 unsigned regno = REGNO (rtl);
13180 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13182 #ifdef LEAF_REG_REMAP
13183 if (current_function_uses_only_leaf_regs)
13185 int leaf_reg = LEAF_REG_REMAP (regno);
13186 if (leaf_reg != -1)
13187 regno = (unsigned) leaf_reg;
13191 return DBX_REGISTER_NUMBER (regno);
13194 /* Optionally add a DW_OP_piece term to a location description expression.
13195 DW_OP_piece is only added if the location description expression already
13196 doesn't end with DW_OP_piece. */
13199 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13201 dw_loc_descr_ref loc;
13203 if (*list_head != NULL)
13205 /* Find the end of the chain. */
13206 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13209 if (loc->dw_loc_opc != DW_OP_piece)
13210 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13214 /* Return a location descriptor that designates a machine register or
13215 zero if there is none. */
13217 static dw_loc_descr_ref
13218 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13222 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13225 /* We only use "frame base" when we're sure we're talking about the
13226 post-prologue local stack frame. We do this by *not* running
13227 register elimination until this point, and recognizing the special
13228 argument pointer and soft frame pointer rtx's.
13229 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13230 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13231 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13233 dw_loc_descr_ref result = NULL;
13235 if (dwarf_version >= 4 || !dwarf_strict)
13237 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13239 add_loc_descr (&result,
13240 new_loc_descr (DW_OP_stack_value, 0, 0));
13245 regs = targetm.dwarf_register_span (rtl);
13247 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13248 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13250 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13253 /* Return a location descriptor that designates a machine register for
13254 a given hard register number. */
13256 static dw_loc_descr_ref
13257 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13259 dw_loc_descr_ref reg_loc_descr;
13263 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13265 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13267 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13268 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13270 return reg_loc_descr;
13273 /* Given an RTL of a register, return a location descriptor that
13274 designates a value that spans more than one register. */
13276 static dw_loc_descr_ref
13277 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13278 enum var_init_status initialized)
13280 int nregs, size, i;
13282 dw_loc_descr_ref loc_result = NULL;
13285 #ifdef LEAF_REG_REMAP
13286 if (current_function_uses_only_leaf_regs)
13288 int leaf_reg = LEAF_REG_REMAP (reg);
13289 if (leaf_reg != -1)
13290 reg = (unsigned) leaf_reg;
13293 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13294 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13296 /* Simple, contiguous registers. */
13297 if (regs == NULL_RTX)
13299 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13304 dw_loc_descr_ref t;
13306 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13307 VAR_INIT_STATUS_INITIALIZED);
13308 add_loc_descr (&loc_result, t);
13309 add_loc_descr_op_piece (&loc_result, size);
13315 /* Now onto stupid register sets in non contiguous locations. */
13317 gcc_assert (GET_CODE (regs) == PARALLEL);
13319 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13322 for (i = 0; i < XVECLEN (regs, 0); ++i)
13324 dw_loc_descr_ref t;
13326 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13327 VAR_INIT_STATUS_INITIALIZED);
13328 add_loc_descr (&loc_result, t);
13329 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13330 add_loc_descr_op_piece (&loc_result, size);
13333 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13334 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13338 /* Return a location descriptor that designates a constant. */
13340 static dw_loc_descr_ref
13341 int_loc_descriptor (HOST_WIDE_INT i)
13343 enum dwarf_location_atom op;
13345 /* Pick the smallest representation of a constant, rather than just
13346 defaulting to the LEB encoding. */
13350 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13351 else if (i <= 0xff)
13352 op = DW_OP_const1u;
13353 else if (i <= 0xffff)
13354 op = DW_OP_const2u;
13355 else if (HOST_BITS_PER_WIDE_INT == 32
13356 || i <= 0xffffffff)
13357 op = DW_OP_const4u;
13364 op = DW_OP_const1s;
13365 else if (i >= -0x8000)
13366 op = DW_OP_const2s;
13367 else if (HOST_BITS_PER_WIDE_INT == 32
13368 || i >= -0x80000000)
13369 op = DW_OP_const4s;
13374 return new_loc_descr (op, i, 0);
13377 /* Return loc description representing "address" of integer value.
13378 This can appear only as toplevel expression. */
13380 static dw_loc_descr_ref
13381 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13384 dw_loc_descr_ref loc_result = NULL;
13386 if (!(dwarf_version >= 4 || !dwarf_strict))
13393 else if (i <= 0xff)
13395 else if (i <= 0xffff)
13397 else if (HOST_BITS_PER_WIDE_INT == 32
13398 || i <= 0xffffffff)
13401 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13407 else if (i >= -0x8000)
13409 else if (HOST_BITS_PER_WIDE_INT == 32
13410 || i >= -0x80000000)
13413 litsize = 1 + size_of_sleb128 (i);
13415 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13416 is more compact. For DW_OP_stack_value we need:
13417 litsize + 1 (DW_OP_stack_value)
13418 and for DW_OP_implicit_value:
13419 1 (DW_OP_implicit_value) + 1 (length) + size. */
13420 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13422 loc_result = int_loc_descriptor (i);
13423 add_loc_descr (&loc_result,
13424 new_loc_descr (DW_OP_stack_value, 0, 0));
13428 loc_result = new_loc_descr (DW_OP_implicit_value,
13430 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13431 loc_result->dw_loc_oprnd2.v.val_int = i;
13435 /* Return a location descriptor that designates a base+offset location. */
13437 static dw_loc_descr_ref
13438 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13439 enum var_init_status initialized)
13441 unsigned int regno;
13442 dw_loc_descr_ref result;
13443 dw_fde_ref fde = current_fde ();
13445 /* We only use "frame base" when we're sure we're talking about the
13446 post-prologue local stack frame. We do this by *not* running
13447 register elimination until this point, and recognizing the special
13448 argument pointer and soft frame pointer rtx's. */
13449 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13451 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13455 if (GET_CODE (elim) == PLUS)
13457 offset += INTVAL (XEXP (elim, 1));
13458 elim = XEXP (elim, 0);
13460 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13461 && (elim == hard_frame_pointer_rtx
13462 || elim == stack_pointer_rtx))
13463 || elim == (frame_pointer_needed
13464 ? hard_frame_pointer_rtx
13465 : stack_pointer_rtx));
13467 /* If drap register is used to align stack, use frame
13468 pointer + offset to access stack variables. If stack
13469 is aligned without drap, use stack pointer + offset to
13470 access stack variables. */
13471 if (crtl->stack_realign_tried
13472 && reg == frame_pointer_rtx)
13475 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13476 ? HARD_FRAME_POINTER_REGNUM
13477 : STACK_POINTER_REGNUM);
13478 return new_reg_loc_descr (base_reg, offset);
13481 offset += frame_pointer_fb_offset;
13482 return new_loc_descr (DW_OP_fbreg, offset, 0);
13487 && (fde->drap_reg == REGNO (reg)
13488 || fde->vdrap_reg == REGNO (reg)))
13490 /* Use cfa+offset to represent the location of arguments passed
13491 on the stack when drap is used to align stack.
13492 Only do this when not optimizing, for optimized code var-tracking
13493 is supposed to track where the arguments live and the register
13494 used as vdrap or drap in some spot might be used for something
13495 else in other part of the routine. */
13496 return new_loc_descr (DW_OP_fbreg, offset, 0);
13499 regno = dbx_reg_number (reg);
13501 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13504 result = new_loc_descr (DW_OP_bregx, regno, offset);
13506 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13507 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13512 /* Return true if this RTL expression describes a base+offset calculation. */
13515 is_based_loc (const_rtx rtl)
13517 return (GET_CODE (rtl) == PLUS
13518 && ((REG_P (XEXP (rtl, 0))
13519 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13520 && CONST_INT_P (XEXP (rtl, 1)))));
13523 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13526 static dw_loc_descr_ref
13527 tls_mem_loc_descriptor (rtx mem)
13530 dw_loc_descr_ref loc_result;
13532 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13535 base = get_base_address (MEM_EXPR (mem));
13537 || TREE_CODE (base) != VAR_DECL
13538 || !DECL_THREAD_LOCAL_P (base))
13541 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13542 if (loc_result == NULL)
13545 if (INTVAL (MEM_OFFSET (mem)))
13546 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13551 /* Output debug info about reason why we failed to expand expression as dwarf
13555 expansion_failed (tree expr, rtx rtl, char const *reason)
13557 if (dump_file && (dump_flags & TDF_DETAILS))
13559 fprintf (dump_file, "Failed to expand as dwarf: ");
13561 print_generic_expr (dump_file, expr, dump_flags);
13564 fprintf (dump_file, "\n");
13565 print_rtl (dump_file, rtl);
13567 fprintf (dump_file, "\nReason: %s\n", reason);
13571 /* Helper function for const_ok_for_output, called either directly
13572 or via for_each_rtx. */
13575 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13579 if (GET_CODE (rtl) == UNSPEC)
13581 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13582 we can't express it in the debug info. */
13583 #ifdef ENABLE_CHECKING
13584 /* Don't complain about TLS UNSPECs, those are just too hard to
13586 if (XVECLEN (rtl, 0) != 1
13587 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13588 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13589 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13590 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13591 inform (current_function_decl
13592 ? DECL_SOURCE_LOCATION (current_function_decl)
13593 : UNKNOWN_LOCATION,
13594 #if NUM_UNSPEC_VALUES > 0
13595 "non-delegitimized UNSPEC %s (%d) found in variable location",
13596 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
13597 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
13600 "non-delegitimized UNSPEC %d found in variable location",
13604 expansion_failed (NULL_TREE, rtl,
13605 "UNSPEC hasn't been delegitimized.\n");
13609 if (GET_CODE (rtl) != SYMBOL_REF)
13612 if (CONSTANT_POOL_ADDRESS_P (rtl))
13615 get_pool_constant_mark (rtl, &marked);
13616 /* If all references to this pool constant were optimized away,
13617 it was not output and thus we can't represent it. */
13620 expansion_failed (NULL_TREE, rtl,
13621 "Constant was removed from constant pool.\n");
13626 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13629 /* Avoid references to external symbols in debug info, on several targets
13630 the linker might even refuse to link when linking a shared library,
13631 and in many other cases the relocations for .debug_info/.debug_loc are
13632 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13633 to be defined within the same shared library or executable are fine. */
13634 if (SYMBOL_REF_EXTERNAL_P (rtl))
13636 tree decl = SYMBOL_REF_DECL (rtl);
13638 if (decl == NULL || !targetm.binds_local_p (decl))
13640 expansion_failed (NULL_TREE, rtl,
13641 "Symbol not defined in current TU.\n");
13649 /* Return true if constant RTL can be emitted in DW_OP_addr or
13650 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13651 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13654 const_ok_for_output (rtx rtl)
13656 if (GET_CODE (rtl) == SYMBOL_REF)
13657 return const_ok_for_output_1 (&rtl, NULL) == 0;
13659 if (GET_CODE (rtl) == CONST)
13660 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13665 /* The following routine converts the RTL for a variable or parameter
13666 (resident in memory) into an equivalent Dwarf representation of a
13667 mechanism for getting the address of that same variable onto the top of a
13668 hypothetical "address evaluation" stack.
13670 When creating memory location descriptors, we are effectively transforming
13671 the RTL for a memory-resident object into its Dwarf postfix expression
13672 equivalent. This routine recursively descends an RTL tree, turning
13673 it into Dwarf postfix code as it goes.
13675 MODE is the mode of the memory reference, needed to handle some
13676 autoincrement addressing modes.
13678 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13679 location list for RTL.
13681 Return 0 if we can't represent the location. */
13683 static dw_loc_descr_ref
13684 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13685 enum var_init_status initialized)
13687 dw_loc_descr_ref mem_loc_result = NULL;
13688 enum dwarf_location_atom op;
13689 dw_loc_descr_ref op0, op1;
13691 /* Note that for a dynamically sized array, the location we will generate a
13692 description of here will be the lowest numbered location which is
13693 actually within the array. That's *not* necessarily the same as the
13694 zeroth element of the array. */
13696 rtl = targetm.delegitimize_address (rtl);
13698 switch (GET_CODE (rtl))
13703 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13706 /* The case of a subreg may arise when we have a local (register)
13707 variable or a formal (register) parameter which doesn't quite fill
13708 up an entire register. For now, just assume that it is
13709 legitimate to make the Dwarf info refer to the whole register which
13710 contains the given subreg. */
13711 if (!subreg_lowpart_p (rtl))
13713 rtl = SUBREG_REG (rtl);
13714 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13716 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13718 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13722 /* Whenever a register number forms a part of the description of the
13723 method for calculating the (dynamic) address of a memory resident
13724 object, DWARF rules require the register number be referred to as
13725 a "base register". This distinction is not based in any way upon
13726 what category of register the hardware believes the given register
13727 belongs to. This is strictly DWARF terminology we're dealing with
13728 here. Note that in cases where the location of a memory-resident
13729 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13730 OP_CONST (0)) the actual DWARF location descriptor that we generate
13731 may just be OP_BASEREG (basereg). This may look deceptively like
13732 the object in question was allocated to a register (rather than in
13733 memory) so DWARF consumers need to be aware of the subtle
13734 distinction between OP_REG and OP_BASEREG. */
13735 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13736 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13737 else if (stack_realign_drap
13739 && crtl->args.internal_arg_pointer == rtl
13740 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13742 /* If RTL is internal_arg_pointer, which has been optimized
13743 out, use DRAP instead. */
13744 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13745 VAR_INIT_STATUS_INITIALIZED);
13751 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13752 VAR_INIT_STATUS_INITIALIZED);
13757 int shift = DWARF2_ADDR_SIZE
13758 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13759 shift *= BITS_PER_UNIT;
13760 if (GET_CODE (rtl) == SIGN_EXTEND)
13764 mem_loc_result = op0;
13765 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13766 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13767 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13768 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13773 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13774 VAR_INIT_STATUS_INITIALIZED);
13775 if (mem_loc_result == NULL)
13776 mem_loc_result = tls_mem_loc_descriptor (rtl);
13777 if (mem_loc_result != 0)
13779 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13781 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13784 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13785 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13787 add_loc_descr (&mem_loc_result,
13788 new_loc_descr (DW_OP_deref_size,
13789 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13793 rtx new_rtl = avoid_constant_pool_reference (rtl);
13794 if (new_rtl != rtl)
13795 return mem_loc_descriptor (new_rtl, mode, initialized);
13800 rtl = XEXP (rtl, 1);
13802 /* ... fall through ... */
13805 /* Some ports can transform a symbol ref into a label ref, because
13806 the symbol ref is too far away and has to be dumped into a constant
13810 if (GET_CODE (rtl) == SYMBOL_REF
13811 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13813 dw_loc_descr_ref temp;
13815 /* If this is not defined, we have no way to emit the data. */
13816 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13819 /* We used to emit DW_OP_addr here, but that's wrong, since
13820 DW_OP_addr should be relocated by the debug info consumer,
13821 while DW_OP_GNU_push_tls_address operand should not. */
13822 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13823 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13824 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13825 temp->dw_loc_oprnd1.v.val_addr = rtl;
13826 temp->dtprel = true;
13828 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13829 add_loc_descr (&mem_loc_result, temp);
13834 if (!const_ok_for_output (rtl))
13838 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13839 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13840 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13841 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13847 case DEBUG_IMPLICIT_PTR:
13848 expansion_failed (NULL_TREE, rtl,
13849 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13855 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
13856 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
13857 if (REG_P (ENTRY_VALUE_EXP (rtl)))
13858 mem_loc_result->dw_loc_oprnd1.v.val_loc
13859 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
13860 VAR_INIT_STATUS_INITIALIZED);
13861 else if (MEM_P (ENTRY_VALUE_EXP (rtl)) && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
13863 dw_loc_descr_ref ref
13864 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), GET_MODE (rtl),
13865 VAR_INIT_STATUS_INITIALIZED);
13866 if (ref == NULL || ref->dw_loc_opc == DW_OP_fbreg)
13868 mem_loc_result->dw_loc_oprnd1.v.val_loc = ref;
13871 gcc_unreachable ();
13872 return mem_loc_result;
13875 /* Extract the PLUS expression nested inside and fall into
13876 PLUS code below. */
13877 rtl = XEXP (rtl, 1);
13882 /* Turn these into a PLUS expression and fall into the PLUS code
13884 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13885 GEN_INT (GET_CODE (rtl) == PRE_INC
13886 ? GET_MODE_UNIT_SIZE (mode)
13887 : -GET_MODE_UNIT_SIZE (mode)));
13889 /* ... fall through ... */
13893 if (is_based_loc (rtl))
13894 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13895 INTVAL (XEXP (rtl, 1)),
13896 VAR_INIT_STATUS_INITIALIZED);
13899 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13900 VAR_INIT_STATUS_INITIALIZED);
13901 if (mem_loc_result == 0)
13904 if (CONST_INT_P (XEXP (rtl, 1)))
13905 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13908 dw_loc_descr_ref mem_loc_result2
13909 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13910 VAR_INIT_STATUS_INITIALIZED);
13911 if (mem_loc_result2 == 0)
13913 add_loc_descr (&mem_loc_result, mem_loc_result2);
13914 add_loc_descr (&mem_loc_result,
13915 new_loc_descr (DW_OP_plus, 0, 0));
13920 /* If a pseudo-reg is optimized away, it is possible for it to
13921 be replaced with a MEM containing a multiply or shift. */
13963 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13964 VAR_INIT_STATUS_INITIALIZED);
13965 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13966 VAR_INIT_STATUS_INITIALIZED);
13968 if (op0 == 0 || op1 == 0)
13971 mem_loc_result = op0;
13972 add_loc_descr (&mem_loc_result, op1);
13973 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13977 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13978 VAR_INIT_STATUS_INITIALIZED);
13979 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13980 VAR_INIT_STATUS_INITIALIZED);
13982 if (op0 == 0 || op1 == 0)
13985 mem_loc_result = op0;
13986 add_loc_descr (&mem_loc_result, op1);
13987 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13988 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13989 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13990 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13991 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
14007 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14008 VAR_INIT_STATUS_INITIALIZED);
14013 mem_loc_result = op0;
14014 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14018 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
14046 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14047 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14051 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14053 if (op_mode == VOIDmode)
14054 op_mode = GET_MODE (XEXP (rtl, 1));
14055 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14058 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14059 VAR_INIT_STATUS_INITIALIZED);
14060 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14061 VAR_INIT_STATUS_INITIALIZED);
14063 if (op0 == 0 || op1 == 0)
14066 if (op_mode != VOIDmode
14067 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14069 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
14070 shift *= BITS_PER_UNIT;
14071 /* For eq/ne, if the operands are known to be zero-extended,
14072 there is no need to do the fancy shifting up. */
14073 if (op == DW_OP_eq || op == DW_OP_ne)
14075 dw_loc_descr_ref last0, last1;
14077 last0->dw_loc_next != NULL;
14078 last0 = last0->dw_loc_next)
14081 last1->dw_loc_next != NULL;
14082 last1 = last1->dw_loc_next)
14084 /* deref_size zero extends, and for constants we can check
14085 whether they are zero extended or not. */
14086 if (((last0->dw_loc_opc == DW_OP_deref_size
14087 && last0->dw_loc_oprnd1.v.val_int
14088 <= GET_MODE_SIZE (op_mode))
14089 || (CONST_INT_P (XEXP (rtl, 0))
14090 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14091 == (INTVAL (XEXP (rtl, 0))
14092 & GET_MODE_MASK (op_mode))))
14093 && ((last1->dw_loc_opc == DW_OP_deref_size
14094 && last1->dw_loc_oprnd1.v.val_int
14095 <= GET_MODE_SIZE (op_mode))
14096 || (CONST_INT_P (XEXP (rtl, 1))
14097 && (unsigned HOST_WIDE_INT)
14098 INTVAL (XEXP (rtl, 1))
14099 == (INTVAL (XEXP (rtl, 1))
14100 & GET_MODE_MASK (op_mode)))))
14103 add_loc_descr (&op0, int_loc_descriptor (shift));
14104 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14105 if (CONST_INT_P (XEXP (rtl, 1)))
14106 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14109 add_loc_descr (&op1, int_loc_descriptor (shift));
14110 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14116 mem_loc_result = op0;
14117 add_loc_descr (&mem_loc_result, op1);
14118 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14119 if (STORE_FLAG_VALUE != 1)
14121 add_loc_descr (&mem_loc_result,
14122 int_loc_descriptor (STORE_FLAG_VALUE));
14123 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14144 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14145 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14149 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14151 if (op_mode == VOIDmode)
14152 op_mode = GET_MODE (XEXP (rtl, 1));
14153 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14156 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14157 VAR_INIT_STATUS_INITIALIZED);
14158 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14159 VAR_INIT_STATUS_INITIALIZED);
14161 if (op0 == 0 || op1 == 0)
14164 if (op_mode != VOIDmode
14165 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14167 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14168 dw_loc_descr_ref last0, last1;
14170 last0->dw_loc_next != NULL;
14171 last0 = last0->dw_loc_next)
14174 last1->dw_loc_next != NULL;
14175 last1 = last1->dw_loc_next)
14177 if (CONST_INT_P (XEXP (rtl, 0)))
14178 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14179 /* deref_size zero extends, so no need to mask it again. */
14180 else if (last0->dw_loc_opc != DW_OP_deref_size
14181 || last0->dw_loc_oprnd1.v.val_int
14182 > GET_MODE_SIZE (op_mode))
14184 add_loc_descr (&op0, int_loc_descriptor (mask));
14185 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14187 if (CONST_INT_P (XEXP (rtl, 1)))
14188 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14189 /* deref_size zero extends, so no need to mask it again. */
14190 else if (last1->dw_loc_opc != DW_OP_deref_size
14191 || last1->dw_loc_oprnd1.v.val_int
14192 > GET_MODE_SIZE (op_mode))
14194 add_loc_descr (&op1, int_loc_descriptor (mask));
14195 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14200 HOST_WIDE_INT bias = 1;
14201 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14202 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14203 if (CONST_INT_P (XEXP (rtl, 1)))
14204 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14205 + INTVAL (XEXP (rtl, 1)));
14207 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14217 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14218 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14219 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14222 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14223 VAR_INIT_STATUS_INITIALIZED);
14224 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14225 VAR_INIT_STATUS_INITIALIZED);
14227 if (op0 == 0 || op1 == 0)
14230 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14231 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14232 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14233 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14235 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14237 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14238 add_loc_descr (&op0, int_loc_descriptor (mask));
14239 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14240 add_loc_descr (&op1, int_loc_descriptor (mask));
14241 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14245 HOST_WIDE_INT bias = 1;
14246 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14247 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14248 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14251 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14253 int shift = DWARF2_ADDR_SIZE
14254 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14255 shift *= BITS_PER_UNIT;
14256 add_loc_descr (&op0, int_loc_descriptor (shift));
14257 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14258 add_loc_descr (&op1, int_loc_descriptor (shift));
14259 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14262 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14266 mem_loc_result = op0;
14267 add_loc_descr (&mem_loc_result, op1);
14268 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14270 dw_loc_descr_ref bra_node, drop_node;
14272 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14273 add_loc_descr (&mem_loc_result, bra_node);
14274 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14275 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14276 add_loc_descr (&mem_loc_result, drop_node);
14277 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14278 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14284 if (CONST_INT_P (XEXP (rtl, 1))
14285 && CONST_INT_P (XEXP (rtl, 2))
14286 && ((unsigned) INTVAL (XEXP (rtl, 1))
14287 + (unsigned) INTVAL (XEXP (rtl, 2))
14288 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14289 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14290 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14293 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14294 VAR_INIT_STATUS_INITIALIZED);
14297 if (GET_CODE (rtl) == SIGN_EXTRACT)
14301 mem_loc_result = op0;
14302 size = INTVAL (XEXP (rtl, 1));
14303 shift = INTVAL (XEXP (rtl, 2));
14304 if (BITS_BIG_ENDIAN)
14305 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14307 if (shift + size != (int) DWARF2_ADDR_SIZE)
14309 add_loc_descr (&mem_loc_result,
14310 int_loc_descriptor (DWARF2_ADDR_SIZE
14312 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14314 if (size != (int) DWARF2_ADDR_SIZE)
14316 add_loc_descr (&mem_loc_result,
14317 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14318 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14325 dw_loc_descr_ref op2, bra_node, drop_node;
14326 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14327 VAR_INIT_STATUS_INITIALIZED);
14328 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14329 VAR_INIT_STATUS_INITIALIZED);
14330 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
14331 VAR_INIT_STATUS_INITIALIZED);
14332 if (op0 == NULL || op1 == NULL || op2 == NULL)
14335 mem_loc_result = op1;
14336 add_loc_descr (&mem_loc_result, op2);
14337 add_loc_descr (&mem_loc_result, op0);
14338 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14339 add_loc_descr (&mem_loc_result, bra_node);
14340 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14341 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14342 add_loc_descr (&mem_loc_result, drop_node);
14343 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14344 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14352 /* In theory, we could implement the above. */
14353 /* DWARF cannot represent the unsigned compare operations
14380 case FLOAT_TRUNCATE:
14382 case UNSIGNED_FLOAT:
14385 case FRACT_CONVERT:
14386 case UNSIGNED_FRACT_CONVERT:
14388 case UNSIGNED_SAT_FRACT:
14400 case VEC_DUPLICATE:
14403 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14404 can't express it in the debug info. This can happen e.g. with some
14409 resolve_one_addr (&rtl, NULL);
14413 #ifdef ENABLE_CHECKING
14414 print_rtl (stderr, rtl);
14415 gcc_unreachable ();
14421 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14422 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14424 return mem_loc_result;
14427 /* Return a descriptor that describes the concatenation of two locations.
14428 This is typically a complex variable. */
14430 static dw_loc_descr_ref
14431 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14433 dw_loc_descr_ref cc_loc_result = NULL;
14434 dw_loc_descr_ref x0_ref
14435 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14436 dw_loc_descr_ref x1_ref
14437 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14439 if (x0_ref == 0 || x1_ref == 0)
14442 cc_loc_result = x0_ref;
14443 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14445 add_loc_descr (&cc_loc_result, x1_ref);
14446 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14448 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14449 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14451 return cc_loc_result;
14454 /* Return a descriptor that describes the concatenation of N
14457 static dw_loc_descr_ref
14458 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14461 dw_loc_descr_ref cc_loc_result = NULL;
14462 unsigned int n = XVECLEN (concatn, 0);
14464 for (i = 0; i < n; ++i)
14466 dw_loc_descr_ref ref;
14467 rtx x = XVECEXP (concatn, 0, i);
14469 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14473 add_loc_descr (&cc_loc_result, ref);
14474 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14477 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14478 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14480 return cc_loc_result;
14483 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14484 for DEBUG_IMPLICIT_PTR RTL. */
14486 static dw_loc_descr_ref
14487 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14489 dw_loc_descr_ref ret;
14494 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14495 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14496 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14497 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14498 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14499 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14502 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14503 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14504 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14508 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14509 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14514 /* Output a proper Dwarf location descriptor for a variable or parameter
14515 which is either allocated in a register or in a memory location. For a
14516 register, we just generate an OP_REG and the register number. For a
14517 memory location we provide a Dwarf postfix expression describing how to
14518 generate the (dynamic) address of the object onto the address stack.
14520 MODE is mode of the decl if this loc_descriptor is going to be used in
14521 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14522 allowed, VOIDmode otherwise.
14524 If we don't know how to describe it, return 0. */
14526 static dw_loc_descr_ref
14527 loc_descriptor (rtx rtl, enum machine_mode mode,
14528 enum var_init_status initialized)
14530 dw_loc_descr_ref loc_result = NULL;
14532 switch (GET_CODE (rtl))
14535 /* The case of a subreg may arise when we have a local (register)
14536 variable or a formal (register) parameter which doesn't quite fill
14537 up an entire register. For now, just assume that it is
14538 legitimate to make the Dwarf info refer to the whole register which
14539 contains the given subreg. */
14540 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14544 loc_result = reg_loc_descriptor (rtl, initialized);
14548 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14550 if (loc_result == NULL)
14551 loc_result = tls_mem_loc_descriptor (rtl);
14552 if (loc_result == NULL)
14554 rtx new_rtl = avoid_constant_pool_reference (rtl);
14555 if (new_rtl != rtl)
14556 loc_result = loc_descriptor (new_rtl, mode, initialized);
14561 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14566 loc_result = concatn_loc_descriptor (rtl, initialized);
14571 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14573 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14574 if (GET_CODE (loc) == EXPR_LIST)
14575 loc = XEXP (loc, 0);
14576 loc_result = loc_descriptor (loc, mode, initialized);
14580 rtl = XEXP (rtl, 1);
14585 rtvec par_elems = XVEC (rtl, 0);
14586 int num_elem = GET_NUM_ELEM (par_elems);
14587 enum machine_mode mode;
14590 /* Create the first one, so we have something to add to. */
14591 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14592 VOIDmode, initialized);
14593 if (loc_result == NULL)
14595 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14596 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14597 for (i = 1; i < num_elem; i++)
14599 dw_loc_descr_ref temp;
14601 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14602 VOIDmode, initialized);
14605 add_loc_descr (&loc_result, temp);
14606 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14607 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14613 if (mode != VOIDmode && mode != BLKmode)
14614 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14619 if (mode == VOIDmode)
14620 mode = GET_MODE (rtl);
14622 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14624 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14626 /* Note that a CONST_DOUBLE rtx could represent either an integer
14627 or a floating-point constant. A CONST_DOUBLE is used whenever
14628 the constant requires more than one word in order to be
14629 adequately represented. We output CONST_DOUBLEs as blocks. */
14630 loc_result = new_loc_descr (DW_OP_implicit_value,
14631 GET_MODE_SIZE (mode), 0);
14632 if (SCALAR_FLOAT_MODE_P (mode))
14634 unsigned int length = GET_MODE_SIZE (mode);
14635 unsigned char *array
14636 = (unsigned char*) ggc_alloc_atomic (length);
14638 insert_float (rtl, array);
14639 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14640 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14641 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14642 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14646 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14647 loc_result->dw_loc_oprnd2.v.val_double
14648 = rtx_to_double_int (rtl);
14654 if (mode == VOIDmode)
14655 mode = GET_MODE (rtl);
14657 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14659 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14660 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14661 unsigned char *array = (unsigned char *)
14662 ggc_alloc_atomic (length * elt_size);
14666 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14667 switch (GET_MODE_CLASS (mode))
14669 case MODE_VECTOR_INT:
14670 for (i = 0, p = array; i < length; i++, p += elt_size)
14672 rtx elt = CONST_VECTOR_ELT (rtl, i);
14673 double_int val = rtx_to_double_int (elt);
14675 if (elt_size <= sizeof (HOST_WIDE_INT))
14676 insert_int (double_int_to_shwi (val), elt_size, p);
14679 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14680 insert_double (val, p);
14685 case MODE_VECTOR_FLOAT:
14686 for (i = 0, p = array; i < length; i++, p += elt_size)
14688 rtx elt = CONST_VECTOR_ELT (rtl, i);
14689 insert_float (elt, p);
14694 gcc_unreachable ();
14697 loc_result = new_loc_descr (DW_OP_implicit_value,
14698 length * elt_size, 0);
14699 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14700 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14701 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14702 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14707 if (mode == VOIDmode
14708 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14709 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14710 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14712 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14717 if (!const_ok_for_output (rtl))
14720 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14721 && (dwarf_version >= 4 || !dwarf_strict))
14723 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14724 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14725 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14726 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14727 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14731 case DEBUG_IMPLICIT_PTR:
14732 loc_result = implicit_ptr_descriptor (rtl, 0);
14736 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14737 && CONST_INT_P (XEXP (rtl, 1)))
14740 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14745 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14746 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14747 && (dwarf_version >= 4 || !dwarf_strict))
14749 /* Value expression. */
14750 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14752 add_loc_descr (&loc_result,
14753 new_loc_descr (DW_OP_stack_value, 0, 0));
14761 /* We need to figure out what section we should use as the base for the
14762 address ranges where a given location is valid.
14763 1. If this particular DECL has a section associated with it, use that.
14764 2. If this function has a section associated with it, use that.
14765 3. Otherwise, use the text section.
14766 XXX: If you split a variable across multiple sections, we won't notice. */
14768 static const char *
14769 secname_for_decl (const_tree decl)
14771 const char *secname;
14773 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14775 tree sectree = DECL_SECTION_NAME (decl);
14776 secname = TREE_STRING_POINTER (sectree);
14778 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14780 tree sectree = DECL_SECTION_NAME (current_function_decl);
14781 secname = TREE_STRING_POINTER (sectree);
14783 else if (cfun && in_cold_section_p)
14784 secname = crtl->subsections.cold_section_label;
14786 secname = text_section_label;
14791 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14794 decl_by_reference_p (tree decl)
14796 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14797 || TREE_CODE (decl) == VAR_DECL)
14798 && DECL_BY_REFERENCE (decl));
14801 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14804 static dw_loc_descr_ref
14805 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14806 enum var_init_status initialized)
14808 int have_address = 0;
14809 dw_loc_descr_ref descr;
14810 enum machine_mode mode;
14812 if (want_address != 2)
14814 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14816 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14818 varloc = PAT_VAR_LOCATION_LOC (varloc);
14819 if (GET_CODE (varloc) == EXPR_LIST)
14820 varloc = XEXP (varloc, 0);
14821 mode = GET_MODE (varloc);
14822 if (MEM_P (varloc))
14824 rtx addr = XEXP (varloc, 0);
14825 descr = mem_loc_descriptor (addr, mode, initialized);
14830 rtx x = avoid_constant_pool_reference (varloc);
14832 descr = mem_loc_descriptor (x, mode, initialized);
14836 descr = mem_loc_descriptor (varloc, mode, initialized);
14843 if (GET_CODE (varloc) == VAR_LOCATION)
14844 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14846 mode = DECL_MODE (loc);
14847 descr = loc_descriptor (varloc, mode, initialized);
14854 if (want_address == 2 && !have_address
14855 && (dwarf_version >= 4 || !dwarf_strict))
14857 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14859 expansion_failed (loc, NULL_RTX,
14860 "DWARF address size mismatch");
14863 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14866 /* Show if we can't fill the request for an address. */
14867 if (want_address && !have_address)
14869 expansion_failed (loc, NULL_RTX,
14870 "Want address and only have value");
14874 /* If we've got an address and don't want one, dereference. */
14875 if (!want_address && have_address)
14877 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14878 enum dwarf_location_atom op;
14880 if (size > DWARF2_ADDR_SIZE || size == -1)
14882 expansion_failed (loc, NULL_RTX,
14883 "DWARF address size mismatch");
14886 else if (size == DWARF2_ADDR_SIZE)
14889 op = DW_OP_deref_size;
14891 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14897 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14898 if it is not possible. */
14900 static dw_loc_descr_ref
14901 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14903 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14904 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14905 else if (dwarf_version >= 3 || !dwarf_strict)
14906 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14911 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14912 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14914 static dw_loc_descr_ref
14915 dw_sra_loc_expr (tree decl, rtx loc)
14918 unsigned int padsize = 0;
14919 dw_loc_descr_ref descr, *descr_tail;
14920 unsigned HOST_WIDE_INT decl_size;
14922 enum var_init_status initialized;
14924 if (DECL_SIZE (decl) == NULL
14925 || !host_integerp (DECL_SIZE (decl), 1))
14928 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14930 descr_tail = &descr;
14932 for (p = loc; p; p = XEXP (p, 1))
14934 unsigned int bitsize = decl_piece_bitsize (p);
14935 rtx loc_note = *decl_piece_varloc_ptr (p);
14936 dw_loc_descr_ref cur_descr;
14937 dw_loc_descr_ref *tail, last = NULL;
14938 unsigned int opsize = 0;
14940 if (loc_note == NULL_RTX
14941 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14943 padsize += bitsize;
14946 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14947 varloc = NOTE_VAR_LOCATION (loc_note);
14948 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14949 if (cur_descr == NULL)
14951 padsize += bitsize;
14955 /* Check that cur_descr either doesn't use
14956 DW_OP_*piece operations, or their sum is equal
14957 to bitsize. Otherwise we can't embed it. */
14958 for (tail = &cur_descr; *tail != NULL;
14959 tail = &(*tail)->dw_loc_next)
14960 if ((*tail)->dw_loc_opc == DW_OP_piece)
14962 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14966 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14968 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14972 if (last != NULL && opsize != bitsize)
14974 padsize += bitsize;
14978 /* If there is a hole, add DW_OP_*piece after empty DWARF
14979 expression, which means that those bits are optimized out. */
14982 if (padsize > decl_size)
14984 decl_size -= padsize;
14985 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14986 if (*descr_tail == NULL)
14988 descr_tail = &(*descr_tail)->dw_loc_next;
14991 *descr_tail = cur_descr;
14993 if (bitsize > decl_size)
14995 decl_size -= bitsize;
14998 HOST_WIDE_INT offset = 0;
14999 if (GET_CODE (varloc) == VAR_LOCATION
15000 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15002 varloc = PAT_VAR_LOCATION_LOC (varloc);
15003 if (GET_CODE (varloc) == EXPR_LIST)
15004 varloc = XEXP (varloc, 0);
15008 if (GET_CODE (varloc) == CONST
15009 || GET_CODE (varloc) == SIGN_EXTEND
15010 || GET_CODE (varloc) == ZERO_EXTEND)
15011 varloc = XEXP (varloc, 0);
15012 else if (GET_CODE (varloc) == SUBREG)
15013 varloc = SUBREG_REG (varloc);
15018 /* DW_OP_bit_size offset should be zero for register
15019 or implicit location descriptions and empty location
15020 descriptions, but for memory addresses needs big endian
15022 if (MEM_P (varloc))
15024 unsigned HOST_WIDE_INT memsize
15025 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
15026 if (memsize != bitsize)
15028 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
15029 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
15031 if (memsize < bitsize)
15033 if (BITS_BIG_ENDIAN)
15034 offset = memsize - bitsize;
15038 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
15039 if (*descr_tail == NULL)
15041 descr_tail = &(*descr_tail)->dw_loc_next;
15045 /* If there were any non-empty expressions, add padding till the end of
15047 if (descr != NULL && decl_size != 0)
15049 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
15050 if (*descr_tail == NULL)
15056 /* Return the dwarf representation of the location list LOC_LIST of
15057 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
15060 static dw_loc_list_ref
15061 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
15063 const char *endname, *secname;
15065 enum var_init_status initialized;
15066 struct var_loc_node *node;
15067 dw_loc_descr_ref descr;
15068 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15069 dw_loc_list_ref list = NULL;
15070 dw_loc_list_ref *listp = &list;
15072 /* Now that we know what section we are using for a base,
15073 actually construct the list of locations.
15074 The first location information is what is passed to the
15075 function that creates the location list, and the remaining
15076 locations just get added on to that list.
15077 Note that we only know the start address for a location
15078 (IE location changes), so to build the range, we use
15079 the range [current location start, next location start].
15080 This means we have to special case the last node, and generate
15081 a range of [last location start, end of function label]. */
15083 secname = secname_for_decl (decl);
15085 for (node = loc_list->first; node; node = node->next)
15086 if (GET_CODE (node->loc) == EXPR_LIST
15087 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
15089 if (GET_CODE (node->loc) == EXPR_LIST)
15091 /* This requires DW_OP_{,bit_}piece, which is not usable
15092 inside DWARF expressions. */
15093 if (want_address != 2)
15095 descr = dw_sra_loc_expr (decl, node->loc);
15101 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15102 varloc = NOTE_VAR_LOCATION (node->loc);
15103 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15107 bool range_across_switch = false;
15108 /* If section switch happens in between node->label
15109 and node->next->label (or end of function) and
15110 we can't emit it as a single entry list,
15111 emit two ranges, first one ending at the end
15112 of first partition and second one starting at the
15113 beginning of second partition. */
15114 if (node == loc_list->last_before_switch
15115 && (node != loc_list->first || loc_list->first->next)
15116 && current_function_decl)
15118 endname = current_fde ()->dw_fde_end;
15119 range_across_switch = true;
15121 /* The variable has a location between NODE->LABEL and
15122 NODE->NEXT->LABEL. */
15123 else if (node->next)
15124 endname = node->next->label;
15125 /* If the variable has a location at the last label
15126 it keeps its location until the end of function. */
15127 else if (!current_function_decl)
15128 endname = text_end_label;
15131 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15132 current_function_funcdef_no);
15133 endname = ggc_strdup (label_id);
15136 *listp = new_loc_list (descr, node->label, endname, secname);
15137 listp = &(*listp)->dw_loc_next;
15139 if (range_across_switch)
15141 if (GET_CODE (node->loc) == EXPR_LIST)
15142 descr = dw_sra_loc_expr (decl, node->loc);
15145 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15146 varloc = NOTE_VAR_LOCATION (node->loc);
15147 descr = dw_loc_list_1 (decl, varloc, want_address,
15150 gcc_assert (descr);
15151 /* The variable has a location between NODE->LABEL and
15152 NODE->NEXT->LABEL. */
15154 endname = node->next->label;
15156 endname = current_fde ()->dw_fde_second_end;
15157 *listp = new_loc_list (descr,
15158 current_fde ()->dw_fde_second_begin,
15160 listp = &(*listp)->dw_loc_next;
15165 /* Try to avoid the overhead of a location list emitting a location
15166 expression instead, but only if we didn't have more than one
15167 location entry in the first place. If some entries were not
15168 representable, we don't want to pretend a single entry that was
15169 applies to the entire scope in which the variable is
15171 if (list && loc_list->first->next)
15177 /* Return if the loc_list has only single element and thus can be represented
15178 as location description. */
15181 single_element_loc_list_p (dw_loc_list_ref list)
15183 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15184 return !list->ll_symbol;
15187 /* To each location in list LIST add loc descr REF. */
15190 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15192 dw_loc_descr_ref copy;
15193 add_loc_descr (&list->expr, ref);
15194 list = list->dw_loc_next;
15197 copy = ggc_alloc_dw_loc_descr_node ();
15198 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15199 add_loc_descr (&list->expr, copy);
15200 while (copy->dw_loc_next)
15202 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15203 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15204 copy->dw_loc_next = new_copy;
15207 list = list->dw_loc_next;
15211 /* Given two lists RET and LIST
15212 produce location list that is result of adding expression in LIST
15213 to expression in RET on each possition in program.
15214 Might be destructive on both RET and LIST.
15216 TODO: We handle only simple cases of RET or LIST having at most one
15217 element. General case would inolve sorting the lists in program order
15218 and merging them that will need some additional work.
15219 Adding that will improve quality of debug info especially for SRA-ed
15223 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15232 if (!list->dw_loc_next)
15234 add_loc_descr_to_each (*ret, list->expr);
15237 if (!(*ret)->dw_loc_next)
15239 add_loc_descr_to_each (list, (*ret)->expr);
15243 expansion_failed (NULL_TREE, NULL_RTX,
15244 "Don't know how to merge two non-trivial"
15245 " location lists.\n");
15250 /* LOC is constant expression. Try a luck, look it up in constant
15251 pool and return its loc_descr of its address. */
15253 static dw_loc_descr_ref
15254 cst_pool_loc_descr (tree loc)
15256 /* Get an RTL for this, if something has been emitted. */
15257 rtx rtl = lookup_constant_def (loc);
15258 enum machine_mode mode;
15260 if (!rtl || !MEM_P (rtl))
15265 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15267 /* TODO: We might get more coverage if we was actually delaying expansion
15268 of all expressions till end of compilation when constant pools are fully
15270 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15272 expansion_failed (loc, NULL_RTX,
15273 "CST value in contant pool but not marked.");
15276 mode = GET_MODE (rtl);
15277 rtl = XEXP (rtl, 0);
15278 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15281 /* Return dw_loc_list representing address of addr_expr LOC
15282 by looking for innder INDIRECT_REF expression and turing it
15283 into simple arithmetics. */
15285 static dw_loc_list_ref
15286 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15289 HOST_WIDE_INT bitsize, bitpos, bytepos;
15290 enum machine_mode mode;
15292 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15293 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15295 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15296 &bitsize, &bitpos, &offset, &mode,
15297 &unsignedp, &volatilep, false);
15299 if (bitpos % BITS_PER_UNIT)
15301 expansion_failed (loc, NULL_RTX, "bitfield access");
15304 if (!INDIRECT_REF_P (obj))
15306 expansion_failed (obj,
15307 NULL_RTX, "no indirect ref in inner refrence");
15310 if (!offset && !bitpos)
15311 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15313 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15314 && (dwarf_version >= 4 || !dwarf_strict))
15316 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15321 /* Variable offset. */
15322 list_ret1 = loc_list_from_tree (offset, 0);
15323 if (list_ret1 == 0)
15325 add_loc_list (&list_ret, list_ret1);
15328 add_loc_descr_to_each (list_ret,
15329 new_loc_descr (DW_OP_plus, 0, 0));
15331 bytepos = bitpos / BITS_PER_UNIT;
15333 add_loc_descr_to_each (list_ret,
15334 new_loc_descr (DW_OP_plus_uconst,
15336 else if (bytepos < 0)
15337 loc_list_plus_const (list_ret, bytepos);
15338 add_loc_descr_to_each (list_ret,
15339 new_loc_descr (DW_OP_stack_value, 0, 0));
15345 /* Generate Dwarf location list representing LOC.
15346 If WANT_ADDRESS is false, expression computing LOC will be computed
15347 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15348 if WANT_ADDRESS is 2, expression computing address useable in location
15349 will be returned (i.e. DW_OP_reg can be used
15350 to refer to register values). */
15352 static dw_loc_list_ref
15353 loc_list_from_tree (tree loc, int want_address)
15355 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15356 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15357 int have_address = 0;
15358 enum dwarf_location_atom op;
15360 /* ??? Most of the time we do not take proper care for sign/zero
15361 extending the values properly. Hopefully this won't be a real
15364 switch (TREE_CODE (loc))
15367 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15370 case PLACEHOLDER_EXPR:
15371 /* This case involves extracting fields from an object to determine the
15372 position of other fields. We don't try to encode this here. The
15373 only user of this is Ada, which encodes the needed information using
15374 the names of types. */
15375 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15379 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15380 /* There are no opcodes for these operations. */
15383 case PREINCREMENT_EXPR:
15384 case PREDECREMENT_EXPR:
15385 case POSTINCREMENT_EXPR:
15386 case POSTDECREMENT_EXPR:
15387 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15388 /* There are no opcodes for these operations. */
15392 /* If we already want an address, see if there is INDIRECT_REF inside
15393 e.g. for &this->field. */
15396 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15397 (loc, want_address == 2);
15400 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15401 && (ret = cst_pool_loc_descr (loc)))
15404 /* Otherwise, process the argument and look for the address. */
15405 if (!list_ret && !ret)
15406 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15410 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15416 if (DECL_THREAD_LOCAL_P (loc))
15419 enum dwarf_location_atom first_op;
15420 enum dwarf_location_atom second_op;
15421 bool dtprel = false;
15423 if (targetm.have_tls)
15425 /* If this is not defined, we have no way to emit the
15427 if (!targetm.asm_out.output_dwarf_dtprel)
15430 /* The way DW_OP_GNU_push_tls_address is specified, we
15431 can only look up addresses of objects in the current
15432 module. We used DW_OP_addr as first op, but that's
15433 wrong, because DW_OP_addr is relocated by the debug
15434 info consumer, while DW_OP_GNU_push_tls_address
15435 operand shouldn't be. */
15436 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15438 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15440 second_op = DW_OP_GNU_push_tls_address;
15444 if (!targetm.emutls.debug_form_tls_address
15445 || !(dwarf_version >= 3 || !dwarf_strict))
15447 /* We stuffed the control variable into the DECL_VALUE_EXPR
15448 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15449 no longer appear in gimple code. We used the control
15450 variable in specific so that we could pick it up here. */
15451 loc = DECL_VALUE_EXPR (loc);
15452 first_op = DW_OP_addr;
15453 second_op = DW_OP_form_tls_address;
15456 rtl = rtl_for_decl_location (loc);
15457 if (rtl == NULL_RTX)
15462 rtl = XEXP (rtl, 0);
15463 if (! CONSTANT_P (rtl))
15466 ret = new_loc_descr (first_op, 0, 0);
15467 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15468 ret->dw_loc_oprnd1.v.val_addr = rtl;
15469 ret->dtprel = dtprel;
15471 ret1 = new_loc_descr (second_op, 0, 0);
15472 add_loc_descr (&ret, ret1);
15481 if (DECL_HAS_VALUE_EXPR_P (loc))
15482 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15486 case FUNCTION_DECL:
15489 var_loc_list *loc_list = lookup_decl_loc (loc);
15491 if (loc_list && loc_list->first)
15493 list_ret = dw_loc_list (loc_list, loc, want_address);
15494 have_address = want_address != 0;
15497 rtl = rtl_for_decl_location (loc);
15498 if (rtl == NULL_RTX)
15500 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15503 else if (CONST_INT_P (rtl))
15505 HOST_WIDE_INT val = INTVAL (rtl);
15506 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15507 val &= GET_MODE_MASK (DECL_MODE (loc));
15508 ret = int_loc_descriptor (val);
15510 else if (GET_CODE (rtl) == CONST_STRING)
15512 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15515 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15517 ret = new_loc_descr (DW_OP_addr, 0, 0);
15518 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15519 ret->dw_loc_oprnd1.v.val_addr = rtl;
15523 enum machine_mode mode;
15525 /* Certain constructs can only be represented at top-level. */
15526 if (want_address == 2)
15528 ret = loc_descriptor (rtl, VOIDmode,
15529 VAR_INIT_STATUS_INITIALIZED);
15534 mode = GET_MODE (rtl);
15537 rtl = XEXP (rtl, 0);
15540 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15543 expansion_failed (loc, rtl,
15544 "failed to produce loc descriptor for rtl");
15551 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15555 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15559 case COMPOUND_EXPR:
15560 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15563 case VIEW_CONVERT_EXPR:
15566 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15568 case COMPONENT_REF:
15569 case BIT_FIELD_REF:
15571 case ARRAY_RANGE_REF:
15572 case REALPART_EXPR:
15573 case IMAGPART_EXPR:
15576 HOST_WIDE_INT bitsize, bitpos, bytepos;
15577 enum machine_mode mode;
15579 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15581 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15582 &unsignedp, &volatilep, false);
15584 gcc_assert (obj != loc);
15586 list_ret = loc_list_from_tree (obj,
15588 && !bitpos && !offset ? 2 : 1);
15589 /* TODO: We can extract value of the small expression via shifting even
15590 for nonzero bitpos. */
15593 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15595 expansion_failed (loc, NULL_RTX,
15596 "bitfield access");
15600 if (offset != NULL_TREE)
15602 /* Variable offset. */
15603 list_ret1 = loc_list_from_tree (offset, 0);
15604 if (list_ret1 == 0)
15606 add_loc_list (&list_ret, list_ret1);
15609 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15612 bytepos = bitpos / BITS_PER_UNIT;
15614 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15615 else if (bytepos < 0)
15616 loc_list_plus_const (list_ret, bytepos);
15623 if ((want_address || !host_integerp (loc, 0))
15624 && (ret = cst_pool_loc_descr (loc)))
15626 else if (want_address == 2
15627 && host_integerp (loc, 0)
15628 && (ret = address_of_int_loc_descriptor
15629 (int_size_in_bytes (TREE_TYPE (loc)),
15630 tree_low_cst (loc, 0))))
15632 else if (host_integerp (loc, 0))
15633 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15636 expansion_failed (loc, NULL_RTX,
15637 "Integer operand is not host integer");
15646 if ((ret = cst_pool_loc_descr (loc)))
15649 /* We can construct small constants here using int_loc_descriptor. */
15650 expansion_failed (loc, NULL_RTX,
15651 "constructor or constant not in constant pool");
15654 case TRUTH_AND_EXPR:
15655 case TRUTH_ANDIF_EXPR:
15660 case TRUTH_XOR_EXPR:
15665 case TRUTH_OR_EXPR:
15666 case TRUTH_ORIF_EXPR:
15671 case FLOOR_DIV_EXPR:
15672 case CEIL_DIV_EXPR:
15673 case ROUND_DIV_EXPR:
15674 case TRUNC_DIV_EXPR:
15675 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15684 case FLOOR_MOD_EXPR:
15685 case CEIL_MOD_EXPR:
15686 case ROUND_MOD_EXPR:
15687 case TRUNC_MOD_EXPR:
15688 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15693 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15694 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15695 if (list_ret == 0 || list_ret1 == 0)
15698 add_loc_list (&list_ret, list_ret1);
15701 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15702 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15703 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15704 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15705 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15717 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15720 case POINTER_PLUS_EXPR:
15722 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15724 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15728 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15736 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15743 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15750 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15757 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15772 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15773 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15774 if (list_ret == 0 || list_ret1 == 0)
15777 add_loc_list (&list_ret, list_ret1);
15780 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15783 case TRUTH_NOT_EXPR:
15797 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15801 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15807 const enum tree_code code =
15808 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15810 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15811 build2 (code, integer_type_node,
15812 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15813 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15816 /* ... fall through ... */
15820 dw_loc_descr_ref lhs
15821 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15822 dw_loc_list_ref rhs
15823 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15824 dw_loc_descr_ref bra_node, jump_node, tmp;
15826 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15827 if (list_ret == 0 || lhs == 0 || rhs == 0)
15830 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15831 add_loc_descr_to_each (list_ret, bra_node);
15833 add_loc_list (&list_ret, rhs);
15834 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15835 add_loc_descr_to_each (list_ret, jump_node);
15837 add_loc_descr_to_each (list_ret, lhs);
15838 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15839 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15841 /* ??? Need a node to point the skip at. Use a nop. */
15842 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15843 add_loc_descr_to_each (list_ret, tmp);
15844 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15845 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15849 case FIX_TRUNC_EXPR:
15853 /* Leave front-end specific codes as simply unknown. This comes
15854 up, for instance, with the C STMT_EXPR. */
15855 if ((unsigned int) TREE_CODE (loc)
15856 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15858 expansion_failed (loc, NULL_RTX,
15859 "language specific tree node");
15863 #ifdef ENABLE_CHECKING
15864 /* Otherwise this is a generic code; we should just lists all of
15865 these explicitly. We forgot one. */
15866 gcc_unreachable ();
15868 /* In a release build, we want to degrade gracefully: better to
15869 generate incomplete debugging information than to crash. */
15874 if (!ret && !list_ret)
15877 if (want_address == 2 && !have_address
15878 && (dwarf_version >= 4 || !dwarf_strict))
15880 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15882 expansion_failed (loc, NULL_RTX,
15883 "DWARF address size mismatch");
15887 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15889 add_loc_descr_to_each (list_ret,
15890 new_loc_descr (DW_OP_stack_value, 0, 0));
15893 /* Show if we can't fill the request for an address. */
15894 if (want_address && !have_address)
15896 expansion_failed (loc, NULL_RTX,
15897 "Want address and only have value");
15901 gcc_assert (!ret || !list_ret);
15903 /* If we've got an address and don't want one, dereference. */
15904 if (!want_address && have_address)
15906 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15908 if (size > DWARF2_ADDR_SIZE || size == -1)
15910 expansion_failed (loc, NULL_RTX,
15911 "DWARF address size mismatch");
15914 else if (size == DWARF2_ADDR_SIZE)
15917 op = DW_OP_deref_size;
15920 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15922 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15925 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15930 /* Same as above but return only single location expression. */
15931 static dw_loc_descr_ref
15932 loc_descriptor_from_tree (tree loc, int want_address)
15934 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15937 if (ret->dw_loc_next)
15939 expansion_failed (loc, NULL_RTX,
15940 "Location list where only loc descriptor needed");
15946 /* Given a value, round it up to the lowest multiple of `boundary'
15947 which is not less than the value itself. */
15949 static inline HOST_WIDE_INT
15950 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15952 return (((value + boundary - 1) / boundary) * boundary);
15955 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15956 pointer to the declared type for the relevant field variable, or return
15957 `integer_type_node' if the given node turns out to be an
15958 ERROR_MARK node. */
15961 field_type (const_tree decl)
15965 if (TREE_CODE (decl) == ERROR_MARK)
15966 return integer_type_node;
15968 type = DECL_BIT_FIELD_TYPE (decl);
15969 if (type == NULL_TREE)
15970 type = TREE_TYPE (decl);
15975 /* Given a pointer to a tree node, return the alignment in bits for
15976 it, or else return BITS_PER_WORD if the node actually turns out to
15977 be an ERROR_MARK node. */
15979 static inline unsigned
15980 simple_type_align_in_bits (const_tree type)
15982 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15985 static inline unsigned
15986 simple_decl_align_in_bits (const_tree decl)
15988 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15991 /* Return the result of rounding T up to ALIGN. */
15993 static inline double_int
15994 round_up_to_align (double_int t, unsigned int align)
15996 double_int alignd = uhwi_to_double_int (align);
15997 t = double_int_add (t, alignd);
15998 t = double_int_add (t, double_int_minus_one);
15999 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
16000 t = double_int_mul (t, alignd);
16004 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
16005 lowest addressed byte of the "containing object" for the given FIELD_DECL,
16006 or return 0 if we are unable to determine what that offset is, either
16007 because the argument turns out to be a pointer to an ERROR_MARK node, or
16008 because the offset is actually variable. (We can't handle the latter case
16011 static HOST_WIDE_INT
16012 field_byte_offset (const_tree decl)
16014 double_int object_offset_in_bits;
16015 double_int object_offset_in_bytes;
16016 double_int bitpos_int;
16018 if (TREE_CODE (decl) == ERROR_MARK)
16021 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
16023 /* We cannot yet cope with fields whose positions are variable, so
16024 for now, when we see such things, we simply return 0. Someday, we may
16025 be able to handle such cases, but it will be damn difficult. */
16026 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
16029 bitpos_int = tree_to_double_int (bit_position (decl));
16031 #ifdef PCC_BITFIELD_TYPE_MATTERS
16032 if (PCC_BITFIELD_TYPE_MATTERS)
16035 tree field_size_tree;
16036 double_int deepest_bitpos;
16037 double_int field_size_in_bits;
16038 unsigned int type_align_in_bits;
16039 unsigned int decl_align_in_bits;
16040 double_int type_size_in_bits;
16042 type = field_type (decl);
16043 type_size_in_bits = double_int_type_size_in_bits (type);
16044 type_align_in_bits = simple_type_align_in_bits (type);
16046 field_size_tree = DECL_SIZE (decl);
16048 /* The size could be unspecified if there was an error, or for
16049 a flexible array member. */
16050 if (!field_size_tree)
16051 field_size_tree = bitsize_zero_node;
16053 /* If the size of the field is not constant, use the type size. */
16054 if (TREE_CODE (field_size_tree) == INTEGER_CST)
16055 field_size_in_bits = tree_to_double_int (field_size_tree);
16057 field_size_in_bits = type_size_in_bits;
16059 decl_align_in_bits = simple_decl_align_in_bits (decl);
16061 /* The GCC front-end doesn't make any attempt to keep track of the
16062 starting bit offset (relative to the start of the containing
16063 structure type) of the hypothetical "containing object" for a
16064 bit-field. Thus, when computing the byte offset value for the
16065 start of the "containing object" of a bit-field, we must deduce
16066 this information on our own. This can be rather tricky to do in
16067 some cases. For example, handling the following structure type
16068 definition when compiling for an i386/i486 target (which only
16069 aligns long long's to 32-bit boundaries) can be very tricky:
16071 struct S { int field1; long long field2:31; };
16073 Fortunately, there is a simple rule-of-thumb which can be used
16074 in such cases. When compiling for an i386/i486, GCC will
16075 allocate 8 bytes for the structure shown above. It decides to
16076 do this based upon one simple rule for bit-field allocation.
16077 GCC allocates each "containing object" for each bit-field at
16078 the first (i.e. lowest addressed) legitimate alignment boundary
16079 (based upon the required minimum alignment for the declared
16080 type of the field) which it can possibly use, subject to the
16081 condition that there is still enough available space remaining
16082 in the containing object (when allocated at the selected point)
16083 to fully accommodate all of the bits of the bit-field itself.
16085 This simple rule makes it obvious why GCC allocates 8 bytes for
16086 each object of the structure type shown above. When looking
16087 for a place to allocate the "containing object" for `field2',
16088 the compiler simply tries to allocate a 64-bit "containing
16089 object" at each successive 32-bit boundary (starting at zero)
16090 until it finds a place to allocate that 64- bit field such that
16091 at least 31 contiguous (and previously unallocated) bits remain
16092 within that selected 64 bit field. (As it turns out, for the
16093 example above, the compiler finds it is OK to allocate the
16094 "containing object" 64-bit field at bit-offset zero within the
16097 Here we attempt to work backwards from the limited set of facts
16098 we're given, and we try to deduce from those facts, where GCC
16099 must have believed that the containing object started (within
16100 the structure type). The value we deduce is then used (by the
16101 callers of this routine) to generate DW_AT_location and
16102 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16103 the case of DW_AT_location, regular fields as well). */
16105 /* Figure out the bit-distance from the start of the structure to
16106 the "deepest" bit of the bit-field. */
16107 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16109 /* This is the tricky part. Use some fancy footwork to deduce
16110 where the lowest addressed bit of the containing object must
16112 object_offset_in_bits
16113 = double_int_sub (deepest_bitpos, type_size_in_bits);
16115 /* Round up to type_align by default. This works best for
16117 object_offset_in_bits
16118 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16120 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16122 object_offset_in_bits
16123 = double_int_sub (deepest_bitpos, type_size_in_bits);
16125 /* Round up to decl_align instead. */
16126 object_offset_in_bits
16127 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16131 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16132 object_offset_in_bits = bitpos_int;
16134 object_offset_in_bytes
16135 = double_int_div (object_offset_in_bits,
16136 uhwi_to_double_int (BITS_PER_UNIT), true,
16138 return double_int_to_shwi (object_offset_in_bytes);
16141 /* The following routines define various Dwarf attributes and any data
16142 associated with them. */
16144 /* Add a location description attribute value to a DIE.
16146 This emits location attributes suitable for whole variables and
16147 whole parameters. Note that the location attributes for struct fields are
16148 generated by the routine `data_member_location_attribute' below. */
16151 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16152 dw_loc_list_ref descr)
16156 if (single_element_loc_list_p (descr))
16157 add_AT_loc (die, attr_kind, descr->expr);
16159 add_AT_loc_list (die, attr_kind, descr);
16162 /* Add DW_AT_accessibility attribute to DIE if needed. */
16165 add_accessibility_attribute (dw_die_ref die, tree decl)
16167 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16168 children, otherwise the default is DW_ACCESS_public. In DWARF2
16169 the default has always been DW_ACCESS_public. */
16170 if (TREE_PROTECTED (decl))
16171 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16172 else if (TREE_PRIVATE (decl))
16174 if (dwarf_version == 2
16175 || die->die_parent == NULL
16176 || die->die_parent->die_tag != DW_TAG_class_type)
16177 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16179 else if (dwarf_version > 2
16181 && die->die_parent->die_tag == DW_TAG_class_type)
16182 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16185 /* Attach the specialized form of location attribute used for data members of
16186 struct and union types. In the special case of a FIELD_DECL node which
16187 represents a bit-field, the "offset" part of this special location
16188 descriptor must indicate the distance in bytes from the lowest-addressed
16189 byte of the containing struct or union type to the lowest-addressed byte of
16190 the "containing object" for the bit-field. (See the `field_byte_offset'
16193 For any given bit-field, the "containing object" is a hypothetical object
16194 (of some integral or enum type) within which the given bit-field lives. The
16195 type of this hypothetical "containing object" is always the same as the
16196 declared type of the individual bit-field itself (for GCC anyway... the
16197 DWARF spec doesn't actually mandate this). Note that it is the size (in
16198 bytes) of the hypothetical "containing object" which will be given in the
16199 DW_AT_byte_size attribute for this bit-field. (See the
16200 `byte_size_attribute' function below.) It is also used when calculating the
16201 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16202 function below.) */
16205 add_data_member_location_attribute (dw_die_ref die, tree decl)
16207 HOST_WIDE_INT offset;
16208 dw_loc_descr_ref loc_descr = 0;
16210 if (TREE_CODE (decl) == TREE_BINFO)
16212 /* We're working on the TAG_inheritance for a base class. */
16213 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16215 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16216 aren't at a fixed offset from all (sub)objects of the same
16217 type. We need to extract the appropriate offset from our
16218 vtable. The following dwarf expression means
16220 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16222 This is specific to the V3 ABI, of course. */
16224 dw_loc_descr_ref tmp;
16226 /* Make a copy of the object address. */
16227 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16228 add_loc_descr (&loc_descr, tmp);
16230 /* Extract the vtable address. */
16231 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16232 add_loc_descr (&loc_descr, tmp);
16234 /* Calculate the address of the offset. */
16235 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16236 gcc_assert (offset < 0);
16238 tmp = int_loc_descriptor (-offset);
16239 add_loc_descr (&loc_descr, tmp);
16240 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16241 add_loc_descr (&loc_descr, tmp);
16243 /* Extract the offset. */
16244 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16245 add_loc_descr (&loc_descr, tmp);
16247 /* Add it to the object address. */
16248 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16249 add_loc_descr (&loc_descr, tmp);
16252 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16255 offset = field_byte_offset (decl);
16259 if (dwarf_version > 2)
16261 /* Don't need to output a location expression, just the constant. */
16263 add_AT_int (die, DW_AT_data_member_location, offset);
16265 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16270 enum dwarf_location_atom op;
16272 /* The DWARF2 standard says that we should assume that the structure
16273 address is already on the stack, so we can specify a structure
16274 field address by using DW_OP_plus_uconst. */
16276 #ifdef MIPS_DEBUGGING_INFO
16277 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16278 operator correctly. It works only if we leave the offset on the
16282 op = DW_OP_plus_uconst;
16285 loc_descr = new_loc_descr (op, offset, 0);
16289 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16292 /* Writes integer values to dw_vec_const array. */
16295 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16299 *dest++ = val & 0xff;
16305 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16307 static HOST_WIDE_INT
16308 extract_int (const unsigned char *src, unsigned int size)
16310 HOST_WIDE_INT val = 0;
16316 val |= *--src & 0xff;
16322 /* Writes double_int values to dw_vec_const array. */
16325 insert_double (double_int val, unsigned char *dest)
16327 unsigned char *p0 = dest;
16328 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16330 if (WORDS_BIG_ENDIAN)
16336 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16337 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16340 /* Writes floating point values to dw_vec_const array. */
16343 insert_float (const_rtx rtl, unsigned char *array)
16345 REAL_VALUE_TYPE rv;
16349 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16350 real_to_target (val, &rv, GET_MODE (rtl));
16352 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16353 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16355 insert_int (val[i], 4, array);
16360 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16361 does not have a "location" either in memory or in a register. These
16362 things can arise in GNU C when a constant is passed as an actual parameter
16363 to an inlined function. They can also arise in C++ where declared
16364 constants do not necessarily get memory "homes". */
16367 add_const_value_attribute (dw_die_ref die, rtx rtl)
16369 switch (GET_CODE (rtl))
16373 HOST_WIDE_INT val = INTVAL (rtl);
16376 add_AT_int (die, DW_AT_const_value, val);
16378 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16383 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16384 floating-point constant. A CONST_DOUBLE is used whenever the
16385 constant requires more than one word in order to be adequately
16388 enum machine_mode mode = GET_MODE (rtl);
16390 if (SCALAR_FLOAT_MODE_P (mode))
16392 unsigned int length = GET_MODE_SIZE (mode);
16393 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16395 insert_float (rtl, array);
16396 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16399 add_AT_double (die, DW_AT_const_value,
16400 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16406 enum machine_mode mode = GET_MODE (rtl);
16407 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16408 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16409 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16410 (length * elt_size);
16414 switch (GET_MODE_CLASS (mode))
16416 case MODE_VECTOR_INT:
16417 for (i = 0, p = array; i < length; i++, p += elt_size)
16419 rtx elt = CONST_VECTOR_ELT (rtl, i);
16420 double_int val = rtx_to_double_int (elt);
16422 if (elt_size <= sizeof (HOST_WIDE_INT))
16423 insert_int (double_int_to_shwi (val), elt_size, p);
16426 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16427 insert_double (val, p);
16432 case MODE_VECTOR_FLOAT:
16433 for (i = 0, p = array; i < length; i++, p += elt_size)
16435 rtx elt = CONST_VECTOR_ELT (rtl, i);
16436 insert_float (elt, p);
16441 gcc_unreachable ();
16444 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16449 if (dwarf_version >= 4 || !dwarf_strict)
16451 dw_loc_descr_ref loc_result;
16452 resolve_one_addr (&rtl, NULL);
16454 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16455 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16456 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16457 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16458 add_AT_loc (die, DW_AT_location, loc_result);
16459 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16465 if (CONSTANT_P (XEXP (rtl, 0)))
16466 return add_const_value_attribute (die, XEXP (rtl, 0));
16469 if (!const_ok_for_output (rtl))
16472 if (dwarf_version >= 4 || !dwarf_strict)
16477 /* In cases where an inlined instance of an inline function is passed
16478 the address of an `auto' variable (which is local to the caller) we
16479 can get a situation where the DECL_RTL of the artificial local
16480 variable (for the inlining) which acts as a stand-in for the
16481 corresponding formal parameter (of the inline function) will look
16482 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16483 exactly a compile-time constant expression, but it isn't the address
16484 of the (artificial) local variable either. Rather, it represents the
16485 *value* which the artificial local variable always has during its
16486 lifetime. We currently have no way to represent such quasi-constant
16487 values in Dwarf, so for now we just punt and generate nothing. */
16495 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16496 && MEM_READONLY_P (rtl)
16497 && GET_MODE (rtl) == BLKmode)
16499 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16505 /* No other kinds of rtx should be possible here. */
16506 gcc_unreachable ();
16511 /* Determine whether the evaluation of EXPR references any variables
16512 or functions which aren't otherwise used (and therefore may not be
16515 reference_to_unused (tree * tp, int * walk_subtrees,
16516 void * data ATTRIBUTE_UNUSED)
16518 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16519 *walk_subtrees = 0;
16521 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16522 && ! TREE_ASM_WRITTEN (*tp))
16524 /* ??? The C++ FE emits debug information for using decls, so
16525 putting gcc_unreachable here falls over. See PR31899. For now
16526 be conservative. */
16527 else if (!cgraph_global_info_ready
16528 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16530 else if (TREE_CODE (*tp) == VAR_DECL)
16532 struct varpool_node *node = varpool_get_node (*tp);
16533 if (!node || !node->needed)
16536 else if (TREE_CODE (*tp) == FUNCTION_DECL
16537 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16539 /* The call graph machinery must have finished analyzing,
16540 optimizing and gimplifying the CU by now.
16541 So if *TP has no call graph node associated
16542 to it, it means *TP will not be emitted. */
16543 if (!cgraph_get_node (*tp))
16546 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16552 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16553 for use in a later add_const_value_attribute call. */
16556 rtl_for_decl_init (tree init, tree type)
16558 rtx rtl = NULL_RTX;
16562 /* If a variable is initialized with a string constant without embedded
16563 zeros, build CONST_STRING. */
16564 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16566 tree enttype = TREE_TYPE (type);
16567 tree domain = TYPE_DOMAIN (type);
16568 enum machine_mode mode = TYPE_MODE (enttype);
16570 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16572 && integer_zerop (TYPE_MIN_VALUE (domain))
16573 && compare_tree_int (TYPE_MAX_VALUE (domain),
16574 TREE_STRING_LENGTH (init) - 1) == 0
16575 && ((size_t) TREE_STRING_LENGTH (init)
16576 == strlen (TREE_STRING_POINTER (init)) + 1))
16578 rtl = gen_rtx_CONST_STRING (VOIDmode,
16579 ggc_strdup (TREE_STRING_POINTER (init)));
16580 rtl = gen_rtx_MEM (BLKmode, rtl);
16581 MEM_READONLY_P (rtl) = 1;
16584 /* Other aggregates, and complex values, could be represented using
16586 else if (AGGREGATE_TYPE_P (type)
16587 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
16588 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
16589 || TREE_CODE (type) == COMPLEX_TYPE)
16591 /* Vectors only work if their mode is supported by the target.
16592 FIXME: generic vectors ought to work too. */
16593 else if (TREE_CODE (type) == VECTOR_TYPE
16594 && !VECTOR_MODE_P (TYPE_MODE (type)))
16596 /* If the initializer is something that we know will expand into an
16597 immediate RTL constant, expand it now. We must be careful not to
16598 reference variables which won't be output. */
16599 else if (initializer_constant_valid_p (init, type)
16600 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16602 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16604 if (TREE_CODE (type) == VECTOR_TYPE)
16605 switch (TREE_CODE (init))
16610 if (TREE_CONSTANT (init))
16612 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16613 bool constant_p = true;
16615 unsigned HOST_WIDE_INT ix;
16617 /* Even when ctor is constant, it might contain non-*_CST
16618 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16619 belong into VECTOR_CST nodes. */
16620 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16621 if (!CONSTANT_CLASS_P (value))
16623 constant_p = false;
16629 init = build_vector_from_ctor (type, elts);
16639 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16641 /* If expand_expr returns a MEM, it wasn't immediate. */
16642 gcc_assert (!rtl || !MEM_P (rtl));
16648 /* Generate RTL for the variable DECL to represent its location. */
16651 rtl_for_decl_location (tree decl)
16655 /* Here we have to decide where we are going to say the parameter "lives"
16656 (as far as the debugger is concerned). We only have a couple of
16657 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16659 DECL_RTL normally indicates where the parameter lives during most of the
16660 activation of the function. If optimization is enabled however, this
16661 could be either NULL or else a pseudo-reg. Both of those cases indicate
16662 that the parameter doesn't really live anywhere (as far as the code
16663 generation parts of GCC are concerned) during most of the function's
16664 activation. That will happen (for example) if the parameter is never
16665 referenced within the function.
16667 We could just generate a location descriptor here for all non-NULL
16668 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16669 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16670 where DECL_RTL is NULL or is a pseudo-reg.
16672 Note however that we can only get away with using DECL_INCOMING_RTL as
16673 a backup substitute for DECL_RTL in certain limited cases. In cases
16674 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16675 we can be sure that the parameter was passed using the same type as it is
16676 declared to have within the function, and that its DECL_INCOMING_RTL
16677 points us to a place where a value of that type is passed.
16679 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16680 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16681 because in these cases DECL_INCOMING_RTL points us to a value of some
16682 type which is *different* from the type of the parameter itself. Thus,
16683 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16684 such cases, the debugger would end up (for example) trying to fetch a
16685 `float' from a place which actually contains the first part of a
16686 `double'. That would lead to really incorrect and confusing
16687 output at debug-time.
16689 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16690 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16691 are a couple of exceptions however. On little-endian machines we can
16692 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16693 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16694 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16695 when (on a little-endian machine) a non-prototyped function has a
16696 parameter declared to be of type `short' or `char'. In such cases,
16697 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16698 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16699 passed `int' value. If the debugger then uses that address to fetch
16700 a `short' or a `char' (on a little-endian machine) the result will be
16701 the correct data, so we allow for such exceptional cases below.
16703 Note that our goal here is to describe the place where the given formal
16704 parameter lives during most of the function's activation (i.e. between the
16705 end of the prologue and the start of the epilogue). We'll do that as best
16706 as we can. Note however that if the given formal parameter is modified
16707 sometime during the execution of the function, then a stack backtrace (at
16708 debug-time) will show the function as having been called with the *new*
16709 value rather than the value which was originally passed in. This happens
16710 rarely enough that it is not a major problem, but it *is* a problem, and
16711 I'd like to fix it.
16713 A future version of dwarf2out.c may generate two additional attributes for
16714 any given DW_TAG_formal_parameter DIE which will describe the "passed
16715 type" and the "passed location" for the given formal parameter in addition
16716 to the attributes we now generate to indicate the "declared type" and the
16717 "active location" for each parameter. This additional set of attributes
16718 could be used by debuggers for stack backtraces. Separately, note that
16719 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16720 This happens (for example) for inlined-instances of inline function formal
16721 parameters which are never referenced. This really shouldn't be
16722 happening. All PARM_DECL nodes should get valid non-NULL
16723 DECL_INCOMING_RTL values. FIXME. */
16725 /* Use DECL_RTL as the "location" unless we find something better. */
16726 rtl = DECL_RTL_IF_SET (decl);
16728 /* When generating abstract instances, ignore everything except
16729 constants, symbols living in memory, and symbols living in
16730 fixed registers. */
16731 if (! reload_completed)
16734 && (CONSTANT_P (rtl)
16736 && CONSTANT_P (XEXP (rtl, 0)))
16738 && TREE_CODE (decl) == VAR_DECL
16739 && TREE_STATIC (decl))))
16741 rtl = targetm.delegitimize_address (rtl);
16746 else if (TREE_CODE (decl) == PARM_DECL)
16748 if (rtl == NULL_RTX
16749 || is_pseudo_reg (rtl)
16751 && is_pseudo_reg (XEXP (rtl, 0))
16752 && DECL_INCOMING_RTL (decl)
16753 && MEM_P (DECL_INCOMING_RTL (decl))
16754 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
16756 tree declared_type = TREE_TYPE (decl);
16757 tree passed_type = DECL_ARG_TYPE (decl);
16758 enum machine_mode dmode = TYPE_MODE (declared_type);
16759 enum machine_mode pmode = TYPE_MODE (passed_type);
16761 /* This decl represents a formal parameter which was optimized out.
16762 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16763 all cases where (rtl == NULL_RTX) just below. */
16764 if (dmode == pmode)
16765 rtl = DECL_INCOMING_RTL (decl);
16766 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
16767 && SCALAR_INT_MODE_P (dmode)
16768 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16769 && DECL_INCOMING_RTL (decl))
16771 rtx inc = DECL_INCOMING_RTL (decl);
16774 else if (MEM_P (inc))
16776 if (BYTES_BIG_ENDIAN)
16777 rtl = adjust_address_nv (inc, dmode,
16778 GET_MODE_SIZE (pmode)
16779 - GET_MODE_SIZE (dmode));
16786 /* If the parm was passed in registers, but lives on the stack, then
16787 make a big endian correction if the mode of the type of the
16788 parameter is not the same as the mode of the rtl. */
16789 /* ??? This is the same series of checks that are made in dbxout.c before
16790 we reach the big endian correction code there. It isn't clear if all
16791 of these checks are necessary here, but keeping them all is the safe
16793 else if (MEM_P (rtl)
16794 && XEXP (rtl, 0) != const0_rtx
16795 && ! CONSTANT_P (XEXP (rtl, 0))
16796 /* Not passed in memory. */
16797 && !MEM_P (DECL_INCOMING_RTL (decl))
16798 /* Not passed by invisible reference. */
16799 && (!REG_P (XEXP (rtl, 0))
16800 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16801 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16802 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16803 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16806 /* Big endian correction check. */
16807 && BYTES_BIG_ENDIAN
16808 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16809 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16812 int offset = (UNITS_PER_WORD
16813 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16815 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16816 plus_constant (XEXP (rtl, 0), offset));
16819 else if (TREE_CODE (decl) == VAR_DECL
16822 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16823 && BYTES_BIG_ENDIAN)
16825 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16826 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16828 /* If a variable is declared "register" yet is smaller than
16829 a register, then if we store the variable to memory, it
16830 looks like we're storing a register-sized value, when in
16831 fact we are not. We need to adjust the offset of the
16832 storage location to reflect the actual value's bytes,
16833 else gdb will not be able to display it. */
16835 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16836 plus_constant (XEXP (rtl, 0), rsize-dsize));
16839 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16840 and will have been substituted directly into all expressions that use it.
16841 C does not have such a concept, but C++ and other languages do. */
16842 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16843 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16846 rtl = targetm.delegitimize_address (rtl);
16848 /* If we don't look past the constant pool, we risk emitting a
16849 reference to a constant pool entry that isn't referenced from
16850 code, and thus is not emitted. */
16852 rtl = avoid_constant_pool_reference (rtl);
16854 /* Try harder to get a rtl. If this symbol ends up not being emitted
16855 in the current CU, resolve_addr will remove the expression referencing
16857 if (rtl == NULL_RTX
16858 && TREE_CODE (decl) == VAR_DECL
16859 && !DECL_EXTERNAL (decl)
16860 && TREE_STATIC (decl)
16861 && DECL_NAME (decl)
16862 && !DECL_HARD_REGISTER (decl)
16863 && DECL_MODE (decl) != VOIDmode)
16865 rtl = make_decl_rtl_for_debug (decl);
16867 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16868 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16875 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16876 returned. If so, the decl for the COMMON block is returned, and the
16877 value is the offset into the common block for the symbol. */
16880 fortran_common (tree decl, HOST_WIDE_INT *value)
16882 tree val_expr, cvar;
16883 enum machine_mode mode;
16884 HOST_WIDE_INT bitsize, bitpos;
16886 int volatilep = 0, unsignedp = 0;
16888 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16889 it does not have a value (the offset into the common area), or if it
16890 is thread local (as opposed to global) then it isn't common, and shouldn't
16891 be handled as such. */
16892 if (TREE_CODE (decl) != VAR_DECL
16893 || !TREE_STATIC (decl)
16894 || !DECL_HAS_VALUE_EXPR_P (decl)
16898 val_expr = DECL_VALUE_EXPR (decl);
16899 if (TREE_CODE (val_expr) != COMPONENT_REF)
16902 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16903 &mode, &unsignedp, &volatilep, true);
16905 if (cvar == NULL_TREE
16906 || TREE_CODE (cvar) != VAR_DECL
16907 || DECL_ARTIFICIAL (cvar)
16908 || !TREE_PUBLIC (cvar))
16912 if (offset != NULL)
16914 if (!host_integerp (offset, 0))
16916 *value = tree_low_cst (offset, 0);
16919 *value += bitpos / BITS_PER_UNIT;
16924 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16925 data attribute for a variable or a parameter. We generate the
16926 DW_AT_const_value attribute only in those cases where the given variable
16927 or parameter does not have a true "location" either in memory or in a
16928 register. This can happen (for example) when a constant is passed as an
16929 actual argument in a call to an inline function. (It's possible that
16930 these things can crop up in other ways also.) Note that one type of
16931 constant value which can be passed into an inlined function is a constant
16932 pointer. This can happen for example if an actual argument in an inlined
16933 function call evaluates to a compile-time constant address.
16935 CACHE_P is true if it is worth caching the location list for DECL,
16936 so that future calls can reuse it rather than regenerate it from scratch.
16937 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16938 since we will need to refer to them each time the function is inlined. */
16941 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
16942 enum dwarf_attribute attr)
16945 dw_loc_list_ref list;
16946 var_loc_list *loc_list;
16947 cached_dw_loc_list *cache;
16950 if (TREE_CODE (decl) == ERROR_MARK)
16953 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16954 || TREE_CODE (decl) == RESULT_DECL);
16956 /* Try to get some constant RTL for this decl, and use that as the value of
16959 rtl = rtl_for_decl_location (decl);
16960 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16961 && add_const_value_attribute (die, rtl))
16964 /* See if we have single element location list that is equivalent to
16965 a constant value. That way we are better to use add_const_value_attribute
16966 rather than expanding constant value equivalent. */
16967 loc_list = lookup_decl_loc (decl);
16970 && loc_list->first->next == NULL
16971 && NOTE_P (loc_list->first->loc)
16972 && NOTE_VAR_LOCATION (loc_list->first->loc)
16973 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16975 struct var_loc_node *node;
16977 node = loc_list->first;
16978 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16979 if (GET_CODE (rtl) == EXPR_LIST)
16980 rtl = XEXP (rtl, 0);
16981 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16982 && add_const_value_attribute (die, rtl))
16985 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16986 list several times. See if we've already cached the contents. */
16988 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
16992 cache = (cached_dw_loc_list *)
16993 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
16995 list = cache->loc_list;
16999 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
17000 /* It is usually worth caching this result if the decl is from
17001 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
17002 if (cache_p && list && list->dw_loc_next)
17004 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
17005 DECL_UID (decl), INSERT);
17006 cache = ggc_alloc_cleared_cached_dw_loc_list ();
17007 cache->decl_id = DECL_UID (decl);
17008 cache->loc_list = list;
17014 add_AT_location_description (die, attr, list);
17017 /* None of that worked, so it must not really have a location;
17018 try adding a constant value attribute from the DECL_INITIAL. */
17019 return tree_add_const_value_attribute_for_decl (die, decl);
17022 /* Add VARIABLE and DIE into deferred locations list. */
17025 defer_location (tree variable, dw_die_ref die)
17027 deferred_locations entry;
17028 entry.variable = variable;
17030 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
17033 /* Helper function for tree_add_const_value_attribute. Natively encode
17034 initializer INIT into an array. Return true if successful. */
17037 native_encode_initializer (tree init, unsigned char *array, int size)
17041 if (init == NULL_TREE)
17045 switch (TREE_CODE (init))
17048 type = TREE_TYPE (init);
17049 if (TREE_CODE (type) == ARRAY_TYPE)
17051 tree enttype = TREE_TYPE (type);
17052 enum machine_mode mode = TYPE_MODE (enttype);
17054 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
17056 if (int_size_in_bytes (type) != size)
17058 if (size > TREE_STRING_LENGTH (init))
17060 memcpy (array, TREE_STRING_POINTER (init),
17061 TREE_STRING_LENGTH (init));
17062 memset (array + TREE_STRING_LENGTH (init),
17063 '\0', size - TREE_STRING_LENGTH (init));
17066 memcpy (array, TREE_STRING_POINTER (init), size);
17071 type = TREE_TYPE (init);
17072 if (int_size_in_bytes (type) != size)
17074 if (TREE_CODE (type) == ARRAY_TYPE)
17076 HOST_WIDE_INT min_index;
17077 unsigned HOST_WIDE_INT cnt;
17078 int curpos = 0, fieldsize;
17079 constructor_elt *ce;
17081 if (TYPE_DOMAIN (type) == NULL_TREE
17082 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
17085 fieldsize = int_size_in_bytes (TREE_TYPE (type));
17086 if (fieldsize <= 0)
17089 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
17090 memset (array, '\0', size);
17091 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17093 tree val = ce->value;
17094 tree index = ce->index;
17096 if (index && TREE_CODE (index) == RANGE_EXPR)
17097 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
17100 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
17105 if (!native_encode_initializer (val, array + pos, fieldsize))
17108 curpos = pos + fieldsize;
17109 if (index && TREE_CODE (index) == RANGE_EXPR)
17111 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17112 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17116 memcpy (array + curpos, array + pos, fieldsize);
17117 curpos += fieldsize;
17120 gcc_assert (curpos <= size);
17124 else if (TREE_CODE (type) == RECORD_TYPE
17125 || TREE_CODE (type) == UNION_TYPE)
17127 tree field = NULL_TREE;
17128 unsigned HOST_WIDE_INT cnt;
17129 constructor_elt *ce;
17131 if (int_size_in_bytes (type) != size)
17134 if (TREE_CODE (type) == RECORD_TYPE)
17135 field = TYPE_FIELDS (type);
17137 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17139 tree val = ce->value;
17140 int pos, fieldsize;
17142 if (ce->index != 0)
17148 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17151 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17152 && TYPE_DOMAIN (TREE_TYPE (field))
17153 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17155 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17156 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17158 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17159 pos = int_byte_position (field);
17160 gcc_assert (pos + fieldsize <= size);
17162 && !native_encode_initializer (val, array + pos, fieldsize))
17168 case VIEW_CONVERT_EXPR:
17169 case NON_LVALUE_EXPR:
17170 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17172 return native_encode_expr (init, array, size) == size;
17176 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17177 attribute is the const value T. */
17180 tree_add_const_value_attribute (dw_die_ref die, tree t)
17183 tree type = TREE_TYPE (t);
17186 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17190 gcc_assert (!DECL_P (init));
17192 rtl = rtl_for_decl_init (init, type);
17194 return add_const_value_attribute (die, rtl);
17195 /* If the host and target are sane, try harder. */
17196 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17197 && initializer_constant_valid_p (init, type))
17199 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17200 if (size > 0 && (int) size == size)
17202 unsigned char *array = (unsigned char *)
17203 ggc_alloc_cleared_atomic (size);
17205 if (native_encode_initializer (init, array, size))
17207 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17215 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17216 attribute is the const value of T, where T is an integral constant
17217 variable with static storage duration
17218 (so it can't be a PARM_DECL or a RESULT_DECL). */
17221 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17225 || (TREE_CODE (decl) != VAR_DECL
17226 && TREE_CODE (decl) != CONST_DECL))
17229 if (TREE_READONLY (decl)
17230 && ! TREE_THIS_VOLATILE (decl)
17231 && DECL_INITIAL (decl))
17236 /* Don't add DW_AT_const_value if abstract origin already has one. */
17237 if (get_AT (var_die, DW_AT_const_value))
17240 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17243 /* Convert the CFI instructions for the current function into a
17244 location list. This is used for DW_AT_frame_base when we targeting
17245 a dwarf2 consumer that does not support the dwarf3
17246 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17249 static dw_loc_list_ref
17250 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17253 dw_loc_list_ref list, *list_tail;
17255 dw_cfa_location last_cfa, next_cfa;
17256 const char *start_label, *last_label, *section;
17257 dw_cfa_location remember;
17259 fde = current_fde ();
17260 gcc_assert (fde != NULL);
17262 section = secname_for_decl (current_function_decl);
17266 memset (&next_cfa, 0, sizeof (next_cfa));
17267 next_cfa.reg = INVALID_REGNUM;
17268 remember = next_cfa;
17270 start_label = fde->dw_fde_begin;
17272 /* ??? Bald assumption that the CIE opcode list does not contain
17273 advance opcodes. */
17274 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
17275 lookup_cfa_1 (cfi, &next_cfa, &remember);
17277 last_cfa = next_cfa;
17278 last_label = start_label;
17280 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi == NULL)
17282 /* If the first partition contained no CFI adjustments, the
17283 CIE opcodes apply to the whole first partition. */
17284 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17285 fde->dw_fde_begin, fde->dw_fde_end, section);
17286 list_tail =&(*list_tail)->dw_loc_next;
17287 start_label = last_label = fde->dw_fde_second_begin;
17290 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17292 switch (cfi->dw_cfi_opc)
17294 case DW_CFA_set_loc:
17295 case DW_CFA_advance_loc1:
17296 case DW_CFA_advance_loc2:
17297 case DW_CFA_advance_loc4:
17298 if (!cfa_equal_p (&last_cfa, &next_cfa))
17300 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17301 start_label, last_label, section);
17303 list_tail = &(*list_tail)->dw_loc_next;
17304 last_cfa = next_cfa;
17305 start_label = last_label;
17307 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17310 case DW_CFA_advance_loc:
17311 /* The encoding is complex enough that we should never emit this. */
17312 gcc_unreachable ();
17315 lookup_cfa_1 (cfi, &next_cfa, &remember);
17318 if (cfi == fde->dw_fde_switch_cfi)
17320 if (!cfa_equal_p (&last_cfa, &next_cfa))
17322 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17323 start_label, last_label, section);
17325 list_tail = &(*list_tail)->dw_loc_next;
17326 last_cfa = next_cfa;
17327 start_label = last_label;
17329 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17330 start_label, fde->dw_fde_end, section);
17331 list_tail = &(*list_tail)->dw_loc_next;
17332 start_label = last_label = fde->dw_fde_second_begin;
17336 if (!cfa_equal_p (&last_cfa, &next_cfa))
17338 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17339 start_label, last_label, section);
17340 list_tail = &(*list_tail)->dw_loc_next;
17341 start_label = last_label;
17344 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17346 fde->dw_fde_second_begin
17347 ? fde->dw_fde_second_end : fde->dw_fde_end,
17350 if (list && list->dw_loc_next)
17356 /* Compute a displacement from the "steady-state frame pointer" to the
17357 frame base (often the same as the CFA), and store it in
17358 frame_pointer_fb_offset. OFFSET is added to the displacement
17359 before the latter is negated. */
17362 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17366 #ifdef FRAME_POINTER_CFA_OFFSET
17367 reg = frame_pointer_rtx;
17368 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17370 reg = arg_pointer_rtx;
17371 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17374 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17375 if (GET_CODE (elim) == PLUS)
17377 offset += INTVAL (XEXP (elim, 1));
17378 elim = XEXP (elim, 0);
17381 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17382 && (elim == hard_frame_pointer_rtx
17383 || elim == stack_pointer_rtx))
17384 || elim == (frame_pointer_needed
17385 ? hard_frame_pointer_rtx
17386 : stack_pointer_rtx));
17388 frame_pointer_fb_offset = -offset;
17391 /* Generate a DW_AT_name attribute given some string value to be included as
17392 the value of the attribute. */
17395 add_name_attribute (dw_die_ref die, const char *name_string)
17397 if (name_string != NULL && *name_string != 0)
17399 if (demangle_name_func)
17400 name_string = (*demangle_name_func) (name_string);
17402 add_AT_string (die, DW_AT_name, name_string);
17406 /* Generate a DW_AT_comp_dir attribute for DIE. */
17409 add_comp_dir_attribute (dw_die_ref die)
17411 const char *wd = get_src_pwd ();
17417 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17421 wdlen = strlen (wd);
17422 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17424 wd1 [wdlen] = DIR_SEPARATOR;
17425 wd1 [wdlen + 1] = 0;
17429 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17432 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17436 lower_bound_default (void)
17438 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17443 case DW_LANG_C_plus_plus:
17445 case DW_LANG_ObjC_plus_plus:
17448 case DW_LANG_Fortran77:
17449 case DW_LANG_Fortran90:
17450 case DW_LANG_Fortran95:
17454 case DW_LANG_Python:
17455 return dwarf_version >= 4 ? 0 : -1;
17456 case DW_LANG_Ada95:
17457 case DW_LANG_Ada83:
17458 case DW_LANG_Cobol74:
17459 case DW_LANG_Cobol85:
17460 case DW_LANG_Pascal83:
17461 case DW_LANG_Modula2:
17463 return dwarf_version >= 4 ? 1 : -1;
17469 /* Given a tree node describing an array bound (either lower or upper) output
17470 a representation for that bound. */
17473 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17475 switch (TREE_CODE (bound))
17480 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17483 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17486 /* Use the default if possible. */
17487 if (bound_attr == DW_AT_lower_bound
17488 && host_integerp (bound, 0)
17489 && (dflt = lower_bound_default ()) != -1
17490 && tree_low_cst (bound, 0) == dflt)
17493 /* Otherwise represent the bound as an unsigned value with the
17494 precision of its type. The precision and signedness of the
17495 type will be necessary to re-interpret it unambiguously. */
17496 else if (prec < HOST_BITS_PER_WIDE_INT)
17498 unsigned HOST_WIDE_INT mask
17499 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17500 add_AT_unsigned (subrange_die, bound_attr,
17501 TREE_INT_CST_LOW (bound) & mask);
17503 else if (prec == HOST_BITS_PER_WIDE_INT
17504 || TREE_INT_CST_HIGH (bound) == 0)
17505 add_AT_unsigned (subrange_die, bound_attr,
17506 TREE_INT_CST_LOW (bound));
17508 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17509 TREE_INT_CST_LOW (bound));
17514 case VIEW_CONVERT_EXPR:
17515 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17525 dw_die_ref decl_die = lookup_decl_die (bound);
17527 /* ??? Can this happen, or should the variable have been bound
17528 first? Probably it can, since I imagine that we try to create
17529 the types of parameters in the order in which they exist in
17530 the list, and won't have created a forward reference to a
17531 later parameter. */
17532 if (decl_die != NULL)
17534 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17542 /* Otherwise try to create a stack operation procedure to
17543 evaluate the value of the array bound. */
17545 dw_die_ref ctx, decl_die;
17546 dw_loc_list_ref list;
17548 list = loc_list_from_tree (bound, 2);
17549 if (list == NULL || single_element_loc_list_p (list))
17551 /* If DW_AT_*bound is not a reference nor constant, it is
17552 a DWARF expression rather than location description.
17553 For that loc_list_from_tree (bound, 0) is needed.
17554 If that fails to give a single element list,
17555 fall back to outputting this as a reference anyway. */
17556 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17557 if (list2 && single_element_loc_list_p (list2))
17559 add_AT_loc (subrange_die, bound_attr, list2->expr);
17566 if (current_function_decl == 0)
17567 ctx = comp_unit_die ();
17569 ctx = lookup_decl_die (current_function_decl);
17571 decl_die = new_die (DW_TAG_variable, ctx, bound);
17572 add_AT_flag (decl_die, DW_AT_artificial, 1);
17573 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17574 add_AT_location_description (decl_die, DW_AT_location, list);
17575 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17581 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17582 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17583 Note that the block of subscript information for an array type also
17584 includes information about the element type of the given array type. */
17587 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17589 unsigned dimension_number;
17591 dw_die_ref subrange_die;
17593 for (dimension_number = 0;
17594 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17595 type = TREE_TYPE (type), dimension_number++)
17597 tree domain = TYPE_DOMAIN (type);
17599 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17602 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17603 and (in GNU C only) variable bounds. Handle all three forms
17605 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17608 /* We have an array type with specified bounds. */
17609 lower = TYPE_MIN_VALUE (domain);
17610 upper = TYPE_MAX_VALUE (domain);
17612 /* Define the index type. */
17613 if (TREE_TYPE (domain))
17615 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17616 TREE_TYPE field. We can't emit debug info for this
17617 because it is an unnamed integral type. */
17618 if (TREE_CODE (domain) == INTEGER_TYPE
17619 && TYPE_NAME (domain) == NULL_TREE
17620 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17621 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17624 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17628 /* ??? If upper is NULL, the array has unspecified length,
17629 but it does have a lower bound. This happens with Fortran
17631 Since the debugger is definitely going to need to know N
17632 to produce useful results, go ahead and output the lower
17633 bound solo, and hope the debugger can cope. */
17635 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17637 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17640 /* Otherwise we have an array type with an unspecified length. The
17641 DWARF-2 spec does not say how to handle this; let's just leave out the
17647 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17651 switch (TREE_CODE (tree_node))
17656 case ENUMERAL_TYPE:
17659 case QUAL_UNION_TYPE:
17660 size = int_size_in_bytes (tree_node);
17663 /* For a data member of a struct or union, the DW_AT_byte_size is
17664 generally given as the number of bytes normally allocated for an
17665 object of the *declared* type of the member itself. This is true
17666 even for bit-fields. */
17667 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17670 gcc_unreachable ();
17673 /* Note that `size' might be -1 when we get to this point. If it is, that
17674 indicates that the byte size of the entity in question is variable. We
17675 have no good way of expressing this fact in Dwarf at the present time,
17676 so just let the -1 pass on through. */
17677 add_AT_unsigned (die, DW_AT_byte_size, size);
17680 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17681 which specifies the distance in bits from the highest order bit of the
17682 "containing object" for the bit-field to the highest order bit of the
17685 For any given bit-field, the "containing object" is a hypothetical object
17686 (of some integral or enum type) within which the given bit-field lives. The
17687 type of this hypothetical "containing object" is always the same as the
17688 declared type of the individual bit-field itself. The determination of the
17689 exact location of the "containing object" for a bit-field is rather
17690 complicated. It's handled by the `field_byte_offset' function (above).
17692 Note that it is the size (in bytes) of the hypothetical "containing object"
17693 which will be given in the DW_AT_byte_size attribute for this bit-field.
17694 (See `byte_size_attribute' above). */
17697 add_bit_offset_attribute (dw_die_ref die, tree decl)
17699 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17700 tree type = DECL_BIT_FIELD_TYPE (decl);
17701 HOST_WIDE_INT bitpos_int;
17702 HOST_WIDE_INT highest_order_object_bit_offset;
17703 HOST_WIDE_INT highest_order_field_bit_offset;
17704 HOST_WIDE_INT bit_offset;
17706 /* Must be a field and a bit field. */
17707 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17709 /* We can't yet handle bit-fields whose offsets are variable, so if we
17710 encounter such things, just return without generating any attribute
17711 whatsoever. Likewise for variable or too large size. */
17712 if (! host_integerp (bit_position (decl), 0)
17713 || ! host_integerp (DECL_SIZE (decl), 1))
17716 bitpos_int = int_bit_position (decl);
17718 /* Note that the bit offset is always the distance (in bits) from the
17719 highest-order bit of the "containing object" to the highest-order bit of
17720 the bit-field itself. Since the "high-order end" of any object or field
17721 is different on big-endian and little-endian machines, the computation
17722 below must take account of these differences. */
17723 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17724 highest_order_field_bit_offset = bitpos_int;
17726 if (! BYTES_BIG_ENDIAN)
17728 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17729 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17733 = (! BYTES_BIG_ENDIAN
17734 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17735 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17737 if (bit_offset < 0)
17738 add_AT_int (die, DW_AT_bit_offset, bit_offset);
17740 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
17743 /* For a FIELD_DECL node which represents a bit field, output an attribute
17744 which specifies the length in bits of the given field. */
17747 add_bit_size_attribute (dw_die_ref die, tree decl)
17749 /* Must be a field and a bit field. */
17750 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17751 && DECL_BIT_FIELD_TYPE (decl));
17753 if (host_integerp (DECL_SIZE (decl), 1))
17754 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17757 /* If the compiled language is ANSI C, then add a 'prototyped'
17758 attribute, if arg types are given for the parameters of a function. */
17761 add_prototyped_attribute (dw_die_ref die, tree func_type)
17763 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
17764 && prototype_p (func_type))
17765 add_AT_flag (die, DW_AT_prototyped, 1);
17768 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17769 by looking in either the type declaration or object declaration
17772 static inline dw_die_ref
17773 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17775 dw_die_ref origin_die = NULL;
17777 if (TREE_CODE (origin) != FUNCTION_DECL)
17779 /* We may have gotten separated from the block for the inlined
17780 function, if we're in an exception handler or some such; make
17781 sure that the abstract function has been written out.
17783 Doing this for nested functions is wrong, however; functions are
17784 distinct units, and our context might not even be inline. */
17788 fn = TYPE_STUB_DECL (fn);
17790 fn = decl_function_context (fn);
17792 dwarf2out_abstract_function (fn);
17795 if (DECL_P (origin))
17796 origin_die = lookup_decl_die (origin);
17797 else if (TYPE_P (origin))
17798 origin_die = lookup_type_die (origin);
17800 /* XXX: Functions that are never lowered don't always have correct block
17801 trees (in the case of java, they simply have no block tree, in some other
17802 languages). For these functions, there is nothing we can really do to
17803 output correct debug info for inlined functions in all cases. Rather
17804 than die, we'll just produce deficient debug info now, in that we will
17805 have variables without a proper abstract origin. In the future, when all
17806 functions are lowered, we should re-add a gcc_assert (origin_die)
17810 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17814 /* We do not currently support the pure_virtual attribute. */
17817 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17819 if (DECL_VINDEX (func_decl))
17821 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17823 if (host_integerp (DECL_VINDEX (func_decl), 0))
17824 add_AT_loc (die, DW_AT_vtable_elem_location,
17825 new_loc_descr (DW_OP_constu,
17826 tree_low_cst (DECL_VINDEX (func_decl), 0),
17829 /* GNU extension: Record what type this method came from originally. */
17830 if (debug_info_level > DINFO_LEVEL_TERSE
17831 && DECL_CONTEXT (func_decl))
17832 add_AT_die_ref (die, DW_AT_containing_type,
17833 lookup_type_die (DECL_CONTEXT (func_decl)));
17837 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17838 given decl. This used to be a vendor extension until after DWARF 4
17839 standardized it. */
17842 add_linkage_attr (dw_die_ref die, tree decl)
17844 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17846 /* Mimic what assemble_name_raw does with a leading '*'. */
17847 if (name[0] == '*')
17850 if (dwarf_version >= 4)
17851 add_AT_string (die, DW_AT_linkage_name, name);
17853 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17856 /* Add source coordinate attributes for the given decl. */
17859 add_src_coords_attributes (dw_die_ref die, tree decl)
17861 expanded_location s;
17863 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
17865 s = expand_location (DECL_SOURCE_LOCATION (decl));
17866 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17867 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17870 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17873 add_linkage_name (dw_die_ref die, tree decl)
17875 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17876 && TREE_PUBLIC (decl)
17877 && !DECL_ABSTRACT (decl)
17878 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17879 && die->die_tag != DW_TAG_member)
17881 /* Defer until we have an assembler name set. */
17882 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17884 limbo_die_node *asm_name;
17886 asm_name = ggc_alloc_cleared_limbo_die_node ();
17887 asm_name->die = die;
17888 asm_name->created_for = decl;
17889 asm_name->next = deferred_asm_name;
17890 deferred_asm_name = asm_name;
17892 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17893 add_linkage_attr (die, decl);
17897 /* Add a DW_AT_name attribute and source coordinate attribute for the
17898 given decl, but only if it actually has a name. */
17901 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17905 decl_name = DECL_NAME (decl);
17906 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17908 const char *name = dwarf2_name (decl, 0);
17910 add_name_attribute (die, name);
17911 if (! DECL_ARTIFICIAL (decl))
17912 add_src_coords_attributes (die, decl);
17914 add_linkage_name (die, decl);
17917 #ifdef VMS_DEBUGGING_INFO
17918 /* Get the function's name, as described by its RTL. This may be different
17919 from the DECL_NAME name used in the source file. */
17920 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17922 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17923 XEXP (DECL_RTL (decl), 0));
17924 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17926 #endif /* VMS_DEBUGGING_INFO */
17929 #ifdef VMS_DEBUGGING_INFO
17930 /* Output the debug main pointer die for VMS */
17933 dwarf2out_vms_debug_main_pointer (void)
17935 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17938 /* Allocate the VMS debug main subprogram die. */
17939 die = ggc_alloc_cleared_die_node ();
17940 die->die_tag = DW_TAG_subprogram;
17941 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17942 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17943 current_function_funcdef_no);
17944 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17946 /* Make it the first child of comp_unit_die (). */
17947 die->die_parent = comp_unit_die ();
17948 if (comp_unit_die ()->die_child)
17950 die->die_sib = comp_unit_die ()->die_child->die_sib;
17951 comp_unit_die ()->die_child->die_sib = die;
17955 die->die_sib = die;
17956 comp_unit_die ()->die_child = die;
17959 #endif /* VMS_DEBUGGING_INFO */
17961 /* Push a new declaration scope. */
17964 push_decl_scope (tree scope)
17966 VEC_safe_push (tree, gc, decl_scope_table, scope);
17969 /* Pop a declaration scope. */
17972 pop_decl_scope (void)
17974 VEC_pop (tree, decl_scope_table);
17977 /* Return the DIE for the scope that immediately contains this type.
17978 Non-named types get global scope. Named types nested in other
17979 types get their containing scope if it's open, or global scope
17980 otherwise. All other types (i.e. function-local named types) get
17981 the current active scope. */
17984 scope_die_for (tree t, dw_die_ref context_die)
17986 dw_die_ref scope_die = NULL;
17987 tree containing_scope;
17990 /* Non-types always go in the current scope. */
17991 gcc_assert (TYPE_P (t));
17993 containing_scope = TYPE_CONTEXT (t);
17995 /* Use the containing namespace if it was passed in (for a declaration). */
17996 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17998 if (context_die == lookup_decl_die (containing_scope))
18001 containing_scope = NULL_TREE;
18004 /* Ignore function type "scopes" from the C frontend. They mean that
18005 a tagged type is local to a parmlist of a function declarator, but
18006 that isn't useful to DWARF. */
18007 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
18008 containing_scope = NULL_TREE;
18010 if (SCOPE_FILE_SCOPE_P (containing_scope))
18011 scope_die = comp_unit_die ();
18012 else if (TYPE_P (containing_scope))
18014 /* For types, we can just look up the appropriate DIE. But
18015 first we check to see if we're in the middle of emitting it
18016 so we know where the new DIE should go. */
18017 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
18018 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
18023 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
18024 || TREE_ASM_WRITTEN (containing_scope));
18025 /*We are not in the middle of emitting the type
18026 CONTAINING_SCOPE. Let's see if it's emitted already. */
18027 scope_die = lookup_type_die (containing_scope);
18029 /* If none of the current dies are suitable, we get file scope. */
18030 if (scope_die == NULL)
18031 scope_die = comp_unit_die ();
18034 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
18037 scope_die = context_die;
18042 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
18045 local_scope_p (dw_die_ref context_die)
18047 for (; context_die; context_die = context_die->die_parent)
18048 if (context_die->die_tag == DW_TAG_inlined_subroutine
18049 || context_die->die_tag == DW_TAG_subprogram)
18055 /* Returns nonzero if CONTEXT_DIE is a class. */
18058 class_scope_p (dw_die_ref context_die)
18060 return (context_die
18061 && (context_die->die_tag == DW_TAG_structure_type
18062 || context_die->die_tag == DW_TAG_class_type
18063 || context_die->die_tag == DW_TAG_interface_type
18064 || context_die->die_tag == DW_TAG_union_type));
18067 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
18068 whether or not to treat a DIE in this context as a declaration. */
18071 class_or_namespace_scope_p (dw_die_ref context_die)
18073 return (class_scope_p (context_die)
18074 || (context_die && context_die->die_tag == DW_TAG_namespace));
18077 /* Many forms of DIEs require a "type description" attribute. This
18078 routine locates the proper "type descriptor" die for the type given
18079 by 'type', and adds a DW_AT_type attribute below the given die. */
18082 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
18083 int decl_volatile, dw_die_ref context_die)
18085 enum tree_code code = TREE_CODE (type);
18086 dw_die_ref type_die = NULL;
18088 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18089 or fixed-point type, use the inner type. This is because we have no
18090 support for unnamed types in base_type_die. This can happen if this is
18091 an Ada subrange type. Correct solution is emit a subrange type die. */
18092 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
18093 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
18094 type = TREE_TYPE (type), code = TREE_CODE (type);
18096 if (code == ERROR_MARK
18097 /* Handle a special case. For functions whose return type is void, we
18098 generate *no* type attribute. (Note that no object may have type
18099 `void', so this only applies to function return types). */
18100 || code == VOID_TYPE)
18103 type_die = modified_type_die (type,
18104 decl_const || TYPE_READONLY (type),
18105 decl_volatile || TYPE_VOLATILE (type),
18108 if (type_die != NULL)
18109 add_AT_die_ref (object_die, DW_AT_type, type_die);
18112 /* Given an object die, add the calling convention attribute for the
18113 function call type. */
18115 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
18117 enum dwarf_calling_convention value = DW_CC_normal;
18119 value = ((enum dwarf_calling_convention)
18120 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
18123 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
18125 /* DWARF 2 doesn't provide a way to identify a program's source-level
18126 entry point. DW_AT_calling_convention attributes are only meant
18127 to describe functions' calling conventions. However, lacking a
18128 better way to signal the Fortran main program, we used this for
18129 a long time, following existing custom. Now, DWARF 4 has
18130 DW_AT_main_subprogram, which we add below, but some tools still
18131 rely on the old way, which we thus keep. */
18132 value = DW_CC_program;
18134 if (dwarf_version >= 4 || !dwarf_strict)
18135 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
18138 /* Only add the attribute if the backend requests it, and
18139 is not DW_CC_normal. */
18140 if (value && (value != DW_CC_normal))
18141 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18144 /* Given a tree pointer to a struct, class, union, or enum type node, return
18145 a pointer to the (string) tag name for the given type, or zero if the type
18146 was declared without a tag. */
18148 static const char *
18149 type_tag (const_tree type)
18151 const char *name = 0;
18153 if (TYPE_NAME (type) != 0)
18157 /* Find the IDENTIFIER_NODE for the type name. */
18158 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18159 && !TYPE_NAMELESS (type))
18160 t = TYPE_NAME (type);
18162 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18163 a TYPE_DECL node, regardless of whether or not a `typedef' was
18165 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18166 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18168 /* We want to be extra verbose. Don't call dwarf_name if
18169 DECL_NAME isn't set. The default hook for decl_printable_name
18170 doesn't like that, and in this context it's correct to return
18171 0, instead of "<anonymous>" or the like. */
18172 if (DECL_NAME (TYPE_NAME (type))
18173 && !DECL_NAMELESS (TYPE_NAME (type)))
18174 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18177 /* Now get the name as a string, or invent one. */
18178 if (!name && t != 0)
18179 name = IDENTIFIER_POINTER (t);
18182 return (name == 0 || *name == '\0') ? 0 : name;
18185 /* Return the type associated with a data member, make a special check
18186 for bit field types. */
18189 member_declared_type (const_tree member)
18191 return (DECL_BIT_FIELD_TYPE (member)
18192 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18195 /* Get the decl's label, as described by its RTL. This may be different
18196 from the DECL_NAME name used in the source file. */
18199 static const char *
18200 decl_start_label (tree decl)
18203 const char *fnname;
18205 x = DECL_RTL (decl);
18206 gcc_assert (MEM_P (x));
18209 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18211 fnname = XSTR (x, 0);
18216 /* These routines generate the internal representation of the DIE's for
18217 the compilation unit. Debugging information is collected by walking
18218 the declaration trees passed in from dwarf2out_decl(). */
18221 gen_array_type_die (tree type, dw_die_ref context_die)
18223 dw_die_ref scope_die = scope_die_for (type, context_die);
18224 dw_die_ref array_die;
18226 /* GNU compilers represent multidimensional array types as sequences of one
18227 dimensional array types whose element types are themselves array types.
18228 We sometimes squish that down to a single array_type DIE with multiple
18229 subscripts in the Dwarf debugging info. The draft Dwarf specification
18230 say that we are allowed to do this kind of compression in C, because
18231 there is no difference between an array of arrays and a multidimensional
18232 array. We don't do this for Ada to remain as close as possible to the
18233 actual representation, which is especially important against the language
18234 flexibilty wrt arrays of variable size. */
18236 bool collapse_nested_arrays = !is_ada ();
18239 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18240 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18241 if (TYPE_STRING_FLAG (type)
18242 && TREE_CODE (type) == ARRAY_TYPE
18244 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18246 HOST_WIDE_INT size;
18248 array_die = new_die (DW_TAG_string_type, scope_die, type);
18249 add_name_attribute (array_die, type_tag (type));
18250 equate_type_number_to_die (type, array_die);
18251 size = int_size_in_bytes (type);
18253 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18254 else if (TYPE_DOMAIN (type) != NULL_TREE
18255 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18256 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18258 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18259 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18261 size = int_size_in_bytes (TREE_TYPE (szdecl));
18262 if (loc && size > 0)
18264 add_AT_location_description (array_die, DW_AT_string_length, loc);
18265 if (size != DWARF2_ADDR_SIZE)
18266 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18272 /* ??? The SGI dwarf reader fails for array of array of enum types
18273 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18274 array type comes before the outer array type. We thus call gen_type_die
18275 before we new_die and must prevent nested array types collapsing for this
18278 #ifdef MIPS_DEBUGGING_INFO
18279 gen_type_die (TREE_TYPE (type), context_die);
18280 collapse_nested_arrays = false;
18283 array_die = new_die (DW_TAG_array_type, scope_die, type);
18284 add_name_attribute (array_die, type_tag (type));
18285 equate_type_number_to_die (type, array_die);
18287 if (TREE_CODE (type) == VECTOR_TYPE)
18288 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18290 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18292 && TREE_CODE (type) == ARRAY_TYPE
18293 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18294 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18295 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18298 /* We default the array ordering. SDB will probably do
18299 the right things even if DW_AT_ordering is not present. It's not even
18300 an issue until we start to get into multidimensional arrays anyway. If
18301 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18302 then we'll have to put the DW_AT_ordering attribute back in. (But if
18303 and when we find out that we need to put these in, we will only do so
18304 for multidimensional arrays. */
18305 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18308 #ifdef MIPS_DEBUGGING_INFO
18309 /* The SGI compilers handle arrays of unknown bound by setting
18310 AT_declaration and not emitting any subrange DIEs. */
18311 if (TREE_CODE (type) == ARRAY_TYPE
18312 && ! TYPE_DOMAIN (type))
18313 add_AT_flag (array_die, DW_AT_declaration, 1);
18316 if (TREE_CODE (type) == VECTOR_TYPE)
18318 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18319 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18320 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18321 add_bound_info (subrange_die, DW_AT_upper_bound,
18322 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18325 add_subscript_info (array_die, type, collapse_nested_arrays);
18327 /* Add representation of the type of the elements of this array type and
18328 emit the corresponding DIE if we haven't done it already. */
18329 element_type = TREE_TYPE (type);
18330 if (collapse_nested_arrays)
18331 while (TREE_CODE (element_type) == ARRAY_TYPE)
18333 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18335 element_type = TREE_TYPE (element_type);
18338 #ifndef MIPS_DEBUGGING_INFO
18339 gen_type_die (element_type, context_die);
18342 add_type_attribute (array_die, element_type, 0, 0, context_die);
18344 if (get_AT (array_die, DW_AT_name))
18345 add_pubtype (type, array_die);
18348 static dw_loc_descr_ref
18349 descr_info_loc (tree val, tree base_decl)
18351 HOST_WIDE_INT size;
18352 dw_loc_descr_ref loc, loc2;
18353 enum dwarf_location_atom op;
18355 if (val == base_decl)
18356 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18358 switch (TREE_CODE (val))
18361 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18363 return loc_descriptor_from_tree (val, 0);
18365 if (host_integerp (val, 0))
18366 return int_loc_descriptor (tree_low_cst (val, 0));
18369 size = int_size_in_bytes (TREE_TYPE (val));
18372 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18375 if (size == DWARF2_ADDR_SIZE)
18376 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18378 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18380 case POINTER_PLUS_EXPR:
18382 if (host_integerp (TREE_OPERAND (val, 1), 1)
18383 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18386 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18389 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18395 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18398 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18401 add_loc_descr (&loc, loc2);
18402 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18424 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18425 tree val, tree base_decl)
18427 dw_loc_descr_ref loc;
18429 if (host_integerp (val, 0))
18431 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18435 loc = descr_info_loc (val, base_decl);
18439 add_AT_loc (die, attr, loc);
18442 /* This routine generates DIE for array with hidden descriptor, details
18443 are filled into *info by a langhook. */
18446 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18447 dw_die_ref context_die)
18449 dw_die_ref scope_die = scope_die_for (type, context_die);
18450 dw_die_ref array_die;
18453 array_die = new_die (DW_TAG_array_type, scope_die, type);
18454 add_name_attribute (array_die, type_tag (type));
18455 equate_type_number_to_die (type, array_die);
18457 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18459 && info->ndimensions >= 2)
18460 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18462 if (info->data_location)
18463 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18465 if (info->associated)
18466 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18468 if (info->allocated)
18469 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18472 for (dim = 0; dim < info->ndimensions; dim++)
18474 dw_die_ref subrange_die
18475 = new_die (DW_TAG_subrange_type, array_die, NULL);
18477 if (info->dimen[dim].lower_bound)
18479 /* If it is the default value, omit it. */
18482 if (host_integerp (info->dimen[dim].lower_bound, 0)
18483 && (dflt = lower_bound_default ()) != -1
18484 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18487 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18488 info->dimen[dim].lower_bound,
18491 if (info->dimen[dim].upper_bound)
18492 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18493 info->dimen[dim].upper_bound,
18495 if (info->dimen[dim].stride)
18496 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18497 info->dimen[dim].stride,
18501 gen_type_die (info->element_type, context_die);
18502 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18504 if (get_AT (array_die, DW_AT_name))
18505 add_pubtype (type, array_die);
18510 gen_entry_point_die (tree decl, dw_die_ref context_die)
18512 tree origin = decl_ultimate_origin (decl);
18513 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18515 if (origin != NULL)
18516 add_abstract_origin_attribute (decl_die, origin);
18519 add_name_and_src_coords_attributes (decl_die, decl);
18520 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18521 0, 0, context_die);
18524 if (DECL_ABSTRACT (decl))
18525 equate_decl_number_to_die (decl, decl_die);
18527 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18531 /* Walk through the list of incomplete types again, trying once more to
18532 emit full debugging info for them. */
18535 retry_incomplete_types (void)
18539 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18540 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18541 DINFO_USAGE_DIR_USE))
18542 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
18545 /* Determine what tag to use for a record type. */
18547 static enum dwarf_tag
18548 record_type_tag (tree type)
18550 if (! lang_hooks.types.classify_record)
18551 return DW_TAG_structure_type;
18553 switch (lang_hooks.types.classify_record (type))
18555 case RECORD_IS_STRUCT:
18556 return DW_TAG_structure_type;
18558 case RECORD_IS_CLASS:
18559 return DW_TAG_class_type;
18561 case RECORD_IS_INTERFACE:
18562 if (dwarf_version >= 3 || !dwarf_strict)
18563 return DW_TAG_interface_type;
18564 return DW_TAG_structure_type;
18567 gcc_unreachable ();
18571 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18572 include all of the information about the enumeration values also. Each
18573 enumerated type name/value is listed as a child of the enumerated type
18577 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18579 dw_die_ref type_die = lookup_type_die (type);
18581 if (type_die == NULL)
18583 type_die = new_die (DW_TAG_enumeration_type,
18584 scope_die_for (type, context_die), type);
18585 equate_type_number_to_die (type, type_die);
18586 add_name_attribute (type_die, type_tag (type));
18587 if (dwarf_version >= 4 || !dwarf_strict)
18589 if (ENUM_IS_SCOPED (type))
18590 add_AT_flag (type_die, DW_AT_enum_class, 1);
18591 if (ENUM_IS_OPAQUE (type))
18592 add_AT_flag (type_die, DW_AT_declaration, 1);
18595 else if (! TYPE_SIZE (type))
18598 remove_AT (type_die, DW_AT_declaration);
18600 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18601 given enum type is incomplete, do not generate the DW_AT_byte_size
18602 attribute or the DW_AT_element_list attribute. */
18603 if (TYPE_SIZE (type))
18607 TREE_ASM_WRITTEN (type) = 1;
18608 add_byte_size_attribute (type_die, type);
18609 if (TYPE_STUB_DECL (type) != NULL_TREE)
18611 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18612 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18615 /* If the first reference to this type was as the return type of an
18616 inline function, then it may not have a parent. Fix this now. */
18617 if (type_die->die_parent == NULL)
18618 add_child_die (scope_die_for (type, context_die), type_die);
18620 for (link = TYPE_VALUES (type);
18621 link != NULL; link = TREE_CHAIN (link))
18623 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18624 tree value = TREE_VALUE (link);
18626 add_name_attribute (enum_die,
18627 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18629 if (TREE_CODE (value) == CONST_DECL)
18630 value = DECL_INITIAL (value);
18632 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18633 /* DWARF2 does not provide a way of indicating whether or
18634 not enumeration constants are signed or unsigned. GDB
18635 always assumes the values are signed, so we output all
18636 values as if they were signed. That means that
18637 enumeration constants with very large unsigned values
18638 will appear to have negative values in the debugger. */
18639 add_AT_int (enum_die, DW_AT_const_value,
18640 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18644 add_AT_flag (type_die, DW_AT_declaration, 1);
18646 if (get_AT (type_die, DW_AT_name))
18647 add_pubtype (type, type_die);
18652 /* Generate a DIE to represent either a real live formal parameter decl or to
18653 represent just the type of some formal parameter position in some function
18656 Note that this routine is a bit unusual because its argument may be a
18657 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18658 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18659 node. If it's the former then this function is being called to output a
18660 DIE to represent a formal parameter object (or some inlining thereof). If
18661 it's the latter, then this function is only being called to output a
18662 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18663 argument type of some subprogram type.
18664 If EMIT_NAME_P is true, name and source coordinate attributes
18668 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18669 dw_die_ref context_die)
18671 tree node_or_origin = node ? node : origin;
18672 tree ultimate_origin;
18673 dw_die_ref parm_die
18674 = new_die (DW_TAG_formal_parameter, context_die, node);
18676 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18678 case tcc_declaration:
18679 ultimate_origin = decl_ultimate_origin (node_or_origin);
18680 if (node || ultimate_origin)
18681 origin = ultimate_origin;
18682 if (origin != NULL)
18683 add_abstract_origin_attribute (parm_die, origin);
18684 else if (emit_name_p)
18685 add_name_and_src_coords_attributes (parm_die, node);
18687 || (! DECL_ABSTRACT (node_or_origin)
18688 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18689 decl_function_context
18690 (node_or_origin))))
18692 tree type = TREE_TYPE (node_or_origin);
18693 if (decl_by_reference_p (node_or_origin))
18694 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18697 add_type_attribute (parm_die, type,
18698 TREE_READONLY (node_or_origin),
18699 TREE_THIS_VOLATILE (node_or_origin),
18702 if (origin == NULL && DECL_ARTIFICIAL (node))
18703 add_AT_flag (parm_die, DW_AT_artificial, 1);
18705 if (node && node != origin)
18706 equate_decl_number_to_die (node, parm_die);
18707 if (! DECL_ABSTRACT (node_or_origin))
18708 add_location_or_const_value_attribute (parm_die, node_or_origin,
18709 node == NULL, DW_AT_location);
18714 /* We were called with some kind of a ..._TYPE node. */
18715 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18719 gcc_unreachable ();
18725 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18726 children DW_TAG_formal_parameter DIEs representing the arguments of the
18729 PARM_PACK must be a function parameter pack.
18730 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18731 must point to the subsequent arguments of the function PACK_ARG belongs to.
18732 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18733 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18734 following the last one for which a DIE was generated. */
18737 gen_formal_parameter_pack_die (tree parm_pack,
18739 dw_die_ref subr_die,
18743 dw_die_ref parm_pack_die;
18745 gcc_assert (parm_pack
18746 && lang_hooks.function_parameter_pack_p (parm_pack)
18749 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18750 add_src_coords_attributes (parm_pack_die, parm_pack);
18752 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18754 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18757 gen_formal_parameter_die (arg, NULL,
18758 false /* Don't emit name attribute. */,
18763 return parm_pack_die;
18766 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18767 at the end of an (ANSI prototyped) formal parameters list. */
18770 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18772 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18775 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18776 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18777 parameters as specified in some function type specification (except for
18778 those which appear as part of a function *definition*). */
18781 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18784 tree formal_type = NULL;
18785 tree first_parm_type;
18788 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18790 arg = DECL_ARGUMENTS (function_or_method_type);
18791 function_or_method_type = TREE_TYPE (function_or_method_type);
18796 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18798 /* Make our first pass over the list of formal parameter types and output a
18799 DW_TAG_formal_parameter DIE for each one. */
18800 for (link = first_parm_type; link; )
18802 dw_die_ref parm_die;
18804 formal_type = TREE_VALUE (link);
18805 if (formal_type == void_type_node)
18808 /* Output a (nameless) DIE to represent the formal parameter itself. */
18809 parm_die = gen_formal_parameter_die (formal_type, NULL,
18810 true /* Emit name attribute. */,
18812 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18813 && link == first_parm_type)
18815 add_AT_flag (parm_die, DW_AT_artificial, 1);
18816 if (dwarf_version >= 3 || !dwarf_strict)
18817 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18819 else if (arg && DECL_ARTIFICIAL (arg))
18820 add_AT_flag (parm_die, DW_AT_artificial, 1);
18822 link = TREE_CHAIN (link);
18824 arg = DECL_CHAIN (arg);
18827 /* If this function type has an ellipsis, add a
18828 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18829 if (formal_type != void_type_node)
18830 gen_unspecified_parameters_die (function_or_method_type, context_die);
18832 /* Make our second (and final) pass over the list of formal parameter types
18833 and output DIEs to represent those types (as necessary). */
18834 for (link = TYPE_ARG_TYPES (function_or_method_type);
18835 link && TREE_VALUE (link);
18836 link = TREE_CHAIN (link))
18837 gen_type_die (TREE_VALUE (link), context_die);
18840 /* We want to generate the DIE for TYPE so that we can generate the
18841 die for MEMBER, which has been defined; we will need to refer back
18842 to the member declaration nested within TYPE. If we're trying to
18843 generate minimal debug info for TYPE, processing TYPE won't do the
18844 trick; we need to attach the member declaration by hand. */
18847 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18849 gen_type_die (type, context_die);
18851 /* If we're trying to avoid duplicate debug info, we may not have
18852 emitted the member decl for this function. Emit it now. */
18853 if (TYPE_STUB_DECL (type)
18854 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18855 && ! lookup_decl_die (member))
18857 dw_die_ref type_die;
18858 gcc_assert (!decl_ultimate_origin (member));
18860 push_decl_scope (type);
18861 type_die = lookup_type_die_strip_naming_typedef (type);
18862 if (TREE_CODE (member) == FUNCTION_DECL)
18863 gen_subprogram_die (member, type_die);
18864 else if (TREE_CODE (member) == FIELD_DECL)
18866 /* Ignore the nameless fields that are used to skip bits but handle
18867 C++ anonymous unions and structs. */
18868 if (DECL_NAME (member) != NULL_TREE
18869 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18870 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18872 gen_type_die (member_declared_type (member), type_die);
18873 gen_field_die (member, type_die);
18877 gen_variable_die (member, NULL_TREE, type_die);
18883 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18884 may later generate inlined and/or out-of-line instances of. */
18887 dwarf2out_abstract_function (tree decl)
18889 dw_die_ref old_die;
18893 htab_t old_decl_loc_table;
18894 htab_t old_cached_dw_loc_list_table;
18895 int old_call_site_count, old_tail_call_site_count;
18896 struct call_arg_loc_node *old_call_arg_locations;
18898 /* Make sure we have the actual abstract inline, not a clone. */
18899 decl = DECL_ORIGIN (decl);
18901 old_die = lookup_decl_die (decl);
18902 if (old_die && get_AT (old_die, DW_AT_inline))
18903 /* We've already generated the abstract instance. */
18906 /* We can be called while recursively when seeing block defining inlined subroutine
18907 DIE. Be sure to not clobber the outer location table nor use it or we would
18908 get locations in abstract instantces. */
18909 old_decl_loc_table = decl_loc_table;
18910 decl_loc_table = NULL;
18911 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
18912 cached_dw_loc_list_table = NULL;
18913 old_call_arg_locations = call_arg_locations;
18914 call_arg_locations = NULL;
18915 old_call_site_count = call_site_count;
18916 call_site_count = -1;
18917 old_tail_call_site_count = tail_call_site_count;
18918 tail_call_site_count = -1;
18920 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18921 we don't get confused by DECL_ABSTRACT. */
18922 if (debug_info_level > DINFO_LEVEL_TERSE)
18924 context = decl_class_context (decl);
18926 gen_type_die_for_member
18927 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18930 /* Pretend we've just finished compiling this function. */
18931 save_fn = current_function_decl;
18932 current_function_decl = decl;
18933 push_cfun (DECL_STRUCT_FUNCTION (decl));
18935 was_abstract = DECL_ABSTRACT (decl);
18936 set_decl_abstract_flags (decl, 1);
18937 dwarf2out_decl (decl);
18938 if (! was_abstract)
18939 set_decl_abstract_flags (decl, 0);
18941 current_function_decl = save_fn;
18942 decl_loc_table = old_decl_loc_table;
18943 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
18944 call_arg_locations = old_call_arg_locations;
18945 call_site_count = old_call_site_count;
18946 tail_call_site_count = old_tail_call_site_count;
18950 /* Helper function of premark_used_types() which gets called through
18953 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18954 marked as unused by prune_unused_types. */
18957 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
18962 type = (tree) *slot;
18963 die = lookup_type_die (type);
18965 die->die_perennial_p = 1;
18969 /* Helper function of premark_types_used_by_global_vars which gets called
18970 through htab_traverse.
18972 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18973 marked as unused by prune_unused_types. The DIE of the type is marked
18974 only if the global variable using the type will actually be emitted. */
18977 premark_types_used_by_global_vars_helper (void **slot,
18978 void *data ATTRIBUTE_UNUSED)
18980 struct types_used_by_vars_entry *entry;
18983 entry = (struct types_used_by_vars_entry *) *slot;
18984 gcc_assert (entry->type != NULL
18985 && entry->var_decl != NULL);
18986 die = lookup_type_die (entry->type);
18989 /* Ask cgraph if the global variable really is to be emitted.
18990 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18991 struct varpool_node *node = varpool_get_node (entry->var_decl);
18992 if (node && node->needed)
18994 die->die_perennial_p = 1;
18995 /* Keep the parent DIEs as well. */
18996 while ((die = die->die_parent) && die->die_perennial_p == 0)
18997 die->die_perennial_p = 1;
19003 /* Mark all members of used_types_hash as perennial. */
19006 premark_used_types (void)
19008 if (cfun && cfun->used_types_hash)
19009 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
19012 /* Mark all members of types_used_by_vars_entry as perennial. */
19015 premark_types_used_by_global_vars (void)
19017 if (types_used_by_vars_hash)
19018 htab_traverse (types_used_by_vars_hash,
19019 premark_types_used_by_global_vars_helper, NULL);
19022 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
19023 for CA_LOC call arg loc node. */
19026 gen_call_site_die (tree decl, dw_die_ref subr_die,
19027 struct call_arg_loc_node *ca_loc)
19029 dw_die_ref stmt_die = NULL, die;
19030 tree block = ca_loc->block;
19033 && block != DECL_INITIAL (decl)
19034 && TREE_CODE (block) == BLOCK)
19036 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
19037 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
19040 block = BLOCK_SUPERCONTEXT (block);
19042 if (stmt_die == NULL)
19043 stmt_die = subr_die;
19044 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
19045 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
19046 if (ca_loc->tail_call_p)
19047 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
19048 if (ca_loc->symbol_ref)
19050 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
19052 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
19054 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
19059 /* Generate a DIE to represent a declared function (either file-scope or
19063 gen_subprogram_die (tree decl, dw_die_ref context_die)
19065 tree origin = decl_ultimate_origin (decl);
19066 dw_die_ref subr_die;
19068 dw_die_ref old_die = lookup_decl_die (decl);
19069 int declaration = (current_function_decl != decl
19070 || class_or_namespace_scope_p (context_die));
19072 premark_used_types ();
19074 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
19075 started to generate the abstract instance of an inline, decided to output
19076 its containing class, and proceeded to emit the declaration of the inline
19077 from the member list for the class. If so, DECLARATION takes priority;
19078 we'll get back to the abstract instance when done with the class. */
19080 /* The class-scope declaration DIE must be the primary DIE. */
19081 if (origin && declaration && class_or_namespace_scope_p (context_die))
19084 gcc_assert (!old_die);
19087 /* Now that the C++ front end lazily declares artificial member fns, we
19088 might need to retrofit the declaration into its class. */
19089 if (!declaration && !origin && !old_die
19090 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
19091 && !class_or_namespace_scope_p (context_die)
19092 && debug_info_level > DINFO_LEVEL_TERSE)
19093 old_die = force_decl_die (decl);
19095 if (origin != NULL)
19097 gcc_assert (!declaration || local_scope_p (context_die));
19099 /* Fixup die_parent for the abstract instance of a nested
19100 inline function. */
19101 if (old_die && old_die->die_parent == NULL)
19102 add_child_die (context_die, old_die);
19104 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19105 add_abstract_origin_attribute (subr_die, origin);
19109 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19110 struct dwarf_file_data * file_index = lookup_filename (s.file);
19112 if (!get_AT_flag (old_die, DW_AT_declaration)
19113 /* We can have a normal definition following an inline one in the
19114 case of redefinition of GNU C extern inlines.
19115 It seems reasonable to use AT_specification in this case. */
19116 && !get_AT (old_die, DW_AT_inline))
19118 /* Detect and ignore this case, where we are trying to output
19119 something we have already output. */
19123 /* If the definition comes from the same place as the declaration,
19124 maybe use the old DIE. We always want the DIE for this function
19125 that has the *_pc attributes to be under comp_unit_die so the
19126 debugger can find it. We also need to do this for abstract
19127 instances of inlines, since the spec requires the out-of-line copy
19128 to have the same parent. For local class methods, this doesn't
19129 apply; we just use the old DIE. */
19130 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
19131 && (DECL_ARTIFICIAL (decl)
19132 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
19133 && (get_AT_unsigned (old_die, DW_AT_decl_line)
19134 == (unsigned) s.line))))
19136 subr_die = old_die;
19138 /* Clear out the declaration attribute and the formal parameters.
19139 Do not remove all children, because it is possible that this
19140 declaration die was forced using force_decl_die(). In such
19141 cases die that forced declaration die (e.g. TAG_imported_module)
19142 is one of the children that we do not want to remove. */
19143 remove_AT (subr_die, DW_AT_declaration);
19144 remove_AT (subr_die, DW_AT_object_pointer);
19145 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
19149 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19150 add_AT_specification (subr_die, old_die);
19151 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19152 add_AT_file (subr_die, DW_AT_decl_file, file_index);
19153 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19154 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
19159 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19161 if (TREE_PUBLIC (decl))
19162 add_AT_flag (subr_die, DW_AT_external, 1);
19164 add_name_and_src_coords_attributes (subr_die, decl);
19165 if (debug_info_level > DINFO_LEVEL_TERSE)
19167 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
19168 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
19169 0, 0, context_die);
19172 add_pure_or_virtual_attribute (subr_die, decl);
19173 if (DECL_ARTIFICIAL (decl))
19174 add_AT_flag (subr_die, DW_AT_artificial, 1);
19176 add_accessibility_attribute (subr_die, decl);
19181 if (!old_die || !get_AT (old_die, DW_AT_inline))
19183 add_AT_flag (subr_die, DW_AT_declaration, 1);
19185 /* If this is an explicit function declaration then generate
19186 a DW_AT_explicit attribute. */
19187 if (lang_hooks.decls.function_decl_explicit_p (decl)
19188 && (dwarf_version >= 3 || !dwarf_strict))
19189 add_AT_flag (subr_die, DW_AT_explicit, 1);
19191 /* The first time we see a member function, it is in the context of
19192 the class to which it belongs. We make sure of this by emitting
19193 the class first. The next time is the definition, which is
19194 handled above. The two may come from the same source text.
19196 Note that force_decl_die() forces function declaration die. It is
19197 later reused to represent definition. */
19198 equate_decl_number_to_die (decl, subr_die);
19201 else if (DECL_ABSTRACT (decl))
19203 if (DECL_DECLARED_INLINE_P (decl))
19205 if (cgraph_function_possibly_inlined_p (decl))
19206 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19208 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19212 if (cgraph_function_possibly_inlined_p (decl))
19213 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19215 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19218 if (DECL_DECLARED_INLINE_P (decl)
19219 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19220 add_AT_flag (subr_die, DW_AT_artificial, 1);
19222 equate_decl_number_to_die (decl, subr_die);
19224 else if (!DECL_EXTERNAL (decl))
19226 HOST_WIDE_INT cfa_fb_offset;
19228 if (!old_die || !get_AT (old_die, DW_AT_inline))
19229 equate_decl_number_to_die (decl, subr_die);
19231 if (!flag_reorder_blocks_and_partition)
19233 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19234 if (fde->dw_fde_begin)
19236 /* We have already generated the labels. */
19237 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19238 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19242 /* Create start/end labels and add the range. */
19243 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
19244 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19245 current_function_funcdef_no);
19246 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19247 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19248 current_function_funcdef_no);
19249 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19252 #if VMS_DEBUGGING_INFO
19253 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19254 Section 2.3 Prologue and Epilogue Attributes:
19255 When a breakpoint is set on entry to a function, it is generally
19256 desirable for execution to be suspended, not on the very first
19257 instruction of the function, but rather at a point after the
19258 function's frame has been set up, after any language defined local
19259 declaration processing has been completed, and before execution of
19260 the first statement of the function begins. Debuggers generally
19261 cannot properly determine where this point is. Similarly for a
19262 breakpoint set on exit from a function. The prologue and epilogue
19263 attributes allow a compiler to communicate the location(s) to use. */
19266 if (fde->dw_fde_vms_end_prologue)
19267 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19268 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19270 if (fde->dw_fde_vms_begin_epilogue)
19271 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19272 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19276 add_pubname (decl, subr_die);
19279 { /* Generate pubnames entries for the split function code
19281 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19283 if (fde->dw_fde_second_begin)
19285 if (dwarf_version >= 3 || !dwarf_strict)
19287 /* We should use ranges for non-contiguous code section
19288 addresses. Use the actual code range for the initial
19289 section, since the HOT/COLD labels might precede an
19290 alignment offset. */
19291 bool range_list_added = false;
19292 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
19293 fde->dw_fde_end, &range_list_added);
19294 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
19295 fde->dw_fde_second_end,
19296 &range_list_added);
19297 add_pubname (decl, subr_die);
19298 if (range_list_added)
19303 /* There is no real support in DW2 for this .. so we make
19304 a work-around. First, emit the pub name for the segment
19305 containing the function label. Then make and emit a
19306 simplified subprogram DIE for the second segment with the
19307 name pre-fixed by __hot/cold_sect_of_. We use the same
19308 linkage name for the second die so that gdb will find both
19309 sections when given "b foo". */
19310 const char *name = NULL;
19311 tree decl_name = DECL_NAME (decl);
19312 dw_die_ref seg_die;
19314 /* Do the 'primary' section. */
19315 add_AT_lbl_id (subr_die, DW_AT_low_pc,
19316 fde->dw_fde_begin);
19317 add_AT_lbl_id (subr_die, DW_AT_high_pc,
19320 add_pubname (decl, subr_die);
19322 /* Build a minimal DIE for the secondary section. */
19323 seg_die = new_die (DW_TAG_subprogram,
19324 subr_die->die_parent, decl);
19326 if (TREE_PUBLIC (decl))
19327 add_AT_flag (seg_die, DW_AT_external, 1);
19329 if (decl_name != NULL
19330 && IDENTIFIER_POINTER (decl_name) != NULL)
19332 name = dwarf2_name (decl, 1);
19333 if (! DECL_ARTIFICIAL (decl))
19334 add_src_coords_attributes (seg_die, decl);
19336 add_linkage_name (seg_die, decl);
19338 gcc_assert (name != NULL);
19339 add_pure_or_virtual_attribute (seg_die, decl);
19340 if (DECL_ARTIFICIAL (decl))
19341 add_AT_flag (seg_die, DW_AT_artificial, 1);
19343 name = concat ("__second_sect_of_", name, NULL);
19344 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19345 fde->dw_fde_second_begin);
19346 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19347 fde->dw_fde_second_end);
19348 add_name_attribute (seg_die, name);
19349 add_pubname_string (name, seg_die);
19354 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19355 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19356 add_pubname (decl, subr_die);
19360 #ifdef MIPS_DEBUGGING_INFO
19361 /* Add a reference to the FDE for this routine. */
19362 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19365 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19367 /* We define the "frame base" as the function's CFA. This is more
19368 convenient for several reasons: (1) It's stable across the prologue
19369 and epilogue, which makes it better than just a frame pointer,
19370 (2) With dwarf3, there exists a one-byte encoding that allows us
19371 to reference the .debug_frame data by proxy, but failing that,
19372 (3) We can at least reuse the code inspection and interpretation
19373 code that determines the CFA position at various points in the
19375 if (dwarf_version >= 3)
19377 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19378 add_AT_loc (subr_die, DW_AT_frame_base, op);
19382 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19383 if (list->dw_loc_next)
19384 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19386 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19389 /* Compute a displacement from the "steady-state frame pointer" to
19390 the CFA. The former is what all stack slots and argument slots
19391 will reference in the rtl; the later is what we've told the
19392 debugger about. We'll need to adjust all frame_base references
19393 by this displacement. */
19394 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19396 if (cfun->static_chain_decl)
19397 add_AT_location_description (subr_die, DW_AT_static_link,
19398 loc_list_from_tree (cfun->static_chain_decl, 2));
19401 /* Generate child dies for template paramaters. */
19402 if (debug_info_level > DINFO_LEVEL_TERSE)
19403 gen_generic_params_dies (decl);
19405 /* Now output descriptions of the arguments for this function. This gets
19406 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19407 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19408 `...' at the end of the formal parameter list. In order to find out if
19409 there was a trailing ellipsis or not, we must instead look at the type
19410 associated with the FUNCTION_DECL. This will be a node of type
19411 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19412 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19413 an ellipsis at the end. */
19415 /* In the case where we are describing a mere function declaration, all we
19416 need to do here (and all we *can* do here) is to describe the *types* of
19417 its formal parameters. */
19418 if (debug_info_level <= DINFO_LEVEL_TERSE)
19420 else if (declaration)
19421 gen_formal_types_die (decl, subr_die);
19424 /* Generate DIEs to represent all known formal parameters. */
19425 tree parm = DECL_ARGUMENTS (decl);
19426 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19427 tree generic_decl_parm = generic_decl
19428 ? DECL_ARGUMENTS (generic_decl)
19431 /* Now we want to walk the list of parameters of the function and
19432 emit their relevant DIEs.
19434 We consider the case of DECL being an instance of a generic function
19435 as well as it being a normal function.
19437 If DECL is an instance of a generic function we walk the
19438 parameters of the generic function declaration _and_ the parameters of
19439 DECL itself. This is useful because we want to emit specific DIEs for
19440 function parameter packs and those are declared as part of the
19441 generic function declaration. In that particular case,
19442 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19443 That DIE has children DIEs representing the set of arguments
19444 of the pack. Note that the set of pack arguments can be empty.
19445 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19448 Otherwise, we just consider the parameters of DECL. */
19449 while (generic_decl_parm || parm)
19451 if (generic_decl_parm
19452 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19453 gen_formal_parameter_pack_die (generic_decl_parm,
19458 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19460 if (parm == DECL_ARGUMENTS (decl)
19461 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19463 && (dwarf_version >= 3 || !dwarf_strict))
19464 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19466 parm = DECL_CHAIN (parm);
19469 if (generic_decl_parm)
19470 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19473 /* Decide whether we need an unspecified_parameters DIE at the end.
19474 There are 2 more cases to do this for: 1) the ansi ... declaration -
19475 this is detectable when the end of the arg list is not a
19476 void_type_node 2) an unprototyped function declaration (not a
19477 definition). This just means that we have no info about the
19478 parameters at all. */
19479 if (prototype_p (TREE_TYPE (decl)))
19481 /* This is the prototyped case, check for.... */
19482 if (stdarg_p (TREE_TYPE (decl)))
19483 gen_unspecified_parameters_die (decl, subr_die);
19485 else if (DECL_INITIAL (decl) == NULL_TREE)
19486 gen_unspecified_parameters_die (decl, subr_die);
19489 /* Output Dwarf info for all of the stuff within the body of the function
19490 (if it has one - it may be just a declaration). */
19491 outer_scope = DECL_INITIAL (decl);
19493 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19494 a function. This BLOCK actually represents the outermost binding contour
19495 for the function, i.e. the contour in which the function's formal
19496 parameters and labels get declared. Curiously, it appears that the front
19497 end doesn't actually put the PARM_DECL nodes for the current function onto
19498 the BLOCK_VARS list for this outer scope, but are strung off of the
19499 DECL_ARGUMENTS list for the function instead.
19501 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19502 the LABEL_DECL nodes for the function however, and we output DWARF info
19503 for those in decls_for_scope. Just within the `outer_scope' there will be
19504 a BLOCK node representing the function's outermost pair of curly braces,
19505 and any blocks used for the base and member initializers of a C++
19506 constructor function. */
19507 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19509 int call_site_note_count = 0;
19510 int tail_call_site_note_count = 0;
19512 /* Emit a DW_TAG_variable DIE for a named return value. */
19513 if (DECL_NAME (DECL_RESULT (decl)))
19514 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19516 current_function_has_inlines = 0;
19517 decls_for_scope (outer_scope, subr_die, 0);
19519 if (call_arg_locations && !dwarf_strict)
19521 struct call_arg_loc_node *ca_loc;
19522 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
19524 dw_die_ref die = NULL;
19525 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
19528 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
19529 arg; arg = next_arg)
19531 dw_loc_descr_ref reg, val;
19532 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
19535 next_arg = XEXP (arg, 1);
19536 if (REG_P (XEXP (XEXP (arg, 0), 0))
19538 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
19539 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
19540 && REGNO (XEXP (XEXP (arg, 0), 0))
19541 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
19542 next_arg = XEXP (next_arg, 1);
19543 if (mode == VOIDmode)
19545 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
19546 if (mode == VOIDmode)
19547 mode = GET_MODE (XEXP (arg, 0));
19549 if (GET_MODE_CLASS (mode) != MODE_INT
19550 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
19552 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
19554 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19555 tloc = XEXP (XEXP (arg, 0), 1);
19558 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
19559 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
19561 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19562 tlocc = XEXP (XEXP (arg, 0), 1);
19565 if (REG_P (XEXP (XEXP (arg, 0), 0)))
19566 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
19567 VAR_INIT_STATUS_INITIALIZED);
19568 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
19569 reg = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 0),
19571 VAR_INIT_STATUS_INITIALIZED);
19576 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), VOIDmode,
19577 VAR_INIT_STATUS_INITIALIZED);
19581 die = gen_call_site_die (decl, subr_die, ca_loc);
19582 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
19584 add_AT_loc (cdie, DW_AT_location, reg);
19585 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
19586 if (next_arg != XEXP (arg, 1))
19588 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
19590 VAR_INIT_STATUS_INITIALIZED);
19592 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
19596 && (ca_loc->symbol_ref || tloc))
19597 die = gen_call_site_die (decl, subr_die, ca_loc);
19598 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
19600 dw_loc_descr_ref tval = NULL;
19602 if (tloc != NULL_RTX)
19603 tval = mem_loc_descriptor (tloc, VOIDmode,
19604 VAR_INIT_STATUS_INITIALIZED);
19606 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
19607 else if (tlocc != NULL_RTX)
19609 tval = mem_loc_descriptor (tlocc, VOIDmode,
19610 VAR_INIT_STATUS_INITIALIZED);
19612 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
19618 call_site_note_count++;
19619 if (ca_loc->tail_call_p)
19620 tail_call_site_note_count++;
19624 call_arg_locations = NULL;
19625 call_arg_loc_last = NULL;
19626 if (tail_call_site_count >= 0
19627 && tail_call_site_count == tail_call_site_note_count
19630 if (call_site_count >= 0
19631 && call_site_count == call_site_note_count)
19632 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
19634 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
19636 call_site_count = -1;
19637 tail_call_site_count = -1;
19639 /* Add the calling convention attribute if requested. */
19640 add_calling_convention_attribute (subr_die, decl);
19644 /* Returns a hash value for X (which really is a die_struct). */
19647 common_block_die_table_hash (const void *x)
19649 const_dw_die_ref d = (const_dw_die_ref) x;
19650 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19653 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19654 as decl_id and die_parent of die_struct Y. */
19657 common_block_die_table_eq (const void *x, const void *y)
19659 const_dw_die_ref d = (const_dw_die_ref) x;
19660 const_dw_die_ref e = (const_dw_die_ref) y;
19661 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19664 /* Generate a DIE to represent a declared data object.
19665 Either DECL or ORIGIN must be non-null. */
19668 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19672 tree decl_or_origin = decl ? decl : origin;
19673 tree ultimate_origin;
19674 dw_die_ref var_die;
19675 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19676 dw_die_ref origin_die;
19677 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19678 || class_or_namespace_scope_p (context_die));
19679 bool specialization_p = false;
19681 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19682 if (decl || ultimate_origin)
19683 origin = ultimate_origin;
19684 com_decl = fortran_common (decl_or_origin, &off);
19686 /* Symbol in common gets emitted as a child of the common block, in the form
19687 of a data member. */
19690 dw_die_ref com_die;
19691 dw_loc_list_ref loc;
19692 die_node com_die_arg;
19694 var_die = lookup_decl_die (decl_or_origin);
19697 if (get_AT (var_die, DW_AT_location) == NULL)
19699 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19704 /* Optimize the common case. */
19705 if (single_element_loc_list_p (loc)
19706 && loc->expr->dw_loc_opc == DW_OP_addr
19707 && loc->expr->dw_loc_next == NULL
19708 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19710 loc->expr->dw_loc_oprnd1.v.val_addr
19711 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19713 loc_list_plus_const (loc, off);
19715 add_AT_location_description (var_die, DW_AT_location, loc);
19716 remove_AT (var_die, DW_AT_declaration);
19722 if (common_block_die_table == NULL)
19723 common_block_die_table
19724 = htab_create_ggc (10, common_block_die_table_hash,
19725 common_block_die_table_eq, NULL);
19727 com_die_arg.decl_id = DECL_UID (com_decl);
19728 com_die_arg.die_parent = context_die;
19729 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19730 loc = loc_list_from_tree (com_decl, 2);
19731 if (com_die == NULL)
19734 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19737 com_die = new_die (DW_TAG_common_block, context_die, decl);
19738 add_name_and_src_coords_attributes (com_die, com_decl);
19741 add_AT_location_description (com_die, DW_AT_location, loc);
19742 /* Avoid sharing the same loc descriptor between
19743 DW_TAG_common_block and DW_TAG_variable. */
19744 loc = loc_list_from_tree (com_decl, 2);
19746 else if (DECL_EXTERNAL (decl))
19747 add_AT_flag (com_die, DW_AT_declaration, 1);
19748 add_pubname_string (cnam, com_die); /* ??? needed? */
19749 com_die->decl_id = DECL_UID (com_decl);
19750 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19751 *slot = (void *) com_die;
19753 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19755 add_AT_location_description (com_die, DW_AT_location, loc);
19756 loc = loc_list_from_tree (com_decl, 2);
19757 remove_AT (com_die, DW_AT_declaration);
19759 var_die = new_die (DW_TAG_variable, com_die, decl);
19760 add_name_and_src_coords_attributes (var_die, decl);
19761 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19762 TREE_THIS_VOLATILE (decl), context_die);
19763 add_AT_flag (var_die, DW_AT_external, 1);
19768 /* Optimize the common case. */
19769 if (single_element_loc_list_p (loc)
19770 && loc->expr->dw_loc_opc == DW_OP_addr
19771 && loc->expr->dw_loc_next == NULL
19772 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19773 loc->expr->dw_loc_oprnd1.v.val_addr
19774 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19776 loc_list_plus_const (loc, off);
19778 add_AT_location_description (var_die, DW_AT_location, loc);
19780 else if (DECL_EXTERNAL (decl))
19781 add_AT_flag (var_die, DW_AT_declaration, 1);
19782 equate_decl_number_to_die (decl, var_die);
19786 /* If the compiler emitted a definition for the DECL declaration
19787 and if we already emitted a DIE for it, don't emit a second
19788 DIE for it again. Allow re-declarations of DECLs that are
19789 inside functions, though. */
19790 if (old_die && declaration && !local_scope_p (context_die))
19793 /* For static data members, the declaration in the class is supposed
19794 to have DW_TAG_member tag; the specification should still be
19795 DW_TAG_variable referencing the DW_TAG_member DIE. */
19796 if (declaration && class_scope_p (context_die))
19797 var_die = new_die (DW_TAG_member, context_die, decl);
19799 var_die = new_die (DW_TAG_variable, context_die, decl);
19802 if (origin != NULL)
19803 origin_die = add_abstract_origin_attribute (var_die, origin);
19805 /* Loop unrolling can create multiple blocks that refer to the same
19806 static variable, so we must test for the DW_AT_declaration flag.
19808 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19809 copy decls and set the DECL_ABSTRACT flag on them instead of
19812 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19814 ??? The declare_in_namespace support causes us to get two DIEs for one
19815 variable, both of which are declarations. We want to avoid considering
19816 one to be a specification, so we must test that this DIE is not a
19818 else if (old_die && TREE_STATIC (decl) && ! declaration
19819 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19821 /* This is a definition of a C++ class level static. */
19822 add_AT_specification (var_die, old_die);
19823 specialization_p = true;
19824 if (DECL_NAME (decl))
19826 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19827 struct dwarf_file_data * file_index = lookup_filename (s.file);
19829 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19830 add_AT_file (var_die, DW_AT_decl_file, file_index);
19832 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19833 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19835 if (old_die->die_tag == DW_TAG_member)
19836 add_linkage_name (var_die, decl);
19840 add_name_and_src_coords_attributes (var_die, decl);
19842 if ((origin == NULL && !specialization_p)
19844 && !DECL_ABSTRACT (decl_or_origin)
19845 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19846 decl_function_context
19847 (decl_or_origin))))
19849 tree type = TREE_TYPE (decl_or_origin);
19851 if (decl_by_reference_p (decl_or_origin))
19852 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19854 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19855 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19858 if (origin == NULL && !specialization_p)
19860 if (TREE_PUBLIC (decl))
19861 add_AT_flag (var_die, DW_AT_external, 1);
19863 if (DECL_ARTIFICIAL (decl))
19864 add_AT_flag (var_die, DW_AT_artificial, 1);
19866 add_accessibility_attribute (var_die, decl);
19870 add_AT_flag (var_die, DW_AT_declaration, 1);
19872 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19873 equate_decl_number_to_die (decl, var_die);
19876 && (! DECL_ABSTRACT (decl_or_origin)
19877 /* Local static vars are shared between all clones/inlines,
19878 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19880 || (TREE_CODE (decl_or_origin) == VAR_DECL
19881 && TREE_STATIC (decl_or_origin)
19882 && DECL_RTL_SET_P (decl_or_origin)))
19883 /* When abstract origin already has DW_AT_location attribute, no need
19884 to add it again. */
19885 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19887 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19888 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19889 defer_location (decl_or_origin, var_die);
19891 add_location_or_const_value_attribute (var_die, decl_or_origin,
19892 decl == NULL, DW_AT_location);
19893 add_pubname (decl_or_origin, var_die);
19896 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19899 /* Generate a DIE to represent a named constant. */
19902 gen_const_die (tree decl, dw_die_ref context_die)
19904 dw_die_ref const_die;
19905 tree type = TREE_TYPE (decl);
19907 const_die = new_die (DW_TAG_constant, context_die, decl);
19908 add_name_and_src_coords_attributes (const_die, decl);
19909 add_type_attribute (const_die, type, 1, 0, context_die);
19910 if (TREE_PUBLIC (decl))
19911 add_AT_flag (const_die, DW_AT_external, 1);
19912 if (DECL_ARTIFICIAL (decl))
19913 add_AT_flag (const_die, DW_AT_artificial, 1);
19914 tree_add_const_value_attribute_for_decl (const_die, decl);
19917 /* Generate a DIE to represent a label identifier. */
19920 gen_label_die (tree decl, dw_die_ref context_die)
19922 tree origin = decl_ultimate_origin (decl);
19923 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19925 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19927 if (origin != NULL)
19928 add_abstract_origin_attribute (lbl_die, origin);
19930 add_name_and_src_coords_attributes (lbl_die, decl);
19932 if (DECL_ABSTRACT (decl))
19933 equate_decl_number_to_die (decl, lbl_die);
19936 insn = DECL_RTL_IF_SET (decl);
19938 /* Deleted labels are programmer specified labels which have been
19939 eliminated because of various optimizations. We still emit them
19940 here so that it is possible to put breakpoints on them. */
19944 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19946 /* When optimization is enabled (via -O) some parts of the compiler
19947 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19948 represent source-level labels which were explicitly declared by
19949 the user. This really shouldn't be happening though, so catch
19950 it if it ever does happen. */
19951 gcc_assert (!INSN_DELETED_P (insn));
19953 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19954 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19959 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19960 attributes to the DIE for a block STMT, to describe where the inlined
19961 function was called from. This is similar to add_src_coords_attributes. */
19964 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19966 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19968 if (dwarf_version >= 3 || !dwarf_strict)
19970 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19971 add_AT_unsigned (die, DW_AT_call_line, s.line);
19976 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19977 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19980 add_high_low_attributes (tree stmt, dw_die_ref die)
19982 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19984 if (BLOCK_FRAGMENT_CHAIN (stmt)
19985 && (dwarf_version >= 3 || !dwarf_strict))
19989 if (inlined_function_outer_scope_p (stmt))
19991 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19992 BLOCK_NUMBER (stmt));
19993 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19996 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19998 chain = BLOCK_FRAGMENT_CHAIN (stmt);
20001 add_ranges (chain);
20002 chain = BLOCK_FRAGMENT_CHAIN (chain);
20009 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
20010 BLOCK_NUMBER (stmt));
20011 add_AT_lbl_id (die, DW_AT_low_pc, label);
20012 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
20013 BLOCK_NUMBER (stmt));
20014 add_AT_lbl_id (die, DW_AT_high_pc, label);
20018 /* Generate a DIE for a lexical block. */
20021 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
20023 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
20025 if (call_arg_locations)
20027 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
20028 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
20029 BLOCK_NUMBER (stmt) + 1);
20030 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
20033 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
20034 add_high_low_attributes (stmt, stmt_die);
20036 decls_for_scope (stmt, stmt_die, depth);
20039 /* Generate a DIE for an inlined subprogram. */
20042 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
20046 /* The instance of function that is effectively being inlined shall not
20048 gcc_assert (! BLOCK_ABSTRACT (stmt));
20050 decl = block_ultimate_origin (stmt);
20052 /* Emit info for the abstract instance first, if we haven't yet. We
20053 must emit this even if the block is abstract, otherwise when we
20054 emit the block below (or elsewhere), we may end up trying to emit
20055 a die whose origin die hasn't been emitted, and crashing. */
20056 dwarf2out_abstract_function (decl);
20058 if (! BLOCK_ABSTRACT (stmt))
20060 dw_die_ref subr_die
20061 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
20063 if (call_arg_locations)
20065 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
20066 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
20067 BLOCK_NUMBER (stmt) + 1);
20068 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
20070 add_abstract_origin_attribute (subr_die, decl);
20071 if (TREE_ASM_WRITTEN (stmt))
20072 add_high_low_attributes (stmt, subr_die);
20073 add_call_src_coords_attributes (stmt, subr_die);
20075 decls_for_scope (stmt, subr_die, depth);
20076 current_function_has_inlines = 1;
20080 /* Generate a DIE for a field in a record, or structure. */
20083 gen_field_die (tree decl, dw_die_ref context_die)
20085 dw_die_ref decl_die;
20087 if (TREE_TYPE (decl) == error_mark_node)
20090 decl_die = new_die (DW_TAG_member, context_die, decl);
20091 add_name_and_src_coords_attributes (decl_die, decl);
20092 add_type_attribute (decl_die, member_declared_type (decl),
20093 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
20096 if (DECL_BIT_FIELD_TYPE (decl))
20098 add_byte_size_attribute (decl_die, decl);
20099 add_bit_size_attribute (decl_die, decl);
20100 add_bit_offset_attribute (decl_die, decl);
20103 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
20104 add_data_member_location_attribute (decl_die, decl);
20106 if (DECL_ARTIFICIAL (decl))
20107 add_AT_flag (decl_die, DW_AT_artificial, 1);
20109 add_accessibility_attribute (decl_die, decl);
20111 /* Equate decl number to die, so that we can look up this decl later on. */
20112 equate_decl_number_to_die (decl, decl_die);
20116 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20117 Use modified_type_die instead.
20118 We keep this code here just in case these types of DIEs may be needed to
20119 represent certain things in other languages (e.g. Pascal) someday. */
20122 gen_pointer_type_die (tree type, dw_die_ref context_die)
20125 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20127 equate_type_number_to_die (type, ptr_die);
20128 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20129 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20132 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20133 Use modified_type_die instead.
20134 We keep this code here just in case these types of DIEs may be needed to
20135 represent certain things in other languages (e.g. Pascal) someday. */
20138 gen_reference_type_die (tree type, dw_die_ref context_die)
20140 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20142 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
20143 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20145 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20147 equate_type_number_to_die (type, ref_die);
20148 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
20149 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20153 /* Generate a DIE for a pointer to a member type. */
20156 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20159 = new_die (DW_TAG_ptr_to_member_type,
20160 scope_die_for (type, context_die), type);
20162 equate_type_number_to_die (type, ptr_die);
20163 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20164 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20165 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20168 /* Generate the DIE for the compilation unit. */
20171 gen_compile_unit_die (const char *filename)
20174 char producer[250];
20175 const char *language_string = lang_hooks.name;
20178 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20182 add_name_attribute (die, filename);
20183 /* Don't add cwd for <built-in>. */
20184 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20185 add_comp_dir_attribute (die);
20188 sprintf (producer, "%s %s", language_string, version_string);
20190 #ifdef MIPS_DEBUGGING_INFO
20191 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20192 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20193 not appear in the producer string, the debugger reaches the conclusion
20194 that the object file is stripped and has no debugging information.
20195 To get the MIPS/SGI debugger to believe that there is debugging
20196 information in the object file, we add a -g to the producer string. */
20197 if (debug_info_level > DINFO_LEVEL_TERSE)
20198 strcat (producer, " -g");
20201 add_AT_string (die, DW_AT_producer, producer);
20203 /* If our producer is LTO try to figure out a common language to use
20204 from the global list of translation units. */
20205 if (strcmp (language_string, "GNU GIMPLE") == 0)
20209 const char *common_lang = NULL;
20211 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
20213 if (!TRANSLATION_UNIT_LANGUAGE (t))
20216 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20217 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20219 else if (strncmp (common_lang, "GNU C", 5) == 0
20220 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20221 /* Mixing C and C++ is ok, use C++ in that case. */
20222 common_lang = "GNU C++";
20225 /* Fall back to C. */
20226 common_lang = NULL;
20232 language_string = common_lang;
20235 language = DW_LANG_C89;
20236 if (strcmp (language_string, "GNU C++") == 0)
20237 language = DW_LANG_C_plus_plus;
20238 else if (strcmp (language_string, "GNU F77") == 0)
20239 language = DW_LANG_Fortran77;
20240 else if (strcmp (language_string, "GNU Pascal") == 0)
20241 language = DW_LANG_Pascal83;
20242 else if (dwarf_version >= 3 || !dwarf_strict)
20244 if (strcmp (language_string, "GNU Ada") == 0)
20245 language = DW_LANG_Ada95;
20246 else if (strcmp (language_string, "GNU Fortran") == 0)
20247 language = DW_LANG_Fortran95;
20248 else if (strcmp (language_string, "GNU Java") == 0)
20249 language = DW_LANG_Java;
20250 else if (strcmp (language_string, "GNU Objective-C") == 0)
20251 language = DW_LANG_ObjC;
20252 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20253 language = DW_LANG_ObjC_plus_plus;
20256 add_AT_unsigned (die, DW_AT_language, language);
20260 case DW_LANG_Fortran77:
20261 case DW_LANG_Fortran90:
20262 case DW_LANG_Fortran95:
20263 /* Fortran has case insensitive identifiers and the front-end
20264 lowercases everything. */
20265 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20268 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20274 /* Generate the DIE for a base class. */
20277 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20279 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20281 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
20282 add_data_member_location_attribute (die, binfo);
20284 if (BINFO_VIRTUAL_P (binfo))
20285 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20287 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20288 children, otherwise the default is DW_ACCESS_public. In DWARF2
20289 the default has always been DW_ACCESS_private. */
20290 if (access == access_public_node)
20292 if (dwarf_version == 2
20293 || context_die->die_tag == DW_TAG_class_type)
20294 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20296 else if (access == access_protected_node)
20297 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20298 else if (dwarf_version > 2
20299 && context_die->die_tag != DW_TAG_class_type)
20300 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20303 /* Generate a DIE for a class member. */
20306 gen_member_die (tree type, dw_die_ref context_die)
20309 tree binfo = TYPE_BINFO (type);
20312 /* If this is not an incomplete type, output descriptions of each of its
20313 members. Note that as we output the DIEs necessary to represent the
20314 members of this record or union type, we will also be trying to output
20315 DIEs to represent the *types* of those members. However the `type'
20316 function (above) will specifically avoid generating type DIEs for member
20317 types *within* the list of member DIEs for this (containing) type except
20318 for those types (of members) which are explicitly marked as also being
20319 members of this (containing) type themselves. The g++ front- end can
20320 force any given type to be treated as a member of some other (containing)
20321 type by setting the TYPE_CONTEXT of the given (member) type to point to
20322 the TREE node representing the appropriate (containing) type. */
20324 /* First output info about the base classes. */
20327 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
20331 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20332 gen_inheritance_die (base,
20333 (accesses ? VEC_index (tree, accesses, i)
20334 : access_public_node), context_die);
20337 /* Now output info about the data members and type members. */
20338 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20340 /* If we thought we were generating minimal debug info for TYPE
20341 and then changed our minds, some of the member declarations
20342 may have already been defined. Don't define them again, but
20343 do put them in the right order. */
20345 child = lookup_decl_die (member);
20347 splice_child_die (context_die, child);
20349 gen_decl_die (member, NULL, context_die);
20352 /* Now output info about the function members (if any). */
20353 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20355 /* Don't include clones in the member list. */
20356 if (DECL_ABSTRACT_ORIGIN (member))
20359 child = lookup_decl_die (member);
20361 splice_child_die (context_die, child);
20363 gen_decl_die (member, NULL, context_die);
20367 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20368 is set, we pretend that the type was never defined, so we only get the
20369 member DIEs needed by later specification DIEs. */
20372 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20373 enum debug_info_usage usage)
20375 dw_die_ref type_die = lookup_type_die (type);
20376 dw_die_ref scope_die = 0;
20378 int complete = (TYPE_SIZE (type)
20379 && (! TYPE_STUB_DECL (type)
20380 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20381 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20382 complete = complete && should_emit_struct_debug (type, usage);
20384 if (type_die && ! complete)
20387 if (TYPE_CONTEXT (type) != NULL_TREE
20388 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20389 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20392 scope_die = scope_die_for (type, context_die);
20394 if (! type_die || (nested && is_cu_die (scope_die)))
20395 /* First occurrence of type or toplevel definition of nested class. */
20397 dw_die_ref old_die = type_die;
20399 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20400 ? record_type_tag (type) : DW_TAG_union_type,
20402 equate_type_number_to_die (type, type_die);
20404 add_AT_specification (type_die, old_die);
20406 add_name_attribute (type_die, type_tag (type));
20409 remove_AT (type_die, DW_AT_declaration);
20411 /* Generate child dies for template paramaters. */
20412 if (debug_info_level > DINFO_LEVEL_TERSE
20413 && COMPLETE_TYPE_P (type))
20414 schedule_generic_params_dies_gen (type);
20416 /* If this type has been completed, then give it a byte_size attribute and
20417 then give a list of members. */
20418 if (complete && !ns_decl)
20420 /* Prevent infinite recursion in cases where the type of some member of
20421 this type is expressed in terms of this type itself. */
20422 TREE_ASM_WRITTEN (type) = 1;
20423 add_byte_size_attribute (type_die, type);
20424 if (TYPE_STUB_DECL (type) != NULL_TREE)
20426 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20427 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20430 /* If the first reference to this type was as the return type of an
20431 inline function, then it may not have a parent. Fix this now. */
20432 if (type_die->die_parent == NULL)
20433 add_child_die (scope_die, type_die);
20435 push_decl_scope (type);
20436 gen_member_die (type, type_die);
20439 /* GNU extension: Record what type our vtable lives in. */
20440 if (TYPE_VFIELD (type))
20442 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20444 gen_type_die (vtype, context_die);
20445 add_AT_die_ref (type_die, DW_AT_containing_type,
20446 lookup_type_die (vtype));
20451 add_AT_flag (type_die, DW_AT_declaration, 1);
20453 /* We don't need to do this for function-local types. */
20454 if (TYPE_STUB_DECL (type)
20455 && ! decl_function_context (TYPE_STUB_DECL (type)))
20456 VEC_safe_push (tree, gc, incomplete_types, type);
20459 if (get_AT (type_die, DW_AT_name))
20460 add_pubtype (type, type_die);
20463 /* Generate a DIE for a subroutine _type_. */
20466 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20468 tree return_type = TREE_TYPE (type);
20469 dw_die_ref subr_die
20470 = new_die (DW_TAG_subroutine_type,
20471 scope_die_for (type, context_die), type);
20473 equate_type_number_to_die (type, subr_die);
20474 add_prototyped_attribute (subr_die, type);
20475 add_type_attribute (subr_die, return_type, 0, 0, context_die);
20476 gen_formal_types_die (type, subr_die);
20478 if (get_AT (subr_die, DW_AT_name))
20479 add_pubtype (type, subr_die);
20482 /* Generate a DIE for a type definition. */
20485 gen_typedef_die (tree decl, dw_die_ref context_die)
20487 dw_die_ref type_die;
20490 if (TREE_ASM_WRITTEN (decl))
20493 TREE_ASM_WRITTEN (decl) = 1;
20494 type_die = new_die (DW_TAG_typedef, context_die, decl);
20495 origin = decl_ultimate_origin (decl);
20496 if (origin != NULL)
20497 add_abstract_origin_attribute (type_die, origin);
20502 add_name_and_src_coords_attributes (type_die, decl);
20503 if (DECL_ORIGINAL_TYPE (decl))
20505 type = DECL_ORIGINAL_TYPE (decl);
20507 gcc_assert (type != TREE_TYPE (decl));
20508 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20512 type = TREE_TYPE (decl);
20514 if (is_naming_typedef_decl (TYPE_NAME (type)))
20516 /* Here, we are in the case of decl being a typedef naming
20517 an anonymous type, e.g:
20518 typedef struct {...} foo;
20519 In that case TREE_TYPE (decl) is not a typedef variant
20520 type and TYPE_NAME of the anonymous type is set to the
20521 TYPE_DECL of the typedef. This construct is emitted by
20524 TYPE is the anonymous struct named by the typedef
20525 DECL. As we need the DW_AT_type attribute of the
20526 DW_TAG_typedef to point to the DIE of TYPE, let's
20527 generate that DIE right away. add_type_attribute
20528 called below will then pick (via lookup_type_die) that
20529 anonymous struct DIE. */
20530 if (!TREE_ASM_WRITTEN (type))
20531 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20533 /* This is a GNU Extension. We are adding a
20534 DW_AT_linkage_name attribute to the DIE of the
20535 anonymous struct TYPE. The value of that attribute
20536 is the name of the typedef decl naming the anonymous
20537 struct. This greatly eases the work of consumers of
20538 this debug info. */
20539 add_linkage_attr (lookup_type_die (type), decl);
20543 add_type_attribute (type_die, type, TREE_READONLY (decl),
20544 TREE_THIS_VOLATILE (decl), context_die);
20546 if (is_naming_typedef_decl (decl))
20547 /* We want that all subsequent calls to lookup_type_die with
20548 TYPE in argument yield the DW_TAG_typedef we have just
20550 equate_type_number_to_die (type, type_die);
20552 add_accessibility_attribute (type_die, decl);
20555 if (DECL_ABSTRACT (decl))
20556 equate_decl_number_to_die (decl, type_die);
20558 if (get_AT (type_die, DW_AT_name))
20559 add_pubtype (decl, type_die);
20562 /* Generate a DIE for a struct, class, enum or union type. */
20565 gen_tagged_type_die (tree type,
20566 dw_die_ref context_die,
20567 enum debug_info_usage usage)
20571 if (type == NULL_TREE
20572 || !is_tagged_type (type))
20575 /* If this is a nested type whose containing class hasn't been written
20576 out yet, writing it out will cover this one, too. This does not apply
20577 to instantiations of member class templates; they need to be added to
20578 the containing class as they are generated. FIXME: This hurts the
20579 idea of combining type decls from multiple TUs, since we can't predict
20580 what set of template instantiations we'll get. */
20581 if (TYPE_CONTEXT (type)
20582 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20583 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20585 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20587 if (TREE_ASM_WRITTEN (type))
20590 /* If that failed, attach ourselves to the stub. */
20591 push_decl_scope (TYPE_CONTEXT (type));
20592 context_die = lookup_type_die (TYPE_CONTEXT (type));
20595 else if (TYPE_CONTEXT (type) != NULL_TREE
20596 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20598 /* If this type is local to a function that hasn't been written
20599 out yet, use a NULL context for now; it will be fixed up in
20600 decls_for_scope. */
20601 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20602 /* A declaration DIE doesn't count; nested types need to go in the
20604 if (context_die && is_declaration_die (context_die))
20605 context_die = NULL;
20610 context_die = declare_in_namespace (type, context_die);
20614 if (TREE_CODE (type) == ENUMERAL_TYPE)
20616 /* This might have been written out by the call to
20617 declare_in_namespace. */
20618 if (!TREE_ASM_WRITTEN (type))
20619 gen_enumeration_type_die (type, context_die);
20622 gen_struct_or_union_type_die (type, context_die, usage);
20627 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20628 it up if it is ever completed. gen_*_type_die will set it for us
20629 when appropriate. */
20632 /* Generate a type description DIE. */
20635 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20636 enum debug_info_usage usage)
20638 struct array_descr_info info;
20640 if (type == NULL_TREE || type == error_mark_node)
20643 if (TYPE_NAME (type) != NULL_TREE
20644 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
20645 && is_redundant_typedef (TYPE_NAME (type))
20646 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
20647 /* The DECL of this type is a typedef we don't want to emit debug
20648 info for but we want debug info for its underlying typedef.
20649 This can happen for e.g, the injected-class-name of a C++
20651 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
20653 /* If TYPE is a typedef type variant, let's generate debug info
20654 for the parent typedef which TYPE is a type of. */
20655 if (typedef_variant_p (type))
20657 if (TREE_ASM_WRITTEN (type))
20660 /* Prevent broken recursion; we can't hand off to the same type. */
20661 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20663 /* Use the DIE of the containing namespace as the parent DIE of
20664 the type description DIE we want to generate. */
20665 if (DECL_CONTEXT (TYPE_NAME (type))
20666 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20667 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20669 TREE_ASM_WRITTEN (type) = 1;
20671 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20675 /* If type is an anonymous tagged type named by a typedef, let's
20676 generate debug info for the typedef. */
20677 if (is_naming_typedef_decl (TYPE_NAME (type)))
20679 /* Use the DIE of the containing namespace as the parent DIE of
20680 the type description DIE we want to generate. */
20681 if (DECL_CONTEXT (TYPE_NAME (type))
20682 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20683 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20685 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20689 /* If this is an array type with hidden descriptor, handle it first. */
20690 if (!TREE_ASM_WRITTEN (type)
20691 && lang_hooks.types.get_array_descr_info
20692 && lang_hooks.types.get_array_descr_info (type, &info)
20693 && (dwarf_version >= 3 || !dwarf_strict))
20695 gen_descr_array_type_die (type, &info, context_die);
20696 TREE_ASM_WRITTEN (type) = 1;
20700 /* We are going to output a DIE to represent the unqualified version
20701 of this type (i.e. without any const or volatile qualifiers) so
20702 get the main variant (i.e. the unqualified version) of this type
20703 now. (Vectors are special because the debugging info is in the
20704 cloned type itself). */
20705 if (TREE_CODE (type) != VECTOR_TYPE)
20706 type = type_main_variant (type);
20708 if (TREE_ASM_WRITTEN (type))
20711 switch (TREE_CODE (type))
20717 case REFERENCE_TYPE:
20718 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20719 ensures that the gen_type_die recursion will terminate even if the
20720 type is recursive. Recursive types are possible in Ada. */
20721 /* ??? We could perhaps do this for all types before the switch
20723 TREE_ASM_WRITTEN (type) = 1;
20725 /* For these types, all that is required is that we output a DIE (or a
20726 set of DIEs) to represent the "basis" type. */
20727 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20728 DINFO_USAGE_IND_USE);
20732 /* This code is used for C++ pointer-to-data-member types.
20733 Output a description of the relevant class type. */
20734 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20735 DINFO_USAGE_IND_USE);
20737 /* Output a description of the type of the object pointed to. */
20738 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20739 DINFO_USAGE_IND_USE);
20741 /* Now output a DIE to represent this pointer-to-data-member type
20743 gen_ptr_to_mbr_type_die (type, context_die);
20746 case FUNCTION_TYPE:
20747 /* Force out return type (in case it wasn't forced out already). */
20748 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20749 DINFO_USAGE_DIR_USE);
20750 gen_subroutine_type_die (type, context_die);
20754 /* Force out return type (in case it wasn't forced out already). */
20755 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20756 DINFO_USAGE_DIR_USE);
20757 gen_subroutine_type_die (type, context_die);
20761 gen_array_type_die (type, context_die);
20765 gen_array_type_die (type, context_die);
20768 case ENUMERAL_TYPE:
20771 case QUAL_UNION_TYPE:
20772 gen_tagged_type_die (type, context_die, usage);
20778 case FIXED_POINT_TYPE:
20781 /* No DIEs needed for fundamental types. */
20786 /* Just use DW_TAG_unspecified_type. */
20788 dw_die_ref type_die = lookup_type_die (type);
20789 if (type_die == NULL)
20791 tree name = TYPE_NAME (type);
20792 if (TREE_CODE (name) == TYPE_DECL)
20793 name = DECL_NAME (name);
20794 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
20795 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20796 equate_type_number_to_die (type, type_die);
20802 gcc_unreachable ();
20805 TREE_ASM_WRITTEN (type) = 1;
20809 gen_type_die (tree type, dw_die_ref context_die)
20811 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20814 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20815 things which are local to the given block. */
20818 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20820 int must_output_die = 0;
20823 /* Ignore blocks that are NULL. */
20824 if (stmt == NULL_TREE)
20827 inlined_func = inlined_function_outer_scope_p (stmt);
20829 /* If the block is one fragment of a non-contiguous block, do not
20830 process the variables, since they will have been done by the
20831 origin block. Do process subblocks. */
20832 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20836 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20837 gen_block_die (sub, context_die, depth + 1);
20842 /* Determine if we need to output any Dwarf DIEs at all to represent this
20845 /* The outer scopes for inlinings *must* always be represented. We
20846 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20847 must_output_die = 1;
20850 /* Determine if this block directly contains any "significant"
20851 local declarations which we will need to output DIEs for. */
20852 if (debug_info_level > DINFO_LEVEL_TERSE)
20853 /* We are not in terse mode so *any* local declaration counts
20854 as being a "significant" one. */
20855 must_output_die = ((BLOCK_VARS (stmt) != NULL
20856 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20857 && (TREE_USED (stmt)
20858 || TREE_ASM_WRITTEN (stmt)
20859 || BLOCK_ABSTRACT (stmt)));
20860 else if ((TREE_USED (stmt)
20861 || TREE_ASM_WRITTEN (stmt)
20862 || BLOCK_ABSTRACT (stmt))
20863 && !dwarf2out_ignore_block (stmt))
20864 must_output_die = 1;
20867 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20868 DIE for any block which contains no significant local declarations at
20869 all. Rather, in such cases we just call `decls_for_scope' so that any
20870 needed Dwarf info for any sub-blocks will get properly generated. Note
20871 that in terse mode, our definition of what constitutes a "significant"
20872 local declaration gets restricted to include only inlined function
20873 instances and local (nested) function definitions. */
20874 if (must_output_die)
20878 /* If STMT block is abstract, that means we have been called
20879 indirectly from dwarf2out_abstract_function.
20880 That function rightfully marks the descendent blocks (of
20881 the abstract function it is dealing with) as being abstract,
20882 precisely to prevent us from emitting any
20883 DW_TAG_inlined_subroutine DIE as a descendent
20884 of an abstract function instance. So in that case, we should
20885 not call gen_inlined_subroutine_die.
20887 Later though, when cgraph asks dwarf2out to emit info
20888 for the concrete instance of the function decl into which
20889 the concrete instance of STMT got inlined, the later will lead
20890 to the generation of a DW_TAG_inlined_subroutine DIE. */
20891 if (! BLOCK_ABSTRACT (stmt))
20892 gen_inlined_subroutine_die (stmt, context_die, depth);
20895 gen_lexical_block_die (stmt, context_die, depth);
20898 decls_for_scope (stmt, context_die, depth);
20901 /* Process variable DECL (or variable with origin ORIGIN) within
20902 block STMT and add it to CONTEXT_DIE. */
20904 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20907 tree decl_or_origin = decl ? decl : origin;
20909 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20910 die = lookup_decl_die (decl_or_origin);
20911 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20912 && TYPE_DECL_IS_STUB (decl_or_origin))
20913 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20917 if (die != NULL && die->die_parent == NULL)
20918 add_child_die (context_die, die);
20919 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20920 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20921 stmt, context_die);
20923 gen_decl_die (decl, origin, context_die);
20926 /* Generate all of the decls declared within a given scope and (recursively)
20927 all of its sub-blocks. */
20930 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20936 /* Ignore NULL blocks. */
20937 if (stmt == NULL_TREE)
20940 /* Output the DIEs to represent all of the data objects and typedefs
20941 declared directly within this block but not within any nested
20942 sub-blocks. Also, nested function and tag DIEs have been
20943 generated with a parent of NULL; fix that up now. */
20944 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20945 process_scope_var (stmt, decl, NULL_TREE, context_die);
20946 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20947 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20950 /* If we're at -g1, we're not interested in subblocks. */
20951 if (debug_info_level <= DINFO_LEVEL_TERSE)
20954 /* Output the DIEs to represent all sub-blocks (and the items declared
20955 therein) of this block. */
20956 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20958 subblocks = BLOCK_CHAIN (subblocks))
20959 gen_block_die (subblocks, context_die, depth + 1);
20962 /* Is this a typedef we can avoid emitting? */
20965 is_redundant_typedef (const_tree decl)
20967 if (TYPE_DECL_IS_STUB (decl))
20970 if (DECL_ARTIFICIAL (decl)
20971 && DECL_CONTEXT (decl)
20972 && is_tagged_type (DECL_CONTEXT (decl))
20973 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20974 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20975 /* Also ignore the artificial member typedef for the class name. */
20981 /* Return TRUE if TYPE is a typedef that names a type for linkage
20982 purposes. This kind of typedefs is produced by the C++ FE for
20985 typedef struct {...} foo;
20987 In that case, there is no typedef variant type produced for foo.
20988 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20992 is_naming_typedef_decl (const_tree decl)
20994 if (decl == NULL_TREE
20995 || TREE_CODE (decl) != TYPE_DECL
20996 || !is_tagged_type (TREE_TYPE (decl))
20997 || DECL_IS_BUILTIN (decl)
20998 || is_redundant_typedef (decl)
20999 /* It looks like Ada produces TYPE_DECLs that are very similar
21000 to C++ naming typedefs but that have different
21001 semantics. Let's be specific to c++ for now. */
21005 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
21006 && TYPE_NAME (TREE_TYPE (decl)) == decl
21007 && (TYPE_STUB_DECL (TREE_TYPE (decl))
21008 != TYPE_NAME (TREE_TYPE (decl))));
21011 /* Returns the DIE for a context. */
21013 static inline dw_die_ref
21014 get_context_die (tree context)
21018 /* Find die that represents this context. */
21019 if (TYPE_P (context))
21021 context = TYPE_MAIN_VARIANT (context);
21022 return strip_naming_typedef (context, force_type_die (context));
21025 return force_decl_die (context);
21027 return comp_unit_die ();
21030 /* Returns the DIE for decl. A DIE will always be returned. */
21033 force_decl_die (tree decl)
21035 dw_die_ref decl_die;
21036 unsigned saved_external_flag;
21037 tree save_fn = NULL_TREE;
21038 decl_die = lookup_decl_die (decl);
21041 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
21043 decl_die = lookup_decl_die (decl);
21047 switch (TREE_CODE (decl))
21049 case FUNCTION_DECL:
21050 /* Clear current_function_decl, so that gen_subprogram_die thinks
21051 that this is a declaration. At this point, we just want to force
21052 declaration die. */
21053 save_fn = current_function_decl;
21054 current_function_decl = NULL_TREE;
21055 gen_subprogram_die (decl, context_die);
21056 current_function_decl = save_fn;
21060 /* Set external flag to force declaration die. Restore it after
21061 gen_decl_die() call. */
21062 saved_external_flag = DECL_EXTERNAL (decl);
21063 DECL_EXTERNAL (decl) = 1;
21064 gen_decl_die (decl, NULL, context_die);
21065 DECL_EXTERNAL (decl) = saved_external_flag;
21068 case NAMESPACE_DECL:
21069 if (dwarf_version >= 3 || !dwarf_strict)
21070 dwarf2out_decl (decl);
21072 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21073 decl_die = comp_unit_die ();
21076 case TRANSLATION_UNIT_DECL:
21077 decl_die = comp_unit_die ();
21081 gcc_unreachable ();
21084 /* We should be able to find the DIE now. */
21086 decl_die = lookup_decl_die (decl);
21087 gcc_assert (decl_die);
21093 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21094 always returned. */
21097 force_type_die (tree type)
21099 dw_die_ref type_die;
21101 type_die = lookup_type_die (type);
21104 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21106 type_die = modified_type_die (type, TYPE_READONLY (type),
21107 TYPE_VOLATILE (type), context_die);
21108 gcc_assert (type_die);
21113 /* Force out any required namespaces to be able to output DECL,
21114 and return the new context_die for it, if it's changed. */
21117 setup_namespace_context (tree thing, dw_die_ref context_die)
21119 tree context = (DECL_P (thing)
21120 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21121 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21122 /* Force out the namespace. */
21123 context_die = force_decl_die (context);
21125 return context_die;
21128 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21129 type) within its namespace, if appropriate.
21131 For compatibility with older debuggers, namespace DIEs only contain
21132 declarations; all definitions are emitted at CU scope. */
21135 declare_in_namespace (tree thing, dw_die_ref context_die)
21137 dw_die_ref ns_context;
21139 if (debug_info_level <= DINFO_LEVEL_TERSE)
21140 return context_die;
21142 /* If this decl is from an inlined function, then don't try to emit it in its
21143 namespace, as we will get confused. It would have already been emitted
21144 when the abstract instance of the inline function was emitted anyways. */
21145 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21146 return context_die;
21148 ns_context = setup_namespace_context (thing, context_die);
21150 if (ns_context != context_die)
21154 if (DECL_P (thing))
21155 gen_decl_die (thing, NULL, ns_context);
21157 gen_type_die (thing, ns_context);
21159 return context_die;
21162 /* Generate a DIE for a namespace or namespace alias. */
21165 gen_namespace_die (tree decl, dw_die_ref context_die)
21167 dw_die_ref namespace_die;
21169 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21170 they are an alias of. */
21171 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21173 /* Output a real namespace or module. */
21174 context_die = setup_namespace_context (decl, comp_unit_die ());
21175 namespace_die = new_die (is_fortran ()
21176 ? DW_TAG_module : DW_TAG_namespace,
21177 context_die, decl);
21178 /* For Fortran modules defined in different CU don't add src coords. */
21179 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21181 const char *name = dwarf2_name (decl, 0);
21183 add_name_attribute (namespace_die, name);
21186 add_name_and_src_coords_attributes (namespace_die, decl);
21187 if (DECL_EXTERNAL (decl))
21188 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21189 equate_decl_number_to_die (decl, namespace_die);
21193 /* Output a namespace alias. */
21195 /* Force out the namespace we are an alias of, if necessary. */
21196 dw_die_ref origin_die
21197 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21199 if (DECL_FILE_SCOPE_P (decl)
21200 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21201 context_die = setup_namespace_context (decl, comp_unit_die ());
21202 /* Now create the namespace alias DIE. */
21203 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21204 add_name_and_src_coords_attributes (namespace_die, decl);
21205 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21206 equate_decl_number_to_die (decl, namespace_die);
21210 /* Generate Dwarf debug information for a decl described by DECL.
21211 The return value is currently only meaningful for PARM_DECLs,
21212 for all other decls it returns NULL. */
21215 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21217 tree decl_or_origin = decl ? decl : origin;
21218 tree class_origin = NULL, ultimate_origin;
21220 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21223 switch (TREE_CODE (decl_or_origin))
21229 if (!is_fortran () && !is_ada ())
21231 /* The individual enumerators of an enum type get output when we output
21232 the Dwarf representation of the relevant enum type itself. */
21236 /* Emit its type. */
21237 gen_type_die (TREE_TYPE (decl), context_die);
21239 /* And its containing namespace. */
21240 context_die = declare_in_namespace (decl, context_die);
21242 gen_const_die (decl, context_die);
21245 case FUNCTION_DECL:
21246 /* Don't output any DIEs to represent mere function declarations,
21247 unless they are class members or explicit block externs. */
21248 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21249 && DECL_FILE_SCOPE_P (decl_or_origin)
21250 && (current_function_decl == NULL_TREE
21251 || DECL_ARTIFICIAL (decl_or_origin)))
21256 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21257 on local redeclarations of global functions. That seems broken. */
21258 if (current_function_decl != decl)
21259 /* This is only a declaration. */;
21262 /* If we're emitting a clone, emit info for the abstract instance. */
21263 if (origin || DECL_ORIGIN (decl) != decl)
21264 dwarf2out_abstract_function (origin
21265 ? DECL_ORIGIN (origin)
21266 : DECL_ABSTRACT_ORIGIN (decl));
21268 /* If we're emitting an out-of-line copy of an inline function,
21269 emit info for the abstract instance and set up to refer to it. */
21270 else if (cgraph_function_possibly_inlined_p (decl)
21271 && ! DECL_ABSTRACT (decl)
21272 && ! class_or_namespace_scope_p (context_die)
21273 /* dwarf2out_abstract_function won't emit a die if this is just
21274 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21275 that case, because that works only if we have a die. */
21276 && DECL_INITIAL (decl) != NULL_TREE)
21278 dwarf2out_abstract_function (decl);
21279 set_decl_origin_self (decl);
21282 /* Otherwise we're emitting the primary DIE for this decl. */
21283 else if (debug_info_level > DINFO_LEVEL_TERSE)
21285 /* Before we describe the FUNCTION_DECL itself, make sure that we
21286 have its containing type. */
21288 origin = decl_class_context (decl);
21289 if (origin != NULL_TREE)
21290 gen_type_die (origin, context_die);
21292 /* And its return type. */
21293 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21295 /* And its virtual context. */
21296 if (DECL_VINDEX (decl) != NULL_TREE)
21297 gen_type_die (DECL_CONTEXT (decl), context_die);
21299 /* Make sure we have a member DIE for decl. */
21300 if (origin != NULL_TREE)
21301 gen_type_die_for_member (origin, decl, context_die);
21303 /* And its containing namespace. */
21304 context_die = declare_in_namespace (decl, context_die);
21307 /* Now output a DIE to represent the function itself. */
21309 gen_subprogram_die (decl, context_die);
21313 /* If we are in terse mode, don't generate any DIEs to represent any
21314 actual typedefs. */
21315 if (debug_info_level <= DINFO_LEVEL_TERSE)
21318 /* In the special case of a TYPE_DECL node representing the declaration
21319 of some type tag, if the given TYPE_DECL is marked as having been
21320 instantiated from some other (original) TYPE_DECL node (e.g. one which
21321 was generated within the original definition of an inline function) we
21322 used to generate a special (abbreviated) DW_TAG_structure_type,
21323 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21324 should be actually referencing those DIEs, as variable DIEs with that
21325 type would be emitted already in the abstract origin, so it was always
21326 removed during unused type prunning. Don't add anything in this
21328 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21331 if (is_redundant_typedef (decl))
21332 gen_type_die (TREE_TYPE (decl), context_die);
21334 /* Output a DIE to represent the typedef itself. */
21335 gen_typedef_die (decl, context_die);
21339 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21340 gen_label_die (decl, context_die);
21345 /* If we are in terse mode, don't generate any DIEs to represent any
21346 variable declarations or definitions. */
21347 if (debug_info_level <= DINFO_LEVEL_TERSE)
21350 /* Output any DIEs that are needed to specify the type of this data
21352 if (decl_by_reference_p (decl_or_origin))
21353 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21355 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21357 /* And its containing type. */
21358 class_origin = decl_class_context (decl_or_origin);
21359 if (class_origin != NULL_TREE)
21360 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21362 /* And its containing namespace. */
21363 context_die = declare_in_namespace (decl_or_origin, context_die);
21365 /* Now output the DIE to represent the data object itself. This gets
21366 complicated because of the possibility that the VAR_DECL really
21367 represents an inlined instance of a formal parameter for an inline
21369 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21370 if (ultimate_origin != NULL_TREE
21371 && TREE_CODE (ultimate_origin) == PARM_DECL)
21372 gen_formal_parameter_die (decl, origin,
21373 true /* Emit name attribute. */,
21376 gen_variable_die (decl, origin, context_die);
21380 /* Ignore the nameless fields that are used to skip bits but handle C++
21381 anonymous unions and structs. */
21382 if (DECL_NAME (decl) != NULL_TREE
21383 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21384 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21386 gen_type_die (member_declared_type (decl), context_die);
21387 gen_field_die (decl, context_die);
21392 if (DECL_BY_REFERENCE (decl_or_origin))
21393 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21395 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21396 return gen_formal_parameter_die (decl, origin,
21397 true /* Emit name attribute. */,
21400 case NAMESPACE_DECL:
21401 case IMPORTED_DECL:
21402 if (dwarf_version >= 3 || !dwarf_strict)
21403 gen_namespace_die (decl, context_die);
21407 /* Probably some frontend-internal decl. Assume we don't care. */
21408 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21415 /* Output debug information for global decl DECL. Called from toplev.c after
21416 compilation proper has finished. */
21419 dwarf2out_global_decl (tree decl)
21421 /* Output DWARF2 information for file-scope tentative data object
21422 declarations, file-scope (extern) function declarations (which
21423 had no corresponding body) and file-scope tagged type declarations
21424 and definitions which have not yet been forced out. */
21425 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
21426 dwarf2out_decl (decl);
21429 /* Output debug information for type decl DECL. Called from toplev.c
21430 and from language front ends (to record built-in types). */
21432 dwarf2out_type_decl (tree decl, int local)
21435 dwarf2out_decl (decl);
21438 /* Output debug information for imported module or decl DECL.
21439 NAME is non-NULL name in the lexical block if the decl has been renamed.
21440 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21441 that DECL belongs to.
21442 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21444 dwarf2out_imported_module_or_decl_1 (tree decl,
21446 tree lexical_block,
21447 dw_die_ref lexical_block_die)
21449 expanded_location xloc;
21450 dw_die_ref imported_die = NULL;
21451 dw_die_ref at_import_die;
21453 if (TREE_CODE (decl) == IMPORTED_DECL)
21455 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21456 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21460 xloc = expand_location (input_location);
21462 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21464 at_import_die = force_type_die (TREE_TYPE (decl));
21465 /* For namespace N { typedef void T; } using N::T; base_type_die
21466 returns NULL, but DW_TAG_imported_declaration requires
21467 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21468 if (!at_import_die)
21470 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21471 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21472 at_import_die = lookup_type_die (TREE_TYPE (decl));
21473 gcc_assert (at_import_die);
21478 at_import_die = lookup_decl_die (decl);
21479 if (!at_import_die)
21481 /* If we're trying to avoid duplicate debug info, we may not have
21482 emitted the member decl for this field. Emit it now. */
21483 if (TREE_CODE (decl) == FIELD_DECL)
21485 tree type = DECL_CONTEXT (decl);
21487 if (TYPE_CONTEXT (type)
21488 && TYPE_P (TYPE_CONTEXT (type))
21489 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21490 DINFO_USAGE_DIR_USE))
21492 gen_type_die_for_member (type, decl,
21493 get_context_die (TYPE_CONTEXT (type)));
21495 at_import_die = force_decl_die (decl);
21499 if (TREE_CODE (decl) == NAMESPACE_DECL)
21501 if (dwarf_version >= 3 || !dwarf_strict)
21502 imported_die = new_die (DW_TAG_imported_module,
21509 imported_die = new_die (DW_TAG_imported_declaration,
21513 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21514 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21516 add_AT_string (imported_die, DW_AT_name,
21517 IDENTIFIER_POINTER (name));
21518 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21521 /* Output debug information for imported module or decl DECL.
21522 NAME is non-NULL name in context if the decl has been renamed.
21523 CHILD is true if decl is one of the renamed decls as part of
21524 importing whole module. */
21527 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21530 /* dw_die_ref at_import_die; */
21531 dw_die_ref scope_die;
21533 if (debug_info_level <= DINFO_LEVEL_TERSE)
21538 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21539 We need decl DIE for reference and scope die. First, get DIE for the decl
21542 /* Get the scope die for decl context. Use comp_unit_die for global module
21543 or decl. If die is not found for non globals, force new die. */
21545 && TYPE_P (context)
21546 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21549 if (!(dwarf_version >= 3 || !dwarf_strict))
21552 scope_die = get_context_die (context);
21556 gcc_assert (scope_die->die_child);
21557 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21558 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21559 scope_die = scope_die->die_child;
21562 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21563 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21567 /* Write the debugging output for DECL. */
21570 dwarf2out_decl (tree decl)
21572 dw_die_ref context_die = comp_unit_die ();
21574 switch (TREE_CODE (decl))
21579 case FUNCTION_DECL:
21580 /* What we would really like to do here is to filter out all mere
21581 file-scope declarations of file-scope functions which are never
21582 referenced later within this translation unit (and keep all of ones
21583 that *are* referenced later on) but we aren't clairvoyant, so we have
21584 no idea which functions will be referenced in the future (i.e. later
21585 on within the current translation unit). So here we just ignore all
21586 file-scope function declarations which are not also definitions. If
21587 and when the debugger needs to know something about these functions,
21588 it will have to hunt around and find the DWARF information associated
21589 with the definition of the function.
21591 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21592 nodes represent definitions and which ones represent mere
21593 declarations. We have to check DECL_INITIAL instead. That's because
21594 the C front-end supports some weird semantics for "extern inline"
21595 function definitions. These can get inlined within the current
21596 translation unit (and thus, we need to generate Dwarf info for their
21597 abstract instances so that the Dwarf info for the concrete inlined
21598 instances can have something to refer to) but the compiler never
21599 generates any out-of-lines instances of such things (despite the fact
21600 that they *are* definitions).
21602 The important point is that the C front-end marks these "extern
21603 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21604 them anyway. Note that the C++ front-end also plays some similar games
21605 for inline function definitions appearing within include files which
21606 also contain `#pragma interface' pragmas. */
21607 if (DECL_INITIAL (decl) == NULL_TREE)
21610 /* If we're a nested function, initially use a parent of NULL; if we're
21611 a plain function, this will be fixed up in decls_for_scope. If
21612 we're a method, it will be ignored, since we already have a DIE. */
21613 if (decl_function_context (decl)
21614 /* But if we're in terse mode, we don't care about scope. */
21615 && debug_info_level > DINFO_LEVEL_TERSE)
21616 context_die = NULL;
21620 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21621 declaration and if the declaration was never even referenced from
21622 within this entire compilation unit. We suppress these DIEs in
21623 order to save space in the .debug section (by eliminating entries
21624 which are probably useless). Note that we must not suppress
21625 block-local extern declarations (whether used or not) because that
21626 would screw-up the debugger's name lookup mechanism and cause it to
21627 miss things which really ought to be in scope at a given point. */
21628 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
21631 /* For local statics lookup proper context die. */
21632 if (TREE_STATIC (decl) && decl_function_context (decl))
21633 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21635 /* If we are in terse mode, don't generate any DIEs to represent any
21636 variable declarations or definitions. */
21637 if (debug_info_level <= DINFO_LEVEL_TERSE)
21642 if (debug_info_level <= DINFO_LEVEL_TERSE)
21644 if (!is_fortran () && !is_ada ())
21646 if (TREE_STATIC (decl) && decl_function_context (decl))
21647 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21650 case NAMESPACE_DECL:
21651 case IMPORTED_DECL:
21652 if (debug_info_level <= DINFO_LEVEL_TERSE)
21654 if (lookup_decl_die (decl) != NULL)
21659 /* Don't emit stubs for types unless they are needed by other DIEs. */
21660 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21663 /* Don't bother trying to generate any DIEs to represent any of the
21664 normal built-in types for the language we are compiling. */
21665 if (DECL_IS_BUILTIN (decl))
21668 /* If we are in terse mode, don't generate any DIEs for types. */
21669 if (debug_info_level <= DINFO_LEVEL_TERSE)
21672 /* If we're a function-scope tag, initially use a parent of NULL;
21673 this will be fixed up in decls_for_scope. */
21674 if (decl_function_context (decl))
21675 context_die = NULL;
21683 gen_decl_die (decl, NULL, context_die);
21686 /* Write the debugging output for DECL. */
21689 dwarf2out_function_decl (tree decl)
21691 dwarf2out_decl (decl);
21692 call_arg_locations = NULL;
21693 call_arg_loc_last = NULL;
21694 call_site_count = -1;
21695 tail_call_site_count = -1;
21696 VEC_free (dw_die_ref, heap, block_map);
21697 htab_empty (decl_loc_table);
21698 htab_empty (cached_dw_loc_list_table);
21701 /* Output a marker (i.e. a label) for the beginning of the generated code for
21702 a lexical block. */
21705 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21706 unsigned int blocknum)
21708 switch_to_section (current_function_section ());
21709 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21712 /* Output a marker (i.e. a label) for the end of the generated code for a
21716 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21718 switch_to_section (current_function_section ());
21719 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21722 /* Returns nonzero if it is appropriate not to emit any debugging
21723 information for BLOCK, because it doesn't contain any instructions.
21725 Don't allow this for blocks with nested functions or local classes
21726 as we would end up with orphans, and in the presence of scheduling
21727 we may end up calling them anyway. */
21730 dwarf2out_ignore_block (const_tree block)
21735 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21736 if (TREE_CODE (decl) == FUNCTION_DECL
21737 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21739 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21741 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21742 if (TREE_CODE (decl) == FUNCTION_DECL
21743 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21750 /* Hash table routines for file_hash. */
21753 file_table_eq (const void *p1_p, const void *p2_p)
21755 const struct dwarf_file_data *const p1 =
21756 (const struct dwarf_file_data *) p1_p;
21757 const char *const p2 = (const char *) p2_p;
21758 return filename_cmp (p1->filename, p2) == 0;
21762 file_table_hash (const void *p_p)
21764 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21765 return htab_hash_string (p->filename);
21768 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21769 dwarf2out.c) and return its "index". The index of each (known) filename is
21770 just a unique number which is associated with only that one filename. We
21771 need such numbers for the sake of generating labels (in the .debug_sfnames
21772 section) and references to those files numbers (in the .debug_srcinfo
21773 and.debug_macinfo sections). If the filename given as an argument is not
21774 found in our current list, add it to the list and assign it the next
21775 available unique index number. In order to speed up searches, we remember
21776 the index of the filename was looked up last. This handles the majority of
21779 static struct dwarf_file_data *
21780 lookup_filename (const char *file_name)
21783 struct dwarf_file_data * created;
21785 /* Check to see if the file name that was searched on the previous
21786 call matches this file name. If so, return the index. */
21787 if (file_table_last_lookup
21788 && (file_name == file_table_last_lookup->filename
21789 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
21790 return file_table_last_lookup;
21792 /* Didn't match the previous lookup, search the table. */
21793 slot = htab_find_slot_with_hash (file_table, file_name,
21794 htab_hash_string (file_name), INSERT);
21796 return (struct dwarf_file_data *) *slot;
21798 created = ggc_alloc_dwarf_file_data ();
21799 created->filename = file_name;
21800 created->emitted_number = 0;
21805 /* If the assembler will construct the file table, then translate the compiler
21806 internal file table number into the assembler file table number, and emit
21807 a .file directive if we haven't already emitted one yet. The file table
21808 numbers are different because we prune debug info for unused variables and
21809 types, which may include filenames. */
21812 maybe_emit_file (struct dwarf_file_data * fd)
21814 if (! fd->emitted_number)
21816 if (last_emitted_file)
21817 fd->emitted_number = last_emitted_file->emitted_number + 1;
21819 fd->emitted_number = 1;
21820 last_emitted_file = fd;
21822 if (DWARF2_ASM_LINE_DEBUG_INFO)
21824 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21825 output_quoted_string (asm_out_file,
21826 remap_debug_filename (fd->filename));
21827 fputc ('\n', asm_out_file);
21831 return fd->emitted_number;
21834 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21835 That generation should happen after function debug info has been
21836 generated. The value of the attribute is the constant value of ARG. */
21839 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21841 die_arg_entry entry;
21846 if (!tmpl_value_parm_die_table)
21847 tmpl_value_parm_die_table
21848 = VEC_alloc (die_arg_entry, gc, 32);
21852 VEC_safe_push (die_arg_entry, gc,
21853 tmpl_value_parm_die_table,
21857 /* Return TRUE if T is an instance of generic type, FALSE
21861 generic_type_p (tree t)
21863 if (t == NULL_TREE || !TYPE_P (t))
21865 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
21868 /* Schedule the generation of the generic parameter dies for the
21869 instance of generic type T. The proper generation itself is later
21870 done by gen_scheduled_generic_parms_dies. */
21873 schedule_generic_params_dies_gen (tree t)
21875 if (!generic_type_p (t))
21878 if (generic_type_instances == NULL)
21879 generic_type_instances = VEC_alloc (tree, gc, 256);
21881 VEC_safe_push (tree, gc, generic_type_instances, t);
21884 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21885 by append_entry_to_tmpl_value_parm_die_table. This function must
21886 be called after function DIEs have been generated. */
21889 gen_remaining_tmpl_value_param_die_attribute (void)
21891 if (tmpl_value_parm_die_table)
21896 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21897 tree_add_const_value_attribute (e->die, e->arg);
21901 /* Generate generic parameters DIEs for instances of generic types
21902 that have been previously scheduled by
21903 schedule_generic_params_dies_gen. This function must be called
21904 after all the types of the CU have been laid out. */
21907 gen_scheduled_generic_parms_dies (void)
21912 if (generic_type_instances == NULL)
21915 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
21916 gen_generic_params_dies (t);
21920 /* Replace DW_AT_name for the decl with name. */
21923 dwarf2out_set_name (tree decl, tree name)
21929 die = TYPE_SYMTAB_DIE (decl);
21933 dname = dwarf2_name (name, 0);
21937 attr = get_AT (die, DW_AT_name);
21940 struct indirect_string_node *node;
21942 node = find_AT_string (dname);
21943 /* replace the string. */
21944 attr->dw_attr_val.v.val_str = node;
21948 add_name_attribute (die, dname);
21951 /* Called by the final INSN scan whenever we see a var location. We
21952 use it to drop labels in the right places, and throw the location in
21953 our lookup table. */
21956 dwarf2out_var_location (rtx loc_note)
21958 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21959 struct var_loc_node *newloc;
21961 static const char *last_label;
21962 static const char *last_postcall_label;
21963 static bool last_in_cold_section_p;
21967 if (!NOTE_P (loc_note))
21969 if (CALL_P (loc_note))
21972 if (SIBLING_CALL_P (loc_note))
21973 tail_call_site_count++;
21978 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
21979 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21982 next_real = next_real_insn (loc_note);
21984 /* If there are no instructions which would be affected by this note,
21985 don't do anything. */
21987 && next_real == NULL_RTX
21988 && !NOTE_DURING_CALL_P (loc_note))
21991 if (next_real == NULL_RTX)
21992 next_real = get_last_insn ();
21994 /* If there were any real insns between note we processed last time
21995 and this note (or if it is the first note), clear
21996 last_{,postcall_}label so that they are not reused this time. */
21997 if (last_var_location_insn == NULL_RTX
21998 || last_var_location_insn != next_real
21999 || last_in_cold_section_p != in_cold_section_p)
22002 last_postcall_label = NULL;
22007 decl = NOTE_VAR_LOCATION_DECL (loc_note);
22008 newloc = add_var_loc_to_decl (decl, loc_note,
22009 NOTE_DURING_CALL_P (loc_note)
22010 ? last_postcall_label : last_label);
22011 if (newloc == NULL)
22020 /* If there were no real insns between note we processed last time
22021 and this note, use the label we emitted last time. Otherwise
22022 create a new label and emit it. */
22023 if (last_label == NULL)
22025 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
22026 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
22028 last_label = ggc_strdup (loclabel);
22033 struct call_arg_loc_node *ca_loc
22034 = ggc_alloc_cleared_call_arg_loc_node ();
22035 rtx prev = prev_real_insn (loc_note), x;
22036 ca_loc->call_arg_loc_note = loc_note;
22037 ca_loc->next = NULL;
22038 ca_loc->label = last_label;
22041 || (NONJUMP_INSN_P (prev)
22042 && GET_CODE (PATTERN (prev)) == SEQUENCE
22043 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
22044 if (!CALL_P (prev))
22045 prev = XVECEXP (PATTERN (prev), 0, 0);
22046 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
22047 x = PATTERN (prev);
22048 if (GET_CODE (x) == PARALLEL)
22049 x = XVECEXP (x, 0, 0);
22050 if (GET_CODE (x) == SET)
22052 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
22054 x = XEXP (XEXP (x, 0), 0);
22055 if (GET_CODE (x) == SYMBOL_REF
22056 && SYMBOL_REF_DECL (x)
22057 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
22058 ca_loc->symbol_ref = x;
22060 ca_loc->block = insn_scope (prev);
22061 if (call_arg_locations)
22062 call_arg_loc_last->next = ca_loc;
22064 call_arg_locations = ca_loc;
22065 call_arg_loc_last = ca_loc;
22067 else if (!NOTE_DURING_CALL_P (loc_note))
22068 newloc->label = last_label;
22071 if (!last_postcall_label)
22073 sprintf (loclabel, "%s-1", last_label);
22074 last_postcall_label = ggc_strdup (loclabel);
22076 newloc->label = last_postcall_label;
22079 last_var_location_insn = next_real;
22080 last_in_cold_section_p = in_cold_section_p;
22083 /* Note in one location list that text section has changed. */
22086 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
22088 var_loc_list *list = (var_loc_list *) *slot;
22090 list->last_before_switch
22091 = list->last->next ? list->last->next : list->last;
22095 /* Note in all location lists that text section has changed. */
22098 var_location_switch_text_section (void)
22100 if (decl_loc_table == NULL)
22103 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
22106 /* We need to reset the locations at the beginning of each
22107 function. We can't do this in the end_function hook, because the
22108 declarations that use the locations won't have been output when
22109 that hook is called. Also compute have_multiple_function_sections here. */
22112 dwarf2out_begin_function (tree fun)
22114 if (function_section (fun) != text_section)
22115 have_multiple_function_sections = true;
22116 if (flag_reorder_blocks_and_partition && !cold_text_section)
22118 gcc_assert (current_function_decl == fun);
22119 cold_text_section = unlikely_text_section ();
22120 switch_to_section (cold_text_section);
22121 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22122 switch_to_section (current_function_section ());
22125 dwarf2out_note_section_used ();
22126 call_site_count = 0;
22127 tail_call_site_count = 0;
22130 /* Output a label to mark the beginning of a source code line entry
22131 and record information relating to this source line, in
22132 'line_info_table' for later output of the .debug_line section. */
22135 dwarf2out_source_line (unsigned int line, const char *filename,
22136 int discriminator, bool is_stmt)
22138 static bool last_is_stmt = true;
22140 if (debug_info_level >= DINFO_LEVEL_NORMAL
22143 int file_num = maybe_emit_file (lookup_filename (filename));
22145 switch_to_section (current_function_section ());
22147 /* If requested, emit something human-readable. */
22148 if (flag_debug_asm)
22149 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
22152 if (DWARF2_ASM_LINE_DEBUG_INFO)
22154 /* Emit the .loc directive understood by GNU as. */
22155 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
22156 if (is_stmt != last_is_stmt)
22158 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
22159 last_is_stmt = is_stmt;
22161 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
22162 fprintf (asm_out_file, " discriminator %d", discriminator);
22163 fputc ('\n', asm_out_file);
22165 /* Indicate that line number info exists. */
22166 line_info_table_in_use++;
22168 else if (function_section (current_function_decl) != text_section)
22170 dw_separate_line_info_ref line_info;
22171 targetm.asm_out.internal_label (asm_out_file,
22172 SEPARATE_LINE_CODE_LABEL,
22173 separate_line_info_table_in_use);
22175 /* Expand the line info table if necessary. */
22176 if (separate_line_info_table_in_use
22177 == separate_line_info_table_allocated)
22179 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22180 separate_line_info_table
22181 = GGC_RESIZEVEC (dw_separate_line_info_entry,
22182 separate_line_info_table,
22183 separate_line_info_table_allocated);
22184 memset (separate_line_info_table
22185 + separate_line_info_table_in_use,
22187 (LINE_INFO_TABLE_INCREMENT
22188 * sizeof (dw_separate_line_info_entry)));
22191 /* Add the new entry at the end of the line_info_table. */
22193 = &separate_line_info_table[separate_line_info_table_in_use++];
22194 line_info->dw_file_num = file_num;
22195 line_info->dw_line_num = line;
22196 line_info->function = current_function_funcdef_no;
22200 dw_line_info_ref line_info;
22202 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
22203 line_info_table_in_use);
22205 /* Expand the line info table if necessary. */
22206 if (line_info_table_in_use == line_info_table_allocated)
22208 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22210 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
22211 line_info_table_allocated);
22212 memset (line_info_table + line_info_table_in_use, 0,
22213 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
22216 /* Add the new entry at the end of the line_info_table. */
22217 line_info = &line_info_table[line_info_table_in_use++];
22218 line_info->dw_file_num = file_num;
22219 line_info->dw_line_num = line;
22224 /* Record the beginning of a new source file. */
22227 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22229 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22231 /* Record the beginning of the file for break_out_includes. */
22232 dw_die_ref bincl_die;
22234 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22235 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22238 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22241 e.code = DW_MACINFO_start_file;
22243 e.info = xstrdup (filename);
22244 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22248 /* Record the end of a source file. */
22251 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22253 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22254 /* Record the end of the file for break_out_includes. */
22255 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22257 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22260 e.code = DW_MACINFO_end_file;
22263 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22267 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22268 the tail part of the directive line, i.e. the part which is past the
22269 initial whitespace, #, whitespace, directive-name, whitespace part. */
22272 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22273 const char *buffer ATTRIBUTE_UNUSED)
22275 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22278 e.code = DW_MACINFO_define;
22280 e.info = xstrdup (buffer);;
22281 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22285 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22286 the tail part of the directive line, i.e. the part which is past the
22287 initial whitespace, #, whitespace, directive-name, whitespace part. */
22290 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22291 const char *buffer ATTRIBUTE_UNUSED)
22293 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22296 e.code = DW_MACINFO_undef;
22298 e.info = xstrdup (buffer);;
22299 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22304 output_macinfo (void)
22307 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
22308 macinfo_entry *ref;
22313 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
22317 case DW_MACINFO_start_file:
22319 int file_num = maybe_emit_file (lookup_filename (ref->info));
22320 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22321 dw2_asm_output_data_uleb128
22322 (ref->lineno, "Included from line number %lu",
22323 (unsigned long)ref->lineno);
22324 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22327 case DW_MACINFO_end_file:
22328 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22330 case DW_MACINFO_define:
22331 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
22332 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22333 (unsigned long)ref->lineno);
22334 dw2_asm_output_nstring (ref->info, -1, "The macro");
22336 case DW_MACINFO_undef:
22337 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
22338 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22339 (unsigned long)ref->lineno);
22340 dw2_asm_output_nstring (ref->info, -1, "The macro");
22343 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22344 ASM_COMMENT_START, (unsigned long)ref->code);
22350 /* Set up for Dwarf output at the start of compilation. */
22353 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
22355 /* Allocate the file_table. */
22356 file_table = htab_create_ggc (50, file_table_hash,
22357 file_table_eq, NULL);
22359 /* Allocate the decl_die_table. */
22360 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
22361 decl_die_table_eq, NULL);
22363 /* Allocate the decl_loc_table. */
22364 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
22365 decl_loc_table_eq, NULL);
22367 /* Allocate the cached_dw_loc_list_table. */
22368 cached_dw_loc_list_table
22369 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
22370 cached_dw_loc_list_table_eq, NULL);
22372 /* Allocate the initial hunk of the decl_scope_table. */
22373 decl_scope_table = VEC_alloc (tree, gc, 256);
22375 /* Allocate the initial hunk of the abbrev_die_table. */
22376 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
22377 (ABBREV_DIE_TABLE_INCREMENT);
22378 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
22379 /* Zero-th entry is allocated, but unused. */
22380 abbrev_die_table_in_use = 1;
22382 /* Allocate the initial hunk of the line_info_table. */
22383 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
22384 (LINE_INFO_TABLE_INCREMENT);
22385 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
22387 /* Zero-th entry is allocated, but unused. */
22388 line_info_table_in_use = 1;
22390 /* Allocate the pubtypes and pubnames vectors. */
22391 pubname_table = VEC_alloc (pubname_entry, gc, 32);
22392 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
22394 incomplete_types = VEC_alloc (tree, gc, 64);
22396 used_rtx_array = VEC_alloc (rtx, gc, 32);
22398 debug_info_section = get_section (DEBUG_INFO_SECTION,
22399 SECTION_DEBUG, NULL);
22400 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
22401 SECTION_DEBUG, NULL);
22402 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
22403 SECTION_DEBUG, NULL);
22404 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
22405 SECTION_DEBUG, NULL);
22406 debug_line_section = get_section (DEBUG_LINE_SECTION,
22407 SECTION_DEBUG, NULL);
22408 debug_loc_section = get_section (DEBUG_LOC_SECTION,
22409 SECTION_DEBUG, NULL);
22410 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
22411 SECTION_DEBUG, NULL);
22412 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
22413 SECTION_DEBUG, NULL);
22414 debug_str_section = get_section (DEBUG_STR_SECTION,
22415 DEBUG_STR_SECTION_FLAGS, NULL);
22416 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
22417 SECTION_DEBUG, NULL);
22418 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
22419 SECTION_DEBUG, NULL);
22421 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
22422 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
22423 DEBUG_ABBREV_SECTION_LABEL, 0);
22424 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
22425 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
22426 COLD_TEXT_SECTION_LABEL, 0);
22427 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
22429 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
22430 DEBUG_INFO_SECTION_LABEL, 0);
22431 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
22432 DEBUG_LINE_SECTION_LABEL, 0);
22433 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
22434 DEBUG_RANGES_SECTION_LABEL, 0);
22435 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
22436 DEBUG_MACINFO_SECTION_LABEL, 0);
22438 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22439 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
22441 switch_to_section (text_section);
22442 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
22445 /* Called before cgraph_optimize starts outputtting functions, variables
22446 and toplevel asms into assembly. */
22449 dwarf2out_assembly_start (void)
22451 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22452 && dwarf2out_do_cfi_asm ()
22453 && (!(flag_unwind_tables || flag_exceptions)
22454 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
22455 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
22458 /* A helper function for dwarf2out_finish called through
22459 htab_traverse. Emit one queued .debug_str string. */
22462 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22464 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22466 if (node->label && node->refcount)
22468 switch_to_section (debug_str_section);
22469 ASM_OUTPUT_LABEL (asm_out_file, node->label);
22470 assemble_string (node->str, strlen (node->str) + 1);
22476 #if ENABLE_ASSERT_CHECKING
22477 /* Verify that all marks are clear. */
22480 verify_marks_clear (dw_die_ref die)
22484 gcc_assert (! die->die_mark);
22485 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
22487 #endif /* ENABLE_ASSERT_CHECKING */
22489 /* Clear the marks for a die and its children.
22490 Be cool if the mark isn't set. */
22493 prune_unmark_dies (dw_die_ref die)
22499 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
22502 /* Given DIE that we're marking as used, find any other dies
22503 it references as attributes and mark them as used. */
22506 prune_unused_types_walk_attribs (dw_die_ref die)
22511 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22513 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
22515 /* A reference to another DIE.
22516 Make sure that it will get emitted.
22517 If it was broken out into a comdat group, don't follow it. */
22518 if (dwarf_version < 4
22519 || a->dw_attr == DW_AT_specification
22520 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
22521 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
22523 /* Set the string's refcount to 0 so that prune_unused_types_mark
22524 accounts properly for it. */
22525 if (AT_class (a) == dw_val_class_str)
22526 a->dw_attr_val.v.val_str->refcount = 0;
22530 /* Mark the generic parameters and arguments children DIEs of DIE. */
22533 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
22537 if (die == NULL || die->die_child == NULL)
22539 c = die->die_child;
22542 switch (c->die_tag)
22544 case DW_TAG_template_type_param:
22545 case DW_TAG_template_value_param:
22546 case DW_TAG_GNU_template_template_param:
22547 case DW_TAG_GNU_template_parameter_pack:
22548 prune_unused_types_mark (c, 1);
22554 } while (c && c != die->die_child);
22557 /* Mark DIE as being used. If DOKIDS is true, then walk down
22558 to DIE's children. */
22561 prune_unused_types_mark (dw_die_ref die, int dokids)
22565 if (die->die_mark == 0)
22567 /* We haven't done this node yet. Mark it as used. */
22569 /* If this is the DIE of a generic type instantiation,
22570 mark the children DIEs that describe its generic parms and
22572 prune_unused_types_mark_generic_parms_dies (die);
22574 /* We also have to mark its parents as used.
22575 (But we don't want to mark our parents' kids due to this.) */
22576 if (die->die_parent)
22577 prune_unused_types_mark (die->die_parent, 0);
22579 /* Mark any referenced nodes. */
22580 prune_unused_types_walk_attribs (die);
22582 /* If this node is a specification,
22583 also mark the definition, if it exists. */
22584 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
22585 prune_unused_types_mark (die->die_definition, 1);
22588 if (dokids && die->die_mark != 2)
22590 /* We need to walk the children, but haven't done so yet.
22591 Remember that we've walked the kids. */
22594 /* If this is an array type, we need to make sure our
22595 kids get marked, even if they're types. If we're
22596 breaking out types into comdat sections, do this
22597 for all type definitions. */
22598 if (die->die_tag == DW_TAG_array_type
22599 || (dwarf_version >= 4
22600 && is_type_die (die) && ! is_declaration_die (die)))
22601 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
22603 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22607 /* For local classes, look if any static member functions were emitted
22608 and if so, mark them. */
22611 prune_unused_types_walk_local_classes (dw_die_ref die)
22615 if (die->die_mark == 2)
22618 switch (die->die_tag)
22620 case DW_TAG_structure_type:
22621 case DW_TAG_union_type:
22622 case DW_TAG_class_type:
22625 case DW_TAG_subprogram:
22626 if (!get_AT_flag (die, DW_AT_declaration)
22627 || die->die_definition != NULL)
22628 prune_unused_types_mark (die, 1);
22635 /* Mark children. */
22636 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
22639 /* Walk the tree DIE and mark types that we actually use. */
22642 prune_unused_types_walk (dw_die_ref die)
22646 /* Don't do anything if this node is already marked and
22647 children have been marked as well. */
22648 if (die->die_mark == 2)
22651 switch (die->die_tag)
22653 case DW_TAG_structure_type:
22654 case DW_TAG_union_type:
22655 case DW_TAG_class_type:
22656 if (die->die_perennial_p)
22659 for (c = die->die_parent; c; c = c->die_parent)
22660 if (c->die_tag == DW_TAG_subprogram)
22663 /* Finding used static member functions inside of classes
22664 is needed just for local classes, because for other classes
22665 static member function DIEs with DW_AT_specification
22666 are emitted outside of the DW_TAG_*_type. If we ever change
22667 it, we'd need to call this even for non-local classes. */
22669 prune_unused_types_walk_local_classes (die);
22671 /* It's a type node --- don't mark it. */
22674 case DW_TAG_const_type:
22675 case DW_TAG_packed_type:
22676 case DW_TAG_pointer_type:
22677 case DW_TAG_reference_type:
22678 case DW_TAG_rvalue_reference_type:
22679 case DW_TAG_volatile_type:
22680 case DW_TAG_typedef:
22681 case DW_TAG_array_type:
22682 case DW_TAG_interface_type:
22683 case DW_TAG_friend:
22684 case DW_TAG_variant_part:
22685 case DW_TAG_enumeration_type:
22686 case DW_TAG_subroutine_type:
22687 case DW_TAG_string_type:
22688 case DW_TAG_set_type:
22689 case DW_TAG_subrange_type:
22690 case DW_TAG_ptr_to_member_type:
22691 case DW_TAG_file_type:
22692 if (die->die_perennial_p)
22695 /* It's a type node --- don't mark it. */
22699 /* Mark everything else. */
22703 if (die->die_mark == 0)
22707 /* Now, mark any dies referenced from here. */
22708 prune_unused_types_walk_attribs (die);
22713 /* Mark children. */
22714 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22717 /* Increment the string counts on strings referred to from DIE's
22721 prune_unused_types_update_strings (dw_die_ref die)
22726 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22727 if (AT_class (a) == dw_val_class_str)
22729 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22731 /* Avoid unnecessarily putting strings that are used less than
22732 twice in the hash table. */
22734 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22737 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22738 htab_hash_string (s->str),
22740 gcc_assert (*slot == NULL);
22746 /* Remove from the tree DIE any dies that aren't marked. */
22749 prune_unused_types_prune (dw_die_ref die)
22753 gcc_assert (die->die_mark);
22754 prune_unused_types_update_strings (die);
22756 if (! die->die_child)
22759 c = die->die_child;
22761 dw_die_ref prev = c;
22762 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22763 if (c == die->die_child)
22765 /* No marked children between 'prev' and the end of the list. */
22767 /* No marked children at all. */
22768 die->die_child = NULL;
22771 prev->die_sib = c->die_sib;
22772 die->die_child = prev;
22777 if (c != prev->die_sib)
22779 prune_unused_types_prune (c);
22780 } while (c != die->die_child);
22783 /* A helper function for dwarf2out_finish called through
22784 htab_traverse. Clear .debug_str strings that we haven't already
22785 decided to emit. */
22788 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22790 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22792 if (!node->label || !node->refcount)
22793 htab_clear_slot (debug_str_hash, h);
22798 /* Remove dies representing declarations that we never use. */
22801 prune_unused_types (void)
22804 limbo_die_node *node;
22805 comdat_type_node *ctnode;
22808 #if ENABLE_ASSERT_CHECKING
22809 /* All the marks should already be clear. */
22810 verify_marks_clear (comp_unit_die ());
22811 for (node = limbo_die_list; node; node = node->next)
22812 verify_marks_clear (node->die);
22813 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22814 verify_marks_clear (ctnode->root_die);
22815 #endif /* ENABLE_ASSERT_CHECKING */
22817 /* Mark types that are used in global variables. */
22818 premark_types_used_by_global_vars ();
22820 /* Set the mark on nodes that are actually used. */
22821 prune_unused_types_walk (comp_unit_die ());
22822 for (node = limbo_die_list; node; node = node->next)
22823 prune_unused_types_walk (node->die);
22824 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22826 prune_unused_types_walk (ctnode->root_die);
22827 prune_unused_types_mark (ctnode->type_die, 1);
22830 /* Also set the mark on nodes referenced from the
22832 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22833 prune_unused_types_mark (pub->die, 1);
22835 /* Get rid of nodes that aren't marked; and update the string counts. */
22836 if (debug_str_hash && debug_str_hash_forced)
22837 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22838 else if (debug_str_hash)
22839 htab_empty (debug_str_hash);
22840 prune_unused_types_prune (comp_unit_die ());
22841 for (node = limbo_die_list; node; node = node->next)
22842 prune_unused_types_prune (node->die);
22843 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22844 prune_unused_types_prune (ctnode->root_die);
22846 /* Leave the marks clear. */
22847 prune_unmark_dies (comp_unit_die ());
22848 for (node = limbo_die_list; node; node = node->next)
22849 prune_unmark_dies (node->die);
22850 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22851 prune_unmark_dies (ctnode->root_die);
22854 /* Set the parameter to true if there are any relative pathnames in
22857 file_table_relative_p (void ** slot, void *param)
22859 bool *p = (bool *) param;
22860 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22861 if (!IS_ABSOLUTE_PATH (d->filename))
22869 /* Routines to manipulate hash table of comdat type units. */
22872 htab_ct_hash (const void *of)
22875 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22877 memcpy (&h, type_node->signature, sizeof (h));
22882 htab_ct_eq (const void *of1, const void *of2)
22884 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22885 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22887 return (! memcmp (type_node_1->signature, type_node_2->signature,
22888 DWARF_TYPE_SIGNATURE_SIZE));
22891 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22892 to the location it would have been added, should we know its
22893 DECL_ASSEMBLER_NAME when we added other attributes. This will
22894 probably improve compactness of debug info, removing equivalent
22895 abbrevs, and hide any differences caused by deferring the
22896 computation of the assembler name, triggered by e.g. PCH. */
22899 move_linkage_attr (dw_die_ref die)
22901 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22902 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22904 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22905 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22909 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22911 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22915 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22917 VEC_pop (dw_attr_node, die->die_attr);
22918 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22922 /* Helper function for resolve_addr, attempt to resolve
22923 one CONST_STRING, return non-zero if not successful. Similarly verify that
22924 SYMBOL_REFs refer to variables emitted in the current CU. */
22927 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22931 if (GET_CODE (rtl) == CONST_STRING)
22933 size_t len = strlen (XSTR (rtl, 0)) + 1;
22934 tree t = build_string (len, XSTR (rtl, 0));
22935 tree tlen = build_int_cst (NULL_TREE, len - 1);
22937 = build_array_type (char_type_node, build_index_type (tlen));
22938 rtl = lookup_constant_def (t);
22939 if (!rtl || !MEM_P (rtl))
22941 rtl = XEXP (rtl, 0);
22942 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22947 if (GET_CODE (rtl) == SYMBOL_REF
22948 && SYMBOL_REF_DECL (rtl))
22950 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
22952 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
22955 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22959 if (GET_CODE (rtl) == CONST
22960 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22966 /* Helper function for resolve_addr, handle one location
22967 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22968 the location list couldn't be resolved. */
22971 resolve_addr_in_expr (dw_loc_descr_ref loc)
22973 for (; loc; loc = loc->dw_loc_next)
22974 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22975 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22976 || (loc->dw_loc_opc == DW_OP_implicit_value
22977 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22978 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22980 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
22981 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
22984 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
22987 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
22988 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
22989 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
22994 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22995 an address in .rodata section if the string literal is emitted there,
22996 or remove the containing location list or replace DW_AT_const_value
22997 with DW_AT_location and empty location expression, if it isn't found
22998 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22999 to something that has been emitted in the current CU. */
23002 resolve_addr (dw_die_ref die)
23006 dw_loc_list_ref *curr, *start, loc;
23009 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23010 switch (AT_class (a))
23012 case dw_val_class_loc_list:
23013 start = curr = AT_loc_list_ptr (a);
23016 /* The same list can be referenced more than once. See if we have
23017 already recorded the result from a previous pass. */
23019 *curr = loc->dw_loc_next;
23020 else if (!loc->resolved_addr)
23022 /* As things stand, we do not expect or allow one die to
23023 reference a suffix of another die's location list chain.
23024 References must be identical or completely separate.
23025 There is therefore no need to cache the result of this
23026 pass on any list other than the first; doing so
23027 would lead to unnecessary writes. */
23030 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
23031 if (!resolve_addr_in_expr ((*curr)->expr))
23033 dw_loc_list_ref next = (*curr)->dw_loc_next;
23034 if (next && (*curr)->ll_symbol)
23036 gcc_assert (!next->ll_symbol);
23037 next->ll_symbol = (*curr)->ll_symbol;
23042 curr = &(*curr)->dw_loc_next;
23045 loc->resolved_addr = 1;
23049 loc->dw_loc_next = *start;
23054 remove_AT (die, a->dw_attr);
23058 case dw_val_class_loc:
23059 if (!resolve_addr_in_expr (AT_loc (a)))
23061 remove_AT (die, a->dw_attr);
23065 case dw_val_class_addr:
23066 if (a->dw_attr == DW_AT_const_value
23067 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
23069 remove_AT (die, a->dw_attr);
23072 if (die->die_tag == DW_TAG_GNU_call_site
23073 && a->dw_attr == DW_AT_abstract_origin)
23075 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
23076 dw_die_ref tdie = lookup_decl_die (tdecl);
23077 if (tdie == NULL && DECL_EXTERNAL (tdecl))
23079 force_decl_die (tdecl);
23080 tdie = lookup_decl_die (tdecl);
23084 a->dw_attr_val.val_class = dw_val_class_die_ref;
23085 a->dw_attr_val.v.val_die_ref.die = tdie;
23086 a->dw_attr_val.v.val_die_ref.external = 0;
23090 remove_AT (die, a->dw_attr);
23099 FOR_EACH_CHILD (die, c, resolve_addr (c));
23102 /* Helper routines for optimize_location_lists.
23103 This pass tries to share identical local lists in .debug_loc
23106 /* Iteratively hash operands of LOC opcode. */
23108 static inline hashval_t
23109 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
23111 dw_val_ref val1 = &loc->dw_loc_oprnd1;
23112 dw_val_ref val2 = &loc->dw_loc_oprnd2;
23114 switch (loc->dw_loc_opc)
23116 case DW_OP_const4u:
23117 case DW_OP_const8u:
23121 case DW_OP_const1u:
23122 case DW_OP_const1s:
23123 case DW_OP_const2u:
23124 case DW_OP_const2s:
23125 case DW_OP_const4s:
23126 case DW_OP_const8s:
23130 case DW_OP_plus_uconst:
23166 case DW_OP_deref_size:
23167 case DW_OP_xderef_size:
23168 hash = iterative_hash_object (val1->v.val_int, hash);
23175 gcc_assert (val1->val_class == dw_val_class_loc);
23176 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
23177 hash = iterative_hash_object (offset, hash);
23180 case DW_OP_implicit_value:
23181 hash = iterative_hash_object (val1->v.val_unsigned, hash);
23182 switch (val2->val_class)
23184 case dw_val_class_const:
23185 hash = iterative_hash_object (val2->v.val_int, hash);
23187 case dw_val_class_vec:
23189 unsigned int elt_size = val2->v.val_vec.elt_size;
23190 unsigned int len = val2->v.val_vec.length;
23192 hash = iterative_hash_object (elt_size, hash);
23193 hash = iterative_hash_object (len, hash);
23194 hash = iterative_hash (val2->v.val_vec.array,
23195 len * elt_size, hash);
23198 case dw_val_class_const_double:
23199 hash = iterative_hash_object (val2->v.val_double.low, hash);
23200 hash = iterative_hash_object (val2->v.val_double.high, hash);
23202 case dw_val_class_addr:
23203 hash = iterative_hash_rtx (val2->v.val_addr, hash);
23206 gcc_unreachable ();
23210 case DW_OP_bit_piece:
23211 hash = iterative_hash_object (val1->v.val_int, hash);
23212 hash = iterative_hash_object (val2->v.val_int, hash);
23218 unsigned char dtprel = 0xd1;
23219 hash = iterative_hash_object (dtprel, hash);
23221 hash = iterative_hash_rtx (val1->v.val_addr, hash);
23223 case DW_OP_GNU_implicit_pointer:
23224 hash = iterative_hash_object (val2->v.val_int, hash);
23226 case DW_OP_GNU_entry_value:
23227 hash = hash_loc_operands (val1->v.val_loc, hash);
23231 /* Other codes have no operands. */
23237 /* Iteratively hash the whole DWARF location expression LOC. */
23239 static inline hashval_t
23240 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
23242 dw_loc_descr_ref l;
23243 bool sizes_computed = false;
23244 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23245 size_of_locs (loc);
23247 for (l = loc; l != NULL; l = l->dw_loc_next)
23249 enum dwarf_location_atom opc = l->dw_loc_opc;
23250 hash = iterative_hash_object (opc, hash);
23251 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
23253 size_of_locs (loc);
23254 sizes_computed = true;
23256 hash = hash_loc_operands (l, hash);
23261 /* Compute hash of the whole location list LIST_HEAD. */
23264 hash_loc_list (dw_loc_list_ref list_head)
23266 dw_loc_list_ref curr = list_head;
23267 hashval_t hash = 0;
23269 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
23271 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
23272 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
23274 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
23276 hash = hash_locs (curr->expr, hash);
23278 list_head->hash = hash;
23281 /* Return true if X and Y opcodes have the same operands. */
23284 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
23286 dw_val_ref valx1 = &x->dw_loc_oprnd1;
23287 dw_val_ref valx2 = &x->dw_loc_oprnd2;
23288 dw_val_ref valy1 = &y->dw_loc_oprnd1;
23289 dw_val_ref valy2 = &y->dw_loc_oprnd2;
23291 switch (x->dw_loc_opc)
23293 case DW_OP_const4u:
23294 case DW_OP_const8u:
23298 case DW_OP_const1u:
23299 case DW_OP_const1s:
23300 case DW_OP_const2u:
23301 case DW_OP_const2s:
23302 case DW_OP_const4s:
23303 case DW_OP_const8s:
23307 case DW_OP_plus_uconst:
23343 case DW_OP_deref_size:
23344 case DW_OP_xderef_size:
23345 return valx1->v.val_int == valy1->v.val_int;
23348 gcc_assert (valx1->val_class == dw_val_class_loc
23349 && valy1->val_class == dw_val_class_loc
23350 && x->dw_loc_addr == y->dw_loc_addr);
23351 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
23352 case DW_OP_implicit_value:
23353 if (valx1->v.val_unsigned != valy1->v.val_unsigned
23354 || valx2->val_class != valy2->val_class)
23356 switch (valx2->val_class)
23358 case dw_val_class_const:
23359 return valx2->v.val_int == valy2->v.val_int;
23360 case dw_val_class_vec:
23361 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
23362 && valx2->v.val_vec.length == valy2->v.val_vec.length
23363 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
23364 valx2->v.val_vec.elt_size
23365 * valx2->v.val_vec.length) == 0;
23366 case dw_val_class_const_double:
23367 return valx2->v.val_double.low == valy2->v.val_double.low
23368 && valx2->v.val_double.high == valy2->v.val_double.high;
23369 case dw_val_class_addr:
23370 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
23372 gcc_unreachable ();
23375 case DW_OP_bit_piece:
23376 return valx1->v.val_int == valy1->v.val_int
23377 && valx2->v.val_int == valy2->v.val_int;
23380 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
23381 case DW_OP_GNU_implicit_pointer:
23382 return valx1->val_class == dw_val_class_die_ref
23383 && valx1->val_class == valy1->val_class
23384 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
23385 && valx2->v.val_int == valy2->v.val_int;
23386 case DW_OP_GNU_entry_value:
23387 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
23389 /* Other codes have no operands. */
23394 /* Return true if DWARF location expressions X and Y are the same. */
23397 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
23399 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
23400 if (x->dw_loc_opc != y->dw_loc_opc
23401 || x->dtprel != y->dtprel
23402 || !compare_loc_operands (x, y))
23404 return x == NULL && y == NULL;
23407 /* Return precomputed hash of location list X. */
23410 loc_list_hash (const void *x)
23412 return ((const struct dw_loc_list_struct *) x)->hash;
23415 /* Return 1 if location lists X and Y are the same. */
23418 loc_list_eq (const void *x, const void *y)
23420 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
23421 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
23424 if (a->hash != b->hash)
23426 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
23427 if (strcmp (a->begin, b->begin) != 0
23428 || strcmp (a->end, b->end) != 0
23429 || (a->section == NULL) != (b->section == NULL)
23430 || (a->section && strcmp (a->section, b->section) != 0)
23431 || !compare_locs (a->expr, b->expr))
23433 return a == NULL && b == NULL;
23436 /* Recursively optimize location lists referenced from DIE
23437 children and share them whenever possible. */
23440 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
23447 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23448 if (AT_class (a) == dw_val_class_loc_list)
23450 dw_loc_list_ref list = AT_loc_list (a);
23451 /* TODO: perform some optimizations here, before hashing
23452 it and storing into the hash table. */
23453 hash_loc_list (list);
23454 slot = htab_find_slot_with_hash (htab, list, list->hash,
23457 *slot = (void *) list;
23459 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
23462 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
23465 /* Optimize location lists referenced from DIE
23466 children and share them whenever possible. */
23469 optimize_location_lists (dw_die_ref die)
23471 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
23472 optimize_location_lists_1 (die, htab);
23473 htab_delete (htab);
23476 /* Output stuff that dwarf requires at the end of every file,
23477 and generate the DWARF-2 debugging info. */
23480 dwarf2out_finish (const char *filename)
23482 limbo_die_node *node, *next_node;
23483 comdat_type_node *ctnode;
23484 htab_t comdat_type_table;
23487 gen_scheduled_generic_parms_dies ();
23488 gen_remaining_tmpl_value_param_die_attribute ();
23490 /* Add the name for the main input file now. We delayed this from
23491 dwarf2out_init to avoid complications with PCH. */
23492 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
23493 if (!IS_ABSOLUTE_PATH (filename))
23494 add_comp_dir_attribute (comp_unit_die ());
23495 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
23498 htab_traverse (file_table, file_table_relative_p, &p);
23500 add_comp_dir_attribute (comp_unit_die ());
23503 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
23505 add_location_or_const_value_attribute (
23506 VEC_index (deferred_locations, deferred_locations_list, i)->die,
23507 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
23512 /* Traverse the limbo die list, and add parent/child links. The only
23513 dies without parents that should be here are concrete instances of
23514 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23515 For concrete instances, we can get the parent die from the abstract
23517 for (node = limbo_die_list; node; node = next_node)
23519 dw_die_ref die = node->die;
23520 next_node = node->next;
23522 if (die->die_parent == NULL)
23524 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
23527 add_child_die (origin->die_parent, die);
23528 else if (is_cu_die (die))
23530 else if (seen_error ())
23531 /* It's OK to be confused by errors in the input. */
23532 add_child_die (comp_unit_die (), die);
23535 /* In certain situations, the lexical block containing a
23536 nested function can be optimized away, which results
23537 in the nested function die being orphaned. Likewise
23538 with the return type of that nested function. Force
23539 this to be a child of the containing function.
23541 It may happen that even the containing function got fully
23542 inlined and optimized out. In that case we are lost and
23543 assign the empty child. This should not be big issue as
23544 the function is likely unreachable too. */
23545 tree context = NULL_TREE;
23547 gcc_assert (node->created_for);
23549 if (DECL_P (node->created_for))
23550 context = DECL_CONTEXT (node->created_for);
23551 else if (TYPE_P (node->created_for))
23552 context = TYPE_CONTEXT (node->created_for);
23554 gcc_assert (context
23555 && (TREE_CODE (context) == FUNCTION_DECL
23556 || TREE_CODE (context) == NAMESPACE_DECL));
23558 origin = lookup_decl_die (context);
23560 add_child_die (origin, die);
23562 add_child_die (comp_unit_die (), die);
23567 limbo_die_list = NULL;
23569 resolve_addr (comp_unit_die ());
23571 for (node = deferred_asm_name; node; node = node->next)
23573 tree decl = node->created_for;
23574 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
23576 add_linkage_attr (node->die, decl);
23577 move_linkage_attr (node->die);
23581 deferred_asm_name = NULL;
23583 /* Walk through the list of incomplete types again, trying once more to
23584 emit full debugging info for them. */
23585 retry_incomplete_types ();
23587 if (flag_eliminate_unused_debug_types)
23588 prune_unused_types ();
23590 /* Generate separate CUs for each of the include files we've seen.
23591 They will go into limbo_die_list. */
23592 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
23593 break_out_includes (comp_unit_die ());
23595 /* Generate separate COMDAT sections for type DIEs. */
23596 if (dwarf_version >= 4)
23598 break_out_comdat_types (comp_unit_die ());
23600 /* Each new type_unit DIE was added to the limbo die list when created.
23601 Since these have all been added to comdat_type_list, clear the
23603 limbo_die_list = NULL;
23605 /* For each new comdat type unit, copy declarations for incomplete
23606 types to make the new unit self-contained (i.e., no direct
23607 references to the main compile unit). */
23608 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23609 copy_decls_for_unworthy_types (ctnode->root_die);
23610 copy_decls_for_unworthy_types (comp_unit_die ());
23612 /* In the process of copying declarations from one unit to another,
23613 we may have left some declarations behind that are no longer
23614 referenced. Prune them. */
23615 prune_unused_types ();
23618 /* Traverse the DIE's and add add sibling attributes to those DIE's
23619 that have children. */
23620 add_sibling_attributes (comp_unit_die ());
23621 for (node = limbo_die_list; node; node = node->next)
23622 add_sibling_attributes (node->die);
23623 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23624 add_sibling_attributes (ctnode->root_die);
23626 /* Output a terminator label for the .text section. */
23627 switch_to_section (text_section);
23628 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
23629 if (cold_text_section)
23631 switch_to_section (cold_text_section);
23632 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
23635 /* We can only use the low/high_pc attributes if all of the code was
23637 if (!have_multiple_function_sections
23638 || (dwarf_version < 3 && dwarf_strict))
23640 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
23641 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
23646 unsigned fde_idx = 0;
23647 bool range_list_added = false;
23649 /* We need to give .debug_loc and .debug_ranges an appropriate
23650 "base address". Use zero so that these addresses become
23651 absolute. Historically, we've emitted the unexpected
23652 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23653 Emit both to give time for other tools to adapt. */
23654 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
23655 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
23657 if (text_section_used)
23658 add_ranges_by_labels (comp_unit_die (), text_section_label,
23659 text_end_label, &range_list_added);
23660 if (cold_text_section_used)
23661 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
23662 cold_end_label, &range_list_added);
23664 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
23666 dw_fde_ref fde = &fde_table[fde_idx];
23668 if (!fde->in_std_section)
23669 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
23670 fde->dw_fde_end, &range_list_added);
23671 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
23672 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
23673 fde->dw_fde_second_end, &range_list_added);
23676 if (range_list_added)
23680 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23681 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
23682 debug_line_section_label);
23684 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23685 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
23687 if (have_location_lists)
23688 optimize_location_lists (comp_unit_die ());
23690 /* Output all of the compilation units. We put the main one last so that
23691 the offsets are available to output_pubnames. */
23692 for (node = limbo_die_list; node; node = node->next)
23693 output_comp_unit (node->die, 0);
23695 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
23696 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23698 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
23700 /* Don't output duplicate types. */
23701 if (*slot != HTAB_EMPTY_ENTRY)
23704 /* Add a pointer to the line table for the main compilation unit
23705 so that the debugger can make sense of DW_AT_decl_file
23707 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23708 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
23709 debug_line_section_label);
23711 output_comdat_type_unit (ctnode);
23714 htab_delete (comdat_type_table);
23716 /* Output the main compilation unit if non-empty or if .debug_macinfo
23717 will be emitted. */
23718 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
23720 /* Output the abbreviation table. */
23721 switch_to_section (debug_abbrev_section);
23722 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
23723 output_abbrev_section ();
23725 /* Output location list section if necessary. */
23726 if (have_location_lists)
23728 /* Output the location lists info. */
23729 switch_to_section (debug_loc_section);
23730 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
23731 DEBUG_LOC_SECTION_LABEL, 0);
23732 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
23733 output_location_lists (comp_unit_die ());
23736 /* Output public names table if necessary. */
23737 if (!VEC_empty (pubname_entry, pubname_table))
23739 gcc_assert (info_section_emitted);
23740 switch_to_section (debug_pubnames_section);
23741 output_pubnames (pubname_table);
23744 /* Output public types table if necessary. */
23745 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23746 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23747 simply won't look for the section. */
23748 if (!VEC_empty (pubname_entry, pubtype_table))
23750 bool empty = false;
23752 if (flag_eliminate_unused_debug_types)
23754 /* The pubtypes table might be emptied by pruning unused items. */
23758 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
23759 if (p->die->die_offset != 0)
23767 gcc_assert (info_section_emitted);
23768 switch_to_section (debug_pubtypes_section);
23769 output_pubnames (pubtype_table);
23773 /* Output the address range information. We only put functions in the
23774 arange table, so don't write it out if we don't have any. */
23775 if (info_section_emitted)
23777 unsigned long aranges_length = size_of_aranges ();
23779 /* Empty .debug_aranges would contain just header and
23780 terminating 0,0. */
23782 != (unsigned long) (DWARF_ARANGES_HEADER_SIZE
23783 + 2 * DWARF2_ADDR_SIZE))
23785 switch_to_section (debug_aranges_section);
23786 output_aranges (aranges_length);
23790 /* Output ranges section if necessary. */
23791 if (ranges_table_in_use)
23793 switch_to_section (debug_ranges_section);
23794 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
23798 /* Output the source line correspondence table. We must do this
23799 even if there is no line information. Otherwise, on an empty
23800 translation unit, we will generate a present, but empty,
23801 .debug_info section. IRIX 6.5 `nm' will then complain when
23802 examining the file. This is done late so that any filenames
23803 used by the debug_info section are marked as 'used'. */
23804 switch_to_section (debug_line_section);
23805 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
23806 if (! DWARF2_ASM_LINE_DEBUG_INFO)
23807 output_line_info ();
23809 /* Have to end the macro section. */
23810 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23812 switch_to_section (debug_macinfo_section);
23813 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
23814 if (!VEC_empty (macinfo_entry, macinfo_table))
23816 dw2_asm_output_data (1, 0, "End compilation unit");
23819 /* If we emitted any DW_FORM_strp form attribute, output the string
23821 if (debug_str_hash)
23822 htab_traverse (debug_str_hash, output_indirect_string, NULL);
23825 #include "gt-dwarf2out.h"